Location: PHPKode > scripts > SimpleSiteAudit > index.php
<?php
/*
  _, _ _, _ __, _,  __,    _, _ ___ __,    _, _,_ __, _ ___  
 (_  | |\/| |_) |   |_    (_  |  |  |_    / \ | | | \ |  |   
 , ) | |  | |   | , |     , ) |  |  |     |~| | | | / |  |   
  ~  ~ ~  ~ ~   ~~~ ~~~    ~  ~  ~  ~~~   ~ ~ `~' ~~  ~  ~   v1.5.2 Multisite
 * 
 * Copyright (C) 2012 Terry Heffernan. All rights reserved.
 * Technical support: http://simplesiteaudit.terryheffernan.net
 */


session_start();
error_reporting (E_ALL ^ E_NOTICE);
// Start page-load timer    
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
$ssa_ver = "1.5.2";

if (isset($_GET['fileEmptied'])){
$fileEmptied = $_GET['fileEmptied'];
}

$logs_dir = '../../logs';
$ftp_server = "";

if(isset($_GET['server'])){
    $ftp_server = stripslashes($_GET['server']);
}elseif(isit_dir($logs_dir) > 0 && $ftp_server == ""){
    $scan = scandir($logs_dir);
    $i = 0;
    foreach($scan as $value){
      if($i == 0){
        if($value != '.' && $value != '..'){
            $ftp_server = stripslashes(trim($value));
            $i++;
        }
      }
    }
 }

$dbsettings = $logs_dir.'/'.$ftp_server.'/db_settings.txt';
if(file_exists($dbsettings)){
    $file = file($dbsettings);
    $db_server = trim($file[0]); 
    $db_user = trim($file[1]);
    $db_pass = trim($file[2]);
    $db_name = trim($file[3]);
        
    $key = 'hide@address.com@hide@address.com';         
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($db_pass), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
    $db_pass = trim($decrypt);
}else{
    header("Location: index1.php");
}

// Clear history of POST variables, so that browser doesn't object to a refresh.
if (isset($_GET['start_prg'])) {
    simple_prg(true, 'PHP_SELF');
} else {
    simple_prg(null, 'PHP_SELF');
}
$u = simple_prg(); // get the current transaction id 
setcookie("uid", $u, time() + 1200); // record the current transaction id, with 20 minute time-out
   
$site_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_site';

if($db_server != ""){
$is_table_empty = is_table_empty($site_table,$db_server,$db_user,$db_pass,$db_name);
}

if($ftp_server != "" && $ftp_server != null && $db_server != "" && $is_table_empty > 0){
    $con = mysql_connect($db_server,$db_user,$db_pass)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());
    
    $site_table = 'ssa_'.stripslashes(str_replace('-','_',str_replace('.','_',$ftp_server))).'_site';
    $result = mysql_query("SELECT * FROM $site_table") or die(mysql_error());

    while($row = mysql_fetch_array($result)) 
    {
       $id = $row[id];
       $subject = $row[email_subj];
       $skipfile = $row[skip_files];
       $skipdir = $row[skip_dir];
       $alert = $row[email_alert];
       $message = $row[email_header];
       $from = $row[from_addr];
       $createLog = $row[SSA_log];
       $cronlogpath = $row[cron_path];
       $dte = $row[date];
       $tme = $row[time];
    }
    mysql_close($con)or die(mysql_error()); 
}

if($_POST['submit']){
    $ftp_server = trim($_POST['site_list']);
    //$routeDirectory = trim($_POST[routeDirectory]);
    $subject = trim($_POST['subject']);
    $skipfile = trim($_POST['skipfile']);
    $skipdir = trim($_POST['skipdir']);
    $alert = trim($_POST['alertAddress']);
    $from = trim($_POST['fromAddress']);
    $message = trim($_POST['message']);
    $createLog = trim($_POST['createLog']);
    $cronlogpath = trim($_POST['cronlogpath']);
}

$clear = trim($_GET['clear']);
$fileEmptied = $_GET['fileEmptied'];

if (file_exists($logs_dir)) {
    if (!is_removeable($logs_dir)) { // Check if 'logs' directory is writeable. Files within the directory will also be checked.
        echo '<p class="sub1" style="text-align: left"><img border="0" src="images/cross.jpg" align="left" width="16" height="16"> Error!</p>
        <p class="sub1" style="text-align: left">Your \'logs\' directory doesn\'t exist or is not writeable or files within it are not writeable.</p>
        <p class="sub1" style="text-align: left">Please read the <a href="readme.html">README file.</a></p>
        <p class="sub1" style="text-align: left">Setup is unable to continue.</p>';
        exit();
    }
}

$id = $_GET['uniqid'];

if ($createLog == 'Y' || $clear == 'Y') { // Show checkbox checked or not
    $log = 'checked';
} elseif($createLog == 'Y' && $uid == $id) {
    $log = 'checked';
}else{
    $log = "";
}

// Generate sites list drop-down menu    
$site_list = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($logs_dir), RecursiveIteratorIterator::SELF_FIRST);
$html = Select($logs_dir, 'site_list', $site_list);

if($_POST['submit'] && $ftp_server != ""){
    store_details($db_server, $db_user, $db_pass, $db_name, $ftp_server, $subject, $skipfile, $skipdir, $alert, $from, $message, $createLog, $cronlogpath);
}



// Start html     
echo '
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
  <link href="css/simplesiteaudit.css" rel="stylesheet" type="text/css">
  <script language="JavaScript" src="validation/validate.js"
    type="text/javascript" xml:space="preserve"></script>

  <script type="text/javascript">
  function populate(server, default_subject, default_ignore_files, TO_address, FROM_address, default_message,cronlogpath){
     document.myform.site_list.value=server; 
     //document.myform.remote_dir_path.value=settingsFTP;
     document.myform.routeDirectory.value=server;
     document.myform.subject.value=default_subject;
     document.myform.skipfile.value=default_ignore_files;
     document.myform.alertAddress.value=TO_address;
     document.myform.fromAddress.value=FROM_address;
     document.myform.message.value=default_message;
     document.myform.cronlogpath.value=cronlogpath;
  }
  
 function open_win(){
    window.open("ftp_scan.php?server='.$ftp_server.'");
    window.location.href=\'index.php?server='.$ftp_server.'\';
 }
 
function pageScroll2() {
    	window.scrollBy(0,50); // horizontal and vertical scroll increments
      //alert( getPosition2() ); 
       if( getPosition2() <= 700 &&  getPosition2() >= 150){
    	scrolldelay = setTimeout(\'pageScroll2()\',50); // scroll increments every 50 milliseconds
       }
}

function getPosition2(){
    var e = document.getElementById(\'cronlogcontents\');
    var offset = {x:0,y:0};
    while (e)
    {
        offset.x += e.offsetLeft;
        offset.y += e.offsetTop;
        e = e.offsetParent;
    }

    if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft))
    {
        offset.x -= document.documentElement.scrollLeft;
        offset.y -= document.documentElement.scrollTop;
    }
    else if (document.body && (document.body.scrollTop || document.body.scrollLeft))
    {
        offset.x -= document.body.scrollLeft;
        offset.y -= document.body.scrollTop;
    }
    else if (window.pageXOffset || window.pageYOffset)
    {
        offset.x -= window.pageXOffset;
        offset.y -= window.pageYOffset;
    }

    return offset.y;
}

</script>

<script type="text/javascript">
function selected()
{
document.getElementById("selected").bgColor=#ccc;
}
</script>
        
 <script type="text/javascript">// <![CDATA[
 function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
// ]]></script>

<SCRIPT LANGUAGE="JavaScript">
function respConfirm () {
     var response = confirm(\'Click OK to empty the SSA log:\');
     if (response) window.location.href=\'clear_log.php?server='.$ftp_server.'\';
}
</SCRIPT>
<style>
div.floating-menu {position:fixed;width:60px;}
div.floating-menu a, div.floating-menu h3 {display:block;margin:400 55.0em;}
</style>

<!--[if IE]>
<style>
#tab6{
border: 1px solid gray
}
th, td {
    padding: 15;
}
input {
margin: 0;
padding: 1;
width: auto;
overflow: visible;
}
input.text{
width:350px;
}
image{
border: 0px;
}
</style>
<![endif]-->
</head><body>

<![if !IE]>
<div class="floating-menu">
<a><input onclick="window.location.href=\'#top\'" style="width: auto;" title="Top of page" type="button" name="top" value="Top" /></a>
</div><![endif]>';

echo '
    <a name="top"></a>
  <table class="tab1"><tr><td>
  <table padding="15px" id="tab0" class="tab0">
  <tr><td colspan="2">
  <p class="sub2"><font color="brown">SimpleSiteAudit</font> Admin<label> Multisite v1.5.2 </label>
  <img border="0" src="images/spacer.gif" width="90" height="0">
  <input type="button" id="back" onclick="window.location.href=\'index1.php\'" style="width: auto; background-color: #ffffff;" name="back" alt="Back to FTP/DB setup form" value="Back to FTP/DB setup">
  <input type="button" id="compare" onclick="window.location.href=\'filediff/uploadform.html\'" style="width: auto; background-color: #ADFF2F;" name="compare" alt="Compare 2 text-based files" value="Compare files">
  <br /><br />
    <label>Step 2: Enter your preferences for each site you wish to monitor.<label>
    <img border="0" src="images/spacer.gif" width="100" height="5">
    <small>Fields marked with <a class="asterisk">*</a> are required</small><br /><br />';
echo '<form name="myform" method="POST" action="index.php">
    <label>Select site: </label>';
echo $html; // Will contain a drop-down list of all sites being monitored

echo '<img border="0" src="images/spacer.gif" width="150" height="2">';
echo '<br />';

echo '<tr><td>';
echo '<div id="myform">';

echo '<a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <img border="0" src="images/spacer.gif" width="0" height="21"><br />
  <img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'Email address to alert\'</b><br /><br />This address will be used as the recipient\'s address in the email alert. A short, comma seperated list of addresses is allowed if required (Max characters: 300)</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Email address to alert:</label><br /> 
  <input size="50" type="text" name="alertAddress" value="';
    echo $alert;
echo '" id="alertAddress" />
<br />
   <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <![if !IE]><br /><![endif]><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'Subject for message\'</b><br /><br />This will be used as the \'Subject\' line in the email that is transmitted when changes are found.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><small><font color="red">*</font></small></small><label>Subject for message:</label><br />
  <input size="50" type="text" name="subject" value="';
    echo $subject;
echo '" />
<br />
  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <![if !IE]><br /><![endif]><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'List of files to ignore\'</b><br /><br />This should consist of a list of comma separated file names, including the file extension.<br />
  Be careful with the selection of file names. If, for example, index.php is entered, all files with that name, throughout the site, will be ignored. (This field is optional)</span></a>
 <img border="0" src="images/spacer.gif" width="10" height="5">
 <font color="#fbfbfb">-</font><label>List of files to ignore:</label> 
  <input size="50" type="text" name="skipfile" value="';
    echo $skipfile;
echo '" id="skipfile" />';

echo '
<br />
  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <![if !IE]><br /><![endif]><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'List of directories to ignore\'</b><br /><br />This should consist of a list of comma separated directory names.<br />
  Be careful with the selection of directory names. If, for example, the \'images\' directory is entered, all directories with that name, throughout the site, will be ignored. (This field is optional)</span></a>
 <img border="0" src="images/spacer.gif" width="10" height="5">
 <font color="#fbfbfb">-</font><label>List of directories to ignore:</label> 
  <input size="50" type="text" name="skipdir" value="';
    echo $skipdir;
echo '" id="skipdir" />';

echo '
</div>
<td><![if !IE]><img border="0" src="images/spacer.gif" width="0" height="2"><![endif]>
<div id="myform2">

  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <br /><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'The \'From\' email address\'</b><br /><br />This address will be used as the sender\'s address in the email alert.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>The \'From\' email address:</label><br /> 
  <input size="50" type="text" name="fromAddress" value="';
    echo $from;
echo '" id="fromAddress" />
<br />
  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <br /><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'Message body opening line\'</b><br /><br />This text will be used as the header line in the email body.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Message body opening line:</label><br /> 
  <input size="50" type="text" name="message" id="message" value="';
    echo $message;
echo '" id="message" />
<br />
  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <br /><img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'Path to and name of your Cron log\'</b><br /><br />Relative to your SSA files location. e.g. <font color="blue">../../cronfilename.txt</font> The \'view file\' button will not appear if this file does not exist.<br />
  Recommend leaving this field empty if using the SSA log file and vice versa.<br /><br />
  The log contents will appear in a read only textarea. Further formatting is not possible due to unknown input by the Cron process itself. There is no \'Clear log\' button for this feature.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="#fbfbfb">-</font></small><label>Path to, and name of your Cron log:</label><br /> 
  <input size="50" type="text" name="cronlogpath" value="';
    echo $cronlogpath;
echo '" id="cronlogpath" /><br />';
echo '
  <br />
  <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"> 
  <img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">  
  <span><b>\'Create an SSA log\'</b><br /><br />Choose this option if you would prefer to set up a log in the database, as opposed to the file created by the Cron process.<br />
  <br />The advantages in choosing this option is to allow a nicely formatted view of the log. Also, the SSA log will only record the script output if changes are detected. As opposed to The Cron log, which will record the output for every run.<br /><br />The log can grow quite large. 
  Therefore, it is advisable to empty it periodically via the \'Clear SSA log\' button. The \'View/hide SSA log\' and the \'Clear SSA log\' buttons will appear after the first changes have been detected. They will not be visible if the log is empty.</span></a>  
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <label>Create an SSA log: </label>
  <input style="width: auto;" type="checkbox" name="createLog" value="Y" ';
echo $log;
echo '/><br /><small>(Log will only be updated when changes are detected.)</small>';
echo '</td></tr><tr><td colspan="2">';
//Submit button
echo '<![if !IE]><br /><![endif]><input style=" width: auto;" title="Submit to update database." type="submit" name="submit" value="Submit settings" onclick="location.href=\'index1.php?server='.$ftp_server.'\'"/>';

    $log_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_log';
   
if (is_table_empty($log_table,$db_server,$db_user,$db_pass,$db_name) > 0 && $log == 'checked') {
    echo '
    <input  onclick="respConfirm ();"  title="Clear the SSA log" style="width: auto;background-color: #ffffcc;" type="button" name="" value="Clear SSA log">
    <input onclick="toggle_visibility(\'view\');window.scroll(0,500);" style="width: auto;background-color: #ffffcc;" type="button" name="view_log" value="View/hide SSA log" >';
}//

if (is_table_empty($site_table,$db_server,$db_user,$db_pass,$db_name) > 0) {
    echo '
<!--<img border="0" src="images/spacer.gif" width="200" height="5">-->
    <input style="width: auto;" title="Run the script on selected site" class="button" type="button" name="runScript" value="Run the SSA script" onClick="open_win()"/>
<!--<input id="activate" onclick="window.location.href=\'clear_log.php?server='.$ftp_server.'\'" style="display: none; width: auto; background-color: #ffffcc;" type="button" name="clear" value="Clear SSA log">-->
<!--<input id="cronlog" onclick="location.href=\'clearcronlog.php?dir='.$logs_dir.'&pass=letmeinnow&outputfile='.$cronlogpath.'" style="display: none;width: auto;background-color: #FFD3DA"" type="button" name="clear" value="Clear Cron log file">-->
<!--<img border="0" src="images/spacer.gif" width="145" height="5">-->';

}

if ($cronlogpath != "") {
   if(file_exists($cronlogpath)){
    echo '<input onclick="toggle_visibility(\'cronlogcontents\');pageScroll2()" style="width: auto;background-color: #FFD3DA;" type="button" name="view_cronlog" value="View/hide Cron log"><!--[if IE]></div><![endif]-->';
   }
}
     echo '</form>';
echo '<![if !IE]><br /><br /><center><![endif]><small>SSA v1.5.2 | Check for the <a target="_blank" href="http://simplesiteaudit.terryheffernan.net/">latest version</a></small><![if !IE]></center><br /><![endif]>
      <!--Paypal form-->
<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="item_name" value="In support of SimpleSiteAudit Multisite project">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHFgYJKoZIhvcNAQcEoIIHBzCC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xODU1MTBaMCMGCSqGSIb3DQEJBDEWBBS53oFTubWNnShVmU1VFLJWBGdpNjANBgkqhkiG9w0BAQEFAASBgDBlYQjvc6iOtKrogl5eSbEfdQdPnG+UsRpzUULswDu6t+bazbTbzV49VXa3+ucCktO7aq+oVmI7OCE+JSV+2yIYOsnFO1gZb3jkftaiwpNwqDEx4wemaCAm31SDsZslyI12+ukVqXxtEeZKQlQ4zy8Zs9MSfUsTc/Hl92erV5x2-----END PKCS7-----
">
<![if !IE]><center><![endif]><small>If you think this software is worthy of support, please 
<input type="submit" style=" width: auto;" value="Donate" border="0" name="submit" title="PayPal - The safer, easier way to pay online." alt="PayPal - The safer, easier way to pay online."><![if !IE]></center><![endif]>

<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<![if !IE]><center><![endif]><small><a target="_blank" href="http://simplesiteaudit.terryheffernan.net/forum?mingleforumaction=vforum&g=5.0">Feedback</a> would be appreciated. Thank you.</small><![if !IE]></center></div><![endif]>
';
echo '</td></tr>';
$uid = $_COOKIE["uid"]; // get unique transaction id from stored cookie.

echo '
    <script language="JavaScript" type="text/javascript"
        xml:space="preserve">//<![CDATA[
    var frmvalidator  = new Validator("myform"); 
    frmvalidator.EnableMsgsTogether();    
    frmvalidator.addValidation("alertAddress","req","Need Email address to alert    ");
    frmvalidator.addValidation("alertAddress","maxlen=300");
    frmvalidator.addValidation("subject","req","Need subject for message    ");                                     
    frmvalidator.addValidation("fromAddress","req","Need the \'From\' email address    ");                                       
    frmvalidator.addValidation("message","req","Need message body opening line    ");
    //]]></script>
    ';

echo '
    </table>
    <table rowspan="2" border="0" width="400">
    <tr><td>';


if(file_exists($logs_dir .'/'.$ftp_server.'/'. 'db_settings.txt') && !$_POST['submit']){
  echo '<script>
    populate(
        \''.$ftp_server.'\',
        \''.$subject.'\', 
        \''.$skipfile.'\',
        \''.$alert.'\',
        \''.$from.'\',
        \''.$message.'\',
        \''.$cronlogpath.'\'
            )
     </script>';
}elseif($_POST['submit']){
  echo '<script>
    populate(
        \''.trim($_POST['site_list']).'\',         
        \''.trim($_POST['subject']).'\',
        \''.trim($_POST['alertAddress']).'\', 
        \''.trim($_POST['skipfile']).'\',
        \''.trim($_POST['fromAddress']).'\',
        \''.trim($_POST['message']).'\',
        \''.trim($_POST['cronlogpath']).'\'
            )
     </script>';
}

echo '<div style="display: none;" class="cronlogcontents" id="cronlogcontents">';
    $log_contents = array();    
    if(file_exists($cronlogpath)){
      $log_contents = file($cronlogpath); // Parse the contents of cron log file into an array
    }
    
    $view_log = displayString($log_contents); // Parse the array values into a string

  echo '<p class="sub2"><br /><label>Cron log file contents - '.$ftp_server.' <input type="button" onclick="toggle_visibility(\'cronlogcontents\');" style="width:auto;background-color: #FFD3DA;" name="Hide_cronlog" value="Hide Cron log" /a></label></p>';
  echo '<textarea readonly rows="40" cols="30">';
  echo $view_log;
  echo '</textarea><br /><img border="0" src="images/spacer.gif" width="0" height="600">';
  echo '</div>'; 
  echo '<div id="fadeBlock">';// Responses

echo '<table class="tab3" style="margin-left: 187px;"><td>'; // responses table
// Confirmation response - settings saved
if ($id != $uid && $id != "" && $fileEmptied != 1) {
    include 'includes/confirm.html';
}

// Confirmation response - cleared log file   && $id != $uid           
if ($fileEmptied == 1) {
    include 'includes/empty_file.html';
}
echo '</tr></td></table>'; // end responses table

echo '</div>
        <div class="view" id="view">';//Log file display.
echo '<input type="button" onclick="toggle_visibility(\'view\');" style="width:auto;background-color: #FFffcc;" name="Hide_ssa_log" value="Hide SSA log" /a>';
if (is_table_empty($log_table,$db_server,$db_user,$db_pass,$db_name) > 0 && $log == 'checked') {
   $contents_header = '<p class="sub1" ><label>SSA Log contents</label><br />
       <small class="noPrint">(You might need to refresh the page to show the latest updates)</small></p>';
}else{
   $contents_header = '<p class="sub1" style="text-align: center;"><label>SSA Log is empty</label><br />
       <small class="noPrint">(You might need to refresh the page to show the latest updates)</small></p>'; 
}
echo '<a name="1"></a>';// bookmark for files that can't be downloaded
echo '<table class="tab2" border="1" bordercolor="#ccc">
      <tr><td colspan="9">'.$contents_header.'</td></tr>';

if($ftp_server != "" && $ftp_server != null && $db_server != "" && $is_table_empty > 0){
    $con = mysql_connect($db_server,$db_user,$db_pass)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());
    
    $log_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_log';
    $settings_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_settings';
    $result = mysql_query("SELECT * FROM $log_table") or die(mysql_error());
    $dir_to_monitor = mysql_query("SELECT * FROM $settings_table") or die(mysql_error());

    while($row = mysql_fetch_array($result)) 
    {
       $log_lines[] = $row;
    }
    
    $dir_to_mon = mysql_fetch_array($dir_to_monitor);

    mysql_close($con)or die(mysql_error()); 
}

echo '<tr><td colspan="8" style="padding: 3px;font-size:12px;"><b>Web site:</b> '.$ftp_server.'<br /><b>Start Dir:</b> '.$dir_to_mon[root_dir].'</td>
    <td><input class="noPrint" type="button" id="print" onclick="printDiv(\'view\')" style="margin-top:5;margin-left:30; width: auto; background-color: #ffffff;" name="print" alt="Print" title="Print the log" value="PRINT"></td></tr>
        <tr><td style="padding: 3px;"><font color="brown">Status</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">Path to file (relative to \'Start Dir\')</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">File date</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">File time</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">Old perms</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">New perms</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">Old size</font></td>
        <td style="padding: 3px; width: 110px;"><font color="brown">New size</font></td>
        <td style="padding: 3px"><font color="brown">Script run time </font></td></tr></font>';

foreach($log_lines as $value){
       $id = $value[id];
       $status = $value[status];
       $file_name = $value[file];
       $file_date = $value[date];
       $file_time = $value[time];
       $old_perms = $value[old_perms];
       $new_perms = $value[new_perms];
       $old_size = $value[old_size];
       $new_size = $value[new_size];
       $last_run = $value[last_run];
    
    
    if($status == "Added"){
        $bgcolor = "#F0F8FF";
    }
    
    if($status == "Modified"){
        $bgcolor = "#FFE4E1";
    }
    
    if($status == "Missing"){
        $bgcolor = "#DEFADE";
    }
        
    if($status == "Permissions"){
        $bgcolor = "#ffffcc";
    }

       echo '<tr onclick="selected()" id="selected" style="background-color:'.$bgcolor.';">';
       
       $file_name = trim(stristr ($file_name,'/'));

       if(@file_get_contents("http://".$ftp_server.$file_name)){// Test if file is downloadable
                 $img = 'images/arrow_down_blue.gif';
                 $alt = 'Download this file for comparison with backup file.';
                 $ttl = 'Download this file for comparison with backup file.';
                 $href = "filediff/download.php?file=$file_name&server=$ftp_server";
       }else{
                 $img = 'images/button_cancel.png';
                 $alt = 'Remote server returned an error. I am unable to download this file.';
                 $ttl = 'Remote server returned an error. I am unable to download this file.';
                 $href = "#1";
       }
       
       

       if($status == "Modified"){
         echo '<td style="padding: 1px;">'.$status.'<a href="'.$href.'" /><img title="'.$ttl.'" alt="'.$alt.'"src="'.$img.'" /></td>';
         echo '<td style="padding: 1px; width: auto;"><img border="0" src="images/spacer.gif" width="3" height="0">'.$file_name.'</td>';
       }else{
         echo '<td style="padding: 4px;">'.$status.'</td>';
         echo '<td style="padding: 4px; width: auto;">'.$file_name.'</td>';
       }
       echo '<td style="padding: 4px; width: auto;">'.$file_date.'</td>';
       echo '<td style="padding: 4px; width: 110px;">'.$file_time.'</td>';
       echo '<td style="padding: 4px; width: auto;">'.$old_perms.'</td>';
       echo '<td style="padding: 4px; width: auto;">'.$new_perms.'</td>';
       echo '<td style="padding: 4px; width: 110px;">'.$old_size.'</td>';
       echo '<td style="padding: 4px; width: auto;">'.$new_size.'</td>';
       echo '<td style="padding: 4px; width: auto;">'.$last_run.'</td></tr>';
}
echo '</div></table>';


// Show page-load time.
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);

function simple_prg($start_prg = false, $request_uri = null) {
    // check to see if we should start prg
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $uniqid = uniqid();
        $_SESSION['post'][$uniqid] = $_POST;
        if (!$request_uri) {
            $request_uri = 'REQUEST_URI';
        }

        header("HTTP/1.1 303 See Other");

        $header = "Location: " . $_SERVER[$request_uri] . '?prg=1&uniqid=' . $uniqid;
        header($header);
        die;
    }

    if ($start_prg) {
        // on start we clean all session posts
        @$_SESSION['post'] = '';
    } else {
        if (isset($_GET['prg'])) {
            $uniqid = $_GET['uniqid'];
            $_POST = @$_SESSION['post'][$uniqid];
        }
    }
    return $uniqid;
}

function Select($logs_dir, $name, $options = array() ) {
global $ftp_server;

    $html = '<select class="dropdown" name="'.$name.'" onchange="location.href=\'index.php?load_start_file=N&server=\'+this.value">';
    $html .= '<option selected>'.$ftp_server.'</option>';

    foreach ($options as $option =>$value) {
        if ($value->isDir()) {
            $html .= '<option value='.str_replace('/',"",stripslashes(str_replace($logs_dir,"",$value))). '>' .str_replace('/',"",stripslashes(str_replace($logs_dir,"",$option))). '</option>';
            $value->getRealpath() . '<br />';
        }
    }
    $html .= '</select>';
    return  $html;
}


function is_removeable($dir) {
    $folder = opendir($dir);

    while ($file = readdir($folder))
        if ($file != '.' && $file != '..' &&
                (!is_writable($dir . "/" . $file) ||
                ( is_dir($dir . "/" . $file) && !is_removeable($dir . "/" . $file) ) )) {
            closedir($folder);
            return false;
        }
    closedir($folder);
    return true;
}

function displayString($log) {
    $string = '';
    foreach ($log as $val) {
        $string .= $val . "\r\n";
    }
    return $string;
}

function refresh_logview() {
    $log_contents = array();
    if (file_exists($logs_dir . '/ssa_output.txt')) {
        $log_contents = file($logs_dir . '/ssa_output.txt'); // Parse the contents of ssa_output.txt into an array
    }
    $view_log = displayString($log_contents);
}

function isit_dir($dir){
 if($dir != '.' && $dir != '..'){
    $count = (count(glob("$dir/*",GLOB_ONLYDIR)));
    return $count;
 }
}

function store_details($db_server, $db_user, $db_pass, $db_name, $ftp_server, $subject, $skipfile, $skipdir, $alert, $from, $message, $createLog, $cronlogpath){

$date = date ("dMy");
$time = date("H:i");

    $site_table = 'ssa_'.stripslashes(str_replace('-','_',str_replace('.','_',$ftp_server))).'_site';
    $con = mysql_connect($db_server,$db_user,$db_pass)or die('MySql ERROR1! '.mysql_error());
    mysql_select_db($db_name, $con)or die('MySql ERROR2! '.mysql_error());
    $query = "TRUNCATE TABLE $site_table";
    mysql_query($query)or die('MySql ERROR3! '.mysql_error());
    $query ="INSERT INTO $site_table (
        email_subj,
        email_alert,        
        skip_files,
        skip_dir,
        from_addr,
        email_header,
        cron_path,
        SSA_log,
        date,
        time
       )
    VALUES (
        '$subject',
        '$alert',        
        '$skipfile',
        '$skipdir',
        '$from',        
        '$message',
        '$cronlogpath',
        '$createLog',
        '$date',
        '$time')";

    mysql_query($query)or die('MySql ERROR4! '.mysql_error());
    mysql_close($con)or die(mysql_error());
}

function is_table_empty($table_name,$db_server,$db_user,$db_pass,$db_name){
    
    $con = mysql_connect($db_server,$db_user,$db_pass)or die('no conn: '.mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());
    
    $x = "SELECT COUNT(*) FROM $table_name"; 
    $result = mysql_query($x) or die(mysql_error()); 
    $total_rows = mysql_fetch_row($result);
    //mysql_close($con)or die(mysql_error()); 
    return $total_rows[0];    
}
?>
Return current item: SimpleSiteAudit