function update_release() { $sock = new sockets(); $unix = new unix(); $autoinstall = true; $ini = new iniFrameWork(); $tmpdir = $unix->TEMP_DIR(); if (!master_index()) { return false; } $RebootAfterArticaUpgrade = $sock->GET_INFO("RebootAfterArticaUpgrade"); if (!is_numeric($RebootAfterArticaUpgrade)) { $RebootAfterArticaUpgrade = 0; } $MyCurrentVersion = GetCurrentVersion(); $ini->loadFile('/etc/artica-postfix/artica-update.conf'); $ini->_params["AUTOUPDATE"]["autoinstall"] = trim(strtolower($ini->_params["AUTOUPDATE"]["autoinstall"])); $ini->_params["AUTOUPDATE"]["enabled"] = trim(strtolower($ini->_params["AUTOUPDATE"]["enabled"])); if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) { $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes"; } if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == 1) { $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes"; } if (trim($ini->_params["AUTOUPDATE"]["enabled"]) == 1) { $ini->_params["AUTOUPDATE"]["enabled"] = "yes"; } if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") { $autoinstall = false; } $uri = $ini->_params["AUTOUPDATE"]["uri"]; if ($uri == null) { $uri = "http://www.articatech.net/auto.update.php"; } $arrayURI = parse_url($uri); if (!isset($arrayURI["host"])) { $arrayURI["host"] = "www.articatech.net"; } $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}"; echo "Starting......: " . date("H:i:s") . " Source:{$uri}\n"; if (!$GLOBALS["FORCE"]) { if ($ini->_params["AUTOUPDATE"]["enabled"] != 'yes') { echo "Starting......: " . date("H:i:s") . " Update feature is disabled AUTOUPDATE/enabled = `{$ini->_params["AUTOUPDATE"]["enabled"]}`\n"; echo "Starting......: " . date("H:i:s") . " Add --force to bypass or enable the update feature trough Artica Web console.\n"; return; } } $CheckEveryMinutes = $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]; if (!is_numeric($CheckEveryMinutes)) { $CheckEveryMinutes = 60; } if ($GLOBALS["FORCE"]) { if (is_file("/root/artica-latest.tgz")) { _artica_update_event(1, "Installing old downloaded package /root/artica-latest.tgz", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " Installing old downloaded package\n"; if (install_package("/root/artica-latest.tgz", null)) { return; } } } RefreshIndex(); $ini = new iniFrameWork(); $ini->loadFile($GLOBALS["MasterIndexFile"]); if (!isset($ini->_params["NEXT"])) { echo "Starting......: " . date("H:i:s") . " Corrupted Index: {$GLOBALS["MasterIndexFile"]}..\n"; return; } $Lastest = trim(strtolower($ini->_params["NEXT"]["artica"])); $nightly = trim(strtolower($ini->_params["NEXT"]["artica-nightly"])); $GLOBALS["lastest-nightly"] = $nightly; if ($RebootAfterArticaUpgrade == 1) { echo "Starting......: " . date("H:i:s") . " Reboot after upgrade is enabled\n"; } $buildtime = trim(strtolower($ini->_params["NEXT"]["buildtime"])); if (!is_numeric($buildtime)) { _artica_update_event(1, "There is an issue on the index file (no build time)", null, __FILE__, __LINE__); } else { echo "Starting......: " . date("H:i:s") . " Index file refreshed on : " . date("Y-m-d H:i:s", $buildtime) . "\n"; } echo "Starting......: " . date("H:i:s") . " Last Official release: \"{$Lastest}\"\n"; echo "Starting......: " . date("H:i:s") . " Last Nightly release:. \"{$nightly}\"\n"; $MyNextVersion = intval(str_replace(".", "", $Lastest)); echo "Starting......: " . date("H:i:s") . " Official release Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n"; if ($MyNextVersion == $MyCurrentVersion) { echo "Starting......: " . date("H:i:s") . " Official release {$MyCurrentVersion}/{$MyNextVersion} \"Up to date\"\n"; return; } if ($MyCurrentVersion > $MyNextVersion) { echo "Starting......: " . date("H:i:s") . " Official release {$MyCurrentVersion}/{$MyNextVersion} \"Up to date\"\n"; return; } $t1 = time(); _artica_update_event(1, "New official release available version {$Lastest}", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " Official release Downloading new version {$Lastest}, please wait\n"; events("Downloading new version {$Lastest}"); $uri = "{$MAIN_URI}/download/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(); echo "Starting......: " . date("H:i:s") . " Official release Downloading {$uri}\n"; if (!$curl->GetFile($ArticaFileTemp)) { _artica_update_event(0, "Error: Official release Unable to download latest build with error {$curl->error}", null, __FILE__, __LINE__); events("Unable to download latest build with error {$curl->error}"); system_admin_events("Unable to download latest build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); @unlink($ArticaFileTemp); return; } $size = @filesize($ArticaFileTemp) / 1024; echo "Starting......: " . date("H:i:s") . " Official release size:{$size}KB\n"; $took = $unix->distanceOfTimeInWords($t, time(), true); _artica_update_event(2, "artica-{$Lastest}.tgz downloaded, took {$took}", null, __FILE__, __LINE__); system_admin_events("artica-{$Lastest}.tgz downloaded, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); ArticaMeta_release($ArticaFileTemp); events("artica-{$Lastest}.tgz downloaded, took {$took}"); echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository\n"; ArticaMeta_release($ArticaFileTemp); 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"); $size = @filesize($ArticaFileTemp); $size = FormatBytes($size / 1024, true); @unlink($ArticaFileTemp); _artica_update_event(1, "New Artica v.{$Lastest} ({$size}) waiting administrator order", null, __FILE__, __LINE__); system_admin_events("New Artica update v.{$Lastest} waiting your order", __FUNCTION__, __FILE__, __LINE__, "artica-update"); return; } } echo "Starting......: " . date("H:i:s") . " Official release took {$took}\n"; $size = @filesize($ArticaFileTemp); $size = FormatBytes($size / 1024, true); if (install_package($ArticaFileTemp, $Lastest)) { return; } events("New Artica update v.{$Lastest}"); _artica_update_event(1, "Nightly build: Artica v.{$Lastest} ({$size})", null, __FILE__, __LINE__); system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); }
function update_release() { $sock = new sockets(); $unix = new unix(); $autoinstall = true; $tmpdir = $unix->TEMP_DIR(); if (!master_index()) { return false; } $RebootAfterArticaUpgrade = $sock->GET_INFO("RebootAfterArticaUpgrade"); if (!is_numeric($RebootAfterArticaUpgrade)) { $RebootAfterArticaUpgrade = 0; } $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates"); $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("EnableScheduleUpdates")); if (!is_numeric($EnableScheduleUpdates)) { $EnableScheduleUpdates = 0; } $ArticaAutoUpateOfficial = $sock->GET_INFO("ArticaAutoUpateOfficial"); $ArticaAutoUpateNightly = intval($sock->GET_INFO("ArticaAutoUpateNightly")); $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("ArticaUpdateIntervalAllways")); $OfficialArticaUri = $sock->GET_INFO("OfficialArticaUri"); if (!is_numeric($ArticaAutoUpateOfficial)) { $ArticaAutoUpateOfficial = 1; } if ($OfficialArticaUri == null) { $OfficialArticaUri = "http://articatech.net/artica.update.php"; } $CheckEveryMinutes = 60; $uri = $OfficialArticaUri; $MyCurrentVersion = GetCurrentVersion(); echo "Starting......: " . date("H:i:s") . " Retreve Index file from cloud...\n"; if (!RefreshIndex()) { echo "Starting......: " . date("H:i:s") . " index file failed\n"; updater_events("Index file failed"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100); die; } if ($RebootAfterArticaUpgrade == 1) { echo "Starting......: " . date("H:i:s") . " Reboot after upgrade is enabled\n"; } $key = update_find_latest(); $MyNextVersion = $key; $array = unserialize(@file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaUpdateRepos")); $OFFICIALS = $array["OFF"]; $Lastest = $OFFICIALS[$key]["VERSION"]; $MAIN_URI = $OFFICIALS[$key]["URL"]; $MAIN_MD5 = $OFFICIALS[$key]["MD5"]; $MAIN_FILENAME = $OFFICIALS[$key]["FILENAME"]; $uri = $MAIN_URI; $nightly = trim(strtolower($ini->_params["NEXT"]["artica-nightly"])); $GLOBALS["lastest-nightly"] = $nightly; echo "Starting......: " . date("H:i:s") . " Last Official release: \"{$Lastest}\"\n"; echo "Starting......: " . date("H:i:s") . " Last Official release: \"{$MAIN_URI}\"\n"; echo "Starting......: " . date("H:i:s") . " Last Official release: \"{$MAIN_MD5}\"\n"; echo "Starting......: " . date("H:i:s") . " Last Nightly release:. \"{$nightly}\"\n"; echo "Starting......: " . date("H:i:s") . " Official release Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n"; if ($MyNextVersion == $MyCurrentVersion) { echo "Starting......: " . date("H:i:s") . " Official release {$MyCurrentVersion}/{$MyNextVersion} \"Up to date\"\n"; updater_events("Official release {$MyCurrentVersion}/{$MyNextVersion} UP TO DATE"); return; } if ($MyCurrentVersion > $MyNextVersion) { echo "Starting......: " . date("H:i:s") . " Official release {$MyCurrentVersion}/{$MyNextVersion} \"Up to date\"\n"; updater_events("Official release {$MyCurrentVersion}/{$MyNextVersion} UP TO DATE"); return; } $t1 = time(); _artica_update_event(1, "New official release available version {$Lastest}", null, __FILE__, __LINE__); echo "Starting......: " . date("H:i:s") . " Official release Downloading new version {$Lastest}, please wait\n"; updater_events("Downloading new version {$Lastest}"); $ArticaFileTemp = "{$tmpdir}/{$Lastest}/{$MAIN_FILENAME}"; @mkdir("{$tmpdir}/{$Lastest}", 0755, true); $curl = new ccurl($uri); $curl->Timeout = 2400; $curl->WriteProgress = true; $curl->ProgressFunction = "nightly_progress"; $t = time(); echo "Starting......: " . date("H:i:s") . " Official release Downloading {$uri}\n"; if (!$curl->GetFile($ArticaFileTemp)) { _artica_update_event(0, "Error: Official release Unable to download latest build with error {$curl->error}", null, __FILE__, __LINE__); updater_events("Unable to download latest build with error {$curl->error}"); system_admin_events("Unable to download latest build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); @unlink($ArticaFileTemp); return; } $size = @filesize($ArticaFileTemp) / 1024; $md5_file = md5_file($ArticaFileTemp); if ($md5_file != $MAIN_MD5) { events("Corrupted file {$md5_file} <> {$MAIN_MD5}"); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100); die; } echo "Starting......: " . date("H:i:s") . " Official release size:{$size}KB\n"; $took = $unix->distanceOfTimeInWords($t, time(), true); _artica_update_event(2, "{$MAIN_FILENAME} downloaded, took {$took}", null, __FILE__, __LINE__); system_admin_events("{$MAIN_FILENAME} downloaded, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); ArticaMeta_release($ArticaFileTemp); events("{$MAIN_FILENAME} downloaded, took {$took}"); echo "Starting......: " . date("H:i:s") . " Checking Artica-meta repository\n"; ArticaMeta_release($ArticaFileTemp); echo "Starting......: " . date("H:i:s") . " Official release took {$took}\n"; $size = @filesize($ArticaFileTemp); $size = FormatBytes($size / 1024, true); if (install_package($ArticaFileTemp, $Lastest)) { return; } events("New Artica update v.{$Lastest}"); _artica_update_event(1, "Nightly build: Artica v.{$Lastest} ({$size})", null, __FILE__, __LINE__); system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update"); }