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

/*
   if( !ini_get('safe_mode') ){
      set_time_limit(30); // 30 secs should cover most sites. This may be your default already.
   }
*/

session_start();
error_reporting (E_ALL ^ E_NOTICE);
$logs_dir = '../../logs';
$ftp_user = "";
$ftp_pass = "";
$site_deleted = $_GET['site_deleted'];
$root_dir = "";

if($_GET['ftp_server']){
    $ftp_server = $_GET['ftp_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 = trim($value);
            $i++;
        }
      }
    }
 } 
     
if ($_POST['submit']){
  if(!file_exists($logs_dir)){
    mkdir($logs_dir,0777,TRUE);
  }
  
$ftp_server = $_POST['ftp_server']; 
$cron_file = '_'.$ftp_server.'.php';
    
    If(!file_exists($cron_file) && $ftp_server != ""){
        $string = '<?php 
        $ftp_server = "'.$ftp_server.'";
        include "ftp_scan.php";
        ?>';   
        $fp = fopen($cron_file, "w") or die('Unable to create cron file');
        fwrite($fp, $string);
        fclose($fp);
    }
    
    $dbsettings = $logs_dir.'/'.$ftp_server.'/db_settings.txt';
    $db_server = $_POST['db_server']; 
    $db_user = $_POST['db_user'];
    $db_pass = $_POST['db_pass'];
    $db_name = $_POST['db_name'];    
    $ftp_user  = $_POST['ftp_user'];
    $ftp_pass   = $_POST['ftp_pass'];
    $root_dir   = $_POST['root_dir'];
    create_db($db_user,$db_server,$db_pass,$db_name,$ftp_server);
 }
 
 if(!$_POST['submit'] && isit_dir($logs_dir) > 0){
    $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);
    }
 }
 
 if(file_exists($dbsettings)){
    $con = mysql_connect($db_server,$db_user,$db_pass)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());    
    $settings_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_settings';
    $result = @mysql_query("SELECT site_URL,FTP_user,FTP_pass,root_dir FROM $settings_table");
}
    
if(is_resource ($result) && !$_POST['submit']){

    while($row = mysql_fetch_array($result))
    {
       $ftp_server = stripslashes($row[site_URL]);
       $ftp_user = $row[FTP_user];
       $ftp_pass = $row[FTP_pass];
       $root_dir = $row[root_dir];
    }    
     mysql_close($con)or die(mysql_error());
   
     if(is_table_empty($settings_table,$db_server,$db_user,$db_pass,$db_name) > 0){
         $key = 'hide@address.com@hide@address.com';
         $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($ftp_pass), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
         $ftp_pass = trim($decrypted);
     }
}
     if($_POST['submit']){
       store_details($db_server, $db_user, $db_pass, $db_name, $dbsettings, $ftp_server, $ftp_user, $ftp_pass, $logs_dir, $root_dir);
     }
  
 
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>';

echo ' 
<script type="text/javascript">
function depopulate(){
    for (i=0;i<document.form.elements.length;i++)
    {
        if (document.form.elements[i].type == "text" || document.form.elements[i].name == "site_list"){
          if (document.form.elements[i].name == "ftp_server" || 
              document.form.elements[i].name == "ftp_user" || 
              document.form.elements[i].name == "ftp_pass" || 
              document.form.elements[i].name == "root_dir" || 
              document.form.elements[i].name == "site_list"){
              document.form.elements[i].value="";
          }
        }
    }
}
</script>

<SCRIPT LANGUAGE="JavaScript">
function respConfirm () {
     var response = confirm(\'Confirm deletion:\');
     if (response) location.href=\'delete_site.php?server='.$ftp_server.'\';
}

</SCRIPT>

<!--[if IE]>
<style>
th, td {
    padding: 15;
    width: 50%;
}
input {
margin: 0;
padding: 1;
width: auto;
overflow: visible;
align: absmiddle;
}
input.text{
width:350px;
}
</style>
<![endif]-->
</head><body>';

echo '<table class="tab1"><tr><td>
  <table class="tab0">
  <tr><td colspan="2">
  <p class="sub2"><font color="brown">SimpleSiteAudit</font> Admin<label> Multisite v1.5.2 </label>';
echo '<img border="0" src="images/spacer.gif" width="275" height="5">
    <input type="button" id="readme" onclick="window.open(\'readme.html\',\'_blank\',\'width=850,height=600\');" style="width: auto; background-color: #ffffff;" name="readme" alt="View the README file" value="README">
    <br />';
echo '<label>STEP 1: Please provide FTP and database details for the sites to be monitored</label>
      <img border="0" src="images/spacer.gif" width="15" height="5"><small> All fields are required</small><label><br />';
echo '<form name="form" method="POST" action="index1.php">';

if(isit_dir($logs_dir) > 0){    
    echo '<br /><label>Number of sites being monitored: '.isit_dir($logs_dir).'  </label>';
    $site_list = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($logs_dir), RecursiveIteratorIterator::SELF_FIRST);
    $html = Select($logs_dir, 'site_list', $site_list);
    echo $html; // Will contain a drop-down list of all sites being monitored
}
echo '</td></tr></td></tr><tr><td>';

echo '<![if !IE]><br /><![endif]><label><b>FTP details </b></label><small>(Remote site)</small>
      <a class="ToolText" onclick="javascript:this.className=\'ToolTextHover\'" onMouseOut="javascript:this.className=\'ToolText\'"><br /><br />     
      <img alt="Click for info" title="Click for info" border="0" src="images/info.png" width="16" height="16">';
echo '<span><b>\'URL of site to be monitored\'</b><br /><br />E.g.  
      <font color="blue">sitetobemonitored.com</font> without http://<br /><br />
      On Windows/IIS servers, you may need to add the prefix: \'ftp.\'</span></a>   
      <img border="0" src="images/spacer.gif" width="10" height="5">        
      <small><font color="red">*</font></small><label>URL of site to be monitored:</label>
      <!--[if IE]>
        <br />
      <![endif]-->
      ';

echo   '<input size="55" type="text" name="ftp_server" id="ftp_server" value="';
echo $ftp_server;
echo '" /><br />';

echo '  <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>\'FTP User Name\'</b><br /><br />This is the user name required for FTP access to the site being monitored.<br /><br />
  On Windows/IIS servers, you may need to experiment with the point at which the ftp user accesses the site, especially where sub-domains are concerned.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>FTP User Name:</label><br />  
  <input size="55" type="text" name="ftp_user" value="';
echo $ftp_user;
echo '" id="ftp_user" /><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>\'FTP password\'</b><br /><br />This is the password required for FTP access to the site being monitored.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><small><font color="red">*</font></small></small><label>FTP password:</label><br />
  <input size="55" type="password" name="ftp_pass" id="ftp_pass" value="';
echo $ftp_pass;
echo '" /><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>\'Directory or sub-domain to be monitored\'</b><br /><br />To monitor a whole web site, enter the name of the site\'s root directory, e.g. <font color="blue">htdocs</font> or <font color="blue">wwwroot</font> etc.
  <br /><br />
  To monitor a sub-domain or sub-directory, this field should be entered as, e.g. <font color="blue">htdocs/sub-dir-name</font> or the <font color="blue">sub-domain-name</font>
  - a sub-directory can be added to the sub-domain-name if required, e.g. <font color="blue">sub-domain-name/sub-dir-name</font>.<br /><br />
  On Windows/IIS servers, this will depend on how your hosting provider sets up your account. Check it out first using your ftp client.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Directory or sub-domain to be monitored:</label><br /> 
  <input size="55" type="text" name="root_dir" value="';
echo $root_dir;
echo '" id="root_dir" />

<td><![if !IE]><img border="0" src="images/spacer.gif" width="1" height="26"><br /><![endif]>
<!--[if IE]><img border="0" src="images/spacer.gif" width="0" height="6"><br /><![endif]-->
<label><b>Database details </b></label><small>(Master site)</small><br /><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>Mysql database server</b><br /><br />This is the name of your database server, usually <font color="blue">localhost</font></span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Mysql database server:</label><br /> 
  <input size="55" type="text" name="db_server" id="db_server" value="';
    echo $db_server;

echo '" id="db_server" /><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>Database user name</b><br /><br />Enter the username for database access. This user must have \'Drop\' privileges</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Database user name:</label><br /> 
  <input size="55" type="text" name="db_user" id="db_user" value="';
    echo $db_user;

echo '" id="db_user" /><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>Database password</b><br /><br />Enter the password for database access</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Database password:</label><br /> 
  <input size="55" type="password" name="db_pass" id="db_pass" value="';
   echo $db_pass;

echo '" id="db_pass" /><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>Database name</b><br /><br />Enter the database name you would like to use for SSAM. If you only have 1 database available, don\'t worry. 
  SSAM will create tables with a prefix consisting of \'ssa_\' and the domain name i.e. \'ssa_domainname_com\' or \'ssa_subdomain_domainname_com\', so there won\'t be any conflicts with existing tables. 
  Just enter the name of the database here.</span></a>
  <img border="0" src="images/spacer.gif" width="10" height="5">
  <small><font color="red">*</font></small><label>Database name:</label><br /> 
  <input size="55" type="text" name="db_name" id="db_name" value="';
echo $db_name;

echo '" id="db_name" /></td><![if !IE]><br /><![endif]>';

echo '<tr><td colspan="2" style="text-align: center;"><![if !IE]><br /><![endif]>
    <input style=" width: auto;" title="Submit to update settings." type="submit" name="submit" value="Submit settings"/>';

if(file_exists($dbsettings)){
  echo '<input style=" width: auto;background-color: #ffffcc" title="Clear the relevent fields to add another site." type="button" name="clear_form" value="Add another site" onclick="depopulate()"/>';
  echo '<input style=" width: auto;background-color: #FFD3DA" title="Click to proceed." type="button" name="step2" value="Finished" onclick="location.href=\'index.php?load_start_file=N\'"/>';
  echo '<img border="0" src="images/spacer.gif" width="270" height="5">';
  echo '<input style=" width: auto;background-color: #B0C4DE" title="Remove this site from the database (This is a 1-click operation)." type="button" name="delete_site" value="Delete this site" onclick="respConfirm ();"/>';
}
    
echo '</form>';
    
echo '<![if !IE]><br /><br /><![endif]><small style="text-align: left">SSAM v1.5.2 | Check for the <a target="_blank" href="http://simplesiteaudit.terryheffernan.net/">latest version</a></small>

<!--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-----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-----END PKCS7-----
">
<center><small>If you think this software is worthy of support, please <a href="#">
<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."></a></center>
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<center><small><a target="_blank" href="http://simplesiteaudit.terryheffernan.net/forum?mingleforumaction=vforum&g=5.0">Feedback</a> would be appreciated. Thank you.</small></center>

</td></td></tr>';

echo '
    <script language="JavaScript" type="text/javascript"
        xml:space="preserve">//<![CDATA[
    var frmvalidator  = new Validator("form");
    frmvalidator.EnableMsgsTogether();
    //frmvalidator.addValidation("ftp_server","alphanumeric","Subdirectories not handled    ");
    frmvalidator.addValidation("ftp_server","req","Need URL of site to be monitored    "); 
    frmvalidator.addValidation("ftp_user","req","Need FTP User Name    ");      
    frmvalidator.addValidation("ftp_pass","req","Need FTP password    ");                 
    frmvalidator.addValidation("root_dir","req","Need document root of site being monitored     ");
    frmvalidator.addValidation("db_server","req","Need Mysql database server    "); 
    frmvalidator.addValidation("db_user","req","Need database user name    ");      
    frmvalidator.addValidation("db_pass","req","Need database password    ");                 
    frmvalidator.addValidation("db_name","req","Need database name    "); 
    //]]></script>';

echo '</td></tr></table>';

echo '<div id="fadeBlock">'; // Responses

echo '<table class="tab3" style="margin-left: 190px;"><tr><td>'; // responses table

if($site_deleted == 1){
    include 'includes/site_deleted.html';
}
// Confirmation response - cleared log file           
if ($_POST['submit'] && file_exists($dbsettings)) {
    include 'includes/confirm.html';
}

echo '</tr></td></table>'; // end responses table
echo '</div>';

echo '</tr></td></table>';

echo '</td></tr></table>
      </td></tr></table>';
echo '</body></html>';

// Functions start here  
function store_details($db_server, $db_user, $db_pass, $db_name, $dbsettings, $ftp_server, $ftp_user, $ftp_pass, $logs_dir, $root_dir) {

    $date = date ("dMy");
    $time = date("H:i");
    $key = 'hide@address.com@hide@address.com';

  if(!file_exists($logs_dir.'/'.$ftp_server)){
     mkdir($logs_dir.'/'.$ftp_server,0777,TRUE);
  }

    $db_settings = fopen($dbsettings, 'w');  
        
        $string = ' '.$db_pass.' '; // note the spaces    
        $db_pass = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
        
    $db_setts = trim($db_server)."\r\n".trim($db_user)."\r\n".trim($db_pass)."\r\n".trim($db_name);
    fwrite($db_settings, $db_setts);
    fclose($db_settings);
    
        $decrypt = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($db_pass), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
        $db_pass = trim($decrypt);    
        $settings_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_server)).'_settings';

    
    $con = mysql_connect($db_server,$db_user,$db_pass)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());
    $query = "TRUNCATE TABLE $settings_table";
    mysql_query($query)or die('MySql ERROR3! '.mysql_error());

        $string = ' '.$ftp_pass.' '; // note the spaces    
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));

    $query ="INSERT INTO $settings_table (
        site_URL,
        FTP_user,
        FTP_pass,
        root_dir,
        root_URL,
        date,
        time
       )
    VALUES (
        '$ftp_server',
        '$ftp_user',
        '$encrypted',
        '$root_dir',
        '$ftp_server',
        '$date',
        '$time')";

    mysql_query($query)or die('Query failed:<br />'.mysql_error());
    mysql_close($con)or die(mysql_error());
}

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

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

function isit_dir($dir){
 if($dir != '.' && $dir != '..'){
    $count = (count(glob("$dir/*",GLOB_ONLYDIR)));
    return $count;
 }
}
                  
function Select($logs_dir, $name, $options = array() ) {
 global $ftp_server;
    $html = '<select class="dropdown" id="'.$name.'" name="'.$name.'" onchange="location.href=\'index1.php?ftp_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_table_empty($table_name,$db_server,$db_user,$db_pass,$db_name){
    
    $con = mysql_connect($db_server,$db_user,$db_pass)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());
    
    $x = "SELECT COUNT(*) FROM $table_name"; 
    $result = mysql_query($x) or die('is_table_empty query1: '.mysql_error()); 
    $total_rows = mysql_fetch_row($result);
    mysql_close($con)or die(mysql_error()); 
    return $total_rows[0];    
}

function create_db($db_user,$db_server,$db_pass,$db_name,$ftp_server){
    $ftp_svr  = str_replace('-','_',str_replace('/','_',$ftp_server));
    $newlist_table  = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_svr)).'_newlist';
    $settings_table = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_svr)).'_settings';
    $log_table      = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_svr)).'_log';
    $site_table     = 'ssa_'.str_replace('-','_',str_replace('.','_',$ftp_svr)).'_site';

    $con = mysql_connect($db_server,$db_user,$db_pass)or die('Unknown MySQL server for host'.$db_server.'<br />
        <a href="index1.php">Click to reload form</a>');
    mysql_query("CREATE DATABASE IF NOT EXISTS $db_name",$con)or die(mysql_error());
    mysql_select_db($db_name, $con)or die(mysql_error());

    // Create table
    $sql = "CREATE TABLE IF NOT EXISTS $newlist_table
    (
    id int NOT NULL AUTO_INCREMENT,
    path varchar(150),
    filename varchar(150),
    size varchar(50),
    date varchar(5),
    time varchar(5),
    perms varchar(10),
    PRIMARY KEY (id)
    )";
    // Execute query
    mysql_query($sql,$con)or die('create_db query2: '.mysql_error());

    $sql = "CREATE TABLE IF NOT EXISTS $settings_table
    (
    id int NOT NULL AUTO_INCREMENT,
    site_URL varchar(150),
    FTP_user varchar(50),
    FTP_pass varchar(50),
    root_dir varchar(150),
    root_URL varchar(150),
    date varchar(7),
    time varchar(5),
    PRIMARY KEY (id)
    )";
    // Execute query
    mysql_query($sql,$con)or die('query2: '.mysql_error());

    $sql = "CREATE TABLE IF NOT EXISTS $site_table
    (
    id int NOT NULL AUTO_INCREMENT,
    email_subj varchar(100),
    email_alert varchar(300),
    skip_files varchar(300),
    skip_dir varchar(300),
    from_addr varchar(150),
    email_header varchar(100),
    cron_path varchar(150),
    SSA_log varchar(1),
    date varchar(7),
    time varchar(5),
    PRIMARY KEY (id)
    )";
    // Execute query
    mysql_query($sql,$con)or die('query3: '.mysql_error());

    $sql = "CREATE TABLE IF NOT EXISTS $log_table
    (
    id int NOT NULL AUTO_INCREMENT,
    status varchar(30),
    file varchar(150),
    date varchar(5),
    time varchar(5),
    old_perms int(4),
    new_perms int(4),
    old_size int(20),
    new_size int(20),
    last_run varchar(20),
    PRIMARY KEY (id)
    )";
    // Execute query
    mysql_query($sql,$con)or die('query4: '.mysql_error());

    mysql_close($con)or die(mysql_error());
}
?>
Return current item: SimpleSiteAudit