Beispiel #1
0
function sargToFile($filePath)
{
    if (!is_file($filePath)) {
        progress("Fatal {$filePath} no such file", 10);
        return;
    }
    $unix = new unix();
    $sarg_bin = $unix->find_program("sarg");
    $linesNumber = $unix->COUNT_LINES_OF_FILE($filePath);
    $basename = basename($filePath);
    progress("Open {$filePath} {$linesNumber} lines", 10);
    $sock = new sockets();
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $nice = EXEC_NICE();
    $usersauth = false;
    $t = time();
    $squid = new squidbee();
    if ($squid->is_auth()) {
        $usersauth = true;
    }
    if ($usersauth) {
        events("User authentification enabled");
        $u = " -i ";
    } else {
        events("User authentification disabled");
    }
    $t = time();
    $cmd = "{$nice}{$sarg_bin} {$u}-f /etc/squid3/sarg.conf -l \"{$filePath}\" -o \"{$SargOutputDir}\" -x -z 2>&1";
    progress("Open {$cmd}", 10);
    exec($cmd, $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#SARG: OPTION:#", $line)) {
            continue;
        }
        events($line);
    }
    if ($basename == "sarg.log") {
        continue;
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    sarg_admin_events("{$basename} generated took: {$took}\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "sarg");
    build_index_page();
}