示例#1
0
文件: update.php 项目: nopuls/dzcp
 }
 //Bilder aus der Usergalerie verschieben
 $files = get_files('../inc/images/uploads/usergallery/');
 for ($i = 0; $i < count($files); $i++) {
     if (is_dir('../inc/images/uploads/usergallery/' . $files[$i])) {
         $sc = get_files('../inc/images/uploads/usergallery/' . $files[$i]);
         for ($e = 0; $e < count($sc); $e++) {
             @copy('../inc/images/uploads/usergallery/' . $files[$i] . '/' . $sc[$e], '../inc/images/uploads/usergallery/' . $files[$i] . '_' . $sc[$e]);
             @unlink('../inc/images/uploads/usergallery/' . $files[$i] . '/' . $sc[$e]);
         }
         @unlink('../inc/images/uploads/usergallery/' . $files[$i]);
         @rmdir('../inc/images/uploads/usergallery/' . $files[$i]);
     }
 }
 if ($_POST['version'] == "1.1") {
     update_mysql();
     update_mysql_1_3();
     update_mysql_1_4();
     update_mysql_1_5();
     update_mysql_1_5_1();
     update_mysql_1_5_2();
     update_mysql_1_5_4();
 } elseif ($_POST['version'] == "1.2.x") {
     update_mysql_1_3();
     update_mysql_1_4();
     update_mysql_1_5();
     update_mysql_1_5_1();
     update_mysql_1_5_2();
     update_mysql_1_5_4();
 } elseif ($_POST['version'] == "1.3.x") {
     update_mysql_1_4();
function xstart()
{
    $T1 = time();
    $curl = new ccurl();
    $unix = new unix();
    $GLOBALS["MYPID"] = getmypid();
    $pidfile = "/etc/artica-postfix/pids/windowupdate.partial.processor.pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__), true);
    if (count($pids) > 0) {
        while (list($i, $line) = each($pids)) {
            events("Already executed PID:{$i}... aborting ", __LINE__);
        }
        die;
    }
    $TEMPDIR = $unix->TEMP_DIR() . "/WindowsUpdates";
    $rm = $unix->find_program("rm");
    @file_put_contents($pidfile, $GLOBALS["MYPID"]);
    if (is_dir($TEMPDIR)) {
        shell_exec("{$rm} -rf {$TEMPDIR}");
        @mkdir($TEMPDIR);
    }
    $GLOBALS["WindowsUpdateMaxToPartialQueue"] = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateMaxToPartialQueue"));
    $GLOBALS["WindowsUpdateCachingDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateCachingDir");
    if ($GLOBALS["WindowsUpdateCachingDir"] == null) {
        $GLOBALS["WindowsUpdateCachingDir"] = "/home/squid/WindowsUpdate";
    }
    $WindowsUpdateDownTimeout = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateDownTimeout"));
    if ($WindowsUpdateDownTimeout == 0) {
        $WindowsUpdateDownTimeout = 600;
    }
    $WindowsUpdateBandwidthMaxFailed = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateBandwidthMaxFailed"));
    if ($WindowsUpdateBandwidthMaxFailed == 0) {
        $WindowsUpdateBandwidthMaxFailed = 50;
    }
    $WindowsUpdateMaxPartition = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateMaxPartition"));
    if ($WindowsUpdateMaxPartition == 0) {
        $WindowsUpdateMaxPartition = 80;
    }
    $fileSource = "{$GLOBALS["WindowsUpdateCachingDir"]}/Partials/Queue.log";
    $LinesCount = $unix->COUNT_LINES_OF_FILE($fileSource);
    if (!is_file($fileSource)) {
        return;
    }
    $md5start = md5_file($fileSource);
    $CheckPartitionPercentage = CheckPartitionPercentage();
    if ($CheckPartitionPercentage > $WindowsUpdateMaxPartition) {
        events("Failed: Storage Partition exceed {$WindowsUpdateMaxPartition}% Stopping retreivals", __LINE__);
        @touch("/etc/squid3/WindowsUpdatePartitionExceed");
        DirectorySize();
        return;
    }
    $WindowsUpdateInProduction = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateInProduction"));
    if ($WindowsUpdateInProduction == 0) {
        if ($unix->IsProductionTime()) {
            $time = $unix->file_time_min("/etc/artica-postfix/pids/WindowsUpdateInProduction");
            if ($time > 15) {
                @unlink("/etc/artica-postfix/pids/WindowsUpdateInProduction");
                @touch("/etc/artica-postfix/pids/WindowsUpdateInProduction");
                events("INFO: Aborting, No download during production time", __LINE__);
                DirectorySize();
            }
            return;
        }
    }
    if (is_file("/etc/squid3/WindowsUpdatePartitionExceed")) {
        @unlink("/etc/squid3/WindowsUpdatePartitionExceed");
    }
    $handle = @fopen($fileSource, "r");
    if (!$handle) {
        events("Fopen failed on {$fileSource}", __LINE__);
        return false;
    }
    $NEWBUFFER = array();
    $URLALREADY = array();
    $NewBuffer = array();
    $FinalSize = 0;
    $FF = 0;
    $c = 0;
    while (!feof($handle)) {
        $buffer = trim(fgets($handle));
        $c++;
        if ($buffer == null) {
            continue;
        }
        $TR = explode("|||", $buffer);
        $LocalFile = $TR[0];
        $URI = $TR[1];
        $ExpectedSize = $TR[2];
        if (!isset($TR[3])) {
            $TR[3] = 1;
        }
        if (isset($URLALREADY[$URI])) {
            continue;
        }
        $URLALREADY[$URI] = true;
        $BaseNameOfFile = basename($URI);
        events("INFO: {$BaseNameOfFile} " . xFormatBytes($ExpectedSize / 1024) . " Retry:{$TR[3]} [{$c}/{$LinesCount}]", __LINE__);
        if (DownloadByRange($URI, $ExpectedSize, $LocalFile)) {
            update_mysql($LocalFile, $URI);
            continue;
        }
        $TR[3] = $TR[3] + 1;
        if ($TR[3] > $WindowsUpdateBandwidthMaxFailed) {
            events("Error: Max retry ({$WindowsUpdateBandwidthMaxFailed}) for filename: {$BaseNameOfFile}", __LINE__);
            SaveToBlacklists($BaseNameOfFile);
            RemoveTempOf($URI, $LocalFile);
            continue;
        }
        $NewBuffer[] = @implode("|||", $TR);
    }
    if (count($NewBuffer) == 0) {
        @unlink($fileSource);
        return;
    }
    events("INFO: add " . count($NewBuffer) . " orders to queue", __LINE__);
    @file_put_contents($fileSource, @implode("\n", $NewBuffer));
    DirectorySize();
}
示例#3
0
function xstart()
{
    $T1 = time();
    $curl = new ccurl();
    $unix = new unix();
    $GLOBALS["MYPID"] = getmypid();
    $pidfile = "/etc/artica-postfix/pids/windowupdate.processor.pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__), true);
    if (count($pids) > 0) {
        while (list($i, $line) = each($pids)) {
            events("Already executed PID:{$i}... aborting ", __LINE__);
        }
        die;
    }
    $TEMPDIR = $unix->TEMP_DIR() . "/WindowsUpdates";
    $rm = $unix->find_program("rm");
    @file_put_contents($pidfile, $GLOBALS["MYPID"]);
    if (is_dir($TEMPDIR)) {
        shell_exec("{$rm} -rf {$TEMPDIR}");
    }
    @mkdir($TEMPDIR, 0755, true);
    $WindowsUpdateMaxPartition = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateMaxPartition"));
    if ($WindowsUpdateMaxPartition == 0) {
        $WindowsUpdateMaxPartition = 80;
    }
    $CheckPartitionPercentage = CheckPartitionPercentage();
    if ($CheckPartitionPercentage > $WindowsUpdateMaxPartition) {
        $time = $unix->file_time_min("/etc/squid3/WindowsUpdatePartitionExceed");
        if ($time > 10) {
            @unlink("/etc/squid3/WindowsUpdatePartitionExceed");
            events("Failed: Storage Partition exceed {$WindowsUpdateMaxPartition}%, Stopping retreivals", __LINE__);
            @touch("/etc/squid3/WindowsUpdatePartitionExceed");
            DirectorySize();
        }
        return;
    }
    $WindowsUpdateInProduction = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateInProduction"));
    if ($WindowsUpdateInProduction == 0) {
        if ($unix->IsProductionTime()) {
            $time = $unix->file_time_min("/etc/artica-postfix/pids/WindowsUpdateInProduction");
            if ($time > 15) {
                @unlink("/etc/artica-postfix/pids/WindowsUpdateInProduction");
                @touch("/etc/artica-postfix/pids/WindowsUpdateInProduction");
                events("INFO: Aborting, No download during production time", __LINE__);
                DirectorySize();
            }
            return;
        }
    }
    if (is_file("/etc/squid3/WindowsUpdatePartitionExceed")) {
        @unlink("/etc/squid3/WindowsUpdatePartitionExceed");
    }
    $q = new mysql_squid_builder();
    $sql = "CREATE TABLE IF NOT EXISTS `windowsupdate` (\n\t\t\t`filemd5` VARCHAR( 90 ) NOT NULL ,\n\t\t\t`zDate` DATETIME NOT NULL ,\n\t\t\t`zUri` VARCHAR( 255 ) NOT NULL ,\n\t\t\t`localpath` VARCHAR( 255 ) NOT NULL ,\n\t\t\t`filesize` BIGINT UNSIGNED DEFAULT '0',\n\t\t\t INDEX ( `filesize` ,`zDate`) ,\n\t\t\t KEY `localpath`(`localpath`),\n\t\t\t KEY `zUri`(`zUri`),\n\t\t\t PRIMARY KEY (`filemd5`)) ENGINE=MYISAM;";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        events("MySQL Failed {$q->mysql_error}", __LINE__);
        die;
    }
    $GLOBALS["WindowsUpdateMaxToPartialQueue"] = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateMaxToPartialQueue"));
    if ($GLOBALS["WindowsUpdateMaxToPartialQueue"] == 0) {
        $GLOBALS["WindowsUpdateMaxToPartialQueue"] = 350;
    }
    $GLOBALS["WindowsUpdateCachingDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateCachingDir");
    if ($GLOBALS["WindowsUpdateCachingDir"] == null) {
        $GLOBALS["WindowsUpdateCachingDir"] = "/home/squid/WindowsUpdate";
    }
    $filepath = "{$GLOBALS["WindowsUpdateCachingDir"]}/Queue.log";
    $WindowsUpdateDownTimeout = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateDownTimeout"));
    if ($WindowsUpdateDownTimeout == 0) {
        $WindowsUpdateDownTimeout = 600;
    }
    $WindowsUpdateMaxToPartialQueue = $GLOBALS["WindowsUpdateMaxToPartialQueue"] * 1000;
    $WindowsUpdateMaxToPartialQueue = $WindowsUpdateMaxToPartialQueue * 1000;
    $LinesCount = $unix->COUNT_LINES_OF_FILE($filepath);
    if (!is_file($filepath)) {
        return;
    }
    $md5start = md5_file($filepath);
    $handle = @fopen($filepath, "r");
    if (!$handle) {
        events("Fopen failed on {$filepath}", __LINE__);
        return false;
    }
    $NEWBUFFER = array();
    $URLALREADY = array();
    $FinalSize = 0;
    $FF = 0;
    $c = 0;
    while (!feof($handle)) {
        $buffer = trim(fgets($handle));
        $c++;
        if ($buffer == null) {
            continue;
        }
        $TR = explode("|||", $buffer);
        $prc = $c / $LinesCount;
        $prc = round($prc * 100);
        $LocalFile = $TR[0];
        $URI = $TR[1];
        $ExpectedSize = 0;
        if (strpos($URI, $GLOBALS["WindowsUpdateCachingDir"]) > 0) {
            events("FOUND! directory in  URI", __LINE__);
            $TTR = explode($GLOBALS["WindowsUpdateCachingDir"], $URI);
            $URI = $TTR[0];
            $LocalFile = "{$GLOBALS["WindowsUpdateCachingDir"]}{$TTR[1]}";
            events("FOUND! URI:{$URI}", __LINE__);
            events("FOUND! NEXT:{$LocalFile}", __LINE__);
        }
        $BASENAMELL = basename($LocalFile);
        if (strlen($BASENAMELL) > 20) {
            $BASENAMELL = substr($BASENAMELL, 0, 17) . "...";
        }
        build_progressG("{$BASENAMELL} {$c}/{$LinesCount} {files}", $prc);
        if (isset($URLALREADY[$URI])) {
            continue;
        }
        $URLALREADY[$URI] = true;
        if (isBlacklisted($URI)) {
            events(basename($URI) . " blacklisted...");
            continue;
        }
        if (is_file($LocalFile)) {
            $size = @filesize($LocalFile);
            if ($size > 5) {
                events("SKIP " . basename($LocalFile) . " " . xFormatBytes($size / 1024), __LINE__);
                update_mysql($LocalFile, $URI);
                continue;
            } else {
                @unlink($LocalFile);
            }
        }
        $dirname = dirname($LocalFile);
        if (!is_dir($dirname)) {
            @mkdir($dirname, true, 0755);
        }
        $curl = new ccurl($URI);
        $Headers = $curl->getHeaders();
        $TIMEDOWN = time();
        $TMPFILE = "{$TEMPDIR}/" . basename($LocalFile);
        $GLOBALS["previousProgress"] = 0;
        $GLOBALS["DOWNLOADED_FILE"] = basename($LocalFile);
        $GLOBALS["TMPFILE"] = $TMPFILE;
        $ExpectedSize = GetTargetedSize($URI);
        if ($ExpectedSize == 0) {
            events("Failed to download {$URI} ( unable to get expected size)", __LINE__);
            continue;
        }
        if ($ExpectedSize > $WindowsUpdateMaxToPartialQueue) {
            $ExpectedSizeText = xFormatBytes($ExpectedSize / 1024, true);
            events(basename($URI) . " ({$ExpectedSizeText} {$ExpectedSize}/{$WindowsUpdateMaxToPartialQueue}) Limit {$WindowsUpdateMaxToPartialQueue} to BigFiles queue", __LINE__);
            AddToPartialQueue($URI, $ExpectedSize, $LocalFile);
            continue;
        }
        $curl = new ccurl($URI);
        $curl->WriteProgress = true;
        $curl->Timeout = $WindowsUpdateDownTimeout * 60;
        $curl->ProgressFunction = "xdownload_progress";
        events("Downloading " . basename($URI) . " to {$TMPFILE} (" . xFormatBytes($ExpectedSize / 1024, true) . " max:{$WindowsUpdateDownTimeout} Minutes)", __LINE__);
        if (!$curl->GetFile($TMPFILE)) {
            events("Failed: TMP: &laquo;{$TMPFILE}&raquo;", __LINE__);
            events("Failed: URL: &laquo;{$URI}&raquo;", __LINE__);
            events("Failed: After: " . $unix->distanceOfTimeInWords($TIMEDOWN, time(), true), __LINE__);
            events("Failed: With error: {$curl->error} http code: {$curl->CURLINFO_HTTP_CODE} (" . count($curl->CURL_ALL_INFOS) . ") infos", __LINE__);
            reset($curl->CURL_ALL_INFOS);
            while (list($index, $value) = each($curl->CURL_ALL_INFOS)) {
                events("Failed: &laquo;{$index}&raquo; [{$value}]", __LINE__);
            }
            if ($curl->CURLINFO_HTTP_CODE == 404) {
                continue;
            }
            @unlink($TMPFILE);
            $NEWBUFFER[] = "{$buffer}";
            continue;
        }
        if (!is_file($TMPFILE)) {
            events("Fatal {$TMPFILE}: no such file", __LINE__);
            continue;
        }
        $size = filesize($TMPFILE);
        $sizeT = xFormatBytes($size / 1024);
        if ($size < 5) {
            @unlink($TMPFILE);
            events("Failed: File less than 5 Bytes ({$size}), aborting", __LINE__);
            continue;
        }
        if ($ExpectedSize > 0) {
            if ($size != $ExpectedSize) {
                $ExpectedSizeT = xFormatBytes($ExpectedSize / 1024);
                events("Failed: corrupted download " . basename($URI) . " expected size {$ExpectedSizeT}/{$ExpectedSize} current:({$sizeT}/{$size})", __LINE__);
                @unlink($TMPFILE);
                continue;
            }
        }
        if (!@copy($TMPFILE, $LocalFile)) {
            @unlink($TMPFILE);
            events("Failed: Translating to {$LocalFile}", __LINE__);
            $NEWBUFFER[] = "{$buffer}";
            continue;
        }
        events("Success: " . basename($TMPFILE) . " ({$sizeT})", __LINE__);
        @unlink($TMPFILE);
        $FF++;
        $size = @filesize($LocalFile);
        $FinalSize = $FinalSize + $size;
        update_mysql($LocalFile, $URI);
    }
    $took = $unix->distanceOfTimeInWords($T1, time(), true);
    if ($FinalSize > 0) {
        $CURLINFO_SPEED_DOWNLOAD = $curl->CURL_ALL_INFOS["CURLINFO_SPEED_DOWNLOAD"];
        events("Downloaded {$FF} files for " . xFormatBytes($FinalSize / 1024, true) . " ({$CURLINFO_SPEED_DOWNLOAD}) took: {$took}", __LINE__);
    }
    $md5finish = md5_file($filepath);
    if (count($NEWBUFFER) > 0) {
        events("Retry " . count($NEWBUFFER) . " requests next time...", __LINE__);
        @file_put_contents($filepath, @implode("\n", $NEWBUFFER));
    } else {
        events("No new file downloaded....", __LINE__);
        events("Removing queue {$filepath}", __LINE__);
        @unlink($filepath);
    }
    DirectorySize();
    events("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * * * END TOOK: {$took} * * *", __LINE__);
}