if ($argv[1] == "--sitesinfos") { die; } if ($argv[1] == "--groupby") { die; } if ($argv[1] == "--import") { import(); die; } if ($argv[1] == "--export") { export(true); die; } if ($argv[1] == "--export-deleted") { export_deleted_categories(true); die; } if ($argv[1] == "--export-weighted") { Export_Weighted(true); die; } if ($argv[1] == "--export-perso-cats") { ExportPersonalCategories(true); die; } if ($argv[1] == "--export-not-categorized") { ExportNoCategorized(true); die; } if ($argv[1] == "--export-category-tickets") {
exit; } if (isset($_GET["rebuild-filters"])) { rebuild_filters(); exit; } if (isset($_GET["ufdbguardconf"])) { ufdbguardconf(); exit; } if (isset($_GET["export-web-categories"])) { export_web_categories(); exit; } if (isset($_GET["export-deleted-categories"])) { export_deleted_categories(); exit; } if (isset($_GET["ufdbguard-compile-database"])) { ufdbguard_compile_database(); exit; } if (isset($_GET["ufdbguard-compile-alldatabases"])) { ufdbguard_compile_all_databases(); exit; } if (isset($_GET["caches-types"])) { caches_type(); exit; } if (isset($_GET["full-version"])) {
function Export($asPid = false) { $unix = new unix(); $restartProcess = false; $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $restart_cmd = trim("{$nohup} {$php5} " . __FILE__ . " --export >/dev/null 2>&1 &"); if ($asPid) { $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)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); } export_deleted_categories(); $q = new mysql_squid_builder(); $tables = $q->LIST_TABLES_CATEGORIES(); while (list($table, $www) = each($tables)) { $sql = "SELECT COUNT(zmd5) as tcount FROM {$table} WHERE sended=0 and enabled=1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $prefix = "INSERT IGNORE INTO categorize (zmd5 ,pattern,zDate,uuid,category) VALUES"; if ($ligne["tcount"] > 0) { echo "{$table} {$ligne["tcount"]} items to export\n"; $results = $q->QUERY_SQL("SELECT * FROM {$table} WHERE sended=0 and enabled=1"); while ($ligne2 = mysql_fetch_array($results, MYSQL_ASSOC)) { $f[] = "('{$ligne2["zmd5"]}','{$ligne2["pattern"]}','{$ligne2["zDate"]}','{$uuid}','{$ligne2["category"]}')"; $c++; if (count($f) > 1000) { $q->QUERY_SQL($prefix . @implode(",", $f)); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } $f = array(); } } $q->QUERY_SQL("UPDATE {$table} SET sended=1 WHERE sended=0"); } } if (count($f) > 0) { $q->QUERY_SQL($prefix . @implode(",", $f)); $f = array(); } $ALLCOUNT = $q->COUNT_ROWS("categorize"); if ($ALLCOUNT > 4000) { $restartProcess = true; } $sql = "SELECT * FROM categorize ORDER BY zDate DESC LIMIT 0,4000"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error . "\n{$sql}\n"; return; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["category"] == null) { continue; } if ($ligne["pattern"] == null) { continue; } if ($ligne["zmd5"] == null) { continue; } $logsExp[] = "{$ligne["pattern"]}:{$ligne["category"]}"; $array[$ligne["zmd5"]] = array("category" => $ligne["category"], "pattern" => $ligne["pattern"], "uuid" => $ligne["uuid"]); } if (!is_array($array)) { WriteMyLogs("Nothing to export", __FUNCTION__, __FILE__, __LINE__); return; } if (count($array) == 0) { WriteMyLogs("Nothing to export", __FUNCTION__, __FILE__, __LINE__); return; } WriteMyLogs("Exporting " . count($array) . " websites", __FUNCTION__, __FILE__, __LINE__); $f = base64_encode(serialize($array)); $curl = new ccurl("http://www.artica.fr/shalla-orders.php"); $curl->parms["COMMUNITY_POST"] = $f; if (!$curl->get()) { writelogs("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers", __FUNCTION__, __FILE__, __LINE__); $unix->send_email_events("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers", null, "proxy"); writelogs_squid("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers \"{$curl->error}\"", __FUNCTION__, __FILE__, __LINE__, "export"); return null; } if (preg_match("#<ANSWER>OK</ANSWER>#is", $curl->data)) { WriteMyLogs("Exporting success " . count($array) . " websites", __FUNCTION__, __FILE__, __LINE__); if (count($logsExp) < 10) { $textadd = @implode(",", $logsExp); } writelogs_squid("Success exporting " . count($array) . " categorized websites to Artica cloud repository servers", __FUNCTION__, __FILE__, __LINE__, "export"); writelogs("Deleting websites...", __FUNCTION__, __FILE__, __LINE__); while (list($md5, $datas) = each($array)) { $sql = "DELETE FROM categorize WHERE zmd5='{$md5}'"; $q->QUERY_SQL($sql, "artica_backup"); } if ($restartProcess) { writelogs("{$restart_cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($restart_cmd); } else { $q->QUERY_SQL("OPTIMIZE TABLE categorize", "artica_backup"); } } else { writelogs_squid("Failed exporting " . count($array) . " categorized websites to Artica cloud repository servers \"{$curl->data}\"", __FUNCTION__, __FILE__, __LINE__, "export"); } }