This is an example with a

headline

`

This php script will send you a mail with all the files that have been changed within an interval you specify.

I created this script because someone hacked into my shared hosting account and added some hidden spammy link into my templates. And since most shared hosting accounts do not have any kind of logfiles available, it is almost impossible for you to find out how the hacker got in. I could even be, the hacker got acces to your files by hacking another shared hosting account on that server.

With this script you will at least be notified when someone has changed the files on your server.

settings:

PHP:
  1. $from="name@domain.com";
  2. $to="name@domain.com";
  3. $subject="changes on webhosting";
  4. $domain = "yourdomain.com";
  5.  
  6. $settings = array( array(
  7.                 wwwname => 'htdocs1',
  8.                 wwwdirectory => '/mounted-storage/home/website1.com'
  9.             ),
  10.             array(
  11.                 wwwname => 'htdocs2',
  12.                 wwwdirectory => '/mounted-storage/home/website2.com'
  13.             )
  14.          );

functions

PHP:
  1. function url_remove_lastslash($url){   
  2.     if (substr($url,strlen($url)-1,1)=="/"){
  3.         return substr($url,0,strlen($url)-1);
  4.     }else{
  5.         return $url;
  6.     }
  7. }
  8.  
  9. $resultsarray();
  10. function getfiles($path_start) {
  11.     global $results;
  12.     $dir = @opendir($path_start);
  13.     while (false!=($file = @readdir($dir))) {
  14.         if ($file != "." && $file != "..") {
  15.        
  16.             $file_path = url_remove_lastslash($path_start) . "/"$file;
  17.             if(is_dir($file_path)){
  18.                 getfiles ($file_path);
  19.             }
  20.             $date_mod = filemtime($file_path); //get last modified date of file
  21.             if(trim($date_mod) <> ""){
  22.                            
  23.                 $date_mod = date("Y-m-d", $date_mod);         
  24.                 $yr = substr($date_mod,0,4); //display 'new' image if item not-older than 7days
  25.                 $mnth = substr($date_mod,5,2);
  26.                 $dy = substr($date_mod,8,2);
  27.                 $newday = date("Y-m-d", mktime(0,0,0,$mnth,$dy + 2,$yr));
  28.                 $now = date("Y-m-d");
  29.                 //echo $yr .$mnth . $dy."<br>";
  30.                
  31.                     if (($now <= $newday)  ) {
  32.                         //echo $file_path . " " . $date_mod  . " " . $now  . " " . $newday. $yr .$mnth . $dy."<br>";
  33.                         $results[$file_path][0] = $file_path ;
  34.                         $results[$file_path][1]$date_mod;
  35.                     }
  36.             }
  37.  
  38.         }
  39.  
  40.     }
  41. }

check all hosting accounts & create mailbody

PHP:
  1. foreach ($settings as $setting){
  2.     $resultsarray();
  3.     $date_change = "";
  4.     $filename= "";
  5.    
  6.     getfiles($setting['wwwdirectory']);
  7.    
  8.     $mail_body .=  "<b>".$setting['wwwname']."</b><br/>";
  9.    
  10.     //sort by change date
  11.     foreach ($results as $key => $row) {
  12.         $date_change[$key]  = $row[0];
  13.         $filename[$key] = $row[1];
  14.        
  15.     }
  16.    
  17.     //array_multisort($filename, SORT_DESC, $date_change, SORT_ASC, $results);
  18.    
  19.     foreach ($results as $result){
  20.         $mail_body .=  $result[1] . ": " . str_replace($setting['wwwdirectory'],"",$result[0])."<br/>";
  21.     }
  22.    
  23. }

mail the changed files

PHP:
  1. $headers="";
  2.    $headers .= "X-Sender:  $from <$from>\n"; //
  3.    $headers .="From: $from <$from>\n";
  4.    $headers .= "Reply-To: $from <$from>\n";
  5.    $headers .= "Date: ".date("r")."\n";
  6.    $headers .= "Message-ID: <".date("YmdHis")."$from>\n";
  7.    $headers .= "Subject: $subject\n";
  8.    $headers .= "Return-Path: $from <$from>\n";
  9.    $headers .= "Delivered-to: $from <$from>\n";
  10.    $headers .= "MIME-Version: 1.0\n";
  11.    $headers .= "Content-type: text/html;charset=ISO-8859-9\n";
  12.    $headers .= "X-MSMail-Priority: Normal\n";
  13.    $headers .= "X-Mailer: Mail send from ".$domain."!\n";
  14.  
  15.    //mail to customer
  16.    if(mail($to,$subject,$mail_body,$headers)){
  17.      echo "job executed succesfully";
  18.    }else{
  19.         echo "error executing job";
  20.    }

You can download a copy of phpHackChecker here. Change the file extension to ".php".

Popularity: 24% [?]