@unlink($targetFile); } } $BaseWorkDir = "/usr/share/artica-postfix/ressources/interface-cache"; if ($handle = opendir($BaseWorkDir)) { while (false !== ($filename = readdir($handle))) { if ($filename == ".") { continue; } if ($filename == "..") { continue; } $targetFile = "{$BaseWorkDir}/{$filename}"; if (is_dir($targetFile)) { continue; } @unlink($targetFile); } } include_once dirname(__FILE__) . "/ressources/class.mysql.squid.builder.php"; $q = new mysql_squid_builder(); $q->QUERY_SQL("DROP TABLE webfilters_categories_caches"); $q->create_webfilters_categories_caches(); $q = new mysql(); $q->QUERY_SQL("UPDATE setup_center SET CODE_NAME_STRING='',CODE_NAME_ABOUT=''", 'artica_backup'); $tpl = new templates(); $html = $tpl->javascript_parse_text($text, 1); $html = str_replace("\n", "<br>", $html); echo "<div class=explain style='font-size:14px'>" . $html . "</div>"; $sock = new sockets(); $sock->getFrameWork("services.php?cache-pages=yes");
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.: " . numberFormat($items, 0, "", " "); $ITEMS_COLONE[] = "{$ProductName}: " . 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 = " "; } $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: " . 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 blacklist() { $page = CurrentPageName(); $tpl = new templates(); $t = time(); $main_filter_rule_edit = null; $q = new mysql_squid_builder(); if (!$q->TABLE_EXISTS("webfilters_categories_caches")) { $q->CheckTables(); } if (isset($_GET["main_filter_rule_edit"])) { $main_filter_rule_edit = "&main_filter_rule_edit=yes"; } $sql = "SELECT master_category FROM webfilters_categories_caches GROUP BY master_category"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { if (preg_match("#does.*?exist#", $q->mysql_error)) { $q->create_webfilters_categories_caches(); if (!$q->ok) { $create_webfilters_categories_caches = "webfilters_categories_caches error while creating the table {$q->mysql_error}<br>"; } $results = $q->QUERY_SQL($sql); $create_webfilters_categories_caches = "{$create_webfilters_categories_caches} after webfilters_categories_caches created...<br>"; if (class_exists("dansguardian_rules")) { $dans = new dansguardian_rules(); $dans->CategoriesTableCache(); } } } if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2><code style='font-size:11px'>{$create_webfilters_categories_caches}{$sql}</code>"; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $catsz = $ligne["master_category"]; $butts[$catsz] = $catsz; } $butts[null] = "{all}"; $field = Field_array_Hash($butts, "CatzByGroup-{$t}", null, "RefreshBlackListTable()", null, 0, "font-size:10px"); $onlyEnabled = Field_checkbox("CatzByEnabled-{$t}", 1, 0, "RefreshBlackListTable()"); $html = "\n\t<div id='blacklist-js-generator-{$t}'></div>\n\t\n\t<script>\n\t\tfunction RefreshBlackListTable(){\n\t\t\tvar CatzByEnabled='';\n\t\t\t\$('#blacklist-table-1').remove();\n\t\t\t\$('#blacklist-table-2').remove();\n\t\t\tLoadAjax('blacklist-js-generator-{$t}','{$page}?blacklist-js=yes&t={$t}{$main_filter_rule_edit}&RULEID={$_GET["RULEID"]}&TimeID={$_GET["TimeID"]}&ID={$_GET["RULEID"]}&modeblk={$_GET["modeblk"]}&QuotaID={$_GET["QuotaID"]}');\n\t\t\t}\n\t\t\t\n\tvar x_EnableDisableCategoryRule{$t}= function (obj) {\n\t\tvar res=obj.responseText;\n\t\tif (res.length>3){alert(res);}\n\t\tif(document.getElementById('WebFilteringMainTableID') ){ \$('#'+document.getElementById('WebFilteringMainTableID').value).flexReload(); }\n\t\tif(document.getElementById('blacklist-table-by-rule') ){ \$('#'+document.getElementById('blacklist-table-by-rule').value).flexReload(); }\n\t\tif(document.getElementById('SQUID_ARTICA_QUOTA_RULES') ){ \$('#'+document.getElementById('SQUID_ARTICA_QUOTA_RULES').value).flexReload(); }\n\t}\t\t\t\n\t\n\t\n\tfunction EnableDisableCategoryRule(categorykey,RULEID,modeblk){\n\t\tvar XHR = new XHRConnection();\n\t\tvar idname='cats_'+RULEID+'_'+modeblk+'_'+categorykey;\n\t\tXHR.appendData('EnableDisableCategoryRule','yes');\n\t\tXHR.appendData('categorykey',categorykey);\n\t\tXHR.appendData('modeblk',modeblk);\n\t\tXHR.appendData('RULEID',RULEID);\n\t\tXHR.appendData('TimeID','{$_GET["TimeID"]}');\n\t\tXHR.appendData('QuotaID','{$_GET["QuotaID"]}');\n\t\tif(document.getElementById(idname).checked){\n\t\tXHR.appendData('enabled',1);}else{XHR.appendData('enabled',0);}\n\t\tXHR.sendAndLoad('{$page}', 'POST',x_EnableDisableCategoryRule{$t});\t\n\t}\t\t\t\n\t\t\t\n\t\t\t\n\tRefreshBlackListTable();\n\t</script>\n\t"; echo $tpl->_ENGINE_parse_body($html); }
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); }