コード例 #1
0
ファイル: exec.sys-stats.php プロジェクト: articatech/artica
function RXTX()
{
    $unix = new unix();
    $Cache = unserialize(@file_get_contents("/etc/artica-postfix/RXTX.array"));
    $ifconfig = $unix->find_program("ifconfig");
    exec("{$ifconfig} -a 2>&1", $results);
    foreach ($results as $line) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#^([a-z0-9]+)\\s+Link#", $line, $re)) {
            $Interface = $re[1];
            continue;
        }
        if (preg_match("#RX bytes:([0-9]+).*?TX bytes:([0-9]+)#", $line, $re)) {
            $ARRAY[$Interface]["RX"] = $re[1];
            $ARRAY[$Interface]["TX"] = $re[2];
            continue;
        }
    }
    $q = new influx();
    $q = new postgres_sql();
    $date = date("Y-m-d H:i:s");
    $hostname = $unix->hostname_g();
    while (list($Interface, $array) = each($ARRAY)) {
        $RX = $array["RX"];
        $TX = $array["TX"];
        $OLD_RX = intval($Cache[$Interface]["RX"]);
        $OLD_TX = intval($Cache[$Interface]["TX"]);
        if ($OLD_RX > $RX) {
            continue;
        }
        if ($OLD_TX > $TX) {
            continue;
        }
        $RX_NEW = $RX - $OLD_RX;
        $TX_NEW = $TX - $OLD_TX;
        if ($GLOBALS["VERBOSE"]) {
            echo "{$Interface} Rec:" . xFormatBytes($RX_NEW / 1024) . " Trans:" . xFormatBytes($TX_NEW / 1024) . "\n";
        }
        $q->QUERY_SQL("INSERT INTO ethrxtx (zdate,tx,rx,eth,proxyname) VALUES ('{$date}','{$TX_NEW}','{$RX_NEW}','{$Interface}','{$hostname}')");
    }
    @file_put_contents("/etc/artica-postfix/RXTX.array", serialize($ARRAY));
}
コード例 #2
0
ファイル: exec.sys-stats.php プロジェクト: BillTheBest/1.6.x
function RXTX()
{
    $unix = new unix();
    $Cache = unserialize(@file_get_contents("/etc/artica-postfix/RXTX.array"));
    $ifconfig = $unix->find_program("ifconfig");
    exec("{$ifconfig} -a 2>&1", $results);
    foreach ($results as $line) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#^([a-z0-9]+)\\s+Link#", $line, $re)) {
            $Interface = $re[1];
            continue;
        }
        if (preg_match("#RX bytes:([0-9]+).*?TX bytes:([0-9]+)#", $line, $re)) {
            $ARRAY[$Interface]["RX"] = $re[1];
            $ARRAY[$Interface]["TX"] = $re[2];
            continue;
        }
    }
    $q = new influx();
    while (list($Interface, $array) = each($ARRAY)) {
        $RX = $array["RX"];
        $TX = $array["TX"];
        $OLD_RX = intval($Cache[$Interface]["RX"]);
        $OLD_TX = intval($Cache[$Interface]["TX"]);
        if ($OLD_RX > $RX) {
            continue;
        }
        if ($OLD_TX > $TX) {
            continue;
        }
        $RX_NEW = $RX - $OLD_RX;
        $TX_NEW = $TX - $OLD_TX;
        if ($GLOBALS["VERBOSE"]) {
            echo "{$Interface} Rec:" . xFormatBytes($RX_NEW / 1024) . " Trans:" . xFormatBytes($TX_NEW / 1024) . "\n";
        }
        $INFLX["fields"]["TX"] = $TX_NEW;
        $INFLX["fields"]["RX"] = $RX_NEW;
        $INFLX["tags"]["ETH"] = $Interface;
        $INFLX["tags"]["proxyname"] = $unix->hostname_g();
        $q->insert("ethrxtx", $INFLX);
        $INFLX = array();
    }
    @file_put_contents("/etc/artica-postfix/RXTX.array", serialize($ARRAY));
}
コード例 #3
0
function DownloadByRange($URI, $EXPECTED_SIZE = 0, $LocalFile = null)
{
    $HTTP_CODE = 0;
    $Time = null;
    if (!isset($GLOBALS["WindowsUpdateCachingDir"])) {
        $GLOBALS["WindowsUpdateCachingDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateCachingDir");
        if ($GLOBALS["WindowsUpdateCachingDir"] == null) {
            $GLOBALS["WindowsUpdateCachingDir"] = "/home/squid/WindowsUpdate";
        }
    }
    $WindowsUpdateBandwidthPartial = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateBandwidthPartial"));
    $WindowsUpdateUseLocalProxy = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateUseLocalProxy"));
    $WindowsUpdateInterface = @file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateInterface");
    if ($WindowsUpdateBandwidthPartial == 0) {
        $WindowsUpdateBandwidthPartial = 512;
    }
    if ($EXPECTED_SIZE == 0) {
        $EXPECTED_SIZE = GetTargetedSize($URI);
    }
    $EXPECTED_SIZE_TEXT = xFormatBytes($EXPECTED_SIZE / 1024);
    $BaseNameOfFile = basename($URI);
    $unix = new unix();
    $curl = $unix->find_program("curl");
    $rm = $unix->find_program("rm");
    $mv = $unix->find_program("mv");
    $TempDir = "{$GLOBALS["WindowsUpdateCachingDir"]}/Partials/" . md5($URI);
    $TempFile = "{$TempDir}/FILE";
    if (is_file($TempFile)) {
        $size = @filesize($TempFile);
    }
    @mkdir($TempDir, 0755, true);
    $WorkingPort = $SquidMgrListenPort = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort"));
    @unlink("{$TempDir}/stderr.txt");
    $f[] = "{$curl} --location";
    if ($WindowsUpdateUseLocalProxy == 1) {
        events("Downloading {$BaseNameOfFile} Proxy:127.0.0.1:{$WorkingPort}", __LINE__);
        $f[] = "--proxy 127.0.0.1:{$WorkingPort} --url \"{$URI}\"";
    }
    if ($WindowsUpdateInterface != null) {
        $INTERFACES = $unix->NETWORK_ALL_INTERFACES();
        $ipaddr = $INTERFACES[$WindowsUpdateInterface]["IPADDR"];
        if ($ipaddr == "0.0.0.0") {
            $ipaddr = null;
        }
        if ($ipaddr != null) {
            events("Downloading {$BaseNameOfFile} Interface:{$ipaddr}", __LINE__);
            $f[] = "--interface {$ipaddr}";
        }
    }
    $f[] = "--show-error --write-out \"RRRR:%{http_code} TTT:%{time_total}\"";
    $f[] = "--stderr {$TempDir}/stderr.txt";
    $f[] = "--output \"{$TempFile}\"";
    $f[] = "--continue-at -";
    $f[] = "--limit-rate {$WindowsUpdateBandwidthPartial}K";
    $f[] = "--url \"{$URI}\"";
    $f[] = "2>&1";
    $cmd = @implode(" ", $f);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    $T1 = time();
    events("Downloading {$BaseNameOfFile} {$EXPECTED_SIZE_TEXT} limit:{$WindowsUpdateBandwidthPartial}Kb/s", __LINE__);
    exec($cmd, $results);
    $stderr = trim(@file_get_contents("{$TempDir}/stderr.txt"));
    if ($stderr != null) {
        while (list($num, $val) = each($results)) {
            if (preg_match("#RRRR:(.+?)\\s+TTT:(.+)#", $val, $re)) {
                $HTTP_CODE = $re[1];
                $Time = $re[2];
                continue;
            }
            events("INFO: {$val}", __LINE__);
        }
        if (intval($HTTP_CODE) != 200) {
            if (preg_match("#Resuming transfer from byte position\\s+([0-9]+)#", $stderr, $re)) {
                events("Downloading {$BaseNameOfFile} stopped duration:{$Time} HTTP Code:{$HTTP_CODE} and resuming position at : {$re[1]} (" . xFormatBytes($re[1] / 1024) . ")", __LINE__);
                return false;
            }
            events("Failed: duration:{$Time} {$BaseNameOfFile} with error {$HTTP_CODE} «{$stderr}»", __LINE__);
            return false;
        }
    }
    $size = @filesize($TempFile);
    $size_text = xFormatBytes($size);
    events("INFO: {$BaseNameOfFile} ({$size_text}) HTTP Code:{$HTTP_CODE} Duration:{$Time}", __LINE__);
    if ($size < $EXPECTED_SIZE) {
        events("Warning: {$BaseNameOfFile} {$size} is not {$EXPECTED_SIZE} (broken download) retry next time", __LINE__);
        return false;
    }
    events("INFO: {$BaseNameOfFile} move to {$LocalFile}", __LINE__);
    @mkdir(dirname($LocalFile));
    $cmd = "{$mv} \"{$TempFile}\" \"{$LocalFile}\"";
    exec($cmd, $output, $return_val);
    if ($return_val == 0) {
        events("Success: Retranslate {$BaseNameOfFile} to target directory", __LINE__);
        if (is_dir($TempDir)) {
            shell_exec("{$rm} -rf {$TempDir}");
        }
        return true;
    } else {
        events("Failed: {$BaseNameOfFile}, unable to move to target directory!", __LINE__);
        return false;
    }
}
コード例 #4
0
function delete($path)
{
    if (is_file($path)) {
        $size = @filesize($path);
        events("INFO: Remove {$path} (" . xFormatBytes($size / 1024) . ")", __LINE__);
        @unlink($path);
    }
    $sql = "DELETE FROM windowsupdate WHERE `localpath`='{$path}'";
    $q = new mysql_squid_builder();
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        events("FATAL: MySQL error {$q->mysql_error}", __LINE__);
        return;
    }
    events("INFO: Remove {$path} fro MySQL Done", __LINE__);
}