コード例 #1
0
function parse()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.pid";
    $unix = new unix();
    $sock = new sockets();
    $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth"));
    $ActiveDirectoryEmergency = intval($sock->GET_INFO("ActiveDirectoryEmergency"));
    if (!is_file("/etc/artica-postfix/settings/Daemons/SQUIDEnable")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 1);
    }
    if ($ActiveDirectoryEmergency == 1) {
        $EnableKerbAuth = 0;
    }
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pid} already executed since {$timepid}Mn\n";
        }
        if (!$GLOBALS["FORCE"]) {
            if ($timepid < 14) {
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["VERBOSE"]) {
            $time = $unix->file_time_min($TimeFile);
            if ($time < 14) {
                echo "Current {$time}Mn, require at least 14mn\n";
                return;
            }
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    events("Proxy performance set to {$SquidPerformance}");
    build_progress("{refresh_dashboard_values}", 10);
    system_values();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{refresh_dashboard_values}", 11);
    $dateint = InfluxQueryFromUTC(strtotime("-48 hours"));
    $date = date("Y-m-d H:00:00", $dateint);
    $qSimple = new mysql();
    $sql = "SELECT COUNT(ID) as tcount FROM squid_admin_mysql WHERE severity=0 AND zDate>'{$date}'";
    $ligne = mysql_fetch_array($qSimple->QUERY_SQL($sql, "artica_events"));
    @file_put_contents("{$GLOBALS["BASEDIR"]}/WATCHDOG_COUNT_EVENTS", $ligne["tcount"]);
    @chmod("{$GLOBALS["BASEDIR"]}/WATCHDOG_COUNT_EVENTS", 0777);
    build_progress("{refresh_dashboard_values} APACHE_STATISTICS (2)", 11);
    APACHE_STATISTICS();
    build_progress("{refresh_dashboard_values} NETWORK_INTERFACES_RXTX (3)", 11);
    NETWORK_INTERFACES_RXTX();
    build_progress("{refresh_dashboard_values} COUNT_OF_SURICATA (4)", 11);
    COUNT_OF_SURICATA();
    build_progress("{refresh_dashboard_values} NOT_CATEGORIZED (5)", 11);
    NOT_CATEGORIZED();
    $SQUIDEnable = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable"));
    if ($SQUIDEnable == 0) {
        build_progress("{done}", 100);
        return;
    }
    if ($SquidPerformance > 1) {
        if (is_file("/etc/cron.d/artica-stats-hourly")) {
            @unlink("/etc/cron.d/artica-stats-hourly");
            system("/etc/init.d/cron reload");
        }
        build_progress("{statistics_are_disabled}", 110);
        die;
    }
    if (!is_file("/etc/cron.d/artica-stats-hourly")) {
        @unlink("/etc/cron.d/artica-stats-hourly");
    }
    @mkdir("/usr/share/artica-postfix/ressources/interface-cache", 0755, true);
    $t1 = time();
    $q = new mysql_squid_builder();
    $tables[] = "dashboard_size_day";
    $tables[] = "dashboard_countwebsite_day";
    $tables[] = "dashboard_countuser_day";
    $tables[] = "dashboard_user_day";
    $tables[] = "dashboard_notcached";
    $tables[] = "dashboard_cached";
    $tables[] = "dashboard_blocked_day";
    while (list($num, $table) = each($tables)) {
        if (!$q->TABLE_EXISTS($table)) {
            events("Table: {$table} is not yet ready...");
            continue;
        }
        $NUM = $q->COUNT_ROWS($table);
        events("Table: {$table} {$NUM} rows");
    }
    build_progress("{calculate_cache_rate}", 12);
    CachedOrNot();
    squidhour_clean();
    $t1 = time();
    $influx = new influx();
    $now = InfluxQueryFromUTC(strtotime("-24 hour"));
    build_progress("{refresh_dashboard_values}", 13);
    // -----------------------------------------------------------------------------------------------------
    build_progress("{refresh_dashboard_values}", 14);
    // -----------------------------------------------------------------------------------------------------
    build_progress("{cleaning_databases}", 16);
    squidhour_clean();
    build_progress("{refresh_dashboard_values}", 17);
    FLUX_RQS();
    build_progress("{refresh_dashboard_values}", 18);
    build_progress("{refresh_dashboard_values}", 19);
    //USERAGENTS();
    build_progress("{calculate_dates}", 20);
    MAX_MIN();
    backup_size();
    build_progress("{refresh_dashboard_values}", 21);
    WEBFILTERING();
    build_progress("{refresh_dashboard_values}", 22);
    $f = array();
    // -----------------------------------------------------------------------------------------------------
    $q = new mysql_squid_builder();
    $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(*) as tcount FROM proxy_ports WHERE enabled=1 AND transparent=1 AND Tproxy=1"));
    if ($q->ok) {
        @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_TRANSPARENT", intval($ligne["tcount"]));
    }
    // -----------------------------------------------------------------------------------------------------
    build_progress("{refresh_dashboard_values}", 51);
    $MAIN = array();
    $xdata = array();
    $ydata = array();
    $f = array();
    // -----------------------------------------------------------------------------------------------------
    // Calcul des caches en cours.
    $SquidCacheLevel = $sock->GET_INFO("SquidCacheLevel");
    if (!is_numeric($SquidCacheLevel)) {
        $SquidCacheLevel = 4;
    }
    if ($SquidCacheLevel == 0) {
        @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_CACHES", 0);
    }
    build_progress("{refresh_dashboard_values}", 52);
    $q = new mysql();
    $sql = "SELECT cache_size,cache_type FROM squid_caches_center WHERE remove=0";
    $xsize = 0;
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $cache_size = $ligne["cache_size"];
        $cache_type = $ligne["cache_type"];
        if ($cache_type == "Cachenull") {
            continue;
        }
        $xsize = $xsize + $cache_size;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "COUNT_DE_CACHES: {$xsize}MB\n";
    }
    @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_CACHES", $xsize);
    if ($GLOBALS["PROGRESS"]) {
        build_progress("{refresh_dashboard_values}", 90);
        system("{$php} /usr/share/artica-postfix/exec.status.php --all --verbose");
    }
    build_progress("{refresh_dashboard_values} {done}", 100);
    // -----------------------------------------------------------------------------------------------------
}
コード例 #2
0
function parse()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.pid";
    $unix = new unix();
    $sock = new sockets();
    $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth"));
    $ActiveDirectoryEmergency = intval($sock->GET_INFO("ActiveDirectoryEmergency"));
    if ($ActiveDirectoryEmergency == 1) {
        $EnableKerbAuth = 0;
    }
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pid} already executed since {$timepid}Mn\n";
        }
        if (!$GLOBALS["FORCE"]) {
            if ($timepid < 14) {
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["VERBOSE"]) {
            $time = $unix->file_time_min($TimeFile);
            if ($time < 14) {
                echo "Current {$time}Mn, require at least 14mn\n";
                return;
            }
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    events("Proxy performance set to {$SquidPerformance}");
    build_progress("{refresh_dashboard_values}", 10);
    system_values();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{refresh_dashboard_values}", 11);
    $dateint = InfluxQueryFromUTC(strtotime("-48 hours"));
    $date = date("Y-m-d H:00:00", $dateint);
    $qSimple = new mysql();
    $sql = "SELECT COUNT(ID) as tcount FROM squid_admin_mysql WHERE severity=0 AND zDate>'{$date}'";
    $ligne = mysql_fetch_array($qSimple->QUERY_SQL($sql, "artica_events"));
    @file_put_contents("{$GLOBALS["BASEDIR"]}/WATCHDOG_COUNT_EVENTS", $ligne["tcount"]);
    @chmod("{$GLOBALS["BASEDIR"]}/WATCHDOG_COUNT_EVENTS", 0777);
    if ($SquidPerformance > 1) {
        if (is_file("/etc/cron.d/artica-stats-hourly")) {
            @unlink("/etc/cron.d/artica-stats-hourly");
            system("/etc/init.d/cron reload");
        }
        build_progress("{statistics_are_disabled}", 110);
        die;
    }
    if (!is_file("/etc/cron.d/artica-stats-hourly")) {
        @unlink("/etc/cron.d/artica-stats-hourly");
    }
    @mkdir("/usr/share/artica-postfix/ressources/interface-cache", 0755, true);
    $t1 = time();
    $q = new mysql_squid_builder();
    $tables[] = "dashboard_size_day";
    $tables[] = "dashboard_countwebsite_day";
    $tables[] = "dashboard_countuser_day";
    $tables[] = "dashboard_user_day";
    $tables[] = "dashboard_notcached";
    $tables[] = "dashboard_cached";
    $tables[] = "dashboard_blocked_day";
    while (list($num, $table) = each($array)) {
        if (!$q->TABLE_EXISTS($table)) {
            events("Table: {$table} is not yet ready...");
            continue;
        }
        $NUM = $q->COUNT_ROWS($table);
        events("Table: {$table} {$NUM} rows");
    }
    build_progress("{calculate_cache_rate}", 12);
    CachedOrNot();
    squidhour_clean();
    $t1 = time();
    $influx = new influx();
    $now = InfluxQueryFromUTC(strtotime("-24 hour"));
    build_progress("{refresh_dashboard_values}", 13);
    // -----------------------------------------------------------------------------------------------------
    $COUNT_DE_SNI_CERTS_TIME = 1000000;
    $COUNT_DE_SNI_CERTS = "{$GLOBALS["BASEDIR"]}/COUNT_DE_SNI_CERTS";
    if (is_file($COUNT_DE_SNI_CERTS)) {
        $COUNT_DE_SNI_CERTS_TIME = $unix->file_time_min($COUNT_DE_SNI_CERTS);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "COUNT_DE_SNI_CERTS_TIME = {$COUNT_DE_SNI_CERTS_TIME}\n";
        $COUNT_DE_SNI_CERTS_TIME = 999999;
    }
    if ($COUNT_DE_SNI_CERTS_TIME > 60) {
        $sql = "SELECT COUNT(website) as tcount,website FROM sni_certs WHERE time > {$now}s GROUP BY time(24h),website";
        $f = array();
        echo $sql . "\n";
        $main = $influx->QUERY_SQL($sql);
        foreach ($main as $row) {
            $website = $row->website;
            $count = intval($row->tcount);
            if ($GLOBALS["VERBOSE"]) {
                echo "SNI: {$website} -> {$count}\n";
            }
            $f[] = "('{$count}','{$website}')";
        }
        if (count($f) > 0) {
            $q = new mysql_squid_builder();
            $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS sni_certs (`hits` BIGINT UNSIGNED, `websites` VARCHAR(128) NOT NULL PRIMARY KEY, KEY `hits` (`hits`) ) ENGINE=MYISAM");
            $q->QUERY_SQL("TRUNCATE TABLE sni_certs");
            $q->QUERY_SQL("INSERT IGNORE INTO sni_certs (hits,websites) VALUES " . @implode(",", $f));
            @unlink($COUNT_DE_SNI_CERTS);
            @file_put_contents($COUNT_DE_SNI_CERTS, count($f));
        }
    }
    build_progress("{refresh_dashboard_values}", 14);
    $NETS = $unix->NETWORK_ALL_INTERFACES();
    // -----------------------------------------------------------------------------------------------------
    while (list($Interface, $array) = each($NETS)) {
        $sql = "SELECT SUM(RX) as size FROM ethrxtx WHERE time > {$now}s AND ETH='{$Interface}' GROUP BY time(10m) ORDER BY ASC";
        if ($GLOBALS["VERBOSE"]) {
            echo "\n*****\n{$sql}\n******\n";
        }
        $MAIN = array();
        $xdata = array();
        $ydata = array();
        $main = $influx->QUERY_SQL($sql);
        foreach ($main as $row) {
            $time = InfluxToTime($row->time);
            $min = date("H:i", $time);
            $size = intval($row->size) / 1024;
            if ($GLOBALS["VERBOSE"]) {
                echo "({$time}): ethrxtx {$Interface}:RX: {$min} -> {$size}\n";
            }
            $size = $size / 1024;
            if (round($size) == 0) {
                continue;
            }
            $xdata[] = $min;
            $ydata[] = round($size);
        }
        $MAIN["xdata"] = $xdata;
        $MAIN["ydata"] = $ydata;
        @file_put_contents("{$GLOBALS["BASEDIR"]}/FLUX_{$Interface}_RX", serialize($MAIN));
        if (count($xdata) < 2) {
            @unlink("{$GLOBALS["BASEDIR"]}/FLUX_{$Interface}_RX");
        }
        $sql = "SELECT SUM(TX) as size FROM ethrxtx WHERE time > {$now}s AND ETH='{$Interface}' GROUP BY time(10m) ORDER BY ASC";
        $MAIN = array();
        $xdata = array();
        $ydata = array();
        build_progress("{refresh_dashboard_values}", 15);
        $main = $influx->QUERY_SQL($sql);
        foreach ($main as $row) {
            $time = InfluxToTime($row->time);
            $min = date("H:i", $time);
            $size = intval($row->size) / 1024;
            $size = $size / 1024;
            if ($size == 0) {
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "ethrxtx {$Interface}:TX: {$min} -> {$size}\n";
            }
            $xdata[] = $min;
            $ydata[] = round($size);
        }
        $MAIN["xdata"] = $xdata;
        $MAIN["ydata"] = $ydata;
        @file_put_contents("{$GLOBALS["BASEDIR"]}/FLUX_{$Interface}_TX", serialize($MAIN));
        if (count($xdata) < 2) {
            @unlink("{$GLOBALS["BASEDIR"]}/FLUX_{$Interface}_TX");
        }
    }
    // -----------------------------------------------------------------------------------------------------
    build_progress("{cleaning_databases}", 16);
    squidhour_clean();
    build_progress("{refresh_dashboard_values}", 17);
    FLUX_RQS();
    build_progress("{refresh_dashboard_values}", 18);
    build_progress("{refresh_dashboard_values}", 19);
    USERAGENTS();
    build_progress("{calculate_dates}", 20);
    MAX_MIN();
    backup_size();
    build_progress("{refresh_dashboard_values}", 21);
    WEBFILTERING();
    build_progress("{refresh_dashboard_values}", 22);
    $f = array();
    // -----------------------------------------------------------------------------------------------------
    $q = new mysql_squid_builder();
    $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(*) as tcount FROM proxy_ports WHERE enabled=1 AND transparent=1 AND Tproxy=1"));
    if ($q->ok) {
        @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_TRANSPARENT", intval($ligne["tcount"]));
    }
    // -----------------------------------------------------------------------------------------------------
    build_progress("{refresh_dashboard_values}", 51);
    $MAIN = array();
    $xdata = array();
    $ydata = array();
    $f = array();
    // -----------------------------------------------------------------------------------------------------
    // Calcul des caches en cours.
    $SquidCacheLevel = $sock->GET_INFO("SquidCacheLevel");
    if (!is_numeric($SquidCacheLevel)) {
        $SquidCacheLevel = 4;
    }
    if ($SquidCacheLevel == 0) {
        @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_CACHES", 0);
    }
    build_progress("{refresh_dashboard_values}", 52);
    $q = new mysql();
    $sql = "SELECT cache_size,cache_type FROM squid_caches_center WHERE remove=0";
    $xsize = 0;
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $cache_size = $ligne["cache_size"];
        $cache_type = $ligne["cache_type"];
        if ($cache_type == "Cachenull") {
            continue;
        }
        $xsize = $xsize + $cache_size;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "COUNT_DE_CACHES: {$xsize}MB\n";
    }
    @file_put_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_CACHES", $xsize);
    if ($GLOBALS["PROGRESS"]) {
        build_progress("{refresh_dashboard_values}", 90);
        system("{$php} /usr/share/artica-postfix/exec.status.php --all --verbose");
    }
    build_progress("{refresh_dashboard_values} {done}", 100);
    // -----------------------------------------------------------------------------------------------------
}