コード例 #1
0
function Compile()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid}\n";
        }
        return;
    }
    $t = time();
    $q = new mysql_squid_builder();
    echo "**** LIST_TABLES_CATEGORIES_PERSO *****\n";
    $tablescat = $q->LIST_TABLES_CATEGORIES_PERSO();
    $source_dir = "/home/artica/categories_perso";
    if (count($tablescat) == 0) {
        echo "tablescat = 0\n";
        return;
    }
    $i = 0;
    while (list($tablename, $ligne) = each($tablescat)) {
        if (preg_match("#^categoryuris#", $tablename)) {
            continue;
        }
        $COUNT_ROWS = $q->COUNT_ROWS($tablename);
        if ($COUNT_ROWS == 0) {
            continue;
        }
        echo " **** {$tablename} {$COUNT_ROWS} ITEMS *****\n";
        $Dir = "{$source_dir}/{$tablename}";
        @mkdir("{$Dir}", 0777, true);
        echo "{$tablename}: Building {$Dir}/domains";
        @unlink("{$Dir}/domains");
        @chmod("{$Dir}/domains", 0777);
        $sql = "SELECT pattern FROM {$tablename} WHERE enabled=1 ORDER BY pattern INTO OUTFILE '{$Dir}/domains' LINES TERMINATED BY '\n';";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            echo "{$tablename}: {$q->mysql_error}\n";
            continue;
        }
        $handle = @fopen("{$Dir}/domains", "r");
        if (!$handle) {
            echo "Failed to open file {$Dir}/domains\n";
            continue;
        }
        $DestDB = "{$Dir}/domains.db";
        @unlink($DestDB);
        $db_desttmp = dba_open($DestDB, "n", "db4");
        if (!$db_desttmp) {
            echo "Unable to Create {$DestDB}\n";
            continue;
        }
        dba_close($db_desttmp);
        $db_dest = dba_open($DestDB, "w", "db4");
        @chmod($DestDB, 0777);
        if (!$db_dest) {
            echo "Unable to open for `writing` \"{$DestDB}\"\n";
            continue;
        }
        while (!feof($handle)) {
            $www = trim(fgets($handle, 4096));
            $www = trim(str_replace('"', "", $www));
            if ($www == null) {
                continue;
            }
            $www = strtolower($www);
            if (!dba_insert("{$www}", "yes", $db_dest)) {
                echo "dba_insert({$www},yes... false\n";
                continue;
            }
        }
        $i++;
        dba_close($db_dest);
        @fclose($handle);
        @unlink("{$Dir}/domains");
    }
    stats_admin_events(2, "1%) {$i} Personal tables compiled took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
}
コード例 #2
0
function writelogs_squid($text, $function = null, $file = null, $line = 0, $category = null, $nosql = false)
{
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        $GLOBALS["CLASS_UNIX"] = new unix();
    }
    if (!isset($GLOBALS["MYPID"])) {
        $GLOBALS["MYPID"] = @getmypid();
    }
    if (!isset($GLOBALS["AS_ROOT"])) {
        if (posix_getuid() == 0) {
            $GLOBALS["AS_ROOT"] = true;
        } else {
            $GLOBALS["AS_ROOT"] = false;
        }
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    if ($file != null) {
        $me = basename($file);
    } else {
        $me = basename(__FILE__);
    }
    $date = @date("H:i:s");
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $sourcefile = basename($trace[1]["file"]);
            $sourcefunction = $trace[1]["function"];
            $sourceline = $trace[1]["line"];
        }
    }
    if ($function == __FUNCTION__) {
        $function = null;
    }
    if ($function == null) {
        $function = $sourcefunction;
    }
    if ($line == 0) {
        $line = $sourceline;
    }
    if ($file == null) {
        $line = $sourcefile;
    }
    if (function_exists("stats_admin_events")) {
        stats_admin_events(2, $text, "{$date} {$me}" . "[" . $GLOBALS["MYPID"] . "/{$internal_load}]:{$category}::{$function}", $sourcefile, $sourceline);
    }
    if ($GLOBALS["AS_ROOT"]) {
        $logFile = "/var/log/artica-squid-stats.log";
        if (is_file($logFile)) {
            $size = filesize($logFile);
            if ($size > 5000000) {
                unlink($logFile);
            }
        }
        $f = fopen($logFile, 'a');
        fwrite($f, "{$date} {$me}" . "[" . $GLOBALS["MYPID"] . "/{$internal_load}]:{$category}::{$function}::{$line}: {$text}\n");
        fclose($f);
    }
    if ($nosql) {
        return;
    }
    if (function_exists("ufdbguard_admin_events")) {
        ufdbguard_admin_events($text, $function, $file, $line, $category);
    }
}
コード例 #3
0
function last_days()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "last_days Loading done...\nTimeFile:{$timefile}\n";
    }
    $unix = new unix();
    if (!$GLOBALS["VERBOSE"]) {
        if (SquidStatisticsTasksOverTime()) {
            stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
            return;
        }
    }
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 7200) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timeexec} <> 7200...\n";
            }
            return;
        }
    }
    $q = new mysql_squid_builder();
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    @file_put_contents($timefile, time());
    $current_table = date("Ymd") . "_hour";
    $t = time();
    $sql = "SELECT DATE_FORMAT(zDate,'%Y%m%d') AS `suffix` FROM tables_day \n\t\t\tWHERE DAY(zDate)<DAY(NOW()) AND YEAR(zDate) = YEAR(NOW()) AND MONTH(zDate) = MONTH(NOW()) AND zDate>DATE_SUB(NOW(),INTERVAL 7 DAY)";
    $results = $q->QUERY_SQL($sql);
    $num = mysql_num_rows($results);
    if ($num == 0) {
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $current_table = $ligne["suffix"] . "_hour";
        if (!$q->TABLE_EXISTS($current_table)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$current_table} no such table\n";
            }
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Processing {$current_table}\n";
        }
        if (!$GLOBALS["VERBOSE"]) {
            if (SquidStatisticsTasksOverTime()) {
                stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                return;
            }
        }
        _xprocess_table($current_table, true);
        $f[] = $current_table;
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    stats_admin_events(2, "Processing categorization of {$num} tables {$took}", @implode("\n", $f), __FILE__, __LINE__);
}
コード例 #4
0
function backup_squidlogs($tablename)
{
    $q = new mysql_squid_builder();
    $unix = new unix();
    $mysqldump = $unix->find_program("mysqldump");
    $tar = $unix->find_program("tar");
    $mysqldump_prefix = "{$mysqldump} {$q->MYSQL_CMDLINES} --skip-add-locks --insert-ignore --quote-names --skip-add-drop-table --verbose --force {$q->database} ";
    $container = "/home/artica/squid/backup-statistics/{$tablename}.sql";
    if (is_file($container)) {
        return;
    }
    $cmdline = "{$mysqldump_prefix}{$tablename} >{$container}";
    echo "{$cmdline}\n";
    if ($GLOBALS["VERBOSE"]) {
        echo "\n*******\n{$cmdline}\n*******\n";
    }
    exec($cmdline, $resultsZ);
    if (!$unix->Mysql_TestDump($resultsZ, $container)) {
        stats_admin_events(0, "Fatal Error: day: Dump failed {$tablename}", "", __FILE__, __LINE__);
    }
    $size = @filesize($container);
    @mkdir("/home/artica/squid/backup-statistics", 0755, true);
    chdir("/home/artica/squid/backup-statistics");
    $cmdline = "{$tar} cfz {$container}.tar.gz {$container} 2>&1";
    $resultsZ = array();
    exec($cmdline, $resultsZ);
    if ($GLOBALS["VERBOSE"]) {
        while (list($a, $b) = each($resultsZ)) {
            echo "Compress: `{$b}`\n";
        }
    }
    if (!$unix->TARGZ_TEST_CONTAINER("{$container}.tar.gz")) {
        stats_admin_events(0, "Test container failed: {$container}.tar.gz", "", __FILE__, __LINE__);
        @unlink($container);
        @unlink("{$container}.tar.gz");
        return;
    }
    $size = FormatBytes($size / 1024);
    @unlink($container);
    return true;
}
コード例 #5
0
function members_uid()
{
    $GLOBALS["Q"] = new mysql_squid_builder();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading...\n";
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading done...\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if (!$GLOBALS["SCHEDULED"]) {
            if ($timeexec < 540) {
                return;
            }
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    if (isset($GLOBALS["members_uid_executed"])) {
        return;
    }
    $GLOBALS["members_uid_executed"] = true;
    $q = new mysql_squid_builder();
    $sql = "SELECT tablename,zDate FROM `tables_day` WHERE members_uid=0 AND zDate<DATE_SUB(NOW(),INTERVAL 1 DAY)";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo "############# ERROR #########\n{$q->mysql_error}\\Line:" . __LINE__ . "\n#############\n";
        }
    }
    if (mysql_num_rows($results) > 0) {
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $date = $ligne["zDate"];
            $time = strtotime($date . " 00:00:00");
            if (SquidStatisticsTasksOverTime()) {
                stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                return;
            }
            $tablename = $ligne["tablename"];
            if ($q->TABLE_EXISTS($tablename)) {
                if (members_uid_from_dansguardian_events($tablename, $time)) {
                    $q->QUERY_SQL("UPDATE tables_day SET members_uid=1 WHERE tablename='{$tablename}'");
                    if (SquidStatisticsTasksOverTime()) {
                        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                        return;
                    }
                    continue;
                }
            }
            $hourtable = date("Ymd", $time) . "_hour";
            if ($q->TABLE_EXISTS($hourtable)) {
                if (members_uid_from_hourtable($hourtable, $time)) {
                    $q->QUERY_SQL("UPDATE tables_day SET members_uid=1 WHERE tablename='{$tablename}'");
                    if (SquidStatisticsTasksOverTime()) {
                        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                        return;
                    }
                    continue;
                }
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "############# ERROR #########\nNO TABLE FOR {$date}\n#############\n";
            }
        }
    }
}
コード例 #6
0
function squid_running_schedules()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        _statussquid("{$pid} already executed since {$timepid}Mn");
        if ($timepid < 5) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 4) {
            _statussquid("Current {$time}Mn need 5Mn");
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $BASEDIR = "/usr/share/artica-postfix";
    $SQUIDEnable = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (function_exists("systemMaxOverloaded")) {
        if (systemMaxOverloaded()) {
            _statussquid("Overloaded system, aborting...");
            return;
        }
    }
    if ($SQUIDEnable == 0) {
        return;
    }
    _statussquid("squid_running_schedules");
    shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.logfile_daemon-parse.php --tables-primaires >/dev/null 2>&1 &");
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/ufdb.rules_toolbox_left.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/dansguardian2.mainrules.php rules-toolbox-left >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_mem_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --mem-status >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/SQUID_MGR_INFO.DB";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --info >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_stores_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 20) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --store-status >/dev/null 2>&1 &");
    }
    $filetimeF = '/etc/artica-postfix/pids/Winbindd_privileged_SQUID.time';
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        $GLOBALS["CLASS_UNIX"]->Winbindd_privileged_SQUID();
        @unlink($filetimeF);
        @file_put_contents($filetimeF, time());
    }
    $filetimeF = '/etc/artica-postfix/pids/EnableKerbAuth.time';
    $EnableKerbAuth = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerbAuth"));
    if ($EnableKerbAuth == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 5) {
            @unlink($filetimeF);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.kerbauth.php --pinglic >/dev/null 2>&1 &");
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = '/etc/artica-postfix/pids/DisableGoogleSSL.time';
    $DisableGoogleSSL = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableGoogleSSL"));
    if ($DisableGoogleSSL == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($GLOBALS["CLASS_UNIX"]->file_time_min($filetime) > 4320) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.nosslsearch.google.com.php --run >/dev/null 2>&1 &");
            @unlink($filetimeF);
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.RTTZ_WORKSHOURS.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.hours.php --rtt >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.tables_hours.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.hours.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.Defaultschedules.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --defaults-schedules");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        @unlink("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time");
        @file_put_contents("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time", time());
        stats_admin_events(2, "Launching importation tables task", null, __FILE__, __LINE__);
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.central.php --import");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.not-categorized.php.not_categorized_scan.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.not-categorized.php --recategorize >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.totals.php.donnees_interface.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 30) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.totals.php --interface >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.interface-size.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 14) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 1880) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quota-week.parser.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.parser.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 19) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.parser.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 19) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.proto.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.hourly.tables.php.current_access_db.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 9) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.hourly.tables.php --current_access >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.hourly.tables.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 64) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.hourly.tables.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.quotaday.php.start.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quotaday.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.quotaday.php.quotatemp.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quotaday.php --quotatemp >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid-searchwords.php.searchwords_hour.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid-searchwords.php --hour >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/YoutubeByHour.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.youtube.days.php --youtube-hours >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.notcached-week.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 30) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.notcached-week.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.protos.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 240) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.protos.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.php.rotate_logs.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --rotate >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.rotate.php >/dev/null 2>&1 &");
    }
    $SquidEnforceRules = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidEnforceRules"));
    if ($SquidEnforceRules == 1) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squidcache.php >/dev/null 2>&1 &");
    }
    $timefile = "/usr/share/artica-postfix/ressources/logs/web/squid_redirectors_status.db";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 10) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --redirector-array >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.dansguardian.injector.php.ParseAllUfdbs.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.dansguardian.injector.php --blocked >/dev/null 2>&1 &");
    }
}
コード例 #7
0
function week_uris_blocked($asPid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    $myfile = basename(__FILE__);
    if ($unix->process_exists($pid, $myfile)) {
        return;
    }
    $tStart = time();
    if ($GLOBALS["VERBOSE"]) {
        echo "Create current week table\n";
    }
    $GLOBALS["Q"]->CreateWeekBlockedTable();
    if (!$GLOBALS["REBUILD"]) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Rebuild is not ordered\n";
        }
    }
    if ($GLOBALS["REBUILD"]) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Rebuild tables...\n";
        }
        $GLOBALS["Q"]->QUERY_SQL("UPDATE tables_day SET weekbdone=0 WHERE weekbdone=1");
    }
    $sql = "SELECT tablename,DATE_FORMAT( zDate, '%Y%m%d' ) AS tablesource,\n\t DAYOFWEEK(zDate) as DayNumber,WEEK( zDate ) AS tweek,\n\t YEAR( zDate ) AS tyear FROM tables_day WHERE weekbdone=0 AND zDate < DATE_SUB( NOW( ) , INTERVAL 1 DAY ) ORDER BY zDate";
    $unix = new unix();
    $results = $GLOBALS["Q"]->QUERY_SQL($sql);
    if (!$GLOBALS["Q"]->ok) {
        stats_admin_events(0, "[Weekly]: Fatal  MySQL error on `tables_day`", "{$GLOBALS["Q"]->mysql_error}", __FILE__, __LINE__);
        return;
    }
    $c = 0;
    $FailedTables = 0;
    if ($GLOBALS["VERBOSE"]) {
        echo mysql_num_rows($results) . " rows\n";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "\n*********** WEEK {$ligne["tweek"]} of year {$ligne["tyear"]} ***********\n";
        }
        continue;
        $week_table = "{$ligne["tyear"]}{$ligne["tweek"]}_blocked_week";
        if ($GLOBALS["VERBOSE"]) {
            echo "Week Table:{$week_table}  - > CreateWeekBlockedTable('{$ligne["tyear"]}{$ligne["tweek"]}')\n";
        }
        if (!$GLOBALS["Q"]->CreateWeekBlockedTable("{$ligne["tyear"]}{$ligne["tweek"]}")) {
            ufdbguard_admin_events("Fatal: {$GLOBALS["Q"]->mysql_error} on `{$week_table}` (CREATE)", __FUNCTION__, __FILE__, __LINE__, "stats");
            continue;
        }
        $DayNumber = $ligne["DayNumber"];
        $tablesource = "{$ligne["tablesource"]}_blocked";
        $tablesources[] = $tablesource;
        if ($GLOBALS["VERBOSE"]) {
            echo "Table source :{$week_table}  - > _week_uris_blocked_perform({$tablesource},{$week_table},{$DayNumber})\n";
        }
        $t = time();
        if (_week_uris_blocked_perform($tablesource, $week_table, $DayNumber)) {
            $GLOBALS["Q"]->QUERY_SQL("UPDATE tables_day SET weekbdone=1 WHERE tablename='{$ligne["tablename"]}'");
            $c++;
        } else {
            $FailedTables++;
        }
        if (SquidStatisticsTasksOverTime()) {
            stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
            return;
        }
    }
    $took = $unix->distanceOfTimeInWords($tStart, time(), true);
    if ($FailedTables > 0) {
        stats_admin_events(2, "[Weekly]: blocked events done ( {$took} ) {$FailedTables} Failed tables", "Tables:\n" . @implode("\n", $tablesources), __FILE__, __LINE__);
    }
}
コード例 #8
0
function visited_sites()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/squid.visited_sites_rescan.pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    $t = time();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid} since {$time}mn\n";
        }
        die;
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    stats_admin_events(2, "Starting table visited_sites", "", __FILE__, __LINE__);
    progress("Starting table visited_sites", 5);
    $q = new mysql_squid_builder();
    $sql = "SELECT sitename FROM visited_sites WHERE LENGTH(category)=0";
    $results = $q->QUERY_SQL($sql);
    $num_rows = mysql_num_rows($results);
    $took = $unix->distanceOfTimeInWords($t, time());
    stats_admin_events(2, "Query done {$num_rows} websites to scan", "took:{$took}", __FILE__, __LINE__);
    if ($num_rows == 0) {
        progress(null, 100);
        return;
    }
    progress("Query done {$num_rows} websites to scan", 10);
    $c = 0;
    $t = 0;
    $d = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $sitenameOrg = $ligne["sitename"];
        $sitename = strtolower(trim($sitenameOrg));
        if (badCharacters($sitename)) {
            $q->categorize_reaffected($sitename);
            $sitenameOrg = mysql_escape_string2($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        if (strpos($sitename, ".") == 0) {
            $q->categorize_reaffected($sitename);
            $sitenameOrg = mysql_escape_string2($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $sitename)) {
            $sitename = gethostbyaddr($sitename);
            if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $sitename)) {
                $c++;
                continue;
            }
        }
        $ipaddr = gethostbyname($sitename);
        if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $ipaddr)) {
            $q->categorize_reaffected($sitenameOrg);
            $q->QUERY_SQL("UPDATE visited_sites SET category='reaffected' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
            $d++;
            $c++;
            continue;
        }
        $cat = $q->GET_CATEGORIES($sitename);
        if ($cat != null) {
            $d++;
            $q->QUERY_SQL("UPDATE visited_sites SET category='{$cat}' WHERE `sitename`='{$sitenameOrg}'");
            if (!$q->ok) {
                progress("Fatal", 100);
                die;
            }
        }
        $c++;
        if ($c > 50) {
            $t = $t + $c;
            $purc = $t / $num_rows;
            $purc = round($purc, 2) * 100;
            $c = 0;
            if ($purc > 10) {
                progress("{$sitename} {$t}/{$num_rows}", $purc);
            }
        }
    }
    progress($sitename, 100);
    $took = $unix->distanceOfTimeInWords($t, time());
    if ($d > 0) {
        stats_admin_events(2, "{$d} New categorized websites...", "took:{$took}", __FILE__, __LINE__);
    }
}
コード例 #9
0
function TOTALS_REPAIR($aspid = false, $checktime = false)
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $timefile = "/etc/artica-postfix/pids/exec.squid.stats.totals.php.TOTALS_REPAIR.time";
        if ($GLOBALS["VERBOSE"]) {
            echo "time: {$timefile}\n";
        }
        $pid = @file_get_contents($pidfile);
        if (!$GLOBALS["VERBOSE"]) {
            if (!$GLOBALS["FORCE"]) {
                if ($pid < 100) {
                    $pid = null;
                }
                if ($unix->process_exists($pid, basename(__FILE__))) {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Already executed pid {$pid}\n";
                    }
                    return;
                }
                if (!$GLOBALS["BY_SCHEDULE"]) {
                    $timeexec = $unix->file_time_min($timefile);
                    if ($timeexec < 1440) {
                        return;
                    }
                }
                $mypid = getmypid();
                @file_put_contents($pidfile, $mypid);
            }
        }
    }
    if ($checktime) {
        $timeCK = $unix->file_time_min($timefile);
        if ($timeCK < 240) {
            return false;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $q = new mysql_squid_builder();
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $q = new mysql_squid_builder();
    $currentDay = date("Ymd");
    $dansguardian_events_current = "dansguardian_events_{$currentDay}";
    if ($GLOBALS["FORCE"]) {
        $q->QUERY_SQL("UPDATE tables_day SET totalsize=0");
    }
    $results = $q->QUERY_SQL("SELECT DATE_FORMAT(zDate,'%Y%m%d') as tprefix,totalsize,tablename FROM tables_day WHERE totalsize<100");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["tprefix"] == $currentDay) {
            continue;
        }
        $quota_day = "quotaday_{$ligne["tprefix"]}";
        $dansguardian_events = "dansguardian_events_{$ligne["tprefix"]}";
        if ($q->TABLE_EXISTS($quota_day)) {
            $sql = "SELECT SUM(size) as tsize FROM `{$quota_day}`";
            $ligne2 = mysql_fetch_array($q->QUERY_SQL($sql));
            $SumSize = intval($ligne2["tsize"]);
            $sql = "SELECT SUM(hits) as tsize FROM `{$dansguardian_events}`";
            $ligne2 = mysql_fetch_array($q->QUERY_SQL($sql));
            $SumHits = intval($ligne2["tsize"]);
            stats_admin_events(2, "Repair: {$ligne["tablename"]} = {$ligne["totalsize"]} {$quota_day} = {$SumSize}", null, __FILE__, __LINE__);
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ligne["tablename"]} = {$ligne["totalsize"]} {$quota_day} = {$SumSize}\n";
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "{$dansguardian_events} = {$SumHits}\n";
            }
            $q->QUERY_SQL("UPDATE tables_day SET `totalsize`='{$SumSize}',`requests`={$SumHits} WHERE tablename='{$ligne["tablename"]}'");
        }
    }
    $q = new mysql_squid_builder();
    if (!$q->FIELD_EXISTS("tables_day", "totalKeyWords")) {
        $q->QUERY_SQL("ALTER TABLE `tables_day` ADD `totalKeyWords` BIGINT( 255 ) NOT NULL NOT NULL,ADD INDEX ( `totalKeyWords`)");
    }
    $sql = "SELECT DATE_FORMAT(zDate,'%Y%m%d') as tprefix,`totalKeyWords`,`tablename` FROM `tables_day` \n\t\t\tWHERE `totalKeyWords`=0";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$sql}\n";
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["tprefix"] == $currentDay) {
            continue;
        }
        $SourceTable = "searchwordsD_{$ligne["tprefix"]}";
        if ($GLOBALS["VERBOSE"]) {
            echo "**** {$SourceTable} ****\n";
        }
        if ($q->TABLE_EXISTS($SourceTable)) {
            $sql = "SELECT `words` FROM `{$SourceTable}` GROUP BY `words`";
            $results2 = $q->QUERY_SQL($sql);
            $SumSize = mysql_num_rows($results2);
            stats_admin_events(2, "Repair: {$ligne["tablename"]} totalKeyWords = {$ligne["totalKeyWords"]} {$SourceTable} = {$SumSize}", null, __FILE__, __LINE__);
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ligne["tablename"]} = {$ligne["totalKeyWords"]} {$SourceTable} = {$SumSize}\n";
            }
            $q->QUERY_SQL("UPDATE tables_day SET `totalKeyWords`='{$SumSize}' WHERE tablename='{$ligne["tablename"]}'");
        }
    }
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT DATE_FORMAT(zDate,'%Y%m%d') as tprefix,totalKeyWords,tablename FROM tables_day WHERE totalKeyWords=0");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["tprefix"] == $currentDay) {
            continue;
        }
        $SourceTable = "youtubeday_{$ligne["tprefix"]}";
        if ($GLOBALS["VERBOSE"]) {
            echo "**** {$SourceTable} ****\n";
        }
        if ($q->TABLE_EXISTS($SourceTable)) {
            $sql = "SELECT `youtubeid` FROM `{$SourceTable}` GROUP BY `youtubeid`";
            $results2 = $q->QUERY_SQL($sql);
            $SumSize = mysql_num_rows($results2);
            stats_admin_events(2, "Repair: {$ligne["tablename"]} YouTubeHits: {$SourceTable} = {$SumSize}", null, __FILE__, __LINE__);
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ligne["tablename"]} {$SourceTable} = {$SumSize}\n";
            }
            $q->QUERY_SQL("UPDATE tables_day SET `YouTubeHits`='{$SumSize}' WHERE tablename='{$ligne["tablename"]}'");
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Find Members = 0\n";
    }
    $results = $q->QUERY_SQL("SELECT zDate,DATE_FORMAT(zDate,'%Y%m%d') as tprefix,MembersCount,tablename FROM tables_day WHERE MembersCount=0 ORDER BY zDate");
    $COUNT_DE_FAILED_MEMBERS = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $tablesource = "{$ligne["tprefix"]}_members";
        if ($ligne["tprefix"] == $currentDay) {
            continue;
        }
        if (!$q->TABLE_EXISTS($tablesource)) {
            $COUNT_DE_FAILED_MEMBERS++;
            if ($GLOBALS["VERBOSE"]) {
                echo "Table `{$tablesource}` Doesn't exists...\n";
            }
            continue;
        }
        if ($q->COUNT_ROWS($tablesource) > 0) {
            $sql = "SELECT CLIENT, uid,MAC,hostname FROM `{$tablesource}` GROUP BY CLIENT,uid,MAC,hostname";
            $results1 = $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q - mysql_error;
                return;
            }
            $Sum = mysql_num_rows($results1);
            stats_admin_events(2, "Repair: {$ligne["tablename"]} MembersCount: {$tablesource} = {$SumSize}", null, __FILE__, __LINE__);
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ligne["tablename"]} -> {$tablesource} = {$Sum}\n";
            }
            $q->QUERY_SQL("UPDATE tables_day SET `MembersCount`='{$Sum}' WHERE tablename='{$ligne["tablename"]}'");
        }
    }
    if ($COUNT_DE_FAILED_MEMBERS > 0) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.stats.repair.php --coherences-tables --force-time >/dev/null 2>&1 &");
    }
    donnees_interface();
}
コード例 #10
0
function _not_categorized_months($table)
{
    $t = time();
    $unix = new unix();
    $sql = "SELECT familysite FROM {$table} WHERE category='' GROUP BY familysite";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL($sql);
    if (mysql_num_rows($results) == 0) {
        return true;
    }
    $c = 0;
    while ($ligne = mysql_fetch_assoc($results)) {
        $category = $q->GET_CATEGORIES($ligne["familysite"]);
        echo "{$table} {$ligne["familysite"]} -> `{$category}`\n";
        if ($category == null) {
            continue;
        }
        $q->QUERY_SQL("UPDATE {$table} SET category='{$category}' WHERE familysite='{$ligne["familysite"]}'");
        $c++;
    }
    if ($c > 0) {
        stats_admin_events(2, "{$table} {$c} websites categorized took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
    }
}
コード例 #11
0
function squid_running_schedules()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        _statussquid("{$pid} already executed since {$timepid}Mn");
        if ($timepid < 5) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 4) {
            _statussquid("Current {$time}Mn need 5Mn");
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $StatsApplianceReceivers = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/StatsApplianceReceivers"));
    $SquidPerformance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance"));
    $BASEDIR = "/usr/share/artica-postfix";
    $SQUIDEnable = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (function_exists("systemMaxOverloaded")) {
        if (systemMaxOverloaded()) {
            squid_admin_mysql(1, "{$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: System is overloaded, Artica tasks as been aborted", null, __FILE__, __LINE__);
            _statussquid("Overloaded system, aborting...");
            return;
        }
    }
    if ($SQUIDEnable == 0) {
        return;
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_mem_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --mem-status >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/SQUID_MGR_INFO.DB";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --info >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_stores_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 20) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --store-status >/dev/null 2>&1 &");
    }
    $filetimeF = '/etc/artica-postfix/pids/Winbindd_privileged_SQUID.time';
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        $GLOBALS["CLASS_UNIX"]->Winbindd_privileged_SQUID();
        @unlink($filetimeF);
        @file_put_contents($filetimeF, time());
    }
    $filetimeF = '/etc/artica-postfix/pids/EnableKerbAuth.time';
    $EnableKerbAuth = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerbAuth"));
    if ($EnableKerbAuth == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 5) {
            @unlink($filetimeF);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.kerbauth.php --pinglic >/dev/null 2>&1 &");
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = '/etc/artica-postfix/pids/DisableGoogleSSL.time';
    $EnableGoogleDNS = 1;
    $DisableGoogleSSL = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableGoogleSSL"));
    $EnableGoogleSafeSearch = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableGoogleSafeSearch");
    if (!is_numeric($EnableGoogleSafeSearch)) {
        $EnableGoogleSafeSearch = 1;
    }
    if ($DisableGoogleSSL == 0) {
        if ($EnableGoogleSafeSearch == 0) {
            $EnableGoogleDNS = 0;
        }
    }
    if ($EnableGoogleDNS == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($GLOBALS["CLASS_UNIX"]->file_time_min($filetime) > 4320) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.nosslsearch.google.com.php --run >/dev/null 2>&1 &");
            @unlink($filetimeF);
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.Defaultschedules.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --defaults-schedules");
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 120) {
            @unlink("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time");
            @file_put_contents("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time", time());
            stats_admin_events(2, "Launching importation tables task", null, __FILE__, __LINE__);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.central.php --import");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.not-categorized.php.not_categorized_scan.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 120) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.not-categorized.php --recategorize >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.totals.php.donnees_interface.pid";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 30) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.totals.php --interface >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 1880) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quota-week.parser.php >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 19) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.proto.php >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/YoutubeByHour.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 61) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.youtube.days.php --youtube-hours >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.rotate_logs.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --rotate >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.rotate.php >/dev/null 2>&1 &");
    }
    if ($SquidPerformance < 3) {
        $SquidEnforceRules = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidEnforceRules"));
        if ($SquidEnforceRules == 1) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squidcache.php >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_redirectors_status.db";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 10) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --redirector-array >/dev/null 2>&1 &");
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.interface-size.php.CachedOrNot.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 4) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php --cache-or-not >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/settings/Daemons/StatsApplianceReceivers";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 4) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php --stats-apps-clients >/dev/null 2>&1 &");
    }
    if ($StatsApplianceReceivers > 0) {
        $filetimeF = "/etc/artica-postfix/pids/exec.stats-appliance-clean.php.start_parse.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 59) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.stats-appliance-clean.php >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.clean.varlog.php.varlog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.varlog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.ufdb.parse-categories.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.ufdb.parse-categories.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.mysqld.crash.php.check_crashed_squid.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.mysqld.crash.php --crashed-squid >/dev/null 2>&1 &");
    }
    squid_tasks();
}
コード例 #12
0
function __re_categorize_subtables($oldT1 = 0, $websites)
{
    $unix = new unix();
    if (!$GLOBALS["FORCE"]) {
        if (SquidStatisticsTasksOverTime()) {
            stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
            return;
        }
    }
    $sock = new sockets();
    $RecategorizeSecondsToWaitOverload = $sock->GET_INFO("RecategorizeSecondsToWaitOverload");
    $RecategorizeMaxExecutionTime = $sock->GET_INFO("RecategorizeSecondsToWaitOverload");
    if (!is_numeric($RecategorizeSecondsToWaitOverload)) {
        $RecategorizeSecondsToWaitOverload = 30;
    }
    if (!is_numeric($RecategorizeMaxExecutionTime)) {
        $RecategorizeMaxExecutionTime = 210;
    }
    if ($oldT1 > 1) {
        $t = $oldT1;
    } else {
        $t = time();
    }
    $tables_days = $GLOBALS["Q"]->LIST_TABLES_DAYS();
    $tables_hours = $GLOBALS["Q"]->LIST_TABLES_HOURS();
    $tables_week = $GLOBALS["Q"]->LIST_TABLES_WEEKS();
    $tables_blocked_week = $GLOBALS["Q"]->LIST_TABLES_WEEKS_BLOCKED();
    $tables_blocked_days = $GLOBALS["Q"]->LIST_TABLES_DAYS_BLOCKED();
    $CountUpdatedTables = 0;
    while (list($website, $category) = each($websites)) {
        if ($website == null) {
            continue;
        }
        if ($category == null) {
            continue;
        }
        reset($tables_days);
        reset($tables_hours);
        reset($tables_week);
        while (list($num, $tablename) = each($tables_days)) {
            $category = addslashes($category);
            $CountUpdatedTables++;
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE familysite='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "categorize");
                return;
            }
        }
        while (list($num, $tablename) = each($tables_hours)) {
            $category = addslashes($category);
            $CountUpdatedTables++;
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE sitename='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "categorize");
                return;
            }
        }
        while (list($num, $tablename) = each($tables_week)) {
            $category = addslashes($category);
            $CountUpdatedTables++;
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE sitename='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "categorize");
                return;
            }
        }
        while (list($num, $tablename) = each($tables_blocked_days)) {
            $category = addslashes($category);
            $CountUpdatedTables++;
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE website='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "categorize");
                return;
            }
        }
        while (list($num, $tablename) = each($tables_blocked_week)) {
            $category = addslashes($category);
            $CountUpdatedTables++;
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE website='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "categorize");
                return;
            }
        }
        if (SquidStatisticsTasksOverTime()) {
            stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
            return;
        }
        $distanceInSeconds = round(abs(time() - $t));
        $distanceInMinutes = round($distanceInSeconds / 60);
        if ($distanceInMinutes > $RecategorizeMaxExecutionTime) {
            $took = $unix->distanceOfTimeInWords($t, time());
            writelogs_squid("Re-categorized websites task aborted (Max execution time {$RecategorizeMaxExecutionTime}Mn) ({$took})", __FUNCTION__, __FILE__, __LINE__, "categorize");
            return;
        }
    }
    $took = $unix->distanceOfTimeInWords($t, time());
    stats_admin_events(2, count($websites) . "re-categorized  websites updated in `{$CountUpdatedTables}` MySQL tables ({$took})", __FUNCTION__, __FILE__, __LINE__, "stats");
}
コード例 #13
0
function thumbnail_parse_dir($directory)
{
    $unix = new unix();
    $countDefile = $unix->COUNT_FILES($directory);
    $sock = new sockets();
    $DisableLocalStatisticsTasks = $sock->GET_INFO("DisableLocalStatisticsTasks");
    if (!is_numeric($DisableLocalStatisticsTasks)) {
        $DisableLocalStatisticsTasks = 0;
    }
    events_tail("{$directory}  {$countDefile} files on Line: " . __LINE__);
    if ($countDefile == 0) {
        events("thumbnail_parse_dir():: {$directory}:  remove... on Line: " . __LINE__);
        @rmdir($directory);
        return;
    }
    if (!($handle = opendir($directory))) {
        ufdbguard_admin_events("Fatal: {$directory} no such directory", __FUNCTION__, __FILE__, __LINE__, "stats");
        return;
    }
    $c = 0;
    $d = 0;
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$directory}/{$filename}";
        $d++;
        if ($DisableLocalStatisticsTasks == 1) {
            @unlink($targetFile);
            continue;
        }
        $arrayFile = unserialize(@file_get_contents($targetFile));
        if (!is_array($arrayFile)) {
            @unlink($targetFile);
            continue;
        }
        while (list($sitename, $RTTSIZEARRAY) = each($arrayFile)) {
            thumbnail_site($sitename);
        }
        $c++;
        @unlink($targetFile);
        if ($d > 100) {
            if (SquidStatisticsTasksOverTime()) {
                stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                return;
            }
            $d = 0;
        }
    }
}
コード例 #14
0
function OverStatsTime()
{
    if (SquidStatisticsTasksOverTime()) {
        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
        StampDone(1000, "OverTime");
        return true;
    }
}
コード例 #15
0
function perform($tabledata, $nexttable)
{
    $q = new mysql_squid_builder();
    if (!$q->CreateUsersDayTable($nexttable)) {
        return false;
    }
    $q = new mysql_squid_builder();
    if ($q->TABLE_EXISTS($nexttable)) {
        $q->QUERY_SQL("DROP TABLE {$nexttable}");
    }
    $f = array();
    if (!$q->CreateUsersDayTable($nexttable)) {
        return false;
    }
    $sql = "SELECT SUM(size) as size, SUM(hits) as hits,client,hostname,uid,MAC FROM {$tabledata} GROUP BY client,hostname,uid,MAC";
    $prefix = "INSERT IGNORE INTO {$nexttable} (zMD5,client,hostname,MAC,size,hits,uid) VALUES";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        stats_admin_events(0, "Processing failed with {$tabledata}", $q->mysql_error, __FILE__, __LINE__);
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $md5 = md5(serialize($ligne));
        $client = mysql_escape_string2(trim(strtolower($ligne["client"])));
        $uid = mysql_escape_string2(trim(strtolower($ligne["uid"])));
        $hostname = mysql_escape_string2(trim(strtolower($ligne["hostname"])));
        $MAC = mysql_escape_string2(trim(strtolower($ligne["MAC"])));
        $f[] = "('{$md5}','{$client}','{$hostname}','{$MAC}','{$ligne["size"]}','{$ligne["hits"]}','{$uid}')";
        if (count($f) > 500) {
            $q->QUERY_SQL("{$prefix}" . @implode(",", $f));
            events_tail("Processing " . count($f) . " rows");
            if (!$q->ok) {
                events_tail("Failed to process query to {$nexttable} {$q->mysql_error}");
                return;
            }
            $f = array();
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL("{$prefix}" . @implode(",", $f));
        events_tail("Processing " . count($f) . " rows");
        if (!$q->ok) {
            events_tail("Failed to process query to {$nexttable} {$q->mysql_error}");
            return;
        }
        $f = array();
    }
    return true;
}
コード例 #16
0
function websites_uid()
{
    $GLOBALS["Q"] = new mysql_squid_builder();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading...\n";
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading done...\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 540) {
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    if (isset($GLOBALS["websites_uid_executed"])) {
        return;
    }
    $GLOBALS["websites_uid_executed"] = true;
    $q = new mysql_squid_builder();
    $sql = "SELECT tablename,zDate FROM `tables_day` WHERE websites_uid=0 AND zDate<DATE_SUB(NOW(),INTERVAL 1 DAY)";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if (preg_match("#Unknown column#", $q->mysql_error)) {
            $q->CheckTables();
            $results = $q->QUERY_SQL($sql);
        }
    }
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo "############# ERROR #########\n{$q->mysql_error}\\Line:" . __LINE__ . "\n#############\n";
        }
        return;
    }
    $c = 0;
    if (mysql_num_rows($results) == 0) {
        return;
    }
    $TOT = mysql_num_rows($results);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $date = $ligne["zDate"];
        $c++;
        $time = strtotime($date . " 00:00:00");
        $tablename = $ligne["tablename"];
        $but = null;
        $hourtable = date("Ymd", $time) . "_hour";
        if (!$q->TABLE_EXISTS($hourtable)) {
            if ($q->TABLE_EXISTS($tablename)) {
                $but = " but {$tablename} exists..";
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "############# ERROR #########\n{$hourtable} no such table ({$date}) {$but}\n#############\n";
            }
            continue;
        }
        events("websites_uid_from_hourtable({$hourtable},{$time})");
        percentage("Statistics by Users/Websites: {$date} {$c}/{$TOT}", 71);
        if (websites_uid_from_hourtable($hourtable, $time)) {
            $q->QUERY_SQL("UPDATE tables_day SET websites_uid=1 WHERE tablename='{$tablename}'");
            if (SquidStatisticsTasksOverTime()) {
                stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                return;
            }
            continue;
        } else {
            if ($GLOBALS["VERBOSE"]) {
                echo "Return false for {$hourtable} injection\n";
            }
        }
    }
    if (SquidStatisticsTasksOverTime()) {
        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
        return;
    }
}