Ejemplo n.º 1
0
function install($filename)
{
    $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/artica.install.progress";
    $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/artica.install.progress.txt";
    $unix = new unix();
    $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME();
    $LINUX_DISTRIBUTION = $unix->LINUX_DISTRIBUTION();
    $LINUX_VERS = $unix->LINUX_VERS();
    $LINUX_ARCHITECTURE = $unix->LINUX_ARCHITECTURE();
    $APACHEUSER = $unix->APACHE_SRC_ACCOUNT();
    $DebianVer = "debian{$LINUX_VERS[0]}";
    $TMP_DIR = $unix->TEMP_DIR();
    $ORGV = @file_get_contents("/usr/share/artica-postfix/VERSION");
    $PATCH_VER = null;
    $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}";
    echo "Package {$tarballs_file}\n";
    $size = filesize($tarballs_file);
    ArticaMeta_release($tarballs_file);
    if (preg_match('#([0-9\\.]+)_([0-9\\.]+)-([0-9]+).tgz$#i', $filename, $r)) {
        $CUR_BRANCH = @file_get_contents("/usr/share/artica-postfix/MAIN_RELEASE");
        $CUR_BRANCH = trim($CUR_BRANCH);
        echo "Patch....................: {$r[3]}\n";
        echo "From.....................: {$r[1]}\n";
        echo "To.......................: {$r[2]}\n";
        echo "Current Branch..........: {$CUR_BRANCH}\n";
        if ($CUR_BRANCH != $r[1]) {
            echo "{$CUR_BRANCH} != {$r[1]}\n";
            build_progress("{not_for_current_branch} {requested} {$r[1]}", 110);
            return;
        }
        $PATCH_VER = $r[2] . " :";
        $ASPATCH = true;
    }
    echo "Size....................: " . FormatBytes($size / 1024) . "\n";
    echo "Current version.........: {$ORGV}\n";
    build_progress("{analyze}...", 10);
    echo "Current system..........: {$LINUX_CODE_NAME} {$LINUX_DISTRIBUTION} {$LINUX_VERS[0]}/{$LINUX_VERS[1]} {$LINUX_ARCHITECTURE}\n";
    echo "Package.................: {$filename}\n";
    echo "Temp dir................: {$TMP_DIR}\n";
    echo "Apache User.............: {$APACHEUSER}\n";
    if (!is_file($tarballs_file)) {
        echo "{$tarballs_file} no such file...\n";
        build_progress("No such file...", 110);
        return;
    }
    echo "Uncompressing {$tarballs_file}...\n";
    build_progress("{extracting} {$filename}...", 20);
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $squid = $unix->LOCATE_SQUID_BIN();
    build_progress("{extracting} {$filename}...", 50);
    system("{$tar} xpf {$tarballs_file} -C /usr/share/");
    echo "Removing {$tarballs_file}...\n";
    @unlink($tarballs_file);
    shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/conf/upload/*");
    build_progress("{apply_permissions}...", 55);
    echo "{$APACHEUSER} -> /usr/share/artica-postfix\n";
    shell_exec("{$chown} -R {$APACHEUSER} /usr/share/artica-postfix");
    echo "0755 -> /usr/share/artica-postfix\n";
    shell_exec("{$chmod} -R 0755 /usr/share/artica-postfix");
    $ORGD = @file_get_contents("/usr/share/artica-postfix/VERSION");
    echo "Old version.............: {$ORGV}\n";
    if ($ASPATCH) {
        $patched = " (patched)";
    }
    echo "Current version.........: {$ORGD}{$patched}\n";
    sleep(2);
    if ($ORGV == $ORGD) {
        build_progress("{operation_failed} Same version {$PATCH_VER}{$filename}...", 110);
        return;
    }
    build_progress("{restarting} Artica...", 60);
    $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register");
    build_progress("{restarting} Artica...", 65);
    build_progress("{building_init_scripts}...", 70);
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php");
    build_progress("{updating_network}...", 75);
    system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php");
    system("{$php} /usr/share/artica-postfix/exec.monit.php --build");
    echo "Starting......: " . date("H:i:s") . " Purge and clean....\n";
    build_progress("{restarting} Artica...", 80);
    if (is_file("/etc/init.d/nginx")) {
        shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &");
    }
    build_progress("{restarting} Artica...", 81);
    shell_exec("{$nohup} /etc/init.d/auth-tail restart");
    build_progress("{restarting} Artica...", 82);
    shell_exec("{$nohup} /etc/init.d/artica-framework");
    build_progress("{restarting} Artica...", 83);
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 --force --verbose " . time() . "");
    build_progress("{restarting} Artica...", 84);
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 85);
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 86);
    shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 87);
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 88);
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 90);
    build_progress("{restarting} Artica...", 100);
    echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n";
}
Ejemplo n.º 2
0
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");
}
Ejemplo n.º 3
0
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");
}