Exemplo n.º 1
0
function visited_sites()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $oldpid = @file_get_contents($pidfile);
    if ($oldpid < 100) {
        $oldpid = null;
    }
    $unix = new unix();
    if ($unix->process_exists($oldpid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$oldpid}\n";
        }
        return;
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $t1 = time();
    $sql = "SELECT sitename,country,category FROM visited_sites";
    $results = $GLOBALS["Q"]->QUERY_SQL($sql);
    $num_rows = mysql_num_rows($results);
    if ($num_rows == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "No datas " . __FUNCTION__ . " " . __LINE__ . "\n";
        }
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $country = null;
        $array = _visited_sites_calculate($ligne["sitename"]);
        if (!is_array($array)) {
            continue;
        }
        if (trim($ligne["country"] == null)) {
            $array_country = GeoIP($ligne["sitename"]);
        }
        if (isset($array_country)) {
            if (isset($array_country[0])) {
                $country = $array_country[0];
            }
        }
        if ($country != null) {
            $country = ",country='" . addslashes($country) . "'";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$ligne["sitename"]} {$array[0]} hits, {$array[1]} size Country '{$country}' on {$array[2]} tables\n";
        }
        $categories = $GLOBALS["Q"]->GET_CATEGORIES($ligne["sitename"], true);
        $categories = addslashes($categories);
        $sql = "UPDATE visited_sites SET HitsNumber='{$array[0]}',Querysize='{$array[1]}'{$country},category='{$categories}' WHERE sitename='{$ligne["sitename"]}'";
        $GLOBALS["Q"]->QUERY_SQL($sql);
    }
    $took = $unix->distanceOfTimeInWords($t1, time());
    writelogs_squid("Scanned {$num_rows} visisted websites {$took}", __FUNCTION__, __FILE__, __LINE__);
}
Exemplo n.º 2
0
function visited_sites()
{
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["FORCE"] = true;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid}\n";
        }
        return;
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    if (!$GLOBALS["FORCE"]) {
        $timeOfFile = $unix->file_time_min($timefile);
        if ($timeOfFile < 240) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timeOfFile}Mn,require 240Mn\n";
            }
            return;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    squid_status_sub_percentage("Running query", 5);
    $t1 = time();
    if (!$GLOBALS["Q"]->TABLE_EXISTS("visited_sites_catz")) {
        $GLOBALS["Q"]->CheckTables();
    }
    squid_status_sub_percentage();
    $sql = "SELECT sitename,country,category FROM visited_sites WHERE LENGTH(category)=0 LIMIT 0,1500";
    $results = $GLOBALS["Q"]->QUERY_SQL($sql);
    $num_rows = mysql_num_rows($results);
    events("visited_sites(): {$num_rows} items");
    stats_admin_events(2, "visited_sites {$num_rows} items", null, __FILE__, __LINE__);
    if ($num_rows == 0) {
        squid_status_sub_percentage("Done", 100);
        if ($GLOBALS["VERBOSE"]) {
            echo "No datas " . __FUNCTION__ . " " . __LINE__ . "\n";
        }
        return;
    }
    visited_sites_percentage("{$num_rows} entries");
    if ($GLOBALS["VERBOSE"]) {
        echo "{$num_rows} entries... in " . __FUNCTION__ . " " . __LINE__ . "\n";
    }
    squid_status_sub_percentage("{$num_rows} entries... in", 10);
    $ROWS_visited_sites_catz = array();
    $ROWS_visited_sites_prefix = "INSERT IGNORE INTO visited_sites_catz (`zmd5`,`category`,`familysite`) VALUES ";
    $z = 0;
    $MinutesFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".minutes";
    @unlink($MinutesFile);
    @file_put_contents($MinutesFile, time());
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $z++;
        $perc = round($z / $num_rows) * 100;
        $country = null;
        $FamilySite_update = null;
        $array = _visited_sites_calculate($ligne["sitename"]);
        if (!is_array($array)) {
            continue;
        }
        if (trim($ligne["country"] == null)) {
            $array_country = GeoIP($ligne["sitename"]);
        }
        if (isset($array_country)) {
            if (isset($array_country[0])) {
                $country = $array_country[0];
            }
        }
        if ($country != null) {
            $country = ",country='" . addslashes($country) . "'";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$ligne["sitename"]} {$array[0]} hits, {$array[1]} size Country '{$country}' on {$array[2]} tables\n";
        }
        $TimeLoop = $unix->file_time_min($MinutesFile);
        if ($TimeLoop > 4) {
            if (count($ROWS_visited_sites_prefix) > 0) {
                $GLOBALS["Q"]->QUERY_SQL($ROWS_visited_sites_prefix . @implode(",", $ROWS_visited_sites_catz));
                $ROWS_visited_sites_catz = array();
            }
            visited_sites_percentage("{$perc}% {$z}/{$num_rows} rows");
            stats_admin_events(2, "{$perc}% {$z}/{$num_rows} rows", null, __FILE__, __LINE__);
            if (SquidStatisticsTasksOverTime()) {
                stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
                return;
            }
            @unlink($MinutesFile);
            @file_put_contents($MinutesFile, time());
        }
        $categories = $GLOBALS["Q"]->GET_CATEGORIES($ligne["sitename"], true);
        if ($categories != null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "UPDATE {$ligne["sitename"]} ->{$categories}\n";
            }
            $GLOBALS["Q"]->QUERY_SQL("UPDATE visited_sites SET category='{$categories}' WHERE sitename='{$ligne["sitename"]}'");
            if (!$GLOBALS["Q"]->ok) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "UPDATE {$GLOBALS["Q"]->mysql_error}\n";
                }
            }
        }
        squid_status_sub_percentage("visited_sites();{$z}/{$num_rows} entries... in", $perc);
        $FamilySite = $GLOBALS["Q"]->GetFamilySites($ligne["sitename"]);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$ligne["sitename"]} categories = {$categories}\n";
        }
        thumbnail_site($ligne["sitename"]);
        if ($FamilySite != null) {
            $FamilySite_update = ",familysite='{$FamilySite}'";
            if (strpos(" {$categories}", ",") > 0) {
                $bb = explode(",", $categories);
                while (list($hh, $ii) = each($bb)) {
                    if (trim($ii) == null) {
                        continue;
                    }
                    $mmd5 = md5("{$FamilySite}{$ii}");
                    $ROWS_visited_sites_catz[] = "('{$mmd5}','{$FamilySite}','{$ii}')";
                }
            } else {
                $mmd5 = md5("{$FamilySite}{$categories}");
                $ROWS_visited_sites_catz[] = "('{$mmd5}','{$FamilySite}','{$categories}')";
            }
            if (count($ROWS_visited_sites_catz) > 1500) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "visited_sites_catz:: 1500\n";
                }
                $GLOBALS["Q"]->QUERY_SQL($ROWS_visited_sites_prefix . @implode(",", $ROWS_visited_sites_catz));
                $ROWS_visited_sites_catz = array();
            }
        }
        $categories = addslashes($categories);
        $sql = "UPDATE visited_sites SET HitsNumber='{$array[0]}',Querysize='{$array[1]}'{$country},category='{$categories}'{$FamilySite_update} WHERE sitename='{$ligne["sitename"]}'";
        $GLOBALS["Q"]->QUERY_SQL($sql);
    }
    if (count($ROWS_visited_sites_catz) > 0) {
        $GLOBALS["Q"]->QUERY_SQL($ROWS_visited_sites_prefix . @implode(",", $ROWS_visited_sites_catz));
        $ROWS_visited_sites_catz = array();
    }
    $took = $unix->distanceOfTimeInWords($t1, time());
    ufdbguard_admin_events("Scanned {$num_rows} visisted websites {$took}", __FUNCTION__, __FILE__, __LINE__, "visited");
    visited_sites_whois();
    WeekDaysNums();
}