Exemple #1
0
function view_stats()
{
    if (!privs()) {
        die;
    }
    $ou = $_GET["ou"];
    $users = new usersMenus();
    sql_domain($ou);
    $sql = "SELECT COUNT( ID ) AS tcount, DATE_FORMAT( time_stamp, '%m-%d' ) AS tday\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -7\nDAY )\nGROUP BY DATE_FORMAT( time_stamp, '%m-%d' )";
    $q = new mysql();
    //echo $sql;
    $g = new artica_graphs($fileName, 60);
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $g->ydata[] = $ligne["tcount"];
        $g->xdata[] = $ligne["tday"];
    }
    //print_r($g->ydata);
    $fileName = "/usr/share/artica-postfix/ressources/logs/web/{$ou}-stats-7.png";
    $g->title = "Inbound messages";
    $g->x_title = "messages number";
    $g->y_title = "days-month";
    $g->width = 700;
    $g->filename = $fileName;
    $g->line_green();
    echo "<img src='ressources/logs/web/{$ou}-stats-7.png'>";
}
function page()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    $t = time();
    $sql = "SELECT zDate,not_categorized FROM tables_day ORDER BY zDate";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["tdate"];
        $ydata[] = $ligne["not_categorized"];
    }
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . ".png";
    $gp = new artica_graphs();
    $gp->width = 880;
    $gp->height = 350;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    if (!is_file($targetedfile)) {
        writelogs("Fatal \"{$targetedfile}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
        $targetedfile = "img/kas-graph-no-datas.png";
    }
    $sql = "SELECT zDate,not_categorized FROM tables_day WHERE not_categorized>0 ORDER BY zDate DESC";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    $c = 0;
    $table = null;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $c++;
        $table = $table . "<tr>\n\t\t\t<td style='font-size:14px' width=99%><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.visited.php?day={$ligne["zDate"]}&onlyNot=yes');\" style='font-size:14px;text-decoration:underline'>{$ligne["zDate"]}</a></td>\n\t\t\t<td style='font-size:14px' width=1%><strong>{$ligne["not_categorized"]}</strong></td>\n\t\t</tr>\n\t\t";
        if ($c > 10) {
            $c = 0;
            $tr[] = "<table style='width:20%' class=form><tbody>{$table}</tbody></table>";
            $table = null;
        }
    }
    if ($c > 0) {
        $tr[] = "<table style='width:20%' class=form><tbody>{$table}</tbody></table>";
    }
    $t = time();
    echo $tpl->_ENGINE_parse_body("\n\t<div id='{$t}'>\n\t<div style='font-size:18px'>{not_categorized}/{days}</div>\n\t\n\t<center>\n\t<div style='margin:8px;float-right;width:100%'>" . button("{analyze}", "NoCategorizedAnalyze()") . "</div>\n\t<img src='{$targetedfile}?t=" . time() . "'>\n\t</center>\n\t" . CompileTrGen($tr, 6) . "\n\t</div>\n\t</div>\n\t<script>\n\t\t\n\tvar x_NoCategorizedAnalyze= function (obj) {\n\t\t\tvar tempvalue=obj.responseText;\n\t\t\tif(tempvalue.length>3){alert(tempvalue)};\n\t\t\tif(document.getElementById('squid_stats_consumption')){\n\t    \t\tRefreshTab('squid_stats_consumption');\n\t\t\t}\n\t\t\t\n\t\t\tif(document.getElementById('squid_stats_central')){\n\t    \t\tRefreshTab('squid_stats_central');\n\t\t\t}\t\t\t\n\t\t}\t\n\n\t\tfunction NoCategorizedAnalyze(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('NoCategorizedAnalyze','yes');\n\t\t\tAnimateDiv('{$t}');\n\t\t\tXHR.sendAndLoad('{$page}', 'POST',x_NoCategorizedAnalyze);\n\t\t}\n\t</script>\t\t\n\t\n\t");
}
Exemple #3
0
function popup()
{
    $tpl = new templates();
    $time = time();
    echo "<div style='width:98%' class=form>";
    $sql = "SELECT DATE_FORMAT(zDate,'%H') as tdate,AVG(download) as tbandwith FROM speedtests \n\tWHERE DATE_FORMAT(zDate,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d') \n\tGROUP BY DATE_FORMAT(zDate,'%H')\n\tORDER BY zDate";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><code>{$sql}</code>";
        return;
    }
    $fileName = "ressources/logs/web/bandwith-day.png";
    $g = new artica_graphs($fileName, 10);
    if (mysql_num_rows($results) > 1) {
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $g->ydata[] = round($ligne["tbandwith"], 0);
            $g->xdata[] = $ligne["tdate"];
        }
        $g->title = $tpl->_ENGINE_parse_body("{today}: {bandwith} KBi/s");
        $g->x_title = "hours";
        $g->y_title = null;
        $g->width = 650;
        $g->line_green();
        @chmod($fileName, 0777);
        echo "<center style='margin:5px'><img src='ressources/logs/web/bandwith-day.png?{$time}'</center>";
    }
    $sql = "SELECT YEARWEEK(zDate) as tweek,AVG(download) as tbandwith,DAYOFMONTH(zDate) as tdate \nFROM speedtests WHERE YEARWEEK(zDate)=YEARWEEK(NOW()) GROUP BY DAYOFMONTH(zDate) ORDER BY DAYOFMONTH(zDate) ";
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><code>{$sql}</code>";
        return;
    }
    $fileName = "ressources/logs/web/bandwith-week.png";
    $g = new artica_graphs($fileName, 10);
    if (mysql_num_rows($results) > 1) {
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $g->ydata[] = round($ligne["tbandwith"], 0);
            $g->xdata[] = $ligne["tdate"];
        }
        $g->title = $tpl->_ENGINE_parse_body("{this_week}: {bandwith} KBi/s");
        $g->x_title = "day";
        $g->y_title = null;
        $g->width = 650;
        $g->line_green();
        @chmod($fileName, 0777);
        echo "<center style='margin:5px'><img src='ressources/logs/web/bandwith-week.png?{$time}'</center>";
    }
    echo "</div>";
}
function page()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $week = $_GET["week"];
    $year = $_GET["year"];
    $familysite = $_GET["familysite"];
    $t = time();
    $tablename = "{$year}{$week}_week";
    $sql = "SELECT `day`,SUM(hits) as hits,SUM(size) as size FROM {$tablename} GROUP BY `day`,familysite HAVING familysite='{$familysite}'";
    $q = new mysql_squid_builder();
    $timeZ = $q->WEEK_TOTIMEHASH_FROM_TABLENAME($tablename);
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $tpl->_ENGINE_parse_body(date("{l}", $timeZ[$ligne["day"]]));
        $ydata[] = $ligne["hits"];
        $ydata2[] = round($ligne["size"] / 1024 / 1000);
    }
    $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . "." . $sql) . ".6.png";
    $gp = new artica_graphs();
    $gp->width = 938;
    $gp->height = 250;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $t = time();
    $gp->line_green();
    if (is_file($targetedfile)) {
        $image = "<center>\n\t<p style='font-size:18px'>{$familysite}: {requests_during_this_week}</p>\n\t<img src='{$targetedfile}'></center>";
    }
    reset($xdata);
    $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . "." . $sql) . ".7.png";
    $gp = new artica_graphs();
    $gp->width = 938;
    $gp->height = 250;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata2;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $t = time();
    $gp->line_green();
    if (is_file($targetedfile)) {
        $image2 = "<center>\n\t<p style='font-size:18px'>{$familysite}: {size_during_this_week} (MB)</p>\n\t<img src='{$targetedfile}'></center>";
    }
    $html = "\n\t{$image}\n\t{$image2}\n\t<hr>\n\t<div id='{$t}'></div>\n\t<script>\n\t\tLoadAjax('{$t}','{$page}?sites-tables=yes&familysite={$familysite}&week={$_GET["week"]}&year={$_GET["year"]}');\n\t</script>\n\t";
    echo $html;
}
function GraphLast24H()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $uid = $_GET["uid"];
    $cmp = new computers($uid);
    $MAC = $cmp->ComputerMacAddress;
    $sql = "SELECT DATE_FORMAT(zDate,'%Y-%m-%d %H') as tdate , SUM(live) as tl,MAC FROM computers_available\n\tGROUP BY DATE_FORMAT(zDate,'%Y-%m-%d %H'),MAC\n\tHAVING MAC='{$MAC}' AND tdate>DATE_SUB(NOW(),INTERVAL 24 HOUR) ORDER BY tdate";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) == 0) {
        echo $tpl->_ENGINE_parse_body("{$title}<center style='margin:50px'><H2>{error_no_datas}</H2>{$sql}</center>");
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ttdate = explode(" ", $ligne["tdate"]);
        $xdata[] = $ttdate[1];
        $ydata[] = $ligne["tl"];
    }
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . ".day." . md5("{$_GET["uid"]}") . ".png";
    $gp = new artica_graphs();
    $gp->width = 550;
    $gp->height = 220;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{hours}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    $image = "<center style='margin-top:10px'><img src='{$targetedfile}'></center>";
    if (!is_file($targetedfile)) {
        writelogs("Fatal \"{$targetedfile}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
        $image = null;
    }
    echo $tpl->_ENGINE_parse_body($html . $image);
}
Exemple #6
0
function week_categories_graph($xtime = 0)
{
    $tpl = new templates();
    $cache_file = "/usr/share/artica-postfix/ressources/logs/web/" . basename(__FILE__) . "." . md5(serialize($_GET)) . "." . __FUNCTION__ . '.cache';
    $time = file_time_min_Web($cache_file);
    //if($time<360){echo @file_get_contents($cache_file);return;}
    if ($xtime == 0) {
        $d = date("W");
        $sqlq = "WEEK(days)=WEEK(NOW())";
    }
    if ($xtime == 1) {
        $d = date("Y-m");
        $sqlq = "MONTH(days)=MONTH(NOW())";
    }
    $page = CurrentPageName();
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/squid.{$d}.categories.png", 0);
    //$gp->ImageMap="javascript:Loadjs('squid.stats.category.php?category-js=yes&time=week&category=";
    $html = "<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t<th>{hits}</th>\n\t<th>{websites}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    $sql = "SELECT SUM(website_hits) as tsum,category FROM squid_events_sites_day WHERE \n\t{$sqlq} AND YEAR(days)=YEAR(NOW()) GROUP BY category ORDER BY tsum DESC LIMIT 0,10";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (mysql_num_rows($results) == 0) {
        $tpl = new templates();
        echo $tpl->_ENGINE_parse_body("<H2>{NO_DATA_COME_BACK_LATER}</H2>");
        return;
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if (trim($ligne["category"]) == null) {
            $ligne["category"] = "unknown";
        }
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $js = "Loadjs('squid.stats.category.php?category-js=yes&time={$xtime}&category=" . urlencode($ligne["category"]) . "')";
        $html = $html . "\n\t\t\t<tr class={$classtr}>\n\t\t\t<td style='font-size:15px'><a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\">{$ligne["tsum"]}</a></td>\n\t\t\t<td style='font-size:15px'><a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\">{$ligne["category"]}</a></td>\n\t\t\t</tr>";
        $gp->xdata[] = $ligne["tsum"];
        $gp->ydata[] = $ligne["category"];
    }
    $gp->width = 560;
    $gp->height = 580;
    $gp->ViewValues = false;
    $gp->x_title = "{categories}";
    $gp->pie();
    $html = $tpl->_ENGINE_parse_body("<img src='ressources/logs/web/squid.{$d}.categories.png'  border=0><hr>{$html}</table>");
    @file_put_contents($cache_file, $html);
    echo $html;
}
function top10()
{
    $tpl = new templates();
    $q = new mysql();
    $sql = "SELECT SUM(emails) as conx,delivery_domain FROM smtp_logs_day \n\tGROUP BY delivery_domain ORDER BY conx DESC LIMIT 0,10";
    $html = "\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th>{mails}</th>\n\t\t<th>{domains}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    $filename = "postfix.domains.top.png";
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/{$filename}", 50);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $js = "Loadjs('postfix.stats.single-domain.php?domain=" . urlencode($ligne["delivery_domain"]) . "')";
        $style = " style='text-decoration:underline' ";
        $html = $html . "\n\t<tr class={$classtr}>\n\t\t\t<td style='font-size:14px;font-weight:bold' width=1% align='center'><a href=\"javascript:blur()\" OnClick=\"javascript:{$js}\">{$ligne["conx"]}</a></td>\n\t\t\t<td style='font-size:14px;font-weight:bold' nowrap width=99%><a href=\"javascript:blur()\" OnClick=\"javascript:{$js}\" {$style}>{$ligne["delivery_domain"]}</a></td>\n\t\t</tr>\n\t";
        $gp->xdata[] = $ligne["conx"];
        $gp->ydata[] = $ligne["delivery_domain"];
    }
    $table[] = "</table>";
    $time = time();
    $gp->width = 560;
    $gp->height = 580;
    $gp->ViewValues = false;
    $gp->x_title = "{ipaddr}";
    $gp->pie();
    echo "<center><img src='ressources/logs/web/{$filename}?time={$time}'></center>";
    echo "<hr>";
    echo $tpl->_ENGINE_parse_body("{$html}</table>");
}
function right()
{
    $q = new mysql_squid_builder();
    $page = CurrentPageName();
    $tpl = new templates();
    if (!isset($_GET["day"])) {
        $_GET["day"] = date('Y-m-d');
    }
    $title_style = "font-size:16px;width:100%;font-weight:bold;text-decoration:underline";
    $day = $_GET["day"];
    $time = strtotime("{$day} 00:00:00");
    $table = date("YW", $time) . "_week";
    echo "<!-- LINE:" . __LINE__ . ">\n";
    $_GET["week"] = date("W", $time);
    $_GET["year"] = date("Y", $time);
    $tt = getDaysInWeek($_GET["week"], $_GET["year"]);
    foreach ($tt as $dayTime) {
        $f[] = date('{l} d {F}', $dayTime);
    }
    if ($_GET["field-user"] != null) {
        $title_add = "<br>{{$_GET["field-user"]}}:{$_GET["field-user-value"]}";
        $fieldadd = "{$_GET["field-user"]},";
        $GROUP_SELECT = " HAVING `{$_GET["field-user"]}`='{$_GET["field-user-value"]}'";
    }
    echo "<script>\n\t\tLoadAjax('statistics-week-left-status','{$page}?left-status=yes&day={$_GET["day"]}');\n\t</script>\n\t";
    echo "<!-- LINE:" . __LINE__ . ">\n";
    $sourcetable = "{$_GET["year"]}{$_GET["week"]}_week";
    $title00 = $tpl->_ENGINE_parse_body("\n\t<center style='font-size:16px;width:100%;font-weight:bold;margin:10px'>\n\t\t\t{week}:&nbsp;{from}&nbsp;{$f[0]}&nbsp;{to}&nbsp;{$f[6]}{$title_add}\n\t</center>");
    if (!$q->TABLE_EXISTS($sourcetable)) {
        echo $tpl->_ENGINE_parse_body("{$title}<center style='margin:50px'>\n\t\t<H2>{$sourcetable}:{error_no_datas} ({$sourcetable} no such table)</H2></center>");
    }
    echo "<!-- LINE:" . __LINE__ . ">\n";
    $sql = "SELECT {$fieldadd}category,SUM(hits) as totalsize FROM {$sourcetable} GROUP BY {$fieldadd}category {$GROUP_SELECT} ORDER BY totalsize DESC LIMIT 0,10";
    $title0 = TITLE_SQUID_STATSTABLE($sql, "{statistics}:&nbsp;{week}:{$_GET["week"]} ({categories} TOP 10){$title_add}");
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["totalsize"];
        $ydata[] = $ligne["category"];
    }
    echo "<!-- LINE:" . __LINE__ . ">\n";
    $targetedfilePie = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".pie.png";
    $gp = new artica_graphs($targetedfilePie);
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->width = 550;
    $gp->height = 550;
    $gp->ViewValues = true;
    $gp->x_title = $tpl->_ENGINE_parse_body("{top_websites}");
    $gp->pie();
    echo "<!-- LINE:" . __LINE__ . ">\n";
    $sql = "SELECT {$fieldadd}SUM(hits) as totalsize,`day` FROM {$sourcetable} GROUP BY {$fieldadd}`day` {$GROUP_SELECT} ORDER BY `day`";
    $title1 = TITLE_SQUID_STATSTABLE($sql, "{statistics}:&nbsp;{week}:{$_GET["week"]} ({requests}){$title_add}");
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) == 0) {
        echo $tpl->_ENGINE_parse_body("{$title00}\n\t<center style='margin:50px'>\n\t\t<H2>{error_no_datas}</H2>\n\t\t<i>{$sourcetable} (no such data in line " . __LINE__ . ")</i>\n\t</center>");
        return;
    }
    $weeksd = array(1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday");
    $xdata = array();
    $ydata = array();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $tpl->_ENGINE_parse_body("{{$weeksd[$ligne["day"]]}}");
        $ydata[] = $ligne["totalsize"];
    }
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".png";
    $gp = new artica_graphs();
    $gp->width = 550;
    $gp->height = 350;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    if (!is_file($targetedfile)) {
        writelogs("Fatal \"{$targetedfile}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
    }
    $sql = "SELECT {$fieldadd}SUM(size) as totalsize,`day` FROM {$sourcetable} GROUP BY {$fieldadd}`day` {$GROUP_SELECT} ORDER BY `day`";
    $title2 = TITLE_SQUID_STATSTABLE($sql, "{statistics}:&nbsp;{week}:{$_GET["week"]} ({downloaded_flow} MB){$title_add}");
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) == 0) {
        echo $tpl->_ENGINE_parse_body("\n\t\t{$title00}\n\t\t<center style='margin:50px'>\n\t\t\t<H2>{error_no_datas}</H2><i>{$sourcetable} no such data (no such data in line " . __LINE__ . ")</i>\n\t\t</center>");
    }
    $weeksd = array(1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday");
    $xdata = array();
    $ydata = array();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $tpl->_ENGINE_parse_body("{{$weeksd[$ligne["day"]]}}");
        $ydata[] = round($ligne["totalsize"] / 1024 / 1000);
    }
    $targetedfile2 = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".png";
    $gp = new artica_graphs();
    $gp->width = 550;
    $gp->height = 350;
    $gp->filename = "{$targetedfile2}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    if (!is_file($targetedfile2)) {
        writelogs("Fatal \"{$targetedfile2}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
    }
    $html = "\n\t{$title00}\n\t<div class=RoundedGrey>\n\t\t{$title0}\n\t\t<img src='{$targetedfilePie}' style='margin:10px'>\n\t</div>\n\t<div class=RoundedGrey>\n\t{$title1}<img src='{$targetedfile}' style='margin:10px'>\n\t</div>\n\t<div class=RoundedGrey>\n\t{$title2}\n\t<img src='{$targetedfile2}' style='margin:10px'>\n\t</div>\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
Exemple #9
0
function status()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $infos = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-showvminfo=yes&uuid=" . base64_encode($_GET["uuid"]))));
    $paragraphe = Paragraphe(oslistIMG($infos["GUEST OS"]), "{$infos["NAME"]}", "<hr>{$infos["GUEST OS"]}");
    $kill_process = $tpl->javascript_parse_text("{kill_process}");
    $pid_array = unserialize(base64_decode($sock->getFrameWork("cmd.php?VboxPid={$_GET["uuid"]}")));
    if ($pid_array["PID"] > 1) {
        $ini = new Bs_IniHandler();
        $ini->loadString($pid_array["INFOS"]);
        $status = "\n\t\t<table class=form style='width:218px'>\n\t\t\t<tr>\n\t\t\t<td align='right' nowrap class=legend><strong>{pid}:</strong></td>\n\t\t\t<td><strong style='font-size:13px'>{$ini->_params["APP_VIRTUALBOX"]["master_pid"]}</strong></td>\n\t\t\t<td>" . imgtootltip("ed_delete.gif", "{kill_process}", "VirtBoxKill('{$ini->_params["APP_VIRTUALBOX"]["master_pid"]}');") . "</td>\n\t\t</tr>\t\t\t\n\t\t<tr>\n\t\t\t<td align='right' class=legend><strong>{memory}:</strong></td>\n\t\t\t<td colspan=2><strong style='font-size:13px'>" . FormatBytes($ini->_params["APP_VIRTUALBOX"]["master_memory"]) . "</strong></td>\n\t\t</tr>\t\t\n\t\t<tr>\n\t\t\t<td align='right' class=legend><strong>{virtual_memory}:</strong></td>\n\t\t\t<td colspan=2><strong style='font-size:13px'>" . FormatBytes($ini->_params["APP_VIRTUALBOX"]["master_cached_memory"]) . "</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=3><div style='text-align:right'><i style='font-size:13px'>{since}: {$ini->_params["APP_VIRTUALBOX"]["uptime"]}</i></div></td>\n\t\t</tr>\n\t\t</table>\n\t\t\n\t\t<script>\n\t\t\n\tvar X_VirtBoxKill= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);}\n\t\tRefreshTab('main_config_{$_GET["uuid"]}');\n\t\tRefreshVirtualBoxList();\n\t}\n\t\t\n\t\t\tfunction VirtBoxKill(pid){\n\t\t\t\tif(confirm('{$kill_process} '+pid+'?')){\n\t\t\t\t\tvar XHR = new XHRConnection();\n\t\t\t\t\tXHR.appendData('pid-kill',pid);\n\t\t\t\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\t\t\t\tXHR.sendAndLoad('{$page}', 'GET',X_VirtBoxKill);\n\t\t\t\t}\n\t\t\t\n\t\t\t}\n\t</script>\n\t\t";
    }
    $APP_NO_VBOXADDITIONS = $tpl->javascript_parse_text("{APP_NO_VBOXADDITIONS}");
    if (preg_match("#([0-9]+)#", $infos["CONFIGURED MEMORY BALLOON SIZE"], $re)) {
        $memoryballon = $re[1];
    }
    if (preg_match("#([0-9]+)#", $infos["MEMORY SIZE"], $re)) {
        $memory_size = $re[1];
    }
    if (preg_match("#([0-9]+)#", $infos["VRAM SIZE"], $re)) {
        $vram = $re[1];
    }
    $MEMORY_BALLON_ASK_MB = $tpl->_ENGINE_parse_body("{MEMORY_BALLON_ASK_MB}");
    $MEMORY_SIZE_ASK = $tpl->_ENGINE_parse_body("{MEMORY_SIZE_ASK}");
    $virtual_box_cpus = $tpl->_ENGINE_parse_body("{virtual_box_cpus}");
    if (strlen($infos["ADDITIONS ACTIVE"]) > 0) {
        if ($infos["ADDITIONS ACTIVE"] == "no") {
            $ADDITIONSimg = "<img src='img/status_warning.gif'>";
        }
        $infos["ADDITIONS ACTIVE"] = "{{$infos["ADDITIONS ACTIVE"]}}";
    }
    if ($infos["PAGE FUSION"] == "off") {
        $pagefusion = 0;
    }
    if ($infos["PAGE FUSION"] == "on") {
        $pagefusion = 1;
    }
    if ($infos["NESTED PAGING"] == "off") {
        $nestedpaging = 0;
    }
    if ($infos["NESTED PAGING"] == "on") {
        $nestedpaging = 1;
    }
    if ($infos["LARGE PAGES"] == "on") {
        $largepages = 1;
    }
    if ($infos["LARGE PAGES"] == "off") {
        $largepages = 0;
    }
    if ($infos["VT-X VPID"] == "on") {
        $vtxvpid = 1;
    }
    if ($infos["VT-X VPID"] == "off") {
        $vtxvpid = 0;
    }
    if ($infos["ACPI"] == "on") {
        $acpi = 1;
    }
    if ($infos["ACPI"] == "off") {
        $acpi = 0;
    }
    if ($infos["IOAPIC"] == "on") {
        $ioapic = 1;
    }
    if ($infos["IOAPIC"] == "off") {
        $ioapic = 0;
    }
    if ($infos["HPET"] == "on") {
        $hpet = 1;
    }
    if ($infos["HPET"] == "off") {
        $hpet = 0;
    }
    $html = "\n\n\n\n<table style='width:100%'>\n<tr>\n<td valign='top'>{$paragraphe}<br>{$status}</td>\n<td valign='top'>\n\t<table style='width:100%'>\n\t\n\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{APP_VBOXADDITIONS}:</td>\n\t\t<td style='font-size:13px;' nowrap>{$infos["ADDITIONS ACTIVE"]}</td>\n\t\t<td align='center'>{$ADDITIONSimg}</td>\n\t</tr>\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>\n\t\t\t<a href='javascript:blur();' OnClick=\"javascript:VboxMemory()\" \n\t\t\tstyle='text-decoration:underline'>{physical_memory}</a>:</td>\n\t\t<td style='font-size:13px;'>{$infos["MEMORY SIZE"]}</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\n\t\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap><a href='javascript:blur();' OnClick=\"javascript:VboxVram()\" \n\t\t\tstyle='text-decoration:underline'>{vramsize}:</td>\n\t\t<td style='font-size:13px;'>{$infos["VRAM SIZE"]}</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap><a href='javascript:blur();' OnClick=\"javascript:guestmemoryballoon()\" style='text-decoration:underline'>{guestmemoryballoon}:</a></td>\n\t\t<td style='font-size:13px;' nowrap>{$infos["CONFIGURED MEMORY BALLOON SIZE"]}</a></td>\n\t\t<td>" . help_icon("{guestmemoryballoon_text}") . "</td>\n\t</tr>\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{pagefusion}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("pagefusion", 1, $pagefusion, "pagefusion()") . "</td>\n\t\t<td></td>\n\t</tr>\t\t\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>\n\t\t<a href='javascript:blur();' OnClick=\"javascript:VboxCpus()\" style='text-decoration:underline'>{virtual_box_cpus}:</a></td>\n\t\t<td style='font-size:13px;'>{$infos["NUMBER OF CPUS"]}</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{vtxvpid}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("vtxvpid", 1, $vtxvpid, "vtxvpid()") . "</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\n\t\n\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{acpi}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("acpi", 1, $acpi, "acpi()") . "</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\n\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{ioapic}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("ioapic", 1, $ioapic, "ioapic()") . "</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{hpet}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("hpet", 1, $hpet, "hpet()") . "</td>\n\t\t<td>" . help_icon("{hpet_text}") . "</td>\n\t</tr>\n\n\t\n\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{nestedpaging}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("nestedpaging", 1, $nestedpaging, "nestedpaging()") . "</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\n\t</tr>\t\n\t\t<td class=legend style='font-size:13px;' nowrap>{largepages}:</td>\n\t\t<td style='font-size:13px;'>" . Field_checkbox("largepages", 1, $largepages, "largepages()") . "</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\t\t\t\n\t<tr>\n\t\n\t<tr>\n\t\t<td class=legend style='font-size:13px;' nowrap>{accelerate3d}:</td>\n\t\t<td style='font-size:13px;'>{$infos["3D ACCELERATION"]}</td>\n\t\t<td>&nbsp;</td>\n\t</tr>\t\n\t</table>\n\t</td>\n</tr>\n</table>\n<script>\n\nvar X_guestmemoryballoon= function (obj) {\n\tvar results=obj.responseText;\n\tif(results.length>0){alert(results);}\n\tRefreshTab('main_config_{$_GET["uuid"]}');\n\t}\n\t\n\t\n\tfunction guestmemoryballoon(){\n\t\tvar additions='{$infos["ADDITIONS ACTIVE"]}';\n\t\tif(additions.length>0){\n\t\t\tif(additions!=='yes'){\n\t\t\t\talert('{$APP_NO_VBOXADDITIONS}');\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\tvar ballon=prompt('{$MEMORY_BALLON_ASK_MB}','{$memoryballon}');\n\t\tif(ballon){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('guestmemoryballoon',ballon);\n\t\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\t\n\t\t}\n\t}\n\t\n\tfunction VboxMemory(){\n\t\tvar ballon=prompt('{$MEMORY_SIZE_ASK}','{$memory_size}');\n\t\tif(ballon){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('guestmemory',ballon);\n\t\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\t\n\t\t}\n\t}\n\n\tfunction VboxCpus(){\n\tvar ballon=prompt('{$virtual_box_cpus}','{$infos["NUMBER OF CPUS"]}');\n\t\tif(ballon){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('VboxCpus',ballon);\n\t\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\t\n\t\t}\n\t\n\t}\n\t\n\t\n\tfunction VboxVram(){\n\t\tvar ballon=prompt('{$MEMORY_SIZE_ASK}','{$vram}');\n\t\tif(ballon){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('vram',ballon);\n\t\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\t\n\t\t}\n\t}\t\t\n\t\n\t\n\t\n\t\n\tfunction nestedpaging(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('nestedpaging').checked){XHR.appendData('nestedpaging',1);}else{XHR.appendData('nestedpaging',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\n\t\n\tfunction vtxvpid(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('vtxvpid').checked){XHR.appendData('vtxvpid',1);}else{XHR.appendData('vtxvpid',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\n\n\tfunction acpi(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('acpi').checked){XHR.appendData('acpi',1);}else{XHR.appendData('acpi',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\t\n\tfunction ioapic(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('ioapic').checked){XHR.appendData('ioapic',1);}else{XHR.appendData('ioapic',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\t\t\n\tfunction pagefusion(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('pagefusion').checked){XHR.appendData('pagefusion',1);}else{XHR.appendData('pagefusion',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\n\tfunction hpet(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('hpet').checked){XHR.appendData('hpet',1);}else{XHR.appendData('hpet',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\t\t\n\t\n\t\n\t\n\tfunction largepages(){\n\t\tvar XHR = new XHRConnection();\n\t\tif(document.getElementById('largepages').checked){XHR.appendData('largepages',1);}else{XHR.appendData('largepages',0);}\n\t\tXHR.appendData('uuid','{$_GET["uuid"]}');\n\t\tXHR.sendAndLoad('{$page}', 'GET',X_guestmemoryballoon);\n\t}\t\n</script>\n\n\n\n\t";
    $stats = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-showcpustats=yes&virtual-machine=" . base64_encode($infos["NAME"]))));
    if (is_array($stats["CPU_LOAD_KERNEL_TABLE"])) {
        $fileName = dirname(__FILE__) . "/ressources/logs/{$_GET["uuid"]}-cpu-kernel.png";
        $g = new artica_graphs($fileName, 1);
        while (list($index, $data) = each($stats["CPU_LOAD_KERNEL_TABLE"])) {
            $g->ydata[] = $data;
            $g->xdata[] = "";
        }
        $g->title = 'CPU Kernel';
        $g->x_title = "%";
        $g->y_title = $tpl->_ENGINE_parse_body("{seconds}");
        $g->width = 600;
        $g->line_green();
        $html = $html . "<hr><center style='margin-top:10px'><img src='ressources/logs/{$_GET["uuid"]}-cpu-kernel.png'></center>";
    }
    echo $tpl->_ENGINE_parse_body($html);
}
function month(){
	$tpl=new templates();
	$sql="SELECT WEEK( zDate) AS ttime2, WEEK( zDate) AS ttime, SUM( size ) as tsize, cached FROM squid_cache_perfs 
	WHERE zDate > DATE_SUB( NOW( ) , INTERVAL 6 MONTH ) AND YEAR(zDate)=YEAR(NOW()) GROUP BY ttime,ttime2, cached ORDER BY ttime2";
	
	$q=new mysql();
	$results=$q->QUERY_SQL($sql,"artica_events");
	if(!$q->ok){echo $q->mysql_error;return;}		
	$count=mysql_num_rows($results);
	
	if(mysql_num_rows($results)==0){return;}	
	
	if(!$q->ok){echo $q->mysql_error;}
	while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		$size=$ligne["tsize"]/1024;
		$size=$size/1000;
		if($ligne["cached"]==1){
			$ydata2[]=$size;
		}else{
			$ydata[]=$size;
		}
		$time[$ligne["ttime"]]=$ligne["ttime"];
		
	}
	
	while (list ($path, $array) = each ($time) ){
		$xdata[]=$path;
	}
	
	$gp=new artica_graphs();
	$gp->width=650;
	$gp->height=500;
	$gp->filename="ressources/logs/squid-caches-months.png";
	$gp->xdata=$xdata;
	$gp->ydata=$ydata;
	$gp->ydata2=$ydata2;
	$gp->y_title=null;
	$gp->x_title=$tpl->_ENGINE_parse_body("{week}");
	$gp->title=null;
	$gp->margin0=true;
	$gp->Fillcolor="blue@0.9";
	$gp->color="146497";
	$tpl=new templates();
	$gp->LineLegend=$tpl->javascript_parse_text("{not_cached}");
	$gp->LineLegend2=$tpl->javascript_parse_text("{cached}");
	//$gp->SetFillColor('green'); 
	
	$gp->line_green_double();	
	echo "<center><img src='ressources/logs/squid-caches-months.png'></center>";	
	
}	
function generate_graph()
{
    include_once 'ressources/class.artica.graphs.inc';
    $q = new mysql_squid_builder();
    $page = CurrentPageName();
    $tpl = new templates();
    $t = $_GET["t"];
    $ff = time();
    $year = $_GET["year"];
    $week = $_GET["week"];
    $tablename_prod = "{$year}{$week}_blocked_week";
    $WEEKZ = $q->WEEK_TOTIMEHASH_FROM_TABLENAME($tablename_prod);
    $sql = "SELECT SUM(hits) as tcount,`day` FROM {$tablename_prod} GROUP BY `day` ORDER BY `day`";
    $c = 0;
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) > 0) {
        $nb_events = mysql_num_rows($results);
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $xdata[] = $tpl->_ENGINE_parse_body(date("{l}", $WEEKZ[$ligne["day"]]));
            $ydata[] = $ligne["tcount"];
            $c++;
        }
        $t = time();
        $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . ".day.{$tablename}") . ".png";
        $gp = new artica_graphs();
        $gp->width = 920;
        $gp->height = 350;
        $gp->filename = "{$targetedfile}";
        $gp->xdata = $xdata;
        $gp->ydata = $ydata;
        $gp->y_title = null;
        $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
        $gp->title = null;
        $gp->margin0 = true;
        $gp->Fillcolor = "blue@0.9";
        $gp->color = "146497";
        $gp->line_green();
        if (is_file($targetedfile)) {
            echo "<center>\n\t\t\t<div style='font-size:18px;margin-bottom:10px'>" . $tpl->_ENGINE_parse_body("{blocked}/{day}") . "</div>\n\t\t\t<img src='{$targetedfile}'></center>";
        }
    }
}
function hour()
{
    $page = CurrentPageName();
    $GLOBALS["CPU_NUMBER"] = intval($users->CPU_NUMBER);
    $cpunum = $GLOBALS["CPU_NUMBER"] + 1;
    $sql = "SELECT AVG( `load` ) AS sload, DATE_FORMAT( stime, '%i' ) AS ttime FROM `loadavg` WHERE `stime` > DATE_SUB( NOW( ) , INTERVAL 60 MINUTE ) GROUP BY ttime ORDER BY `ttime` ASC";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    if (mysql_num_rows($results) == 0) {
        return;
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    $c = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $size = $ligne["tsize"] / 1024;
        $size = $size / 1000;
        $xdata[] = $ligne["ttime"];
        $ydata[] = $ligne["sload"];
        $c++;
        if ($ligne["sload"] > $cpunum) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<li>!!!! {$ligne["stime"]} -> {$c}</LI>";
            }
            if (!isset($red["START"])) {
                $red["START"] = $c;
            }
        } else {
            if (isset($red["START"])) {
                $area[] = array($red["START"], $c);
                unset($red);
            }
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "<li>{$ligne["stime"]} -> {$ligne["ttime"]} -> {$ligne["sload"]}</LI>";
        }
    }
    if (isset($red["START"])) {
        $area[] = array($red["START"], $c);
    }
    $file = time();
    $gp = new artica_graphs();
    $gp->RedAreas = $area;
    $gp->width = 650;
    $gp->height = 350;
    $gp->filename = "ressources/logs/loadavg-hour.png";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = "Mn";
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $tpl = new templates();
    //$gp->SetFillColor('green');
    $gp->line_green();
    echo "\n\t<div id='loadavg-clean'>\n\t<img src='ressources/logs/loadavg-hour.png'></div></div>\n\t<div style='text-align:right'><hr>" . $tpl->_ENGINE_parse_body(button("{clean_datas}", "LoadAvgClean()")) . "</div>\n\t<script>\n\t\n\tvar x_LoadAvgClean=function(obj){\n      var tempvalue=obj.responseText;\n\t  if(tempvalue.length>3){alert(tempvalue);}\n      YahooWin3Hide();\n      document.getElementById('loadavggraph').innerHTML='';\n      }\t\n\t\n\tfunction LoadAvgClean(){\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('LoadAvgClean','yes');\n\t\t\n\t\tAnimateDiv('loadavg-clean');\n\t\tXHR.sendAndLoad('{$page}', 'POST',x_LoadAvgClean);\t\t\n\t\t}\t\n\t\n\t\n\t</script>";
}
Exemple #13
0
function week()
{
    $page = CurrentPageName();
    $GLOBALS["CPU_NUMBER"] = intval($users->CPU_NUMBER);
    $cpunum = $GLOBALS["CPU_NUMBER"] + 1;
    $sql = "SELECT AVG( `load` ) AS sload, DATE_FORMAT( stime, '%d' ) AS ttime FROM `loadavg` WHERE `stime` > DATE_SUB( NOW( ) , INTERVAL 7 DAY ) GROUP BY ttime ORDER BY `ttime` ASC";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    if (mysql_num_rows($results) == 0) {
        return;
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    $c = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $size = $ligne["tsize"] / 1024;
        $size = $size / 1000;
        $xdata[] = $ligne["ttime"];
        $ydata[] = $ligne["sload"];
        $c++;
        if ($ligne["sload"] > $cpunum) {
            if ($GLOBALS["VERBOSE"]) {
                echo "<li>!!!! {$ligne["stime"]} -> {$c}</LI>";
            }
            if (!isset($red["START"])) {
                $red["START"] = $c;
            }
        } else {
            if (isset($red["START"])) {
                $area[] = array($red["START"], $c);
                unset($red);
            }
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "<li>{$ligne["stime"]} -> {$ligne["ttime"]} -> {$ligne["sload"]}</LI>";
        }
    }
    $tpl = new templates();
    if ($c < 2) {
        echo "<H2>" . $tpl->_ENGINE_parse_body("{error_no_datas}") . "</H2>";
        return;
    }
    if (isset($red["START"])) {
        $area[] = array($red["START"], $c);
    }
    $file = time();
    $gp = new artica_graphs();
    $gp->RedAreas = $area;
    $gp->width = 650;
    $gp->height = 350;
    $gp->filename = "ressources/logs/loadavg-7d.png";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->javascript_parse_text("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    //$gp->SetFillColor('green');
    $gp->line_green();
    $time = time();
    echo "<img src='ressources/logs/loadavg-7d.png'></div>";
}
function members_first_graph(){
	$page=CurrentPageName();
	$tpl=new templates();	
	$q=new mysql_squid_builder();
	$gp=new artica_graphs();
	if(!isset($_GET["month"])){
		$currentmonth=date('Y-m');
		$currentmonthText=date('F');
		$tablesrc=date("Ym")."_members";
	}else{
		$date=strtotime($_GET["month"]."-". date('d'). "00:00:00");
		$currentmonth=$_GET["month"];
		$currentmonthText=date('F',$date);
		$tablesrc=date('Ym',$date)."_members";
	}
	
	if(!$q->TABLE_EXISTS($tablesrc)){$q->CreateMembersDayTable();}
	
	if(!$q->TABLE_EXISTS($tablesrc)){
		echo $tpl->_ENGINE_parse_body("<center style='margin:50px'><H2>L.".__LINE__." {error_no_datas}<hr>$tablesrc No such table</hr></H2></center><script>LoadAjax('month-list-members','$page?month-list-members=yes');</script>");
		return;
	}
	
	
	$sql="SELECT COUNT(zMD5) as tcount,`day` FROM `$tablesrc` GROUP BY `day` ORDER BY `day`";
	$results=$q->QUERY_SQL($sql);
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><center style='font-size:11px'><code>$sql</code></center>";}
	$table="
	<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:10%'>
<thead class='thead'>
	<tr>
	<th width=1%>{days}</th>
	<th>{members}</th>
	</tr>
</thead>
<tbody>";	
	
	
	while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		
		if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
		$table=$table."
			<tr class=$classtr>
				<td width=1%  style='font-size:14px' nowrap align=center><strong>{$ligne["day"]}</strong></td>
				<td  style='font-size:14px' nowrap width=99% align=center><strong>{$ligne["tcount"]}</td>
			</tr>
			";		
			
			$gp->xdata[]=$ligne["day"];
			$gp->ydata[]=$ligne["tcount"];
	}
	
	
	$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".$tablesrc.png";
	$gp->width=550;
	$gp->height=350;
	$gp->filename="$targetedfile";
	$gp->y_title=null;
	$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
	$gp->title=null;
	$gp->margin0=true;
	$gp->Fillcolor="blue@0.9";
	$gp->color="146497";
	$gp->line_green();
	if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);$targetedfile="img/kas-graph-no-datas.png";}

	$html="
	<center style='font-size:14px;font-weight:bold'>{months}</center>
	<div id='month-list-members'></div>
	<div style='font-size:16px'>{number_of_users} {{$currentmonthText}} $currentmonth</div>
	<center>
		<img src='$targetedfile'>
	</center>
	$table</tbody></table>
	</center>

	
	<script>
		LoadAjax('month-list-members','$page?month-list-members=yes');
	</script>
	";
	
	echo $tpl->_ENGINE_parse_body($html);
	
		
}
Exemple #15
0
function week()
{
    $type = $_GET["type"];
    $page = CurrentPageName();
    $GLOBALS["CPU_NUMBER"] = intval($users->CPU_NUMBER);
    $cpunum = $GLOBALS["CPU_NUMBER"] + 1;
    $sql = "SELECT AVG( `{$type}` ) AS sload, DATE_FORMAT( zDate, '%d' ) AS ttime FROM `kav4proxy_av_stats` WHERE `zDate` > DATE_SUB( NOW( ) , INTERVAL 7 DAY ) GROUP BY ttime ORDER BY `ttime` ASC";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    if (mysql_num_rows($results) == 0) {
        return;
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    $c = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $size = $ligne["tsize"] / 1024;
        $size = $size / 1000;
        $xdata[] = $ligne["ttime"];
        $ydata[] = $ligne["sload"];
        $c++;
    }
    $tpl = new templates();
    $file = time();
    $gp = new artica_graphs();
    $gp->RedAreas = $area;
    $gp->width = 650;
    $gp->height = 350;
    $gp->filename = "ressources/logs/kav4-{$type}-7d.png";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->javascript_parse_text("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    //$gp->SetFillColor('green');
    $gp->line_green();
    $time = time();
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body("<div class=explain>{kav4_{$type}_text}</div>");
    echo "<img src='ressources/logs/kav4-{$type}-7d.png'></div>";
}
function query_perform(){
	$page=CurrentPageName();
	$tpl=new templates();
	$q=new mysql_squid_builder();
	$day=$_GET["day"];
	$time=strtotime("$day 00:00:00");
	$tableWeek=date("YW",$time)."_week";	
	$tableDay=date("Ymd",$time)."_day";
	$category=$_GET["category"];
	$DAYNUM=false;
	$weeksd=array(1 => "Sunday", 2 => "Monday",3=>"Tuesday",4=>"Wednesday",5=>"Thursday",6=>"Friday",7=>"Saturday");
	
	if($_GET["field-search"]<>null){
		$title_add="{$_GET["field-search"]}:{$_GET["data-search"]}";
		$FIELDADD="`{$_GET["field-search"]}`,";
		$HAVING=" AND `{$_GET["field-search"]}`='{$_GET["data-search"]}'";
	}
	
	switch ($_GET["TimeType"]) {
		case "week":$table=$tableWeek;$FIELD_TIME="day";$DAYNUM=true; break;
		default:$table=$tableDay;$FIELD_TIME="hour";
		break;
	}
	
	
	$sql="SELECT {$FIELDADD}SUM(hits) as thits,category,$FIELD_TIME FROM $table GROUP BY {$FIELDADD}category,$FIELD_TIME HAVING `category`='$category'$HAVING   ORDER BY $FIELD_TIME";
	$results=array();
	$results=$q->QUERY_SQL($sql);
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><hr><code style='font-size:12px'>$sql</code><hr>";}
	$title=TITLE_SQUID_STATSTABLE($sql,"{statistics}:&nbsp;$category&nbsp;{{$_GET["TimeType"]}}:{$_GET["day"]} ({requests})&nbsp;$title_add");
	if(mysql_num_rows($results)>1){
		while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
			$x=$ligne[$FIELD_TIME];
			if($DAYNUM){$x=$weeksd[$ligne[$FIELD_TIME]];}
			$xdata[]=$x;
			$ydata[]=$ligne["thits"];
		}
		$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".". md5($sql).".png";
		$gp=new artica_graphs();
		$gp->width=400;
		$gp->height=350;
		$gp->filename="$targetedfile";
		$gp->xdata=$xdata;
		$gp->ydata=$ydata;
		$gp->y_title=null;
		$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
		$gp->title=null;
		$gp->margin0=true;
		$gp->Fillcolor="blue@0.9";
		$gp->color="146497";
	
		$gp->line_green();
		if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);}		
		
			
		$html[]="<div class=RoundedGrey>$title<img src='$targetedfile' style='margin:10px'></div>";
	}else{
		
		$ligne=array();
		$ligne=mysql_fetch_array($results);
		$htmlHeader="<center><table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'><thead class='thead'><tr>";
		while (list ($a, $b) = each ($ligne) ){if(is_numeric($a)){continue;}if($a=="category"){continue;}$heads[]="<th>{{$a}}</th>";$datas[]="<td style='font-size:14px'>$b</td>";}
		$html[]="<div class=RoundedGrey>$title$htmlHeader". @implode("\n", $heads)."</tr><tr>". @implode("\n", $datas)."</tr></tbody></table></div>";
		
		
	}
		
	
// ------------------------------------------------------------------------------------------------------------------------------------------------
	@mysql_free_result($results);
	$sql="SELECT {$FIELDADD}SUM(size) as tsize,category,$FIELD_TIME FROM $table GROUP BY {$FIELDADD}category,$FIELD_TIME HAVING `category`='$category'$HAVING   ORDER BY $FIELD_TIME";
	$results=array();
	
	$results=$q->QUERY_SQL($sql);
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><hr><code style='font-size:12px'>$sql</code><hr>";}
	unset($xdata);unset($ydata);
	$title=TITLE_SQUID_STATSTABLE($sql,"{statistics}:&nbsp;$category&nbsp;{{$_GET["TimeType"]}}:{$_GET["day"]} ({downloaded_flow} MB)&nbsp;$title_add");
if(mysql_num_rows($results)>1){	
		while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
			$x=$ligne[$FIELD_TIME];
			if($DAYNUM){$x=$weeksd[$ligne[$FIELD_TIME]];}		
			$xdata[]=$x;
			$ydata[]=round(($ligne["tsize"]/1024)/1000);
		}
		$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".". md5($sql).".png";
		$gp=new artica_graphs();
		$gp->width=400;
		$gp->height=350;
		$gp->filename="$targetedfile";
		$gp->xdata=$xdata;
		$gp->ydata=$ydata;
		$gp->y_title=null;
		$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
		$gp->title=null;
		$gp->margin0=true;
		$gp->Fillcolor="blue@0.9";
		$gp->color="146497";
	
		$gp->line_green();
		if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);}		
		
			
		$html[]="<div class=RoundedGrey>$title<img src='$targetedfile' style='margin:10px'></div>";	
	}else{
		$ligne=array();
		$ligne=mysql_fetch_array($results);
		$htmlHeader="<center><table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'><thead class='thead'><tr>";
		while (list ($a, $b) = each ($ligne) ){
			if(isset($already[$a])){continue;}
			if($a=="category"){continue;}
			if(is_numeric($a)){continue;}
			$heads[]="<th>{{$a}}</th>";
			$datas[]="<td style='font-size:14px'>$b</td>";
		}
		$html[]="<div class=RoundedGrey>$title$htmlHeader". @implode("\n", $heads)."</tr><tr>". @implode("\n", $datas)."</tr></tbody></table></div>";
		
		
	}
	
// ------------------------------------------------------------------------------------------------------------------------------------------------	
	@mysql_free_result($results);unset($xdata);unset($ydata);
	$sql="SELECT {$FIELDADD}SUM(hits) as requests,category,familysite as sitename FROM $table GROUP BY {$FIELDADD}category,familysite HAVING `category`='$category'$HAVING   ORDER BY requests DESC LIMIT 0,10";
	$results=array();
	
	$results=$q->QUERY_SQL($sql);
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><hr><code style='font-size:12px'>$sql</code><hr>";}
	unset($xdata);unset($ydata);
	$title=TITLE_SQUID_STATSTABLE($sql,"{statistics}:&nbsp;$category&nbsp;{{$_GET["TimeType"]}}:{$_GET["day"]} (TOP 10 {websites} {requests})&nbsp;$title_add");
if(mysql_num_rows($results)>1){	
		while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		$xdata[]=$ligne["requests"];
		$ydata[]=$ligne["sitename"];
		}
		$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".". md5($sql).".png";
		$gp=new artica_graphs();
		$gp->width=400;
		$gp->height=350;
		$gp->filename="$targetedfile";
		$gp->xdata=$xdata;
		$gp->ydata=$ydata;
		$gp->y_title=null;
		$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
		$gp->title=null;
		$gp->margin0=true;
		$gp->Fillcolor="blue@0.9";
		$gp->color="146497";
	
		$gp->pie();
		if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);}		
		
			
		$html2[]="<div class=RoundedGrey>$title<img src='$targetedfile' style='margin:10px'></div>";	
	}else{
		$ligne=array();
		$ligne=mysql_fetch_array($results);
		$htmlHeader="<center><table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'><thead class='thead'><tr>";
		while (list ($a, $b) = each ($ligne) ){
			if(isset($already[$a])){continue;}
			if($a=="category"){continue;}
			if(is_numeric($a)){continue;}
			$heads[]="<th>{{$a}}</th>";
			$datas[]="<td style='font-size:14px'>$b</td>";
		}
		$html2[]="<div class=RoundedGrey>$title$htmlHeader". @implode("\n", $heads)."</tr><tr>". @implode("\n", $datas)."</tr></tbody></table></div>";
		
		
	}	
	
// ------------------------------------------------------------------------------------------------------------------------------------------------	
	@mysql_free_result($results);unset($xdata);unset($ydata);
	$sql="SELECT {$FIELDADD}SUM(size) as totalsize,category,familysite as sitename FROM $table GROUP BY {$FIELDADD}category,familysite HAVING `category`='$category'$HAVING   ORDER BY totalsize DESC LIMIT 0,10";
	$results=array();
	
	$results=$q->QUERY_SQL($sql);
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><hr><code style='font-size:12px'>$sql</code><hr>";}
	unset($xdata);unset($ydata);
	$title=TITLE_SQUID_STATSTABLE($sql,"{statistics}:&nbsp;$category&nbsp;{{$_GET["TimeType"]}}:{$_GET["day"]} (TOP 10 {websites} {downloaded_flow})&nbsp;$title_add");
if(mysql_num_rows($results)>1){	
		while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		$xdata[]=$ligne["totalsize"];
		$ydata[]=$ligne["sitename"];
		}
		$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".". md5($sql).".png";
		$gp=new artica_graphs();
		$gp->width=400;
		$gp->height=350;
		$gp->filename="$targetedfile";
		$gp->xdata=$xdata;
		$gp->ydata=$ydata;
		$gp->y_title=null;
		$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
		$gp->title=null;
		$gp->margin0=true;
		$gp->Fillcolor="blue@0.9";
		$gp->color="146497";
	
		$gp->pie();
		if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);}		
		
			
		$html2[]="<div class=RoundedGrey>$title<img src='$targetedfile' style='margin:10px'></div>";	
	}else{
		$ligne=array();
		$ligne=mysql_fetch_array($results);
		$htmlHeader="<center><table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'><thead class='thead'><tr>";
		while (list ($a, $b) = each ($ligne) ){
			if(isset($already[$a])){continue;}
			if($a=="category"){continue;}
			if(is_numeric($a)){continue;}
			$heads[]="<th>{{$a}}</th>";
			$datas[]="<td style='font-size:14px'>$b</td>";
		}
		$html2[]="<div class=RoundedGrey>$title$htmlHeader". @implode("\n", $heads)."</tr><tr>". @implode("\n", $datas)."</tr></tbody></table></div>";
		
		
	}	
	echo 
	"<table style='width:100%'>
	<tbody>
	<tr>
	<td width=50% valign='top'>".$tpl->_ENGINE_parse_body(@implode("\n", $html))."</td>
	<td width=50% valign='top'>".$tpl->_ENGINE_parse_body(@implode("\n", $html2))."</td>
	</tr>
	</tbody>
	</table>
	";
	
	
}
function general_status_cache_graphs(){
	$page=CurrentPageName();
	$tpl=new templates();		
	
	
	
	$q=new mysql_squid_builder();	
	$selected_date="{last_30days}";
	$filter="zDate>DATE_SUB(NOW(),INTERVAL 30 DAY) AND zDate<DATE_SUB(NOW(),INTERVAL 1 DAY)";
	$file_prefix="default";
	
	if($_GET["from"]<>null){
		$filter="zDate>='{$_GET["from"]}' AND zDate<='{$_GET["to"]}'";
		$selected_date="{from_date} {$_GET["from"]} - {to_date} {$_GET["to"]}";
		$default_from_date=$_GET["from"];
		$default_to_date=$_GET["to"];
		$file_prefix="$default_from_date-$default_to_date";
	}
	
	if($_GET["type"]<>null){
		if($_GET["type"]=="req"){
			$field="requests as totalsize";
			$prefix_title="{requests}";
			$hasSize=false;
		}
	}	
	
	
	$sql="SELECT size_cached as totalsize,DATE_FORMAT(zDate,'%d') as tdate FROM tables_day WHERE $filter ORDER BY zDate";
	
	$results=$q->QUERY_SQL($sql);

	if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
	while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		$xdata[]=$ligne["tdate"];
		$ydata[]=round(($ligne["totalsize"]/1024)/1000);
	}
	
	$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".cache-perf.$file_prefix.png";
	$gp=new artica_graphs();
	$gp->width=550;
	$gp->height=350;
	$gp->filename="$targetedfile";
	$gp->xdata=$xdata;
	$gp->ydata=$ydata;
	$gp->y_title=null;
	$gp->x_title=$tpl->_ENGINE_parse_body("{days}");
	$gp->title=null;
	$gp->margin0=true;
	$gp->Fillcolor="blue@0.9";
	$gp->color="146497";

	$gp->line_green();
	if(!is_file($targetedfile)){writelogs("Fatal \"$targetedfile\" no such file!",__FUNCTION__,__FILE__,__LINE__);return;}
	echo $tpl->_ENGINE_parse_body("<div ><h3>{cache} (MB) /{days} - $selected_date</h3>
	<center>
	<img src='$targetedfile'>
	</center>
	</div>");
	
}
Exemple #18
0
function squid_events_hours()
{
    $today = date('Y-m-d');
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/squid.{$today}.wwsize.png", 50);
    if (!$gp->checkfile()) {
        return "<img src='ressources/logs/web/squid.{$today}.wwsize.png'>";
    }
    $sql = "SELECT hour,hits,www_size FROM squid_events_hours WHERE `day`='{$today}'";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    $count = mysql_num_rows($results);
    writelogs($count . " rows", __FUNCTION__, __FILE__, __LINE__);
    if (mysql_num_rows($results) == 0) {
        $tpl = new templates();
        return $tpl->_ENGINE_parse_body("<H2>{NO_DATA_COME_BACK_LATER}</H2>");
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["hour"];
        $ziz = round($ligne["www_size"] / 1024);
        $ziz = $ziz / 1000;
        $ydata[] = $ziz;
    }
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = "MB";
    $gp->x_title = "Hours";
    $gp->title = null;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    return "<img src='ressources/logs/web/squid.{$today}.wwsize.png'>";
}
function zoom_day()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $field = $_GET["field"];
    $value = $_GET["value"];
    $familysite = $_GET["familysite"];
    $daytime = $_GET["daytime"];
    $table_name = date("Ymd", $daytime) . "_hour";
    $daytitle = date("{l} d {F}", $daytime);
    $q = new mysql_squid_builder();
    $month_table = "quotamonth_" . date("Ym");
    $month_text = date("{F}");
    if ($q->COUNT_ROWS($month_table) == 0) {
        $month_text = date("{F}", strtotime('first day of previous month'));
        $month_table = "quotamonth_" . date("Ym", strtotime('first day of previous month'));
    }
    $sql = "SELECT `hour` as thour,SUM(size) as QuerySize,SUM(hits) as hits FROM \n\t`{$table_name}`  WHERE `{$field}`='{$value}' AND familysite='{$familysite}' GROUP BY thour ORDER BY thour";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H3>Warning<hr>{$sql}<hr>{$q->mysql_error}</H3>";
    }
    if (mysql_num_rows($results) == 0) {
        $reqests = "{search} {requests} {from} {$value} {to} {$familysite} {$title_add}";
        echo FATAL_ERROR_SHOW_128("{this_request_contains_no_data}<hr>{$reqests}");
        return;
    }
    if (mysql_num_rows($results) < 2) {
        if (mysql_num_rows($results) == 1) {
            while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
                $size = FormatBytes($ligne["QuerySize"] / 1024);
                $day = $ligne["thour"];
                $timstr = strtotime(date("Y-m-d", $daytime) . " {$day}:00:00");
                $html = $html . "<div style='width:99%' style='font-size:16px;' class=form>\n\t\t\t\t{$field}:{$value}&nbsp;&raquo; {size}:{$size}, {$ligne["hits"]} {hits} " . date('{l} d {F} H:00', $timstr) . "\n\t\t\t\n\t\t\t</div>";
            }
            echo $tpl->_ENGINE_parse_body($html);
            return;
        }
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $size = round($ligne["QuerySize"] / 1024 / 1000);
        $day = $ligne["thour"];
        $xdata[] = $day;
        $xdata2[] = $day;
        $ydata[] = $size;
        $ydata2[] = $ligne["hits"];
    }
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".png";
    $targetedfile2 = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . "." . md5($sql) . ".2.png";
    $gp = new artica_graphs();
    $gp->width = 650;
    $gp->height = 350;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = $tpl->_ENGINE_parse_body("{size}");
    $gp->x_title = $tpl->_ENGINE_parse_body("{hours}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    $gp2 = new artica_graphs();
    $gp2->width = 650;
    $gp2->height = 350;
    $gp2->filename = "{$targetedfile2}";
    $gp2->xdata = $xdata2;
    $gp2->ydata = $ydata2;
    $gp2->y_title = $tpl->_ENGINE_parse_body("{hits}");
    $gp2->x_title = $tpl->_ENGINE_parse_body("{hours}");
    $gp2->title = null;
    $gp2->margin0 = true;
    $gp2->Fillcolor = "blue@0.9";
    $gp2->color = "146497";
    $gp2->line_green();
    if (!is_file($targetedfile)) {
        writelogs("Fatal \"{$targetedfile}\" no such file!", __FUNCTION__, __FILE__, __LINE__);
    } else {
        $html = $html . "\n\t\t<center>\n\t\t\t<div style='width:99%' class=form>\n\t\t\t\t<div style='font-size:18px;margin:8px'>&laquo;{$value}&raquo;{$familysite}&nbsp;{downloaded_size_per_hour} (MB)</div>\n\t\t\t\t<img src='{$targetedfile}'>\n\t\t\t</div>\n\t\t\t\n\t\t\t<div style='width:99%' class=form>\n\t\t\t\t<div style='font-size:18px;margin:8px'>&laquo;{$value}&raquo;{$familysite}&nbsp;{requests_per_hour}</div>\n\t\t\t\t<img src='{$targetedfile2}'>\n\t\t\t</div>\t\t\t\n\t\t</center>\n\t\t\n\t\t";
    }
    echo $tpl->_ENGINE_parse_body($html);
}
Exemple #20
0
function InstantIptablesStats()
{
    $tpl = new templates();
    echo "<CENTER><div style='font-size:16px'>Instant Iptables Month " . date("Y-m") . "</div>";
    include_once 'ressources/class.artica.graphs.inc';
    $sql = "SELECT COUNT(ID) as tcount,DATE_FORMAT(saved_date,'%d') as tdate \n\tFROM iptables WHERE local_port=25 AND disable=0 \n\tAND DATE_FORMAT(saved_date,'%Y-%m')=DATE_FORMAT(NOW(),'%Y-%m') GROUP BY tdate ORDER BY tdate";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/instant-iptables-graphs.png", 0);
    $time = time();
    $count = mysql_num_rows($results);
    writelogs($count . " rows", __FUNCTION__, __FILE__, __LINE__);
    if (mysql_num_rows($results) == 0) {
        $tpl = new templates();
        echo $tpl->_ENGINE_parse_body("<H2>{NO_DATA_COME_BACK_LATER}</H2>");
        return;
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["tdate"];
        $ydata[] = $ligne["tcount"];
    }
    $gp->width = 700;
    $gp->height = 550;
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = "IP blocked";
    $gp->x_title = "Days";
    $gp->title = null;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    echo "<img src='ressources/logs/web/instant-iptables-graphs.png?{$time}'></CENTER>";
}
function user_hits_graph()
{
    $xtime = $_GET["time"];
    if ($xtime == 0) {
        $timesql = "AND WEEK(days)=WEEK(NOW()) AND YEAR(days)=YEAR(NOW())";
    }
    if ($xtime == 1) {
        $timesql = "AND MONTH(days)=MONTH(NOW()) AND YEAR(days)=YEAR(NOW())";
    }
    $sql = "SELECT SUM(hits) as thits,DATE_FORMAT(days,'%d') as tday FROM squid_events_clients_sites WHERE client='{$_GET["client"]}' {$timesql} GROUP BY days ORDER BY UNIX_TIMESTAMP(days)";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    writelogs($count . " rows", __FUNCTION__, __FILE__, __LINE__);
    if (mysql_num_rows($results) == 0) {
        $tpl = new templates();
        return $tpl->_ENGINE_parse_body("<H2 style='color:black'>{NO_DATA_COME_BACK_LATER}</H2>");
    }
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["tday"];
        $ydata[] = $ligne["thits"];
    }
    $md = md5("{$_GET["client"]}{$xtime}");
    $cachefile = "ressources/logs/web/squid.{$md}.client.hits.png";
    $gp = new artica_graphs(dirname(__FILE__) . "/{$cachefile}", 0);
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = "hits";
    $gp->x_title = "days";
    $gp->title = null;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    return "<img src='{$cachefile}'>";
}
Exemple #22
0
function popup()
{
    $img = "<img src='img/bg_sqlgrey-240.jpg'>";
    $page = CurrentPageName();
    $mg = Paragraphe('folder-mailbox-64.png', '{main_settings}', '{main_settings_text}', "javascript:main_settings_greylist()", null, 210, 100, 0, true);
    //$mg1=Paragraphe('folder-rules2-64.png','{acl}','{acl_text}',"javascript:main_accesslist_greylist()",null,210,100,0,true);
    $mg2 = Paragraphe('folder-logs-643.png', '{events}', '{events_text}', "javascript:main_events_greylist()", null, 210, 100, 0, true);
    //$mg3=Buildicon64("DEF_ICO_EVENTS_MGREYLITS_DUMP");
    if (is_file("ressources/logs/greylist-count-master.tot")) {
        $datas = unserialize(@file_get_contents("ressources/logs/greylist-count-master.tot"));
        if (is_array($datas)) {
            @unlink("ressources/logs/web/mgreylist.master1.db.png");
            $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/mgreylist.master1.db.png", 0);
            $gp->xdata[] = $datas["GREYLISTED"];
            $gp->ydata[] = "greylisted";
            $gp->xdata[] = $datas["WHITELISTED"];
            $gp->ydata[] = "whitelisted";
            $gp->width = 350;
            $gp->height = 350;
            $gp->ViewValues = false;
            $gp->x_title = "{status}";
            $gp->pie();
            $imgG = "<img src='ressources/logs/web/mgreylist.master1.db.png'>";
        }
    }
    $content = "\n\t<table style='width:100'>\n\t<tr>\n\t\t<td valign='top'>{$mg}</td>\n\t\t<td valign='top'>{$mg2}</td>\n\t</tr>\n\t</table>\n\t";
    $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td valign='top'>\n\t\t\t{$img}\n\t\t\t<br>\n\t\t\t<div id='mgreylist-status'></div>\n\t\t</td>\n\t\t<td valign='top'>\n\t\t\t{$content}<br><center>{$imgG}</center>\n\t\t</td>\n\t</tr>\n\t\n\t</table>\n\t\n\t<script>\n\t\tmiltergreylist_status();\n\t</script>\n\t\n\t";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
function popup()
{
    $img = "<img src='img/bg_sqlgrey-300.jpg'>";
    $page = CurrentPageName();
    $t = time();
    $tpl = new templates();
    $title = $tpl->_ENGINE_parse_body("{APP_MILTER_GREYLIST}");
    if (is_file("ressources/logs/greylist-count-{$_GET["hostname"]}.tot")) {
        $datas = unserialize(@file_get_contents("ressources/logs/greylist-count-{$_GET["hostname"]}.tot"));
        if (is_array($datas)) {
            @unlink("ressources/logs/web/mgreylist.master1.db.png");
            $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/mgreylist.{$_GET["hostname"]}1.db.png", 0);
            $gp->xdata[] = $datas["GREYLISTED"];
            $gp->ydata[] = "greylisted";
            $gp->xdata[] = $datas["WHITELISTED"];
            $gp->ydata[] = "whitelisted";
            $gp->width = 310;
            $gp->height = 310;
            $gp->ViewValues = false;
            $gp->x_title = "{status}";
            $gp->pie();
            $imgG = "<img src='ressources/logs/web/mgreylist.{$_GET["hostname"]}1.db.png'>";
        }
    }
    $toolbox = "\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td><a href=\"javascript:blur();\" OnClick=\"javascript:MiltergreylistMilterStatus()\" style='font-size:14px;text-decoration:underline'>{refresh_status}</a></td>\n\t</tr>\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td><a href=\"javascript:blur();\" OnClick=\"javascript:SrvMilterServ{$t}('stop')\" style='font-size:14px;text-decoration:underline'>{stop_service}</a></td>\n\t</tr>\n\t<tr>\n\t\t<td width=1%><img src='img/arrow-right-16.png'></td>\n\t\t<td><a href=\"javascript:blur();\" OnClick=\"javascript:SrvMilterServ{$t}('start')\" style='font-size:14px;text-decoration:underline'>{start_service}</a></td>\n\t</tr>\t\t\n\t</table>\n\t\n\t";
    $html = "\n\t<div style='font-size:18px'>{instance}::{$_GET["hostname"]}</div>\n\t<table style='width:99%' class=form>\n\t<tr>\n\t\t<td valign='top'>{$img}</td>\n\t\t<td valign='top' style='width:100%'>\n\t\t\t\t<div id='milter-greylist-status'></div>\n\t\t\t\t{$toolbox}\n\t\t\t</td>\n\t</table>\n\t<center>{$imgG}</center>\n\t\t<script>\n\t\tfunction SrvMilterServ{$t}(type){\n\t\t\tYahooWin5('650','{$page}?SrvMilterServ=yes&hostname={$_GET["hostname"]}&ou={$_GET["ou"]}&type='+type,'{APP_MILTERGREYLIST}&raquo;{service}&raquo;'+type);\n\t\t}\n\t\t\n\t\t\n\t\tMiltergreylistMilterStatus();\n\t\t\n\t\t\n\t\t</script>\n\t";
    $tpl = new templates();
    echo $tpl->_ENGINE_parse_body($html);
}
function senders()
{
    $domain = $_GET["domain"];
    $q = new mysql();
    $tpl = new templates();
    $sql = "\n\tSELECT SUM(hits) as hits, sender_user as mailto \n\tFROM smtp_logs_day_users\n\tWHERE zDay>=DATE_SUB(NOW(),INTERVAL 7 DAY)\n\tAND recipient_domain='{$domain}'\n\tGROUP BY sender_user\n\tORDER BY hits DESC \n\tLIMIT 0,10";
    $html = "\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th>{hits}</th>\n\t\t<th>{senders}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    $filename = "postfix.domain.{$domain}.top.senders.png";
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/{$filename}", 50);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["mailto"] == null) {
            continue;
        }
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        //$js="Loadjs('postfix.stats.single-domain.php?domain=".urlencode($ligne["delivery_domain"])."')";
        //$style=" style='text-decoration:underline' ";
        $html = $html . "\n\t<tr class={$classtr}>\n\t\t\t<td style='font-size:14px;font-weight:bold' width=1% align='center'><a href=\"javascript:blur()\" OnClick=\"javascript:{$js}\">{$ligne["hits"]}</a></td>\n\t\t\t<td style='font-size:14px;font-weight:bold' nowrap width=99%><a href=\"javascript:blur()\" OnClick=\"javascript:{$js}\" {$style}>{$ligne["mailto"]}</a></td>\n\t\t</tr>\n\t";
        $gp->xdata[] = $ligne["hits"];
        $gp->ydata[] = $ligne["mailto"];
    }
    $table[] = "</table>";
    $time = time();
    $gp->width = 560;
    $gp->height = 580;
    $gp->ViewValues = false;
    $gp->x_title = "{mailto}";
    $gp->pie();
    echo "<center><img src='ressources/logs/web/{$filename}?time={$time}'></center>";
    echo "<hr>";
    echo $tpl->_ENGINE_parse_body("{$html}</table>");
}
Exemple #25
0
function details_today($timerq)
{
    $tpl = new templates();
    $page = CurrentPageName();
    $q = new mysql();
    $now = date('Y-m-d');
    $field = $_GET["field"];
    $value = $_GET["value"];
    $t = time();
    $ssubsql = "SELECT size,HOUR(zDate) as hour,DATE_FORMAT(zDate,'%Y-%m-%d') as zDate FROM ipband WHERE {$field}='{$value}' AND DATE_FORMAT(zDate,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')";
    $sql = "SELECT AVG(size) as kbs,hour as tdate\n\t\tFROM ({$ssubsql}) as t GROUP BY\n\t\ttdate\n\t\tORDER BY hour";
    if ($timerq == "week") {
        $ssubsql = "SELECT size,DAY(zDate) as zDate FROM ipband WHERE {$field}='{$value}' AND WEEK(zDate)=WEEK(NOW())";
        $sql = "SELECT AVG(size) as kbs,zDate as tdate FROM ({$ssubsql}) as t GROUP BY tdate ORDER BY tdate";
    }
    if ($timerq == "month") {
        $ssubsql = "SELECT size,DAY(zDate) as zDate FROM ipband WHERE {$field}='{$value}' AND MONTH(zDate)=MONTH(NOW())";
        $sql = "SELECT AVG(size) as kbs,zDate as tdate FROM ({$ssubsql}) as t GROUP BY tdate ORDER BY tdate";
    }
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) == 0) {
        echo $tpl->_ENGINE_parse_body("{$title}<center style='margin:50px'><H2>{error_no_datas}</H2>{$sql}</center>");
        return;
    }
    $nb_events = mysql_num_rows($results);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["tdate"];
        $ydata[] = round($ligne["kbs"] / 1024, 2);
    }
    $t = time();
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . ".day.{$field}.{$value}.png";
    $gp = new artica_graphs();
    $gp->width = 550;
    $gp->height = 220;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{hours}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    if (is_file($targetedfile)) {
        $image = "<center style='margin-top:10px' class=form><img src='{$targetedfile}?{$t}'></center>";
    }
    $html = "\n\t{$image}\n\t<div id='ttable{$t}'></div>\n\t<script>\n\tLoadAjax('ttable{$t}','{$page}?details-table=yes&time={$timerq}&field={$_GET["field"]}&value={$_GET["value"]}');\n\t</script>\n";
    echo $tpl->_ENGINE_parse_body($html);
}
function generate_graph()
{
    include_once 'ressources/class.artica.graphs.inc';
    $q = new mysql_squid_builder();
    $page = CurrentPageName();
    $tpl = new templates();
    $t = $_GET["t"];
    $ff = time();
    $xtime = $_GET["xtime"];
    $tablename = "youtubeday_" . date("Ymd", $xtime);
    $sql = "SELECT SUM(hits) as thits, hour FROM {$tablename} GROUP BY hour ORDER BY hour";
    $c = 0;
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) > 0) {
        $nb_events = mysql_num_rows($results);
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $xdata[] = $ligne["hour"];
            $ydata[] = $ligne["thits"];
            $c++;
        }
        $t = time();
        $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . ".day.{$tablename}") . ".png";
        $gp = new artica_graphs();
        $gp->width = 920;
        $gp->height = 350;
        $gp->filename = "{$targetedfile}";
        $gp->xdata = $xdata;
        $gp->ydata = $ydata;
        $gp->y_title = null;
        $gp->x_title = $tpl->_ENGINE_parse_body("{hours}");
        $gp->title = null;
        $gp->margin0 = true;
        $gp->Fillcolor = "blue@0.9";
        $gp->color = "146497";
        $gp->line_green();
        if (is_file($targetedfile)) {
            echo "<center>\n\t\t\t<div style='font-size:18px;margin-bottom:10px'>" . $tpl->_ENGINE_parse_body("{hits}/{hours}") . "</div>\n\t\t\t<img src='{$targetedfile}'></center>";
        }
    }
}
function popup()
{
    echo "<div class=BodyContent style='padding:3px'>";
    include_once 'ressources/class.artica.graphs.inc';
    $q = new mysql_squid_builder();
    $page = CurrentPageName();
    $tpl = new templates();
    $t = $_GET["t"];
    $ff = time();
    $ID = $_GET["ID"];
    $sitename = $_GET["sitename"];
    $tablename = "WebTrackMem{$ID}";
    $sql = "SELECT SUM(hits) as thits, zDate,sitename FROM {$tablename} GROUP BY zDate,sitename HAVING sitename='{$sitename}' ORDER BY zDate";
    $year = date("Y");
    $c = 0;
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) > 0) {
        $nb_events = mysql_num_rows($results);
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $ligne["zDate"] = str_replace("{$year}-", "", $ligne["zDate"]);
            $xdata[] = $ligne["zDate"];
            $ydata[] = $ligne["thits"];
            $c++;
        }
        $t = time();
        $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . ".day.{$sql}") . ".png";
        $gp = new artica_graphs();
        $gp->width = 920;
        $gp->height = 350;
        $gp->filename = "{$targetedfile}";
        $gp->xdata = $xdata;
        $gp->ydata = $ydata;
        $gp->y_title = null;
        $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
        $gp->title = null;
        $gp->margin0 = true;
        $gp->Fillcolor = "blue@0.9";
        $gp->color = "146497";
        $gp->line_green();
        if (is_file($targetedfile)) {
            echo "<center>\n\t\t\t<div style='font-size:18px;margin-bottom:10px'>" . $tpl->_ENGINE_parse_body("{hits}/{day}") . "</div>\n\t\t\t<img src='{$targetedfile}'></center>";
        }
    }
    $sql = "SELECT SUM(size) as thits, zDate,sitename FROM {$tablename} GROUP BY zDate,sitename HAVING sitename='{$sitename}' ORDER BY zDate";
    $xdata = array();
    $ydata = array();
    $c = 0;
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    if (mysql_num_rows($results) > 0) {
        $nb_events = mysql_num_rows($results);
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $ligne["zDate"] = str_replace("{$year}-", "", $ligne["zDate"]);
            $xdata[] = $ligne["zDate"];
            $ydata[] = round($ligne["thits"] / 1024 / 1000);
            $c++;
        }
        $t = time();
        $targetedfile = "ressources/logs/" . md5(basename(__FILE__) . "." . __FUNCTION__ . ".day.{$sql}") . ".png";
        $gp = new artica_graphs();
        $gp->width = 920;
        $gp->height = 350;
        $gp->filename = "{$targetedfile}";
        $gp->xdata = $xdata;
        $gp->ydata = $ydata;
        $gp->y_title = null;
        $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
        $gp->title = null;
        $gp->margin0 = true;
        $gp->Fillcolor = "blue@0.9";
        $gp->color = "146497";
        $gp->line_green();
        if (is_file($targetedfile)) {
            echo "<center>\n\t\t\t<div style='font-size:18px;margin-bottom:10px'>" . $tpl->_ENGINE_parse_body("{size}/{day} (MB)") . "</div>\n\t\t\t<img src='{$targetedfile}'></center>";
        }
    }
    echo "</div>\n\t<div class=BodyContent style='padding:3px' id='{$t}'></div>\n\t<script>\n\t\tLoadAjax('{$t}','{$page}?table=yes&ID={$ID}&sitename={$sitename}');\n\t</script>\n\t\n\t\n\t";
}
function countries_month()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $sql = "SELECT SUM(hits) as thits,country FROM kav4proxyDays WHERE MONTH(days)=MONTH(NOW()) AND YEAR(days)=YEAR(NOW()) GROUP BY country ORDER BY thits DESC LIMIT 0,10";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}\n</H2>";
        return;
    }
    $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t<td valign='top' width=1%><img src=img/domain-64.png></td>\n\t<td><div class=explain>{kav4proxycountry_month_stats_explain}</div></td>\n\t</tr>\n\t</table>\n\t<center style='margin:5px'><img src='ressources/logs/web/kav4proxy.MCOUNT.png'  border=0></center>\n\t\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th width=1% colspan=2>{hits}</th>\n\t\t<th width=1%>{country}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>";
    $gp->xdata[] = "";
    $gp->ydata[] = "";
    @unlink(dirname(__FILE__) . "/ressources/logs/web/kav4proxy.MCOUNT.png");
    $gp = new artica_graphs(dirname(__FILE__) . "/ressources/logs/web/kav4proxy.MCOUNT.png", 0);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        $gp->xdata[] = $ligne["thits"];
        $text_category = $ligne["country"];
        $country = $ligne["country"];
        if ($country != null) {
            $img_country = GetFlags($country);
        } else {
            $img_country = "flags/name.png";
        }
        if ($text_category == null) {
            $text_category = $tpl->_ENGINE_parse_body("{unknown}");
        }
        $gp->ydata[] = $text_category;
        $html = $html . "<tr class={$classtr}>\n\t\t\t<td width=1% nowrap><img src='img/{$img_country}'></td>\n\t\t\t<td width=1% nowrap><strong style='font-size:14px'>{$ligne["thits"]}</strong></td>\n\t\t\t<td width=99% nowrap align=left><strong style='font-size:14px'>{$text_category}</strong></td>\n\t\t\t</tr>\n\t\t\t";
    }
    $html = $html . "\n\t</tbody>\n\t</table>\n\t";
    $gp->width = 560;
    $gp->height = 580;
    $gp->ViewValues = false;
    $gp->x_title = "{country}";
    $gp->pie();
    echo $tpl->_ENGINE_parse_body($html);
}
function topwebsites_graph(){
	$tpl=new templates();
	$page=CurrentPageName();
	$q=new mysql_squid_builder();
	
	
	$table=$_GET["table"];
	$id=md5($_GET["table"].$_GET["hour"]);
	if(!$q->TABLE_EXISTS($table)){echo "<H3>".$tpl->_ENGINE_parse_body("{ERROR_NO_DATA}")."</h3>";}

	$sql="SELECT SUM(size) as tsize,`hour`,familysite FROM $table GROUP BY familysite,`hour` HAVING `hour`='{$_GET["hour"]}' ORDER BY tsize DESC LIMIT 0,5";
	$results=$q->QUERY_SQL($sql);
	while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		$downloaded_bin=$ligne["tsize"];
		$downloaded_text=FormatBytes($downloaded_bin/1024);
		$downloaded_text=str_replace("&nbsp;", " ", $downloaded_text);
		$downloaded_bin=round((($downloaded_bin/1024)/1000));
		
		$website=$ligne["familysite"];
		$ydata[]="MB $website $downloaded_text";
		$xdata[]=$downloaded_bin;	
		
		
	}
	
	
	$targetedfile="ressources/logs/".basename(__FILE__).".".__FUNCTION__.".".time().".png";
	$gp=new artica_graphs($targetedfile);	
	$gp->xdata=$xdata;
	$gp->ydata=$ydata;	
	$gp->width=250;
	$gp->height=400;
	$gp->ViewValues=true;
	//$gp->PieLegendHide=true;
	$gp->x_title=$tpl->_ENGINE_parse_body("{cache}");
	$gp->pie();		
	echo $tpl->_ENGINE_parse_body("<center style='margin:0px;margin-bottom:5px;padding:3px;border:1px solid #CCCCCC'>
		<strong style='font-size:12px'>{phrase_topwebsize_bysize}</strong>
		<img src='$targetedfile' style='margin-bottom:5px'>
		
	 	</center>
	 	
	")."<script>LoadAjax('panel-right-$id','$page?users-usually=yes&time={$_GET["time"]}&hour={$_GET["hour"]}&table={$_GET["table"]}')</script>";
	
}
function paragraphe1()
{
    $table = $_GET["table"];
    $user = $_GET["user"];
    $field = $_GET["field"];
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_squid_builder();
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(size) as tsize FROM {$table}"));
    $downloadedINT = $ligne["tsize"];
    $sql = "SELECT SUM(size) as tsize FROM {$table} WHERE `{$field}`='{$user}' AND cached=1";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    $X3_bin = $ligne["tsize"];
    $X3_text = "<strong>" . FormatBytes($X3_bin / 1024) . "</strong>";
    $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(size) as tsize FROM {$table} WHERE `{$field}`='{$user}'"));
    $X1_bin = $ligne2["tsize"];
    $X1_text = "<strong>" . FormatBytes($X1_bin / 1024) . "</strong>";
    $PRC = $X3_bin / $X1_bin * 100;
    $PRC = round($PRC, 3);
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(hits) as tsize FROM {$table} WHERE `{$field}`='{$user}'"));
    $X2_bin = $ligne["tsize"];
    $X2_text = "<strong>{$X2_bin}</strong>";
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(familysite) as familysite,`{$field}` FROM {$table} WHERE `{$field}`='{$user}'"));
    $X0_bin = $ligne["familysite"];
    $X0_text = "<strong>{$X0_bin}</strong>";
    $webstatsUserIntro1 = $tpl->_ENGINE_parse_body("{webstatsUserIntro1}");
    $webstatsUserIntro1 = str_replace("X3PRC", "<strong style='color:#CF1717'>{$PRC}%</strong>", $webstatsUserIntro1);
    $webstatsUserIntro1 = str_replace("X0", $X0_text, $webstatsUserIntro1);
    $webstatsUserIntro1 = str_replace("X1", $X1_text, $webstatsUserIntro1);
    $webstatsUserIntro1 = str_replace("X2", $X2_text, $webstatsUserIntro1);
    $webstatsUserIntro1 = str_replace("X3", $X3_text, $webstatsUserIntro1);
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(size) as tsize,familysite,`{$field}` FROM {$table} GROUP BY familysite,`{$field}` HAVING `{$field}`='{$user}' ORDER BY tsize DESC LIMIT 0,1"));
    $XXWWWS = $ligne["familysite"];
    $XWSZE = FormatBytes($ligne["tsize"] / 1024);
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT SUM(hits) as tsize,familysite,`{$field}` FROM {$table} GROUP BY familysite,`{$field}` HAVING `{$field}`='{$user}' ORDER BY tsize DESC LIMIT 0,1"));
    $XXWWWR = $ligne["familysite"];
    $XWSZR = $ligne["tsize"];
    $XWSCAT = familysite_MergeCategories(array($XXWWWS, $XXWWWR));
    $line = $tpl->_ENGINE_parse_body("{phrase_the_most_websites}");
    $line = str_replace("XXWWWS", "<strong>{$XXWWWS}</strong>", $line);
    $line = str_replace("XWSZE", "<strong>{$XWSZE}</strong>", $line);
    $line = str_replace("XXWWWR", "<strong>{$XXWWWR}</strong>", $line);
    $line = str_replace("XWSZR", "<strong>{$XWSZR}</strong>", $line);
    $line = str_replace("XWSCAT", "<strong>{$XWSCAT}</strong>", $line);
    $webstatsUserIntro2 = "<div style='font-size:12px;text-align:justify'>{$line}</div>";
    //*********************************************************************** GRAPHIQUE PAR JOUR
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT `day`,SUM(hits) as thits,SUM(size) as tsize,`{$field}`  \n\tFROM {$table} GROUP BY `day`,`{$field}`  HAVING `{$field}`='{$user}' ORDER BY thits DESC LIMIT 0,1"));
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    $MostActiveDayNum = $ligne["day"] - 1;
    $MostActiveDaySize = FormatBytes($ligne["tsize"] / 1024);
    $Cyear = substr($table, 0, 4);
    $Cweek = substr($table, 4, 2);
    $Cweek = str_replace("_", "", $Cweek);
    $days = $q->getDaysInWeek($Cweek, $Cyear);
    $dayText = date('{l}', $days[$MostActiveDayNum]);
    $title = "{$dayText} {phrase_most_day_activeday} {for} {$user}";
    $prc = round($ligne["tsize"] / $downloadedINT, 2) * 100;
    $webstatsUserIntro3 = "<div style='color:#CF1717;font-weight:bold;margin-top:5px;font-size:13.5px'>{$title}</div>\n\t<div style='font-size:12px;text-align:justify;'>{with} <strong>{$ligne["thits"]} {hits}</strong> {or} <strong>{$MostActiveDaySize}</strong> {it_represents} <strong>{$prc}%</strong> {of_bandwith}</div>\n\t<div style='font-size:12px;text-align:justify;margin-top:10px;margin-bottom:15px'>{phrase_thisisthegraph1}:</div>";
    $sql = "SELECT `day`,SUM(hits) as thits,`{$field}` FROM {$table} GROUP BY `day`,`{$field}` HAVING  `{$field}`='{$user}' ORDER BY `day`";
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $xdata[] = $ligne["day"];
        $ydata[] = $ligne["thits"];
    }
    $time = time();
    $targetedfile = "ressources/logs/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$table}.{$time}.png";
    $gp = new artica_graphs();
    $gp->width = 270;
    $gp->height = 150;
    $gp->filename = "{$targetedfile}";
    $gp->xdata = $xdata;
    $gp->ydata = $ydata;
    $gp->y_title = null;
    $gp->x_title = $tpl->_ENGINE_parse_body("{days}");
    $gp->title = null;
    $gp->margin0 = true;
    $gp->Fillcolor = "blue@0.9";
    $gp->color = "146497";
    $gp->line_green();
    if (!is_file($targetedfile)) {
        $targetedfile = "img/nograph-000.png";
    }
    $graph1 = "<center style='margin-top:5px'><img src='{$targetedfile}'></center>";
    $HTML = "<p style='font-size:12px'>{$webstatsUserIntro1}</p>\n\t<p style='font-size:12px'>{$webstatsUserIntro2}</p>\n\t{$webstatsUserIntro3}\n\t{$graph1}\n\t<script>LoadUserReport2()</script>\n\t";
    echo $tpl->_ENGINE_parse_body($HTML);
}