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");
}
示例#2
0
function inject()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if (!$GLOBALS["FULL"]) {
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, __FILE__)) {
            writelogsBLKS("Warning: Already running pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $working_dir = $GLOBALS["working_directory"];
    $unix = new unix();
    $sql = "SELECT * FROM updates_categories WHERE finish=0 and progress>0 AND filesize>0 ORDER BY categories";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "Fatal error {$sql}\n";
        ufdbguard_admin_events("Fatal: mysql database error {$q->mysql_error} while retreive update list", __FUNCTION__, __FILE__, __LINE__, "update");
        return;
    }
    $num = mysql_num_rows($results);
    echo "{$num} files to check\n";
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $filename = $ligne["filename"];
        $targetfile = $working_dir . "/" . $filename;
        $targetfileUncompress = $working_dir . "/" . $filename . ".ext";
        UpdateCategories($filename, 30, "{uncompress}", 0);
        if (!extractGZ($targetfile, $targetfileUncompress)) {
            ufdbguard_admin_events("Fatal: unable to extract {$targetfile}", __FUNCTION__, __FILE__, __LINE__, "update");
            $unix->send_email_events("Proxy:[BlacklistsDB] Fatal: unable to extract {$targetfile}", "", "proxy");
            UpdateCategories($filename, 30, "{failed_uncompress}", 0);
            continue;
        }
        inject_sql($filename, $targetfileUncompress);
        //return;
    }
    CategoriesCountCache();
}