Added traffic overview for admins over all customers, refs #492, thx yabawock
Signed-off-by: Florian Aders (EleRas) <eleras@froxlor.org>
This commit is contained in:
141
admin_traffic.php
Normal file
141
admin_traffic.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Morton Jonuschat <m.jonuschat@chrome-it.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package Panel
|
||||
* @version $Id: $
|
||||
*/
|
||||
|
||||
define('AREA', 'admin');
|
||||
|
||||
/**
|
||||
* Include our init.php, which manages Sessions, Language etc.
|
||||
*/
|
||||
|
||||
require ("./lib/init.php");
|
||||
|
||||
if($action == 'logout')
|
||||
{
|
||||
$db->query("DELETE FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid` = '" . (int)$userinfo['adminid'] . "' AND `adminsession` = '1'");
|
||||
redirectTo('index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($_POST['id']))
|
||||
{
|
||||
$id = intval($_POST['id']);
|
||||
}
|
||||
elseif(isset($_GET['id']))
|
||||
{
|
||||
$id = intval($_GET['id']);
|
||||
}
|
||||
|
||||
$months = array(
|
||||
'0' => 'empty',
|
||||
'1' => 'jan',
|
||||
'2' => 'feb',
|
||||
'3' => 'mar',
|
||||
'4' => 'apr',
|
||||
'5' => 'may',
|
||||
'6' => 'jun',
|
||||
'7' => 'jul',
|
||||
'8' => 'aug',
|
||||
'9' => 'sep',
|
||||
'10' => 'oct',
|
||||
'11' => 'nov',
|
||||
'12' => 'dec',
|
||||
);
|
||||
|
||||
if($page == 'overview' || $page == 'customers')
|
||||
{
|
||||
if($action == 'su' && $id != 0)
|
||||
{
|
||||
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid`='" . (int)$id . "' " . ($userinfo['customers_see_all'] ? '' : " AND `adminid` = '" . (int)$userinfo['adminid'] . "' "));
|
||||
|
||||
if($result['loginname'] != '')
|
||||
{
|
||||
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid`='" . (int)$userinfo['userid'] . "'");
|
||||
$s = md5(uniqid(microtime(), 1));
|
||||
$db->query("INSERT INTO `" . TABLE_PANEL_SESSIONS . "` (`hash`, `userid`, `ipaddress`, `useragent`, `lastactivity`, `language`, `adminsession`) VALUES ('" . $db->escape($s) . "', '" . (int)$id . "', '" . $db->escape($result['ipaddress']) . "', '" . $db->escape($result['useragent']) . "', '" . time() . "', '" . $db->escape($result['language']) . "', '0')");
|
||||
redirectTo('customer_traffic.php', Array(
|
||||
's' => $s
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
redirectTo('index.php', Array(
|
||||
'action' => 'login'
|
||||
));
|
||||
}
|
||||
}
|
||||
$customerview = 1;
|
||||
$stats_tables = '';
|
||||
$minyear = $db->query_first("SELECT `year` FROM `". TABLE_PANEL_TRAFFIC . "` ORDER BY `year` ASC LIMIT 1");
|
||||
$maxyears = date("Y") - $minyear['year'];
|
||||
for($years = 0; $years<=$maxyears; $years++) {
|
||||
$overview['year'] = date("Y")-$years;
|
||||
$overview['type'] = $lng['traffic']['customer'];
|
||||
$domain_list = '';
|
||||
$customer_name_list = $db->query("SELECT `customerid`,`company`,`name`,`firstname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `deactivated`='0'" . ($userinfo['customers_see_all'] ? '' : " AND `adminid` = '" . (int)$userinfo['adminid'] . "' ") . " ORDER BY name");
|
||||
$totals = array(
|
||||
'jan' => 0,
|
||||
'feb' => 0,
|
||||
'mar' => 0,
|
||||
'apr' => 0,
|
||||
'may' => 0,
|
||||
'jun' => 0,
|
||||
'jul' => 0,
|
||||
'aug' => 0,
|
||||
'sep' => 0,
|
||||
'oct' => 0,
|
||||
'nov' => 0,
|
||||
'dec' => 0,
|
||||
);
|
||||
while($customer_name = $db->fetch_array($customer_name_list)) {
|
||||
$virtual_host = array(
|
||||
'name' => ($customer_name['company'] == '' ? $customer_name['name'] . ", " . $customer_name['firstname'] : $customer_name['company']),
|
||||
'customerid' => $customer_name['customerid'],
|
||||
'jan' => '-',
|
||||
'feb' => '-',
|
||||
'mar' => '-',
|
||||
'apr' => '-',
|
||||
'may' => '-',
|
||||
'jun' => '-',
|
||||
'jul' => '-',
|
||||
'aug' => '-',
|
||||
'sep' => '-',
|
||||
'oct' => '-',
|
||||
'nov' => '-',
|
||||
'dec' => '-',
|
||||
);
|
||||
|
||||
$traffic_list = $db->query("SELECT month, SUM(http+ftp_up+ftp_down+mail)*1024 AS traffic FROM `" . TABLE_PANEL_TRAFFIC . "` WHERE year = " . (date("Y")-$years) . " AND `customerid` = '" . $customer_name['customerid'] . "' GROUP BY month ORDER BY month");
|
||||
while($traffic_month = $db->fetch_array($traffic_list)) {
|
||||
$virtual_host[$months[(int)$traffic_month['month']]] = size_readable($traffic_month['traffic'], 'GiB', 'bi', '%01.3f %s');
|
||||
$totals[$months[(int)$traffic_month['month']]] += $traffic_month['traffic'];
|
||||
}
|
||||
eval("\$domain_list .= sprintf(\"%s\", \"" . getTemplate("traffic/index_table_row") . "\");");
|
||||
}
|
||||
// sum up totals
|
||||
$virtual_host = array(
|
||||
'name' => $lng['traffic']['months']['total'],
|
||||
);
|
||||
foreach($totals as $month => $bytes) {
|
||||
$virtual_host[$month] = ($bytes == 0 ? '-' : size_readable($bytes, 'GiB', 'bi', '%01.3f %s'));
|
||||
}
|
||||
$customerview = 0;
|
||||
eval("\$total_list = sprintf(\"%s\", \"" . getTemplate("traffic/index_table_row") . "\");");
|
||||
eval("\$stats_tables .= sprintf(\"%s\", \"" . getTemplate("traffic/index_table") . "\");");
|
||||
}
|
||||
eval("echo \"" . getTemplate("traffic/index") . "\";");
|
||||
}
|
||||
36
lib/functions/phphelpers/function.size_readable.php
Normal file
36
lib/functions/phphelpers/function.size_readable.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Return human readable sizes
|
||||
*
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version 1.3.0
|
||||
* @link http://aidanlister.com/2004/04/human-readable-file-sizes/
|
||||
* @param int $size size in bytes
|
||||
* @param string $max maximum unit
|
||||
* @param string $system 'si' for SI, 'bi' for binary prefixes
|
||||
* @param string $retstring return string format
|
||||
*/
|
||||
|
||||
function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
|
||||
{
|
||||
// Pick units
|
||||
$systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
|
||||
$systems['si']['size'] = 1000;
|
||||
$systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
|
||||
$systems['bi']['size'] = 1024;
|
||||
$sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];
|
||||
|
||||
// Max unit to display
|
||||
$depth = count($sys['prefix']) - 1;
|
||||
if ($max && false !== $d = array_search($max, $sys['prefix'])) {
|
||||
$depth = $d;
|
||||
}
|
||||
// Loop
|
||||
$i = 0;
|
||||
while ($size >= $sys['size'] && $i < $depth) {
|
||||
$size /= $sys['size'];
|
||||
$i++;
|
||||
}
|
||||
|
||||
return sprintf($retstring, $size, $sys['prefix'][$i]);
|
||||
}
|
||||
@@ -189,6 +189,17 @@ return array (
|
||||
),
|
||||
),
|
||||
),
|
||||
'traffic' => array (
|
||||
'label' => $lng['admin']['traffic'],
|
||||
'required_resources' => 'customers',
|
||||
'elements' => array (
|
||||
array (
|
||||
'url' => 'admin_traffic.php?page=customers',
|
||||
'label' => $lng['admin']['customertraffic'],
|
||||
'required_resources' => 'customers',
|
||||
),
|
||||
),
|
||||
),
|
||||
'server' => array (
|
||||
'label' => $lng['admin']['server'],
|
||||
'required_resources' => 'change_serversettings',
|
||||
|
||||
@@ -1581,3 +1581,25 @@ $lng['serversettings']['validate_domain'] = 'Validate domain names';
|
||||
$lng['login']['combination_not_found'] = 'Combination of user and email adress not found.';
|
||||
$lng['customer']['generated_pwd'] = 'Password suggestion';
|
||||
$lng['customer']['usedmax'] = 'Used / Max';
|
||||
$lng['admin']['traffic'] = 'Traffic';
|
||||
$lng['admin']['domaintraffic'] = 'Domains';
|
||||
$lng['admin']['customertraffic'] = 'Customers';
|
||||
$lng['traffic']['customer'] = 'Customer';
|
||||
$lng['traffic']['domain'] = 'Domain';
|
||||
$lng['traffic']['trafficoverview'] = 'Traffic summary by';
|
||||
$lng['traffic']['months']['jan'] = 'Jan';
|
||||
$lng['traffic']['months']['feb'] = 'Feb';
|
||||
$lng['traffic']['months']['mar'] = 'Mar';
|
||||
$lng['traffic']['months']['apr'] = 'Apr';
|
||||
$lng['traffic']['months']['may'] = 'May';
|
||||
$lng['traffic']['months']['jun'] = 'Jun';
|
||||
$lng['traffic']['months']['jul'] = 'Jul';
|
||||
$lng['traffic']['months']['aug'] = 'Aug';
|
||||
$lng['traffic']['months']['sep'] = 'Sep';
|
||||
$lng['traffic']['months']['oct'] = 'Oct';
|
||||
$lng['traffic']['months']['nov'] = 'Nov';
|
||||
$lng['traffic']['months']['dec'] = 'Dec';
|
||||
$lng['traffic']['months']['total'] = 'Total';
|
||||
$lng['traffic']['details'] = 'Details';
|
||||
$lng['menue']['traffic']['table'] = 'Traffic';
|
||||
|
||||
|
||||
7
templates/Classic/admin/traffic/index.tpl
Normal file
7
templates/Classic/admin/traffic/index.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
$header
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
|
||||
<script type="text/javascript" src="templates/jquery.tablesorter.min.js"></script>
|
||||
{$stats_tables}
|
||||
<br />
|
||||
<br />
|
||||
$footer
|
||||
52
templates/Classic/admin/traffic/index_table.tpl
Normal file
52
templates/Classic/admin/traffic/index_table.tpl
Normal file
@@ -0,0 +1,52 @@
|
||||
<table cellpadding="5" cellspacing="0" border="0" align="center" class="maintable" id="stats{$overview['year']}">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="13" class="maintitle"><b><img src="images/Classic/title.gif" alt="" /> {$lng['traffic']['trafficoverview']} {$overview['type']} {$overview['year']}</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="field_display_border_left" style="text-align:left;">{$overview['type']}</th>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['jan']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['feb']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['mar']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['apr']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['may']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['jun']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['jul']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['aug']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['sep']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['oct']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['nov']}</td>
|
||||
<th class="field_display" style="text-align:right;">{$lng['traffic']['months']['dec']}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{$domain_list}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
{$total_list}
|
||||
<tr>
|
||||
<td colspan="13"> </td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
var myTextExtraction = function(node)
|
||||
{
|
||||
// extract data from markup and return it
|
||||
if(node.innerHTML != '-') {
|
||||
return 1 + node.innerHTML.substr(0,node.innerHTML.length-3);
|
||||
} else {
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
$(document).ready(function()
|
||||
{
|
||||
$("#stats{$overview['year']}").tablesorter( {
|
||||
textExtraction: myTextExtraction
|
||||
} );
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
15
templates/Classic/admin/traffic/index_table_row.tpl
Normal file
15
templates/Classic/admin/traffic/index_table_row.tpl
Normal file
@@ -0,0 +1,15 @@
|
||||
<tr>
|
||||
<th class="field_name_border_left">{$virtual_host['name']}<if $customerview == 1> <a href="$filename?s=$s&page=$page&action=su&id={$virtual_host['customerid']}">[{$lng['traffic']['details']}]</a></if></th>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['jan']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['feb']}</td>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['mar']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['apr']}</td>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['may']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['jun']}</td>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['jul']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['aug']}</td>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['sep']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['oct']}</td>
|
||||
<td class="field_name" style="text-align:right;background-color:white;">{$virtual_host['nov']}</td>
|
||||
<td class="field_name" style="text-align:right;">{$virtual_host['dec']}</td>
|
||||
</tr>
|
||||
@@ -476,3 +476,17 @@ TR.RowOverSelected {
|
||||
}
|
||||
|
||||
|
||||
table.maintable th.field_display .header {
|
||||
background-color: #000000;
|
||||
}
|
||||
|
||||
.headerSortUp {
|
||||
background-image: url(../images/asc.gif);
|
||||
background-position: right bottom;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
.headerSortDown {
|
||||
background-image: url(../images/desc.gif);
|
||||
background-position: right top;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
4
templates/jquery.tablesorter.min.js
vendored
Normal file
4
templates/jquery.tablesorter.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user