function content()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $t = $_GET["t"];
    $ff = time();
    $ID = $_GET["ID"];
    if (!is_numeric($t)) {
        $t = time();
    }
    $rp = new squid_report($ID);
    $html = "\n\t<div class=BodyContent>\n\t\t<div style='font-size:14px'>\n\t\t\t<a href=\"miniadm.index.php\">{myaccount}</a>\n\t\t\t&nbsp;&raquo;&nbsp;<a href=\"miniadm.webstats-start.php?t={$t}\">{web_statistics}</a>\n\t\t\t&nbsp;&raquo;&nbsp;<a href=\"miniadm.MembersTrack.php\">{member_wwwtrack}</a>\n\t\t</div>\n\t\t<H1>{$rp->report}</H1>\n\t\t<p>" . $rp->explain() . "</p>\n\t</div>\t\n\t<div id='webstats-middle-{$ff}'></div>\n\t\n\t<script>\n\t\tLoadAjax('webstats-middle-{$ff}','{$page}?webstats-middle=yes&t={$t}&ID={$ID}');\n\t\t{$jsadd}\n\t</script>\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
function csv_download()
{
    $ID = $_GET["csv"];
    $rp = new squid_report($ID);
    $data = $rp->loadcsv();
    header('Content-type: application/gzip');
    header('Content-Transfer-Encoding: binary');
    header("Content-Disposition: attachment; filename=\"report{$ID}.csv.gz\"");
    header("Pragma: public");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    // Date dans le passé
    $fsize = strlen($data);
    header("Content-Length: " . $fsize);
    ob_clean();
    flush();
    echo $data;
}
Example #3
0
function build_report($ID, $nopid = false)
{
    if (!is_numeric($ID)) {
        ufdbguard_admin_events("Not a numeric ID", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    $t = time();
    $unix = new unix();
    $tablename = "WebTrackMem{$ID}";
    $tableBlock = "WebTrackMeB{$ID}";
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid";
        $pid = @file_get_contents($pidfile);
        if ($pid < 100) {
            $pid = null;
        }
        if ($unix->process_exists($pid, basename(__FILE__))) {
            ufdbguard_admin_events("Already executed pid {$pid}", __FUNCTION__, __FILE__, __LINE__, "reports");
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Building report {$ID}\n";
    }
    $q = new mysql_squid_builder();
    if ($q->TABLE_EXISTS($tablename)) {
        $q->DELETE_TABLE($tablename);
    }
    if ($q->TABLE_EXISTS($tableBlock)) {
        $q->DELETE_TABLE($tableBlock);
    }
    if (!$q->CreateMemberReportTable($tablename)) {
        ufdbguard_admin_events("could not create table {$tablename}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    if (!$q->CreateMemberReportBlockTable($tableBlock)) {
        ufdbguard_admin_events("could not create table {$tablename}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    $rp = new squid_report($ID);
    $LIST_TABLES_dansguardian_events = $q->LIST_TABLES_dansguardian_events();
    progress(10, $ID);
    $counttables = count($LIST_TABLES_dansguardian_events);
    $prefix = "INSERT IGNORE INTO {$tablename} (`zMD5`,`sitename`,`familysite`,`{$rp->userfield}`,`zDate`,`size`,`hits`,`category`) VALUES ";
    while (list($sourcetable, $ligne) = each($LIST_TABLES_dansguardian_events)) {
        $c++;
        $sql = $rp->BuildQuery($sourcetable);
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}\n{$sql}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Parsing {$sourcetable} \n{$sql}\n-> `" . mysql_num_rows($results) . "` rows\n";
        }
        if (mysql_num_rows($results) == 0) {
            continue;
        }
        $purc = round($c / $counttables, 2) * 100;
        progress($purc, $ID);
        $f = array();
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $md5 = md5(serialize($ligne));
            $sitename = $ligne["sitename"];
            $familysite = $q->GetFamilySites($sitename);
            if (!isset($GLOBALS["CATEGORY"][$sitename])) {
                $GLOBALS["CATEGORY"][$sitename] = $q->GET_CATEGORIES($sitename);
            }
            $category = $GLOBALS["CATEGORY"][$sitename];
            $source = addslashes($ligne["source"]);
            $zDate = $ligne["zDate"];
            $size = $ligne["size"];
            $hits = $ligne["hits"];
            $category = addslashes($category);
            $f[] = "('{$md5}','{$sitename}','{$familysite}','{$source}','{$zDate}','{$size}','{$hits}','{$category}')";
        }
        if (count($f) == 0) {
            continue;
        }
        $q->QUERY_SQL($prefix . @implode(",", $f));
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if (system_is_overloaded(__FILE__)) {
            sleep(5);
        }
    }
    if ($rp->csv == 1) {
        SaveCSV($ID);
    }
    $LIST_TABLES_BLOCKED = $q->LIST_TABLES_BLOCKED();
    $prefix = "INSERT IGNORE INTO {$tableBlock} (`zMD5`,`zDate`,`hits`,`website`,`category`,`rulename`,`event`,`why`,`explain`,`blocktype`,`{$rp->userfield}`) VALUES ";
    while (list($sourcetable, $ligne) = each($LIST_TABLES_BLOCKED)) {
        $c++;
        if ($GLOBALS["VERBOSE"]) {
            echo "Parsing {$sourcetable}\n";
        }
        $sql = $rp->BuildQueryBlock($sourcetable);
        if (!$q->FIELD_EXISTS("{$sourcetable}", "uid")) {
            $q->QUERY_SQL("ALTER TABLE `{$sourcetable}` ADD `uid` VARCHAR( 128 ) NOT NULL ,ADD INDEX ( `uid` )");
        }
        $results = $q->QUERY_SQL($sql);
        if (!$q->ok) {
            ufdbguard_admin_events("{$q->mysql_error}\n{$sql}", __FUNCTION__, __FILE__, __LINE__, "reports");
            return;
        }
        if (mysql_num_rows($results) == 0) {
            continue;
        }
        $purc = round($c / $counttables, 2) * 100;
        progress($purc, $ID);
        $f = array();
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $zMD5 = md5(serialize($ligne));
            $sitename = $ligne["sitename"];
            $category = $ligne["category"];
            if ($category == null) {
                if (!isset($GLOBALS["CATEGORY"][$sitename])) {
                    $GLOBALS["CATEGORY"][$sitename] = $q->GET_CATEGORIES($sitename);
                }
                $category = $GLOBALS["CATEGORY"][$sitename];
            }
            $source = addslashes($ligne["source"]);
            $zDate = $ligne["zDate"];
            $hits = $ligne["hits"];
            $rulename = $ligne["rulename"];
            $event = $ligne["event"];
            $why = $ligne["why"];
            $explain = $ligne["explain"];
            $blocktype = $ligne["blocktype"];
            $category = addslashes($category);
            $f[] = "('{$zMD5}','{$zDate}','{$hits}','{$sitename}','{$category}','{$rulename}','{$event}','{$why}','{$explain}','{$blocktype}','{$source}')";
        }
        if (system_is_overloaded(__FILE__)) {
            sleep(5);
        }
    }
    $myisamchk = $unix->find_program("myisamchk");
    $myisampack = $unix->find_program("myisampack");
    $mysql_data = $unix->MYSQL_DATA_DIR();
    echo "OPTIMIZE TABLE {$tableBlock}\n";
    $q->QUERY_SQL("OPTIMIZE TABLE {$tableBlock}");
    echo "OPTIMIZE TABLE {$tablename}\n";
    $q->QUERY_SQL("OPTIMIZE TABLE {$tablename}");
    echo "LOCK TABLE {$tablename}\n";
    $q->QUERY_SQL("LOCK TABLE {$tablename} WRITE");
    echo "LOCK TABLE {$tableBlock}\n";
    $q->QUERY_SQL("LOCK TABLE {$tableBlock} WRITE");
    $q->QUERY_SQL("FLUSH TABLE {$tableBlock}");
    $q->QUERY_SQL("FLUSH TABLE {$tablename}");
    echo "myisamchk {$tablename}\n";
    shell_exec("{$myisamchk} -cFU {$mysql_data}/squidlogs/{$tablename}.MYI");
    echo "myisamchk {$tableBlock}\n";
    shell_exec("{$myisamchk} -cFU {$mysql_data}/squidlogs/{$tableBlock}.MYI");
    echo "myisampack {$tablename}\n";
    shell_exec("{$myisampack} -f {$mysql_data}/squidlogs/{$tablename}.MYI");
    echo "myisampack {$tableBlock}\n";
    shell_exec("{$myisampack} -f {$mysql_data}/squidlogs/{$tableBlock}.MYI");
    $q->QUERY_SQL("FLUSH TABLE {$tablename}");
    $q->QUERY_SQL("FLUSH TABLE {$tableBlock}");
    $rp->set_duration($unix->distanceOfTimeInWords($t, time(), true));
    progress(100, $ID);
}