function others_update() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { build_progress_influx("Already executed", 110); WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); return; } if (!$GLOBALS["FORCE"]) { $TimeCache = $unix->file_time_min($cachetime); if ($TimeCache < 30) { build_progress_influx("Need at least 30Mn ( current {$TimeCache}mn ) ", 110); return; } } $TimeFile = $unix->file_time_min("/etc/artica-postfix/settings/Daemons/ArticaTechNetInfluxRepo"); $tmpfile = $unix->TEMP_DIR() . "/squid.update.db"; if ($GLOBALS["VERBOSE"]) { $TimeFile = 10000; } if (!$GLOBALS["FORCE"]) { if ($TimeFile < 480) { whatsnew(); return; } } $sock = new sockets(); build_progress_influx("{check_repository} (BigData Engine)", 20); $curl = new ccurl("http://articatech.net/influx.php"); if (!$curl->GetFile($tmpfile)) { build_progress_influx("{check_repository} {failed}", 20); echo $curl->error . "\n"; @unlink($tmpfile); squid_admin_mysql(1, "Unable to retreive BigData Engine available versions", $curl->error, __FILE__, __LINE__); } $DATA = @file_get_contents($tmpfile); $ARRAY = unserialize(base64_decode($DATA)); if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } if (count($ARRAY) > 0) { build_progress_influx("{check_repository} (BigData Engine) {success}", 25); @unlink("/etc/artica-postfix/settings/Daemons/ArticaTechNetInfluxRepo"); @copy("{$tmpfile}", "/etc/artica-postfix/settings/Daemons/ArticaTechNetInfluxRepo"); @chmod("/etc/artica-postfix/settings/Daemons/ArticaTechNetInfluxRepo", 0755); build_progress_influx("{check_repository} {success}", 100); } else { echo "**** NOT AN ARRAY ****\n"; build_progress_influx("{check_repository} {failed}", 20); } @unlink($tmpfile); build_progress_influx("{check_repository} (Suricata)", 30); $curl = new ccurl("http://articatech.net/suricata.php"); if (!$curl->GetFile($tmpfile)) { build_progress_influx("{check_repository} (Suricata) {failed}", 110); echo $curl->error . "\n"; @unlink($tmpfile); system_admin_mysql(1, "Unable to retreive Suricata available versions", $curl->error, __FILE__, __LINE__); squid_admin_mysql(1, "Unable to retreive Suricata available versions", $curl->error, __FILE__, __LINE__); } $DATA = @file_get_contents($tmpfile); $ARRAY = unserialize(base64_decode($DATA)); if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } if (count($ARRAY) > 0) { build_progress_influx("{check_repository} (Suricata) {success}", 35); @unlink("/etc/artica-postfix/settings/Daemons/ArticaTechNetSuricataRepo"); @copy("{$tmpfile}", "/etc/artica-postfix/settings/Daemons/ArticaTechNetSuricataRepo"); @chmod("/etc/artica-postfix/settings/Daemons/ArticaTechNetSuricataRepo", 0755); build_progress_influx("{check_repository} (Suricata) {success}", 40); } else { echo "**** NOT AN ARRAY ****\n"; build_progress_influx("{check_repository} (Suricata) {failed}", 35); } //------------------------------------------------------------------------------------------------------- @unlink($tmpfile); build_progress_influx("{check_repository} (HaProxy)", 40); $curl = new ccurl("http://articatech.net/haproxy.php"); if (!$curl->GetFile($tmpfile)) { build_progress_influx("{check_repository} (HaProxy) {failed}", 40); echo $curl->error . "\n"; @unlink($tmpfile); system_admin_mysql(1, "Unable to retreive HaProxy available versions", $curl->error, __FILE__, __LINE__); squid_admin_mysql(1, "Unable to retreive HaProxy available versions", $curl->error, __FILE__, __LINE__); } $DATA = @file_get_contents($tmpfile); $ARRAY = unserialize(base64_decode($DATA)); if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } if (count($ARRAY) > 0) { build_progress_influx("{check_repository} (HaProxy) {success}", 45); @unlink("/etc/artica-postfix/settings/Daemons/ArticaTechNetHaProxyRepo"); @copy("{$tmpfile}", "/etc/artica-postfix/settings/Daemons/ArticaTechNetHaProxyRepo"); @chmod("/etc/artica-postfix/settings/Daemons/ArticaTechNetHaProxyRepo", 0755); } else { echo "**** NOT AN ARRAY ****\n"; build_progress_influx("{check_repository} (HaProxy) {failed}", 45); } //------------------------------------------------------------------------------------------------------- @unlink($tmpfile); build_progress_influx("{check_repository} (ProFTPD)", 50); $curl = new ccurl("http://articatech.net/proftpd.php"); if (!$curl->GetFile($tmpfile)) { build_progress_influx("{check_repository} (ProFTPD) {failed}", 55); echo $curl->error . "\n"; @unlink($tmpfile); system_admin_mysql(1, "Unable to retreive ProFTPD available versions", $curl->error, __FILE__, __LINE__); squid_admin_mysql(1, "Unable to retreive ProFTPD available versions", $curl->error, __FILE__, __LINE__); } $DATA = @file_get_contents($tmpfile); $ARRAY = unserialize(base64_decode($DATA)); if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } if (count($ARRAY) > 0) { build_progress_influx("{check_repository} (ProFTPD) {success}", 55); @unlink("/etc/artica-postfix/settings/Daemons/ArticaTechNetProFTPDRepo"); @copy("{$tmpfile}", "/etc/artica-postfix/settings/Daemons/ArticaTechNetProFTPDRepo"); @chmod("/etc/artica-postfix/settings/Daemons/ArticaTechNetProFTPDRepo", 0755); } else { echo "**** NOT AN ARRAY ****\n"; build_progress_influx("{check_repository} (ProFTPD) {failed}", 55); } //------------------------------------------------------------------------------------------------------- build_progress_influx("{check_repository} (MailSecurity)", 50); $curl = new ccurl("http://articatech.net/mailsecurity.php"); if (!$curl->GetFile($tmpfile)) { build_progress_influx("{check_repository} (MailSecurity) {failed}", 55); echo $curl->error . "\n"; @unlink($tmpfile); system_admin_mysql(1, "Unable to retreive MailSecurity available versions", $curl->error, __FILE__, __LINE__); squid_admin_mysql(1, "Unable to retreive MailSecurity available versions", $curl->error, __FILE__, __LINE__); } $DATA = @file_get_contents($tmpfile); $ARRAY = unserialize(base64_decode($DATA)); if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } if (count($ARRAY) > 0) { build_progress_influx("{check_repository} (MailSecurity) {success}", 55); @unlink("/etc/artica-postfix/settings/Daemons/ArticaTechNetMailSecurityRepo"); @copy("{$tmpfile}", "/etc/artica-postfix/settings/Daemons/ArticaTechNetMailSecurityRepo"); @chmod("/etc/artica-postfix/settings/Daemons/ArticaTechNetMailSecurityRepo", 0755); } else { echo "**** NOT AN ARRAY ****\n"; build_progress_influx("{check_repository} (MailSecurity) {failed}", 55); } //------------------------------------------------------------------------------------------------------- build_progress_influx("{check_repository} Whatsnew", 80); whatsnew(); build_progress_influx("{check_repository} {done}", 100); }
function start() { $unix = new unix(); $unix->ToSyslog("[START_STOP]: Server is started..."); squid_admin_mysql(0, "Server is is started!", "This a notification that notice a system start procedure on the server", __FILE__, __LINE__); $sock = new sockets(); system_admin_mysql(0, "Server is started!", "This a notification that notice a system start procedure on the server", __FILE__, __LINE__); }
function notify_updated() { sigtool(); $bases = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/interface-cache/ClamAVBases")); while (list($db, $MAIN) = each($bases)) { $DBS[] = $db; $DBS[] = "-------------------------------"; $DBS[] = "date: {$MAIN["zDate"]}"; $DBS[] = "version: {$MAIN["version"]}"; $DBS[] = "signatures: {$MAIN["signatures"]}"; $DBS[] = ""; } system_admin_mysql(2, "ClamAV pattern databases updated", @implode("\n", $DBS)); }
function rotate() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); system_admin_mysql(1, "Bandwidthd rotation already executed since {$time}mn", null, __FILE__, __LINE__); return; } @file_put_contents($pidfile, getmypid()); $sock = new sockets(); $mv = $unix->find_program("mv"); $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir"); if ($BackupMaxDaysDir == null) { $BackupMaxDaysDir = "/home/logrotate_backup"; } $f[] = "/usr/bandwidthd/log.1.0.cdf"; $f[] = "/usr/bandwidthd/log.1.1.cdf"; $f[] = "/usr/bandwidthd/log.1.2.cdf"; $f[] = "/usr/bandwidthd/log.1.3.cdf"; $f[] = "/usr/bandwidthd/log.2.0.cdf"; $f[] = "/usr/bandwidthd/log.2.1.cdf"; $f[] = "/usr/bandwidthd/log.3.0.cdf"; $DESTS = array(); while (list($index, $fileSource) = each($f)) { $destination = "{$fileSource}." . time() . "log"; $DESTS[] = $destination; shell_exec("{$mv} {$fileSource} {$destination}"); } system_admin_mysql(2, "Restart bandwidthd in order to rotate events", null, __FILE__, __LINE__); shell_exec("/etc/init.d/bandwidthd restart"); reset($f); while (list($index, $fileSource) = each($DESTS)) { $basename = basename($fileSource); $rotated_source = $fileSource; if (!$unix->compress($rotated_source, "{$BackupMaxDaysDir}/{$basename}.gz")) { continue; } } }
function ScanMainDirs() { $unix = new unix(); $clamscan = $unix->find_program("clamscan"); if (!is_file($clamscan)) { system_admin_mysql(1, "Unable to find ClamScan for periodic scan!", null, __FILE__, __LINE__); die; } $php = $unix->LOCATE_PHP5_BIN(); echo "Running updates...\n"; system("{$php} /usr/share/artica-postfix/exec.freshclam.php --exec --force"); $dirs[] = "/bin"; $dirs[] = "/sbin"; $dirs[] = "/lib"; $dirs[] = "/usr/sbin"; $dirs[] = "/usr/bin"; $dirs[] = "/usr/local/bin"; $dirs[] = "/usr/local/sbin"; $dirs[] = "/lib/x86_64-linux-gnu"; $dirs[] = "/usr/local/lib"; $dirs[] = "/etc/init.d"; $dirs[] = "/etc/rc0.d"; $dirs[] = "/etc/rc1.d"; $dirs[] = "/etc/rc2.d"; $dirs[] = "/etc/rc3.d"; $dirs[] = "/etc/rc4.d"; $dirs[] = "/etc/rc5.d"; $dirs[] = "/lib"; $dirs[] = "/lib32"; $dirs[] = "/lib64"; $dirs[] = "/tmp"; $WARNS = array(); while (list($num, $directory) = each($dirs)) { if (!is_dir($directory)) { continue; } $results = array(); echo "Scanning {$directory}\n"; exec("{$clamscan} --infected --suppress-ok-results --stdout {$directory} 2>&1", $results); while (list($a, $lin) = each($results)) { $lin = trim($lin); if ($lin == null) { continue; } if (!preg_match("#(.+?):\\s+(.+?)\\s+FOUND#", $lin, $re)) { continue; } $filepath = $re[1]; $next_file = str_replace("/", "-", $filepath); @mkdir("/home/artica/.infected", 0755, true); $nextfile = "/home/artica/.infected/{$next_file}"; if (is_file($nextfile)) { $nextfile = "{$nextfile}." . time(); } @copy($filepath, $nextfile); @unlink($filepath); $lineErr = "Found Virus {$re[2]} in {$filepath} ( moved to {$nextfile})"; echo "{$lineErr}\n"; $WARNS[] = $lineErr; } } if (count($WARNS) > 0) { system_admin_mysql(0, "Warning found " . count($WARNS) . " malwares on system", @implode("\n", $WARNS), __FILE__, __LINE__); squid_admin_mysql(0, "Warning found " . count($WARNS) . " malwares on system", @implode("\n", $WARNS), __FILE__, __LINE__); } }
function UpdateUtility() { if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: " . __FUNCTION__ . "\n"; } $unix = new unix(); $sock = new sockets(); $unix = new unix(); $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid"; $pidtime = "/etc/artica-postfix/" . basename(__FILE__) . ".time"; $pidtimeT = $unix->file_time_min($pidtime); if ($pidtimeT < 3) { if (!$GLOBALS["FORCE"]) { if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: last execution time {$pidtimeT} (require 3mn) or set --force " . __FUNCTION__ . "\n"; } die; } } $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $ProcessTime = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: Process {$pid} already in memory since {$ProcessTime} minutes - " . __FUNCTION__ . "\n"; } system_admin_mysql(1, "Process {$pid} already in memory since {$ProcessTime} minutes", __FILE__, __LINE__, "updateutility"); die; } @unlink($pidtime); @file_put_contents($pidtime, time()); @file_put_contents($pidfile, getmypid()); $pid = $unix->PIDOF_PATTERN("UpdateUtility-Console"); if ($unix->process_exists($pid, basename(__FILE__))) { $ProcessTime = $unix->PROCCESS_TIME_MIN($pid); system_admin_mysql(1, "Process {$pid} already in memory since {$ProcessTime} minutes", __FILE__, __LINE__, "updateutility"); die; } $UpdateUtility_Console = "/etc/UpdateUtility/UpdateUtility-Console"; if (!is_file($UpdateUtility_Console)) { if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: UpdateUtility-Console no such binary - " . __FUNCTION__ . "\n"; } system_admin_mysql(0, "UpdateUtility-Console no such binary", __FILE__, __LINE__, "update"); return; } if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: UpdateUtility_Console - {$UpdateUtility_Console}" . __FUNCTION__ . "\n"; } $UpdateUtilityAllProducts = $sock->GET_INFO("UpdateUtilityAllProducts"); $UpdateUtilityOnlyForKav4Proxy = $sock->GET_INFO("UpdateUtilityOnlyForKav4Proxy"); $UpdateUtilityUseLoop = $sock->GET_INFO("UpdateUtilityUseLoop"); if (!is_numeric($UpdateUtilityAllProducts)) { $UpdateUtilityAllProducts = 1; } $UpdateUtilityStorePath = $sock->GET_INFO("UpdateUtilityStorePath"); if ($UpdateUtilityStorePath == null) { $UpdateUtilityStorePath = "/home/kaspersky/UpdateUtility"; } $UpdateUtilityUpdatesType = intval($sock->GET_INFO("UpdateUtilityUpdatesType")); if (is_file("/opt/kaspersky/kav4proxy/sbin/kav4proxy-kavicapserver")) { if (!is_numeric($UpdateUtilityOnlyForKav4Proxy)) { $UpdateUtilityOnlyForKav4Proxy = 1; } } if ($UpdateUtilityUseLoop == 1) { $UpdateUtilityStorePath = "/automounts/UpdateUtility"; $dev = $unix->MOUNTED_DIR($UpdateUtilityStorePath); if ($dev == null) { if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: {$UpdateUtilityStorePath} -> NOT MOUNTED " . __FUNCTION__ . "\n"; } @file_put_contents("/var/log/artica-postfix/UpdateUtility-report-" . time() . ".log", "Report finished at " . date("Y-m-d H:i:s") . "\n{$UpdateUtilityStorePath} not mounted!\n"); return; } if ($GLOBALS["VERBOSE"]) { echo "Line: " . __LINE__ . ":: {$UpdateUtilityStorePath} -> {$dev} OK" . __FUNCTION__ . "\n"; } } @mkdir("{$UpdateUtilityStorePath}/databases/Updates", 0755, true); if (!is_dir($UpdateUtilityStorePath)) { @file_put_contents("/var/log/artica-postfix/UpdateUtility-report-" . time() . ".log", "Report finished at " . date("Y-m-d H:i:s") . "\n{$UpdateUtilityStorePath}/databases/Updates permission denied!\n"); return; } $f[] = "[ConnectionSettings]"; $f[] = "TimeoutConnection=60"; $f[] = "UsePassiveFtpMode=true"; $datas = $sock->GET_INFO("ArticaProxySettings"); if (trim($datas) != null) { $ini2 = new Bs_IniHandler(); $ini2->loadString($datas); $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername = trim($ini->_params["PROXY"]["ArticaProxyServerUsername"]); $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; if (is_numeric($ArticaProxyServerEnabled)) { if ($ArticaProxyServerEnabled == 1) { $ArticaProxyServerEnabled = "yes"; } } if ($ArticaProxyServerEnabled == "yes") { $f[] = "UseProxyServer=true"; $f[] = "ByPassProxyServer=false"; $f[] = "AddressProxyServer={$ArticaProxyServerName}"; $f[] = "PortProxyServer={$ArticaProxyServerPort}"; if ($ArticaProxyServerUsername != null) { $f[] = "UseAuthenticationProxyServer=true"; $f[] = "UserNameProxyServer={$ArticaProxyServerUsername}"; $f[] = "PasswordProxyServer={$ArticaProxyServerUserPassword}"; } } else { $f[] = "UseProxyServer=false"; $f[] = "ByPassProxyServer=true"; } } @mkdir("{$UpdateUtilityStorePath}/databases", 0755, true); @mkdir("{$UpdateUtilityStorePath}/TempFolder", 0755, true); $t = time(); $report_file = "/var/log/artica-postfix/UpdateUtility-report-" . time() . ".log"; $f[] = "AutomaticallyDetectProxyServerSettings=true"; $f[] = "UseSpecifiedProxyServerSettings=false"; $f[] = "DownloadPatches=true"; $f[] = ""; $f[] = "[AdditionalSettings]"; $f[] = "CreateCrashDumpFile=false"; $f[] = "TurnTrace=false"; $f[] = "AddIconToTray=false"; $f[] = "MinimizeProgramUponTermination=true"; $f[] = "AnimateIcon=true"; $f[] = "ReturnCodeDesc="; $f[] = ""; $f[] = "[ReportSettings]"; $f[] = "DisplayReportsOnScreen=false"; $f[] = "SaveReportsToFile=true"; $f[] = "AppendToPreviousFile=false"; $f[] = "SizeLogFileValue=1048576"; $f[] = "ReportFileName={$report_file}"; $f[] = "DeleteIfSize=true"; $f[] = "DeleteIfNumDay=false"; $f[] = "NoChangeLogFile=false"; $f[] = "NumDayLifeLOgFileValue=7"; $f[] = ""; $f[] = "[DirectoriesSettings]"; $f[] = "MoveToCurrentFolder=false"; $f[] = "MoveToCustomFolder=true"; $f[] = "UpdatesFolder={$UpdateUtilityStorePath}/database"; $f[] = "TempFolder={$UpdateUtilityStorePath}/TempFolder"; $f[] = "ClearTempFolder=true"; $f[] = ""; $f[] = "[UpdatesSourceSettings]"; $f[] = "SourceCustomPath="; $f[] = "SourceCustom=false"; $f[] = "SourceKlabServer=true"; $f[] = ""; $f[] = "[DownloadingSettings]"; $f[] = "DownloadDataBasesAndModules=true"; $f[] = ""; if ($UpdateUtilityUpdatesType == 0) { $f[] = UpdateUtility_security_center(); } if ($UpdateUtilityUpdatesType == 1) { $f[] = UpdateUtility_systems(); } if ($UpdateUtilityUpdatesType == 2) { $f[] = UpdateUtility_servers(); } if ($UpdateUtilityUpdatesType == 3) { $f[] = UpdateUtility_gateways(); } if ($UpdateUtilityUpdatesType == 4) { $f[] = UpdateUtility_alls(); } $f[] = ""; $f[] = "[ShedulerSettings]"; $f[] = "LastUpdate=@Variant(ÿÿÿÿÿ)"; $f[] = "ShedulerType=0"; $f[] = "PeriodValue=1"; $f[] = "UseTime=true"; $f[] = "Time=@Variant()"; $f[] = "Monday=true"; $f[] = "Tuesday=true"; $f[] = "Wednesday=true"; $f[] = "Thursday=true"; $f[] = "Friday=true"; $f[] = "Saturday=true"; $f[] = "Sunday=true"; $f[] = ""; $f[] = "[SdkSettings]"; $f[] = "PrimaryIndexFileName=u0607g.xml"; $f[] = "PrimaryIndexRelativeUrlPath=index"; $f[] = "LicensePath="; $f[] = "SimpleModeLicensing=true"; $cgcreate = $unix->find_program("cgcreate"); if (is_file($cgcreate)) { $UpdateUtilityCpuShares = intval($sock->GET_INFO("UpdateUtilityCpuShares")); $UpdateUtilityDiskIO = intval($sock->GET_INFO("UpdateUtilityDiskIO")); if ($UpdateUtilityCpuShares == 0) { $UpdateUtilityCpuShares = 256; } if ($UpdateUtilityDiskIO == 0) { $UpdateUtilityDiskIO = 450; } $unix->CGROUPS_limit_service_structure("kasupt", $UpdateUtilityCpuShares, 0, $UpdateUtilityDiskIO); } $UpdateUtilityPrefix = null; @file_put_contents("/etc/UpdateUtility/updater.ini", @implode("\n", $f)); $f = array(); $SH[] = "#!/bin/sh"; $SH[] = "bindir=`dirname \"\$me\$0\"`"; $SH[] = "libdir=`cd \"\${bindir}/lib\" ; pwd`"; $SH[] = "LD_LIBRARY_PATH=\"\${libdir}:\${LD_LIBRARY_PATH}\""; $SH[] = "export LD_LIBRARY_PATH"; $SH[] = "cd \${bindir}"; if (is_file("/usr/bin/cgexec")) { $UpdateUtilityPrefix = "/usr/bin/cgexec -g cpu,cpuset,blkio:kasupt "; } $SH[] = "{$UpdateUtilityPrefix}./UpdateUtility-Console -u -o /etc/UpdateUtility/updater.ini -r 2>&1\$@"; $SH[] = ""; @file_put_contents("/etc/UpdateUtility/uu-console.sh", @implode("\n", $SH)); $SH = array(); chdir("/etc/UpdateUtility"); @chmod("/etc/UpdateUtility/UpdateUtility-Console", 0755); @chmod("/etc/UpdateUtility/uu-console.sh", 0755); $cmd = "./uu-console.sh 2>&1"; $Restart1 = false; writelogs("Running `{$cmd}`", __FUNCTION__, __FILE__, __LINE__); exec("{$cmd}", $results); while (list($key, $line) = each($results)) { if (preg_match("#Total downloading:\\s+([0-9]+)", $line, $re)) { $PERCT = $re[1]; } if (preg_match("#Segmentation fault#", $line)) { $text = @implode("\n", $results); $Restart1 = true; system_admin_events("Segmentation fault at {$PERCT}% on UpdateUtility restart again...\n{$text}", __FUNCTION__, __FILE__, __LINE__, "update"); $results = array(); break; } writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__); } if ($Restart1) { exec("{$cmd}", $results); while (list($key, $line) = each($results)) { if (preg_match("#Total downloading:\\s+([0-9]+)#", $line, $re)) { $PERCT = $re[1]; } if (preg_match("#Segmentation fault#", $line)) { $text = @implode("\n", $results); system_admin_events("Segmentation fault at {$PERCT}% on UpdateUtility Aborting...\n{$text}", __FUNCTION__, __FILE__, __LINE__, "update"); } writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__); } } $t2 = time(); $timehuman = $unix->distanceOfTimeInWords($t, $t2); $text = @implode("\n", $results); system_admin_events("Executing UpdateUtility Success took {$timehuman}\n{$text}", __FUNCTION__, __FILE__, __LINE__, "update"); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); shell_exec("{$nohup} {$php} " . dirname(__FILE__) . "/exec.freeweb.php --reconfigure-updateutility >/dev/null 2>&1 &"); ScanUpdateUtilityLogs(true); UpdateUtilitySize(true); }
if ($GLOBALS["EnableArticaMetaClient"] == 1) { events("Starting: Dump events each {$GLOBALS["LogFileDaemonMaxEvents"]} rows..."); } $GLOBALS["COUNT_RQS_TIME"] = 0; $GLOBALS["COUNT_RQS"] = 0; $GLOBALS["PURGED"] = 0; $unix = new unix(); $GLOBALS["MYHOSTNAME"] = $unix->hostname_g(); $GLOBALS["iptables"] = $unix->find_program("iptables"); $GLOBALS["nohup"] = $unix->find_program("nohup"); $DCOUNT = 0; $GLOBALS["REQS"] = array(); @file_put_contents($pidfile, getmypid()); load_classifications(); XLOAD_FIREWALL(); system_admin_mysql(2, "Starting Suricata Daemon PID {$GLOBALS["MYPID"]}", null, __FILE__, __LINE__); //$pipe = fopen("php://stdin", "r"); $buffer = null; $pipe = fopen("php://stdin", "r"); while (!feof($pipe)) { $buffer .= fgets($pipe, 4096); try { if ($GLOBALS["VERBOSE"]) { events(" - > `{$buffer}`"); } Parseline($buffer); } catch (Exception $e) { events("Fatal error on buffer {$buffer}"); } $buffer = null; }
function varlog() { $unix = new unix(); $rsync = $unix->find_program("rsync"); $rm = $unix->find_program("rm"); if (!is_file($rsync)) { $unix->DEBIAN_INSTALL_PACKAGE("rsync"); } //$GLOBALS["ArticaMaxLogsSize"]=$ArticaMaxLogsSize; //$GLOBALS["logs_cleaning"]=$sock->GET_NOTIFS("logs_cleaning"); //$GLOBALS["MaxTempLogFilesDay"]=$sock->GET_INFO("MaxTempLogFilesDay"); //if($GLOBALS["MaxTempLogFilesDay"]==null){$GLOBALS["MaxTempLogFilesDay"]=5;} if (!is_numeric($GLOBALS["ArticaMaxLogsSize"])) { init(); } $sock = new sockets(); $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation"); if (!is_numeric($LogsRotateDefaultSizeRotation)) { $LogsRotateDefaultSizeRotation = 100; } $LogsDirectoryStorage = $sock->GET_INFO("LogsDirectoryStorage"); if (trim($LogsDirectoryStorage) == null) { $LogsDirectoryStorage = "/home/logs-backup"; } $echo = $unix->find_program("echo"); $LogRotatePath = $sock->GET_INFO("LogRotatePath"); if ($LogRotatePath == null) { $LogRotatePath = "/home/logrotate"; } $SQUIDEnable = $sock->GET_INFO("SQUIDEnable"); if (!is_numeric($SQUIDEnable)) { $SQUIDEnable = 1; } $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.logon.php"; $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.index.php"; $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.logoff.php"; while (list($index, $filepath) = each($REMOVE_PHP_SCRIPTS)) { if (is_file($filepath)) { @unlink($filepath); } } $RESTART_SQUID = false; $syslog[] = "/var/log/syslog"; $syslog[] = "/var/log/messages"; $syslog[] = "/var/log/daemon.log"; $syslog[] = "/var/log/auth.log"; $syslog[] = "/var/log/kern.log"; $syslog[] = "/var/log/user.log"; $other[] = "/var/log/php.log"; $other[] = "/var/log/artica-postfix/framework.log"; $other[] = "/usr/share/artica-postfix/ressources/logs/php.log"; $other[] = "/var/log/artica-postfix/logrotate.debug"; $other[] = "/var/log/ArticaProc.log"; $other[] = "/var/log/clamav/clamav.log"; $other[] = "/var/log/clamav/clamd.log"; $other[] = "/var/log/clamav/freshclam.log"; $other[] = "/var/log/lighttpd/access.log"; $other[] = "/var/log/lighttpd/apache-access.log"; $other[] = "/var/log/apt/history.log"; $other[] = "/var/log/apt/term.log"; $other[] = "/var/log/redis/redis-server.log"; $other[] = "/var/log/clamav-unofficial-sigs.log"; $other[] = "/var/log/influxdb/influxdb.startup"; $other[] = "/var/log/influxdb/influxd.log"; $other[] = "/var/log/influxdb/influxd.service.log"; if (is_dir("/usr/share/artica-postfix/ressources/ressources")) { shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/ressources"); } if (is_file("/var/log/artica-postfix/squid-logger-start.log")) { shell_exec("{$echo} \"\">/var/log/artica-postfix/squid-logger-start.log"); } if (is_file("/var/log/artica-postfix/exec.syslog-engine.php.log")) { shell_exec("{$echo} \"\">/var/log/artica-postfix/exec.syslog-engine.php.log"); } if (is_file("/var/log/squid/squidtail.log")) { $size = @filesize("/var/log/squid/squidtail.log") / 1024 / 1000; if ($size > $LogsRotateDefaultSizeRotation) { if (@copy("/var/log/squid/squidtail.log", "{$LogRotatePath}/squidtail.log." . time())) { shell_exec("{$echo} \"\">/var/log/squid/squidtail.log"); $RESTART_SYSLOG = true; $RESTART_SQUID = true; } } } if (is_file("/var/log/squid/logfile_daemon.debug")) { $size = @filesize("/var/log/squid/logfile_daemon.debug") / 1024 / 1000; if ($size > $LogsRotateDefaultSizeRotation) { shell_exec("{$echo} \"\">/var/log/squid/logfile_daemon.debug"); $RESTART_SYSLOG = true; } } if (is_file("/var/log/squid/ext_time_quota_acl.log")) { $size = @filesize("/var/log/squid/ext_time_quota_acl.log") / 1024 / 1000; if ($size > $LogsRotateDefaultSizeRotation) { shell_exec("{$echo} \"\">/var/log/squid/ext_time_quota_acl.log"); } } $RESTART_SYSLOG = false; $checks = array(); while (list($index, $filepath) = each($syslog)) { $size = @filesize($filepath) / 1024 / 1000; echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n"; if ($size > $LogsRotateDefaultSizeRotation) { $nextfile = "{$LogsDirectoryStorage}/" . basename($filepath) . "-" . time(); if (!@copy($filepath, $nextfile)) { @unlink($nextfile); continue; } $checks[] = $nextfile; shell_exec("{$echo} \"\" >{$filepath}"); $RESTART_SYSLOG = true; } } if ($RESTART_SQUID) { $squidbin = $unix->LOCATE_SQUID_BIN(); if (is_file($squidbin)) { if ($SQUIDEnable == 1) { $restart_squid_stamp = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __LINE__; if ($unix->file_time_min($restart_squid_stamp) > 240) { system_admin_mysql(1, "Ask to rotate logs after cleaning log files", null, __FILE__, __LINE__); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure"); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k rotate"); @unlink($restart_squid_stamp); @file_put_contents($restart_squid_stamp, time()); } } } } if ($RESTART_SYSLOG) { squid_admin_mysql(1, "Restarting Syslog after a rotation", null, __FILE__, __LINE__); $unix->RESTART_SYSLOG(); } while (list($index, $filepath) = each($other)) { $size = @filesize($filepath) / 1024 / 1000; echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n"; if ($size > 50) { shell_exec("{$echo} \"\" >{$filepath}"); } } $q = new mysql_storelogs(); if ($handle = opendir($LogsDirectoryStorage)) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $filename = "{$LogsDirectoryStorage}/{$fileZ}"; $q->events("Injecting {$filename}", __FUNCTION__, __LINE__); $q->InjectFile($filename, null); } } if ($handle = opendir("/var/log")) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $path = "/var/log/{$filename}"; if (is_dir($path)) { continue; } if (!preg_match("#artica-status\\.log\\.[0-9]+\$#", $fileZ)) { continue; } if ($unix->file_time_min($path) > 1440) { @unlink($path); } } } if ($handle = opendir("/var/log/influxdb")) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $path = "/var/log/influxdb/{$filename}"; if (is_dir($path)) { continue; } if (preg_match("#\\.log\\.[0-9]+\$#", $fileZ)) { @unlink($path); continue; } } } if ($handle = opendir("/var/log/squid")) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $path = "/var/log/squid/{$filename}"; if (is_dir($path)) { continue; } if (preg_match("#ufdbguardd\\.log\\.[0-9]+\$#", $fileZ)) { @unlink($path); continue; } } } $BackupMaxDays = $sock->GET_INFO("BackupMaxDays"); $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir"); $BackupMaxDaysAccess = $sock->GET_INFO("BackupMaxDaysAccess"); if (!is_numeric($BackupMaxDaysAccess)) { $BackupMaxDaysAccess = 365; } $LogRotatePath = $sock->GET_INFO("LogRotatePath"); if (!is_numeric($BackupMaxDays)) { $BackupMaxDays = 30; } $BackupMaxHours = $BackupMaxDays * 24; $BackupMaxMins = $BackupMaxHours * 60; $BackupMaxDaysAccess = $BackupMaxDaysAccess * 24; $BackupMaxDaysAccess = $BackupMaxDaysAccess * 60; if ($BackupMaxDaysDir == null) { $BackupMaxDaysDir = "/home/logrotate_backup"; } if ($LogRotatePath == null) { $LogRotatePath = "/home/logrotate"; } if (is_dir($BackupMaxDaysDir)) { if ($handle = opendir($BackupMaxDaysDir)) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $filename = "{$BackupMaxDaysDir}/{$fileZ}"; $mins = $unix->file_time_min($filename); if (preg_match("#^access\\.#", $filename)) { if ($mins >= $BackupMaxDaysAccess) { $q->events("Removing {$filename} {$mins}>=BackupMaxDaysAccess:{$BackupMaxDaysAccess}", __FUNCTION__, __LINE__); echo "Removing {$filename}\n"; @unlink($filename); } continue; } if ($GLOBALS["VERBOSE"]) { echo "{$filename} = {$mins}Mn\n"; } if ($mins >= $BackupMaxMins) { $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__); echo "Removing {$filename}\n"; @unlink($filename); } $q->events("Injecting {$filename}", __FUNCTION__, __LINE__); $q->InjectFile($filename); } } } if (is_dir($LogRotatePath)) { if ($handle = opendir($LogRotatePath)) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $filename = "{$LogRotatePath}/{$fileZ}"; $mins = $unix->file_time_min($filename); if ($GLOBALS["VERBOSE"]) { echo "{$filename} = {$mins}Mn\n"; } if ($mins >= $BackupMaxMins) { $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__); echo "Removing {$filename}\n"; @unlink($filename); } $q->events("Injecting {$filename}", __FUNCTION__, __LINE__); $q->InjectFile($filename); } } } $LogRotatePath = $LogRotatePath . "/work"; if (is_dir($LogRotatePath)) { if ($handle = opendir($LogRotatePath)) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $filename = "{$LogRotatePath}/{$fileZ}"; $filemd5 = md5_file($filename); if (isset($ARRAYMD[$filemd5])) { @unlink($filename); continue; } $ARRAYMD[$filemd5] = $filename; } } if ($handle = opendir($LogRotatePath)) { while (false !== ($fileZ = readdir($handle))) { if ($fileZ == ".") { continue; } if ($fileZ == "..") { continue; } $filename = "{$LogRotatePath}/{$fileZ}"; $mins = $unix->file_time_min($filename); if ($GLOBALS["VERBOSE"]) { echo "{$filename} = {$mins}Mn\n"; } if (preg_match("#^access\\.#", $filename)) { if ($mins >= $BackupMaxDaysAccess) { echo "Removing {$filename}\n"; $q->events("Removing {$filename} {$mins}>=BackupMaxDaysAccess:{$BackupMaxDaysAccess}", __FUNCTION__, __LINE__); @unlink($filename); continue; } $q->events("Injecting {$filename}", __FUNCTION__, __LINE__); $q->InjectFile($filename); continue; } if ($mins >= $BackupMaxMins) { $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__); echo "Removing {$filename}\n"; @unlink($filename); } $q->events("Injecting {$filename}", __FUNCTION__, __LINE__); $q->InjectFile($filename); } } } }
function purge() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/exec.suricata-fw.php.purge.pid"; $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } if ($unix->process_exists($pid, basename(__FILE__))) { echo "PID: {$pid} Already exists....\n"; die; } @file_put_contents($pidfile, getmypid()); $pidExec = $unix->file_time_min($pidTime); if ($pidExec < 15) { return; } @unlink($pidTime); @file_put_contents($pidTime, time()); $sock = new sockets(); $SuricataFirewallPurges = intval($sock->GET_INFO("SuricataFirewallPurges")); if ($SuricataFirewallPurges == 0) { $SuricataFirewallPurges = 24; } $q = new postgres_sql(); $sql = "SELECT COUNT(*) as tcount FROM suricata_firewall"; $ligne = pg_fetch_assoc($q->QUERY_SQL($sql)); $CountOfRules = intval($ligne["tcount"]); if ($CountOfRules == 0) { echo "No rules...\n"; return; } $time = strtotime("-{$SuricataFirewallPurges} hour"); $date = date("Y-m-d H:i:s", $time); echo "Remove rules before {$date}\n"; $sql = "DELETE FROM suricata_firewall WHERE zdate < '{$date}' "; $q->QUERY_SQL($sql); if (!$q->ok) { system_admin_mysql(0, "Purging MySQL error", $q->mysql_error, __FILE__, __LINE__); return; } $sql = "SELECT COUNT(*) as tcount FROM suricata_firewall"; $ligne = pg_fetch_assoc($q->QUERY_SQL($sql)); $CountOfRules2 = intval($ligne["tcount"]); $removed = $CountOfRules - $CountOfRules2; if ($removed == 0) { return; } system_admin_mysql(1, "Purging {$removed} IDS rules ( added before {$date} ) from firewall", null, __FILE__, __LINE__); xstart(true); shell_exec("/bin/suricata-fw.sh"); }
function philesight() { $pids = array(); $pgrep = $GLOBALS["CLASS_UNIX"]->find_program("pgrep"); $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill"); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . "/" . __LINE__ . "\n"; } exec("{$pgrep} -l -f \"ruby.*?philesight\" 2>&1", $results); while (list($num, $line) = each($results)) { if (preg_match("#pgrep#", $line)) { continue; } if (!preg_match("#^([0-9]+)\\s+#", $line, $re)) { if ($GLOBALS["VERBOSE"]) { echo "No match.. <{$line}>\n"; } } if ($GLOBALS["VERBOSE"]) { echo "match..{$line}\n"; } $pids[$re[1]] = true; } if (count($pids) == 0) { return; } while (list($pid, $line) = each($pids)) { $time = $GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} -> {$time}mn\n"; } if ($time > 30) { system_admin_mysql(1, "Warning killing philesight process {$pid} running since {$time}mn", null, __FILE__, __LINE__); unix_system_kill_force($pid); } } }
function restart_ldap() { $unix = new unix(); $MYPID_FILE = "/etc/artica-postfix/pids/restart_ldap.pid"; $pid = $unix->get_pid_from_file($MYPID_FILE); if (!is_file("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP")) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP", 1); @chmod("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP", 0755); } $EnableOpenLDAP = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP")); if ($unix->process_exists($pid, basename(__FILE__))) { echo "slapd: [INFO] Artica task already running pid {$pid}\n"; restart_ldap_progress("{failed} [" . __LINE__ . "]", 110); die; } $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__) . ".*?--restart", true); if (count($pids) > 0) { while (list($i, $line) = each($pids)) { echo "slapd: [INFO] Artica task already executed PID:{$i}... aborting\n"; } restart_ldap_progress("{failed}", 110); die; } if ($GLOBALS["MONIT"]) { squid_admin_mysql(0, "Monit (Watchdog) Ask to restart OpenLDAP service...", null, __FILE__, __LINE__); system_admin_mysql(0, "Monit (Watchdog) Ask to restart OpenLDAP service...", null, __FILE__, __LINE__); } if (!$GLOBALS["FORCE"]) { $lastexecution = $unix->file_time_min($MYPID_FILE); if ($lastexecution == 0) { $unix->ToSyslog("Restarting the OpenLDAP by `{$GLOBALS["BY_FRAMEWORK"]}` aborted this command must be executed minimal each 1mn", false, basename(__FILE__)); echo "slapd: [INFO] this command must be executed minimal each 1mn\n"; die; } } @unlink($MYPID_FILE); restart_ldap_progress("{build_init_script}", 5); $INITD_PATH = $unix->SLAPD_INITD_PATH(); echo "Script: {$INITD_PATH}\n"; buildscript(); if (!is_file($INITD_PATH)) { restart_ldap_progress("{build_init_script} {failed}", 110); return; } @file_put_contents($MYPID_FILE, getmypid()); $unix->ToSyslog("Restarting the OpenLDAP daemon by `{$GLOBALS["BY_FRAMEWORK"]}`", false, basename(__FILE__)); restart_ldap_progress("{stopping_service}", 10); stop_ldap(true); if ($EnableOpenLDAP == 1) { $php = $unix->LOCATE_PHP5_BIN(); shell_exec("/etc/init.d/monit restart"); restart_ldap_progress("{starting_service}", 40); start_ldap(true); } }
function scan_directories() { $UPDATED = false; if ($GLOBALS["VERBOSE"]) { $GLOBALS["FORCE"] = true; } if ($GLOBALS["FORCE"]) { $UPDATED = true; ini_set('html_errors', 0); ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); } $unix = new unix(); $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $TimeFile = "/etc/artica-postfix/pids/exec.philesight.php.scan_directories.time"; $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { return; } $START_TIME = time(); if (!$GLOBALS["FORCE"]) { $time = $unix->file_time_min($TimeFile); if ($time < 120) { return; } if (system_is_overloaded(__FILE__)) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); if (!is_file("/usr/bin/ruby1.8")) { build_progress("{please_wait}, /usr/bin/ruby1.8 no such binary [installing]...", 5); $unix->DEBIAN_INSTALL_PACKAGE("ruby1.8"); } if (!is_file("/usr/bin/ruby1.8")) { build_progress("{failed}, /usr/bin/ruby1.8 no such binary...", 110); system_admin_events("/usr/bin/ruby1.8 no such binary, philesight cannot be used!", __FUNCTION__, __FILE__, __LINE__); } $sock = new sockets(); $EnableArticaMetaClient = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaClient")); $EnableArticaMetaServer = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaServer")); if ($EnableArticaMetaServer == 1) { $EnableArticaMetaClient = 0; } if ($EnableArticaMetaClient == 1) { meta_events("Meta Client Enabled", __FUNCTION__, __LINE__); } $q = new mysql(); $results = $q->QUERY_SQL("SELECT * FROM philesight WHERE enabled=1", "artica_backup"); @mkdir("/usr/share/artica-postfix/img/philesight", 0755, true); @mkdir("/home/artica/philesight", 0755, true); $NICE = $unix->EXEC_NICE(); build_progress("{please_wait}, {scaning_directories}...", 10); $pr = 10; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $directory = $ligne["directory"]; $partition = $ligne["partition"]; $md5 = md5($directory); $maxtime = $ligne["maxtime"]; if ($maxtime == 0) { continue; } $lastscan = $ligne["lastscan"]; if ($lastscan == 0) { $lastscan = 1000000; } $sql_time_min = sql_time_min($lastscan); $partition = $unix->DIRPART_OF($directory); $hd = $unix->DIRDISK_OF($directory); $ARRAY = $unix->DF_SATUS_K($directory); $USED = $ARRAY["POURC"]; $FREEMB = round($ARRAY["AIVA"] / 1024); $ARRAY_META[$directory]["MD5"] = $md5; $ARRAY_META[$directory]["lastscan"] = $lastscan; $ARRAY_META[$directory]["HD"] = $hd; $ARRAY_META[$directory]["PARTITION"] = $partition; $ARRAY_META[$directory]["USED"] = $USED; $ARRAY_META[$directory]["FREEMB"] = $FREEMB; $directoryXXX = mysql_escape_string2($directory); $sql = "UPDATE `philesight` SET `hd`='{$hd}',\n\t\tpartition='{$partition}',\n\t\thd='{$hd}',\n\t\tUSED='{$USED}',\n\t\tFREEMB='{$FREEMB}'\n\t\tWHERE `directory`='{$directoryXXX}'"; $q->QUERY_SQL($sql, 'artica_backup'); if (is_file("/home/artica/philesight/{$md5}.db")) { if (!$GLOBALS["FORCE"]) { if ($sql_time_min < $maxtime) { continue; } } } $pr++; if ($GLOBALS["FORCE"]) { echo "Partition............: {$partition}\n"; } if ($GLOBALS["FORCE"]) { echo "Hard disk............: {$hd}\n"; } if ($GLOBALS["FORCE"]) { echo "Used.................: {$USED}%\n"; } if ($GLOBALS["FORCE"]) { echo "Free.................: {$FREEMB}MB\n"; } build_progress("{please_wait}, {scaning_directory} {$directory}...", $pr); $UPDATED = true; $cmd = "{$NICE} /usr/share/artica-postfix/bin/philesight --db /home/artica/philesight/{$md5}.db --only-dirs --index \"{$directory}\" 2>&1"; if ($GLOBALS["FORCE"]) { echo "{$cmd}\n"; } system($cmd); if (!is_file("/home/artica/philesight/{$md5}.db")) { if ($GLOBALS["FORCE"]) { echo "/home/artica/philesight/{$md5}.db no such file.\n"; } } build_progress("{please_wait}, Generating report on {$directory}...", $pr); $cmd = "{$NICE} /usr/share/artica-postfix/bin/philesight --db /home/artica/philesight/{$md5}.db --path \"{$directory}\" --draw /usr/share/artica-postfix/img/philesight/{$md5}.png"; if ($GLOBALS["FORCE"]) { echo "{$cmd}\n"; } system($cmd); $directory = mysql_escape_string2($directory); $sql = "UPDATE `philesight` SET `hd`='{$hd}',\n\t\tpartition='{$partition}',\n\t\tlastscan=" . time() . ",\n\t\thd='{$hd}',\n\t\tUSED='{$USED}',\n\t\tFREEMB='{$FREEMB}'\n\t\tWHERE `directory`='{$directory}'"; $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo $q->mysql_error . "\n"; build_progress("{failed}, MySQL error", 110); return; } } build_progress("{success}", 100); $Took = $unix->distanceOfTimeInWords($START_TIME, time()); squid_admin_mysql(2, "{$pr} directories size scanned ( took {$Took}) ", null, __FILE__, __LINE__); system_admin_mysql(2, "{$pr} directories size scanned ( took {$Took}) ", null, __FILE__, __LINE__); if ($EnableArticaMetaClient) { meta_events("UPDATED={$UPDATED}", __FUNCTION__, __LINE__); } if ($UPDATED) { $sock = new sockets(); $EnableArticaMetaClient = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaClient")); $EnableArticaMetaServer = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaServer")); if ($EnableArticaMetaServer == 1) { $EnableArticaMetaClient = 0; } if ($EnableArticaMetaClient == 1) { $cp = $unix->find_program("cp"); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); @mkdir("/home/artica/metaclient/upload/philesight", true, 0755); @file_put_contents("/home/artica/metaclient/upload/philesight/dump.db", serialize($ARRAY_META)); shell_exec("{$cp} -f /usr/share/artica-postfix/img/philesight/* /home/artica/metaclient/upload/philesight/"); @chdir("/home/artica/metaclient/upload/philesight"); system("cd /home/artica/metaclient/upload/philesight"); if (is_file("/home/artica/metaclient/upload/philesight.tgz")) { @unlink("/home/artica/metaclient/upload/philesight.tgz"); } shell_exec("{$tar} -cf /home/artica/metaclient/upload/philesight.tgz *"); shell_exec("{$rm} -rf /home/artica/metaclient/upload/philesight/*"); } } if ($GLOBALS["META_PING"]) { if (is_file("/home/artica/metaclient/upload/philesight.tgz")) { $php = $unix->LOCATE_PHP5_BIN(); system("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &"); } } }