function schedulemaintenance()
{
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " in verbose mode\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        WriteMyLogs("Warning: Already running pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!$GLOBALS["VERBOSE"]) {
        $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
        $time = $unix->file_time_min($cachetime);
        if ($time < 20) {
            WriteMyLogs("{$cachetime}: {$time}Mn need 20Mn", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        @unlink($cachetime);
        @file_put_contents($cachetime, time());
    }
    $sock = new sockets();
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    if ($EnableRemoteStatisticsAppliance == 1) {
        writelogsBLKS("EnableRemoteStatisticsAppliance ACTIVE ,ABORTING TASK", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $t1 = time();
    $q = new mysql_squid_builder();
    $badDomains["com"] = true;
    $badDomains["fr"] = true;
    $badDomains["de"] = true;
    $badDomains["nl"] = true;
    $badDomains["org"] = true;
    $badDomains["co"] = true;
    $badDomains["cz"] = true;
    $badDomains["de"] = true;
    $badDomains["net"] = true;
    $badDomains["us"] = true;
    $badDomains["name"] = true;
    $badDomains["il"] = true;
    $tables = $q->LIST_TABLES_CATEGORIES();
    while (list($table, $none0) = each($tables)) {
        if ($table == null) {
            continue;
        }
        if (strpos($table, ",") > 0) {
            $q->QUERY_SQL("DROP table `{$table}`");
            continue;
        }
        if (blacklisted_tables($table)) {
            continue;
        }
        if (!$q->TABLE_EXISTS($table)) {
            continue;
        }
        reset($badDomains);
        while (list($extensions, $none) = each($badDomains)) {
            $q->QUERY_SQL("DELETE FROM {$table} WHERE pattern='{$extensions}'");
        }
    }
}
Esempio n. 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();
}