Пример #1
0
function ParseLogsDir()
{
    $d = 0;
    $h = 0;
    $sock = new sockets();
    $workingDir = $sock->GET_INFO("SquidOldLogsDefaultDir");
    if (!($handle = opendir($workingDir))) {
        @mkdir($workingDir, 0755, true);
        return;
    }
    $squidtail = new squid_tail();
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$workingDir}/{$filename}";
        if (!is_file($targetFile)) {
            continue;
        }
        $d++;
        $h++;
        $c = 0;
        if ($d > 300) {
            if (systemMaxOverloaded()) {
                $array_load = sys_getloadavg();
                $internal_load = $array_load[0];
                events("ParseSquidLogBrutProcess()::{$workingDir}:: Overloaded: {$internal_load} system, break loop...", __LINE__);
                break;
            }
            $d = 0;
        }
        $handle = @fopen($targetFile, "r");
        if (!$handle) {
            events("Failed to open file", __LINE__);
            continue;
        }
        while (!feof($handle)) {
            $c++;
            $buffer = trim(fgets($handle, 4096));
            if (!$squidtail->parse_tail($buffer, null)) {
                continue;
            }
        }
    }
}
Пример #2
0
function UserSizeRTT_oldfiles()
{
    if (!($handle = opendir("/var/log/artica-postfix/squid-RTTSize"))) {
        ufdbguard_admin_events("Fatal: /var/log/artica-postfix/squid-RTTSize no such directory", __FUNCTION__, __FILE__, __LINE__, "stats");
        return;
    }
    $q = new mysql_squid_builder();
    $classParse = new squid_tail();
    $CurrentFile = date("YmdH");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . ":: scanning /var/log/artica-postfix/squid-RTTSize\n";
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        if ($filename == $CurrentFile) {
            continue;
        }
        $targetFile = "/var/log/artica-postfix/squid-RTTSize/{$filename}";
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . ":: {$targetFile}\n";
        }
        $time = filemtime($targetFile);
        $tablesuffix = date("Ymd", $time);
        $tablename = "UserSizeD_{$tablesuffix}";
        if (!$q->CreateUserSizeRTT_day($tablename)) {
            ufdbguard_admin_events("{$tablename}: Query failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "stats");
            return;
        }
        $RTTSIZEARRAY = unserialize(@file_get_contents($targetFile));
        $Hour = date('H', $time);
        $date = date("Y-m-d H:00:00", $time);
        //$sql="INSERT IGNORE INTO `$tablename` (`zMD5`,`uid`,`zdate`,
        //`ipaddr`,`hostname`,`account`,`MAC`,`UserAgent`,`size`,`hits`,`hour`) VALUES ".@implode(",", $rows);
        if (count($RTTSIZEARRAY["UID"]) > 0) {
            $f = array();
            $prefix = "INSERT IGNORE INTO `{$tablename}` (`zMD5`,`zdate`,`uid`,`size`,`hits`,`hour`) VALUES ";
            while (list($username, $array) = each($RTTSIZEARRAY["UID"])) {
                $hits = $array["HITS"];
                $size = $array["SIZE"];
                $md5 = md5("{$username}{$date}{$Hour}");
                echo $username . " HITS:{$hits} SIZE:{$size}\n";
                $f[] = "('{$md5}','{$date}','{$username}','{$size}','{$hits}','{$Hour}')";
            }
            if (count($f) > 0) {
                $q->QUERY_SQL($prefix . @implode(",", $f));
                if (!$q->ok) {
                    ufdbguard_admin_events("Fatal: {$q->mysql_error}\n", __FUNCTION__, __FILE__, __LINE__, "stats");
                    return;
                }
            }
        }
        if (count($RTTSIZEARRAY["IP"]) > 0) {
            $f = array();
            $prefix = "INSERT IGNORE INTO `{$tablename}` (`zMD5`,`zdate`,`ipaddr`,`hostname`,`size`,`hits`,`hour`) VALUES ";
            while (list($ip, $array) = each($RTTSIZEARRAY["IP"])) {
                $hits = $array["HITS"];
                $size = $array["SIZE"];
                $md5 = md5("{$ip}{$date}{$Hour}");
                $hostname = $classParse->GetComputerName($ip);
                echo $ip . "/{$hostname} HITS:{$hits} SIZE:{$size}\n";
                $f[] = "('{$md5}','{$date}','{$ip}','{$hostname}','{$size}','{$hits}','{$Hour}')";
            }
            if (count($f) > 0) {
                $q->QUERY_SQL($prefix . @implode(",", $f));
                if (!$q->ok) {
                    ufdbguard_admin_events("Fatal: {$q->mysql_error}\n", __FUNCTION__, __FILE__, __LINE__, "stats");
                    return;
                }
            }
        }
        if (count($RTTSIZEARRAY["MAC"]) > 0) {
            $f = array();
            $prefix = "INSERT IGNORE INTO `{$tablename}` (`zMD5`,`zdate`,`MAC`,`size`,`hits`,`hour`) VALUES ";
            while (list($mac, $array) = each($RTTSIZEARRAY["MAC"])) {
                $hits = $array["HITS"];
                $size = $array["SIZE"];
                $md5 = md5("{$mac}{$date}{$Hour}");
                echo "{$mac} HITS:{$hits} SIZE:{$size}\n";
                $f[] = "('{$md5}','{$date}','{$mac}','{$size}','{$hits}','{$Hour}')";
            }
            if (count($f) > 0) {
                $q->QUERY_SQL($prefix . @implode(",", $f));
                if (!$q->ok) {
                    ufdbguard_admin_events("Fatal: {$q->mysql_error}\n", __FUNCTION__, __FILE__, __LINE__, "stats");
                    return;
                }
            }
        }
        @unlink($targetFile);
    }
}
Пример #3
0
function parseline($buffer)
{
    $tail = new squid_tail();
    $return = array();
    $ipaddr = null;
    if (preg_match("#^([0-9\\.]+)\\s+([0-9\\-]+)\\s+(.*?)\\s+([A-Z_]+)\\/([0-9]+)\\s+([0-9]+)\\s+([A-Z_]+)\\s+(.*?)\\s+(.*?)\\s+([A-Z_]+)\\/(.*?)\\s+#is", $buffer, $re)) {
        $cached = 0;
        $time = $re[1];
        $hostname = $re[3];
        $SquidCode = $re[4];
        $code_error = $re[5];
        $size = $re[6];
        $proto = $re[7];
        $uri = $re[8];
        $uid = $re[9];
        $basenameECT = $re[10];
        $remote_ip = $re[11];
        if (trim($uid) == "-") {
            $uid = null;
        }
        if (preg_match("#^[0-9\\.]+\$#", $hostname)) {
            $ipaddr = $hostname;
            $hostname = null;
        }
        $Fdate = date("Y-m-d H:i:s", $time);
        $xtime = strtotime($Fdate);
        if (preg_match("#^(.+?)\\\\(.+)#", $uid, $ri)) {
            $uid = $ri[2];
        }
        if ($tail->CACHEDORNOT($SquidCode)) {
            $cached = 1;
        }
        $return = array("TIME" => $time, "IPADDR" => $ipaddr, "CACHED" => $cached, "UID" => $uid, "HOSTNAME" => $hostname, "ERRCODE" => $code_error, "SIZE" => $size, "PROTO" => $proto, "URI" => $uri, "REMOTE" => $remote_ip);
        return $return;
    } else {
        events("no match \"{$buffer}\"");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "NO MATCH\n{$buffer}\n";
    }
}