function LoadConfig() { WriteMyLogs("Loading PID {$GLOBALS["MYPID"]}", __LINE__); $BaseDir = "/etc/artica-postfix/settings/Daemons"; $GLOBALS["SquidSessionEngineExternalUrl"] = @file_get_contents("{$BaseDir}/SquidSessionEngineExternalUrl"); if ($GLOBALS["SquidSessionEngineExternalUrl"] == null) { WriteMyLogs("SquidSessionEngineExternalUrl is null assume http://www.articatech.net", __LINE__); $GLOBALS["SquidSessionEngineExternalUrl"] = "http://www.articatech.net"; } $GLOBALS["EXTERNAL_HOST"] = uri_to_host($GLOBALS["SquidSessionEngineExternalUrl"]); WriteMyLogs("Config: Whitelisted host:{$GLOBALS["EXTERNAL_HOST"]}", __LINE__); }
function Execute() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $myFile = basename(__FILE__); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, $myFile)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("framework_orders") == 0) { if ($GLOBALS["VERBOSE"]) { echo "Table framework_orders as no row\n"; } die; } $php5 = $unix->LOCATE_PHP5_BIN(); $nice = EXEC_NICE(); $q = new mysql_squid_builder(); $results = $q->QUERY_SQL("SELECT * FROM framework_orders"); if (!$q->ok) { if (strpos($q->mysql_error, "doesn't exist") > 0) { $q->CheckTables(); $results = $q->QUERY_SQL("SELECT * FROM framework_orders"); } } if (!$q->ok) { ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework"); die; } $reconfigure_plugins = false; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($GLOBALS["VERBOSE"]) { echo "ORDER: {$ligne["ORDER"]} -> {$ligne["zmd5"]}\n"; } if (preg_match("#COMPILEDB:(.+)#", $ligne["ORDER"], $re)) { if (preg_match("#english-(.+)#", $re[1])) { $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'"); continue; } ufdbguard_admin_events("LAUNCH: category {$re[1]} compilation", __FUNCTION__, __FILE__, __LINE__, "framework"); $re[1] = trim($re[1]); $table = "category_" . $q->category_transform_name($re[1]); if ($GLOBALS["VERBOSE"]) { echo "order to compile database {$re[1]} (table {$table})\n"; } if (!$q->TABLE_EXISTS($table)) { ufdbguard_admin_events("Fatal: {$table} no suche table, create it", __FUNCTION__, __FILE__, __LINE__, "framework"); $q->CreateCategoryTable(null, $table); } $cmd = "{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --compile-category \"{$re[1]}\""; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'"); if (!$q->ok) { ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework"); die; } shell_exec($cmd); $reconfigure_plugins = true; } } if ($reconfigure_plugins) { ufdbguard_admin_events("LAUNCH: filters reconfiguration", __FUNCTION__, __FILE__, __LINE__, "framework"); shell_exec("{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --build"); } }
function haproxy_errors() { $q = new mysql_haproxy_builder(); $prefixMid = " (sitename,uri,td,http_code,client,hostname,familysite,service,backend,zDate,size,MAC,zMD5,statuslb)"; foreach (glob("{$GLOBALS["ARTICALOGDIR"]}/haproxy-errors/*") as $filename) { $hash = unserialize(@file_get_contents($filename)); while (list($table, $tr) = each($hash)) { if (!$q->create_TableHour($table)) { continue; } $sql = "INSERT IGNORE INTO {$table} {$prefixMid} VALUES " . @implode(",", $tr); $q->QUERY_SQL($sql); if (!$q->ok) { WriteMyLogs($q->mysql_error, __FUNCTION__, __FILE__, __LINE__); continue; } @unlink($filename); if (system_is_overloaded()) { return; } } } }
function WriteCategoriesStatus($force=false){ $unix=new unix(); $cache_file="/usr/share/artica-postfix/ressources/logs/web.community.db.status.txt"; $time=$unix->file_time_min($cache_file); if($GLOBALS["VERBOSE"]){echo "Cache file : $cache_file ({$time}Mn)\n";} if(!$force){ if($time<300){return;} } $sql="SELECT COUNT( zmd5 ) AS tcount, category FROM dansguardian_community_categories WHERE enabled =1 GROUP BY category ORDER BY tcount desc"; $q=new mysql(); $results=$q->QUERY_SQL($sql,"artica_backup"); if(!$q->ok){@unlink($cache_file);return;} if(mysql_numrows($results)==0){@unlink($cache_file);return;} while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){ WriteMyLogs("{$ligne["category"]} = {$ligne["tcount"]}",__FUNCTION__,__FILE__,__LINE__); $array[$ligne["category"]]=$ligne["tcount"]; } @file_put_contents($cache_file,serialize($array)); @chmod($cache_file,"777"); }
function pushit() { $curl = new ccurl("http://www.artica.fr/shalla-orders.php"); $curl->parms["ORDER_EXPORT"] = "yes"; $curl->get(); if (preg_match("#<ANSWER>OK</ANSWER>#is", $curl->data)) { WriteMyLogs("success", __FUNCTION__, __FILE__, __LINE__); } else { WriteMyLogs("failed\n{$curl->data}", __FUNCTION__, __FILE__, __LINE__); } }
$GLOBALS["REBUILD"] = false; $GLOBALS["FORCE"] = false; $GLOBALS["OUTPUT"] = false; $GLOBALS["AS_ROOT"] = true; $GLOBALS["NOCACHES"] = false; $GLOBALS["NOAPPLY"] = false; $GLOBALS["NORELOAD"] = false; $GLOBALS["SMOOTH"] = false; $GLOBALS["RESTART"] = false; $GLOBALS["BY_SCHEDULE"] = false; $GLOBALS["NO_VERIF_CACHES"] = false; $GLOBALS["PROGRESS"] = false; $GLOBALS["EMERGENCY"] = false; CheckSettingsInc(); $GLOBALS["MYCOMMANDS"] = implode(" ", $argv); WriteMyLogs("commands= {$GLOBALS["MYCOMMANDS"]}", "MAIN", __FILE__, __LINE__); if (preg_match("#--smooth#", implode(" ", $argv))) { $GLOBALS["SMOOTH"] = true; } if (preg_match("#--verbose#", implode(" ", $argv))) { $GLOBALS["VERBOSE"] = true; } if (preg_match("#--reload#", implode(" ", $argv))) { $GLOBALS["RELOAD"] = true; } if (preg_match("#--noreload#", implode(" ", $argv))) { $GLOBALS["NORELOAD"] = true; } if (preg_match("#--rebuild#", implode(" ", $argv))) { $GLOBALS["REBUILD"] = true; }
function pushit() { $unix = new unix(); $URIBASE = $unix->MAIN_URI(); $URIBASE = str_replace("articatech.net", "artica.fr", $URIBASE); $curl = new ccurl("{$URIBASE}/shalla-orders.php", false); $curl->parms["ORDER_EXPORT"] = "yes"; $curl->get(); if (preg_match("#<ANSWER>OK</ANSWER>#is", $curl->data)) { WriteMyLogs("success", __FUNCTION__, __FILE__, __LINE__); } else { WriteMyLogs("failed\n{$curl->data}", __FUNCTION__, __FILE__, __LINE__); } }
function importActivedirectoryusers() { $sock = new sockets(); $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 0) { return; } $unix = new unix(); $user = new settings_inc(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { WriteMyLogs("Process {$pid} already exists", __FUNCTION__, __FILE__, __LINE__); return; } if (system_is_overloaded(basename(__FILE__))) { WriteMyLogs("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__); return; } @file_put_contents($pidfile, getmypid()); $TImeStamp = $unix->file_time_min($pidTime); if (!$GLOBALS["FORCE"]) { if ($TImeStamp < 20) { WriteMyLogs("Need 20mn, current={$TImeStamp}Mn executed by:{$GLOBALS["EXECUTOR"]} Params:{$GLOBALS["PARAMS"]}", __FUNCTION__, __FILE__, __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); $netbin = $unix->LOCATE_NET_BIN_PATH(); $usermod = $unix->find_program("usermod"); $chmod = $unix->find_program("chmod"); if (!is_file($netbin)) { WriteMyLogs("net no such binary, aborting", __FUNCTION__, __FILE__, __LINE__); return; } if (is_dir("/var/run/samba/winbindd_privileged")) { shell_exec("{$usermod} -G winbindd_priv squid >/dev/null 2>&1"); shell_exec("{$chmod} 0750 /var/run/samba/winbindd_privileged/ >/dev/null 2>&1"); } $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos"))); $domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]); $domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]); $adminpassword = $array["WINDOWS_SERVER_PASS"]; $adminpassword = $unix->shellEscapeChars($adminpassword); $adminname = $array["WINDOWS_SERVER_ADMIN"]; $ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"]; $GLOBALS["AUTHCMD"] = " -U {$adminname}%{$adminpassword}"; getNetInfos(); if (!isset($GLOBALS["LDAP_HOST"])) { WriteMyLogs("Unable to get ldap infos, aborting", __FUNCTION__, __FILE__, __LINE__); return; } GetUsersArray(); }
function ifMustBeExecuted() { $users = new usersMenus(); $sock = new sockets(); $update = true; $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); $CategoriesRepositoryEnable = $sock->GET_INFO("CategoriesRepositoryEnable"); if (!is_numeric($CategoriesRepositoryEnable)) { $CategoriesRepositoryEnable = 0; } if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if ($EnableRemoteStatisticsAppliance == 1) { WriteMyLogs("EnableRemoteStatisticsAppliance ACTIVE ,ABORTING TASK", __FUNCTION__, __FILE__, __LINE__); die; } if ($EnableWebProxyStatsAppliance == 1) { return true; } $CategoriesRepositoryEnable = $sock->GET_INFO("CategoriesRepositoryEnable"); if ($CategoriesRepositoryEnable == 1) { return true; } if (!$users->SQUID_INSTALLED) { $update = false; } return $update; }
function CheckWatdogCron() { $nice = EXEC_NICE(); $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); if (!is_file("/etc/cron.d/artica-squid-watchdog")) { $f = array(); $f[] = "MAILTO=\"\""; $f[] = "3,6,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,55,57,59 * * * * root {$nice} {$php5} /usr/share/artica-postfix/exec.squid.watchdog.php >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-squid-watchdog", @implode("\n", $f)); WriteMyLogs("Creating Cron task cron.d/artica-squid-watchdog done", __FUNCTION__, __FILE__, __LINE__); } if (!is_file("/etc/cron.d/artica-ping-cloud")) { $f = array(); $f[] = "MAILTO=\"\""; $f[] = "15 0,2,4,6,8,10,12,14,16,18,20,22 * * * * root {$nice} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --bycron >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-ping-cloud", @implode("\n", $f)); WriteMyLogs("Creating Cron task cron.d/artica-ping-cloud done", __FUNCTION__, __FILE__, __LINE__); } }
if ($EnableRemoteStatisticsAppliance == 1) { if ($GLOBALS["VERBOSE"]) { echo "This server is not in charge of statistics... EnableRemoteStatisticsAppliance=1\n"; } die; } if ($squidEnableRemoteStatistics == 1) { events("This server is not in charge of statistics..."); die; } if ($DisableArticaProxyStatistics == 1) { ufdbguard_admin_events("Statistics are disabled in this configuration (DisableArticaProxyStatistics)", "MAIN", __FILE__, __LINE__); die; } if (!ifMustBeExecuted()) { WriteMyLogs("This server is not in charge of statistics", "MAIN", __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "this server is not in charge of statistics (categories repositories or Statistics Appliance) ...\n"; } events("this server is not in charge of statistics (categories repositories or Statistics Appliance) ..."); die; } if ($GLOBALS["VERBOSE"]) { echo "LAUNCH: '{$argv[1]}'\n"; } if ($argv[1] == '--nocat-sync') { not_categorized_day_resync(); exit; } if ($argv[1] == '--repair-hours') { repair_hours(true);
if (trim($BlueCoatKey) == null) { die; } $system_is_overloaded = system_is_overloaded(); if ($system_is_overloaded) { $unix = new unix(); WriteMyLogs("Overloaded system, Web malware maintenance databases tasks aborted (general)", "MAIN", __FILE__, __LINE__); $unix->send_email_events("Overloaded system [{$GLOBALS["SYSTEM_INTERNAL_LOAD"]}], Web filtering maintenance databases tasks aborted (general)", "Artica will wait a new better time...", "proxy"); die; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $myFile = basename(__FILE__); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, $myFile)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } $q = new mysql_squid_builder(); $total1 = $q->COUNT_ROWS("category_malware"); $uri = "http://exposure.iseclab.org/malware_domains.txt"; $targetfile = $unix->FILE_TEMP(); $curl = new ccurl($uri); echo "{$uri}\n"; if (!$curl->GetFile($targetfile)) { echo "Fatal error downloading {$uri}\n"; ufdbguard_admin_events("Fatal: unable to download {$uri}", __FUNCTION__, __FILE__, __LINE__, "update"); exit; } $sock = new sockets(); $uuid = $unix->GetUniqueID();
function communicate() { $unix = new unix(); $sock = new sockets(); $php = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); $GLOBALS["CLASS_SOCKET"] = $sock; $GLOBALS["CLASS_UNIX"] = $unix; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, __FILE__)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Remote stat appliance, Already running pid {$pid}\n"; } if ($time < 10) { WriteMyLogs("Warning: Already running pid {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__); return; } else { unix_system_kill_force($pid); } } $GLOBALS["MYPID"] = getmypid(); WriteMyLogs("New PID: " . getmypid()); @file_put_contents($pidfile, getmypid()); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if ($EnableRemoteStatisticsAppliance == 0) { if ($GLOBALS["VERBOSE"]) { WriteMyLogs("EnableRemoteStatisticsAppliance: {$EnableRemoteStatisticsAppliance} = 0"); echo "EnableRemoteStatisticsAppliance: {$EnableRemoteStatisticsAppliance} = 0\n"; } return; } if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($pidTime); if ($time < 3) { writelogs("Accepted only betwee, 3mn each...", __FUNCTION__, __FILE__, __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); if ($GLOBALS["OUTPUT"]) { echo "Ping the remote appliance...\n"; } $net = new netagent(); WriteMyLogs("->ping()..."); $net->ping(); }
function CoherenceBase() { $unix = new unix(); $myFile = basename(__FILE__); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $unix = new unix(); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, $myFile)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } $q = new mysql_squid_builder(); $unix = new unix(); $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr"); if (!$q->ok) { if (strpos($q->mysql_error, "doesn't exist") > 0) { $q->CheckTables(); $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr"); } } if (!$q->ok) { ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB"); die; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($GLOBALS["VERBOSE"]) { echo "ftpunivtlse1fr: {$ligne["filename"]} -> {$ligne["zmd5"]}\n"; } $ARRAYSUM_LOCALE[$ligne["filename"]] = $ligne["zmd5"]; } $dirs = $unix->dirdir("/var/lib/ftpunivtlse1fr"); while (list($directory, $line) = each($dirs)) { if (!is_file("{$directory}/domains")) { echo "{$directory} has no domains\n"; shell_exec("{$rm} -rf {$directory}"); continue; } $virtualFilename = basename($directory) . ".tar.gz"; if (!isset($ARRAYSUM_LOCALE[$virtualFilename])) { $CountDeSitesFile = CountDeSitesFile("{$directory}/domains"); $md5 = md5($virtualFilename); echo "Add virtual filename {$virtualFilename} with {$CountDeSitesFile} domains"; $q->QUERY_SQL("INSERT INTO ftpunivtlse1fr (`filename`,`zmd5`,`websitesnum`) VALUES ('{$virtualFilename}','{$md5}','{$CountDeSitesFile}')"); } else { if ($GLOBALS["VERBOSE"]) { echo "LOCAL: {$virtualFilename} -> {$directory} OK\n"; } } } }
function start() { $unix = new unix(); $sock = new sockets(); $EnableArticaMirror = intval($sock->GET_INFO("EnableArticaMirror")); if ($EnableArticaMirror == 0) { die; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($GLOBALS["VERBOSE"]) { echo "Time: {$cachetime}\n"; } $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); $cachetimeEx = $unix->file_time_min($cachetime); if (!$GLOBALS["FORCE"]) { if ($cachetimeEx < 25) { return; } } @unlink($cachetime); @file_put_contents($cachetime, time()); $APACHE_USER = $unix->APACHE_SRC_ACCOUNT(); $MyRepo = "/home/www.artica.fr/web/tmpf/auto.update.ini"; $MIRROR = "http://articatech.net"; $REMOTE_URI = "{$MIRROR}/auto.update.php"; $OFFICIAL_DEST = "/home/www.artica.fr/web/download"; $NIGHTLY_DEST = "/home/www.artica.fr/web/nightbuilds"; $TEMP_DIR = $unix->TEMP_DIR(); $MyRepo = "/home/www.artica.fr/web/tmpf/auto.update.ini"; if (!is_file($MyRepo)) { if ($GLOBALS["VERBOSE"]) { echo "{$MyRepo} no such file\n"; } } $ini = new Bs_IniHandler($MyRepo); $LOCAL_OFFICIAL = $ini->_params["NEXT"]["artica"]; $LOCAL_NIGHTLY = $ini->_params["NEXT"]["artica-nightly"]; $tmpfile = $unix->FILE_TEMP(); $curl = new ccurl($REMOTE_URI); if (!$curl->GetFile($tmpfile)) { return; } $ini = new Bs_IniHandler($tmpfile); $REMOTE_OFFICIAL = $ini->_params["NEXT"]["artica"]; $REMOTE_NIGHTLY = $ini->_params["NEXT"]["artica-nightly"]; @unlink($tmpfile); echo "Official {$LOCAL_OFFICIAL}/{$REMOTE_OFFICIAL}\n"; echo "Nightly {$LOCAL_NIGHTLY}/{$REMOTE_NIGHTLY}\n"; if ($LOCAL_OFFICIAL != $REMOTE_OFFICIAL) { $uri = "{$MIRROR}/download/artica-{$REMOTE_OFFICIAL}.tgz"; $ArticaFileTemp = "{$TEMP_DIR}/{$REMOTE_OFFICIAL}.tgz"; echo "Downloading {$uri}\n"; $curl1 = new ccurl($uri); if (!$curl1->GetFile($ArticaFileTemp)) { echo "Failed\n"; return; } @copy($ArticaFileTemp, "{$OFFICIAL_DEST}/artica-{$REMOTE_OFFICIAL}.tgz"); @chown("{$OFFICIAL_DEST}/artica-{$REMOTE_OFFICIAL}.tgz", "{$APACHE_USER}"); @unlink($ArticaFileTemp); @unlink($MyRepo); } if ($LOCAL_NIGHTLY != $REMOTE_NIGHTLY) { $uri = "{$MIRROR}/nightbuilds/artica-{$REMOTE_NIGHTLY}.tgz"; $ArticaFileTemp = "{$TEMP_DIR}/{$REMOTE_NIGHTLY}.tgz"; echo "*******************************************\n"; echo "Downloading {$uri} to {$ArticaFileTemp}\n"; echo "Local: {$NIGHTLY_DEST}/{$REMOTE_NIGHTLY}.tgz\n"; echo "*******************************************\n\n"; $curl2 = new ccurl($uri); if (!$curl2->GetFile($ArticaFileTemp)) { echo "Failed\n"; return; } @copy($ArticaFileTemp, "{$NIGHTLY_DEST}/artica-{$REMOTE_NIGHTLY}.tgz"); @chown("{$NIGHTLY_DEST}/artica-{$REMOTE_NIGHTLY}.tgz", "{$APACHE_USER}"); @unlink($ArticaFileTemp); @unlink($MyRepo); } }
function extractGZ($srcName, $dstName) { $sfp = gzopen($srcName, "rb"); $fp = fopen($dstName, "w"); while ($string = gzread($sfp, 4096)) { fwrite($fp, $string, strlen($string)); } gzclose($sfp); fclose($fp); $size = @filesize($dstName); if ($size > 0) { WriteMyLogs("TASK:{$GLOBALS["SCHEDULE_ID"]} -> extractGZ({$srcName}, {$dstName}) = {$size} bytes OK", __FUNCTION__, __FILE__, __LINE__); return true; } WriteMyLogs("TASK:{$GLOBALS["SCHEDULE_ID"]} -> extractGZ({$srcName}, {$dstName}) = {$size} bytes FAILED", __FUNCTION__, __FILE__, __LINE__); return false; }
function sendtomysql($array) { $q = new mysql(); sumof(); $prefix = "INSERT INTO ipband (`zDate`,`IP_FROM`,`PORT_FROM`,`IP_TO`,`PORT_TO`,`size`,`proto`) VALUES "; if (!$q->TABLE_EXISTS("ipband", "artica_events")) { $q->BuildTables(); } if (!$q->TABLE_EXISTS("ipband", "artica_events")) { WriteMyLogs("ipband no such table", __FUNCTION__, __FILE__, __LINE__, "ipband"); return false; } if (!is_array($array)) { WriteMyLogs("Not an array", __FUNCTION__, __FILE__, __LINE__, "ipband"); return false; } if (count($array) == 0) { WriteMyLogs("No item", __FUNCTION__, __FILE__, __LINE__, "ipband"); return false; } while (list($zdate, $zarray) = each($array)) { $Countzarray = count($zarray); $DF = 0; while (list($index, $Yarray) = each($zarray)) { $DF++; if ($GLOBALS["VERBOSE"]) { echo "{$zdate} {$Yarray["FROM"]} {$Yarray["TO"]}\n"; } $f[] = "('{$zdate}','{$Yarray["FROM"]}','{$Yarray["FROM_PORT"]}','{$Yarray["TO"]}','{$Yarray["TO_PORT"]}','{$Yarray["SIZE"]}','{$Yarray["PROTO"]}')"; WriteMyLogs("{$zdate} {$Yarray["FROM"]} => {$Yarray["TO"]}", __FUNCTION__, __FILE__, __LINE__, "ipband"); if (count($f) > 3000) { $q->QUERY_SQL($prefix . @implode(",", $f), "artica_events"); if (!$q->ok) { system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "ipband"); return false; } $f = array(); } } } system_admin_events(count($f) . " item(s)", __FUNCTION__, __FILE__, __LINE__, "ipband"); if (count($f) > 0) { $q->QUERY_SQL($prefix . @implode(",", $f), "artica_events"); if (!$q->ok) { WriteMyLogs("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "ipband"); return false; } } return true; }
if ($GLOBALS["DEBUG_INCLUDES"]) { echo basename(__FILE__) . "::framework/class.unix.inc\n"; } include_once dirname(__FILE__) . '/framework/class.unix.inc'; if ($GLOBALS["DEBUG_INCLUDES"]) { echo basename(__FILE__) . "::frame.class.inc\n"; } include_once dirname(__FILE__) . '/framework/frame.class.inc'; include_once dirname(__FILE__) . '/ressources/class.mysql.inc'; $GLOBALS["RELOAD"] = false; $GLOBALS["VERBOSE"] = false; $GLOBALS["NO_USE_BIN"] = false; $GLOBALS["REBUILD"] = false; $GLOBALS["FORCE"] = false; $GLOBALS["OUTPUT"] = false; WriteMyLogs("commands= " . implode(" ", $argv), "MAIN", __FILE__, __LINE__); if (preg_match("#--verbose#", implode(" ", $argv))) { $GLOBALS["VERBOSE"] = true; } if (preg_match("#--reload#", implode(" ", $argv))) { $GLOBALS["RELOAD"] = true; } if (preg_match("#--rebuild#", implode(" ", $argv))) { $GLOBALS["REBUILD"] = true; } if (preg_match("#--force#", implode(" ", $argv))) { $GLOBALS["FORCE"] = true; } if (preg_match("#--output#", implode(" ", $argv))) { $GLOBALS["OUTPUT"] = true; }
$results = $GLOBALS["Q"]->QUERY_SQL($sql); $num_rows = mysql_num_rows($results); $CountUpdatedTables = 0; $c = 0; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $category = null; $c++; $category = GetResults2($ligne["sitename"]); if ($category == null) { continue; } $newmd5 = md5("{$category}{$ligne["sitename"]}"); $category_table = "category_" . $GLOBALS["Q"]->category_transform_name("{$category}"); WriteMyLogs("{$c}/{$num_rows}: {$ligne["sitename"]}= {$category} ({$category_table})"); if (!$GLOBALS["Q"]->TABLE_EXISTS("{$category_table}")) { WriteMyLogs("{$c}/{$num_rows}: {$ligne["sitename"]}= {$category_table} no such table"); continue; } $GLOBALS["Q"]->QUERY_SQL("INSERT IGNORE INTO categorize_changes (zmd5,sitename,category) VALUES('{$newmd5}','{$ligne["sitename"]}','{$category}')"); $GLOBALS["Q"]->QUERY_SQL("INSERT IGNORE INTO {$category_table} (zmd5,zDate,category,pattern,uuid) VALUES('{$newmd5}',NOW(),'{$category}','{$ligne["sitename"]}','{$uuid}')"); $sql = "UPDATE visited_sites SET category='{$category}' WHERE sitename='{$ligne["sitename"]}'"; $GLOBALS["Q"]->QUERY_SQL($sql); } function WriteMyLogs($text) { $mem = round(memory_get_usage() / 1024 / 1000, 2); writelogs($text, "non", __FILE__, 0); $logFile = "/var/log/artica-postfix/" . basename(__FILE__) . ".log"; if (!is_dir(dirname($logFile))) { mkdir(dirname($logFile)); }