function CategorizeAWebSite($www, $category) { $md5 = md5($www . $category); $q = new mysql_squid_builder(); $q->CheckTables(); $uuid = $GLOBALS["UUID"]; $category_table = $q->category_transform_name($category); $sql_add = "INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $sql_add2 = "INSERT IGNORE INTO category_{$category_table} (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $q->QUERY_SQL($sql_add); if (!$q->ok) { echo $q->mysql_error . "\n{$sql_add}\n"; return false; } $q->QUERY_SQL($sql_add2); if (!$q->ok) { echo $q->mysql_error . "\n{$sql_add2}\n"; return false; } $categories = $q->GET_CATEGORIES($www, true); if ($categories != null) { $sql = "UPDATE visited_sites SET category='{$categories}' WHERE sitename='{$www}'"; $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n{$sql}\n"; return false; } } }
function export_category($category) { $q = new mysql_squid_builder(); echo "Exporting {$category}\n"; if (!preg_match("#^category_.+?#", $category)) { $table = "category_" . $q->category_transform_name($category); } else { $table = $category; } $t = time(); $dirtmp = "/tmp/categories_{$t}"; $Finaldir = "/root/categories"; @mkdir($dirtmp); @mkdir($Finaldir); shell_exec("/bin/chmod 777 -R {$dirtmp}"); $sql = "SELECT zmd5,zDate,category,pattern,uuid FROM {$table} WHERE enabled=1 ORDER BY pattern\n\tINTO OUTFILE '{$dirtmp}/{$table}.csv'\n\tFIELDS TERMINATED BY ','\n\tENCLOSED BY '\"'\n\tLINES TERMINATED BY '\\n'"; $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n"; } if (!is_file("{$dirtmp}/{$table}.csv")) { echo "{$dirtmp}/{$table}.csv no such file\n"; return; } echo "{$dirtmp}/{$table}.csv success\n"; compress("{$dirtmp}/{$table}.csv", "{$dirtmp}/{$table}.csv.gz"); if (!is_file("{$dirtmp}/{$table}.csv.gz")) { echo "Failed {$dirtmp}/{$table}.csv.gz no such file\n"; return; } @unlink("{$dirtmp}/{$table}.csv"); echo "Success {$dirtmp}/{$table}.csv.gz\n"; copy("{$dirtmp}/{$table}.csv.gz", "{$Finaldir}/{$table}.csv.gz"); @unlink("{$dirtmp}/{$table}.csv.gz"); }
function download() { $category = $_GET["category"]; header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename={$category}.csv"); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 header("Pragma: no-cache"); // HTTP 1.0 header("Expires: 0"); // Proxies $q = new mysql_squid_builder(); $table = "category_" . $q->category_transform_name($category); $sql = "SELECT * FROM {$table} ORDER BY `pattern`"; $results = $q->QUERY_SQL($sql); $f[] = array("Date", "Website"); while ($ligne = mysql_fetch_assoc($results)) { $f[] = array($ligne['zDate'], $ligne["pattern"]); } outputCSV($f); }
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 CategorizeAll_perform() { if ($_GET["pattern"] == null) { return; } $sock = new sockets(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); if ($uuid == null) { echo "UUID=NULL; Aborting"; return; } $pattern = " AND sitename LIKE '%{$_GET["pattern"]}%' "; $pattern = str_replace("*", "%", $pattern); $sql = "SELECT sitename FROM `visited_sites` WHERE LENGTH( `category` )=0 {$pattern}"; $category = $_GET["CategorizeAll_category"]; if ($category == null) { return; } $q = new mysql_squid_builder(); $results = $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { echo $q->mysql_error . "\n" . basename(__FILE__) . "\nLine" . __LINE__; return; } $category_table = "category_" . $q->category_transform_name($category); if (!$q->TABLE_EXISTS($category_table)) { $q->CreateCategoryTable($category); } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $website = $ligne["sitename"]; if ($website == null) { return; } $www = trim(strtolower($website)); if (preg_match("#^www\\.(.+?)\$#i", trim($www), $re)) { $www = $re[1]; } $md5 = md5($www . $category); $enabled = 1; if ($www == null) { echo "Alert: website is null...\n"; return; } $sql_add = "INSERT INTO {$category_table} (zmd5,zDate,category,pattern,uuid,enabled) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}',1)"; $q->QUERY_SQL($sql_add); if (!$q->ok) { echo $q->mysql_error . "\n" . basename(__FILE__) . "\nLine" . __LINE__ . "\n"; echo $sql; return; } $sql = "INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n" . basename(__FILE__) . "\nLine" . __LINE__ . "\n"; echo $sql; return; } if ($_GET["day"] != null) { $time = strtotime($_GET["day"] . " 00:00:00"); $tableSrc = date('Ymd') . "_hour"; $categories = $q->GET_CATEGORIES($www, true); $q->QUERY_SQL("UPDATE {$tableSrc} SET category='{$categories}' WHERE sitename='{$www}'"); } } $sql = "UPDATE `visited_sites` SET `category`='{$category}' WHERE LENGTH( `category` )=0 {$pattern}"; $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n" . basename(__FILE__) . "\nLine" . __LINE__ . "\n"; echo $sql; return; } $sock = new sockets(); $sock->getFrameWork("cmd.php?export-community-categories=yes"); }
function query(){ $category=null; $tpl=new templates(); $also=$tpl->_ENGINE_parse_body("{also}"); $MyPage=CurrentPageName(); $q=new mysql_squid_builder(); $nowebsites=$tpl->_ENGINE_parse_body("{no_saved_web_site_catz}"); writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__); if($category==null){if($_GET["category"]<>null){$category=$_GET["category"];}} if($category==null){if($_POST["qtype"]<>null){$category=$_POST["qtype"];}} if($_POST["query"]<>null){if($_GET["website"]<>null){$_POST["query"]=$_GET["website"];}} if($category==null){json_error_show("Please select a category first");} if($_POST["sortname"]=="sitename"){$_POST["sortname"]="zDate";$_POST["sortorder"]="desc";} writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__); $table="categoryuris_".$q->category_transform_name($category); $CategoriesCheckRightsWrite=CategoriesCheckRightsWrite(); $q->CreateCategoryUrisTable(null,$table); $search='%'; $page=1; $COUNT_ROWS=$q->COUNT_ROWS($table); if($COUNT_ROWS==0){json_error_show("no data",1);} if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}} if (isset($_POST['page'])) {$page = $_POST['page'];} $searchstring=string_to_flexquery(); if($searchstring<>null){ $sql="SELECT COUNT(zmd5) as TCOUNT FROM `$table` WHERE 1 $searchstring"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup")); $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 zDate,zmd5,pattern,enabled FROM `$table` WHERE 1 $searchstring $ORDER $limitSql"; $results = $q->QUERY_SQL($sql); if(!$q->ok){json_error_show($q->mysql_error,1);} if(mysql_num_rows($results)==0){json_error_show("$nowebsites",1);} $disabled_text=$tpl->_ENGINE_parse_body("{disabled}"); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); while ($ligne = mysql_fetch_assoc($results)) { $delete=imgtootltip("delete-24.png","{delete}","DeleteCategorizedURI('{$ligne["zmd5"]}','$table')"); $enabled=$ligne["enabled"]; $color="color:black"; if($enabled==0){ $color="color:#B6ACAC"; $added=$added."<div><i style='font-size:11px'>$disabled_text</i></div>"; $moveAll=" "; $move=" "; } $jscat="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\" style='font-size:14px;text-decoration:underline;$color'>"; if(!$CategoriesCheckRightsWrite){ $jscat=null; $delete=null; } $data['rows'][] = array( 'id' => $ligne['zmd5'], 'cell' => array(" <span style='font-size:14px;$color'>{$ligne['zDate']}</span>", "<span style='font-size:14px;$color'>$jscat{$ligne['pattern']}</a></span>$added",$delete) ); } echo json_encode($data); }
function include_tpl_file($path, $category) { $sock = new sockets(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); if ($uuid == null) { echo "UUID=NULL; Aborting"; return; } if ($category == null) { echo "CATEGORY=NULL; Aborting"; return; } if (!is_file($path)) { echo "{$path} no such file\n"; return; } $q = new mysql_squid_builder(); $q->CreateCategoryTable($category); $TableDest = "category_" . $q->category_transform_name($category); $array = array(); $f = @explode("\n", @file_get_contents($path)); $count_websites = count($f); $i = 0; $d = 0; $group = 0; $prefix = "INSERT IGNORE INTO {$TableDest} (zmd5,zDate,category,pattern,uuid) VALUES"; while (list($index, $website) = each($f)) { $i++; $d++; if ($d > 1000) { $group = $group + $d; events_tail("include_tpl_file({$category}):: importing {$group} sites..."); $d = 0; } if ($website == null) { return; } $www = trim(strtolower($website)); if (preg_match("#www\\.(.+?)\$#i", $www, $re)) { $www = $re[1]; } $md5 = md5($www . $category); if ($array[$md5]) { echo "{$www} already exists\n"; continue; } $enabled = 1; $sql_add[] = "('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $array[$md5] = true; if ($GLOBALS["SIMULATE"]) { echo "{$i}/{$count_websites}: {$sql_add}\n"; continue; } if (count($sql_add) > 500) { $sql = $prefix . @implode(",", $sql_add); $q->QUERY_SQL($sql); if (!$q->ok) { echo "{$i}/{$count_websites} Failed: {$www}\n"; } else { echo "{$i}/{$count_websites} Success: {$www}\n"; } $sql_add = array(); } } if (count($sql_add) > 0) { $sql = $prefix . @implode(",", $sql_add); $q->QUERY_SQL($sql); if (!$q->ok) { echo "{$i}/{$count_websites} Failed: {$www}\n"; } else { echo "{$i}/{$count_websites} Success: {$www}\n"; } $sql_add = array(); } echo " -------------------------------------------------\n"; echo count($array) . " websites done\n"; echo " -------------------------------------------------\n"; }
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 Execute() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $myFile = basename(__FILE__); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, $myFile)) { WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__); die; } $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("framework_orders") == 0) { if ($GLOBALS["VERBOSE"]) { echo "Table framework_orders as no row\n"; } die; } $php5 = $unix->LOCATE_PHP5_BIN(); $nice = EXEC_NICE(); $q = new mysql_squid_builder(); $results = $q->QUERY_SQL("SELECT * FROM framework_orders"); if (!$q->ok) { if (strpos($q->mysql_error, "doesn't exist") > 0) { $q->CheckTables(); $results = $q->QUERY_SQL("SELECT * FROM framework_orders"); } } if (!$q->ok) { ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework"); die; } $reconfigure_plugins = false; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($GLOBALS["VERBOSE"]) { echo "ORDER: {$ligne["ORDER"]} -> {$ligne["zmd5"]}\n"; } if (preg_match("#COMPILEDB:(.+)#", $ligne["ORDER"], $re)) { if (preg_match("#english-(.+)#", $re[1])) { $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'"); continue; } ufdbguard_admin_events("LAUNCH: category {$re[1]} compilation", __FUNCTION__, __FILE__, __LINE__, "framework"); $re[1] = trim($re[1]); $table = "category_" . $q->category_transform_name($re[1]); if ($GLOBALS["VERBOSE"]) { echo "order to compile database {$re[1]} (table {$table})\n"; } if (!$q->TABLE_EXISTS($table)) { ufdbguard_admin_events("Fatal: {$table} no suche table, create it", __FUNCTION__, __FILE__, __LINE__, "framework"); $q->CreateCategoryTable(null, $table); } $cmd = "{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --compile-category \"{$re[1]}\""; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'"); if (!$q->ok) { ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework"); die; } shell_exec($cmd); $reconfigure_plugins = true; } } if ($reconfigure_plugins) { ufdbguard_admin_events("LAUNCH: filters reconfiguration", __FUNCTION__, __FILE__, __LINE__, "framework"); shell_exec("{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --build"); } }
function www_delete() { ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); ini_set('error_prepend_string', "<p class=text-error>"); ini_set('error_append_string', "</p>\n"); $q = new mysql_squid_builder(); $category_table = "category_" . $q->category_transform_name($_POST["category"]); $q->QUERY_SQL("DELETE FROM {$category_table} WHERE pattern='{$_POST["www-delete"]}'"); $q->categorize_logs($_POST["category"], "{delete}", $_POST["www-delete"]); if (!$q->ok) { echo $q->mysql_error; } }
function WriteCategory($category) { $squidguard = new squidguard(); $q = new mysql_squid_builder(); echo "Starting......: " . date("H:i:s") . " Artica database writing category {$category}\n"; echo "Starting......: " . date("H:i:s") . " Artica database /etc/dansguardian/lists/blacklist-artica/{$category}/domains\n"; echo "Starting......: " . date("H:i:s") . " Artica database /var/lib/squidguard/blacklist-artica/{$category}\n"; @mkdir("/etc/dansguardian/lists/blacklist-artica/{$category}", 0755, true); @mkdir("/var/lib/squidguard/blacklist-artica/{$category}", 0755, true); if (!is_dir("/var/lib/squidguard/{$category}")) { @mkdir("/var/lib/squidguard/{$category}", 0755, true); } if (!is_dir("/etc/dansguardian/lists/blacklist/{$category}/urls")) { @mkdir("/etc/dansguardian/lists/blacklist/{$category}/urls", 755, true); } if (!is_file("/etc/dansguardian/lists/blacklist/{$category}/urls")) { @file_put_contents("/etc/dansguardian/lists/blacklist/{$category}/urls", "\n"); } if (!is_file("/var/lib/squidguard/{$category}/urls")) { @file_put_contents("/var/lib/squidguard/{$category}/urls", "\n"); } $tablesource = "category_" . $q->category_transform_name($category); $sql = "SELECT pattern FROM {$tablesource} WHERE enabled=1"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " Artica database {$q->mysql_error}\n"; return; } $num = mysql_num_rows($results); echo "Starting......: " . date("H:i:s") . " Artica database {$num} domains\n"; $domain_path_1 = "/etc/dansguardian/lists/blacklist/{$category}/domains"; $domain_path_2 = "/var/lib/squidguard/{$category}/domains"; $fh1 = fopen($domain_path_1, 'w+'); $fh2 = fopen($domain_path_2, 'w+'); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["pattern"] == null) { continue; } if (!$squidguard->VerifyDomainCompiledPattern($ligne["pattern"])) { continue; } fwrite($fh1, $ligne["pattern"] . "\n"); fwrite($fh2, $ligne["pattern"] . "\n"); } fclose($fh1); fclose($fh2); echo "Starting......: " . date("H:i:s") . " finish\n\n"; }
function inject_sql($srcfilename, $filename, $categoriesTable) { if (trim($categoriesTable) == null) { ufdbguard_admin_events("Fatal : no category table passed to function with the filename:{$filename}, aborting process", __FUNCTION__, __FILE__, __LINE__, "update"); return; } $datas = explode("\n", @file_get_contents($filename)); echo "Processing {$filename} " . count($datas) . " rows\n"; if (!is_array($datas)) { $GLOBALS["MAILLOG"][] = __LINE__ . ") {$filename} no elements"; UpdateCategories($srcfilename, 30, "{corrupted}", 0); } $c = 0; $d = 0; $t1 = time(); $unix = new unix(); $count = count($datas); $q = new mysql_squid_builder(); $q->CreateCategoryTable($categoriesTable); $categoriesTable = $q->category_transform_name($categoriesTable); $prefix = "INSERT IGNORE INTO category_{$categoriesTable} (zmd5,zDate,category,pattern,uuid,sended) VALUES"; $suffixR = array(); while (list($index, $row) = each($datas)) { if (trim($row) == null) { continue; } $ligne = unserialize($row); if (strlen($ligne["category"]) == 1) { continue; } $suffixR[] = "('{$ligne["zmd5"]}','{$ligne["zDate"]}','{$ligne["category"]}','{$ligne["pattern"]}','{$ligne["uuid"]}',1)"; $c++; if (count($suffixR) > 50) { $pourc = round($c / $count * 100); if ($pourc > 30) { UpdateCategories($srcfilename, $pourc, "{importing}", 0); if (system_is_overloaded(basename(__FILE__))) { echo "Overloaded, waiting 30s\n"; $ldao = getSystemLoad(); $GLOBALS["MAILLOG"][] = __LINE__ . ") Overloaded ({$ldao}),waiting 30s..."; sleep(30); } if (system_is_overloaded(basename(__FILE__))) { UpdateCategories($srcfilename, $pourc, "{overloaded}", 0); echo "Overloaded, die...\n"; $ldao = getSystemLoad(); $GLOBALS["MAILLOG"][] = __LINE__ . ") Overloaded,{$ldao} die..."; ufdbguard_admin_events("{$categoriesTable}: processing black list {$srcfilename} database injection aborted System is overloaded ({$ldao}), the processing will be aborted and restart in next cycle\n\t\t\t\t\tTask stopped line {$c}/{$count} rows\n", __FUNCTION__, __FILE__, __LINE__, "update"); die; } } $suffix = @implode(",", $suffixR); $sql = "{$prefix} {$suffix}"; $suffixR = array(); $q = new mysql_squid_builder(); $q->QUERY_SQL($sql); if (!$q->ok) { ufdbguard_admin_events("{$categoriesTable}: Fatal error {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "update"); UpdateCategories($srcfilename, 30, "{sql_error}", 0); return; } usleep(500000); } } if (count($suffixR) > 0) { $suffix = @implode(",", $suffixR); $sql = "{$prefix} {$suffix}"; $q = new mysql_squid_builder(); $q->QUERY_SQL($sql); } ufdbguard_admin_events("{$categoriesTable}: Success importing {$c} elements in " . $unix->distanceOfTimeInWords($t1, time()), __FUNCTION__, __FILE__, __LINE__, "update"); $GLOBALS["MAILLOG"][] = __LINE__ . ") Success importing {$c} elements in " . $unix->distanceOfTimeInWords($t1, time()); UpdateCategories($srcfilename, 100, "{success}", 1); }
function rangetables() { $q = new mysql_squid_builder(); $tables = $q->LIST_TABLES_CATEGORIES(); while (list($table, $none) = each($tables)) { $sql = "SELECT category FROM {$table} GROUP BY category"; $results = $q->QUERY_SQL($sql); if (mysql_numrows($results) == 1) { continue; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if (trim($ligne["category"]) == null) { continue; } $sourceCategory = $ligne["category"]; if ($ligne["category"] == "category_publicite") { $ligne["category"] = "publicite"; } if ($ligne["category"] == "category_automobile_") { $ligne["category"] = "automobile/cars"; } if ($ligne["category"] == "category_finance_oth") { $ligne["category"] = "finance/other"; } if ($ligne["category"] == "category_recreation_") { $ligne["category"] = "recreation/travel"; } echo "Found category `{$ligne["category"]}`\n"; $destTable = "category_" . $q->category_transform_name($ligne["category"]); $destTable = str_replace("category_category_", "category_", $destTable); if (trim($destTable) == trim($table)) { continue; } echo "Move from {$table}: Category {$ligne["category"]} to table {$destTable}\n"; $sql = "INSERT IGNORE INTO {$destTable} (`zmd5`,`zDate`,`category`,`pattern`,`enabled`,`uuid`,`sended`) \n\t\t\tSELECT zmd5,zDate,category,pattern,enabled,uuid,sended FROM {$table} WHERE category='{$sourceCategory}'"; $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n"; continue; } $q->QUERY_SQL("DELETE FROM {$table} WHERE category='{$sourceCategory}'"); } } }
function category_urls_delete() { $category = $_POST["category"]; $item = mysql_escape_string2($_POST["category-items-delete"]); $q = new mysql_squid_builder(); $table = "categoryuris_" . $q->category_transform_name($category); $q->QUERY_SQL("DELETE FROM {$table} WHERE `pattern`='{$item}'"); if (!$q->ok) { echo $q->mysql_error; return; } $sock = new sockets(); $sock->getFrameWork("squid.php?ufdbguard-compile-database={$category}"); }
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"; $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; } $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 MoveCategorizedWebsite($md5=null,$nextCategory=null,$table=null){ $q=new mysql_squid_builder(); $sock=new sockets(); if($md5==null){$md5=$_POST["MoveCategorizedWebsite"];} if($nextCategory==null){$nextCategory=trim($_POST["NextCategory"]);} if($table==null){$table=trim($_POST["TABLE"]);} if($nextCategory==null){echo "Next category = Null\n";return;} if($table==null){echo "Table = Null\n";return;} if($md5==null){echo "md5 = Null\n";return;} if(!isset($GLOBALS["uuid"])){$GLOBALS["uuid"]=base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes"));} $uuid=$GLOBALS["uuid"]; $sql="SELECT * FROM $table WHERE zmd5='$md5'"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); if(!$q->ok){echo $q->mysql_error;return;} $www=$ligne["pattern"]; $sql="INSERT IGNORE INTO categorize_delete (sitename,category,zmd5) VALUES ('{$ligne["pattern"]}','{$ligne["category"]}','{$ligne["zmd5"]}')"; $q->QUERY_SQL($sql); if(!$q->ok){echo $q->mysql_error;return;} $q->QUERY_SQL("UPDATE $table SET enabled=0 WHERE zmd5='$md5'"); if(!$q->ok){echo $q->mysql_error;return;} $sock->getFrameWork("squid.php?export-deleted-categories=yes"); $newmd5=md5($nextCategory.$www); $q->QUERY_SQL("INSERT IGNORE INTO categorize_changes (zmd5,sitename,category) VALUES('$newmd5','$www','$nextCategory')"); if(!$q->ok){echo $q->mysql_error;return;} $q->CreateCategoryTable($nextCategory); $category_table=$q->category_transform_name($nextCategory); $q->QUERY_SQL("INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('$newmd5',NOW(),'$nextCategory','$www','$uuid')"); if(!$q->ok){echo $q->mysql_error;return;} $q->QUERY_SQL("INSERT IGNORE INTO category_$category_table (zmd5,zDate,category,pattern,uuid,enabled) VALUES('$md5',NOW(),'$nextCategory','$www','$uuid',1)"); if(!$q->ok){echo $q->mysql_error;return;} $cats=addslashes($q->GET_CATEGORIES($www,true)); $q->QUERY_SQL("UPDATE visited_sites SET category='$cats' WHERE sitename='$www'"); if(!$q->ok){echo $q->mysql_error."\n";echo $sql."\n";} $sock=new sockets(); $sock->getFrameWork("cmd.php?export-community-categories=yes"); $sock->getFrameWork("squid.php?re-categorize=yes"); }
function CategorizeAll_perform(){ if($_GET["pattern"]==null){return;} $sock=new sockets(); $uuid=base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); if($uuid==null){echo "UUID=NULL; Aborting";return;} $pattern=" AND sitename LIKE '%{$_GET["pattern"]}%' "; $pattern=str_replace("*","%",$pattern); $sql="SELECT sitename FROM `visited_sites` WHERE LENGTH( `category` )=0 $pattern"; $category=$_GET["CategorizeAll_category"]; if($category==null){return;} if($category=="teans"){$category="teens";} $q=new mysql_squid_builder(); $results=$q->QUERY_SQL($sql,"artica_events"); if(!$q->ok){ echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__; return; } if($_GET["week"]<>null){$_GET["day"]=$_GET["week"];} $category_table="category_".$q->category_transform_name($category); if(!$q->TABLE_EXISTS($category_table)){$q->CreateCategoryTable($category);} while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){ $website=$ligne["sitename"]; if($website==null){return;} $www=trim(strtolower($website)); if(preg_match("#^www\.(.+?)$#i",trim($www),$re)){$www=$re[1];} $md5=md5($category.$www); $enabled=1; if($www==null){echo "Alert: website is null...\n";return;} $sql_add="INSERT INTO $category_table (zmd5,zDate,category,pattern,uuid,enabled) VALUES('$md5',NOW(),'$category','$www','$uuid',1)"; $ligne=mysql_fetch_array($q->QUERY_SQL("SELECT category,pattern FROM `$category_table` WHERE zmd5='$md5'")); if($ligne["category"]==null){$sql_add="UPDATE $category_table SET `category`='$category',pattern='$www' WHERE zmd5='$md5'";} if($ligne["pattern"]==null){$sql_add="UPDATE $category_table SET `category`='$category',pattern='$www' WHERE zmd5='$md5'";} $q->QUERY_SQL($sql_add); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;return;} $sql="INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('$md5',NOW(),'$category','$www','$uuid')"; $q->QUERY_SQL($sql); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;return;} $sql="UPDATE `visited_sites` SET `category`='$category' WHERE LENGTH( `category` )=0 $pattern"; $q->QUERY_SQL($sql); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;return;} if($_GET["day"]<>null){ if($pattern<>null){ $time=strtotime($_GET["day"]." 00:00:00"); $tableSrc=date('Ymd',$time)."_hour"; $categories=$q->GET_CATEGORIES($www,true); if($categories==null){$categories=$category;} $sql="UPDATE $tableSrc SET category='$categories' WHERE LENGTH( `category` )=0 $pattern"; $q->QUERY_SQL($sql); writelogs($sql,__FUNCTION__,__FILE__,__LINE__); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;} $tableWeek=date("YW",$time)."_week"; $sql="UPDATE $tableWeek SET category='$categories' WHERE LENGTH( `category` )=0 $pattern"; $q->QUERY_SQL($sql); writelogs($sql,__FUNCTION__,__FILE__,__LINE__); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;} $tableSrcDay=date('Ym',$time)."_day"; if($q->TABLE_EXISTS($tableSrcDay)){ $sql="UPDATE $tableSrcDay SET category='$categories' WHERE LENGTH( `category` )=0 $pattern"; writelogs($sql,__FUNCTION__,__FILE__,__LINE__); $q->QUERY_SQL($sql); if(!$q->ok){echo $q->mysql_error."\n".basename(__FILE__)."\nLine".__LINE__."\n";echo $sql;} } }else{ echo "Pattern is null!!\n"; } } } $sock=new sockets(); $sock->getFrameWork("cmd.php?export-community-categories=yes"); }
function categorize_delete() { $unix = new unix(); $URIBASE = $unix->MAIN_URI(); $tmpdir = $unix->TEMP_DIR(); if (!is_file("{$tmpdir}/categorize_delete.sql")) { $curl = new ccurl("{$URIBASE}/blacklist/categorize_delete.gz"); if (!$curl->GetFile("{$tmpdir}/categorize_delete.gz")) { // ufdbguard_admin_events("Fatal: unable to download categorize_delete.gz file $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica"); return; } if (!extractGZ("{$tmpdir}/categorize_delete.gz", "{$tmpdir}/categorize_delete.sql")) { // ufdbguard_admin_events("Fatal: unable to extract $tmpdir/categorize_delete.gz",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica"); return; } } $q = new mysql_squid_builder(); $datas = explode("\n", @file_get_contents("{$tmpdir}/categorize_delete.sql")); while (list($index, $row) = each($datas)) { if (trim($row) == null) { continue; } $ligne = unserialize($row); $category = $ligne["category"]; $pattern = $ligne["sitename"]; $tablename = "category_" . $q->category_transform_name($category); if (!$q->TABLE_EXISTS($tablename)) { $q->CreateCategoryTable($category); } $q->QUERY_SQL("UPDATE {$tablename} SET enabled=0 WHERE `pattern`='{$pattern}'"); if (!$q->ok) { echo $q->mysql_error . "\n"; } } // ufdbguard_admin_events("Success updating deleted ". count($datas)." websites from categories",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica"); @unlink("{$tmpdir}/categorize_delete.sql"); }
function ParseDirectory($path) { if (!is_dir($path)) { echo "{$path} No such directory\n"; return; } $sock = new sockets(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); if ($uuid == null) { echo "No uuid\n"; return; } $handle = opendir($path); $q = new mysql_squid_builder(); $f = false; while (false !== ($dir = readdir($handle))) { if ($dir == ".") { continue; } if ($dir == "..") { continue; } if (!is_file("{$path}/{$dir}/domains")) { echo "{$path}/{$dir}/domains no such file\n"; continue; } $category = sourceCategoryToArticaCategory($dir); if ($category == null) { echo "{$path}/{$dir}/domains no such category\n"; continue; } $table = "category_" . $q->category_transform_name($category); if (!$q->TABLE_EXISTS($table)) { echo "{$category} -> no such table {$table}\n"; continue; } inject($category, $table, "{$path}/{$dir}/domains"); } $tables = $q->LIST_TABLES_CATEGORIES(); while (list($table, $www) = each($tables)) { $sql = "SELECT COUNT(zmd5) as tcount FROM {$table} WHERE sended=0 and enabled=1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $prefix = "INSERT IGNORE INTO categorize (zmd5 ,pattern,zDate,uuid,category) VALUES"; if ($ligne["tcount"] > 0) { echo "{$table} {$ligne["tcount"]} items to export\n"; $results = $q->QUERY_SQL("SELECT * FROM {$table} WHERE sended=0 and enabled=1"); while ($ligne2 = mysql_fetch_array($results, MYSQL_ASSOC)) { $f[] = "('{$ligne2["zmd5"]}','{$ligne2["pattern"]}','{$ligne2["zDate"]}','{$uuid}','{$ligne2["category"]}')"; $c++; if (count($f) > 3000) { $q->QUERY_SQL($prefix . @implode(",", $f)); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } $f = array(); } } $q->QUERY_SQL("UPDATE {$table} SET sended=1 WHERE sended=0"); } } if (count($f) > 0) { $q->QUERY_SQL($prefix . @implode(",", $f)); $f = array(); } }
function PerformProposal() { $extcat = $_POST["category"]; $sitename = $_POST["sitename"]; $sock = new sockets(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); $newmd5 = md5("{$extcat}{$sitename}"); $q = new mysql_squid_builder(); $category_table = "category_" . $q->category_transform_name($extcat); $q->QUERY_SQL("INSERT IGNORE INTO categorize_changes (zmd5,sitename,category) VALUES('{$newmd5}','{$sitename}','{$extcat}')"); if (!$q->ok) { echo $q->mysql_error; return; } $q->QUERY_SQL("INSERT IGNORE INTO {$category_table} (zmd5,zDate,category,pattern,uuid) VALUES('{$newmd5}',NOW(),'{$extcat}','{$sitename}','{$uuid}')"); if (!$q->ok) { echo $q->mysql_error; return; } $q->QUERY_SQL("DELETE FROM webtests WHERE sitename='{$sitename}'"); if (!$q->ok) { echo $q->mysql_error; return; } }
function blacklist_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(); if (!is_numeric($_GET["TimeID"])) { $_GET["TimeID"] = 0; } $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 = "webfilter_blks"; if ($_GET["TimeID"] > 0) { $tableProd = "webfilters_dtimes_blks"; } if ($_GET["QuotaID"] > 0) { $_GET["RULEID"] = $_GET["QuotaID"]; $tableProd = "webfilters_quotas_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 `webfilter_id`={$_GET["RULEID"]} AND modeblk={$_GET["modeblk"]}"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { json_error_show("{$q->mysql_error}<br>{$sql}", 2); } 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; $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['modeblk']}_{$ligne['categorykey']}", 1, $val, "EnableDisableCategoryRule('{$ligne['categorykey']}','{$_GET["RULEID"]}','{$_GET["modeblk"]}','{$_GET["TimeID"]}')"); $ligne['description'] = utf8_encode($ligne['description']); $data['rows'][] = array('id' => $ligne['categorykey'], 'cell' => array("<img src='{$img}'>", "{$js}{$ligne['categorykey']}</a>", $ligne['description'] . "<br>{$database_items}", $disable)); } echo json_encode($data); }
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(" | ", $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 save_category() { if ($_GET["website"] == null) { return; } $www = trim(strtolower(base64_decode($_GET["website"]))); if (preg_match("#^www\\.(.+?)\$#i", $www, $re)) { $www = $re[1]; } $category = $_GET["category"]; $md5 = md5($www . $category); $sock = new sockets(); $q = new mysql_squid_builder(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); $enabled = $_GET["enabled"]; $q->CreateCategoryTable($category); $category_table = $q->category_transform_name($category); $sql = "SELECT zmd5 FROM category_{$category_table} WHERE pattern='{$www}'"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql)); $sql_add = "INSERT IGNORE INTO categorize (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $sql_add2 = "INSERT IGNORE INTO category_{$category_table} (zmd5,zDate,category,pattern,uuid) VALUES('{$md5}',NOW(),'{$category}','{$www}','{$uuid}')"; $sql_edit = "UPDATE category_{$category_table} SET enabled='{$enabled}' WHERE zmd5='{$ligne["zmd5"]}'"; writelogs("{$www}/{$category} = {$ligne["zmd5"]}", __FUNCTION__, __FILE__, __LINE__); if ($ligne["zmd5"] == null) { $q->QUERY_SQL($sql_add2); $q->QUERY_SQL($sql_add); } else { writelogs("{$sql_edit}", __FUNCTION__, __FILE__, __LINE__); $q->QUERY_SQL($sql_edit); } if (!$q->ok) { echo $q->mysql_error; return; } $q->QUERY_SQL("UPDATE visited_sites SET category='' WHERE sitename='{$www}'"); if (!$q->ok) { echo $q->mysql_error . "\n"; echo $sql . "\n"; } $cats = addslashes($q->GET_CATEGORIES($www, true)); $q->QUERY_SQL("UPDATE visited_sites SET category='{$cats}' WHERE sitename='{$www}'"); if (!$q->ok) { echo $q->mysql_error . "\n"; echo $sql . "\n"; } $newmd5 = md5("{$cats}{$www}"); $q->QUERY_SQL("INSERT IGNORE INTO categorize_changes (zmd5,sitename,category) VALUES('{$newmd5}','{$www}','{$cats}')"); if (!$q->ok) { echo $q->mysql_error . "\n"; echo $sql . "\n"; } if ($enabled == 1) { $q->QUERY_SQL("DELETE FROM categorize_delete WHERE zmd5='{$md5}'"); } else { $q->QUERY_SQL("INSERT IGNORE INTO categorize_delete(zmd5,sitename,category) VALUES('{$md5}','{$www}','{$category}')"); } if ($_GET["day"] != null) { $time = strtotime($_GET["day"] . " 00:00:00"); $tableSrc = date('Ymd') . "_hour"; if (!$q->TABLE_EXISTS($tableSrc)) { $q->CreateHourTable($tableSrc); } $q->QUERY_SQL("UPDATE {$tableSrc} SET category='{$cats}' WHERE sitename='{$www}'"); if (!$q->ok) { echo $q->mysql_error; } } $sock = new sockets(); $sock->getFrameWork("cmd.php?export-community-categories=yes"); $sock->getFrameWork("squid.php?re-categorize=yes"); }