1- <?php
1+ <pre> < ?php
22
33/*
44 * Tripwire
2727 'files ' => array ( // Files to Exclude from Scanning
2828 '. ' ,
2929 '.. ' ,
30- 'filelist .md5 ' ,
30+ 'tripwire_filelist .md5 ' ,
3131 'error_log ' ,
3232 'backup.zip ' ,
3333 '.bash_history '
3434 ) ,
3535 'extns ' => array ( // Extensions to Exclude from Scanning
36- 'flv ' , ' swf ' ,
36+ 'flv ' ,
3737 'log ' ,
3838 'txt ' ,
39- 'mp4 ' , 'mov ' , 'webm ' , 'ogv ' ,
40- 'psd ' , 'jpg ' ,
39+ 'mp4 ' ,
40+ 'mov ' ,
41+ 'psd ' ,
42+ 'swf ' ,
4143 'mno ' ,
44+ 'jpg ' ,
4245 'aif ' ,
4346 'doc ' ,
47+ 'webm ' ,
48+ 'ogv ' ,
4449 'afm ' ,
4550 'sitx '
4651 )
6065
6166function makeHash ( $ dir =false ){
6267 global $ config , $ filelist ;
63-
64- if ( !$ dir )
68+
69+ if ( !$ dir ) // Default to the Root of the Site the script is executed under
6570 $ dir = $ _SERVER ['DOCUMENT_ROOT ' ];
6671
67- if ( !is_dir ( $ dir ) )
72+ if ( substr ( $ dir , -1 )=='/ ' ) // Strip slash from end of directory
73+ $ dir = substr ( $ dir , 0 , -1 );
74+
75+ if ( !is_dir ( $ dir ) ) // If the supplied variable is not a Directory, terminate
6876 return false ;
6977
7078 $ temp = array ();
7179 $ d = dir ( $ dir );
7280
73- while ( false !==( $ entry = $ d ->read () ) ){
74- if ( !is_readable ( $ entry ) ){
75- // File is Unreadable
76- continue ;
81+ while ( false !==( $ entry = $ d ->read () ) ){ // Loop through the files
82+ if ( is_link ( $ entry ) ){
83+ continue ; // Symbolic Link - Excluded
7784 }
7885 if ( in_array ( $ entry , $ config ['exclude ' ]['files ' ] ) ){
79- // Excluded File/Folder
80- continue ;
86+ continue ; // Excluded File/Folder
8187 }
8288 if ( in_array ( pathinfo ( $ entry , PATHINFO_EXTENSION ) , $ config ['exclude ' ]['extns ' ] ) ){
83- // Excluded File Extension
84- continue ;
89+ continue ; // Excluded File Extension
8590 }
8691 if ( is_dir ( $ dir .'/ ' .$ entry ) ){
8792 // Recurse
8893 $ temp = array_merge ( $ temp , makeHash ( $ dir .'/ ' .$ entry ) );
8994 }else {
90- $ temp [$ dir .'/ ' .$ entry ] = md5_file ( $ dir .'/ ' .$ entry );
95+ $ md5 = @md5_file ( $ dir .'/ ' .$ entry );
96+ if ( !$ md5 ){
97+ file_put_contents ( 'tripwire_unreadable.txt ' , "{$ dir }/ {$ entry } - Unreadable \n" , FILE_APPEND );
98+ }else {
99+ $ temp [$ dir .'/ ' .$ entry ] = $ md5 ;
100+ }
91101 }
92102 }
93103
@@ -148,17 +158,14 @@ function file_put_contents( $filename , $data ){
148158
149159
150160
151- echo ' $new<pre> ' ;
161+ echo "\ $new \n" ;
152162var_dump ( $ new );
153- echo '</pre> ' ;
154163
155- echo ' $deleted<pre> ' ;
164+ echo "\ $deleted \n" ;
156165var_dump ( $ deleted );
157- echo '</pre> ' ;
158166
159- echo ' $modified<pre> ' ;
167+ echo "\ $modified \n" ;
160168var_dump ( $ modified );
161- echo '</pre> ' ;
162169
163170
164171
@@ -194,11 +201,11 @@ function file_put_contents( $filename , $data ){
194201 // Prepare the placeholder details
195202 $ body_replacements = array (
196203 '[AN] ' => count ( $ new ) ,
197- '[AF] ' => ( count ( $ new ) ? implode ( "\n" , array_keys ( $ new ) ) : 'No Files ' ) ,
204+ '[AF] ' => ( count ( $ new ) ? implode ( "\n" , $ new ) : 'No Files ' ) ,
198205 '[MN] ' => count ( $ modified ) ,
199206 '[MF] ' => ( count ( $ modified ) ? implode ( "\n" , array_keys ( $ modified ) ) : 'No Files ' ) ,
200207 '[DN] ' => count ( $ deleted ) ,
201- '[DF] ' => ( count ( $ deleted ) ? implode ( "\n" , array_keys ( $ deleted ) ) : 'No Files ' ) ,
208+ '[DF] ' => ( count ( $ deleted ) ? implode ( "\n" , $ deleted ) : 'No Files ' ) ,
202209 );
203210
204211 // Prepare the recipients
@@ -214,9 +221,9 @@ function file_put_contents( $filename , $data ){
214221
215222 // Send it
216223 if ( mail ( $ to , $ title , $ body ) ){
217- echo ' <pre> Email Sent Successfully</pre> ' ;
224+ echo " Email Sent Successfully \n" ;
218225 }else {
219- echo ' <pre> Email Failed</pre> ' ;
226+ echo " Email Failed \n" ;
220227 }
221228
222229 }
0 commit comments