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);
}
Example #2
0
function move_domain(){
	$q=new mysql_squid_builder();
	$domain=$_POST["move-domain"];
	$table=$q->cat_totablename($_POST["from_cat"]);
	$q->QUERY_SQL("DELETE FROM `$table` WHERE `pattern`='$domain'");
	$q->categorize($domain, $_POST["to_cat"],true);
	
}
Example #3
0
function buildconfig()
{
    $q = new mysql_squid_builder();
    $unix = new unix();
    $dirs = $unix->dirdir("/home/ufdbcat");
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    $array["category_industry"] = "industry";
    $array["category_luxury"] = "luxury";
    $array["category_shopping"] = "shopping";
    $array["category_socialnet"] = "socialnet";
    $array["category_searchengines"] = "searchengines";
    $array["category_news"] = "news";
    $array["category_blog"] = "blog";
    $array["category_remote_control"] = "remote-control";
    $array["category_youtube"] = "youtube";
    $array["category_audio_video"] = "audio-video";
    $array["category_webtv"] = "webtv";
    $array["category_movies"] = "movies";
    $array["category_music"] = "music";
    $array["category_animals"] = "animals";
    $array["category_children"] = "children";
    $array["category_cosmetics"] = "cosmetics";
    $array["category_clothing"] = "clothing";
    $array["category_electricalapps"] = "electricalapps";
    $array["category_electronichouse"] = "electronichouse";
    $array["category_associations"] = "associations";
    $array["category_astrology"] = "astrology";
    $array["category_bicycle"] = "bicycle";
    $array["category_automobile_bikes"] = "automobile/bikes";
    $array["category_automobile_boats"] = "automobile/boats";
    $array["category_automobile_carpool"] = "automobile/carpool";
    $array["category_automobile_planes"] = "automobile/planes";
    $array["category_automobile_cars"] = "automobile/cars";
    $array["category_cleaning"] = "cleaning";
    $array["category_converters"] = "converters";
    $array["category_finance_realestate"] = "finance/realestate";
    $array["category_finance_banking"] = "finance/banking";
    $array["category_finance_insurance"] = "finance/insurance";
    $array["category_finance_moneylending"] = "finance/moneylending";
    $array["category_stockexchange"] = "stockexchange";
    $array["category_finance_other"] = "finance/other";
    $array["category_financial"] = "financial";
    $array["category_forums"] = "forums";
    $array["category_games"] = "games";
    $array["category_gamble"] = "gamble";
    $array["category_getmarried"] = "getmarried";
    $array["category_gifts"] = "gifts";
    $array["category_green"] = "green";
    $array["category_handicap"] = "handicap";
    $array["category_humanitarian"] = "humanitarian";
    $array["category_hospitals"] = "hospitals";
    $array["category_medical"] = "medical";
    $array["category_health"] = "health";
    $array["category_hobby_cooking"] = "hobby/cooking";
    $array["category_hobby_fishing"] = "hobby/fishing";
    $array["category_hobby_other"] = "hobby/other";
    $array["category_hobby_pets"] = "hobby/pets";
    $array["category_horses"] = "horses";
    $array["category_housing_accessories"] = "housing/accessories";
    $array["category_housing_builders"] = "housing/builders";
    $array["category_housing_doityourself"] = "housing/doityourself";
    $array["category_jobsearch"] = "jobsearch";
    $array["category_jobtraining"] = "jobtraining";
    $array["category_justice"] = "justice";
    $array["category_learning"] = "learning";
    $array["category_manga"] = "manga";
    $array["category_maps"] = "maps";
    $array["category_mobile_phone"] = "mobile-phone";
    $array["category_nature"] = "nature";
    $array["category_passwords"] = "passwords";
    $array["category_police"] = "police";
    $array["category_politic"] = "politic";
    $array["category_governments"] = "governments";
    $array["category_recreation_humor"] = "recreation/humor";
    $array["category_recreation_schools"] = "recreation/schools";
    $array["category_recreation_sports"] = "recreation/sports";
    $array["category_recreation_travel"] = "recreation/travel";
    $array["category_recreation_nightout"] = "recreation/nightout";
    $array["category_recreation_wellness"] = "recreation/wellness";
    $array["category_models"] = "models";
    $array["category_celebrity"] = "celebrity";
    $array["category_womanbrand"] = "womanbrand";
    $array["category_science_astronomy"] = "science/astronomy";
    $array["category_science_chemistry"] = "science/chemistry";
    $array["category_science_computing"] = "science/computing";
    $array["category_science_weather"] = "science/weather";
    $array["category_culture"] = "culture";
    $array["category_sciences"] = "sciences";
    $array["category_literature"] = "literature";
    $array["category_smallads"] = "smallads";
    $array["category_houseads"] = "houseads";
    $array["category_tattooing"] = "tattooing";
    $array["category_teens"] = "teens";
    $array["category_terrorism"] = "terrorism";
    $array["category_translators"] = "translators";
    $array["category_transport"] = "transport";
    $array["category_tricheur"] = "tricheur";
    $array["category_updatesites"] = "updatesites";
    $array["category_webmail"] = "webmail";
    $array["category_chat"] = "chat";
    $array["category_meetings"] = "meetings";
    $array["category_webapps"] = "webapps";
    $array["category_webplugins"] = "webplugins";
    $array["category_browsersplugins"] = "browsersplugins";
    $array["category_webphone"] = "webphone";
    $array["category_wine"] = "wine";
    $array["category_tobacco"] = "tobacco";
    $array["category_alcohol"] = "alcohol";
    $array["category_drugs"] = "drugs";
    $array["category_books"] = "books";
    $array["category_dictionaries"] = "dictionaries";
    $array["category_photo"] = "photo";
    $array["category_pictureslib"] = "pictureslib";
    $array["category_imagehosting"] = "imagehosting";
    $array["category_downloads"] = "downloads";
    $array["category_filehosting"] = "filehosting";
    $array["category_society"] = "society";
    $array["category_hobby_arts"] = "hobby/arts";
    $array["category_webradio"] = "webradio";
    $array["category_genealogy"] = "genealogy";
    $array["category_paytosurf"] = "paytosurf";
    $array["category_religion"] = "religion";
    $array["category_abortion"] = "abortion";
    $array["category_sect"] = "sect";
    $array["category_suspicious"] = "suspicious";
    $array["category_warez"] = "warez";
    $array["category_hacking"] = "hacking";
    $array["category_proxy"] = "proxy";
    $array["category_porn"] = "p**n";
    $array["category_dating"] = "dating";
    $array["category_mixed_adult"] = "mixed_adult";
    $array["category_sex_lingerie"] = "sex/lingerie";
    $array["category_sexual_education"] = "sexual_education";
    $array["category_marketingware"] = "marketingware";
    $array["category_publicite"] = "publicite";
    $array["category_tracker"] = "tracker";
    $array["category_mailing"] = "mailing";
    $array["category_redirector"] = "redirector";
    $array["category_violence"] = "violence";
    $array["category_spyware"] = "spyware";
    $array["category_malware"] = "malware";
    $array["category_phishing"] = "phishing";
    $array["category_dangerous_material"] = "dangerous_material";
    $array["category_weapons"] = "weapons";
    $array["category_internal"] = "internal";
    $array["category_dynamic"] = "dynamic";
    $array["category_isp"] = "isp";
    $array["category_sslsites"] = "sslsites";
    $array["category_reaffected"] = "reaffected";
    $array["category_arjel"] = "arjel";
    $array["category_bitcoin"] = "bitcoin";
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM personal_categories";
    $results = $q->QUERY_SQL($sql);
    $main_path = "/var/lib/squidguard";
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $category = $ligne["category"];
        $category_table = $q->cat_totablename($category);
        $table = "category_" . $q->category_transform_name($category);
        $categorynamePerso = TransFormCategoryName($category);
        $categorynamePersoBAse = "{$main_path}/{$categorynamePerso}";
        $categorynamePersoPathBase = "{$categorynamePersoBAse}/domains.ufdb";
        $categorynamePersoPathUrls = "{$categorynamePersoBAse}/urls";
        $TARGET_DIR = "/home/ufdbcat/PERSO_{$categorynamePerso}";
        $TARGET_DB = "/home/ufdbcat/PERSO_{$categorynamePerso}/domains.ufdb";
        if (is_file($categorynamePersoPathBase)) {
            @mkdir($TARGET_DIR, 0755, true);
            $size = @filesize($categorynamePersoPathBase);
            $md51 = md5_file($categorynamePersoPathBase);
            $md52 = md5_file($TARGET_DB);
            if ($md51 != $md52) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Duplicate personal database {$category}\n";
                }
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$categorynamePersoPathBase}: {$md51}\n";
                }
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$TARGET_DB}: {$md52}\n";
                }
                @unlink($TARGET_DB);
                if (!@copy($categorynamePersoPathBase, $TARGET_DB)) {
                    if ($GLOBALS["OUTPUT"]) {
                        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Duplicate personal database {$category} [!FAILED]\n";
                    }
                }
                @touch("{$TARGET_DIR}/urls");
                @touch("{$TARGET_DIR}/expressions");
                $md52 = md5_file($TARGET_DB);
                $size2 = @filesize($TARGET_DB);
                if ($md51 != $md52) {
                    if ($GLOBALS["OUTPUT"]) {
                        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Duplicate personal database {$category} [!FAILED]\n";
                    }
                }
                if ($size != $size2) {
                    if ($GLOBALS["OUTPUT"]) {
                        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Duplicate personal database {$category} [!FAILED]\n";
                    }
                }
            } else {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Personal database {$category} [OK]\n";
                }
            }
            $cats[] = "P{$category}";
            $catz[] = "category \"P{$category}\" {";
            $catz[] = "\tdomainlist      \"{$TARGET_DIR}/domains\"";
            $catz[] = "\texpressionlist  \"{$TARGET_DIR}/expressions\"";
            $catz[] = "\tredirect        \"http://none/{$category}\"";
            $catz[] = "}";
        }
    }
    $c = 0;
    while (list($dirname, $realcat) = each($array)) {
        $ADDEDART = false;
        if (is_file("/home/ufdbcat/{$dirname}/domains.ufdb")) {
            $size = filesize("/home/ufdbcat/{$dirname}/domains.ufdb");
            if ($size > 150) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$dirname} {$size} Bytes\n";
                }
                $c++;
                if (!is_file("/home/ufdbcat/{$dirname}/expressions")) {
                    @touch("/home/ufdbcat/{$dirname}/expressions");
                }
                $cats[] = $dirname;
                $catz[] = "category \"{$dirname}\" {";
                $catz[] = "\tdomainlist      \"{$dirname}/domains\"";
                $catz[] = "\texpressionlist  \"{$dirname}/expressions\"";
                $catz[] = "\tredirect        \"http://none/{$realcat}\"";
                $catz[] = "}";
                $ADDEDART = true;
            }
        }
        if (!$ADDEDART) {
            if (is_file("/home/ufdbcat/TLSE_{$realcat}/domains.ufdb")) {
                if (!is_file("/home/ufdbcat/TLSE_{$realcat}/expressions")) {
                    @touch("/home/ufdbcat/TLSE_{$realcat}/expressions");
                }
                $cats[] = "T{$realcat}";
                $catz[] = "category \"T{$realcat}\" {";
                $catz[] = "\tdomainlist      \"TLSE_{$realcat}/domains\"";
                $catz[] = "\texpressionlist  \"TLSE_{$realcat}/expressions\"";
                $catz[] = "\tredirect        \"http://none/{$realcat}\"";
                $catz[] = "}";
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$c} added categories\n";
    }
    $f[] = "dbhome \"/home/ufdbcat\"";
    $f[] = "logdir \"/var/log/ufdbcat\"";
    $f[] = "logblock off";
    $f[] = "logpass off";
    $f[] = "logall off";
    $f[] = "url-lookup-result-during-database-reload deny";
    $f[] = "url-lookup-result-when-fatal-error deny";
    $f[] = "analyse-uncategorised-urls off";
    $EnableLocalUfdbCatService = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableLocalUfdbCatService"));
    if ($AsCategoriesAppliance == 1) {
        $EnableLocalUfdbCatService = 1;
    }
    if ($EnableLocalUfdbCatService == 1) {
        $ufdbCatInterface = @file_get_contents("/etc/artica-postfix/settings/Daemons/ufdbCatInterface");
        if ($ufdbCatInterface != null) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Checking interface \"{$ufdbCatInterface}\"\n";
            }
            if (!$unix->is_interface_available($ufdbCatInterface)) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$ufdbCatInterface} not available\n";
                }
            } else {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$ufdbCatInterface} is available\n";
                }
            }
        }
        $ufdbCatPort = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/ufdbCatPort"));
        if ($ufdbCatPort == 0) {
            $ufdbCatPort = 3978;
        }
        if ($ufdbCatInterface == null) {
            $ufdbCatInterface = "all";
        }
        $f[] = "port {$ufdbCatPort}";
        $f[] = "interface {$ufdbCatInterface}";
    }
    $f[] = "check-proxy-tunnels off";
    $f[] = "safe-search off";
    $f[] = "youtube-edufilter    off";
    $f[] = "max-logfile-size  200000000";
    $f[] = "# refreshuserlist 15";
    $f[] = "# refreshdomainlist 15";
    $f[] = "source allSystems {";
    $f[] = "   ip  0.0.0.0/0  ";
    $f[] = "}";
    $categories = @implode(" !", $cats);
    if (!is_file("/home/ufdbcat/security/cacerts")) {
        @mkdir("/home/ufdbcat/security");
        if (!is_file("/home/ufdbcat/security/cacerts")) {
            @touch("/home/ufdbcat/security/cacerts");
        }
    }
    $f[] = "category security {";
    $cats[] = "\tcacerts \"/home/ufdbcat/security/cacerts\"";
    $f[] = "\toption  enforce-https-with-hostname off";
    $f[] = "\toption  enforce-https-official-certificate off";
    $f[] = "\toption  https-prohibit-insecure-sslv2 off";
    $f[] = "\toption \tallow-aim-over-https off";
    $f[] = "\toption \tallow-gtalk-over-https off";
    $f[] = "\toption \tallow-skype-over-https off";
    $f[] = "\toption \tallow-yahoomsg-over-https off";
    $f[] = "\toption \tallow-fb-chat-over-https off";
    $f[] = "\toption \tallow-citrixonline-over-https off";
    $f[] = "\toption \tallow-unknown-protocol-over-https off";
    $f[] = "}";
    $f[] = "";
    $f[] = "";
    $f[] = @implode("\n", $catz);
    $f[] = "";
    $f[] = "";
    $f[] = "acl {";
    $f[] = "\tallSystems  {";
    $f[] = "\t\tpass !{$categories} any";
    $f[] = "\t}";
    $f[] = "";
    $f[] = "\t\tdefault {";
    $f[] = "\tpass !{$categories} any";
    $f[] = "\tredirect        \"http://cgibin.urlfilterdb.com/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u\"";
    $f[] = "\t}";
    $f[] = "}";
    @file_put_contents("/etc/ufdbcat/ufdbGuard.conf", @implode("\n", $f));
    @unlink("/usr/share/squid3/categories_caches.db");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/ufdbcat/ufdbGuard.conf done\n";
    }
}
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);
}
function category_search()
{
    $t = time();
    ini_set('display_errors', 1);
    ini_set('error_prepend_string', "<p class=text-error>");
    ini_set('error_append_string', "</p>\n");
    $q = new mysql_squid_builder();
    $users = new usersMenus();
    $boot = new boostrap_form();
    $page = CurrentPageName();
    $tpl = new templates();
    $ORDER = $boot->TableOrder(array("pattern" => "ASC"));
    $searchstring = string_to_flexquery("category-search");
    $table = $q->cat_totablename($_GET["category"]);
    $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} ORDER BY {$ORDER} LIMIT 0,250";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<p class=text-error>{$q->mysql_error}<hr>{$sql}</p>\n";
    }
    $tr = array();
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $date = $boot->time_to_date(strtotime($ligne['zDate']), true);
        $md5 = md5(serialize($ligne));
        $pattern = $ligne["pattern"];
        $delete = imgsimple("delete-32.png", null, "Delete{$t}('{$pattern}','{$md5}')");
        $tr[] = "\n\t\t<tr id='{$md5}'>\n\t\t<td style='font-size:18px' nowrap  width=1% nowrap>{$date}</td>\n\t\t<td style='font-size:18px' nowrap >{$pattern}</td>\n\t\t<td style='font-size:18px' nowrap width=1% >{$delete}</td>\n\t\t</tr>";
    }
    echo $boot->TableCompile(array("zDate" => "{date}", "pattern" => "{sitename}", "delete" => "{delete}"), $tr) . "\n\t\t\t\t\t\n<script>\nvar id{$t}='';\n\tvar xDelete{$t}= function (obj) {\n\t\tvar res=obj.responseText;\n\t\tif (res.length>3){alert(res);return;}\n\t\t\$('#'+id{$t}).remove();\n\t\t\n\t}\n\nfunction Delete{$t}(www,md){\n\tid{$t}=md;\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('www-delete',www);\n\tXHR.appendData('category','{$_GET["category"]}');\n\tXHR.sendAndLoad('{$page}', 'POST',xDelete{$t});\t\t\n}\n</script>";
}
Example #6
0
include_once dirname(__FILE__) . '/framework/class.settings.inc';
//error_reporting(0);
if (preg_match("#--verbose#", @implode(" ", $argv))) {
    ini_set('display_errors', 1);
    ini_set('html_errors', 0);
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
    error_reporting(1);
    error_reporting(1);
    $GLOBALS["VERBOSE"] = true;
    echo "VERBOSED MODE\n";
}
$category = $argv[1];
$categorynamePersoPathBaseDOM = $argv[2];
$q = new mysql_squid_builder();
$category_table = $q->cat_totablename($category);
if (!preg_match("#^category_.*#", $category_table)) {
    $category_table = "category_{$category}";
    if (!$q->TABLE_EXISTS($category_table)) {
        compile($categorynamePersoPathBaseDOM);
        die(0);
    }
}
$sql = "SELECT pattern FROM `{$category_table}` ORDER BY pattern";
$results = $q->QUERY_SQL($sql);
if (!$q->ok) {
    die(0);
}
if (@mysql_num_rows($results) == 0) {
    compile($categorynamePersoPathBaseDOM);
    die(0);