function artica_meta_client($force = false) { $unix = new unix(); $WORKDIR = "/var/lib/ftpunivtlse1fr"; @mkdir($WORKDIR, 0755, true); @chmod($WORKDIR, 0755); $tmpdir = $unix->TEMP_DIR(); $myVersion = intval(trim(@file_get_contents("/etc/artica-postfix/ftpunivtlse1fr.txt"))); $tmpdir = $unix->TEMP_DIR(); $meta = new artica_meta(); $curl = $meta->buildCurl("/meta-updates/webfiltering/ftpunivtlse1fr.txt"); if (!$curl->GetFile("{$tmpdir}/ftpunivtlse1fr.txt")) { artica_update_event(0, "Failed Downloading webfiltering/ftpunivtlse1fr.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); $meta->events($curl->errors, __FUNCTION__, __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/ftpunivtlse1fr.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); return false; } $Remote_version = intval(trim(@file_get_contents("{$tmpdir}/ftpunivtlse1fr.txt"))); @unlink("{$tmpdir}/ftpunivtlse1fr.txt"); echo "Current............: {$myVersion}\n"; echo "Available..........: {$Remote_version}\n"; $datev = date("Y-m-d H:i:s", $myVersion); $STATUS = unserialize(@file_get_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD")); $STATUS["LAST_CHECK"] = time(); @file_put_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD", serialize($STATUS)); if ($myVersion > $Remote_version) { echo "My version {$myVersion} is newest than {$Remote_version}, aborting\n"; build_progress("{version-up-to-date} {$datev}", 100); return; } if ($myVersion == $Remote_version) { build_progress("{version-up-to-date} {$datev}", 100); echo "My version {$myVersion} is the same than {$Remote_version}, aborting\n"; return; } $curl = $meta->buildCurl("/meta-updates/webfiltering/ftpunivtlse1fr.tgz"); $curl->Timeout = 120; if (!$curl->GetFile("{$tmpdir}/ftpunivtlse1fr.tgz")) { artica_update_event(0, "Failed Downloading webfiltering/ftpunivtlse1fr.tgz", @implode("\n", $curl->errors), __FILE__, __LINE__); $meta->events($curl->errors, __FUNCTION__, __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/ftpunivtlse1fr.tgz", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink("{$tmpdir}/ftpunivtlse1fr.tgz"); return false; } if (!$unix->TARGZ_TEST_CONTAINER("{$tmpdir}/ftpunivtlse1fr.tgz")) { artica_update_event(0, "Failed {$tmpdir}/ftpunivtlse1fr.tgz corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed {$tmpdir}/ftpunivtlse1fr.tgz corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink("{$tmpdir}/ftpunivtlse1fr.tgz"); return false; } $tar = $unix->find_program("tar"); shell_exec("{$tar} -xf {$tmpdir}/ftpunivtlse1fr.tgz -C {$WORKDIR}/"); @unlink("{$tmpdir}/ftpunivtlse1fr.tgz"); artica_update_event(0, "Success update categories statistics v.{$Remote_version}", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Success update categories statistics v.{$Remote_version}", @implode("\n", $curl->errors), __FILE__, __LINE__); @file_put_contents("/etc/artica-postfix/ftpunivtlse1fr.txt", $Remote_version); build_progress("Using Artica Meta server {done}", 100); CoherenceOffiels(); CoherenceRepertoiresUfdb(); BuildDatabaseStatus(); remove_bad_files(); }
function ufdbtables_artica_meta() { $unix = new unix(); $WORKDIR = $GLOBALS["WORKDIR_LOCAL"]; @mkdir($WORKDIR, 0755, true); @chmod($WORKDIR, 0755); $tmpdir = $unix->TEMP_DIR(); $myVersion = intval(@file_get_contents("/etc/artica-postfix/ufdbartica.txt")); $meta = new artica_meta(); $curl = $meta->buildCurl("/meta-updates/webfiltering/ufdbartica.txt"); if (!$curl->GetFile("{$tmpdir}/ufdbartica.txt")) { artica_update_event(0, "Failed Downloading {$meta->LOG_URI}", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading {$meta->LOG_URI}", @implode("\n", $curl->errors), __FILE__, __LINE__); return false; } if (!is_file("/etc/artica-postfix/artica-webfilter-db-index.txt")) { $curl = $meta->buildCurl("/meta-updates/webfiltering/index.txt"); if (!$curl->GetFile("/etc/artica-postfix/artica-webfilter-db-index.txt")) { artica_update_event(0, "Failed Downloading webfiltering/index.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/index.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); } } if (!is_file("/etc/artica-postfix/ufdbcounts.txt")) { $curl = $meta->buildCurl("/meta-updates/webfiltering/ufdbcounts.txt"); if (!$curl->GetFile("/etc/artica-postfix/ufdbcounts.txt")) { artica_update_event(0, "Failed Downloading webfiltering/ufdbcounts.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/ufdbcounts.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); } } $Remote_version = intval(@file_get_contents("{$tmpdir}/ufdbartica.txt")); echo "Current............: {$myVersion}\n"; echo "Available..........: {$Remote_version}\n"; $Remote_versionTime = date("Y-m-d H:i:s", $Remote_version); $rm = $unix->find_program("rm"); $cat = $unix->find_program("cat"); $tar = $unix->find_program("tar"); if ($myVersion == $Remote_version) { echo "My version {$myVersion} is the same than {$Remote_version} {$Remote_versionTime}, aborting\n"; return; } if ($myVersion > $Remote_version) { echo "My version {$myVersion} is newest than {$Remote_version} {$Remote_versionTime}, aborting\n"; return; } $curl = $meta->buildCurl("/meta-updates/webfiltering/ufdbartica/ufdbartica.txt"); //*************************************************************************************************************** if ($curl->GetFile("{$tmpdir}/ufdbartica.txt")) { $ufdbartica_tmp = "{$tmpdir}/ufdbartica_tmp"; @mkdir($ufdbartica_tmp, 0755, true); $splitted = unserialize(@file_get_contents("{$tmpdir}/ufdbartica.txt")); if (is_array($splitted)) { if (count($splitted) > 2) { while (list($targetFile, $md5file) = each($ARRAY)) { $BaseName = basename($targetFile); $HTTP_LINK = "/meta-updates/webfiltering/ufdbartica/{$BaseName}"; $LOCAL_FILE = "{$ufdbartica_tmp}/{$BaseName}"; writelogs_meta("Checking {$LOCAL_FILE}", __FUNCTION__, __FILE__, __LINE__); if (is_file($LOCAL_FILE)) { $md5Local = md5_file($LOCAL_FILE); if ($md5Local == $md5file) { continue; } writelogs_meta("{$LOCAL_FILE} corrupted...", __FUNCTION__, __FILE__, __LINE__); @unlink($LOCAL_FILE); } writelogs_meta("Downloading {$HTTP_LINK}", __FUNCTION__, __FILE__, __LINE__); $curl = $meta->buildCurl($HTTP_LINK); if (!$curl->GetFile($LOCAL_FILE)) { writelogs_meta("Unable to download {$HTTP_LINK} {$curl->error}\n" . @implode("\n", $curl->errors), __FUNCTION__, __FILE__, __LINE__); return true; } $md5Local = md5_file($LOCAL_FILE); if ($md5Local == $md5file) { writelogs_meta("{$HTTP_LINK} success...", __FUNCTION__, __FILE__, __LINE__); continue; } } system("{$cat} {$ufdbartica_tmp}/*.tgz.* >{$tmpdir}/ufdbartica.tgz"); } } } //*************************************************************************************************************** @unlink("{$tmpdir}/ufdbartica.txt"); if (!is_file("{$tmpdir}/ufdbartica.tgz")) { $curl = $meta->buildCurl("/meta-updates/webfiltering/ufdbartica.tgz"); if (!$curl->GetFile("{$tmpdir}/ufdbartica.tgz")) { artica_update_event(0, "Failed Downloading webfiltering/ufdbartica.tgz", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/ufdbartica.tgz", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink("{$tmpdir}/ufdbartica.tgz"); return false; } } $curl = $meta->buildCurl("/meta-updates/webfiltering/index.txt"); if (!$curl->GetFile("/etc/artica-postfix/artica-webfilter-db-index.txt")) { artica_update_event(0, "Failed Downloading webfiltering/index.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading webfiltering/index.txt", @implode("\n", $curl->errors), __FILE__, __LINE__); } $curl = $meta->buildCurl("/meta-updates/webfiltering/ARTICAUFDB_LAST_DOWNLOAD"); $curl->GetFile("/etc/artica-postfix/ARTICAUFDB_LAST_DOWNLOAD"); $STATUS = unserialize(@file_get_contents("/etc/artica-postfix/ARTICAUFDB_LAST_DOWNLOAD")); $STATUS["LAST_DOWNLOAD"]["LAST_CHECK"] = time(); @file_put_contents("/etc/artica-postfix/ARTICAUFDB_LAST_DOWNLOAD", serialize($STATUS)); if (!$unix->TARGZ_TEST_CONTAINER("{$tmpdir}/ufdbartica.tgz")) { artica_update_event(0, "Failed {$tmpdir}/ufdbartica.tgz corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed {$tmpdir}/ufdbartica.tgz corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink("{$tmpdir}/ufdbartica.tgz"); return false; } @file_put_contents("/etc/artica-postfix/ufdbartica.txt", $Remote_version); $tar = $unix->find_program("tar"); $php5 = $unix->LOCATE_PHP5_BIN(); shell_exec("{$tar} -xf {$tmpdir}/ufdbartica.tgz -C {$WORKDIR}/"); @unlink("{$tmpdir}/ufdbartica.tgz"); if (!is_file("/opt/ufdbcat/bin/ufdbcatdd")) { system("{$php5} /usr/share/artica-postfix/exec.ufdbcat.php --install --noupdate"); } shell_exec("/etc/init.d/ufdbcat reload"); artica_update_event(0, "Success Artica Webfiltering databases v.{$Remote_version}", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Success Artica Webfiltering databases v.{$Remote_version}", @implode("\n", $curl->errors), __FILE__, __LINE__); updatev2_progress(100, "{done} [" . __LINE__ . "]"); }
function artica_updates_scheduled($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if (!$aspid) { $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Starting......: " . date("H:i:s") . " artica_updates_scheduled already executed PID: {$pid} since {$time}Mn\n"; if ($time < 120) { if (!$GLOBALS["FORCE"]) { die; } } unix_system_kill_force($pid); } } else { $pidTimeEx = $unix->file_time_min($pidTime); if ($pidTimeEx < 61) { events("Skip Artica updates, current {$pidTimeEx}Mn, require 60mn ", __FUNCTION__, __FILE__, __LINE__); return; } } @chdir("/root"); @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); $tmpdir = $unix->TEMP_DIR(); $meta = new artica_meta(); $ARRAY = array(); $sock = new sockets(); $MetaClientAutoUpdate = intval($sock->GET_INFO("MetaClientAutoUpdate")); $ini = new iniFrameWork(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"])); if ($nightly == 1) { $nightly = "yes"; } if ($GLOBALS["VERBOSE"]) { echo "Update nightly ? `{$nightly}`\n"; } $curl = $meta->buildCurl("/meta-updates/releases/"); if (!$curl->GetFile("{$tmpdir}/releases.txt")) { events("Fatal: /meta-updates/releases/releases.txt {$curl->errors}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__); return false; } $data = @file_get_contents("{$tmpdir}/releases.txt"); $f = explode("\n", $data); @unlink("{$tmpdir}/releases.txt"); while (list($index, $ligne) = each($f)) { if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) { if ($GLOBALS["VERBOSE"]) { echo "Not Found {$ligne}\n"; } continue; } $verbin = intval(str_replace(".", "", $re[1])); events("Found : v{$verbin} /meta-updates/releases/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__); $ARRAY[$verbin] = "/meta-updates/releases/artica-{$re[1]}.tgz"; } if ($MetaClientAutoUpdate == 1) { $nightly = "yes"; } if ($nightly == "yes") { $curl = $meta->buildCurl("/meta-updates/nightlys/"); if (!$curl->GetFile("{$tmpdir}/nightlys.txt")) { artica_update_event(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__); } else { $data = @file_get_contents("{$tmpdir}/nightlys.txt"); $f = explode("\n", $data); @unlink("{$tmpdir}/nightlys.txt"); while (list($index, $ligne) = each($f)) { if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) { if ($GLOBALS["VERBOSE"]) { echo "Not Found {$ligne}\n"; } continue; } $verbin = intval(str_replace(".", "", $re[1])); events("Found : v{$verbin} /meta-updates/nightlys/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__); $ARRAY[$verbin] = "/meta-updates/nightlys/artica-{$re[1]}.tgz"; } } } krsort($ARRAY); while (list($index, $ligne) = each($ARRAY)) { if ($GLOBALS["VERBOSE"]) { echo "Found v.{$index} / {$ligne}\n"; } $TA[] = $index; $TZ[] = $ligne; } $LASTVER = $TA[0]; $LASTFILE = $TZ[0]; $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION")); $MYVERSION = intval(str_replace(".", "", $MYVERSION_TEXT)); events("Last version: {$LASTVER} -> {$LASTFILE} against {$MYVERSION}", __FUNCTION__, __FILE__, __LINE__); if ($MYVERSION > $LASTVER) { events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "Most updated, aborting\n"; } return; } if ($MYVERSION == $LASTVER) { events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "Most updated, aborting\n"; } return; } $curl = $meta->buildCurl($LASTFILE); $tmpfile = "{$tmpdir}/" . basename($LASTFILE); if (!$curl->GetFile($tmpfile)) { events("Failed Downloading {$LASTFILE} {$curl->errors}", __FUNCTION__, __FILE__, __LINE__); artica_update_event(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink($tmpfile); return; } if (!$unix->TARGZ_TEST_CONTAINER($tmpfile)) { artica_update_event(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); meta_admin_mysql(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__); @unlink($tmpfile); return false; } if ($GLOBALS["VERBOSE"]) { echo "Extracting {$tmpfile}\n"; } $tar = $unix->find_program("tar"); shell_exec("{$tar} xf {$tmpfile} -C /usr/share/"); @unlink($tmpfile); $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION")); $php = $unix->LOCATE_PHP5_BIN(); shell_exec("{$php} /usr/share/artica-postfix/exec.nightly.php --restart-services >/dev/null 2>&1"); artica_update_event(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__); meta_admin_mysql(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__); }