function clean_squid_stats_dbs() { $sock = new sockets(); $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics"); $CleanArticaSquidDatabases = $sock->GET_INFO("CleanArticaSquidDatabases"); if (!is_numeric($DisableArticaProxyStatistics)) { $DisableArticaProxyStatistics = 0; } if (!is_numeric($CleanArticaSquidDatabases)) { $CleanArticaSquidDatabases = 0; } if (!$GLOBALS["FORCE"]) { if ($CleanArticaSquidDatabases == 0) { echo "Option is not activated...\n"; return; } } $q = new mysql_squid_builder(); $tables = $q->LIST_TABLES_DAYS(); $rows = 0; $count_tables = 0; while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $tables = $q->LIST_TABLES_DAYS_BLOCKED(); while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $tables = $q->LIST_TABLES_MEMBERS(); while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $tables = $q->LIST_TABLES_MONTH(); while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $tables = $q->LIST_TABLES_WEEKS(); while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $q = new mysql_catz(); $tables = $q->LIST_TABLES_CATEGORIES(); while (list($num, $table) = each($tables)) { $rows = $rows + $q->COUNT_ROWS($table); if ($GLOBALS["VERBOSE"]) { echo " Delete table {$table} {$rows} rows \n"; } $count_tables++; $q->DELETE_TABLE($table); } $q = new mysql(); if ($q->DATABASE_EXISTS("catz")) { $q->DELETE_DATABASE("catz"); } if ($count_tables > 0) { mysql_admin_mysql(1, "Restarting MySQL service...", null, __FILE__, __LINE__); shell_exec("/etc/init.d/mysql restart"); } $sock->TOP_NOTIFY("{$count_tables} statistics tables as been deleted with {$rows} rows", "info"); //print_r($tables); }
function statusDB() { $tpl = new templates(); $page = CurrentPageName(); $users = new usersMenus(); if (!$users->ARTICADB_INSTALLED) { $html = FATAL_ERROR_SHOW_128("{ARTICADB_NOT_INSTALLED_EXPLAIN}") . "<center style='margin:80px'>\n\t\t<hr>" . button("{install_now}", "Loadjs('squid.blacklist.upd.php')", 16) . "</center>"; echo $tpl->_ENGINE_parse_body($html); return; } $date = GetLastUpdateDate(); $q = new mysql_catz(); $sock = new sockets(); $ini = new Bs_IniHandler(); $catz = $q->LIST_TABLES_CATEGORIES(); $ini->loadString(base64_decode($sock->getFrameWork('cmd.php?squid-ini-status=yes'))); $APP_ARTICADB = DAEMON_STATUS_ROUND("APP_ARTICADB", $ini, null, 1); $sql = "SHOW VARIABLES LIKE '%version%';"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { writelogs("Fatal Error: {$q->mysql_error}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__); return array(); } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["Variable_name"] == "slave_type_conversions") { continue; } $tt[] = "\t<tr>\n\t\t\t\t\t<td colspan=2><div style='font-size:14px'>{{$ligne["Variable_name"]}}: {$ligne["Value"]}</a></div></td>\n\t\t\t\t</tr>"; } $arrayV = unserialize(base64_decode($sock->getFrameWork("squid.php?articadb-nextversion=yes"))); $REMOTE_VERSION = $arrayV["TIME"]; if ($REMOTE_VERSION > $date) { $REMOTE_SIZE = $arrayV["ARTICATECH"]["SIZE"]; $REMOTE_SIZE = FormatBytes($REMOTE_SIZE / 1024); $updaebutton = "<div style='text-align:right'><hr>" . button("{update}:{version} {$REMOTE_VERSION} ({$REMOTE_SIZE})", "Loadjs('squid.blacklist.upd.php')", 16) . "</div>"; } $nextcheck = $sock->getFrameWork("squid.php?articadb-nextcheck=yes"); $nextcheck = intval($nextcheck); if ($nextcheck > 0) { $nextcheck_text = "\t\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{next_check_in}: {$nextcheck}Mn</div></td>\n\t</tr>"; } if ($nextcheck < 0) { $nextcheck = str_replace("-", "", $nextcheck); $nextcheckTime = time() - intval($nextcheck) * 60; $nextcheckTimeText = distanceOfTimeInWords($nextcheckTime, time()); $nextcheck_text = "\t\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{last_check}: {$nextcheckTimeText}</div></td>\n\t</tr>"; } $DB_STATUS = unserialize(base64_decode($sock->getFrameWork("ufdbguard.php?databases-percent=yes"))); $DB_STATUS_TIME = $DB_STATUS["ARTICA"]["LAST_TIME"]; $DB_STATUS_MAX = $DB_STATUS["ARTICA"]["MAX"]; $DB_STATUS_COUNT = $DB_STATUS["ARTICA"]["COUNT"]; $DB_STATUS_PERC = round($DB_STATUS_COUNT / $DB_STATUS_MAX * 100); $dbsize = $sock->getFrameWork("squid.php?articadbsize=yes"); $items = numberFormat($q->COUNT_CATEGORIES(), 0, "", " "); $html = "\n<div style='width:95%;min-height:254px' class=form>\n\t<table style='width:99%'>\n\t<tr>\n\t<td valign='top'>{$APP_ARTICADB}</td>\n\t<td valign='top'>\n\t\t<table style='width:100%'>\n\t\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td colspan=2><div style='font-size:16px'>{pattern_database_version}: {$date} ({$dbsize})</div></td>\n\t\t\t</tr>\n\t\t\t{$nextcheck_text}\n\t\t\t<tr>\n\t\t\t\t<td colspan=2><div style='font-size:16px'>{categories}: " . count($catz) . "</a></div></td>\n\t\t\t\t\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan=2><div style='font-size:16px'>{categorized_websites}: {$items} </div></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan=2><div style='font-size:16px;font-weight:bold;margin-top:10px'>{mysql_engine}:</div></td>\n\t\t\t</tr>\t\n\t\t\t" . @implode("", $tt) . "\n\t\t\t\t\t\n\t\t\t</tbody>\n\t\t</table>\n\t</td>\n\t</tr>\n\t\t<tr>\n\t\t\t<td class=legend style='font-size:12px;font-weight:bold;{$color}'>{update_status}:</td>\n\t\t\t<td>" . pourcentage($DB_STATUS_PERC, 0, "green") . "</td>\n\t\t</tr>\t\t\n\t</table>\n</div>\n\t{$updaebutton}\n\t"; echo $tpl->_ENGINE_parse_body($html); }
function categories_search() { $tpl = new templates(); $catz = new mysql_catz(); $tables = $catz->LIST_TABLES_CATEGORIES(); $dans = new dansguardian_rules(); $dans->LoadBlackListes(); $search = string_to_flexregex("categories-search"); $TransArray = $catz->TransArray(); while (list($key, $value) = each($tables)) { $categoryname = $TransArray[$key]; $text_category = $tpl->_ENGINE_parse_body($dans->array_blacksites[$categoryname]); if (!isset($dans->array_blacksites[$categoryname])) { continue; } if ($dans->array_pics[$categoryname] != null) { $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>"; } else { $pic = " "; } $CTCOUNT = $catz->COUNT_ROWS($key); if ($CTCOUNT == 0) { continue; } $items = numberFormat($CTCOUNT, 0); if ($search != null) { if (!preg_match("#{$search}#", $categoryname)) { if (!preg_match("#{$search}#", $text_category)) { continue; } } } $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td width=1% nowrap>{$pic}</td>\n\t\t<td><i class='icon-globe'></i> <strong>{$categoryname}</strong><div>{$text_category}</div></td>\n\t\t<td nowrap><i class='icon-info-sign'></i> <span style='font-size:18px'>{$items}</span></td>\n\t\t</tr>"; } echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=2>{category}</th>\n\t\t\t\t\t<th>{websites}</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("", $tr) . "</tbody></table>"; }
function statusDB() { $tpl = new templates(); $page = CurrentPageName(); $users = new usersMenus(); $sock = new sockets(); $backbutton = null; if ($_GET["from-ufdbguard"] == "yes") { echo $tpl->_ENGINE_parse_body("\n\t\t\t\t<div style='margin:15px;text-align:right'>\n\t\t\t\t" . button("{back_to_webfiltering}", "AnimateDiv('BodyContent');LoadAjax('BodyContent','dansguardian2.mainrules.php')", 18) . "\n\t\t\t\t</div>"); } $q = new mysql_catz(); $sock = new sockets(); $ini = new Bs_IniHandler(); $catz = $q->LIST_TABLES_CATEGORIES(); $sock->getFrameWork('cmd.php?squid-ini-status=yes'); $ini->loadFile("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS"); $CATZ_ARRAY = unserialize(@file_get_contents("/home/artica/categories_databases/CATZ_ARRAY")); $date = $CATZ_ARRAY["TIME"]; $LOCAL_VERSION = $CATZ_ARRAY["TIME"]; $title = $tpl->_ENGINE_parse_body("{APP_ARTICADB}"); $q = new mysql_catz(); $LOCAL_VERSION_TEXT = $tpl->time_to_date($date); $CountDecategories = intval(@file_get_contents("/usr/share/artica-postfix/ressources/UFDB_ARTICA_COUNT")); $CountDeDatabases = intval(@file_get_contents("/usr/share/artica-postfix/ressources/UFDB_ARTICA_DBS")); if (!is_numeric($CountDecategories)) { $CountDecategories = 0; } $CountDecategories = numberFormat($CountDecategories, 0, "", " "); $APP_SQUID_DB = DAEMON_STATUS_ROUND("APP_SQUID_DB", $ini, null, 1); $APP_UFDBCAT = DAEMON_STATUS_ROUND("APP_UFDBCAT", $ini, null, 1); $DisableCategoriesDatabasesUpdates = intval($sock->GET_INFO("DisableCategoriesDatabasesUpdates")); $CategoriesDatabasesUpdatesAllTimes = intval($sock->GET_INFO("CategoriesDatabasesUpdatesAllTimes")); $CategoriesDatabasesByCron = $sock->GET_INFO("CategoriesDatabasesByCron"); if (!is_numeric($CategoriesDatabasesByCron)) { $CategoriesDatabasesByCron = 1; } $CategoriesDatabasesShowIndex = $sock->GET_INFO("CategoriesDatabasesShowIndex"); if (!is_numeric($CategoriesDatabasesShowIndex)) { $CategoriesDatabasesShowIndex = 1; } $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics"); if (!is_numeric($DisableArticaProxyStatistics)) { $DisableArticaProxyStatistics = 0; } $fbdize = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/web/categories-db.size.db")); $DBSIZE = FormatBytes($fbdize["DBSIZE"]); $POURC = $fbdize["POURC"]; if (is_numeric($POURC)) { $POURC_TXT = " {$POURC}% {used}"; } $p2 = Paragraphe_switch_img("{disable_udpates}", "{disable_udpates_explain}<br>{APP_ARTICADB_EXPLAIN}", "DisableCategoriesDatabasesUpdates", $DisableCategoriesDatabasesUpdates, null, 700); $p3 = Paragraphe_switch_img("{free_update_during_the_day}", "{free_update_during_the_day_explain}", "CategoriesDatabasesUpdatesAllTimes", $CategoriesDatabasesUpdatesAllTimes, null, 700); $p = Paragraphe_switch_img("{update_only_by_schedule}", "{articadb_update_only_by_schedule}", "CategoriesDatabasesByCron", $CategoriesDatabasesByCron, null, 700); $tt0[] = "<tr><td colspan=2>{$p3}</td></tr>"; $tt0[] = "<tr><td colspan=2>{$p2}</td></tr>"; $tt0[] = "<tr><td colspan=2>{$p}</td></tr>"; $tt0[] = "<tr>\n\t\t\t<td width=1%>" . Field_checkbox_design("CategoriesDatabasesShowIndex", 1, $CategoriesDatabasesShowIndex, "CategoriesDatabasesByCron()") . "</td>\n\t\t\t<td nowrap style='font-size:14px;'>:{display_update_info_index}</a></td>\n\t\t</tr>\n\t\t<tr><td colspan=2 align='right'>" . button("{apply}", "CategoriesDatabasesByCron()", 22) . "</td></tr>\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t"; /*$tt[]="<tr> <td width=1%><img src='img/arrow-right-16.png'> <td nowrap><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.catzdb.manual-update.php');\" style='font-size:14px;text-decoration:underline;'>{manual_update}</a></td> </tr>"; */ /*$tt[]="<tr> <td width=1%><img src='img/arrow-right-16.png'> <td nowrap><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.catzdb.changedir.php');\" style='font-size:14px;text-decoration:underline;'>{change_directory}</a></td> </tr>"; */ if ($DisableArticaProxyStatistics == 1) { $tt[] = "<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'>\n\t\t<td nowrap><a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:Loadjs('squid.artica.statistics.php');\"\n\t\tstyle='font-size:14px;text-decoration:underline;color:#D10000'>{ARTICA_STATISTICS} {disabled}</a></td>\n\t\t</tr>"; } else { $tt[] = "<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'>\n\t\t<td nowrap><a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:Loadjs('squid.artica.statistics.php');\"\n\t\tstyle='font-size:14px;text-decoration:underline;color:black'>{ARTICA_STATISTICS}</a></td>\n\t\t</tr>"; } $arrayV = unserialize(base64_decode($sock->getFrameWork("squid.php?articadb-nextversion=yes"))); $REMOTE_VERSION = $arrayV["TIME"]; if ($REMOTE_VERSION > $date) { $REMOTE_VERSION_TEXT = $tpl->time_to_date($REMOTE_VERSION); $newver = "\t<tr>\n\t\t<td colspan=2><div style='font-size:16px;color:#D52210'>{new_version}: {$REMOTE_VERSION} <i style='font-size:11px'>{$REMOTE_VERSION_TEXT}</i> </div></td>\n\t</tr>"; $updaebutton = "<div style='text-align:right'><hr>" . button("{update_now}", "Loadjs('squid.blacklist.upd.php')", 22) . "</div>"; } $nextcheck = $sock->getFrameWork("squid.php?articadb-nextcheck=yes"); $nextcheck = intval($nextcheck); if ($nextcheck > 0) { $nextcheck_text = "\t\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{next_check_in}: {$nextcheck}Mn</div></td>\n\t</tr>"; } if ($nextcheck < 0) { $nextcheck = str_replace("-", "", $nextcheck); $nextcheckTime = time() - intval($nextcheck) * 60; $nextcheckTimeText = distanceOfTimeInWords($nextcheckTime, time()); $nextcheck_text = "\t\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{last_check}: {$nextcheckTimeText}</div></td>\n\t</tr>"; } $dbsize = $sock->getFrameWork("squid.php?articadbsize=yes"); $items = numberFormat($q->COUNT_CATEGORIES(), 0, "", " "); $html = "\n\t<div style='width:98%' class=form>\n\t\n\t<table style='width:100%'>\n\t<tr>\n\t<td valign='top'>{$APP_SQUID_DB}<br>{$APP_UFDBCAT}</td>\n\t<td valign='top'>\n\t<table style='width:100%'>" . @implode("\n", $tt0) . "</table>\n\t<hr>\n\t<table style='width:100%'>\n\t<tbody>\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{pattern_database_version}: {$date} <i style='font-size:11px'>{$LOCAL_VERSION_TEXT}</i> {$POURC_TXT}</div></td>\n\t</tr>\n\t{$newver}\n\t{$nextcheck_text}\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{categories}: {$CountDeDatabases}</a></div></td>\n\t</tr>\n\t<tr>\n\t\t<td colspan=2><div style='font-size:16px'>{categorized_websites}: \n\t\t<a href=\"javascript:Loadjs('squid.catz.php');\" style='font-size:16px;text-decoration:underline'>\n\t\t{$CountDecategories}</a> </div></td>\n\t</tr>\n\t" . @implode("", $tt) . "\n\t</tbody>\n\t</table>\n\t</td>\n\t</tr>\n\t</table>\n\t{$updaebutton}\n\t<div id='database-progress-status'></div>\n<script>\nvar xCategoriesDatabasesByCron= function (obj) {\n\tvar results=obj.responseText;\n\tif(results.length>1){alert(results);}\n}\n\t\nfunction CategoriesDatabasesByCron(){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('CategoriesDatabasesByCron',document.getElementById('CategoriesDatabasesByCron').value);\n\tXHR.appendData('DisableCategoriesDatabasesUpdates',document.getElementById('DisableCategoriesDatabasesUpdates').value);\n\tXHR.appendData('CategoriesDatabasesUpdatesAllTimes',document.getElementById('CategoriesDatabasesUpdatesAllTimes').value);\n\tif(document.getElementById('CategoriesDatabasesShowIndex').checked){XHR.appendData('CategoriesDatabasesShowIndex','1');}else{XHR.appendData('CategoriesDatabasesShowIndex','0');}\n\tXHR.sendAndLoad('{$page}', 'POST',xCategoriesDatabasesByCron);\n}\n\t\n\n</script>"; echo $tpl->_ENGINE_parse_body($html); }