private function getDirContents($dir, $class, $func) { $files = scandir($dir); foreach ($files as $key => $value) { $path = realpath($dir . DIRECTORY_SEPARATOR . $value); // do not process virtual directories where path!=basePath if ($this->startsWith($path, $this->basePath)) { if (!is_dir($path)) { $extension = self::getExtension($path); if ($this->shouldProcessFile($extension)) { if ($this->resetNo > 1000) { set_time_limit(60); $this->resetNo = 0; } $this->resetNo += 1; $this->no += 1; $subpath = substr($path, $this->basePathLen); $class->{$func}($this->basePath, $subpath); } } else { if (is_dir($path) && $value != "." && $value != "..") { if ($this->processFolder($path)) { $this->getDirContents($path, $class, $func); } else { Logfile::writeWhen("Folder excluded: " . $path); } } } } else { Logfile::write("Virtual path ignored: " . $path); } } }
function __destruct() { if (file_exists($this->testrunningfile)) { unlink($this->testrunningfile); } if (file_exists($this->testrunningfile)) { Logfile::writeWhen("ERROR: Application file NOT Deleted: " . $this->testrunningfile); } else { Logfile::writeWhen("File deleted: " . $this->testrunningfile); } }
function emailResults($email, $emailinterval, $alreadyRunning) { $mailed = false; $title = "WebMonitor: "; if ($alreadyRunning) { $this->report .= "<h2>ERROR</h2><p>Last scan failed to complete, displaying results from last scan</p>"; $title .= "ERROR: "; } $witherrors = " "; if (Logfile::getNoErrors() > 0) { $witherrors = " (with errors) "; } if ($this->db->getTotals() === 0) { $title .= $witherrors . $this->domain . ' Integrity Report v' . VERSION_NUMBER . " PHP:" . PHP_VERSION; } else { $title .= $this->domain . ' Change Report (' . $this->db->getTotals() . ') v' . VERSION_NUMBER . " PHP:" . PHP_VERSION; } echo $title; $tested = $this->db->getLastRunDate(); $this->report .= "<p>Last tested {$tested}.</p>" . PHP_EOL; $lastemailsent = $this->db->getLastEmailSentRunDate(); $this->report .= "<p>Last email sent {$lastemailsent}.</p>" . PHP_EOL; // E-Mail Results // display discrepancies $send = $this->sendEmail($lastemailsent, $emailinterval, $alreadyRunning); $this->report .= $this->db->summaryReport(); echo $this->report; if ($send) { $headers = "From: admin@" . $this->domain . "\r\n"; $headers .= "Content-type: text/html\r\n"; $mailed = mail($email, $title, $this->report, $headers); if (!$mailed) { Logfile::writeError("Email failed to be sent"); } else { Logfile::writeWhen("Email sent"); } } else { Logfile::writeWhen("Email not required"); } $this->db->recordtestDate($mailed); }
$scan = new Scan($dbconfig, $domain); if ($scan->Connect()) { // check to see if last scan completed correctly if ($alreadyRunning === false) { $scan->scanFiles($path, $skipFolders, $processExtensions, $skipExtensions); } set_time_limit(30); $scan->emailResults($email, $emailinterval, $alreadyRunning); $scan->deleteOldTestedRecords(); $scan = NULL; } else { $text = "Error in running hashscan.php for this domain, consult logfile"; $mailed = mail($email, "WebMonitor: ERROR SCANNING " . $domain, $text); } unset($appStatus); Logfile::writeWhen("Closing Logfile"); Logfile::close(); function formatDateDiff($interval) { $doPlural = function ($nb, $str) { return $nb > 1 ? $str . 's' : $str; }; // adds plurals $format = array(); if ($interval->y !== 0) { $format[] = "%y " . $doPlural($interval->y, "year"); } if ($interval->m !== 0) { $format[] = "%m " . $doPlural($interval->m, "month"); } if ($interval->d !== 0) {
function getLastRunDate() { $tested = ""; $ok = parent::runQuery("SELECT tested FROM tested ORDER BY tested DESC LIMIT 1"); if ($ok) { $result = parent::getResult(); $row = $result->fetch_row(); $tested = $row[0]; } else { Logfile::writeError('Unable to retrieve last test date(' . parent::error()); } Logfile::writeWhen("Last scan date " . $tested); return $tested; }