function change_week_popup() { $page = CurrentPageName(); $tpl = new templates(); $q = new mysql_squid_builder(); $t = $_GET["t"]; $members = $tpl->_ENGINE_parse_body("{members}"); $week = $tpl->_ENGINE_parse_body("{week}"); $array = array(); $tables = $q->LIST_TABLES_WEEKS(); while (list($index, $tablez) = each($tables)) { $array[$tablez] = $q->WEEK_TITLE_FROM_TABLENAME($tablez); } $field = Field_array_Hash($array, "table-query-{$t}", $table, " DayMemberChangeWeekPanel{$t}()", null, 0, "font-size:14px"); $array = array(); $html = "\n\t<table style='width:99%' class=form>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td class=legend style='font-size:16px;'>{week}:</td>\n\t\t\t\t<td>{$field}</td>\n\t\t\t</tr>\n\t</table>\n\n\t<script>\n\t\tfunction DayMemberChangeWeekPanel{$t}(){\n\t\t\tvar xday=document.getElementById('table-query-{$t}').value;\n\t\t\t\$('.ftitle').html('{$members}»{$week}»table:'+xday);\n\t\t\t\$('#{$t}').flexOptions({url: '{$page}?list-week=yes&week='+xday,title:'{$members}'+xday}).flexReload();\n\t\t\n\t\t}\n\t\n\t</script>"; echo $tpl->_ENGINE_parse_body($html); }
function master_table() { $q = new mysql_squid_builder(); $tpl = new templates(); $page = CurrentPageName(); $year = date("Y"); $week = intval(date('W')); if ($_GET["table"] == null) { $table = "{$year}{$week}_week"; } else { $table = $_GET["table"]; } $array = array(); $tables = $q->LIST_TABLES_WEEKS(); while (list($index, $tablez) = each($tables)) { $array[$tablez] = $q->WEEK_TITLE_FROM_TABLENAME($tablez); } $MasterTitle = $q->WEEK_TITLE_FROM_TABLENAME($table); $field = Field_array_Hash($array, "table-query-{$t}", $table, "ChangeWeekPanel{$t}()", null, 0, "font-size:12px"); $array = array(); $field = "<table style='width:100%'>\n\t<tbody>\n\t<tr><td width=100%' style='font-size:16px;font-weight:bold'>{$MasterTitle}</td>\n\t<td width=1%>\n\t<table><tbody><tr><td class=legend>{week}:</td>{$field}</td></tr></table>\n\t</td>\n\t</tr>\n\t</tbody>\n\t</table>"; $html = "\n\t<div id='master-{$t}'>\n\t{$field}<table style='width:100%'>\n\t<tbody>\n\t<tr>\n\t\t<td width='33.33%' valign='top'><div id='panel-left-top'></div></td>\n\t\t<td width='33.33%' valign='top'><div id='panel-middle-top'></div></td>\n\t\t<td width='33.33%' valign='top'><div id='panel-right-top'></div></td>\n\t</tr>\n\t</tbody>\n\t</table>\n\t</div>\n\t<script>\n\t\tLoadAjax('panel-left-top','{$page}?panel-categories-week=yes&table={$_GET["table"]}');\n\t\t\n\t\tfunction ChangeWeekPanel{$t}(){\n\t\t\t\$('master-{$t}').remove();\t\n\t\t\tvar sdate=document.getElementById('table-query-{$t}').value;\n\t\t\tLoadAjax('panel-start-point','{$page}?master=yes&table='+sdate);\n\t\t}\n\t</script>\n\t"; echo $tpl->_ENGINE_parse_body($html); }
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); }
$mypid = getmypid(); @file_put_contents($pidfile, $mypid); $q = new mysql_squid_builder(); $sql = "SELECT * FROM categorize_changes"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { writelogs("Fatal Error: {$q->mysql_error}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__); die; } if (mysql_num_rows($results) == 0) { echo "No changes\n"; die; } $table_hours = $q->LIST_TABLES_HOURS(); $table_days = $q->LIST_TABLES_DAYS(); $table_week = $q->LIST_TABLES_WEEKS(); $ALREADY = array(); $MAX = mysql_num_rows($results); $D = 0; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { if (isset($ALREADY[$ligne["sitename"]])) { $q->QUERY_SQL("DELETE FROM categorize_changes WHERE `zmd5`='{$ligne["zmd5"]}'"); continue; } $website = $ligne["sitename"]; $categories = $q->GET_CATEGORIES($website, true); $ALREADY[$ligne["sitename"]] = true; reset($table_hours); reset($table_days); reset($table_week); $categories = addslashes($categories);
function remove_numeric_members() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); ufdbguard_admin_events("Already executed pid {$pid} since {$timepid}", __FUNCTION__, __FILE__, __LINE__, "reports"); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid}\n"; } return; } $q = new mysql_squid_builder(); $q->QUERY_SQL("DELETE FROM members_uid WHERE uid REGEXP '^[0-9]+\$'"); $q->QUERY_SQL("DELETE FROM UserAuthDaysGrouped WHERE uid REGEXP '^[0-9]+\$'"); $q->QUERY_SQL("DELETE FROM UserAutDB WHERE uid REGEXP '^[0-9]+\$'"); $tables = $q->LIST_TABLES_WWWUID(); while (list($tablename, $ligne) = each($tables)) { if (!preg_match("#^www_[0-9]+\$#", $ligne)) { continue; } $q->QUERY_SQL("DROP TABLE {$tablename}"); } $tables = $q->LIST_TABLES_DAYS(); while (list($tablename, $ligne) = each($tables)) { $q->QUERY_SQL("DELETE FROM {$tablename} WHERE uid REGEXP '^[0-9]+\$'"); } $tables = $q->LIST_TABLES_WEEKS(); while (list($tablename, $ligne) = each($tables)) { $q->QUERY_SQL("DELETE FROM {$tablename} WHERE uid REGEXP '^[0-9]+\$'"); } $tables = $q->LIST_TABLES_MONTH(); while (list($tablename, $ligne) = each($tables)) { $q->QUERY_SQL("DELETE FROM {$tablename} WHERE uid REGEXP '^[0-9]+\$'"); } $tables = $q->LIST_TABLES_MEMBERS(); while (list($tablename, $ligne) = each($tables)) { $q->QUERY_SQL("DELETE FROM {$tablename} WHERE uid REGEXP '^[0-9]+\$'"); } }
function start_export() { $unix = new unix(); $sock = new sockets(); $q = new mysql_squid_builder(); $ArticaProxyStatisticsBackupFolder = $sock->GET_INFO("ArticaProxyStatisticsBackupFolder"); if ($ArticaProxyStatisticsBackupFolder == null) { $ArticaProxyStatisticsBackupFolder = "/home/artica/squid/backup-statistics"; } $ArticaProxyStatisticsBackupFolder = $ArticaProxyStatisticsBackupFolder . "/export"; $LIST_TABLES_YOUTUBE_HOURS = $q->LIST_TABLES_YOUTUBE_HOURS(); $LIST_TABLES_SIZEHOURS = $q->LIST_TABLES_SIZEHOURS(); $LIST_TABLES_QUOTA_HOURS = $q->LIST_TABLES_QUOTA_HOURS(); $LIST_TABLES_QUOTADAY = $q->LIST_TABLES_QUOTADAY(); $LIST_TABLES_QUOTAMONTH = $q->LIST_TABLES_QUOTAMONTH(); $LIST_TABLES_SEARCHWORDS_HOURS = $q->LIST_TABLES_SEARCHWORDS_HOURS(); $LIST_TABLES_SEARCHWORDS_DAY = $q->LIST_TABLES_SEARCHWORDS_DAY(); $LIST_TABLES_dansguardian_events = $q->LIST_TABLES_dansguardian_events(); $LIST_TABLES_HOURS = $q->LIST_TABLES_HOURS(); $LIST_TABLES_USERSIZED = $q->LIST_TABLES_USERSIZED(); $LIST_TABLES_YOUTUBE_WEEK = $q->LIST_TABLES_YOUTUBE_WEEK(); $LIST_TABLES_WEEKS = $q->LIST_TABLES_WEEKS(); $LIST_TABLES_MEMBERS = $q->LIST_TABLES_MEMBERS(); $LIST_TABLES_GSIZE = $q->LIST_TABLES_GSIZE(); $LIST_TABLES_GCACHE = $q->LIST_TABLES_GCACHE(); $LIST_TABLES_VISITED = $q->LIST_TABLES_VISITED(); $LIST_TABLES_BLOCKED = $q->LIST_TABLES_BLOCKED(); $LIST_TABLES_BLOCKED_WEEK = $q->LIST_TABLES_BLOCKED_WEEK(); $LIST_TABLES_BLOCKED_DAY = $q->LIST_TABLES_BLOCKED_DAY(); $LIST_TABLES_WWWUID = $q->LIST_TABLES_WWWUID(); $LIST_CAT_FAMDAY = $q->LIST_CAT_FAMDAY(); while (list($tablename, $none) = each($LIST_TABLES_YOUTUBE_HOURS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_SIZEHOURS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_QUOTADAY)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_QUOTAMONTH)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_SEARCHWORDS_HOURS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_SEARCHWORDS_DAY)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_QUOTA_HOURS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_dansguardian_events)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_HOURS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_USERSIZED)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_BLOCKED_WEEK)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_BLOCKED)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_YOUTUBE_WEEK)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_WEEKS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_MEMBERS)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_GSIZE)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_GCACHE)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_VISITED)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_BLOCKED_DAY)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_CAT_FAMDAY)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($LIST_TABLES_WWWUID)) { if (trim($tablename) == null) { continue; } $EXPORT_SOURCES[$tablename] = true; } while (list($tablename, $none) = each($EXPORT_SOURCES)) { if (trim($tablename) == null) { continue; } $EXPORT_DESTINATIONS[] = $tablename; } @mkdir($ArticaProxyStatisticsBackupFolder, 0755, true); $target_file = $ArticaProxyStatisticsBackupFolder . "/" . time() . ".sql.gz"; if (is_file($target_file)) { @unlink($target_file); } $EXPORT_DESTINATIONS[] = "visited_sites"; $EXPORT_DESTINATIONS[] = "youtube_objects"; $EXPORT_DESTINATIONS[] = "UserAgents"; $EXPORT_DESTINATIONS[] = "UserAutDB"; $EXPORT_DESTINATIONS[] = "UserAuthDays"; $EXPORT_DESTINATIONS[] = "UserAuthDaysGrouped"; $EXPORT_DESTINATIONS[] = "UserSizeRTT"; $EXPORT_DESTINATIONS[] = "allsizes"; $unix = new unix(); $mysqldump = $unix->find_program("mysqldump"); $bzip2 = $unix->find_program("bzip2"); $bzip2_cmd = "| {$bzip2} "; $AllTables = @implode(" ", $EXPORT_DESTINATIONS); $cmd = "{$mysqldump} -S /var/run/mysqld/squid-db.sock --single-transaction --skip-add-drop-table --no-create-db --insert-ignore --skip-add-locks --skip-lock-tables squidlogs {$AllTables} {$bzip2_cmd}> {$target_file} 2>&1"; $t = time(); $failed = false; if ($GLOBALS["VERBOSE"]) { echo $cmd . "\n"; } exec($cmd, $results); while (list($index, $line) = each($results)) { if (preg_match("#Couldn't#", $line)) { @unlink($target_file); stats_admin_events(0, "Exporting tables failed {$line} took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__); return; } if (preg_match("#Error\\s+([0-9]+)#", $line)) { @unlink($target_file); stats_admin_events(0, "Exporting tables failed {$line} took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__); return; } echo "{$line}\n"; } $size = @filesize($target_file); if ($size < 10000) { @unlink($target_file); stats_admin_events(0, "Exporting tables failed {$size}Bytes < 10000bytes took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__); return; } if ($GLOBALS["VERBOSE"]) { echo "{$target_file} {$size}Bytes " . FormatBytes($size / 1024) . "\n"; } reset($EXPORT_SOURCES); while (list($tablename, $none) = each($EXPORT_SOURCES)) { $q->QUERY_SQL("DROP TABLE {$tablename}"); if ($GLOBALS["VERBOSE"]) { echo "Removing table {$tablename}\n"; } } }