Ejemplo n.º 1
0
$unix = new unix();
$GLOBALS["CLASS_UNIX"] = $unix;
events("Executed " . @implode(" ", $argv));
$sock = new sockets();
if (!is_dir("/var/log/artica-postfix/artica-squid-events")) {
    @mkdir("/var/log/artica-postfix/artica-squid-events", 644, true);
}
$squidEnableRemoteStatistics = $sock->GET_INFO("squidEnableRemoteStatistics");
if (!is_numeric($squidEnableRemoteStatistics)) {
    $squidEnableRemoteStatistics = 0;
}
if ($squidEnableRemoteStatistics == 1) {
    events("this server is not in charge of statistics...");
    die;
}
if (!ifMustBeExecuted()) {
    if ($GLOBALS["VERBOSE"]) {
        echo "this server is not in charge of statistics (categories repositories or Statistics Appliance) ...\n";
    }
    events("this server is not in charge of statistics (categories repositories or Statistics Appliance) ...");
    die;
}
if ($GLOBALS["VERBOSE"]) {
    echo "LAUNCH: '{$argv[1]}'\n";
}
if ($argv[1] == '--scan-hours') {
    scan_hours();
    die;
}
if ($argv[1] == '--scan-months') {
    scan_months();
Ejemplo n.º 2
0
function downloads()
{
    if (!ifMustBeExecuted()) {
        return;
    }
    $working_dir = $GLOBALS["working_directory"];
    $unix = new unix();
    $sql = "SELECT * FROM updates_categories WHERE filesize>0";
    $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 while retreive update list {$q->mysql_error}", __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;
        if (!is_dir(dirname($targetfile))) {
            echo "Creating directory " . dirname($targetfile) . "\n";
            @mkdir(dirname($targetfile), 0755, true);
        }
        if (CheckTargetFile($targetfile, $ligne["filesize"])) {
            echo "{$filename} skipped...\n";
            continue;
        }
        UpdateCategories($filename, 10, "{downloading}", 0);
        $curl = new ccurl("http://www.artica.fr/{$filename}");
        echo "Downloading http://www.artica.fr/{$filename}\n";
        if (!$curl->GetFile($targetfile)) {
            echo "Fatal error downloading http://www.artica.fr/{$filename}\n";
            ufdbguard_admin_events("Fatal: unable to download {$filename}", __FUNCTION__, __FILE__, __LINE__, "update");
            UpdateCategories($filename, 0, "{error}", 0);
            continue;
        }
        if (CheckTargetFile($targetfile, $ligne["filesize"])) {
            UpdateCategories($filename, 20, "{downloaded}", 0);
        }
        echo "{$filename} success...\n";
    }
}
Ejemplo n.º 3
0
function CoherenceOffiels()
{
    if (!ifMustBeExecuted()) {
        WriteMyLogs("No make sense to execute this script...", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "No make sense to execute this script...\n";
        }
        die;
    }
    $workdir = "/var/lib/ftpunivtlse1fr";
    $unix = new unix();
    $BASE_URI = "ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib";
    $q = new mysql_squid_builder();
    $table = $q->TLSE_CONVERTION(true);
    $ARRAYSUM_REMOTE = GET_MD5S_REMOTE();
    while (list($database, $articacat) = each($table)) {
        $directory = str_replace("/", "_", $articacat);
        $targetdir = $workdir . "/{$database}";
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . ":: Checking {$targetdir}/domains\n";
        }
        if (!is_file("{$targetdir}/domains")) {
            ufdbguard_admin_events("{$database} is not in disk... download it..", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB");
            update_remote_file($BASE_URI, "{$database}.tar.gz", $ARRAYSUM_REMOTE["{$database}.tar.gz"]);
        }
    }
    reset($table);
    while (list($database, $articacat) = each($table)) {
        $directory = str_replace("/", "_", $articacat);
        $targetdir = $workdir . "/{$directory}";
        $sourcedir = $workdir . "/{$database}";
        @chmod($sourcedir, 0755);
        $unix->chown_func("squid", "squid", $sourcedir);
        if (!is_dir($targetdir)) {
            if ($GLOBALS["VERBOSE"]) {
                echo __FUNCTION__ . ":: Checking {$targetdir} no such directory make symbolic to {$sourcedir}\n";
            }
            shell_exec("ln -sf {$sourcedir} {$targetdir}");
        }
    }
    if (count($GLOBALS["squid_admin_mysql"])) {
        squid_admin_mysql(2, count($GLOBALS["squid_admin_mysql"]) . " Toulouse Databases updated", @implode("\n", $GLOBALS["squid_admin_mysql"]));
        unset($GLOBALS["squid_admin_mysql"]);
    }
}
Ejemplo n.º 4
0
function week_uris($asPid = false)
{
    if (!ifMustBeExecuted()) {
        ufdbguard_admin_events("Not necessary to execute this task...", __FUNCTION__, __FILE__, __LINE__, "stats");
        return;
    }
    if ($asPid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        $myfile = basename(__FILE__);
        $unix = new unix();
        if ($unix->process_exists($pid, $myfile)) {
            ufdbguard_admin_events("{$pid} already running, aborting", __FUNCTION__, __FILE__, __LINE__, "stats");
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    visited_websites_by_day(true);
    if ($GLOBALS["VERBOSE"]) {
        echo "Search tables sources in tables_day\n";
    }
    $sql = "SELECT tablename,DATE_FORMAT( zDate, '%Y%m%d' ) AS tablesource, \n\tDAYOFWEEK(zDate) as DayNumber,WEEK( zDate ) AS tweek, YEAR( zDate ) AS tyear \n\tFROM tables_day WHERE weekdone =0 AND zDate < DATE_SUB( NOW( ) , INTERVAL 1 DAY ) ORDER BY zDate";
    if ($GLOBALS["VERBOSE"]) {
        echo $sql . "\n";
    }
    $unix = new unix();
    $results = $GLOBALS["Q"]->QUERY_SQL($sql);
    if ($GLOBALS["VERBOSE"]) {
        echo "Search tables sources in tables_day:: " . mysql_num_rows($results) . " rows\n";
    }
    if (!$GLOBALS["Q"]->ok) {
        writelogs_squid("Fatal: {$q->mysql_error} on `tables_day`", __FUNCTION__, __FILE__, __LINE__, "stats");
        return false;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $week_table = "{$ligne["tyear"]}{$ligne["tweek"]}_week";
        if ($GLOBALS["VERBOSE"]) {
            echo "******\n\nWeek table ->`{$week_table}`\n\n******\n";
        }
        if (!$GLOBALS["Q"]->CreateWeekTable($week_table)) {
            writelogs_squid("Fatal: {$GLOBALS["Q"]->mysql_error} on `{$week_table}` (CREATE)", __FUNCTION__, __FILE__, __LINE__, "stats");
            continue;
        }
        $DayNumber = $ligne["DayNumber"];
        $tablesource = "{$ligne["tablesource"]}_hour";
        if (!$GLOBALS["Q"]->TABLE_EXISTS($tablesource)) {
            if ($GLOBALS["Q"]->TABLE_EXISTS("dansguardian_events_{$ligne["tablesource"]}")) {
                $next_table = $tablesource;
                ufdbguard_admin_events("Create lost day table {$tablesource} from dansguardian_events_{$ligne["tablesource"]}", __FUNCTION__, __FILE__, __LINE__, "stats");
            } else {
                ufdbguard_admin_events("Fatal, lost day table {$tablesource} and lost working table dansguardian_events_{$ligne["tablesource"]}, skipping", __FUNCTION__, __FILE__, __LINE__, "stats");
                continue;
            }
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "_week_uris_perform({$tablesource},{$week_table},{$DayNumber})\n";
        }
        $t = time();
        if (_week_uris_perform($tablesource, $week_table, $DayNumber)) {
            $GLOBALS["Q"]->QUERY_SQL("UPDATE tables_day SET weekdone=1 WHERE tablename='{$ligne["tablename"]}'");
            $took = $unix->distanceOfTimeInWords($t, time(), true);
            writelogs_squid("Success update day Number {$DayNumber} from {$tablesource} to {$week_table} in {$took}", __FUNCTION__, __FILE__, __LINE__, "stats");
        }
    }
    members_central();
    WeekDaysNums();
    youtube_week();
}