function mysql_events() { $instance_id = $_GET["instance-id"]; if (!is_numeric($instance_id)) { $instance_id = 0; } $file = "/var/run/mysqld/mysqld.err"; if ($instance_id > 0) { $ini = new iniFrameWork(); $ini->loadFile("/etc/mysql-multi.cnf"); $file = $ini->get("mysqld{$instance_id}", "log_error"); } $unix = new unix(); $tail = $unix->find_program("tail"); $results = array(); if ($instance_id == 0) { if (is_file("/var/lib/mysql/mysqld.err")) { $cmd = "{$tail} -n 300 /var/lib/mysql/mysqld.err 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); } if (is_file("/var/run/mysqld/mysqld.err")) { $cmd = "{$tail} -n 300 /var/run/mysqld/mysqld.err 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); } } else { if (is_file($file)) { $cmd = "{$tail} -n 300 /var/run/mysqld/mysqld.err 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec($cmd, $results); } } if (count($results) == 0) { $datas = base64_encode(serialize(array("{error_no_datas}"))); echo "<articadatascgi>{$datas}</articadatascgi>"; return; } $datas = base64_encode(serialize($results)); echo "<articadatascgi>{$datas}</articadatascgi>"; }
function nightly() { @mkdir("/var/log/artica-postfix", 0755, true); $GLOBALS["MasterIndexFile"] = "/usr/share/artica-postfix/ressources/index.ini"; $unix = new unix(); $sock = new sockets(); $autoinstall = true; $timefile = "/etc/artica-postfix/croned.1/nightly"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = @file_get_contents($pidfile); $kill = $unix->find_program("kill"); $tmpdir = $unix->TEMP_DIR(); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Starting......: " . date("H:i:s") . " nightly build already executed PID: {$pid} since {$time}Mn\n"; system_admin_events("nightly build already executed PID: {$pid} since {$time}Mn", __FUNCTION__, __FILE__, __LINE__, "artica-update"); if ($time < 120) { if (!$GLOBALS["FORCE"]) { die; } } unix_system_kill_force($pid); } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates"); if (!is_numeric($EnableScheduleUpdates)) { $EnableScheduleUpdates = 0; } if ($GLOBALS["FORCE"]) { _artica_update_event(1, "Update task pid {$mypid} is forced by an human.", null, __FILE__, __LINE__); } if ($EnableScheduleUpdates == 1) { if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["BYCRON"]) { _artica_update_event(2, "Operation must be only executed by scheduler ( use --force to by pass)", null, __FILE__, __LINE__); @file_put_contents("/usr/share/artica-postfix/download_progress", 100); return; } } } $ini = new iniFrameWork(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); if (!isset($ini->_params["AUTOUPDATE"]["enabled"])) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if (trim($ini->_params["AUTOUPDATE"]["enabled"]) == null) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if ($ini->_params["AUTOUPDATE"]["enabled"] == null) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if (trim($ini->_params["AUTOUPDATE"]["uri"]) == null) { $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php"; } if ($ini->_params["AUTOUPDATE"]["enabled"] == 1) { $ini->_params["AUTOUPDATE"]["enabled"] = 'yes'; } if (!is_numeric(trim($ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]))) { $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"] = 60; } if ($ini->_params["AUTOUPDATE"]["enabled"] != 'yes') { echo "Starting......: " . date("H:i:s") . " Artica Update feature is disabled (enabled = {$ini->_params["AUTOUPDATE"]["enabled"]} )\n"; return; } $CheckEveryMinutes = $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]; $uri = $ini->_params["AUTOUPDATE"]["uri"]; $arrayURI = parse_url($uri); $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}"; $MAIN_URI = str_replace("www.artica.fr", "www.articatech.net", $MAIN_URI); if (!$GLOBALS["FORCE"]) { if ($EnableScheduleUpdates == 0) { if ($unix->file_time_min($timefile) < $CheckEveryMinutes) { echo "Starting......: " . date("H:i:s") . " update feature (too short time, require {$CheckEveryMinutes}mn)\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 100); return; } } } @unlink($timefile); @file_put_contents($timefile, time()); if ($GLOBALS["FORCE"]) { if (is_file("/root/artica-latest.tgz")) { echo "Starting......: " . date("H:i:s") . " Installing old downloaded package\n"; if (install_package("/root/artica-latest.tgz")) { return; } } } // ----------------------- LANCEMENT ------------------------------------------------------------------------------ $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 1) { echo "Starting......: " . date("H:i:s") . " Nightly builds using Artica Meta console\n"; system("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --artica-updates >/dev/null 2>&1 &"); die; } echo "Starting......: " . date("H:i:s") . " Nightly builds checking an official release first\n"; if (update_release()) { return; } $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"])); if ($nightly == 1) { $nightly = "yes"; } if ($GLOBALS["FORCE"]) { $nightly = "yes"; } if ($GLOBALS["FORCE_NIGHTLY"]) { $nightly = "yes"; } if ($nightly != 'yes') { echo "Starting......: " . date("H:i:s") . " Nightly builds feature is disabled [{$nightly}]\n"; @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100); return; } if ($ini->_params["AUTOUPDATE"]["autoinstall"] == 1) { $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes"; } if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) { $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes"; } if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") { $autoinstall = false; } @file_put_contents("/usr/share/artica-postfix/download_progress", 0); $MyCurrentVersion = GetCurrentVersion(); echo "Starting......: " . date("H:i:s") . " Current version: {$MyCurrentVersion}\n"; $Lastest = trim(strtolower($GLOBALS["lastest-nightly"])); echo "Starting......: " . date("H:i:s") . " Nightly builds version \"{$Lastest}\" on repository\n"; $MyNextVersion = intval(str_replace(".", "", $Lastest)); echo "Starting......: " . date("H:i:s") . " nightly builds Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n"; if ($MyNextVersion == $MyCurrentVersion) { echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Same version\"\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 100); return; } if ($MyCurrentVersion > $MyNextVersion) { echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Most updated\"\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 100); return; } $t1 = time(); _artica_update_event(2, "nightly builds Downloading new version {$Lastest}", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " nightly builds Downloading new version {$Lastest}, please wait\n"; events("Downloading new version {$Lastest}"); $uri = "{$MAIN_URI}/nightbuilds/artica-{$Lastest}.tgz"; $ArticaFileTemp = "{$tmpdir}/{$Lastest}/artica-{$Lastest}.tgz"; @mkdir("{$tmpdir}/{$Lastest}", 0755, true); $curl = new ccurl($uri); $curl->Timeout = 2400; $curl->WriteProgress = true; $curl->ProgressFunction = "nightly_progress"; $t = time(); if (!$curl->GetFile($ArticaFileTemp)) { _artica_update_event(0, "nightly builds Unable to download latest nightly build with error {$curl->error}", null, __FILE__, __LINE__); events("Unable to download latest nightly build with error {$curl->error}"); system_admin_events("Unable to download latest nightly build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); @unlink($ArticaFileTemp); return; } $took = $unix->distanceOfTimeInWords($t, time(), true); _artica_update_event(2, "artica-{$Lastest}.tgz download, took {$took}", null, __FILE__, __LINE__); system_admin_events("artica-{$Lastest}.tgz download, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); events("artica-{$Lastest}.tgz download, took {$took}"); $size = @filesize($ArticaFileTemp); $size = FormatBytes($size / 1024, true); ArticaMeta_nightly($ArticaFileTemp); echo "Starting......: " . date("H:i:s") . " nightly builds took {$took}\n"; if (!$GLOBALS["FORCE"]) { if ($autoinstall == false) { _artica_update_event(2, "artica-latest.tgz will be stored in /root", null, __FILE__, __LINE__); @copy("{$ArticaFileTemp}", "/root/artica-latest.tgz"); @unlink($ArticaFileTemp); _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size}) waiting order", null, __FILE__, __LINE__); system_admin_events("New Artica update v.{$Lastest} waiting your order", __FUNCTION__, __FILE__, __LINE__, "artica-update"); return; } else { } } events("Now, installing the newest version in {$ArticaFileTemp} package..."); $size = @filesize($ArticaFileTemp); $size = FormatBytes($size / 1024, true); if (!install_package($ArticaFileTemp, $Lastest)) { events("Install package Failed..."); return false; } events("New Artica update v.{$Lastest}"); _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size})", null, __FILE__, __LINE__); system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); }
function master_index() { @unlink($GLOBALS["MasterIndexFile"]); $ini = new iniFrameWork(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) { $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes"; } if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") { $autoinstall = false; } $uri = $ini->_params["AUTOUPDATE"]["uri"]; $arrayURI = parse_url($uri); $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}"; echo "Starting......: " . date("H:i:s") . " Refreshing index file...\n"; $curl = new ccurl("{$uri}?time=" . time()); if (!$curl->GetFile($GLOBALS["MasterIndexFile"])) { _artica_update_event(0, "Error {$curl->error}", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " Error {$curl->error_num};{$curl->error}, Try direct\n"; if (!$GLOBALS["NOT_FORCE_PROXY"]) { echo "Starting......: " . date("H:i:s") . " FATAL: Unable to download index file, try in direct mode\n"; $GLOBALS["NOT_FORCE_PROXY"] = true; return master_index(); } if ($curl->error == "{CURLE_COULDNT_RESOLVE_HOST}") { if ($arrayURI["host"] == "www.artica.fr") { if (!$GLOBALS["CHANGED"]) { echo "Starting......: " . date("H:i:s") . " trying www.articatech.net\n"; $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php"; $ini->saveFile("/etc/artica-postfix/artica-update.conf"); $GLOBALS["CHANGED"] = true; return master_index(); } } } return; } if (!is_file($GLOBALS["MasterIndexFile"])) { echo "Starting......: " . date("H:i:s") . " {$GLOBALS["MasterIndexFile"]} no such file...\n"; return; } return true; }
function amavis_watchdog_load_conf(){ if(is_file("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration")){ $ini=new iniFrameWork(); $ini->loadFile("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration"); $GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]=$ini->_params["BEHAVIORS"]["max_servers"]; $GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]=$ini->_params["BEHAVIORS"]["child_timeout"]; } $GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]=filemtime("/usr/local/etc/amavisd.conf"); events("/usr/local/etc/amavisd.conf: time:{$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]}",__FUNCTION__,__LINE__); events("max_servers: {$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]}",__FUNCTION__,__LINE__); events("child_timeout: {$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]}",__FUNCTION__,__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__); }