예제 #1
0
function ufdbcat($sitename)
{
    if (isset($GLOBALS["CATEGORYOF"])) {
        if (count($GLOBALS["CATEGORYOF"]) > 50000) {
            $GLOBALS["CATEGORYOF"] = array();
        }
    }
    if (isset($GLOBALS["CATEGORYOF"][$sitename])) {
        return $GLOBALS["CATEGORYOF"][$sitename];
    }
    $time_start = microtime_float();
    $s = new mysql_catz();
    $resp = $s->GET_CATEGORIES($sitename);
    $time_stop = microtime_float();
    $TimeExec = round($time_stop - $time_start, 3);
    if ($resp != null) {
        $GLOBALS["CATEGORYOF"][$sitename] = $resp;
        return $GLOBALS["CATEGORYOF"][$sitename];
    }
}
function compress_month_perform($day)
{
    $catz = new mysql_catz();
    $q = new postgres_sql();
    $sql = "SELECT SUM(size) as size, SUM(rqs) as rqs,ipaddr,proxyname,category,familysite,userid,mac\n\tFROM access_month WHERE date_trunc('month',zdate)='{$day}' GROUP by ipaddr,proxyname,category,familysite,userid,mac";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        return;
    }
    $rows = pg_num_rows($results);
    echo "Compressing {$day} {$rows} rows\n";
    $pref = "INSERT INTO access_year (zdate,size,rqs,familysite,category,userid,ipaddr,mac,proxyname) VALUES ";
    $f = array();
    $c = 0;
    while ($ligne = @pg_fetch_assoc($results)) {
        $size = $ligne["size"];
        $rqs = $ligne["rqs"];
        $familysite = $ligne["familysite"];
        $category = $ligne["category"];
        $userid = $ligne["userid"];
        $ipaddr = $ligne["ipaddr"];
        $mac = $ligne["mac"];
        $proxyname = $ligne["proxyname"];
        if (preg_match("#,USERID=#", $category)) {
            $category = null;
        }
        if ($category == null) {
            $category = $catz->GET_CATEGORIES($familysite);
        }
        if (preg_match("#IPADDR=#", $userid)) {
            $userid = null;
        }
        $c++;
        $f[] = "('{$day}','{$size}','{$rqs}','{$familysite}','{$category}','{$userid}','{$ipaddr}','{$mac}','{$proxyname}')";
        if (count($f) > 800) {
            $q->QUERY_SQL($pref . @implode(",", $f));
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
                return;
            }
            $f = array();
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL($pref . @implode(",", $f));
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            return;
        }
        $f = array();
    }
    squid_admin_mysql(2, "{$day} was compressed in table access_month with {$c} elements", null, __FILE__, __LINE__);
    return true;
}
예제 #3
0
function categories_match($gpid, $sitname)
{
    if (preg_match("#^www\\.(.+)#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if ($GLOBALS["DEBUG_LEVEL"] > 1) {
        WLOG("Analyze: Group: {$gpid} `{$sitname}`");
    }
    $categories_get_memory = categories_get_memory($gpid, $sitname);
    if ($categories_get_memory != null) {
        if ($GLOBALS["DEBUG_LEVEL"] > 1) {
            WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` ");
        }
        if ($categories_get_memory == "UNKNOWN") {
            return null;
        }
        return $categories_get_memory;
    }
    $q = new mysql_catz();
    if ($GLOBALS["DEBUG_LEVEL"] > 1) {
        WLOG("Group: {$gpid} `{$sitname}` -> CATEGORY ?? [" . __LINE__ . "]");
    }
    $categoriF = $q->GET_CATEGORIES($sitname);
    $trans = $q->TransArray();
    if ($GLOBALS["DEBUG_LEVEL"] > 1) {
        WLOG("Group: {$gpid} `{$sitname}` -> category: `{$categoriF}` ");
    }
    if ($categoriF == null) {
        if ($GLOBALS["DEBUG_LEVEL"] > 1) {
            WLOG("squid_familysite()");
        }
        if (!class_exists("squid_familysite")) {
            include_once dirname(__FILE__) . "/ressources/class.squid.familysites.inc";
        }
        $qF = new squid_familysite();
        $familysite = $qF->GetFamilySites($sitname);
        if ($familysite != $sitname) {
            $categoriF = $q->GET_CATEGORIES($familysite);
            if ($GLOBALS["DEBUG_LEVEL"] > 1) {
                WLOG("Group: {$gpid} `{$sitname}` -> {$familysite} -> category: `{$categoriF}` ");
            }
        }
    }
    if ($categoriF == null) {
        categories_set_memory($gpid, $sitname, "UNKNOWN");
        return null;
    }
    if (strpos($categoriF, ",") > 0) {
        $categoriT = explode(",", $categoriF);
    } else {
        $categoriT[] = $categoriF;
    }
    while (list($a, $b) = each($categoriT)) {
        $MAIN[$b] = true;
    }
    $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl";
    $categories = unserialize(@file_get_contents($filename));
    while (list($category_table, $category_rule) = each($categories)) {
        $category_rule = urlencode($category_rule);
        $categoryname = $trans[$category_table];
        if (isset($MAIN[$categoryname])) {
            if ($GLOBALS["DEBUG_LEVEL"] > 1) {
                WLOG("FOUND `{$categoryname}` -> `{$category_rule}` ");
            }
            categories_set_memory($gpid, $sitname, $category_rule);
            return $category_rule;
        }
    }
    categories_set_memory($gpid, $sitname, "UNKNOWN");
}
예제 #4
0
function VOLUME_LOG_HOURLY_SCAN($workfile)
{
    $unix = new unix();
    $LastScannLine = 0;
    if (is_file("{$workfile}.last")) {
        $LastScannLine = intval(@file_get_contents("{$workfile}.last"));
    }
    $handle = @fopen($workfile, "r");
    if (!$handle) {
        events("Fopen failed on {$workfile}");
        return false;
    }
    if ($LastScannLine > 0) {
        fseek($handle, $LastScannLine, SEEK_SET);
    }
    $handle = @fopen($workfile, "r");
    if (!$handle) {
        events("Fopen failed on {$workfile}");
        return false;
    }
    if ($LastScannLine > 0) {
        fseek($handle, $LastScannLine, SEEK_SET);
    }
    $MEM = array();
    $proxyname = $unix->hostname_g();
    $catz = new mysql_catz();
    $q = new mysql_squid_builder();
    while (!feof($handle)) {
        $buffer = trim(fgets($handle));
        if ($buffer == null) {
            continue;
        }
        $ARRAY = explode(":::", $buffer);
        $TIME = $ARRAY[0];
        $USERID = $ARRAY[1];
        $MAC = $ARRAY[3];
        if ($USERID == null) {
            $USERID = $q->MacToUid($MAC);
        }
        $IPADDR = $ARRAY[2];
        if ($IPADDR == "127.0.0.1") {
            continue;
        }
        $CONTENT_TYPE = $ARRAY[4];
        $FAMILYSITE = $ARRAY[5];
        $HITS = $ARRAY[6];
        $SIZE = $ARRAY[7];
        $HOURTIME = date("Y-m-d H:00:00", $TIME);
        $KEYMD5 = md5("{$HOURTIME}{$USERID}{$IPADDR}{$MAC}{$FAMILYSITE}{$CONTENT_TYPE}");
        if (!isset($MEM[$KEYMD5])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$KEYMD5}] VOLUME_LOG_HOURLY_SCAN: {$HOURTIME} {$USERID}/{$IPADDR}/{$MAC} {$FAMILYSITE} {$CONTENT_TYPE} {$HITS}/{$SIZE}\n";
            }
            $MEM[$KEYMD5]["TIME"] = QueryToUTC(strtotime($HOURTIME), true);
            $MEM[$KEYMD5]["USERID"] = $USERID;
            $MEM[$KEYMD5]["IPADDR"] = $IPADDR;
            $MEM[$KEYMD5]["MAC"] = $MAC;
            $MEM[$KEYMD5]["FAMILYSITE"] = $FAMILYSITE;
            $MEM[$KEYMD5]["CATEGORY"] = $catz->GET_CATEGORIES($FAMILYSITE);
            $MEM[$KEYMD5]["CONTENT_TYPE"] = $CONTENT_TYPE;
            $MEM[$KEYMD5]["SIZE"] = $SIZE;
            $MEM[$KEYMD5]["ZDATE"] = strtotime($HOURTIME);
            $MEM[$KEYMD5]["PROXYNAME"] = $proxyname;
            $MEM[$KEYMD5]["RQS"] = $HITS;
        } else {
            $MEM[$KEYMD5]["RQS"] = $MEM[$KEYMD5]["RQS"] + $HITS;
            $MEM[$KEYMD5]["SIZE"] = $MEM[$KEYMD5]["SIZE"] + $SIZE;
            if ($GLOBALS["VERBOSE"]) {
                echo "{$KEYMD5}] VOLUME_LOG_HOURLY_SCAN: {$HOURTIME} {$USERID}/{$IPADDR}/{$MAC} {$FAMILYSITE} {$CONTENT_TYPE} {$MEM[$KEYMD5]["RQS"]}/{$MEM[$KEYMD5]["SIZE"]}\n";
            }
        }
        if (count($MEM) > 5000) {
            VOLUME_LOG_HOURLY_DUMP($MEM);
            VOLUME_LOG_HOURLY_MYSQL_DUMP($MEM);
            $MEM = array();
        }
    }
    VOLUME_LOG_HOURLY_MYSQL_DUMP($MEM);
    VOLUME_LOG_HOURLY_DUMP($MEM);
    @unlink($workfile);
}
예제 #5
0
function build_last_hour()
{
    $sock = new sockets();
    $influx = new influx();
    $data = $influx->QUERY_SQL("SELECT MAX(ZDATE) as MAX from access_hour");
    $date_end = InfluxQueryFromUTC($data[0]->MAX);
    echo "Date Start: {$date_end}\n";
    $LastHour = InfluxQueryFromUTC(strtotime("-1 hour"));
    $ThisHour = strtotime(date("Y-m-d H:00:00", $LastHour));
    if ($date_end > 0) {
        $WHERE_TIME = "WHERE time > '" . date("Y-m-d H:i:s", $date_end) . "' AND time < '" . date("Y-m-d H:i:s", $ThisHour) . "'";
        $seconds = InfluxQueryFromUTC(time()) - strtotime(date("Y-m-d H:00:00", $date_end));
        $diff = abs($ThisHour - $date_end) / 60;
        if ($GLOBALS["VERBOSE"]) {
            echo "Last date saved is " . date("Y-m-d H:i:s", $date_end) . "({$date_end}) To " . date("Y-m-d H:i:s", $ThisHour) . " ({$ThisHour}) {$diff}mn..\n";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$WHERE_TIME}\n";
        }
        if ($diff < 60) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$diff}mn < 60 aborting...\n";
            }
            return;
        }
    } else {
        $WHERE_TIME = "WHERE time < '" . date("Y-m-d H:i:s", $ThisHour) . "'";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Query From " . date("Y-m-d H:i:s", $date_end) . " to " . date("Y-m-d H:i:s", $ThisHour) . "\n";
    }
    $sql = "SELECT SIZE,RQS,FAMILYSITE,USERID,IPADDR,MAC,CATEGORY FROM access_log {$WHERE_TIME}";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$sql}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "*******************************************\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "\n";
    }
    $main = $influx->QUERY_SQL($sql);
    $MAIN_ARRAY = array();
    $catz = new mysql_catz();
    if ($GLOBALS["VERBOSE"]) {
        echo count($main) . " elements";
    }
    $xtime = 0;
    foreach ($main as $row) {
        $time = InfluxToTime($row->time);
        $Time_hour = date("Y-m-d H:00:00", $time);
        $size = intval($row->SIZE);
        $RQS = intval($row->RQS);
        $FAMILYSITE = $row->FAMILYSITE;
        $CATEGORY = $row->CATEGORY;
        if ($CATEGORY == null) {
            $CATEGORY = $catz->GET_CATEGORIES($FAMILYSITE);
        }
        $USERID = $row->USERID;
        $IPADDR = $row->IPADDR;
        $MAC = $row->MAC;
        //if($GLOBALS["VERBOSE"]){echo "$row->time] [$Time_hour] $FAMILYSITE {$size}Bytes, $CATEGORY $USERID/$IPADDR/$MAC\n";}
        if ($size == 0) {
            continue;
        }
        if ($RQS == 0) {
            continue;
        }
        if ($time > $xtime) {
            $xtime = $time;
        }
        $MD5KEY = md5("{$CATEGORY}{$USERID}{$FAMILYSITE}{$IPADDR}{$MAC}");
        if (!isset($MAIN_ARRAY[$Time_hour][$MD5KEY])) {
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["FAMILYSITE"] = $FAMILYSITE;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["CATEGORY"] = $CATEGORY;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["USERID"] = $USERID;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["IPADDR"] = $IPADDR;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["MAC"] = $MAC;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["size"] = $size;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["hits"] = $RQS;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["ZDATE"] = $time;
        } else {
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["size"] = $MAIN_ARRAY[$Time_hour][$MD5KEY]["size"] + $size;
            $MAIN_ARRAY[$Time_hour][$MD5KEY]["hits"] = $MAIN_ARRAY[$Time_hour][$MD5KEY]["hits"] + $RQS;
            if ($time > $MAIN_ARRAY[$Time_hour][$MD5KEY]["ZDATE"]) {
                $MAIN_ARRAY[$Time_hour][$MD5KEY]["ZDATE"] = $time;
            }
        }
    }
    $sq = new influx();
    if (count($MAIN_ARRAY) == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "No array....\n";
        }
    }
    while (list($ztime, $array) = each($MAIN_ARRAY)) {
        while (list($md5, $Tarray) = each($array)) {
            $sdate = $ztime;
            $USERID = $Tarray["USERID"];
            $IPADDR = $Tarray["IPADDR"];
            $MAC = $Tarray["MAC"];
            $FAMILYSITE = $Tarray["FAMILYSITE"];
            $CATEGORY = $Tarray["CATEGORY"];
            $size = $Tarray["size"];
            $RQS = $Tarray["hits"];
            $ZDATE = $Tarray["ZDATE"];
            if ($GLOBALS["VERBOSE"]) {
                echo date("Y-m-d H:i:s", $ZDATE) . " {$USERID}/{$IPADDR}/{$MAC} -> [{$FAMILYSITE}/{$CATEGORY}] {$size}/{$RQS}\n";
            }
            $zArray = array();
            $zArray["fields"]["time"] = $sdate;
            $zArray["tags"]["CATEGORY"] = $CATEGORY;
            $zArray["tags"]["USERID"] = $USERID;
            $zArray["tags"]["IPADDR"] = $IPADDR;
            $zArray["tags"]["MAC"] = $MAC;
            $zArray["fields"]["SIZE"] = intval($size);
            $zArray["tags"]["FAMILYSITE"] = $FAMILYSITE;
            $zArray["fields"]["RQS"] = intval($RQS);
            $zArray["fields"]["ZDATE"] = $ZDATE;
            $sq->insert("access_hour", $zArray);
        }
    }
    $data = $influx->QUERY_SQL("SELECT MAX(ZDATE) as MAX from access_hour");
    $date_end = $data[0]->MAX;
    if ($GLOBALS["VERBOSE"]) {
        echo "Query was {$WHERE_TIME}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Last time : {$xtime} " . date("Y-m-d H:i:s", $xtime) . "\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Last date saved is " . date("Y-m-d H:i:s", $date_end) . "({$date_end}) To " . date("Y-m-d H:i:s", $ThisHour) . " ({$ThisHour}) {$diff}mn..\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Last final access_hour saved date {$date_end} - " . date("Y-m-d H:i:s", $date_end) . "\n";
    }
}
function run()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.categorize.php.time";
    $MaxTime = "/etc/artica-postfix/pids/exec.squid.stats.categorize.php.maxtime";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.categorize.php.pid";
    $unix = new unix();
    $skiptime = false;
    $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) {
                build_progress("Already executed pid {$pid}", 110);
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        }
    }
    if ($GLOBALS["PROGRESS"]) {
        $skiptime = true;
    }
    if ($GLOBALS["FORCE"]) {
        $skiptime = true;
    }
    @file_put_contents($pidfile, getmypid());
    if (!$skiptime) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 240) {
            echo "Current {$time}Mn, require at least 240mn\n";
            return;
        }
        @unlink($TimeFile);
        @file_put_contents($TimeFile, time());
    }
    @unlink($MaxTime);
    @file_put_contents($MaxTime, time());
    $now = date("Y-m-d H:i:s", strtotime("-24 hour"));
    $catz = new mysql_catz();
    if ($catz->UfdbCatEnabled == 0) {
        build_progress("Categories Engine is disabled", 110);
        squid_admin_mysql(1, "Categories Engine is disabled, skip parsing non-categorized websites.", null, __FILE__, __LINE__);
        return;
    }
    build_progress("Updating databases", 10);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.blacklists.php --bycron");
    build_progress("Construct not categorized webistes...", 15);
    $q = new postgres_sql();
    $q->CREATE_TABLES();
    $sql = "SELECT sum(size) as size,sum(rqs) as rqs, familysite from access_log WHERE category='' AND zdate>'{$now}' GROUP BY familysite ORDER BY size DESC LIMIT 5000";
    $q = new postgres_sql();
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
    $DEST_DAY = array();
    $q->QUERY_SQL("truncate table not_categorized");
    while ($ligne = @pg_fetch_assoc($results)) {
        $familysite = $ligne["familysite"];
        $size = $ligne["size"];
        $rqs = $ligne["rqs"];
        echo "{$familysite} {$size} ({$rqs})\n";
        $q->QUERY_SQL("INSERT INTO not_categorized (zdate,familysite,size,rqs) VALUES (NOW(),'{$familysite}','{$size}','{$rqs}')");
    }
    @file_put_contents("{$GLOBALS["BASEDIR"]}/NOT_CATEGORIZED_TIME", time());
    if (system_is_overloaded()) {
        build_progress("Overloaded, aborting", 110);
        return;
    }
    $sql = "SELECT familysite from not_categorized ORDER BY size DESC LIMIT 5000";
    $c = 0;
    $q = new postgres_sql();
    build_progress("Query the system...", 20);
    $results = $q->QUERY_SQL($sql);
    $sum = pg_num_rows($results);
    $c = 0;
    while ($ligne = @pg_fetch_assoc($results)) {
        $c++;
        $perc = $c / $sum;
        $perc = round($perc * 100);
        $perc = $perc + 20;
        if ($perc > 95) {
            $perc = 95;
        }
        $familysite = $ligne["familysite"];
        build_progress("Analyze {$familysite} {$c}/{$sum}", $perc);
        $category = $catz->GET_CATEGORIES($familysite);
        echo "{$familysite} = {$category}\n";
        if ($category != null) {
            build_progress("Analyze {$familysite} = {$category} {$c}/{$sum}", $perc);
            echo "UPDATE access_log = {$category}\n";
            $q->QUERY_SQL("UPDATE access_log SET category='{$category}' WHERE familysite='{$familysite}' AND category=''");
            echo "UPDATE access_month = {$category}\n";
            $q->QUERY_SQL("UPDATE access_month SET category='{$category}' WHERE familysite='{$familysite}' AND category=''");
            echo "UPDATE access_year = {$category}\n";
            $q->QUERY_SQL("UPDATE access_year SET category='{$category}' WHERE familysite='{$familysite}' AND category=''");
            echo "DELETE not_categorized FOR {$familysite}\n";
            $q->QUERY_SQL("DELETE FROM not_categorized WHERE familysite='{$familysite}'");
        }
        $timexec = $unix->file_time_min($MaxTime);
        if ($timexec > 230) {
            build_progress("Expired time, aborting {$c}/{$sum}", 110);
            return;
        }
        if (system_is_overloaded()) {
            build_progress("Overloaded, aborting {$c}/{$sum}", 110);
            return;
        }
    }
    build_progress("{success}", 100);
}
예제 #7
0
function CHECK_CATEGORY_WEEK($WWW, $gpid)
{
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_WEEK"])) {
        return;
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("CATEGORIES CACHE: " . count($GLOBALS["CATEGORIES"]) . " items");
    }
    if (count($GLOBALS["CATEGORIES"]) > 1000) {
        $GLOBALS["CATEGORIES"] = array();
    }
    if (!isset($GLOBALS["CATEGORIES"][$WWW])) {
        $q = new mysql_catz();
        $GLOBALS["CATEGORIES"][$WWW] = trim(strtolower($q->GET_CATEGORIES($WWW)));
    }
    if ($GLOBALS["CATEGORIES"][$WWW] == null) {
        return;
    }
    $CATEGORY = $GLOBALS["CATEGORIES"][$WWW];
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_WEEK"][$CATEGORY])) {
        return;
    }
    $MaxSize = $GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_WEEK"][$CATEGORY];
    $YEAR = date("Y");
    $MONTH = date("m");
    $DAY = date("d");
    $HOUR = date("H");
    $WEEK = date("W");
    $CATEGORY_FOUND = $GLOBALS["CATEGORIES"][$WWW];
    $CATEGORY_FOUND = str_replace("/", "_", $CATEGORY_FOUND);
    $filename = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$WEEK}/CATS/{$CATEGORY_FOUND}";
    if ($GLOBALS["DEBUG"]) {
        if (!is_file($filename)) {
            WLOG("WARNING! {$filename} no such file");
        }
    }
    $size = intval(@file_get_contents($filename));
    if ($size == 0) {
        return false;
    }
    $size = $size / 1024;
    $size = $size / 1024;
    if ($GLOBALS["DEBUG"]) {
        WLOG("{$WWW}: {$CATEGORY} = {$size}MB check if exceed {$MaxSize}MB");
    }
    if ($size >= $MaxSize) {
        return true;
    }
}
 private function GET_CATEGORIES_DB($sitename)
 {
     $pagename = CurrentPageName();
     $t = time();
     $qz = new mysql_catz();
     $this->cloudlogs("{$pagename}: mysql_catz -> {$sitename}");
     $catz = $qz->GET_CATEGORIES($sitename);
     if ($GLOBALS["VERBOSE"]) {
         $took = distanceOfTimeInWords($t, time(), true);
         echo "qz->GET_CATEGORIES_DB({$sitename}) = {$catz} took {$took}<br>\n";
     }
     if ($catz == null) {
         return;
     }
     if (!isset($GLOBALS["ARTICADB"])) {
         $GLOBALS["ARTICADB"] = 0;
     }
     $GLOBALS["ARTICADB"]++;
     $GLOBALS["CATZWHY"] = "INTERNAL-CATZ";
     return trim($catz);
 }
예제 #9
0
function popup_categories_sql()
{
    //ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string','');ini_set('error_append_string','');
    $tpl = new templates();
    $MyPage = CurrentPageName();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "::" . __LINE__ . ":: mysql_squid_builder()\n<br>";
    }
    $q = new mysql_squid_builder();
    $OnlyEnabled = false;
    if (isset($_GET["OnlyEnabled"])) {
        $OnlyEnabled = true;
    }
    $search = '%';
    $table = "webfilters_categories_caches";
    $page = 1;
    $ORDER = "ORDER BY categorykey ASC";
    if (!$q->TABLE_EXISTS($table)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "<H2>Create create_webfilters_categories_caches()</H2>\n";
        }
        $q->create_webfilters_categories_caches();
    }
    $FORCE_FILTER = null;
    if (trim($_GET["group"]) != null) {
        $FORCE_FILTER = " AND master_category='{$_GET["group"]}'";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "<h2>" . __FUNCTION__ . "::" . __LINE__ . ":: q->COUNT_ROWS({$table})</h2>\n<br>";
    }
    if ($q->COUNT_ROWS($table) == 0) {
        $ss = new dansguardian_rules();
        $ss->CategoriesTableCache();
    }
    $www = trim(strtolower($_GET["www"]));
    $ArticaDBZ = new mysql_catz();
    $CategoriesFound = $ArticaDBZ->GET_CATEGORIES($www);
    $catArDB = explode(",", $CategoriesFound);
    writelogs("ArticaDB({$www}) = " . @implode(",", $catArDB), __FUNCTION__, __FILE__, __LINE__);
    if (is_array($catArDB)) {
        while (list($num, $ligne) = each($catArDB)) {
            $ligne = trim($ligne);
            if ($ligne == null) {
                continue;
            }
            $hash_ARTICA[$ligne] = true;
        }
    }
    if (preg_match("#www\\.(.+?)\$#i", $www, $re)) {
        $www = $re[1];
    }
    $q = new mysql_squid_builder();
    $CategoriesFound = $q->GET_CATEGORIES($www, true, true, true, true);
    $cats = explode(",", $CategoriesFound);
    $www_encoded = base64_encode($_GET["www"]);
    $COUNT_ROWS = $q->COUNT_ROWS($table);
    $hash_community = array();
    if (is_array($cats)) {
        while (list($num, $ligne) = each($cats)) {
            $ligne = trim($ligne);
            if ($ligne == null) {
                continue;
            }
            $hash_community[$ligne] = true;
        }
    }
    if ($COUNT_ROWS == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $_POST["query"] = trim($_POST["query"]);
    if ($_POST["query"] != null) {
        $_POST["query"] = "*{$_POST["query"]}*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $COUNT_ROWS;
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
    }
    $c = 0;
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($ligne['categorykey'] == "phishtank") {
            continue;
        }
        $DISABLED = false;
        if ($ligne["picture"] == null) {
            $ligne["picture"] = "20-categories-personnal.png";
        }
        $TextInterne = null;
        $img = "img/{$ligne["picture"]}";
        $val = 0;
        if ($hash_community[$ligne['categorykey']]) {
            $val = 1;
        }
        if ($hash_ARTICA[$ligne['categorykey']]) {
            $TextInterne = $tpl->_ENGINE_parse_body("<div style='color:#D01313;font-size:11px;font-style:italic'>{categorized_in_articadb}</div>");
            $val = 1;
            $DISABLED = true;
        }
        $md = md5($ligne['categorykey']);
        if ($OnlyEnabled) {
            if ($val == 0) {
                if ($TextInterne == null) {
                    continue;
                }
            }
        }
        $c++;
        $js = "DansCommunityCategory('{$md}','{$ligne["categorykey"]}','{$www_encoded}')";
        $disable = Field_checkbox($md, 1, $val, "{$js}", null, $DISABLED);
        $ligne['description'] = utf8_encode($ligne['description']);
        $data['rows'][] = array('id' => $ligne['categorykey'], 'cell' => array("<img src='{$img}'>", "{$ligne['categorykey']}", $TextInterne . $ligne['description'], $disable));
    }
    if ($OnlyEnabled) {
        $data['total'] = $c;
    }
    echo json_encode($data);
}
예제 #10
0
function parseTemplate()
{
    if (isset($_GET["verbose"])) {
        $GLOBALS["VERBOSE"] = true;
    }
    include_once dirname(__FILE__) . "/ressources/class.ufdb.microsoft.inc";
    $CATEGORY_SOURCE = null;
    $proto = "http";
    $url = $_GET["url"];
    $cacheid = null;
    $HTTP_X_FORWARDED_FOR = null;
    $HTTP_X_REAL_IP = null;
    if (isset($_GET["category"])) {
        $CATEGORY_SOURCE = $_GET["category"];
    }
    $AS_SSL = false;
    $DisableSquidGuardHTTPCache = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableSquidGuardHTTPCache"));
    if ($GLOBALS["VERBOSE"]) {
        echo "<div style='background-color:white;font-size:22px;color:black'>" . __LINE__ . ": DisableSquidGuardHTTPCache: {$DisableSquidGuardHTTPCache}</div>\n";
    }
    $HTTP_REFERER = null;
    if (isset($_GET["targetgroup"])) {
        $TARGET_GROUP_SOURCE = $_GET["targetgroup"];
        if ($CATEGORY_SOURCE == null) {
            $CATEGORY_SOURCE = $TARGET_GROUP_SOURCE;
        }
    }
    $clientgroup = $_GET["clientgroup"];
    $QUERY_STRING = $_SERVER["QUERY_STRING"];
    if (isset($_SERVER["HTTP_REFERER"])) {
        $HTTP_REFERER = $_SERVER["HTTP_REFERER"];
    }
    $HTTP_REFERER_HOST = hostfrom_url($HTTP_REFERER);
    if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
        $HTTP_X_FORWARDED_FOR = $_SERVER["HTTP_X_FORWARDED_FOR"];
    }
    if (isset($_SERVER["HTTP_X_REAL_IP"])) {
        $HTTP_X_REAL_IP = $_SERVER["HTTP_X_REAL_IP"];
    }
    $URL_HOST = hostfrom_url($url);
    if (isset($_GET["rule-id"])) {
        $ID = $_GET["rule-id"];
    }
    if (isset($_GET["fatalerror"])) {
        $ID = 0;
        $cacheid = "fatalerror";
    }
    if (isset($_GET["loading-database"])) {
        $ID = 0;
        $cacheid = "loading-database";
    }
    if (isset($_SERVER['HTTPS'])) {
        if (strtolower($_SERVER['HTTPS']) == 'on') {
            $proto = "https";
            $AS_SSL = true;
        }
    }
    $time = date("Ymdh");
    if ($AS_SSL) {
        if (!isset($_GET["SquidGuardIPWeb"])) {
            $requested_uri = "https://" . $_SERVER["SERVER_NAME"] . "/" . $_SERVER["REQUEST_URI"];
            $arrayURI = parse_url($requested_uri);
            $requested_hostname = $arrayURI["host"];
        }
    }
    if (preg_match("#&url=(.*?)(&|\$)#", $QUERY_STRING, $re)) {
        $requested_uri = parseTemplate_string_to_url($re[1]);
        $arrayURI = parse_url($requested_uri);
        $requested_hostname = $arrayURI["host"];
    }
    $GLOBALS["BLOCK_KEY_CACHE"] = md5("{$HTTP_X_FORWARDED_FOR}{$HTTP_X_REAL_IP}{$time}{$proto}{$proto}{$TARGET_GROUP_SOURCE}{$clientgroup}{$requested_hostname}{$HTTP_REFERER_HOST}{$URL_HOST}{$ID}{$cacheid}");
    if ($GLOBALS["VERBOSE"]) {
        $DisableSquidGuardHTTPCache = 1;
    }
    if ($DisableSquidGuardHTTPCache == 0) {
        if (is_file("/home/squid/error_page_cache/{$GLOBALS["BLOCK_KEY_CACHE"]}")) {
            if (parseTemplate_file_time_min("/home/squid/error_page_cache/{$GLOBALS["BLOCK_KEY_CACHE"]}") < 10) {
                echo @file_get_contents("/home/squid/error_page_cache/{$GLOBALS["BLOCK_KEY_CACHE"]}");
                return;
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "<div style='background-color:white;font-size:22px;color:black'>" . __LINE__ . ": TARGET_GROUP_SOURCE {$TARGET_GROUP_SOURCE} / {$requested_hostname}</div>\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "<div style='background-color:white;font-size:22px;color:black'>" . __LINE__ . ": CATEGORY_SOURCE {$CATEGORY_SOURCE} / {$requested_hostname}</div>\n";
    }
    if ($TARGET_GROUP_SOURCE == "none") {
        $TARGET_GROUP_SOURCE = "{ufdb_none}";
        $EnableSquidGuardSearchCategoryNone = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSquidGuardSearchCategoryNone"));
        if ($CATEGORY_SOURCE == null) {
            $EnableSquidGuardSearchCategoryNone = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSquidGuardSearchCategoryNone"));
            if ($EnableSquidGuardSearchCategoryNone == 1) {
                include_once dirname(__FILE__) . "/ressources/class.mysql.catz.inc";
                $catz = new mysql_catz();
                $CATEGORY_SOURCE = $catz->GET_CATEGORIES($requested_hostname);
                if ($CATEGORY_SOURCE == null) {
                    $CATEGORY_SOURCE = "{unknown}";
                }
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "<div style='background-color:white;font-size:22px;color:black'>" . __LINE__ . ": TARGET_GROUP_SOURCE {$TARGET_GROUP_SOURCE} / {$requested_hostname}</div>\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "<div style='background-color:white;font-size:22px;color:black'>" . __LINE__ . ": CATEGORY_SOURCE {$CATEGORY_SOURCE} / {$requested_hostname}</div>\n";
    }
    session_start();
    $HTTP_REFERER = null;
    $template_default_file = dirname(__FILE__) . "/ressources/databases/dansguard-template.html";
    include_once dirname(__FILE__) . "/ressources/class.sockets.inc";
    include_once dirname(__FILE__) . "/ressources/class.mysql.inc";
    $sock = new sockets();
    $users = new usersMenus();
    //$q=new mysql_squid_builder();
    $UfdbGuardRedirectCategories = unserialize(base64_decode($sock->GET_INFO("UfdbGuardRedirectCategories")));
    $SquidGuardWebFollowExtensions = $sock->GET_INFO("SquidGuardWebFollowExtensions");
    $SquidGuardServerName = $sock->GET_INFO("SquidGuardServerName");
    $SquidGuardApachePort = $sock->GET_INFO("SquidGuardApachePort");
    $SquidGuardWebUseLocalDatabase = $sock->GET_INFO("SquidGuardWebUseLocalDatabase");
    $SquidGuardWebBlankReferer = intval($sock->GET_INFO("SquidGuardWebBlankReferer"));
    if (!is_numeric($SquidGuardWebFollowExtensions)) {
        $SquidGuardWebFollowExtensions = 1;
    }
    if (!is_numeric($SquidGuardWebUseLocalDatabase)) {
        $SquidGuardWebUseLocalDatabase = 0;
    }
    if ($SquidGuardWebBlankReferer == 1) {
        if ($URL_HOST != $HTTP_REFERER_HOST) {
            $data = "<html><head></head><body></body></html>";
            header("Content-Length: " . strlen($data));
            header("Content-Type: text/html");
            echo $data;
            die;
        }
    }
    $GLOBALS["JS_NO_CACHE"] = true;
    $GLOBALS["JS_HEAD_PREPREND"] = "{$proto}://{$_SERVER["SERVER_NAME"]}:{$_SERVER["SERVER_PORT"]}";
    if ($SquidGuardWebFollowExtensions == 1) {
        if (parseTemplate_extension($_GET["url"])) {
            return;
        }
    }
    if (parseTemplateForcejs($_GET["url"])) {
        parseTemplateLogs("JS detected : For {$_GET["url"]}", __FUNCTION__, __FILE__, __LINE__);
        header("content-type: application/x-javascript");
        echo "// blocked by url filtering\n";
        return true;
        return;
    }
    $defaultjs = "alert('Disabled')";
    $ADD_JS_PACK = false;
    if ($SquidGuardWebUseLocalDatabase == 1) {
        $clientaddr = base64_encode($_GET["clientaddr"]);
        $defaultjs = "s_PopUp('{$GLOBALS["JS_HEAD_PREPREND"]}/" . basename(__FILE__) . "?SquidGuardWebUseLocalDatabase=1&url=" . base64_encode("{$_GET["url"]}") . "&clientaddr={$clientaddr}',640,350)";
        $ADD_JS_PACK = true;
    }
    if ($users->CORP_LICENSE) {
        $LICENSE = 1;
        $FOOTER = null;
    }
    if (!$users->CORP_LICENSE) {
        $LICENSE = 0;
    }
    parseTemplateLogs("{$_GET["clientaddr"]}: Category=`{$CATEGORY_SOURCE}` targetgroup=`{$_GET["targetgroup"]}` LICENSE:{$LICENSE}", __FUNCTION__, __FILE__, __LINE__);
    $CATEGORY_KEY = null;
    $_GET["targetgroup"] = parseTemplate_categoryname($TARGET_GROUP_SOURCE, $LICENSE);
    $_GET["clientgroup"] = parseTemplate_categoryname($_GET["clientgroup"], $LICENSE);
    $_GET["category"] = parseTemplate_categoryname($CATEGORY_SOURCE, $LICENSE);
    $CATEGORY_KEY = parseTemplate_categoryname($CATEGORY_SOURCE, $LICENSE, 1);
    if ($CATEGORY_KEY == null) {
        $CATEGORY_KEY = parseTemplate_categoryname($TARGET_GROUP_SOURCE, $LICENSE, 1);
    }
    $_CATEGORIES_K = $_GET["category"];
    $_RULE_K = $_GET["clientgroup"];
    if ($_CATEGORIES_K == null) {
        $_CATEGORIES_K = $_GET["targetgroup"];
    }
    if ($_RULE_K == null) {
        $_RULE_K = "{web_filtering}";
    }
    $REASONGIVEN = "{web_filtering} {$_CATEGORIES_K}";
    if ($_CATEGORIES_K == "restricted_time") {
        $REASONGIVEN = "{restricted_access}";
    }
    parseTemplateLogs("{$REASONGIVEN}: _CATEGORIES_K=`{$_CATEGORIES_K}` _RULE_K={$_RULE_K}` LICENSE:{$LICENSE}", __FUNCTION__, __FILE__, __LINE__);
    $IpToUid = null;
    //$IpToUid=$q->IpToUid($_GET["clientaddr"]);
    if ($IpToUid != null) {
        $IpToUid = "&nbsp;({$IpToUid})";
    }
    if ($LICENSE == 1) {
        if ($CATEGORY_KEY != null) {
            $RedirectCategory = $UfdbGuardRedirectCategories[$CATEGORY_KEY];
            if ($RedirectCategory["enable"] == 1) {
                if ($RedirectCategory["blank_page"] == 1) {
                    parseTemplateLogs("[{$CATEGORY_KEY}]: blank_page : For {$_GET["url"]}", __FUNCTION__, __FILE__, __LINE__);
                    header("HTTP/1.1 200 OK");
                    die;
                    return;
                }
                if (trim($RedirectCategory["template_data"]) != null) {
                    header('Content-Type: text/html; charset=iso-8859-1');
                    $TemplateErrorFinal = $RedirectCategory["template_data"];
                    return;
                }
            }
        }
    }
    $EnableSquidFilterWhiteListing = $sock->GET_INFO("EnableSquidFilterWhiteListing");
    if ($LICENSE == 1) {
        if (is_numeric($ID)) {
            if ($ID == 0) {
                $ligne["groupname"] = "Default";
            } else {
                $sql = "SELECT groupname FROM webfilter_rules WHERE ID={$ID}";
                $q = new mysql_squid_builder();
                $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
                $ruleName = $ligne["groupname"];
            }
        } else {
            writelogs("ID: not a numeric", __FUNCTION__, __FILE__, __LINE__);
        }
    }
    if (isset($_GET["fatalerror"])) {
        $_GET["clientaddr"] = $_SERVER["REMOTE_ADDR"];
        $_GET["clientname"] = $_SERVER["REMOTE_HOST"];
        $REASONGIVEN = "{webfiltering_issue}";
        $_CATEGORIES_K = "{system_Webfiltering_error}";
        $_RULE_K = "{service_error}";
        $_GET["url"] = $_SERVER['HTTP_REFERER'];
    }
    if (isset($_GET["loading-database"])) {
        $_GET["clientaddr"] = $_SERVER["REMOTE_ADDR"];
        $_GET["clientname"] = $_SERVER["REMOTE_HOST"];
        $REASONGIVEN = "{Webfiltering_maintenance}";
        $_CATEGORIES_K = "{please_wait_reloading_databases}";
        $_RULE_K = "{waiting_service}....";
        $_GET["url"] = $_SERVER['HTTP_REFERER'];
    }
    if (!isset($_SESSION["IPRES"][$_GET["clientaddr"]])) {
        $_SESSION["IPRES"][$_GET["clientaddr"]] = gethostbyaddr($_GET["clientaddr"]);
    }
    if (isset($_GET["source"])) {
        $_GET["clientaddr"] = $_GET["source"];
    }
    if (isset($_GET["user"])) {
        $_GET["clientname"] = $_GET["user"];
    }
    if (isset($_GET["virus"])) {
        $_GET["targetgroup"] = $_GET["virus"];
        $ruleName = null;
    }
    if ($_GET["clientuser"] != null) {
        $_GET["clientname"] = $_GET["clientuser"];
    }
    $ruleName = parseTemplate_categoryname($ruleName, $LICENSE);
    $ARRAY["URL"] = $_GET["url"];
    $ARRAY["IPADDR"] = $_GET["clientaddr"];
    $ARRAY["REASONGIVEN"] = $REASONGIVEN;
    $ARRAY["CATEGORY_KEY"] = $CATEGORY_KEY;
    $ARRAY["RULE_ID"] = $ID;
    $ARRAY["CATEGORY"] = $_CATEGORIES_K;
    $ARRAY["RULE"] = $_RULE_K;
    if ($ruleName != null) {
        $ARRAY["RULE"] = $ruleName;
    }
    $ARRAY["targetgroup"] = $_GET["targetgroup"];
    $ARRAY["IpToUid"] = $IpToUid;
    $ARRAY["clientname"] = $_GET["clientname"];
    $ARRAY["HOST"] = $_SESSION["IPRES"][$_GET["clientaddr"]];
    $GLOBALS["BLOCK_KEY_CACHE"];
    $Content = parseTemplate_build_main($ARRAY);
    @file_put_contents("/home/squid/error_page_cache/{$GLOBALS["BLOCK_KEY_CACHE"]}", $Content);
    echo $Content;
}
예제 #11
0
function BANDWIDTH_MONITOR()
{
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 1) {
        return;
    }
    $watchdog = new squid_watchdog();
    $MonitConfig = $watchdog->MonitConfig;
    if ($MonitConfig["CHECK_BANDWITDH"] == 0) {
        return;
    }
    $CHECK_BANDWITDH_INTERVAL = $MonitConfig["CHECK_BANDWITDH_INTERVAL"];
    $influx = new influx();
    if (!is_numeric($CHECK_BANDWITDH_INTERVAL)) {
        $CHECK_BANDWITDH_INTERVAL = 5;
    }
    $olddate = strtotime("-{$CHECK_BANDWITDH_INTERVAL} minutes", time());
    $CHECK_BANDWITDH_SIZE = intval($MonitConfig["CHECK_BANDWITDH_INTERVAL"]);
    $query_date = date("Y-m-d H:i:s", $olddate);
    $postgres = new postgres_sql();
    $sql = "select sum(SIZE) as size from access_log where zdate > '{$olddate}'";
    $ligne = @pg_fetch_assoc($postgres->QUERY_SQL($sql));
    $size = $ligne["size"] / 1024;
    $size = round($size / 1024, 2);
    if ($GLOBALS["VERBOSE"]) {
        echo "Since " . date("Y-m-d H:i:s", $olddate) . "- Size: {$size}MB\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$size}MB must be higher than {$CHECK_BANDWITDH_SIZE}MB\n";
    }
    if ($size < $CHECK_BANDWITDH_SIZE) {
        return;
    }
    $EXCEED_SIZE = $size;
    $REPORT[] = "Report bandwidth usage since: " . date("{l} {F} d H:i:s", $olddate);
    $ipclass = new IP();
    $sql = "select sum(size) as size,ipaddr,mac,userid from access_log where zdate > '{$olddate}' group by IPADDR,MAC,USERID order by size desc";
    $results = $postgres->QUERY_SQL($sql);
    while ($ligne = @pg_fetch_assoc($results)) {
        $users2 = array();
        $size = $ligne["size"] / 1024;
        $size = round($size / 1024, 2);
        if ($size == 0) {
            continue;
        }
        if ($size < 1) {
            continue;
        }
        if ($CHECK_BANDWITDH_SIZE > 1) {
            if ($size < 2) {
                continue;
            }
        }
        $IPADDR = $ligne["ipaddr"];
        $users2[] = $IPADDR;
        $MAC = trim($ligne["mac"]);
        $USERID = $ligne["userid"];
        if ($USERID != null) {
            $users2[] = $USERID;
        }
        if ($ipclass->IsvalidMAC($MAC)) {
            $users2[] = $MAC;
        }
        $REPORT[] = "User: "******", ", $users2) . " {$size}MB used";
        if ($GLOBALS["VERBOSE"]) {
            echo "Since " . date("Y-m-d H:i:s", $olddate) . "- {$IPADDR},{$MAC},{$USERID} Size: {$size}MB\n";
        }
    }
    $catz = new mysql_catz();
    $sql = "select sum(SIZE) as size,familysite from access_log group by familysite where zdate > '{$olddate}' ORDER by size desc";
    $results = $postgres->QUERY_SQL($sql);
    while ($ligne = @pg_fetch_assoc($results)) {
        $size = $ligne["size"] / 1024;
        $size = round($size / 1024, 2);
        if ($size == 0) {
            continue;
        }
        if ($size < 1) {
            continue;
        }
        $FAMILYSITE = $ligne["familysite"];
        $category = $catz->GET_CATEGORIES($FAMILYSITE);
        if ($category != null) {
            $category_text = " (category:{$category})";
        }
        $REPORT[] = "Web site: {$FAMILYSITE} {$size}MB used{$category_text}";
    }
    squid_admin_mysql(0, "Bandwidth usage {$EXCEED_SIZE}MB exceed {$CHECK_BANDWITDH_SIZE}MB", @implode("\n", $REPORT), __FILE__, __LINE__);
}
예제 #12
0
function categories_match($gpid, $sitname)
{
    $sitname = trim($sitname);
    if (preg_match("#^www\\.(.+)#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("Analyze: Group: {$gpid} `{$sitname}`");
    }
    $categories_get_memory = categories_get_memory($gpid, $sitname);
    if ($categories_get_memory != null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` ");
        }
        if ($categories_get_memory == "UNKNOWN") {
            if ($GLOBALS["DEBUG"]) {
                WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> UNKNOWN");
            }
            return null;
        }
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> {$categories_get_memory}");
        }
        return $categories_get_memory;
    }
    $q = new mysql_catz();
    $categoriF = $q->GET_CATEGORIES($sitname);
    $trans = $q->TransArray();
    if ($GLOBALS["DEBUG"]) {
        WLOG("Group: {$gpid} `{$sitname}` -> RESULTS: `{$categoriF}` ");
    }
    if ($categoriF == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> SET TO  `UNKNOWN` ");
        }
        categories_set_memory($gpid, $sitname, "UNKNOWN");
        return null;
    }
    if (strpos($categoriF, ",") > 0) {
        $categoriT = explode(",", $categoriF);
    } else {
        $categoriT[] = $categoriF;
    }
    while (list($a, $b) = each($categoriT)) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> category IS: [{$b}] [" . __LINE__ . "]");
        }
        $MAIN[$b] = true;
    }
    $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl";
    $categories = unserialize(@file_get_contents($filename));
    while (list($category_table, $category_rule) = each($categories)) {
        $category_rule = urlencode($category_rule);
        $categoryname = $trans[$category_table];
        if (isset($MAIN[$categoryname])) {
            if ($GLOBALS["DEBUG"]) {
                WLOG("FOUND `{$categoryname}` -> `{$category_rule}` ");
            }
            categories_set_memory($gpid, $sitname, $category_rule);
            return $category_rule;
        } else {
            if ($GLOBALS["DEBUG"]) {
                WLOG("Group: {$gpid} `{$sitname}` -> {$categoryname} = NO MATCH [" . __LINE__ . "]");
            }
        }
    }
    categories_set_memory($gpid, $sitname, "UNKNOWN");
}
예제 #13
0
function BANDWIDTH_MONITOR()
{
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 1) {
        return;
    }
    $watchdog = new squid_watchdog();
    $MonitConfig = $watchdog->MonitConfig;
    if ($MonitConfig["CHECK_BANDWITDH"] == 0) {
        return;
    }
    $CHECK_BANDWITDH_INTERVAL = $MonitConfig["CHECK_BANDWITDH_INTERVAL"];
    $influx = new influx();
    if (!is_numeric($CHECK_BANDWITDH_INTERVAL)) {
        $CHECK_BANDWITDH_INTERVAL = 5;
    }
    $olddate = strtotime("-{$CHECK_BANDWITDH_INTERVAL} minutes", time());
    $CHECK_BANDWITDH_SIZE = intval($MonitConfig["CHECK_BANDWITDH_INTERVAL"]);
    $sql = "select sum(SIZE) as size from access_log where time > {$olddate}s";
    $main = $influx->QUERY_SQL($sql);
    foreach ($main as $row) {
        $size = $row->size / 1024;
        $size = round($size / 1024, 2);
        if ($GLOBALS["VERBOSE"]) {
            echo "Since " . date("Y-m-d H:i:s", $olddate) . "- Size: {$size}MB\n";
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$size}MB must be higher than {$CHECK_BANDWITDH_SIZE}MB\n";
    }
    if ($size < $CHECK_BANDWITDH_SIZE) {
        return;
    }
    $EXCEED_SIZE = $size;
    $REPORT[] = "Report bandwidth usage since: " . date("{l} {F} d H:i:s", $olddate);
    $ipclass = new IP();
    $sql = "select sum(SIZE) as size,IPADDR,MAC,USERID from access_log group by IPADDR,MAC,USERID where time > {$olddate}s";
    $main = $influx->QUERY_SQL($sql);
    foreach ($main as $row) {
        $users2 = array();
        $size = $row->size / 1024;
        $size = round($size / 1024, 2);
        if ($size == 0) {
            continue;
        }
        if ($size < 1) {
            continue;
        }
        if ($CHECK_BANDWITDH_SIZE > 1) {
            if ($size < 2) {
                continue;
            }
        }
        $IPADDR = $row->IPADDR;
        $users2[] = $IPADDR;
        $MAC = trim($row->MAC);
        $USERID = trim($row->USERID);
        if ($USERID != null) {
            $users2[] = $USERID;
        }
        if ($ipclass->IsvalidMAC($MAC)) {
            $users2[] = $MAC;
        }
        $REPORT[] = "User: "******", ", $users2) . " {$size}MB used";
        if ($GLOBALS["VERBOSE"]) {
            echo "Since " . date("Y-m-d H:i:s", $olddate) . "- {$IPADDR},{$MAC},{$USERID} Size: {$size}MB\n";
        }
    }
    $catz = new mysql_catz();
    $sql = "select sum(SIZE) as size,FAMILYSITE from access_log group by FAMILYSITE where time > {$olddate}s";
    $main = $influx->QUERY_SQL($sql);
    foreach ($main as $row) {
        $size = $row->size / 1024;
        $size = round($size / 1024, 2);
        if ($size == 0) {
            continue;
        }
        if ($size < 1) {
            continue;
        }
        $FAMILYSITE = $row->FAMILYSITE;
        $category = $catz->GET_CATEGORIES($FAMILYSITE);
        if ($category != null) {
            $category_text = " (category:{$category})";
        }
        $REPORT[] = "Web site: {$FAMILYSITE} {$size}MB used{$category_text}";
    }
    squid_admin_mysql(0, "Bandwidth usage {$EXCEED_SIZE}MB exceed {$CHECK_BANDWITDH_SIZE}MB", @implode("\n", $REPORT), __FILE__, __LINE__);
}
예제 #14
0
function inject($category, $table = null, $file = null)
{
    include_once dirname(__FILE__) . "/ressources/class.dansguardian.inc";
    $unix = new unix();
    $q = new mysql_squid_builder();
    if (is_file($category)) {
        $file = $category;
        $category_name = basename($file);
        echo "{$file} -> {$category_name}\n";
        if (preg_match("#(.+?)\\.gz\$#", $category_name)) {
            echo "{$category_name} -> gunzip\n";
            $new_category_name = str_replace(".gz", "", $category_name);
            $gunzip = $unix->find_program("gunzip");
            $target_file = dirname($file) . "/{$new_category_name}";
            $cmd = "/bin/gunzip -d -c \"{$file}\" >{$target_file} 2>&1";
            echo "{$cmd}\n";
            shell_exec($cmd);
            if (!is_file($target_file)) {
                echo "Uncompress failed\n";
                return;
            }
            $file = $target_file;
            $table = $new_category_name;
            $category = $q->tablename_tocat($table);
            echo "{$new_category_name} -> {$table}\n";
        } else {
            $table = $category_name;
            echo "{$new_category_name} -> {$table}\n";
            $category = $q->tablename_tocat($table);
        }
        echo "Table: {$table}\nSource File:{$file}\nCategory: {$category}\n";
    }
    if (!is_file($file)) {
        if (!is_file($table)) {
            echo "`{$table}` No such file\n";
        }
        if (is_file($table)) {
            $file = $table;
            $table = null;
        }
    }
    if ($table == null) {
        $table = "category_" . $q->category_transform_name($category);
        echo "Table will be {$table}\n";
    }
    if (!$q->TABLE_EXISTS($table)) {
        echo "{$table} does not exists, check if it is an official one\n";
        $dans = new dansguardian_rules();
        if (isset($dans->array_blacksites[$category])) {
            $q->CreateCategoryTable($category);
        }
    }
    if (!$q->TABLE_EXISTS($table)) {
        echo "`{$category}` -> no such table \"{$table}\"\n";
        return;
    }
    $sql = "SELECT COUNT(*) AS TCOUNT FROM {$table}";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        if (preg_match("#is marked as crashed and last#", $q->mysql_error)) {
            echo "`{$table}` -> crashed, remove \"{$table}\"\n";
            $q->QUERY_SQL("DROP TABLE {$table}");
            $q->QUERY_SQL("flush tables");
            $q = new mysql_squid_builder();
            echo "`{$table}` -> Create category \"{$category}\"\n";
            $q->CreateCategoryTable($category);
            $q->CreateCategoryTable($category);
            $q = new mysql_squid_builder();
        }
        if (!$q->TABLE_EXISTS($table)) {
            echo "`{$category}` -> no such table \"{$table}\"\n";
            return;
        }
    }
    if ($file == null) {
        $dir = "/var/lib/squidguard";
        if ($GLOBALS["SHALLA"]) {
            $dir = "/root/shalla/BL";
        }
        if (!is_file("{$dir}/{$category}/domains")) {
            echo "{$dir}/{$category}/domains no such file";
            return;
        }
        $file = "{$dir}/{$category}/domains";
    }
    if (!is_file($file)) {
        echo "{$file} no such file";
        return;
    }
    $sock = new sockets();
    $unix = new unix();
    $uuid = $unix->GetUniqueID();
    if ($uuid == null) {
        echo "No uuid\n";
        return;
    }
    echo "open {$file}\n";
    $handle = @fopen($file, "r");
    if (!$handle) {
        echo "Failed to open file\n";
        return;
    }
    $q = new mysql_squid_builder();
    if ($GLOBALS["CATTO"] != null) {
        $category = $GLOBALS["CATTO"];
    }
    $countstart = $q->COUNT_ROWS($table);
    $prefix = "INSERT IGNORE INTO {$table} (zmd5,zDate,category,pattern,uuid) VALUES ";
    echo "{$prefix}\n";
    $catz = new mysql_catz();
    $c = 0;
    $CBAD = 0;
    $CBADIP = 0;
    $CBADNULL = 0;
    while (!feof($handle)) {
        $c++;
        $www = trim(fgets($handle, 4096));
        if ($www == null) {
            $CBADNULL++;
            continue;
        }
        $www = str_replace('"', "", $www);
        if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $www)) {
            $CBADIP++;
            continue;
        }
        $www = trim(strtolower($www));
        if ($www == "thisisarandomentrythatdoesnotexist.com") {
            $CBAD++;
            continue;
        }
        if ($www == null) {
            $CBADNULL++;
            continue;
        }
        if (preg_match("#(.+?)\\s+(.+)#", $www, $re)) {
            $www = $re[1];
        }
        if (preg_match("#^\\.(.*)\$#", $www, $re)) {
            $www = $re[1];
        }
        if (strpos($www, "#") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "'") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "{") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "(") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, ")") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        if (strpos($www, "%") > 0) {
            echo "FALSE: {$www}\n";
            continue;
        }
        $category2 = $catz->GET_CATEGORIES($www);
        if ($category2 != null) {
            if ($category2 == $category) {
                continue;
            }
            $md5 = md5($category . $www);
            if ($category == "p**n") {
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "hobby/arts") {
                    echo date("H:i:s") . " Remove {$www} from hobby/arts and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hobby_arts WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "finance/realestate") {
                    echo date("H:i:s") . " Remove {$www} from finance/realestate and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_finance_realestate WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science/computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "proxy") {
                    echo date("H:i:s") . " Remove {$www} from proxy and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_proxy WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "searchengines") {
                    echo date("H:i:s") . " Remove {$www} from searchengines and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_searchengines WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "blog") {
                    echo date("H:i:s") . " Remove {$www} from blog and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_blog WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "forums") {
                    echo date("H:i:s") . " Remove {$www} from blog and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_blog WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/sports") {
                    echo date("H:i:s") . " Remove {$www} from recreation/sports and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_sports WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "hacking") {
                    echo date("H:i:s") . " Remove {$www} from hacking and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hacking WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "malware") {
                    echo date("H:i:s") . " Remove {$www} from malware and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_malware WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "drugs") {
                    echo date("H:i:s") . " Remove {$www} from drugs and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_drugs WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "health") {
                    echo date("H:i:s") . " Remove {$www} from health and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_health WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "news") {
                    echo date("H:i:s") . " Remove {$www} from news and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_news WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "audio-video") {
                    echo date("H:i:s") . " Remove {$www} from audio-video and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_audio_video WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/schools") {
                    echo date("H:i:s") . " Remove {$www} from recreation/schools and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_schools WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "reaffected") {
                    echo date("H:i:s") . " Remove {$www} from reaffected and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_reaffected WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "warez") {
                    echo date("H:i:s") . " Remove {$www} from warez and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_warez WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "suspicious") {
                    echo date("H:i:s") . " Remove {$www} from suspicious and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_suspicious WHERE `pattern`='{$www}'");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    $q->QUERY_SQL("INSERT IGNORE INTO category_porn (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
            }
            if ($category == "gamble") {
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
            }
            if ($category == "proxy") {
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "p**n") {
                    echo date("H:i:s") . " Remove {$www} from p**n and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_porn WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science/computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "filehosting") {
                    echo date("H:i:s") . " Remove {$www} from filehosting and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_filehosting WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "hacking") {
                    echo date("H:i:s") . " Remove {$www} from hacking and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_hacking WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
                if ($category2 == "governments") {
                    echo date("H:i:s") . " Remove {$www} from governments and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_governments WHERE `pattern`='{$www}'");
                    $q->categorize($www, $category, true);
                    continue;
                }
            }
            if ($category == "spyware") {
                if ($category2 == "society") {
                    echo date("H:i:s") . " Remove {$www} from society and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_society WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "industry") {
                    echo date("H:i:s") . " Remove {$www} from industry and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_industry WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/sports") {
                    echo date("H:i:s") . " Remove {$www} from recreation/sports and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_sports WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/schools") {
                    echo date("H:i:s") . " Remove {$www} from recreation/schools and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_schools WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "searchengines") {
                    echo date("H:i:s") . " Remove {$www} from searchengines and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_searchengines WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "shopping") {
                    echo date("H:i:s") . " Remove {$www} from shopping and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_shopping WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "audio-video") {
                    echo date("H:i:s") . " Remove {$www} from audio-video and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_audio_video WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "suspicious") {
                    $q->QUERY_SQL("DELETE FROM category_suspicious WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "health") {
                    echo date("H:i:s") . " Remove {$www} from health and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_health WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "jobsearch") {
                    echo date("H:i:s") . " Remove {$www} from jobsearch and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_jobsearch WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "hobby/arts") {
                    $q->QUERY_SQL("DELETE FROM category_hobby_arts WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "science/computing") {
                    echo date("H:i:s") . " Remove {$www} from science_computing and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_science_computing WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "recreation/travel") {
                    echo date("H:i:s") . " Remove {$www} from recreation_travel and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_recreation_travel WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "dynamic") {
                    echo date("H:i:s") . " Remove {$www} from dynamic and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_dynamic WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "finance/realestate") {
                    echo date("H:i:s") . " Remove {$www} from finance_realestate and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_finance_realestate WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "isp") {
                    echo date("H:i:s") . " Remove {$www} from isp and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_isp WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "housing/accessories") {
                    echo date("H:i:s") . " Remove {$www} from housing/accessories and add it to {$category}\n";
                    $q->QUERY_SQL("DELETE FROM category_housing_accessories WHERE `pattern`='{$www}'");
                    $q->QUERY_SQL("INSERT IGNORE INTO category_spyware (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'p**n','{$www}','{$uuid}',1)");
                    if (!$q->ok) {
                        echo "{$q->mysql_error}\n";
                        die;
                    }
                    continue;
                }
                if ($category2 == "malware") {
                    continue;
                }
                if ($category2 == "phishing") {
                    continue;
                }
            }
            echo date("H:i:s") . " {$www} {$category2} SKIP\n";
            continue;
        }
        $md5 = md5($www . $category);
        $n[] = "('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')";
        if (count($n) > 6000) {
            $sql = $prefix . @implode(",", $n);
            $q->QUERY_SQL($sql, "artica_backup");
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
                $n = array();
                continue;
            }
            $countend = $q->COUNT_ROWS($table);
            $final = $countend - $countstart;
            echo "" . numberFormat($c, 0, "", " ") . " items, " . numberFormat($final, 0, "", " ") . " new entries added - {$CBADNULL} bad entries for null value,{$CBADIP} entries for IP addresses\n";
            $n = array();
        }
    }
    fclose($handle);
    if (count($f) > 0) {
        if ($c > 0) {
            $countend = $q->COUNT_ROWS($table);
            $final = $countend - $countstart;
            echo "{$c} items, {$final} new entries added - {$CBAD} bad entries\n";
            $sql = $prefix . @implode(",", $n);
            $q->QUERY_SQL($sql, "artica_backup");
            if (!$q->ok) {
                echo $q->mysql_error . "\n{$sql}";
                continue;
            }
            $n = array();
        }
    }
    $countend = $q->COUNT_ROWS($table);
    $final = $countend - $countstart;
    echo "" . numberFormat($final, 0, "", " ") . " new entries added\n";
    @unlink($file);
}
예제 #15
0
function test()
{
    $tpl = new templates();
    $www = $_GET["test"];
    $q = new mysql_squid_builder();
    $ipaddr = $_POST["ipaddr"];
    $user = $_POST["user"];
    $www = $_POST["www"];
    $_SESSION["UFDBT"]["IP"] = $ipaddr;
    $_SESSION["UFDBT"]["USER"] = $user;
    $_SESSION["UFDBT"]["WWW"] = $www;
    if ($user == null) {
        $user = "******";
    }
    if ($ipaddr == null) {
        $ipaddr = "-";
    }
    $sock = new sockets();
    $datas = unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
    if (!isset($datas["UseRemoteUfdbguardService"])) {
        $datas["UseRemoteUfdbguardService"] = 0;
    }
    if (!isset($datas["remote_port"])) {
        $datas["remote_port"] = 3977;
    }
    if (!isset($datas["remote_server"])) {
        $datas["remote_server"] = null;
    }
    if (!isset($datas["listen_addr"])) {
        $datas["listen_addr"] = "127.0.0.1";
    }
    if (!isset($datas["listen_port"])) {
        $datas["listen_port"] = "3977";
    }
    if (!isset($datas["tcpsockets"])) {
        $datas["tcpsockets"] = 1;
    }
    if (!isset($datas["url_rewrite_children_concurrency"])) {
        $datas["url_rewrite_children_concurrency"] = 2;
    }
    if (!isset($datas["url_rewrite_children_startup"])) {
        $datas["url_rewrite_children_startup"] = 5;
    }
    if (!isset($datas["url_rewrite_children_idle"])) {
        $datas["url_rewrite_children_idle"] = 5;
    }
    if (!is_numeric($datas["listen_port"])) {
        $datas["listen_port"] = "3977";
    }
    if (!is_numeric($datas["tcpsockets"])) {
        $datas["tcpsockets"] = 1;
    }
    if (!is_numeric($datas["UseRemoteUfdbguardService"])) {
        $datas["UseRemoteUfdbguardService"] = 0;
    }
    if (!is_numeric($datas["remote_port"])) {
        $datas["remote_port"] = 3977;
    }
    if ($datas["remote_port"] == null) {
        $datas["UseRemoteUfdbguardService"] = 0;
    }
    if ($datas["listen_addr"] == null) {
        $datas["listen_addr"] = "127.0.0.1";
    }
    if ($datas["listen_addr"] == "all") {
        $datas["listen_addr"] = "127.0.0.1";
    }
    $address = null;
    if ($datas["UseRemoteUfdbguardService"] == 1) {
        if (trim($datas["remote_server"] == null)) {
            $datas["remote_server"] = "127.0.0.1";
        }
        $address = "-S {$datas["remote_server"]} -p {$datas["remote_port"]} ";
    }
    if ($address == null) {
        if ($datas["tcpsockets"] == 1) {
            $address = "-S {$datas["listen_addr"]} -p {$datas["listen_port"]} ";
        } else {
            $address = "-S 127.0.0.1 -p {$datas["listen_port"]} ";
        }
    }
    if ($address == null) {
        echo "<strong style='color:#d32d2d'>Cannot determine address</strong>\n";
        return;
    }
    $cmdline = "{$address} {$www} {$ipaddr} {$user}";
    $cmdline = urlencode(base64_encode($cmdline));
    $datas = base64_decode($sock->getFrameWork("squid.php?ufdbclient={$cmdline}"));
    if (preg_match("#^http.*#", $www)) {
        $url_www = parse_url($www);
        $url_host = $url_www["host"];
    } else {
        $url_host = $www;
    }
    $tpl = new templates();
    $title_pass = $tpl->_ENGINE_parse_body("{access_to_internet}");
    $redirected = $tpl->_ENGINE_parse_body("{redirected}");
    $datas = trim($datas);
    if ($datas == "OK") {
        $datas = null;
    }
    if (trim($datas) == null) {
        $catz = new mysql_catz();
        $category = $catz->GET_CATEGORIES($url_host);
        if ($category != null) {
            $category_text = $tpl->_ENGINE_parse_body("<br>{category}: {$category}");
        }
        echo "\n\t\t\t<table style='width:100%'>\n\t\t\t<tr>\n\t\t\t\t<td valign='top' style='width:256px'><img src='img/shield-ok-256.png'>\n\t\t\t\t<td valign='top' style='width:99%;vertical-align:middle'>\n\t\t\t\t\t<div style='font-size:26px;color:#46a346'>{$title_pass}{$category_text}</div></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t\n\t\t\t\n";
        return;
    }
    $HTTP_CODE = "{http_status_code}: 302<br>";
    if (preg_match('#status=([0-9]+)\\s+url="(.*?)"#', $datas, $re)) {
        $datas = $re[2];
        $HTTP_CODE = "{http_status_code}: {$re[1]}<br>";
    }
    $url = parse_url($datas);
    if (!is_numeric($url["port"])) {
        $url["port"] = 80;
    }
    echo "<table style='width:100%'>\n\t\t\t<tr>\n\t\t\t\t<td valign='top' style='width:256px'><img src='img/shield-red-256.png'>\n\t\t\t\t<td valign='top' style='width:99%;vertical-align:middle'>\n\t\t\t<div style='font-size:22px;color:#d32d2d'>";
    echo "{$redirected}: {$url["scheme"]}://{$url["host"]}:{$url["port"]}<br>";
    $queries = explode("&", $url["query"]);
    while (list($num, $line) = each($queries)) {
        if (preg_match("#(.+?)=(.+)#", $line, $re)) {
            $array[$re[1]] = $re[2];
        }
    }
    echo $tpl->_ENGINE_parse_body($HTTP_CODE);
    if ($array["targetgroup"] == "none") {
        $catz = new mysql_catz();
        $category = $catz->GET_CATEGORIES($url_host);
        if ($category == null) {
            $array["targetgroup"] = "{ufdb_none} - {unknown}";
        } else {
            $array["targetgroup"] = "{ufdb_none} - {$category}";
        }
    }
    if ($url["path"] == "/ufdbguardd.php") {
        if (isset($array["rule-id"])) {
            $sql = "SELECT * FROM webfilter_rules WHERE ID={$array["rule-id"]}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
            echo $tpl->_ENGINE_parse_body("{rulename}: {$ligne["rulename"]} - {$array["clientgroup"]}<br>");
        }
        if (isset($array["clientaddr"])) {
            echo $tpl->_ENGINE_parse_body("{address}: {$array["clientaddr"]}<br>");
        }
        if (isset($array["clientuser"])) {
            echo $tpl->_ENGINE_parse_body("{member}: {$array["clientuser"]}<br>");
        }
        if (isset($array["targetgroup"])) {
            echo $tpl->_ENGINE_parse_body("{category}: {$array["targetgroup"]}<br>");
        }
    }
    echo "</div></td></tr></table>";
}
예제 #16
0
function getimg($category, $website)
{
    $f = new mysql_catz();
    $img = "<td style='font-size:18px' width=33% align='left'>&nbsp;</td><td style='width:45px' nowrap><img src='img/ok42.png'></td>";
    $caz = $f->GET_CATEGORIES($website);
    if ($caz == null) {
        return "<td style='font-size:18px' width=33% align='left'>&nbsp;</td><td style='width:45px' nowrap><img src='img/42-red.png'></td>";
    }
    if (trim($category) != trim($caz)) {
        return "<td style='font-size:18px' width=33% align='left'>{$caz}</td><td style='width:45px' nowrap><img src='img/warning42.png'></td>";
    }
    return $img;
}
예제 #17
0
function events_list()
{
    $sock = new sockets();
    $catz = new mysql_catz();
    $sock->getFrameWork("squid.php?access-real=yes&rp={$_POST["rp"]}&query=" . urlencode($_POST["query"]) . "&SearchString={$_GET["SearchString"]}");
    $filename = "/usr/share/artica-postfix/ressources/logs/access.log.tmp";
    $dataZ = explode("\n", @file_get_contents($filename));
    $tpl = new templates();
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($data);
    $data['rows'] = array();
    $today = date("Y-m-d");
    $tcp = new IP();
    $cachedT = $tpl->_ENGINE_parse_body("{cached}");
    $unknown = $tpl->javascript_parse_text("{unknown}");
    $c = 0;
    if (count($dataZ) == 0) {
        json_error_show("no data");
    }
    $zcat = new squid_familysite();
    $logfileD = new logfile_daemon();
    krsort($dataZ);
    $IP = new IP();
    while (list($num, $line) = each($dataZ)) {
        $TR = preg_split("/[\\s]+/", $line);
        if (count($TR) < 5) {
            continue;
        }
        $c++;
        $color = "black";
        $date = date("Y-m-d H:i:s", $TR[0]);
        $durationunit = "s";
        $duration = $TR[1] / 1000;
        if ($duration < 60) {
            $duration = round($duration, 2);
        }
        if ($duration > 60) {
            $duration = round($duration / 60, 2);
            $durationunit = "mn";
        }
        $ip = $TR[2];
        $zCode = explode("/", $TR[3]);
        $size = $TR[4];
        $PROTO = $TR[5];
        if ($logfileD->CACHEDORNOT($zCode[0])) {
            $color = "#009223";
        }
        $codeToString = $logfileD->codeToString($zCode[1]);
        $port = null;
        $infos = null;
        $prefix = null;
        $query = null;
        $scheme = null;
        if ($PROTO == "CONNECT") {
            $color = "#BAB700";
            $PROTO = "SSL";
            $scheme = "https";
        }
        if ($zCode[1] > 399) {
            $color = "#D0080A";
        }
        if ($zCode[1] == 307) {
            $color = "#F59C44";
        }
        if ($PROTO == "GET" or $PROTO == "POST") {
            if (preg_match("#TCP_REDIRECT#", $zCode[0])) {
                $color = "#A01E1E";
            }
        }
        $URL = $TR[6];
        $SOURCE_URL = $URL;
        $fontsize = 14;
        if ($_GET["minsize"] == 1) {
            $fontsize = 12;
        }
        $user = "******";
        if ($user == "-") {
            $user = null;
        }
        if ($user != null) {
            $user = "******";
        }
        if (!isset($parse["scheme"])) {
            if ($PROTO == "SSL") {
                $GET_URL = "https://{$SOURCE_URL}";
            }
        } else {
            $GET_URL = $SOURCE_URL;
        }
        $parse = parse_url($URL);
        if ($scheme == null) {
            $scheme = $parse["scheme"];
        }
        $hostname = $parse["host"];
        if (preg_match("#(.+?):([0-9]+)#", $hostname, $re)) {
            $hostname = $re[1];
            $port = $re[2];
        }
        if ($IP->isValid($hostname)) {
            $parse["query"] = null;
            $parse["path"] = null;
            $TT = explode(".", $hostname);
            $net = $TT[0] . "." . $TT[1] . "." . $TT[2];
            $infos = "&nbsp;(<a href=\"http://www.tcpiputils.com/browse/ip-address/{$hostname}\" style='text-decoration:underline;color:black' target=_new>TCP Utils</a>&nbsp;|&nbsp<a href=\"https://db-ip.com/all/{$net}\" style='text-decoration:underline;color:black' target=_new>Subnet</a>)";
        }
        $path = $parse["path"];
        $query = $parse["query"];
        $familysite = $zcat->GetFamilySites($hostname);
        $familysite = str_replace("'", "`", $familysite);
        $familysiteEnc = urlencode($familysite);
        if ($familysite != $hostname) {
            $prefix = str_replace(".{$familysite}", "", $hostname);
            if ($prefix != "www") {
                $prefix = "<a href=\"javascript:blur();\"\n\t\t\t\tOnClick=\"javascript:Loadjs('squid.access.webfilter.tasks.php?familysite={$hostname}')\"\n\t\t\t\tstyle='text-decoration:underline;font-size:{$fontsize}px;color:{$color};font-weight:bold'>{$prefix}</a>";
            }
        }
        $familysite = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.access.webfilter.tasks.php?familysite={$familysiteEnc}')\"\n\t\tstyle='text-decoration:underline;font-size:{$fontsize}px;color:{$color}'>{$familysite}</a>";
        $URL = "{$scheme}://";
        if ($prefix != null) {
            $URL = $URL . "{$prefix}.";
        }
        $URL = $URL . "{$familysite}";
        if ($port != null) {
            $URL = $URL . ":{$port}";
        }
        if (!isset($_GET["categories-scan"])) {
            if ($path != null) {
                $URL = $URL . $path;
            }
            if ($query != null) {
                $URL = $URL . "?{$query}";
            }
        } else {
            $category = $catz->GET_CATEGORIES($hostname);
            if ($category == null) {
                $category = " ({$unknown})";
            } else {
                $category = " ({$category})";
            }
            $URL = $URL . $category;
        }
        $TR[6] = $URL;
        $link = "<a href=\"{$GET_URL}\" target=_new><img src='img/icon-link.png'></a>";
        if ($size > 1024) {
            $size = FormatBytes($size / 1024);
        } else {
            $size = "{$size} Bytes";
        }
        $date = str_replace($today . " ", "", $date);
        $data['rows'][] = array('id' => md5($line), 'cell' => array("<span style='font-size:{$fontsize}px;color:{$color}'>{$date}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$ip}{$user}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$zCode[0]} - {$codeToString}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$PROTO}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$TR[6]}{$infos}</span>", "<center style='font-size:{$fontsize}px;color:{$color}'>{$link}</center>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$size}</span>", "<span style='font-size:{$fontsize}px;color:{$color}'>{$duration}{$durationunit}</span>", "{$ip}"));
    }
    $data['total'] = $c;
    echo json_encode($data);
}
예제 #18
0
        }
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("{$GLOBALS["DOMAIN"]}: LOOP domain = {$GLOBALS["DOMAIN"]}");
    }
    $DCOUNT++;
    if (!$GLOBALS["XVFERTSZ"]) {
        $error = urlencode("License Error, please remove Artica categories objects in ACL");
        WLOG("{$GLOBALS["DOMAIN"]}: LOOP():: License Error ! [" . __LINE__ . "]");
        categories_logs("ERROR;License error");
        fwrite(STDOUT, "{$prefix_channel}BH message={$error}\n");
        continue;
    }
    try {
        $sitename = $fam->GetFamilySites($GLOBALS["DOMAIN"]);
        $category = $q->GET_CATEGORIES($sitename);
    } catch (Exception $e) {
        $error = $e->getMessage();
        WLOG("{$GLOBALS["DOMAIN"]}: {$DCOUNT}] LOOP::FATAL ERROR {$error}");
    }
    if ($category != null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("{$GLOBALS["DOMAIN"]}: LOOP domain = {$GLOBALS["DOMAIN"]} category={$category}");
        }
        fwrite(STDOUT, "{$prefix_channel}OK tag={$category}\n");
        continue;
    }
    fwrite(STDOUT, "{$prefix_channel}OK\n");
    continue;
}
WLOG("Stopping PID:{$GLOBALS["MYPID"]} After {$DCOUNT} event(s) SAVED {$GLOBALS["DATABASE_ITEMS"]} items in database");
예제 #19
0
function categories_match($gpid, $sitname, $MD5KEY)
{
    $sitname = trim($sitname);
    if (preg_match("#^www\\.(.+)#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) {
        $sitname = $re[1];
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("Analyze: Group: {$gpid} `{$sitname}`");
    }
    $categories_get_memory = categories_get_memory($gpid, $sitname, $MD5KEY);
    if ($categories_get_memory == 0) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` ");
        }
        categories_logs("{$gpid};MEMORY;UNKNOWN/NONE");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> UNKNOWN");
        }
        return false;
    }
    if ($categories_get_memory == 1) {
        categories_logs("{$gpid};MEMORY;TRUE/-");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> TRUE");
        }
        return true;
    }
    if ($categories_get_memory == 2) {
        categories_logs("{$gpid};MEMORY;FALSE/-");
        if ($GLOBALS["DEBUG"]) {
            WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> FALSE");
        }
        return false;
    }
    $q = new mysql_catz();
    $categoriF = $q->GET_CATEGORIES($sitname);
    $trans = $q->TransArray();
    if ($GLOBALS["DEBUG"]) {
        WLOG("Group: {$gpid} `{$sitname}` -> RESULTS: `{$categoriF}` ");
    }
    if ($categoriF == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> SET TO  `UNKNOWN` ");
        }
        categories_logs("{$gpid};QUERY;UNKNOWN/NONE");
        categories_set_memory($gpid, $sitname, 0, $MD5KEY);
        return false;
    }
    if (strpos($categoriF, ",") > 0) {
        $categoriT = explode(",", $categoriF);
    } else {
        $categoriT[] = $categoriF;
    }
    while (list($a, $b) = each($categoriT)) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("Group: {$gpid} `{$sitname}` -> category IS: [{$b}] [" . __LINE__ . "]");
        }
        $MAIN[$b] = true;
    }
    if (!isset($GLOBALS["CONFIG"][$gpid])) {
        $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl";
        $GLOBALS["CONFIG"][$gpid] = unserialize(@file_get_contents($filename));
    }
    $categories = $GLOBALS["CONFIG"][$gpid];
    while (list($category_table, $category_rule) = each($categories)) {
        $category_rule = urlencode($category_rule);
        $categoryname = $trans[$category_table];
        if ($categoryname == null) {
            $categoryname = $category_rule;
        }
        if (isset($MAIN[$categoryname])) {
            if ($GLOBALS["DEBUG"]) {
                WLOG("FOUND `{$categoryname}` -> `{$category_rule}` ");
            }
            categories_logs("{$gpid};QUERY;TRUE/{$categoryname}");
            categories_set_memory($gpid, $sitname, 1, $MD5KEY);
            return true;
        }
    }
    categories_logs("{$gpid};QUERY;FALSE/" . @implode(",", $categoriT));
    categories_set_memory($gpid, $sitname, 2, $MD5KEY);
    return false;
}