Beispiel #1
0
function search()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql();
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexregex();
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $CATZ_ARRAY = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/UFDB_ARTICA_CATZ"));
    $CATZ_ITEMS = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/UFDB_ARTICA_COUNTZ"));
    unset($CATZ_ARRAY["TIME"]);
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($CATZ_ARRAY);
    $data['rows'] = array();
    $catz = new mysql_catz();
    $TransArray = $catz->TransArray();
    $c = 0;
    while (list($tablename, $size) = each($CATZ_ARRAY)) {
        $items = intval($CATZ_ITEMS[$tablename]);
        $size = $size / 1024;
        $size = FormatBytes($size);
        if (isset($TransArray[$tablename])) {
            $tablename = $TransArray[$tablename];
        }
        if ($searchstring != null) {
            if (!preg_match("#{$searchstring}#", $tablename)) {
                continue;
            }
        }
        $c++;
        $items = FormatNumber($items);
        $data['rows'][] = array('id' => md5($tablename), 'cell' => array("<strong style='font-size:18px;color:{$color}'>{$tablename}</strong>", "<div style='font-size:18px;font-weight:normal;color:{$color}'>{$size}</div>", "<div style='font-size:18px;font-weight:normal;color:{$color}'>{$items}</div>"));
    }
    $data['total'] = $c;
    echo json_encode($data);
}
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__);
}
Beispiel #3
0
function status(){
	$tpl=new templates();
	$sock=new sockets();
	$RemoteUfdbCat=intval($sock->GET_INFO("RemoteUfdbCat"));
	$page=CurrentPageName();
	$EnableLocalUfdbCatService=intval($sock->GET_INFO("EnableLocalUfdbCatService"));
	$AsCategoriesAppliance=intval($sock->GET_INFO("AsCategoriesAppliance"));
	if($AsCategoriesAppliance==1){$RemoteUfdbCat=0;$EnableLocalUfdbCatService=1;}
	
	if($RemoteUfdbCat==1){
		$catz=new mysql_catz();
		$categories=$catz->ufdbcat("google.com");
		if($catz->ok){
			echo $tpl->_ENGINE_parse_body(Paragraphe32("{available}", "noacco:
		<span style='font-size:12px'><strong>google.com:</strong><br>{category} <strong>$categories</strong><br>{execution_time} {$catz->TimeExec}s</span>",null,
		"ok48.png","LoadAjax('UFDBCAT_STATUS','$page?status=yes')"));
		echo"<div style='text-align:right'>".imgtootltip("refresh-32.png","{refresh}","LoadAjax('UFDBCAT_STATUS','$page?status=yes');")."</div>";
		return;
		}
		
		
		echo $tpl->_ENGINE_parse_body(Paragraphe32("{connection_error}", "noacco:
		<span style='font-size:12px'>{error} &laquo;$catz->mysql_error&raquo;</span>",null,
		"error-48.png"));
		echo"<div style='text-align:right'>".imgtootltip("refresh-32.png","{refresh}","LoadAjax('UFDBCAT_STATUS','$page?status=yes');")."</div>";
		return;
		
	}
	
	
	
	$data=$sock->getFrameWork('cmd.php?ufdbcat-ini-status=yes');
	$ini=new Bs_IniHandler();
	$ini->loadString(base64_decode($data));
	$APP_UFDBCAT=DAEMON_STATUS_ROUND("APP_UFDBCAT",$ini,null,1);
	echo $tpl->_ENGINE_parse_body($APP_UFDBCAT);
	
	$ufdbCatInterface=$sock->GET_INFO("ufdbCatInterface");
	$ufdbCatPort=intval($sock->GET_INFO("ufdbCatPort"));
	$UfdbCatThreads=intval($sock->GET_INFO("UfdbCatThreads"));
	if($ufdbCatInterface==null){$ufdbCatInterface="127.0.0.1";}
	if($ufdbCatInterface=="all"){$ufdbCatInterface="127.0.0.1";}
	
	
	
	if($EnableLocalUfdbCatService==0){
		$html="<div style='text-align:right'>".imgtootltip("refresh-32.png","{refresh}","LoadAjax('UFDBCAT_STATUS','$page?status=yes');")."</div>";
		echo $tpl->_ENGINE_parse_body($html);
		return;
	}
	
	
	
	$catz=new mysql_catz();
	$categories=$catz->ufdbcat("google.com");
	if($catz->ok){
		echo $tpl->_ENGINE_parse_body(Paragraphe32("{available}", "noacco:
				<span style='font-size:12px'><strong>google.com:</strong><br>{category} <strong>$categories</strong><br>{execution_time} {$catz->TimeExec}s</span>",null,
				"ok48.png","LoadAjax('UFDBCAT_STATUS','$page?status=yes')"));
		echo $tpl->_ENGINE_parse_body("<div style='text-align:right'>".imgtootltip("refresh-32.png","{refresh}","LoadAjax('UFDBCAT_STATUS','$page?status=yes');")."</div>");
		return;
	}
	
	
	echo $tpl->_ENGINE_parse_body(Paragraphe32("{connection_error}", "noacco:
			<span style='font-size:12px'>{error} &laquo;$catz->mysql_error&raquo;</span>",null,
			"error-48.png"));
	echo $tpl->_ENGINE_parse_body("<div style='text-align:right'>".imgtootltip("refresh-32.png","{refresh}","LoadAjax('UFDBCAT_STATUS','$page?status=yes');")."</div>");
	
	
	
	
	
}
Beispiel #4
0
function category_list()
{
    //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();
    $q = new mysql_squid_builder();
    $users = new usersMenus();
    $text_license = null;
    if (!$users->CORP_LICENSE) {
        $text_license = $tpl->_ENGINE_parse_body("({category_no_license_explain})");
    }
    $search = '%';
    $table = "webfilters_categories_caches";
    $tableProd = "cicap_profiles_blks";
    $page = 1;
    $ORDER = "ORDER BY categorykey ASC";
    $FORCE_FILTER = null;
    if (trim($_GET["group"]) != null) {
        $FORCE_FILTER = " AND master_category='{$_GET["group"]}'";
    }
    if (isset($_GET["CatzByEnabled"])) {
        $OnlyEnabled = true;
    }
    $count_webfilters_categories_caches = $q->COUNT_ROWS("webfilters_categories_caches");
    writelogs("webfilters_categories_caches {$count_webfilters_categories_caches} rows", __FUNCTION__, __FILE__, __LINE__);
    if ($count_webfilters_categories_caches == 0) {
        $ss = new dansguardian_rules();
        $ss->CategoriesTableCache();
    }
    if (!$q->TABLE_EXISTS($tableProd)) {
        $q->CheckTables();
    }
    $sql = "SELECT `category` FROM {$tableProd} WHERE `mainid`={$_GET["mainid"]} AND bltype={$_GET["bltype"]}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}", 1);
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $cats[$ligne["category"]] = true;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `webfilters_categories_caches` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($q->mysql_error, "", "", ""));
            json_encode($data);
            return;
        }
        $total = $ligne["TCOUNT"];
        writelogs("{$sql} = {$total} rows", __FUNCTION__, __FILE__, __LINE__);
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `webfilters_categories_caches` WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($q->mysql_error, "", "", ""));
            json_encode($data);
            return;
        }
        $total = $ligne["TCOUNT"];
    }
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    $sql = "SELECT *  FROM `webfilters_categories_caches` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($q->mysql_error, "", "", ""));
        json_encode($data);
        return;
    }
    $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, "", "", ""));
    }
    $items = $tpl->_ENGINE_parse_body("{items}");
    $compile = $tpl->_ENGINE_parse_body("{compile}");
    $catz = new mysql_catz();
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($ligne["picture"] == null) {
            $ligne["picture"] = "20-categories-personnal.png";
        }
        $category_table = "category_" . $q->category_transform_name($ligne['categorykey']);
        $category_table_elements = $q->COUNT_ROWS($category_table);
        $DBTXT = array();
        $database_items = null;
        if ($category_table_elements > 0) {
            $category_table_elements = FormatNumber($category_table_elements);
            $DBTXT[] = "<a href=\"javascript:blurt();\" OnClick=\"javascript:Loadjs('squid.categories.php?category=" . urlencode($ligne['categorykey']) . "',true)\"\n\t\t\tstyle='font-size:11px;font-weight:bold;text-decoration:underline'>{$category_table_elements}</a> {$items}";
            $DBTXT[] = "<a href=\"javascript:blurt();\" OnClick=\"javascript:Loadjs('ufdbguard.compile.category.php?category=" . urlencode($ligne['categorykey']) . "',true)\"\n\t\t\tstyle='font-size:11px;font-weight:bold;text-decoration:underline'>{$compile}</a>";
        }
        $ligneTLS = mysql_fetch_array($q->QUERY_SQL("SELECT websitesnum FROM univtlse1fr WHERE category='{$ligne['categorykey']}'"));
        $category_table_elements_tlse = $ligneTLS["websitesnum"];
        if ($category_table_elements_tlse > 0) {
            $category_table_elements_tlse = FormatNumber($category_table_elements_tlse);
            $DBTXT[] = "{$category_table_elements_tlse} Toulouse University {$items}";
        }
        $catz = new mysql_catz();
        $category_table_elements_artica = $catz->COUNT_ROWS($category_table);
        if ($category_table_elements_artica > 0) {
            $category_table_elements_artica = FormatNumber($category_table_elements_artica);
            $DBTXT[] = "{$category_table_elements_artica} Artica {$items} <i style='font-size:10px;font-weight:normal'>{$text_license}</i>";
        }
        if (count($DBTXT) > 0) {
            $database_items = "<span style='font-size:11px;font-weight:bold'>" . @implode("&nbsp;|&nbsp;", $DBTXT) . "</span>";
        }
        $img = "img/{$ligne["picture"]}";
        $val = 0;
        if ($cats[$ligne['categorykey']]) {
            $val = 1;
        }
        if ($OnlyEnabled) {
            if ($val == 0) {
                continue;
            }
        }
        $disable = Field_checkbox("cats_{$_GET['RULEID']}_{$_GET['bltype']}_{$ligne['categorykey']}", 1, $val, "Loadjs('{$MyPage}?category-enable-js={$ligne['categorykey']}&mainid={$_GET["mainid"]}&bltype={$_GET["bltype"]}')");
        $ligne['description'] = utf8_encode($ligne['description']);
        $data['rows'][] = array('id' => $ligne['categorykey'], 'cell' => array("<img src='{$img}'>", "{$js}{$ligne['categorykey']}</a>", $ligne['description'] . "<br>\n\t\t\t\t{$database_items}", $disable));
    }
    echo json_encode($data);
}
 function CreateCategoryTable($category, $fulltablename = null)
 {
     $catz = new mysql_catz();
     $catz->CreateCategoryTable($category, $fulltablename);
     if ($category == "drogue") {
         $category = "drugs";
     }
     if ($category == "gambling") {
         $category = "gamble";
     }
     if ($category == "hobby/games") {
         $category = "games";
     }
     if ($category == "forum") {
         $category = "forums";
     }
     if ($category == "spywmare") {
         $category = "spyware";
     }
     if ($category == "association") {
         $category = "associations";
     }
     if ($this->EnableRemoteStatisticsAppliance == 1) {
         return;
     }
     $category = $this->category_transform_name($category);
     $tablename = strtolower("category_{$category}");
     if ($fulltablename != null) {
         $tablename = $fulltablename;
     }
     if ($tablename == "category_teans") {
         $tablename = "category_teens";
     }
     $tablename = strtolower($tablename);
     $tablename = str_replace("category_category_", "category_", $tablename);
     if ($tablename == "category_drogue") {
         $tablename = "category_drugs";
     }
     if ($tablename == "category_gambling") {
         $tablename = "category_gamble";
     }
     if ($tablename == "category_hobby_games") {
         $tablename = "category_games";
     }
     if ($tablename == "category_forum") {
         $tablename = "category_forums";
     }
     if ($tablename == "category_spywmare") {
         $tablename = "category_spyware";
     }
     if ($tablename == "category_association") {
         $tablename = "category_associations";
     }
     $tablename = strtolower($tablename);
     if ($GLOBALS["VERBOSE"]) {
         echo "CREATE CATEGORY TABLE `{$tablename}`\n";
     }
     $sql = "CREATE TABLE IF NOT EXISTS `{$this->database}`.`{$tablename}` (\n\t\t\t\t`zmd5` VARCHAR( 90 ) NOT NULL ,\n\t\t\t\t`zDate` DATETIME NOT NULL ,\n\t\t\t\t`category` VARCHAR( 20 ) NOT NULL ,\n\t\t\t\t`familysite` VARCHAR( 128 ) NULL ,\n\t\t\t\t`pattern` VARCHAR( 255 ) NOT NULL ,\n\t\t\t\t`enabled` INT( 1 ) NOT NULL DEFAULT '1',\n\t\t\t\t`uuid` VARCHAR( 255 ) NOT NULL ,\n\t\t\t\t`sended` INT( 1 ) NOT NULL DEFAULT '0',\n\t\t\t\tPRIMARY KEY ( `zmd5` ) ,\n\t\t\t\tUNIQUE KEY `pattern` (`pattern`),\n\t\t\t\tKEY `familysite` (`familysite`),\n\t\t\t\tKEY `zDate` (`zDate`),\n\t  \t\t\tKEY `enabled` (`enabled`),\n\t  \t\t\tKEY `sended` (`sended`),\n\t  \t\t\tKEY `category` (`category`)\n\t\t\t) ENGINE=MYISAM;";
     $this->QUERY_SQL($sql, $this->database);
     if (!$this->ok) {
         writelogs("Failed to create category_{$category}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
         return;
     }
     $this->QUERY_SQL("DROP TABLE webfilters_categories_caches");
     $this->create_webfilters_categories_caches();
 }
Beispiel #6
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);
}
function categories_search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $dans = new dansguardian_rules();
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $t = $_GET["t"];
    $OnlyPersonal = 0;
    $artica = $forceArtica;
    if (isset($_GET["OnlyPersonal"])) {
        $OnlyPersonal = 1;
    }
    $rp = 200;
    if (isset($_GET["artica"])) {
        $artica = true;
    }
    if ($_POST["sortname"] == "table_name") {
        $_POST["sortname"] = "categorykey";
    }
    if (!$q->BD_CONNECT()) {
        json_error_show("Testing connection to MySQL server failed...", 1);
    }
    $sql = "SELECT * FROM personal_categories";
    $table = "personal_categories";
    if ($_POST["sortname"] == "categorykey") {
        $_POST["sortname"] = "category";
    }
    $prefix = "INSERT IGNORE INTO webfilters_categories_caches (`categorykey`,`description`,`picture`,`master_category`,`categoryname`) VALUES ";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    writelogs("{$q->mysql_admin}:{$q->mysql_password}:{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("Not found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $enc = new mysql_catz();
    $field = "category";
    $field_description = "category_description";
    $CATZ_ARRAY = unserialize(@file_get_contents("/home/artica/categories_databases/CATZ_ARRAY"));
    $TransArray = $enc->TransArray();
    while (list($tablename, $items) = each($CATZ_ARRAY)) {
        if (!isset($TransArray[$tablename])) {
            continue;
        }
        $CATZ_ARRAY2[$TransArray[$tablename]] = $items;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $categorykey = $ligne["category"];
        if ($categorykey == null) {
            $categorykey = "UnkNown";
        }
        //Array ( [category] => [category_description] => Ma catégorie [master_category] => [sended] => 1 )
        if ($GLOBALS["VERBOSE"]) {
            echo "Found  {$field}:{$categorykey}<br>\n";
        }
        $categoryname = $categorykey;
        $text_category = null;
        $table = $q->cat_totablename($categorykey);
        if ($GLOBALS["VERBOSE"]) {
            echo "Scanning table {$table}<br>\n";
        }
        $itemsEncTxt = null;
        $items = $q->COUNT_ROWS($table);
        if (!preg_match("#^category_(.+)#", $table, $re)) {
            continue;
        }
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk}", "DansGuardianCompileDB('{$categoryname}')");
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $sizedb_org = $q->TABLE_SIZE($table);
        $sizedb = FormatBytes($sizedb_org / 1024);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categories.php?category={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:18px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $text_category = $tpl->_ENGINE_parse_body(utf8_decode($ligne[$field_description]));
        $text_category = trim($text_category);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:18px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $viewDB = imgsimple("mysql-browse-database-32.png", null, "javascript:Loadjs('squid.categories.php?category={$categoryname}',true)");
        $text_category = utf8_encode($text_category);
        $categoryname_text = utf8_encode($categoryname);
        $categoryText = $tpl->_ENGINE_parse_body("<span style='font-size:18px';font-weight:bold'>{$linkcat}{$categoryname_text}</span>\n\t\t\t\t\t</a><br><span style='font-size:16px;width:100%;font-weight:normal'><i>{$text_category}</i></span>");
        $itemsEncTxt = "<span style='font-size:18px;font-weight:bold'>" . numberFormat($items, 0, "", " ");
        "</span>";
        $compile = imgsimple("compile-distri-48.png", null, "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("dustbin-48.png", null, "TableCategoryPurge('{$table}')");
        if ($categoryname == "UnkNown") {
            $linkcat = null;
            $delete = imgsimple("delete-48.png", null, "TableCategoryPurge('')");
        }
        $cell = array();
        $cell[] = $categoryText;
        $cell[] = "<span style='font-size:18px;padding-top:15px;font-weight:bold'>{$sizedb}</div>";
        $cell[] = $itemsEncTxt;
        $cell[] = $compile;
        $cell[] = $delete;
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}
Beispiel #8
0
function testssocks()
{
    $GLOBALS["VERBOSE"] = true;
    include_once dirname(__FILE__) . '/ressources/class.mysql.catz.inc';
    $catz = new mysql_catz();
    echo "google.fr -> " . $catz->GetMemoryCache("google.fr", true) . "\n";
    echo "google.com -> " . $catz->GetMemoryCache("google.com", true) . "\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);
}
function categories_search($forceArtica = false)
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $dans = new dansguardian_rules();
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $t = $_GET["t"];
    $OnlyPersonal = 0;
    $artica = $forceArtica;
    if (isset($_GET["OnlyPersonal"])) {
        $OnlyPersonal = 1;
    }
    $rp = 200;
    if (isset($_GET["artica"])) {
        $artica = true;
    }
    if ($_POST["sortname"] == "table_name") {
        $_POST["sortname"] = "categorykey";
    }
    if (!$q->BD_CONNECT()) {
        json_error_show("Testing connection to MySQL server failed...", 1);
    }
    $table = "webfilters_categories_caches";
    $sql = "SELECT * FROM personal_categories";
    if ($OnlyPersonal == 0) {
        if (!$q->TABLE_EXISTS($table)) {
            $q->create_webfilters_categories_caches();
        }
        $dans = new dansguardian_rules();
        if ($q->COUNT_ROWS($table) == 0) {
            $dans->CategoriesTableCache();
        }
        $dans->LoadBlackListes();
    } else {
        $table = "personal_categories";
        if ($_POST["sortname"] == "categorykey") {
            $_POST["sortname"] = "category";
        }
    }
    $prefix = "INSERT IGNORE INTO webfilters_categories_caches (`categorykey`,`description`,`picture`,`master_category`,`categoryname`) VALUES ";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    writelogs("{$q->mysql_admin}:{$q->mysql_password}:{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("Not found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $AS_SELECT = false;
    if ($_GET["select"] == "yes") {
        $AS_SELECT = true;
    }
    $enc = new mysql_catz();
    $field = "categorykey";
    $field_description = "description";
    if ($OnlyPersonal == 1) {
        $field = "category";
        $field_description = "category_description";
    }
    $ProductName = "Artica";
    $ProductNamef = dirname(__FILE__) . "/ressources/templates/{$_COOKIE["artica-template"]}/ProducName.conf";
    if (is_file($ProductNamef)) {
        $ProductName = trim(@file_get_contents($ProductNamef));
    }
    $CATZ_ARRAY = unserialize(base64_decode(@file_get_contents(CATZ_ARRAY_FILE())));
    $FULL_ARRAY = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS_FULL.db"));
    $TLSE_ARRAY = $FULL_ARRAY["TLSE_ARRAY"];
    $ARTICA_ARRAY = $FULL_ARRAY["CAT_ARTICAT_ARRAY"];
    //print_r($ARTICA_ARRAY);
    $TransArray = $enc->TransArray();
    while (list($tablename, $items) = each($CATZ_ARRAY)) {
        if (!isset($TransArray[$tablename])) {
            continue;
        }
        $CATZ_ARRAY2[$TransArray[$tablename]] = $items;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $sizedb = array();
        $ZZCOUNT = 0;
        $categorykey = $ligne[$field];
        if ($categorykey == null) {
            $categorykey = "UnkNown";
        }
        //Array ( [category] => [category_description] => Ma catégorie [master_category] => [sended] => 1 )
        if ($GLOBALS["VERBOSE"]) {
            echo "Found  {$field}:{$categorykey}<br>\n";
        }
        $categoryname = $categorykey;
        $ITEMS_COLONE = array();
        $Time = array();
        $text_category = null;
        $table = $q->cat_totablename($categorykey);
        if ($GLOBALS["VERBOSE"]) {
            echo "Scanning table {$table}<br>\n";
        }
        $UnivToulouseItems = null;
        $ligne_databases = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM UPDATE_DBWF_INFOS WHERE category='{$categoryname}'"));
        $size_artica = $ligne_databases["size_artica"];
        $date_artica = $ligne_databases["date_artica"];
        $count_artica = $ligne_databases["count_artica"];
        $size_tlse = $ligne_databases["size_tlse"];
        $date_tlse = $ligne_databases["date_tlse"];
        $count_tlse = $ligne_databases["count_tlse"];
        $size_perso = $ligne_databases["size_perso"];
        $date_perso = $ligne_databases["date_perso"];
        $count_perso = $ligne_databases["count_perso"];
        $items = $count_perso;
        $itemsEnc = $count_artica;
        $ZZCOUNT = $ZZCOUNT + $items;
        $ZZCOUNT = $ZZCOUNT + $itemsEnc;
        if ($date_perso > 0) {
            $Time[] = date("m-d H:i", $date_perso);
        } else {
            $Time[] = "-";
        }
        $sizeArtica = $size_artica;
        if ($date_artica > 0) {
            $Time[] = date("m-d H:i", $date_artica);
        } else {
            $Time[] = "-";
        }
        $ITEMS_COLONE[] = "Perso.:&nbsp;" . numberFormat($items, 0, "", " ");
        $ITEMS_COLONE[] = "{$ProductName}:&nbsp;" . numberFormat($itemsEnc, 0, "", " ");
        if (!preg_match("#^category_(.+)#", $table, $re)) {
            continue;
        }
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk}", "DansGuardianCompileDB('{$categoryname}')");
        if (!isset($dans->array_blacksites[$categoryname])) {
            if (isset($dans->array_blacksites[str_replace("_", "-", $categoryname)])) {
                $categoryname = str_replace("_", "-", $categoryname);
            }
            if (isset($dans->array_blacksites[str_replace("_", "/", $categoryname)])) {
                $categoryname = str_replace("_", "/", $categoryname);
            }
        }
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $sizedb[] = FormatBytes($size_perso / 1024);
        $sizedb[] = FormatBytes($size_artica / 1024);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categories.php?category={$categoryname}&t={$t}',true)\"\n\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $text_category = $tpl->_ENGINE_parse_body(utf8_decode($ligne[$field_description]));
        $text_category = trim($text_category);
        $pic = "<img src='img/20-categories-personnal.png'>";
        if ($ligne["picture"] != null) {
            $pic = "<img src='img/{$ligne["picture"]}'>";
        }
        if ($OnlyPersonal == 0) {
            if (!isset($dans->array_blacksites[$categoryname])) {
                $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
            }
        } else {
            $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        }
        $viewDB = imgsimple("mysql-browse-database-32.png", "{view}", "javascript:Loadjs('squid.categories.php?category={$categoryname}',true)");
        $text_category = utf8_encode($text_category);
        $categoryname_text = utf8_encode($categoryname);
        $categoryText = $tpl->_ENGINE_parse_body("<span style='font-size:14px';font-weight:bold'>{$linkcat}{$categoryname_text}</span>\n\t\t</a><br><span style='font-size:11px;width:100%;font-weight:normal'>{$text_category}</span>");
        if ($OnlyPersonal == 1) {
            $itemsEncTxt = "<br><span style='font-size:11px'>" . numberFormat($itemsEnc, 0, "", " ");
            "</span>";
        }
        $compile = imgsimple("compile-distri-32.png", null, "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("delete-32.png", "{delete}", "TableCategoryPurge('{$table}')");
        if ($_GET["minisize"] == "yes") {
            $delete = null;
        }
        if ($OnlyPersonal == 0) {
            $UnivToulouse_websitesnum = $count_tlse;
            $ZZCOUNT = $ZZCOUNT + $UnivToulouse_websitesnum;
            $UnivToulouse_size = $size_tlse;
            $sizedb[] = FormatBytes($UnivToulouse_size / 1024);
            $ITEMS_COLONE[] = "University:&nbsp;" . numberFormat($UnivToulouse_websitesnum, 0, "", " ");
            if ($date_tlse > 0) {
                $Time[] = date("m-d H:i", $date_tlse);
            } else {
                $Time[] = "-";
            }
        }
        if ($categoryname == "UnkNown") {
            $linkcat = null;
            $delete = imgsimple("delete-32.png", "{delete}", "TableCategoryPurge('')");
        }
        if ($EnableWebProxyStatsAppliance == 0) {
            if ($ZZCOUNT == 0) {
                $pic = "<img src='img/warning-panneau-32.png'>";
            }
        }
        $cell = array();
        $cell[] = $pic;
        $cell[] = $categoryText;
        $cell[] = "<span style='font-size:11px;padding-top:15px;font-weight:bold'>" . @implode("<br>", $sizedb) . "</span>";
        $cell[] = "<span style='font-size:11px;padding-top:5px;font-weight:bold'>" . @implode("<br>", $ITEMS_COLONE) . "</span>";
        if (!$AS_SELECT) {
            $cell[] = "<span style='font-size:11px;padding-top:5px;font-weight:bold'>" . @implode("<br>", $Time) . "</span>";
            $cell[] = $compile;
            $cell[] = $delete;
        } else {
            $select = imgsimple("arrow-right-32.png", null, "{$_GET["callback"]}('{$categorykey}')");
            $cell[] = $select;
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}
Beispiel #11
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);
}
Beispiel #12
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>";
}
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;
    }
}
Beispiel #14
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;
}
Beispiel #15
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);
}
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;
}
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");
}
function parse_realtime_hash()
{
    @mkdir("/var/log/squid/mysql-rtcaches", 0755, true);
    @mkdir("/var/log/squid/mysql-rttime", 0755, true);
    $GLOBALS["TablePrimaireHour"] = array();
    $GLOBALS["TABLES_PRIMAIRES_SEARCHWORDS"] = array();
    $GLOBALS["MacResolvFrfomIP"] = null;
    $GLOBALS["MacResolvInterface"] = null;
    $WORKDIR = "/var/log/squid/mysql-rthash";
    $GLOBALS["MacResolvInterface"] = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/MacResolvInterface"));
    $GLOBALS["EnableMacAddressFilter"] = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableMacAddressFilter"));
    if (!is_numeric($GLOBALS["EnableMacAddressFilter"])) {
        $GLOBALS["EnableMacAddressFilter"] = 1;
    }
    $EnableRemoteSyslogStatsAppliance = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableRemoteSyslogStatsAppliance"));
    $DisableArticaProxyStatistics = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableArticaProxyStatistics"));
    $EnableRemoteStatisticsAppliance = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableRemoteStatisticsAppliance"));
    $SquidActHasReverse = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidActHasReverse"));
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_numeric($EnableRemoteSyslogStatsAppliance)) {
        $EnableRemoteSyslogStatsAppliance = 0;
    }
    if (!is_numeric($SquidActHasReverse)) {
        $SquidActHasReverse = 0;
    }
    @mkdir($WORKDIR, 0755, true);
    chown($WORKDIR, "squid");
    chgrp($WORKDIR, "squid");
    if (!($handle = opendir("/var/log/squid/mysql-rthash"))) {
        return;
    }
    $GLOBALS["LOG_HOSTNAME"] = false;
    $EnableProxyLogHostnames = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableProxyLogHostnames")));
    if ($EnableProxyLogHostnames == 1) {
        $GLOBALS["LOG_HOSTNAME"] = true;
    }
    $GLOBALS["IPCACHE"] = unserialize(@file_get_contents("/etc/squid3/IPCACHE.db"));
    $GLOBALS["SitenameResolved"] = unserialize(@file_get_contents("/etc/squid3/SitenameResolved.db"));
    $GLOBALS["GetFamilySites"] = unserialize(@file_get_contents("/etc/squid3/GetFamilySites.db"));
    $GLOBALS["USERSDB"] = unserialize(@file_get_contents("/etc/squid3/usersMacs.db"));
    $GLOBALS["KEYUSERS"] = unserialize(@file_get_contents("/etc/squid3/KEYUSERS.db"));
    $GLOBALS["CACHEARP"] = unserialize(@file_get_contents("/etc/squid3/CACHEARP.db"));
    if ($GLOBALS["MacResolvInterface"] != null) {
        $GLOBALS["MacResolvFrfomIP"] = ethToIp();
    }
    $GLOBALS["UserAgents"] = array();
    $q = new mysql_squid_builder();
    $logfileD = new logfile_daemon();
    $IpClass = new IP();
    $CountDeFiles = 0;
    $AA = 0;
    $countDeFiles = 0;
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $filepath = "{$WORKDIR}/{$filename}";
        events("parse_realtime_hash():: Scanning {$WORKDIR}/{$filename}");
        $content = unserialize(@file_get_contents($filepath));
        $CountDeFiles++;
        @unlink($filepath);
        while (list($SUFFIX_TABLE, $Arrayz) = each($content)) {
            while (list($index, $rows) = each($Arrayz)) {
                $AA++;
                $cached = 0;
                $hostname = null;
                $SUFFIX_DATE = $SUFFIX_TABLE;
                $key = null;
                $xtime = $rows["TIME"];
                $sitename = $rows["SITENAME"];
                $mac = $rows["MAC"];
                $uid = $rows["UID"];
                $ipaddr = $rows["IPADDR"];
                if (isset($rows["HOSTNAME"])) {
                    $hostname = $rows["HOSTNAME"];
                }
                $SquidCode = $rows["SQUID_CODE"];
                $SIZE = $rows["SIZE"];
                $uri = $rows["URI"];
                $zMD5 = md5(serialize($rows));
                $UserAgent = $rows["USERAGENT"];
                $code_error = $rows["HTTP_CODE"];
                if ($IpClass->isValid($uid)) {
                    $uid = null;
                }
                $RESPONSE_TIME = $rows["RESPONSE_TIME"];
                if ($GLOBALS["VERBOSE"]) {
                    echo "Scanning {$SUFFIX_DATE} {$xtime} {$ipaddr} {$sitename}\n";
                }
                if (isset($GLOBALS["ZMD5"][$zMD5])) {
                    events("{$uri} - md5 = {$zMD5} is the same !!!");
                }
                $GLOBALS["ZMD5"][$zMD5] = true;
                if ($mac == null) {
                    if ($GLOBALS["EnableMacAddressFilter"] == 1) {
                        $mac = IpToMac($ipaddr);
                    }
                }
                if ($uid == null) {
                    if ($mac != null) {
                        if (isset($GLOBALS["USERSDB"]["MACS"][$mac])) {
                            $uid = $GLOBALS["USERSDB"]["MACS"][$mac]["UID"];
                        }
                    }
                }
                if (strpos("   {$sitename}", "www.") > 0) {
                    if (preg_match("#^www\\.(.+)#", $sitename, $re)) {
                        $sitename = $re[1];
                    }
                }
                if ($IpClass->isValid($sitename)) {
                    if (!isset($GLOBALS["SitenameResolved"][$sitename])) {
                        $GLOBALS["SitenameResolved"][$sitename] = gethostbyaddr2($sitename);
                    }
                    if ($GLOBALS["SitenameResolved"][$sitename] != null) {
                        $sitename = $GLOBALS["SitenameResolved"][$sitename];
                    }
                }
                if (!isset($GLOBALS["GetFamilySites"][$sitename])) {
                    $GLOBALS["GetFamilySites"][$sitename] = x_GetFamilySites($sitename);
                    if ($GLOBALS["GetFamilySites"][$sitename] == null) {
                        $GLOBALS["GetFamilySites"][$sitename] = $sitename;
                    }
                }
                $familysite = $GLOBALS["GetFamilySites"][$sitename];
                if ($familysite == "localhost") {
                    continue;
                }
                if ($uid != null) {
                    $key = "uid";
                }
                if ($key == null) {
                    if ($mac != null) {
                        $key = "MAC";
                    }
                }
                if ($key == null) {
                    if ($ipaddr != null) {
                        $key = "ipaddr";
                    }
                }
                if ($key == null) {
                    continue;
                }
                $hour = date("H", $xtime);
                $date = date("Y-m-d H:i:s", $xtime);
                if ($GLOBALS["VERBOSE"]) {
                    echo "Date: {$date}: {$familysite} {$uid}/{$ipaddr}\n";
                }
                $uri = trim($uri);
                if ($uri == null) {
                    continue;
                }
                if ($uid == null) {
                    $uid = x_MacToUid($mac);
                }
                if ($uid == null) {
                    $uid = x_IpToUid($ipaddr);
                }
                if ($hostname == null) {
                    $hostname = x_MacToHost($mac);
                }
                if ($hostname == null) {
                    $hostname = x_IpToHost($ipaddr);
                }
                if (trim($hostname) == null) {
                    if ($GLOBALS["LOG_HOSTNAME"]) {
                        $hostname = gethostbyaddr2($ipaddr);
                    }
                }
                if (preg_match("#(.+?):(.+)#", $SquidCode, $re)) {
                    $SquidCode = $re[1];
                }
                if ($logfileD->CACHEDORNOT($SquidCode)) {
                    $cached = 1;
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "[" . __LINE__ . "]: Uri <{$uri}> Squid code={$SquidCode} cached={$cached}  Client = {$uid}/{$mac}/{$hostname} [{$ipaddr}] , Size={$SIZE} bytes\n";
                }
                //events("$familysite - Squid code=$SquidCode cached=$cached  Client = $uid/$mac/$hostname [$ipaddr] , Size=$SIZE bytes");
                $KeyUser = md5($uid . $hostname . $ipaddr . $mac . $UserAgent);
                $UserAgent = x_mysql_escape_string2($UserAgent);
                if (!isset($GLOBALS["KEYUSERS"][$KeyUser])) {
                    $GLOBALS["UserAutDB"][] = "('{$KeyUser}','{$mac}','{$ipaddr}','{$uid}','{$hostname}','{$UserAgent}')";
                    //$sql="INSERT IGNORE INTO UserAutDB (zmd5,MAC,ipaddr,uid,hostname,UserAgent) VALUES ('$KeyUser','$mac','$ipaddr','$uid','$hostname','$UserAgent')";
                }
                if ($UserAgent != null) {
                    $GLOBALS["UserAgents"][] = "('{$UserAgent}')";
                }
                $catz = new mysql_catz();
                $category = x_mysql_escape_string2($catz->GetMemoryCache($sitename, true));
                events("RTTHASH:: {$sitename} Category = `{$category}`");
                $TablePrimaireHour = "squidhour_" . $SUFFIX_DATE;
                $TableSizeHours = "sizehour_" . $SUFFIX_DATE;
                $TableCacheHours = "cachehour_" . $SUFFIX_DATE;
                $tableYoutube = "youtubehours_" . $SUFFIX_DATE;
                $tableSearchWords = "searchwords_" . $SUFFIX_DATE;
                $sitename = x_mysql_escape_string2($sitename);
                $uri = substr($uri, 0, 254);
                $uri = x_mysql_escape_string2($uri);
                $uriT = x_mysql_escape_string2($uri);
                $hostname = x_mysql_escape_string2($hostname);
                $TYPE = $logfileD->codeToString($code_error);
                $REASON = $TYPE;
                if ($mac != null) {
                    $GLOBALS["macscan"][] = "('{$mac}','{$ipaddr}')";
                }
                $GLOBALS["TablePrimaireHour"][$TablePrimaireHour][] = "('{$sitename}','{$uriT}','{$TYPE}','{$REASON}','{$ipaddr}','{$hostname}','{$date}','{$zMD5}','{$uid}','{$SIZE}','{$cached}','{$mac}','{$category}')";
                //$sql="INSERT IGNORE INTO `$TableSizeHours` (`zDate`,`size`,`cached`) VALUES('$date','$SIZE','$cached')";
                $GLOBALS["TABLES_PRIMAIRES_SIZEHOUR"][$TableSizeHours][] = "('{$date}','{$SIZE}','{$cached}')";
                if ($SIZE > 0) {
                    $GLOBALS["TABLES_PRIMAIRES_CACHEHOUR"][$TableCacheHours][] = "('{$date}','{$SIZE}','{$cached}','{$familysite}')";
                }
                if (strpos(" {$uri}", "youtube") > 0) {
                    $VIDEOID = $logfileD->GetYoutubeID($uri);
                    if ($VIDEOID != null) {
                        events("YOUTUBE:: {$date}: {$ipaddr} {$uid} {$mac} [{$VIDEOID}]");
                        $sql = "INSERT IGNORE INTO `{$tableYoutube}`\n\t\t\t\t\t(`zDate`,`ipaddr`,`hostname`,`uid`,`MAC` ,`account`,`youtubeid`)\n\t\t\t\t\tVALUES ('{$date}','{$ipaddr}','','{$uid}','{$mac}','0','{$VIDEOID}')";
                        $rand = rand(100, 65000);
                        @file_put_contents("/var/log/squid/mysql-queue/YoutubeRTT." . time() . ".{$rand}.sql", $sql);
                    }
                }
                $SearchWords = $logfileD->SearchWords($uri);
                if (is_array($SearchWords)) {
                    $words = x_mysql_escape_string2($SearchWords["WORDS"]);
                    $GLOBALS["TABLES_PRIMAIRES_SEARCHWORDS"][$tableSearchWords][] = "('{$zMD5}','{$sitename}','{$date}','{$ipaddr}','{$hostname}','{$uid}','{$mac}','0','{$familysite}','{$words}')";
                }
                //
                $timekey = date('YmdH', $xtime);
                $stime = date("Y-m-d H:i:s", $xtime);
                $table = "quotatemp_{$timekey}";
                $keyr2 = md5("{$stime}{$date}{$uid}{$ipaddr}{$mac}{$sitename}");
                $GLOBALS["TABLES_PRIMAIRES_QUOTATEMP"][$table][] = "('{$stime}','{$keyr2}','{$ipaddr}','{$familysite}','{$familysite}','{$uid}','{$mac}','{$SIZE}')";
            }
        }
    }
    events("{$WORKDIR} -> {$AA} elements scanned");
    if (count($GLOBALS["UserAgents"]) > 0) {
        $q = new mysql_squid_builder();
        $q->QUERY_SQL("INSERT IGNORE INTO `UserAgents` (`pattern`) VALUES " . @implode(",", $GLOBALS["UserAgents"]));
        $GLOBALS["UserAgents"] = array();
    }
    if ($CountDeFiles > 0) {
        $GLOBALS["PARSE_SECOND_TIME"] = true;
        events(__FUNCTION__ . "():: {$CountDeFiles} parsed files");
        @file_put_contents("/etc/squid3/IPCACHE.db", serialize($GLOBALS["IPCACHE"]));
        @file_put_contents("/etc/squid3/SitenameResolved.db", serialize($GLOBALS["SitenameResolved"]));
        @file_put_contents("/etc/squid3/GetFamilySites.db", serialize($GLOBALS["GetFamilySites"]));
        @file_put_contents("/etc/squid3/KEYUSERS.db", unserialize($GLOBALS["KEYUSERS"]));
        @file_put_contents("/etc/squid3/CACHEARP.db", serialize($GLOBALS["CACHEARP"]));
        PurgeMemory();
        empty_TablePrimaireHour();
    }
}
function categories_search($forceArtica = false)
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $dans = new dansguardian_rules();
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $t = $_GET["t"];
    $artica = $forceArtica;
    if (isset($_GET["artica"])) {
        $artica = true;
    }
    $tableSchema = "squidlogs";
    if (!$q->BD_CONNECT()) {
        json_error_show("Testing connection to MySQL server failed...", 1);
    }
    if (!$q->TABLE_EXISTS("webfilters_categories_caches")) {
        $q->CheckTables();
    }
    $dans = new dansguardian_rules();
    $dans->LoadBlackListes();
    $sql = "SELECT * FROM personal_categories";
    if (!$q->TABLE_EXISTS("personal_categories")) {
        json_error_show("personal_categories no such table!", 1);
    }
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $PERSONALSCATS[$ligne["category"]] = $ligne["category_description"];
    }
    $search = '%';
    $page = 1;
    $ORDER = "ORDER BY table_name";
    $searchstring = "table_name LIKE 'category_%'";
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if ($artica) {
        $q = new mysql_catz();
        writelogs("Artica mode -> {$q->database} " . $q->COUNT_CATEGORIES(), __FUNCTION__, __FILE__, __LINE__);
        $tableSchema = "catz";
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    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 = "table_name LIKE 'category_{$search}'";
        $sql = "SELECT COUNT( table_name ) AS tcount FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND table_name LIKE 'category_{$search}'";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $sql = "SELECT COUNT(table_name) as TCOUNT FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND table_name LIKE 'category_%'";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
        }
        $total = $ligne["TCOUNT"];
        writelogs("{$sql} = {$total}", __FUNCTION__, __FILE__, __LINE__);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT table_name as c,TABLE_ROWS FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND {$searchstring} {$ORDER} {$limitSql}";
    writelogs("{$q->mysql_admin}:{$q->mysql_password}:{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
    }
    if (mysql_num_rows($results) == 0) {
        if (!$artica) {
            categories_search(true);
            return;
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("({$tableSchema}) No categories table found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $enc = new mysql_catz();
    while ($ligne = mysql_fetch_assoc($results)) {
        $table = $ligne["c"];
        writelogs("Scanning table {$table}", __FUNCTION__, __FILE__, __LINE__);
        $select = imgtootltip("32-parameters.png", "{apply}", "DansGuardianEditMember('{$ligne["ID"]}','{$ligne["pattern"]}')");
        $items = $q->COUNT_ROWS($ligne["c"]);
        $itemsEnc = $enc->COUNT_ROWS($ligne["c"]);
        if (!preg_match("#^category_(.+)#", $table, $re)) {
            continue;
        }
        $categoryname = $re[1];
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk}", "DansGuardianCompileDB('{$categoryname}')");
        if (!isset($dans->array_blacksites[$categoryname])) {
            if (isset($dans->array_blacksites[str_replace("_", "-", $categoryname)])) {
                $categoryname = str_replace("_", "-", $categoryname);
            }
            if (isset($dans->array_blacksites[str_replace("_", "/", $categoryname)])) {
                $categoryname = str_replace("_", "/", $categoryname);
            }
        }
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $sizedb_org = $q->TABLE_SIZE($table);
        $sizedb = FormatBytes($sizedb_org / 1024);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categories.php?category={$categoryname}&t={$t}',true)\"\n\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $text_category = $dans->array_blacksites[$categoryname];
        if (isset($PERSONALSCATS[$categoryname])) {
            $text_category = utf8_encode($PERSONALSCATS[$categoryname]);
            if ($pic == "&nbsp;") {
                $pic = "<img src='img/20-categories-personnal.png'>";
            }
            $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        }
        if ($EnableWebProxyStatsAppliance == 0) {
            if ($sizedb_org < 35) {
                $pic = "<img src='img/warning-panneau-32.png'>";
            }
        }
        $viewDB = imgsimple("mysql-browse-database-32.png", "{view}", "javascript:Loadjs('squid.categories.php?category={$categoryname}',true)");
        $categoryText = $tpl->_ENGINE_parse_body("<div style='font-size:14px';font-weight:bold'>{$linkcat}{$categoryname}</div>\n\t\t</a><div style='font-size:11px;width:100%;font-weight:normal'>{$text_category}</div>");
        $items = numberFormat($items, 0, "", " ");
        $itemsEnc = numberFormat($itemsEnc, 0, "", " ");
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk} {$categoryname}", "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("delete-32.png", "{delete}", "TableCategoryPurge('{$table}')");
        if ($_GET["minisize"] == "yes") {
            $delete = null;
        }
        $cell = array();
        $cell[] = $pic;
        $cell[] = $categoryText;
        $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>{$sizedb}</div>";
        if (!$artica) {
            $cell[] = "<div style='font-size:13px;padding-top:5px;font-weight:bold'>{$items}<br>{$itemsEnc}</strong>";
        } else {
            $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>-</strong>";
            $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>{$items}</strong>";
        }
        $cell[] = $compile;
        $cell[] = $delete;
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}
function proxy_status()
{
    $ntmlauthenticators_array = array();
    $COUNT_DE_CACHES_TEXT = null;
    $webfilters_paranoid_text = null;
    $users = new usersMenus();
    if ($users->STATS_APPLIANCE) {
        return influxdb_status();
    }
    if ($users->POSTFIX_INSTALLED) {
        return postfix_status();
    }
    $sock = new sockets();
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $EnableArticaMetaServer = intval($sock->GET_INFO("EnableArticaMetaServer"));
    $EnableNginx = intval($sock->GET_INFO("EnableNginx"));
    $EnableHaProxy = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableHaProxy"));
    if ($SQUIDEnable == 0) {
        if ($EnableArticaMetaServer == 1) {
            return meta_server_status();
        }
        if ($EnableNginx == 1) {
            return nginx_server_status();
        }
        if ($EnableHaProxy == 1) {
            return haproxy_server_status();
        }
    }
    $SquidCacheLevel = $sock->GET_INFO("SquidCacheLevel");
    $HTTrackInSquid = intval($sock->GET_INFO("HTTrackInSquid"));
    if (!is_numeric($SquidCacheLevel)) {
        $SquidCacheLevel = 4;
    }
    unset($_GET["_"]);
    $sock = new sockets();
    if (!isset($_GET["ForceCache"])) {
        $md5CacheF = md5("proxy_status{$_SESSION["uid"]}{$tpl->language}" . serialize($_GET));
        $cachefile = "/usr/share/artica-postfix/ressources/interface-cache/{$md5CacheF}";
        if (file_time_sec_Web($cachefile) < 5) {
            return @file_get_contents($cachefile);
        }
    }
    if (isset($_GET["ForceCache"])) {
        $sock->getFrameWork("cmd.php?Global-Applications-Status=yes");
    }
    $q = new mysql_squid_builder();
    $tpl = new templates();
    $page = CurrentPageName();
    $ini = new Bs_IniHandler();
    $users = new usersMenus();
    $perc_cache = null;
    $active_resquests = null;
    $important_events = null;
    $CountDeServices = null;
    $icon = "disks-128-ok.png";
    $rqs = null;
    $NOT_CATEGORIZED_ROW = null;
    $mgr_client_list = $q->COUNT_ROWS("mgr_client_list");
    $SNMP_WALK = proxy_snmp();
    $EnableUfdbGuard = intval($sock->EnableUfdbGuard());
    $SquidUrgency = intval($sock->GET_INFO("SquidUrgency"));
    $MacToUidUrgency = intval($sock->GET_INFO("MacToUidUrgency"));
    $SquidSSLUrgency = intval($sock->GET_INFO("SquidSSLUrgency"));
    $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth"));
    $LogsWarninStop = intval($sock->GET_INFO("LogsWarninStop"));
    $SquidUFDBUrgency = intval($sock->GET_INFO("SquidUFDBUrgency"));
    $IsPortsConverted = intval($sock->GET_INFO("IsPortsConverted"));
    $SquidCacheFullHideWarn = intval($sock->GET_INFO("SquidCacheFullHideWarn"));
    $ActiveDirectoryEmergency = intval($sock->GET_INFO("ActiveDirectoryEmergency"));
    $BasicAuthenticatorEmergency = intval($sock->GET_INFO("BasicAuthenticatorEmergency"));
    $eCAPClamavEmergency = intval($sock->GET_INFO("eCAPClamavEmergency"));
    $ParanoidBlockerEmergency = intval($sock->GET_INFO("ParanoidBlockerEmergency"));
    $EnableeCapClamav = intval($sock->GET_INFO("EnableeCapClamav"));
    $curs = "OnMouseOver=\"this.style.cursor='pointer';\"\n\tOnMouseOut=\"this.style.cursor='auto'\"";
    $WebFiltering_blocked = null;
    $CACHES_AVG = round(@file_get_contents("{$GLOBALS["BASEDIR"]}/CACHES_AVG"), 1);
    $COUNT_DE_BLOCKED = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_BLOCKED"));
    $SquidDebugAcls = intval($sock->GET_INFO("SquidDebugAcls"));
    $AsTransparent = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_TRANSPARENT"));
    $WATCHDOG_COUNT_EVENTS = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/WATCHDOG_COUNT_EVENTS"));
    $COUNT_DE_CACHES = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/COUNT_DE_CACHES"));
    $SUM_FAMILYSITES = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/SUM_FAMILYSITES"));
    $WindowsUpdateCaching = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/WindowsUpdateCaching"));
    $TOP_WEBSITE = unserialize(@file_get_contents("{$GLOBALS["BASEDIR"]}/TOP_WEBSITE"));
    $NOT_CATEGORIZED = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/NOT_CATEGORIZED"));
    $CACHES_RATES = unserialize(@file_get_contents("{$GLOBALS["BASEDIR"]}/TOTAL_CACHED_ARRAY"));
    $TOTALS_NOT_CACHED = intval($CACHES_RATES["TOTALS_NOT_CACHED"]);
    $TOTALS_CACHED = intval($CACHES_RATES["TOTALS_CACHED"]);
    if ($users->AsProxyMonitor) {
        if ($EnableKerbAuth == 1) {
            $ntmlauthenticators = _ntmlauthenticators();
            while (list($cpu, $purc) = each($ntmlauthenticators)) {
                $color = "black";
                if ($purc > 95) {
                    $color = "#d32d2d";
                }
                $ntmlauthenticators_array[] = "\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td style='font-size:18px'>\n\t\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"javscript:Loadjs('squid.ntmlauthenticators.php?cpu={$cpu}')\"\n\t\t\t\t\tstyle='text-decoration:underline;color:{$color}'>{ntlm_processes}: CPU#{$cpu} {$purc}%</a></td>\n\t\t\t\t\t</tr>";
            }
        }
    }
    $SERVICES_STATUS = SERVICES_STATUS();
    if (!is_array($SERVICES_STATUS)) {
        $CountDeServices = $SERVICES_STATUS;
    } else {
        $icon = "disks-128-warn.png";
        $err = $SERVICES_STATUS;
    }
    $scriptEnd = "LoadAjaxTiny('active-directory-dash-infos','{$page}?active-directory-dash-infos=yes');";
    $EnableUfdbGuard = $sock->EnableUfdbGuard();
    $realsquidversion = @file_get_contents("/etc/artica-postfix/settings/Daemons/SquidRealVersion");
    $sql = "SELECT COUNT(*) as tcount FROM proxy_ports WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    if (!$q->ok) {
        $err[] = proxy_status_warning("MySQL error", $q->mysql_error_html(), "blur()");
    }
    $COUNTDePorts = $ligne["tcount"];
    $js_icon_stats = null;
    $icon_stats = "<div style='float:left;margin-right:10px;margin-top:5px'><img src='img/statistics-24-grey.png'></div>";
    $GotoNotCategorized = "GotoNotCategorized()";
    $ActiveRequests_js = "Loadjs('squid.active.requests.php')";
    $GotoNotCategorized_underline = "underline";
    $ActiveRequests_underline = "underline";
    $GotoMysQLAllWebsites_underline = "underline";
    $GoToCachedStatistics = "GoToCachedStatistics()";
    $GotoMysQLAllWebsites = "GotoMysQLAllWebsites()";
    $LoadProxyUpdate = "LoadProxyUpdate();";
    $LOadUfdbUpdate = "GoToWebfilteringDBstatus();";
    if (!$users->AllowViewStatistics) {
        $GotoNotCategorized = "blur();";
        $ActiveRequests_js = "blur()";
        $GotoNotCategorized_underline = "none";
        $ActiveRequests_underline = "none";
        $GoToCachedStatistics = "blur()";
        $GotoMysQLAllWebsites = "blur()";
        $GotoMysQLAllWebsites_underline = "none";
    }
    if (!$users->AsSquidAdministrator) {
        $LoadProxyUpdate = "blur()";
        $LOadUfdbUpdate = "blur()";
    }
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance < 2) {
        $prec = round(@file_get_contents("{$GLOBALS["BASEDIR"]}/CACHED_AVG"), 1);
        $PROXY_REQUESTS_NUMBER = @file_get_contents("{$GLOBALS["BASEDIR"]}/PROXY_REQUESTS_NUMBER");
        $PROXY_REQUESTS_NUMBER = FormatNumber($PROXY_REQUESTS_NUMBER);
        if ($COUNT_DE_CACHES > 0) {
            $COUNT_DE_CACHES_KB = $COUNT_DE_CACHES * 1024;
            $COUNT_DE_CACHES_TEXT = FormatBytes($COUNT_DE_CACHES_KB);
        }
        $js_icon_stats = "OnMouseOver=\"this.style.cursor='pointer';\"\n\t\tOnMouseOut=\"this.style.cursor='auto'\"\n\t\tOnClick=\"javascript:{$GoToCachedStatistics};\"";
        if (is_file("{$GLOBALS["BASEDIR"]}/CACHED_ROW_DAY")) {
            $icon_stats = "<div style='float:left;margin-right:10px;margin-top:5px'>\n\t\t\t\t\t<img src='img/statistics-24.png'></div>";
        }
        if ($SUM_FAMILYSITES > 0) {
            $SUM_FAMILYSITES = FormatNumber($SUM_FAMILYSITES);
            $SUM_FAMILYSITES_TEXT = "\n\t\t\t<tr>\n\t\t\t<td style='font-size:20px'>{websites}:\n\t\t\t<a href=\"javascript:blur();\" OnClick=\"javascript:{$GotoMysQLAllWebsites};\"\n\t\t\tstyle='text-decoration:{$GotoMysQLAllWebsites_underline}'>{$SUM_FAMILYSITES}</a></td>\n\t\t\t</tr>";
        }
    }
    $ActiveRequestsR = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/active_requests.inc"));
    $ActiveRequestsNumber = count($ActiveRequestsR["CON"]);
    $ActiveRequestsIpaddr = count($ActiveRequestsR["IPS"]);
    $ActiveRequestsMembers = count($ActiveRequestsR["USERS"]);
    if ($NOT_CATEGORIZED > 0) {
        $NOT_CATEGORIZED = FormatNumber($NOT_CATEGORIZED);
        $NOT_CATEGORIZED_ROW = "<tr>\n\t\t\t<td style='font-size:20px'>\n\t\t<a href=\"javascript:blur();\"\n\t\tOnClick=\"{$GotoNotCategorized}\"\n\t\tstyle='text-decoration:{$GotoNotCategorized_underline}'>{websites}: {$NOT_CATEGORIZED} {not_categorized}</a></td>\n\t\t</tr>";
    }
    $TITLE_REQUESTS = "\n\t\t<tr>\n\t\t\t<td style='font-size:20px'>\n\t\t<a href=\"javascript:blur();\"\n\t\tOnClick=\"{$ActiveRequests_js}\"\n\t\tstyle='text-decoration:{$ActiveRequests_underline}'>{$ActiveRequestsNumber} {active_requests}</a></td>\n\t\t</tr>";
    if ($COUNTDePorts == 0) {
        $err[] = proxy_status_warning("{no_listening_port_defined}", "{no_listening_port_proxydefined_explain}", "GotoSquidPorts()");
    }
    if ($SquidDebugAcls == 1) {
        $err[] = proxy_status_warning("{debug_acls}", "{debug_acls_explain}", "Loadjs('squid.acls.options.php')");
    }
    if ($SNMP_WALK["ERROR"]) {
        $err[] = proxy_status_warning("SNMP:{need_to_restart_webconsole}", "{click_to_install}", "Loadjs('php-snmp.progress.php'");
    }
    preg_match("#^([0-9]+)\\.([0-9]+)#", $realsquidversion, $re);
    $MAJOR = intval($re[1]);
    $MINOR = intval($re[2]);
    $INCOMPATIBLE = true;
    $REV = 0;
    $BUILD = 0;
    if ($MAJOR > 2) {
        if ($MINOR > 4) {
            $INCOMPATIBLE = false;
        }
    }
    if ($MAJOR == 0) {
        $INCOMPATIBLE = false;
    }
    if ($MAJOR == 4) {
        $INCOMPATIBLE = false;
    }
    if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)#", $realsquidversion, $re)) {
        $REV = intval($re[3]);
    }
    if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)-([0-9]+)-r([0-9]+)#", $realsquidversion, $re)) {
        $BUILD = intval($re[4] . $re[5]);
    }
    if ($SQUIDEnable == 1) {
        if ($INCOMPATIBLE) {
            $incompatible_proxy_version = $tpl->_ENGINE_parse_body("{incompatible_proxy_version}");
            $incompatible_proxy_version = str_replace("%s", $realsquidversion, $incompatible_proxy_version);
            $err[] = proxy_status_warning($incompatible_proxy_version, $incompatible_proxy_version, $LoadProxyUpdate);
        }
        $ArticaTechNetSquidRepo = unserialize(base64_decode($sock->GET_INFO("ArticaTechNetSquidRepo")));
        $NEWVER = null;
        while (list($key, $array) = each($ArticaTechNetSquidRepo)) {
            $AVVERSION = $array["VERSION"];
            $XREV = 0;
            $XBUILD = 0;
            preg_match("#^([0-9]+)\\.([0-9]+)#", $AVVERSION, $re);
            $XMAJOR = intval($re[1]);
            $XMINOR = intval($re[2]);
            if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)#", $AVVERSION, $re)) {
                $XREV = intval($re[3]);
            }
            if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)-([0-9]+)-r([0-9]+)#", $AVVERSION, $re)) {
                $XBUILD = intval($re[4] . $re[5]);
            }
            $KEY = intval("{$XMAJOR}{$XMINOR}{$XREV}{$XBUILD}");
            if ($MAJOR > $XMAJOR) {
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "<strong> squidver check {$XMAJOR}/{$XMINOR}/{$XREV}/{$XBUILD} - {$MAJOR}/{$MINOR}/{$REV}/{$BUILD}</strong>\n<br>";
            }
            if ($XMAJOR > $MAJOR) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "<strong> squidver check {$XMAJOR}>{$MAJOR}</strong>\n<br>";
                }
                $NEWVER = $AVVERSION;
                break;
            }
            if ($XMAJOR == $MAJOR) {
                if ($XMINOR > $MINOR) {
                    $NEWVER = $AVVERSION;
                    break;
                }
            }
            if ($XMAJOR == $MAJOR) {
                if ($XMINOR == $MINOR) {
                    if ($XREV > $REV) {
                        $NEWVER = $AVVERSION;
                        break;
                    }
                }
            }
            if ($XMAJOR == $MAJOR) {
                if ($XMINOR == $MINOR) {
                    if ($XREV == $REV) {
                        if ($XBUILD > $BUILD) {
                            $NEWVER = $AVVERSION;
                            break;
                        }
                    }
                }
            }
        }
        if ($users->AsSquidAdministrator) {
            if ($NEWVER != null) {
                $INFOS[] = status_info_event("{SQUID_NEWVERSION} {$NEWVER}", "{SQUID_NEWVERSION_TEXT}", $LoadProxyUpdate);
            }
        }
    }
    if ($SquidUrgency == 1) {
        $jsOn = "Loadjs('squid.urgency.php?justbutton=yes')";
        if (!$users->AsSquidAdministrator) {
            $jsOn = "blur()";
        }
        $err[] = proxy_status_warning("{proxy_in_emergency_mode}", "{proxy_in_emergency_mode_explain}", $jsOn);
        $icon = "disks-128-red.png";
        //proxy_in_emergency_mode
        //proxy_in_emergency_mode_explain
    }
    if ($SquidSSLUrgency == 1) {
        $jsOn = "Loadjs('squid.urgency.php?ssl=yes');";
        if (!$users->AsSquidAdministrator) {
            $jsOn = "blur()";
        }
        $icon = "disks-128-red.png";
        $err[] = proxy_status_warning("{proxy_in_ssl_emergency_mode}", "{proxy_in_ssl_emergency_mode_explain}", $jsOn);
    }
    if ($MacToUidUrgency == 1) {
        $jsOn = "Loadjs('squid.urgency.php?justbutton=yes');";
        if (!$users->AsSquidAdministrator) {
            $jsOn = "blur()";
        }
        $icon = "disks-128-red.png";
        $err[] = proxy_status_warning("{proxy_in_MacToUid_emergency_mode}", "{proxy_in_MacToUid_emergency_mode_explain}", $jsOn);
    }
    if ($SQUIDEnable == 1) {
        if ($SquidUFDBUrgency == 1) {
            $jsOn = "Loadjs('squid.urgency.php?ufdb=yes');";
            if (!$users->AsSquidAdministrator) {
                $jsOn = "blur()";
            }
            $icon = "disks-128-red.png";
            $err[] = proxy_status_warning("{proxy_in_webfiltering_emergency_mode}", "{proxy_in_webfiltering_emergency_mode_explain}", $jsOn);
        }
        if ($EnableUfdbGuard == 1) {
            if ($users->CORP_LICENSE) {
                $ufdbguard_artica_cloud_version = ufdbguard_artica_cloud_version();
                if ($ufdbguard_artica_cloud_version == 0) {
                    $jsOn = "Loadjs('dansguardian2.articadb-progress.php')";
                    if (!$users->AsSquidAdministrator) {
                        $jsOn = "blur()";
                    }
                    $important_events[] = status_important_event("{update_webfiltering_artica_databases}", "{update_webfiltering_artica_databases_not_updated}", $jsOn);
                }
                if ($ufdbguard_artica_cloud_version > 1) {
                    $jsOn = "Loadjs('dansguardian2.articadb-progress.php')";
                    if (!$users->AsSquidAdministrator) {
                        $jsOn = "blur()";
                    }
                    $important_events[] = status_important_event("{webfiltering_artica_databases_available}", "{webfiltering_artica_databases_available_explain}", $jsOn);
                }
            }
            $ufdbguard_toulouse_cloud_version = ufdbguard_toulouse_cloud_version();
            if ($ufdbguard_toulouse_cloud_version == 0) {
                $jsOn = "Loadjs('dansguardian2.articadb-progress.php')";
                if (!$users->AsSquidAdministrator) {
                    $jsOn = "blur()";
                }
                $important_events[] = status_important_event("{update_webfiltering_toulouse_databases}", "{update_webfiltering_toulouse_databases_not_updated}", $jsOn);
            }
            if ($ufdbguard_toulouse_cloud_version > 1) {
                $jsOn = "Loadjs('dansguardian2.articadb-progress.php')";
                if (!$users->AsSquidAdministrator) {
                    $jsOn = "blur()";
                }
                $important_events[] = status_important_event("{webfiltering_toulouse_databases_available}", "{webfiltering_artica_databases_available_explain}", $jsOn);
            }
        }
    }
    if ($SQUIDEnable == 1) {
        if ($LogsWarninStop == 1) {
            $jsOn = "Loadjs('system.log.emergency.php');";
            if (!$users->AsSquidAdministrator) {
                $jsOn = "blur()";
            }
            $help = help_icon("{squid_logs_urgency}");
            $text = texttooltip("{squid_logs_urgency_section}", "{squid_logs_urgency}", $jsOn);
            $icon = "disks-128-red.png";
            $err[] = proxy_status_warning("{squid_logs_urgency_section}", "{squid_logs_urgency}", $jsOn);
        }
    }
    if ($SQUIDEnable == 1) {
        if ($IsPortsConverted == 0) {
            $jsOn = "Loadjs('squid.compile.progress.php');";
            if (!$users->AsSquidAdministrator) {
                $jsOn = "blur()";
            }
            $icon = "disks-128-warn.png";
            $err[] = proxy_status_warning("{IsPortsConverted_requested}", "{squid_IsPortsConverted_explain}", $jsOn);
        } else {
            if ($AsTransparent > 0) {
                $FireHolConfigured = intval($sock->GET_INFO("FireHolConfigured"));
                if ($FireHolConfigured == 0) {
                    $icon = "disks-128-warn.png";
                    $err[] = proxy_status_warning("{transparent_mode_issue}", "{squid_transparent_no_firewall}", $jsOn);
                }
            }
        }
    }
    $GoToCategoriesServiceA = "GoToCategoriesServiceA()";
    $GotoAdConnection = "GotoAdConnection()";
    $LoadMainDashProxy = "LoadMainDashProxy()";
    $GoToServices = "GoToServices()";
    $GoToUfdb = "GoToUfdb()";
    $GoToCaches = "GoToCaches()";
    $GoToCaches_underline = "underline";
    if (!$users->AsDansGuardianAdministrator) {
        $GoToCategoriesServiceA = "blur()";
        $GoToUfdb = "blur()";
    }
    if (!$users->AsSquidAdministrator) {
        $GotoAdConnection = "blur()";
        $LoadMainDashProxy = "blur()";
        $GoToServices = "blur()";
        $GoToCaches = "blur()";
        $GoToCaches_underline = "none";
    }
    if ($SQUIDEnable == 1) {
        $catz = new mysql_catz();
        if ($catz->UfdbCatEnabled == 1) {
            $categories = $catz->ufdbcat("google.com");
            if (!$catz->ok) {
                $icon = "disks-128-warn.png";
                $err[] = proxy_status_warning("{APP_UFDBCAT}: {connection_error}", $catz->mysql_error, $GoToCategoriesServiceA);
            }
        }
    }
    if ($SQUIDEnable == 1) {
        if ($sock->SQUID_IS_EXTERNAL_LDAP()) {
            $tests = CHECK_SQUID_EXTERNAL_LDAP();
            if ($tests != null) {
                $err[] = proxy_status_warning("{$tests}", "{$tests}", "GotoOpenldap()");
            }
        }
    }
    if ($BasicAuthenticatorEmergency == 1) {
        $jsOn = "Loadjs('squid.urgency.php?justbutton=yes');";
        if (!$users->AsSquidAdministrator) {
            $jsOn = "blur()";
        }
        $icon = "disks-128-warn.png";
        $err[] = proxy_status_warning("{authentication_emergency_mode}", "{authentication_emergency_mode_explain}", $jsOn);
    }
    if ($SQUIDEnable == 1) {
        if ($EnableKerbAuth == 1) {
            if ($ActiveDirectoryEmergency == 1) {
                $jsOn = "Loadjs('squid.urgency.php?activedirectory=yes');";
                if (!$users->AsSquidAdministrator) {
                    $jsOn = "blur()";
                }
                $icon = "disks-128-warn.png";
                $err[] = proxy_status_warning("{activedirectory_emergency_mode}", "{activedirectory_emergency_mode_explain}", $jsOn);
            }
            if (!$users->CORP_LICENSE) {
                $Days = 86400 * 30;
                $DayToLeft = 30;
                if (is_file("/usr/share/artica-postfix/ressources/class.pinglic.inc")) {
                    include_once "/usr/share/artica-postfix/ressources/class.pinglic.inc";
                    $EndTime = $GLOBALS['ADLINK_TIME'] + $Days;
                    $seconds_diff = $EndTime - time();
                    $DayToLeft = floor($seconds_diff / 3600 / 24);
                }
                $MAIN_ERROR = $tpl->_ENGINE_parse_body("{warn_no_license_activedirectory_30days}");
                $MAIN_ERROR = str_replace("%s", $DayToLeft, $MAIN_ERROR);
                $important_events[] = status_important_event($MAIN_ERROR, $MAIN_ERROR, $jsOn);
            }
            if ($ActiveDirectoryEmergency == 0) {
                $IsConnected = IsKerconnected();
                if ($IsConnected != "TRUE") {
                    $err[] = proxy_status_warning("{proxy_is_not_configured_ad}", null, $GotoAdConnection);
                }
            }
            $TestLDAPAD = TestLDAPAD();
            if ($TestLDAPAD != null) {
                $err[] = $TestLDAPAD;
            }
            $AdminAsSeenNTLMPerfs = intval($sock->GET_INFO("AdminAsSeenNTLMPerfs"));
            if ($AdminAsSeenNTLMPerfs == 0) {
                $err[] = proxy_status_warning("{NTLM_PERFORMANCES_NOT_DEFINED}", null, $GotoAdConnection);
            }
        }
    }
    if ($EnableeCapClamav == 1) {
        if ($eCAPClamavEmergency == 1) {
            $jsOn = "Loadjs('squid.urgency.php?eCAPClamavEmergency=yes');";
            if (!$users->AsSquidAdministrator) {
                $jsOn = "blur()";
            }
            $icon = "disks-128-warn.png";
            $err[] = proxy_status_warning("{eCAPClamav_emergency_mode}", "{activedirectory_emergency_mode_explain}", $jsOn);
        }
    }
    if ($ParanoidBlockerEmergency == 1) {
        $jsOn = "Loadjs('squid.urgency.php?ParanoidBlockerEmergency=yes');";
        if (!$users->AsSquidAdministrator) {
            $jsOn = "blur()";
        }
        $icon = "disks-128-warn.png";
        $err[] = proxy_status_warning("{paranoid_emergency_mode}", "{paranoid_emergency_mode_explain}", $jsOn);
    }
    if ($SquidCacheFullHideWarn == 0) {
        if ($COUNT_DE_CACHES > 0) {
            if ($CACHES_AVG > 85) {
                $err[] = proxy_status_warning("{caches_are_full}", "{caches_are_full_explain}", $GoToCaches);
            }
        }
    }
    if ($COUNT_DE_CACHES > 0) {
        $COUNT_DE_MEMBERS = intval(@file_get_contents("{$GLOBALS["BASEDIR"]}/MEMBERS_COUNT"));
        if ($COUNT_DE_MEMBERS > 15) {
            if ($COUNT_DE_CACHES < 20000) {
                $undersized_proxy_caches_explain = $tpl->_ENGINE_parse_body("{undersized_proxy_caches_explain}");
                $COUNT_DE_CACHES_KB = $COUNT_DE_CACHES * 1024;
                $COUNT_DE_CACHES_TEXT = FormatBytes($COUNT_DE_CACHES_KB);
                $undersized_proxy_caches_explain = str_replace("%S", $COUNT_DE_CACHES_TEXT, $undersized_proxy_caches_explain);
                $undersized_proxy_caches_explain = str_replace("%U", $COUNT_DE_MEMBERS, $undersized_proxy_caches_explain);
                if ($SquidCacheLevel > 0) {
                    $err[] = proxy_status_warning("{undersized_proxy_caches}", $undersized_proxy_caches_explain, $GoToCaches);
                }
            }
        }
    }
    if (!$users->AsSquidAdministrator) {
        $err = array();
    }
    if (count($err) > 0) {
        $errT[] = "<tr><td style='font-size:32px;color:#d32d2d;vertical-align:middle'>" . count($err) . " {issues}</td></tr>\n\t\t<tr><td colspan=2>&nbsp;</td></tr>\t\n\t\t\t\t";
    }
    $ActiveRequestsR = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/active_requests.inc"));
    $ActiveRequestsNumber = count($ActiveRequestsR["CON"]);
    $ActiveRequestsIpaddr = count($ActiveRequestsR["IPS"]);
    $ActiveRequestsMembers = count($ActiveRequestsR["USERS"]);
    $GotoParanoidMode = "GotoParanoidMode()";
    $GotoParanoidMode_underline = "underline";
    $GoToUfdb_underline = "underline";
    if (!$users->AsDansGuardianAdministrator) {
        $GotoParanoidMode = "blur()";
        $GoToUfdb = "blur()";
        $GotoParanoidMode_underline = "none";
        $GoToUfdb_underline = "none";
    }
    $UfdbEnableParanoidMode = intval($sock->GET_INFO("UfdbEnableParanoidMode"));
    if ($UfdbEnableParanoidMode == 1) {
        $q = new mysql_squid_builder();
        $webfilters_paranoid = $q->COUNT_ROWS("webfilters_paranoid");
        if ($webfilters_paranoid > 0) {
            $webfilters_paranoid_text = "\n\t\t<tr>\n\t\t<td style='font-size:20px'>\n\t\t<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:{$GotoParanoidMode}\"\n\t\tstyle='text-decoration:{$GotoParanoidMode_underline}'>{paranoid_mode}: " . FormatNumber($webfilters_paranoid) . " {rules}</a></td>\n\t\t</tr>";
        }
    }
    if ($EnableUfdbGuard == 1) {
        if ($COUNT_DE_BLOCKED > 0) {
            $WebFiltering_blocked = "\n\t\t<tr>\n\t\t<td style='font-size:20px'>\n\t\t<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:{$GoToUfdb}\"\n\t\tstyle='text-decoration:{$GoToUfdb_underline}'>{blocked_events}: " . FormatNumber($COUNT_DE_BLOCKED) . "</a></td>\n\t\t</tr>";
        }
    }
    if (intval($ini->_params["SQUID"]["service_disabled"]) == 1) {
        if ($ini->_params["SQUID"]["running"] == 0) {
            $icon = "disks-128-red.png";
        }
    }
    $mgr_client_list_TR = "\n\t\t<tr>\n\t\t\t<td style='font-size:20px'>\n\t\t\t<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:GotoMgrClientList()\"\n\t\t\tstyle='text-decoration:underline'>{active_clients}: " . FormatNumber($SNMP_WALK["CLIENTS_NUMBER"]) . "</a></td>\n\t\t</tr>";
    $active_resquests_js = "Loadjs('squid.active.requests.php')";
    $active_resquests_underline = "underline";
    if (!$users->AsSquidAdministrator) {
        $active_resquests_js = "blur()";
        $active_resquests_underline = "none";
    }
    if ($ActiveRequestsNumber > 1) {
        $active_resquests = "\n\t\t<tr>\n\t\t\t<td style='font-size:20px'>\n\t\t\t<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$active_resquests_js}\"\n\t\t\tstyle='text-decoration:underline'>{active_requests}: {$ActiveRequestsNumber}</a></td>\n\t\t</tr>";
    }
    if (intval($WATCHDOG_COUNT_EVENTS) > 0) {
        $important_events[] = status_important_event("{$WATCHDOG_COUNT_EVENTS} {important_events_48h}", null, "GotoWatchdog()");
    }
    $CACHES_AVG_COLOR = "black";
    if ($CACHES_AVG > 85) {
        if ($SquidCacheFullHideWarn == 0) {
            $CACHES_AVG_COLOR = "#d32d2d";
        }
    }
    if (count($important_events) > 0) {
        $important_events_text = "<tr><td colspan=2>&nbsp;</td></tr>" . @implode("\n", $important_events);
    }
    if ($SQUIDEnable == 0) {
        $icon = "disks-128-ok-grey.png";
    }
    if (count($INFOS) > 0) {
        $INFOS[] = "<tr><td><br></td></tr>";
    }
    if ($SquidCacheLevel == 0) {
        $SNMP_WALK["PERC_CACHE"] = 0;
        $SNMP_WALK["STORED_OBJECTS"] = 0;
    }
    $prec = intval($SNMP_WALK["PERC_CACHE"]);
    if ($prec > 0) {
        $perc_cache = "\n\t\t<tr>\n\t\t\t<td style='font-size:18px;vertical-align:middle'>{$prec}% {cache} ({currently})</td>\n\t\t</tr>";
    }
    $REQUESTS = intval($SNMP_WALK["REQUESTS"]);
    if ($REQUESTS > 0) {
        $current_req = "<tr>\n\t\t<td style='font-size:18px;vertical-align:middle'>" . FormatNumber($REQUESTS) . " {requests}</td>\n\t\t</tr>";
    }
    if ($SNMP_WALK["CPU"] > 0) {
        $current_cpu_use = "<tr>\n\t\t<td style='font-size:18px;vertical-align:middle'>{$SNMP_WALK["CPU"]}% {cpu_use}</td>\n\t\t</tr>";
    }
    $windowsUpdate = null;
    if ($WindowsUpdateCaching == 1) {
        $cacheFile = "/usr/share/artica-postfix/ressources/logs/web/WindowsUpdate.state";
        $ARRAY = unserialize(@file_get_contents($cacheFile));
        if (intval($ARRAY["SIZEKB"]) > 4) {
            $windowsUpdate = "\n\t\t\t<tr>\n\t\t\t<td style='font-size:18px;vertical-align:middle'> \n\t\t\t<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:GotoWindowsUpdate()\"\n\t\t\tstyle='text-decoration:underline'>Windows Update:</a> " . FormatBytes($ARRAY["SIZEKB"]) . "</td>\n\t\t\t</tr>";
        }
    }
    $HTTrack = null;
    if ($HTTrackInSquid == 1) {
        $HTTRackSize = $sock->GET_INFO("HTTRackSize");
        if ($HTTRackSize > 0) {
            $HTTrack = "\n\t\t\t<tr>\n\t\t\t<td style='font-size:18px;vertical-align:middle'>\n\t\t\t<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:GotoWebCopy()\"\n\t\t\tstyle='text-decoration:underline'>WebCopy:</a> " . FormatBytes($HTTRackSize / 1024) . "</td>\n\t\t\t</tr>";
        }
    }
    if ($SNMP_WALK["STORED_OBJECTS"] > 0) {
        $current_stored_objects = "<tr>\n\t\t<td style='font-size:18px;vertical-align:middle'>" . FormatNumber($SNMP_WALK["STORED_OBJECTS"]) . " {stored_objects}</td>\n\t\t</tr>";
    }
    if ($SquidCacheLevel > 0) {
        if ($COUNT_DE_CACHES_TEXT != null) {
            $INFO_STORAGE_CACHE = "\n\t\t\t<tr>\n\t\t\t<td style='font-size:20px'>\n\t\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"{$GoToCaches}\"\n\t\t\t\t\tstyle='text-decoration:{$GoToCaches_underline};color:{$CACHES_AVG_COLOR}'>\n\t\t\t\t\t\t{storage}: {$CACHES_AVG}%&nbsp;/&nbsp;{$COUNT_DE_CACHES_TEXT}</a>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        }
    }
    $CACHED_DETAILS_TOTAL = null;
    $NOT_CACHED_DETAILS_TOTAL = null;
    if ($TOTALS_CACHED > 0) {
        $CACHED_DETAILS_TOTAL = "\n\t\t<tr>\n\t\t\t<td style='font-size:18px'>\n\t\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"{$GoToCaches}\"\n\t\t\t\t\tstyle='text-decoration:{$GoToCaches_underline};color:black'>\n\t\t\t\t\t\t{cached}: " . FormatBytes($TOTALS_CACHED / 1024) . "</a>\n\t\t\t</td>\n\t\t</tr>\n\t";
    }
    if ($TOTALS_NOT_CACHED > 0) {
        $NOT_CACHED_DETAILS_TOTAL = "\n\t\t<tr>\n\t\t\t<td style='font-size:18px'>\n\t\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"{$GoToCaches}\"\n\t\t\t\t\tstyle='text-decoration:{$GoToCaches_underline};color:black'>\n\t\t\t\t\t\t{not_cached}: " . FormatBytes($TOTALS_NOT_CACHED / 1024) . "</a>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t";
    }
    if (!$users->AsSquidAdministrator) {
        $important_events_text = null;
        $errT = array();
        $windowsUpdate = null;
        $mgr_client_list_TR = null;
    }
    $icon = imgtootltip($icon, "position:right:{configure_your_proxy}", "{$LoadMainDashProxy}");
    $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td valign='top' style='width:128px' >\n\t\t\t{$icon}\n\t\t\t<div id='active-directory-dash-infos'>" . active_directory_infos() . "</div>\t\n\t\t</td>\n\t\t<td>\n\t\t\t<table style='width:100%'>\n\t\t\t<tr>\n\t\t\t\t<td style='font-size:30px'>\n\t\t\t\t" . texttooltip("{your_proxy}", "{configure_your_proxy}", "{$LoadMainDashProxy}") . "\n\t\t\t\t&nbsp;<span style='font-size:22px'>[&nbsp;<a href=\"javascript:blur();\" \n\t\t\t\tOnClick=\"javascript:Loadjs('squid.infos.php');\"\n\t\t\t\tstyle='text-decoration:underline'>Infos.</a>&nbsp;]</span>\t\t\n\t\t\t\t\t\t\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<!-- perc_cache -->\n\t\t\t{$perc_cache}\n\t\t\t<!-- TOTALS_CACHED:{$TOTALS_CACHED} -->\n\t\t\t{$CACHED_DETAILS_TOTAL}\n\t\t\t<!-- TOTALS NOT CACHED:{$TOTALS_NOT_CACHED} -->\n\t\t\t{$NOT_CACHED_DETAILS_TOTAL}\n\t\t\t<!-- windowsUpdate -->\n\t\t\t{$windowsUpdate}\n\t\t\t<!-- HTTrack -->\n\t\t\t{$HTTrack}\n\t\t\t<!-- current_req -->\n\t\t\t{$current_req}\n\t\t\t<!-- SUM_FAMILYSITES_TEXT -->\n\t\t\t{$SUM_FAMILYSITES_TEXT}\n\t\t\n\t\t\t{$active_resquests}\n\t\t\t{$mgr_client_list_TR}\n\t\t\t{$rqs}\n\t\t\t\t" . @implode("", $ntmlauthenticators_array) . "\n\t\t\t\n\t\t\t\n\t\t<!-- WebFiltering_blocked -->\n\t\t{$WebFiltering_blocked}\n\t\t<!-- webfilters_paranoid -->\n\t\t{$webfilters_paranoid_text}\t\n\t\t<!-- INFO_STORAGE_CACHE -->\n\t\t{$INFO_STORAGE_CACHE}\n\t\t\n\t\t\n\t\t\n\t<!-- current_stored_objects -->\n\t\t\t{$current_stored_objects}\n\t<!-- TITLE_REQUESTS -->\n\t\t\t{$TITLE_REQUESTS}\n\t<!-- TOP_GRAPHS -->\n\t\t\t" . TOP_GRAPHS() . "\n\t\t\t{$CountDeServices}\n\t\t\t" . @implode("", $INFOS) . "\n\t\t\t" . @implode("", $errT) . "\n\t\t\t" . @implode("", $err) . "\n\t\t\t{$important_events_text}\n\t\t\t\n\t\t\t</table>\n\t\t</td>\n\t</tr>\n\t</table>\n\t<script>\n\t\tLoadAjaxSilent('proxy_dashboard_counters','{$page}?proxy_dashboard_counters=yes');\n\t</script>\n\t";
    $html = $tpl->_ENGINE_parse_body($html);
    if (!is_dir("/usr/share/artica-postfix/ressources/interface-cache")) {
        @mkdir("/usr/share/artica-postfix/ressources/interface-cache");
    }
    @file_put_contents($cachefile, $html);
    return $html;
}
Beispiel #22
0
function status()
{
    $tpl = new templates();
    $sock = new sockets();
    $RemoteUfdbCat = intval($sock->GET_INFO("RemoteUfdbCat"));
    $page = CurrentPageName();
    $EnableLocalUfdbCatService = intval($sock->GET_INFO("EnableLocalUfdbCatService"));
    $AsCategoriesAppliance = intval($sock->GET_INFO("AsCategoriesAppliance"));
    if ($AsCategoriesAppliance == 1) {
        $RemoteUfdbCat = 0;
        $EnableLocalUfdbCatService = 1;
    }
    $catz = new mysql_catz();
    if ($catz->UfdbCatEnabled == 0) {
        echo $tpl->_ENGINE_parse_body(Paragraphe32("{service_disabled}", "noacco:\n\t\t\t\t<span style='font-size:12px'>&nbsp;</span>\n\t\t\t\t<br>{$catz->FinalUsedServer}", null, "ok48-grey.png"));
        return;
    }
    $categories = $catz->ufdbcat("google.com");
    if ($catz->ok) {
        $table = "<table style='width:99%'>\n\t\t<tr>\n\t\t\t<td width=48px style='vertical-align:top'><img src='/img/ok48.png'></td>\n\t\t\t<td style='vertical-align:top'>\n\t\t\t<td><span style='font-size:12px'><strong>google.com:</strong><br>{category}:<strong>;{$categories}</strong>\n\t\t\t<br>{execution_time} {$catz->TimeExec}s</span>\t\n\t\t\t<br><strong style='font-size:12px'>{$catz->FinalUsedServer}</strong>\t\n\t\t\t<div style='width:100%;text-align:right'>" . imgtootltip("refresh-32.png", "{refresh}", "LoadAjax('UFDBCAT_STATUS','{$page}?status=yes')") . "</duv>\n\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t";
        echo $tpl->_ENGINE_parse_body($table);
    } else {
        $table = "<table style='width:99%'>\n\t\t<tr>\n\t\t<td width=48px style='vertical-align:top'><img src='/img/error-48.png'></td>\n\t\t<td style='vertical-align:top'>\n\t\t<td><span style='font-size:12px;color:#d32d2d'><strong>{connection_error}:</strong>\n\t\t<br>{error}:<strong>;{$catz->mysql_error}</strong>\n\t\t<br><strong style='font-size:12px'>{$catz->FinalUsedServer}</strong>\n\t\t<div style='width:100%;text-align:right'>" . imgtootltip("refresh-32.png", "{refresh}", "LoadAjax('UFDBCAT_STATUS','{$page}?status=yes')") . "</duv>\n\t\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t";
        echo $tpl->_ENGINE_parse_body($table);
    }
    echo "<p>&nbsp;</p>";
    echo "<center>" . $tpl->_ENGINE_parse_body(button("{update_now}", "Loadjs('dansguardian2.articadb-progress.php')", 26)) . "</center>";
    $data = $sock->getFrameWork('cmd.php?ufdbcat-ini-status=yes');
    $ini = new Bs_IniHandler();
    $ini->loadString(base64_decode($data));
    $APP_UFDBCAT = DAEMON_STATUS_ROUND("APP_UFDBCAT", $ini, null, 1);
    echo "<p>&nbsp;</p>";
    echo $tpl->_ENGINE_parse_body($APP_UFDBCAT);
    $ufdbCatInterface = $sock->GET_INFO("ufdbCatInterface");
    $ufdbCatPort = intval($sock->GET_INFO("ufdbCatPort"));
    $UfdbCatThreads = intval($sock->GET_INFO("UfdbCatThreads"));
    if ($ufdbCatInterface == null) {
        $ufdbCatInterface = "127.0.0.1";
    }
    if ($ufdbCatInterface == "all") {
        $ufdbCatInterface = "127.0.0.1";
    }
    echo "<div style='text-align:right'>" . imgtootltip("refresh-32.png", "{refresh}", "LoadAjax('UFDBCAT_STATUS','{$page}?status=yes');") . "\n\t</div>";
}
Beispiel #23
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;
}
function status_category_database(){
	$users=new usersMenus();
	$sock=new sockets();
	$tpl=new templates();
	$DisableArticaProxyStatistics=$sock->GET_INFO("DisableArticaProxyStatistics");
	if(!is_numeric($DisableArticaProxyStatistics)){$DisableArticaProxyStatistics=0;}
	if($DisableArticaProxyStatistics==1){return;}
	
	$CATZ_ARRAY=unserialize(@file_get_contents("/home/artica/categories_databases/CATZ_ARRAY"));
		
	$LOCAL_VERSION=$CATZ_ARRAY["TIME"];
	$title=$tpl->_ENGINE_parse_body("{APP_ARTICADB}");
	$q=new mysql_catz();
	$categories=$q->COUNT_CATEGORIES();
	if(!is_numeric($categories)){$categories=0;}
	$categories=numberFormat($categories,0,""," ");
	$SquidPerformance=intval($sock->GET_INFO("SquidPerformance"));
	
	if($SquidPerformance>0){
		$LOCAL_VERSION="{disabled}";
		$categories="{disabled}";
	}
	
	return Paragraphe32("noacco:$title", "
	<strong>Version</strong>:&nbsp;v.$LOCAL_VERSION<br>
	<strong>{items}</strong>:&nbsp;$categories<br>","Loadjs('squid.categories.php?onlyDB=yes',true)","database-link-32.png");
	
}
function categories_search()
{
    $tpl = new templates();
    $catz = new mysql_catz();
    $tables = $catz->LIST_TABLES_CATEGORIES();
    $dans = new dansguardian_rules();
    $dans->LoadBlackListes();
    $search = string_to_flexregex("categories-search");
    $TransArray = $catz->TransArray();
    while (list($key, $value) = each($tables)) {
        $categoryname = $TransArray[$key];
        $text_category = $tpl->_ENGINE_parse_body($dans->array_blacksites[$categoryname]);
        if (!isset($dans->array_blacksites[$categoryname])) {
            continue;
        }
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $CTCOUNT = $catz->COUNT_ROWS($key);
        if ($CTCOUNT == 0) {
            continue;
        }
        $items = numberFormat($CTCOUNT, 0);
        if ($search != null) {
            if (!preg_match("#{$search}#", $categoryname)) {
                if (!preg_match("#{$search}#", $text_category)) {
                    continue;
                }
            }
        }
        $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td width=1% nowrap>{$pic}</td>\n\t\t<td><i class='icon-globe'></i>&nbsp;<strong>{$categoryname}</strong><div>{$text_category}</div></td>\n\t\t<td nowrap><i class='icon-info-sign'></i>&nbsp;<span style='font-size:18px'>{$items}</span></td>\n\t\t</tr>";
    }
    echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=2>{category}</th>\n\t\t\t\t\t<th>{websites}</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("", $tr) . "</tbody></table>";
}
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);
}
Beispiel #27
0
function clean_squid_stats_dbs()
{
    $sock = new sockets();
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    $CleanArticaSquidDatabases = $sock->GET_INFO("CleanArticaSquidDatabases");
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_numeric($CleanArticaSquidDatabases)) {
        $CleanArticaSquidDatabases = 0;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($CleanArticaSquidDatabases == 0) {
            echo "Option is not activated...\n";
            return;
        }
    }
    $q = new mysql_squid_builder();
    $tables = $q->LIST_TABLES_DAYS();
    $rows = 0;
    $count_tables = 0;
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_DAYS_BLOCKED();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_MEMBERS();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_MONTH();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_WEEKS();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $q = new mysql_catz();
    $tables = $q->LIST_TABLES_CATEGORIES();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $q = new mysql();
    if ($q->DATABASE_EXISTS("catz")) {
        $q->DELETE_DATABASE("catz");
    }
    if ($count_tables > 0) {
        mysql_admin_mysql(1, "Restarting MySQL service...", null, __FILE__, __LINE__);
        shell_exec("/etc/init.d/mysql restart");
    }
    $sock->TOP_NOTIFY("{$count_tables} statistics tables as been deleted with {$rows} rows", "info");
    //print_r($tables);
}
function squid_status_stats()
{
    $off = "<script>UnlockPage();</script>";
    if (!$GLOBALS["AS_ROOT"]) {
        $cachefile = "/usr/share/artica-postfix/ressources/logs/web/traffic.statistics.html";
        if (is_file($cachefile)) {
            $tpl = new templates();
            $cacheContent = @file_get_contents($cachefile);
            if (strlen($cacheContent) > 20) {
                echo $tpl->_ENGINE_parse_body(@file_get_contents($cachefile)) . $off;
                return;
            }
        }
    }
    if (CACHE_SESSION_GET(__FUNCTION__, __FILE__)) {
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " Loading classes<br>\n";
    }
    $sock = new sockets();
    $users = new usersMenus();
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    $SquidActHasReverse = $sock->GET_INFO("SquidActHasReverse");
    if (!is_numeric($SquidActHasReverse)) {
        $SquidActHasReverse = 0;
    }
    if ($EnableRemoteStatisticsAppliance == 1) {
        return;
    }
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    $MalwarePatrolDatabasesCount = $sock->getFrameWork("cmd.php?MalwarePatrolDatabasesCount=yes");
    $mouse = "OnMouseOver=\";this.style.cursor='pointer';\" OnMouseOut=\";this.style.cursor='default';\"";
    $EnableMacAddressFilter = $sock->GET_INFO("EnableMacAddressFilter");
    if (!is_numeric($EnableMacAddressFilter)) {
        $EnableMacAddressFilter = 1;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " Loading mysql_storelogs()<br>\n";
    }
    $syslogs = new mysql_storelogs();
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " Count accesslogs<br>\n";
    }
    $SyslogsFiles = $syslogs->COUNT_ROWS("accesslogs");
    $TR_ACCESSLOG = "\n\t<tr>\n\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' \n\t\tOnClick=\"javascript:Loadjs('squid.accesses.rotate.php')\"><b><span style='font-size:12px'>{$SyslogsFiles}</span></b><span style='font-size:12px'> {access_logs}</td>\n\t</tr>";
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    if ($users->PROXYTINY_APPLIANCE) {
        $DisableArticaProxyStatistics = 1;
    }
    if ($DisableArticaProxyStatistics == 0) {
        $websitesnums = $q->COUNT_ROWS("visited_sites");
        $websitesnums = numberFormat($websitesnums, 0, "", " ");
        $sql = "DELETE FROM categorize WHERE LENGTH(pattern)=0";
        $q->QUERY_SQL($sql);
        $export = $q->COUNT_ROWS("categorize");
        $export = numberFormat($export, 0, "", " ");
    }
    $catz = new mysql_catz();
    $categories = $catz->COUNT_CATEGORIES();
    $categories = numberFormat($categories, 0, "", " ");
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " categories= {$categories}<br>\n";
    }
    $YourItems = $q->COUNT_CATEGORIES();
    $YourItems = numberFormat($YourItems, 0, "", " ");
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " LIST_TABLES_CATEGORIES()<br>\n";
    }
    $tablescat = $q->LIST_TABLES_CATEGORIES();
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " tablescat={$tablescat}<br>\n";
    }
    $tablescatNUM = numberFormat(count($tablescat), 0, "", " ");
    if ($DisableArticaProxyStatistics == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . " EVENTS_SUM()<br>\n";
        }
        $requests = $q->EVENTS_SUM();
        $requests = numberFormat($requests, 0, "", " ");
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . " requests = {$requests}<br>\n";
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " no_license -> translate<br>\n";
    }
    $nolicense = $tpl->_ENGINE_parse_body("{no_license}");
    $PhishingURIS = $q->COUNT_ROWS("categoryuris_phishing");
    $PhishingURIS = numberFormat($PhishingURIS, 0, "", " ");
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " >COUNT_ROWS('categoryuris_malware')<br>\n";
    }
    $MalwaresURIS = $q->COUNT_ROWS("categoryuris_malware");
    $MalwaresURIS = numberFormat($MalwaresURIS, 0, "", " ");
    if (!$users->CORP_LICENSE) {
        $PhishingURIS = $nolicense;
        $MalwaresURIS = $nolicense;
    }
    if ($DisableArticaProxyStatistics == 0) {
        if ($EnableMacAddressFilter == 1) {
            $Computers = $q->COUNT_ROWS("webfilters_nodes");
            $Computers = numberFormat($Computers, 0, "", " ");
            $nodes = "\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.nodes.php',true)\"><b><span style='font-size:12px'>{$Computers}</span></b><span style='font-size:12px'> {computers}</td>\n\t\t\t</tr>";
        } else {
            $Computers = $q->COUNT_ROWS("UserAutDB");
            $Computers = numberFormat($Computers, 0, "", " ");
            $nodes = "\n\t\t\t<tr>\n\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.UserAutDB.php')\"><b><span style='font-size:12px'>{$Computers}</span></b><span style='font-size:12px'> {clients}</td>\n\t\t\t</tr>";
        }
        if (!$users->CORP_LICENSE) {
            $license_inactive = "<br><strong style='font-size:11px;font-weight:bolder;color:#BA1010'>{license_inactive}</strong>";
        }
        if (!$q->TABLE_EXISTS("tables_day")) {
            $q->CheckTables();
        }
        $DAYSNumbers = $q->COUNT_ROWS("tables_day");
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . " DAYSNumbers = {$DAYSNumbers}<br>\n";
        }
        //$GLOBALS["FULL_DEBUG"]
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(totalsize) as tsize FROM tables_day"));
        $totalsize = FormatBytes($ligne["tsize"] / 1024);
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT AVG(cache_perfs) as pourc FROM tables_day"));
        $pref = round($ligne["pourc"]);
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(sitename) as tcount FROM visited_sites WHERE LENGTH(category)=0"));
        $websitesnumsNot = numberFormat($ligne["tcount"], 0, "", " ");
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . " SELECT count(youtubeid),youtubeid FROM `youtube_dayz` GROUP BY youtubeid<br>\n";
        }
        $results = $q->QUERY_SQL("SELECT count(youtubeid),youtubeid FROM `youtube_dayz` GROUP BY youtubeid");
        $youtube_objects = mysql_num_rows($results);
        $youtube_objects = numberFormat($youtube_objects, 0, "", " ");
        $CachePermformance = $q->CachePerfHour();
        if ($GLOBALS["VERBOSE"]) {
            echo __LINE__ . " CachePermformance = {$CachePermformance}<br>\n";
        }
        if ($CachePermformance > -1) {
            $color = "#E01313";
            if ($CachePermformance > 20) {
                $color = "#6DBB6A";
            }
            $cachePerfText = "\n\t\t\t<tr>\n\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t<td valign='top' style='font-size:12px;'><b style='color:{$color}'>{$CachePermformance}%</span></b><span style='font-size:12px'> {cache_performance} ({now})</td>\n\t\t\t</tr>\n\t\t\t";
        }
        if ($SquidActHasReverse == 1) {
            $TR_CAT_NUMBER = null;
        }
        $TR_CAT_NUMBER = "\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.categories.php')\"><b><span style='font-size:12px'>{$categories}</span></b><span style='font-size:12px'> {websites_categorized}{$license_inactive}</td>\n\t</tr>\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.categories.php')\"><span style='font-size:12px'>{youritems}: <b>{$YourItems}</span></b><span style='font-size:12px'></td>\n\t</tr>";
        $TR_CATZ = "\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td width=99% valign='top' style='font-size:12px;text-decoration:underline' \n\t\t{$mouse} OnClick=\"javascript:Loadjs('squid.traffic.statistics.days.php?js=yes&with-purge=yes')\"><b><span style='font-size:12px'>{$DAYSNumbers}</span></b><span style='font-size:12px'> {daysOfStatistics}</td>\n\t</tr>\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' style='font-size:12px'><b><span style='font-size:12px'>{$requests}</span></b><span style='font-size:12px'> {requests}</td>\n\t</tr>\n\t{$nodes}\n\t\t\n\t{$TR_CAT_NUMBER}\n";
        $TR_YOUTUBE = "\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline'\n\t\t{$mouse} OnClick=\"javascript:Loadjs('squid.youtube.all.php')\"\n\t\t><b><span style='font-size:12px'>{$youtube_objects}</span></b><span style='font-size:12px'> Youtube {objects}</td>\n\t</tr>";
        if ($DisableArticaProxyStatistics == 1) {
            $TR_YOUTUBE = null;
            $TR_CATZ = null;
        }
        if ($SquidActHasReverse == 1) {
            $TR_YOUTUBE = null;
        }
        $submenu = "\t\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' style='font-size:12px'><b><span style='font-size:12px'>{$totalsize}</span></b><span style='font-size:12px'> {downloaded_flow}</td>\n\t</tr>\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' style='font-size:12px'><b><span style='font-size:12px'>{$pref}%</span></b><span style='font-size:12px'> {cache_performance}</td>\n\t</tr>\n\t\n\t{$cachePerfText}";
        $main_table = "\n\t\t\n\t\t{$TR_CATZ}\n\t\t{$TR_YOUTUBE}\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$PhishingURIS}</span></b><span style='font-size:12px'> {phishing_uris}</td>\n\t</tr>\t\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$MalwaresURIS}</span></b><span style='font-size:12px'> {viruses_uris}</td>\n\t</tr>\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$MalwarePatrolDatabasesCount}</span></b><span style='font-size:12px'> Malware Patrol</td>\n\t</tr>\t\n\t\t\t\t\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.visited.php?onlyNot=yes')\"><b><span style='font-size:12px'>{$websitesnumsNot}</span></b><span style='font-size:12px'> {not_categorized}</td>\n\t</tr>\t\n\t\t\t\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.categories.php')\"><b><span style='font-size:12px'>{$tablescatNUM}</span></b><span style='font-size:12px'> {categories}</td>\n\t</tr>\t\n\t\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"javascript:Loadjs('squid.categories.toexport.php')\"><b><span style='font-size:12px'>{$export}</span></b><span style='font-size:12px'> {websites_to_export}</td>\n\t</tr>";
    }
    if ($DisableArticaProxyStatistics == 1) {
        $main_table = "\t\n\t\t\t\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$PhishingURIS}</span></b><span style='font-size:12px'> {phishing_uris}</td>\n\t\t\t</tr>\t\n\t\t\t\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$MalwaresURIS}</span></b><span style='font-size:12px'> {viruses_uris}</td>\n\t\t\t</tr>\n\t\t\t\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' OnClick=\"blur()\"><b><span style='font-size:12px'>{$MalwarePatrolDatabasesCount}</span></b><span style='font-size:12px'> Malware Patrol</td>\n\t\t\t</tr>";
    }
    $addwebsites = "\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/plus-16.png'></td>\n\t\t\t<td valign='top' {$mouse} style='font-size:12px;text-decoration:underline' \n\t\t\tOnClick=\"javascript:Loadjs('squid.visited.php?add-www=yes')\"><b><span style='font-size:12px'>{categorize_websites}</span></b><span style='font-size:12px'></td>\n\t\t</tr>\t";
    if ($users->PROXYTINY_APPLIANCE) {
        $addwebsites = null;
        $submenu = null;
    }
    $html = "\n<table style='width:100%'>\n\t<tbody>\n\t{$TR_ACCESSLOG}\n\t{$main_table}\t\n\t{$submenu}\n\t{$addwebsites}\n\t</tbody>\n\t</table>\n{$off}";
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " tpl->_ENGINE_parse_body<br>\n";
    }
    $html = $tpl->_ENGINE_parse_body($html);
    if (!$GLOBALS["AS_ROOT"]) {
        CACHE_SESSION_SET(__FUNCTION__, __FILE__, $html);
    }
}
#!/usr/bin/php -q
<?php 
$GLOBALS["DEBUG"] = false;
$GLOBALS["HERLPER_LOADED_BY_SQUID"] = true;
include_once dirname(__FILE__) . "/ressources/class.squid.familysites.inc";
include_once dirname(__FILE__) . "/ressources/class.mysql.catz.inc";
$GLOBALS["MYPID"] = getmypid();
WLOG("Starting PID:{$GLOBALS["MYPID"]}");
$GLOBALS["XVFERTSZ"] = XVFERTSZ();
$fam = new squid_familysite();
$q = new mysql_catz();
$DCOUNT = 0;
while (!feof(STDIN)) {
    $Buffer = trim(fgets(STDIN));
    if ($Buffer == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("{$DCOUNT}] LOOP::URL `{$Buffer}` is null [" . __LINE__ . "]");
        }
        continue;
    }
    if ($GLOBALS["DEBUG"]) {
        WLOG("{$DCOUNT}] LOOP::URL `{$Buffer}` [" . __LINE__ . "]");
    }
    $MAIN = explode(" ", $Buffer);
    $prefix_channel = null;
    // administrateur 192.168.1.177 3c:a9:f4:13:9b:90 - www.google.fr 57
    if (is_numeric($MAIN[0])) {
        $GLOBALS["CHANNEL"] = $MAIN[0];
        $GLOBALS["DOMAIN"] = trim($MAIN[1]);
    } else {
        $GLOBALS["DOMAIN"] = trim($MAIN[0]);
        $GLOBALS["DEBUG_MEM"] = true;
    }
    if (preg_match("#--old#", implode(" ", $argv))) {
        $GLOBALS["OLD"] = true;
    }
    if (preg_match("#--force#", implode(" ", $argv))) {
        $GLOBALS["FORCE"] = true;
    }
    if (preg_match("#--rebuild#", implode(" ", $argv))) {
        $GLOBALS["REBUILD"] = true;
    }
}
if ($GLOBALS["VERBOSE"]) {
    ini_set('display_errors', 1);
    ini_set('html_errors', 0);
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
}
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ccurl.inc';
include_once dirname(__FILE__) . '/ressources/class.ini.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
include_once dirname(__FILE__) . '/ressources/class.squid.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . "/framework/frame.class.inc";
include_once dirname(__FILE__) . '/ressources/whois/whois.main.php';
$q = new mysql_catz();
echo "Count Categories:...<br>\n";
echo $q->COUNT_CATEGORIES();
echo "<br>\n";