예제 #1
0
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 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 = "&nbsp;";
        }
        $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>&nbsp;<strong>{$categoryname}</strong><div>{$text_category}</div></td>\n\t\t<td nowrap><i class='icon-info-sign'></i>&nbsp;<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>";
}
예제 #3
0
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("&nbsp;|&nbsp;", $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 categories_search($forceArtica = false)
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $dans = new dansguardian_rules();
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $t = $_GET["t"];
    $artica = $forceArtica;
    if (isset($_GET["artica"])) {
        $artica = true;
    }
    $tableSchema = "squidlogs";
    if (!$q->BD_CONNECT()) {
        json_error_show("Testing connection to MySQL server failed...", 1);
    }
    if (!$q->TABLE_EXISTS("webfilters_categories_caches")) {
        $q->CheckTables();
    }
    $dans = new dansguardian_rules();
    $dans->LoadBlackListes();
    $sql = "SELECT * FROM personal_categories";
    if (!$q->TABLE_EXISTS("personal_categories")) {
        json_error_show("personal_categories no such table!", 1);
    }
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $PERSONALSCATS[$ligne["category"]] = $ligne["category_description"];
    }
    $search = '%';
    $page = 1;
    $ORDER = "ORDER BY table_name";
    $searchstring = "table_name LIKE 'category_%'";
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if ($artica) {
        $q = new mysql_catz();
        writelogs("Artica mode -> {$q->database} " . $q->COUNT_CATEGORIES(), __FUNCTION__, __FILE__, __LINE__);
        $tableSchema = "catz";
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*{$_POST["query"]}*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "table_name LIKE 'category_{$search}'";
        $sql = "SELECT COUNT( table_name ) AS tcount FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND table_name LIKE 'category_{$search}'";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $sql = "SELECT COUNT(table_name) as TCOUNT FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND table_name LIKE 'category_%'";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
        }
        $total = $ligne["TCOUNT"];
        writelogs("{$sql} = {$total}", __FUNCTION__, __FILE__, __LINE__);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT table_name as c,TABLE_ROWS FROM information_schema.tables WHERE table_schema = '{$tableSchema}' AND {$searchstring} {$ORDER} {$limitSql}";
    writelogs("{$q->mysql_admin}:{$q->mysql_password}:{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}", 1);
    }
    if (mysql_num_rows($results) == 0) {
        if (!$artica) {
            categories_search(true);
            return;
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("({$tableSchema}) No categories table found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $enc = new mysql_catz();
    while ($ligne = mysql_fetch_assoc($results)) {
        $table = $ligne["c"];
        writelogs("Scanning table {$table}", __FUNCTION__, __FILE__, __LINE__);
        $select = imgtootltip("32-parameters.png", "{apply}", "DansGuardianEditMember('{$ligne["ID"]}','{$ligne["pattern"]}')");
        $items = $q->COUNT_ROWS($ligne["c"]);
        $itemsEnc = $enc->COUNT_ROWS($ligne["c"]);
        if (!preg_match("#^category_(.+)#", $table, $re)) {
            continue;
        }
        $categoryname = $re[1];
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk}", "DansGuardianCompileDB('{$categoryname}')");
        if (!isset($dans->array_blacksites[$categoryname])) {
            if (isset($dans->array_blacksites[str_replace("_", "-", $categoryname)])) {
                $categoryname = str_replace("_", "-", $categoryname);
            }
            if (isset($dans->array_blacksites[str_replace("_", "/", $categoryname)])) {
                $categoryname = str_replace("_", "/", $categoryname);
            }
        }
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $sizedb_org = $q->TABLE_SIZE($table);
        $sizedb = FormatBytes($sizedb_org / 1024);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categories.php?category={$categoryname}&t={$t}',true)\"\n\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $text_category = $dans->array_blacksites[$categoryname];
        if (isset($PERSONALSCATS[$categoryname])) {
            $text_category = utf8_encode($PERSONALSCATS[$categoryname]);
            if ($pic == "&nbsp;") {
                $pic = "<img src='img/20-categories-personnal.png'>";
            }
            $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>";
        }
        if ($EnableWebProxyStatsAppliance == 0) {
            if ($sizedb_org < 35) {
                $pic = "<img src='img/warning-panneau-32.png'>";
            }
        }
        $viewDB = imgsimple("mysql-browse-database-32.png", "{view}", "javascript:Loadjs('squid.categories.php?category={$categoryname}',true)");
        $categoryText = $tpl->_ENGINE_parse_body("<div style='font-size:14px';font-weight:bold'>{$linkcat}{$categoryname}</div>\n\t\t</a><div style='font-size:11px;width:100%;font-weight:normal'>{$text_category}</div>");
        $items = numberFormat($items, 0, "", " ");
        $itemsEnc = numberFormat($itemsEnc, 0, "", " ");
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk} {$categoryname}", "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("delete-32.png", "{delete}", "TableCategoryPurge('{$table}')");
        if ($_GET["minisize"] == "yes") {
            $delete = null;
        }
        $cell = array();
        $cell[] = $pic;
        $cell[] = $categoryText;
        $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>{$sizedb}</div>";
        if (!$artica) {
            $cell[] = "<div style='font-size:13px;padding-top:5px;font-weight:bold'>{$items}<br>{$itemsEnc}</strong>";
        } else {
            $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>-</strong>";
            $cell[] = "<div style='font-size:13px;padding-top:15px;font-weight:bold'>{$items}</strong>";
        }
        $cell[] = $compile;
        $cell[] = $delete;
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}