Skip to content

Commit 5dd3d75

Browse files
committed
Ftp statistics feature
1 parent cfc79e7 commit 5dd3d75

File tree

7 files changed

+448
-0
lines changed

7 files changed

+448
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE `ftp_traffic` (`hostname` varchar(255) NOT NULL,`traffic_date` date NOT NULL,`in_bytes` bigint(32) unsigned NOT NULL,`out_bytes` bigint(32) unsigned NOT NULL, PRIMARY KEY (`hostname`,`traffic_date`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?php
2+
require_once '../../lib/config.inc.php';
3+
require_once '../../lib/app.inc.php';
4+
5+
/******************************************
6+
* Begin Form configuration
7+
******************************************/
8+
9+
$list_def_file = "list/ftp_sites_stats.list.php";
10+
11+
/******************************************
12+
* End Form configuration
13+
******************************************/
14+
15+
//* Check permissions for module
16+
$app->auth->check_module_permissions('sites');
17+
18+
$app->uses('functions');
19+
20+
$app->load('listform_actions');
21+
22+
class list_action extends listform_actions {
23+
24+
private $sum_this_month = 0;
25+
private $sum_this_year = 0;
26+
private $sum_last_month = 0;
27+
private $sum_last_year = 0;
28+
29+
function prepareDataRow($rec)
30+
{
31+
global $app;
32+
33+
$rec = $app->listform->decode($rec);
34+
35+
//* Alternating datarow colors
36+
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
37+
$rec['bgcolor'] = $this->DataRowColor;
38+
39+
//* Set the statistics colums
40+
//** Traffic of the current month
41+
$tmp_year = date('Y');
42+
$tmp_month = date('m');
43+
$tmp_rec = $app->db->queryOneRecord("SELECT SUM(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_traffic WHERE hostname = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month);
44+
$rec['this_month_in'] = $app->functions->formatBytes($tmp_rec['ftp_in']);
45+
$rec['this_month_out'] = $app->functions->formatBytes($tmp_rec['ftp_out']);
46+
$this->sum_this_month += $tmp_rec['ftp_in']+$tmp_rec['ftp_out'];
47+
48+
//** Traffic of the current year
49+
$tmp_rec = $app->db->queryOneRecord("SELECT SUM(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_traffic WHERE hostname = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year);
50+
$rec['this_year_in'] = $app->functions->formatBytes($tmp_rec['ftp_in']);
51+
$rec['this_year_out'] = $app->functions->formatBytes($tmp_rec['ftp_out']);
52+
$this->sum_this_year += $tmp_rec['ftp_in']+$tmp_rec['ftp_out'];
53+
54+
//** Traffic of the last month
55+
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
56+
$tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
57+
$tmp_rec = $app->db->queryOneRecord("SELECT SUM(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_traffic WHERE hostname = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month);
58+
$rec['last_month_in'] = $app->functions->formatBytes($tmp_rec['ftp_in']);
59+
$rec['last_month_out'] = $app->functions->formatBytes($tmp_rec['ftp_out']);
60+
$this->sum_last_month += $tmp_rec['ftp_in']+$tmp_rec['ftp_out'];
61+
62+
//** Traffic of the last year
63+
$tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
64+
$tmp_rec = $app->db->queryOneRecord("SELECT SUM(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_traffic WHERE hostname = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year);
65+
$rec['last_year_in'] = $app->functions->formatBytes($tmp_rec['ftp_in']);
66+
$rec['last_year_out'] = $app->functions->formatBytes($tmp_rec['ftp_out']);
67+
$this->sum_last_year += $tmp_rec['ftp_in']+$tmp_rec['ftp_out'];
68+
69+
//* The variable "id" contains always the index variable
70+
$rec['id'] = $rec[$this->idx_key];
71+
72+
return $rec;
73+
}
74+
75+
function onShowEnd()
76+
{
77+
global $app;
78+
79+
$app->tpl->setVar('sum_this_month', $app->functions->formatBytes($this->sum_this_month));
80+
$app->tpl->setVar('sum_this_year', $app->functions->formatBytes($this->sum_this_year));
81+
$app->tpl->setVar('sum_last_month', $app->functions->formatBytes($this->sum_last_month));
82+
$app->tpl->setVar('sum_last_year', $app->functions->formatBytes($this->sum_last_year));
83+
$app->tpl->setVar('sum_txt', $app->listform->lng('sum_txt'));
84+
85+
$app->tpl_defaults();
86+
$app->tpl->pparse();
87+
}
88+
89+
function getQueryString($no_limit = false) {
90+
global $app;
91+
$sql_where = '';
92+
93+
//* Generate the search sql
94+
if($app->listform->listDef['auth'] != 'no') {
95+
if($_SESSION['s']['user']['typ'] == "admin") {
96+
$sql_where = '';
97+
} else {
98+
$sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and';
99+
//$sql_where = $app->tform->getAuthSQL('r').' and';
100+
}
101+
}
102+
if($this->SQLExtWhere != '') {
103+
$sql_where .= ' '.$this->SQLExtWhere.' and';
104+
}
105+
106+
$sql_where = $app->listform->getSearchSQL($sql_where);
107+
if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
108+
$app->tpl->setVar($app->listform->searchValues);
109+
110+
$order_by_sql = $this->SQLOrderBy;
111+
112+
//* Generate SQL for paging
113+
$limit_sql = $app->listform->getPagingSQL($sql_where);
114+
$app->tpl->setVar('paging', $app->listform->pagingHTML);
115+
116+
$extselect = '';
117+
$join = '';
118+
119+
if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
120+
$order = str_replace(' DESC', '', $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']);
121+
list($tmp_table, $order) = explode('.', $order);
122+
if($order == 'ftp_traffic_last_month'){
123+
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
124+
$tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
125+
$extselect .= ', SUM(ft.in_bytes+out_bytes) as calctraffic';
126+
$join .= ' INNER JOIN ftp_traffic as ft ON '.$app->listform->listDef['table'].'.domain = ft.hostname ';
127+
$sql_where .= " AND YEAR(ft.traffic_date) = '$tmp_year' AND MONTH(ft.traffic_date) = '$tmp_month'";
128+
$order_by_sql = str_replace($app->listform->listDef['table'].'.ftp_traffic_last_month', 'calctraffic', $order_by_sql);
129+
$order_by_sql = "GROUP BY domain ".$order_by_sql;
130+
} elseif($order == 'ftp_traffic_this_month'){
131+
$tmp_year = date('Y');
132+
$tmp_month = date('m');
133+
$extselect .= ', SUM(ft.in_bytes+out_bytes) as calctraffic';
134+
$join .= ' INNER JOIN ftp_traffic as ft ON '.$app->listform->listDef['table'].'.domain = ft.hostname ';
135+
$sql_where .= " AND YEAR(ft.traffic_date) = '$tmp_year' AND MONTH(ft.traffic_date) = '$tmp_month'";
136+
$order_by_sql = str_replace($app->listform->listDef['table'].'.ftp_traffic_this_month', 'calctraffic', $order_by_sql);
137+
$order_by_sql = "GROUP BY domain ".$order_by_sql;
138+
} elseif($order == 'ftp_traffic_last_year'){
139+
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
140+
$extselect .= ', SUM(ft.in_bytes+out_bytes) as calctraffic';
141+
$join .= ' INNER JOIN ftp_traffic as ft ON '.$app->listform->listDef['table'].'.domain = ft.hostname ';
142+
$sql_where .= " AND YEAR(ft.traffic_date) = '$tmp_year'";
143+
$order_by_sql = str_replace($app->listform->listDef['table'].'.ftp_traffic_last_year', 'calctraffic', $order_by_sql);
144+
$order_by_sql = "GROUP BY domain ".$order_by_sql;
145+
} elseif($order == 'ftp_traffic_this_year'){
146+
$tmp_year = date('Y');
147+
$extselect .= ', SUM(ft.in_bytes+out_bytes) as calctraffic';
148+
$join .= ' INNER JOIN ftp_traffic as ft ON '.$app->listform->listDef['table'].'.domain = ft.hostname ';
149+
$sql_where .= " AND YEAR(ft.traffic_date) = '$tmp_year'";
150+
$order_by_sql = str_replace($app->listform->listDef['table'].'.ftp_traffic_this_year', 'calctraffic', $order_by_sql);
151+
$order_by_sql = "GROUP BY domain ".$order_by_sql;
152+
}
153+
}
154+
155+
if($this->SQLExtSelect != '') {
156+
if(substr($this->SQLExtSelect, 0, 1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect;
157+
$extselect .= $this->SQLExtSelect;
158+
}
159+
160+
$table_selects = array();
161+
$table_selects[] = trim($app->listform->listDef['table']).'.*';
162+
$app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
163+
if($app->listform->listDef['additional_tables'] != ''){
164+
$additional_tables = explode(',', $app->listform->listDef['additional_tables']);
165+
foreach($additional_tables as $additional_table){
166+
$table_selects[] = trim($additional_table).'.*';
167+
}
168+
}
169+
$select = implode(', ', $table_selects);
170+
171+
$sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql $limit_sql";
172+
return $sql;
173+
}
174+
}
175+
176+
$list = new list_action;
177+
$list->SQLExtWhere = "(web_domain.type = 'vhost' or web_domain.type = 'vhostsubdomain')";
178+
$list->SQLOrderBy = 'ORDER BY web_domain.domain';
179+
$list->onLoad();
180+
181+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$wb["list_head_txt"] = 'FTP traffic';
3+
$wb["domain_txt"] = 'Domain';
4+
$wb["this_month_txt"] = 'This month';
5+
$wb["last_month_txt"] = 'Last month';
6+
$wb["this_year_txt"] = 'This year';
7+
$wb["last_year_txt"] = 'Last year';
8+
$wb["sum_txt"] = 'Sum (Download + Upload)';
9+
$wb["in_out_txt"] = 'DL/UL';
10+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$wb["list_head_txt"] = 'FTP trafic';
3+
$wb["domain_txt"] = 'Domaine';
4+
$wb["this_month_txt"] = 'Mois en cours';
5+
$wb["last_month_txt"] = 'Mois pr�c�dent';
6+
$wb["this_year_txt"] = 'Ann�e en cours';
7+
$wb["last_year_txt"] = 'Ann�e pr�c�dente';
8+
$wb["sum_txt"] = 'Total (Download + Upload)';
9+
$wb["in_out_txt"] = 'DL/UL';
10+
?>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
Datatypes:
5+
- INTEGER
6+
- DOUBLE
7+
- CURRENCY
8+
- VARCHAR
9+
- TEXT
10+
- DATE
11+
*/
12+
13+
// Name of the list
14+
$liste["name"] = "ftp_sites_stats";
15+
16+
// Database table
17+
$liste["table"] = "web_domain";
18+
19+
// Index index field of the database table
20+
$liste["table_idx"] = "domain_id";
21+
22+
// Search Field Prefix
23+
$liste["search_prefix"] = "search_";
24+
25+
// Records per page
26+
$liste["records_per_page"] = "15";
27+
28+
// Script File of the list
29+
$liste["file"] = "web_sites_stats.php";
30+
31+
// Script file of the edit form
32+
$liste["edit_file"] = "web_domain_edit.php";
33+
34+
// Script File of the delete script
35+
$liste["delete_file"] = "web_domain_del.php";
36+
37+
// Paging Template
38+
$liste["paging_tpl"] = "templates/paging.tpl.htm";
39+
40+
// Enable auth
41+
$liste["auth"] = "yes";
42+
43+
44+
/*****************************************************
45+
* Suchfelder
46+
*****************************************************/
47+
48+
$liste["item"][] = array( 'field' => "domain",
49+
'datatype' => "VARCHAR",
50+
'filters' => array( 0 => array( 'event' => 'SHOW',
51+
'type' => 'IDNTOUTF8')
52+
),
53+
'formtype' => "TEXT",
54+
'op' => "like",
55+
'prefix' => "%",
56+
'suffix' => "%",
57+
'width' => "",
58+
'value' => "");
59+
60+
?>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<div class='page-header'>
2+
<h1><tmpl_var name="list_head_txt"></h1>
3+
</div>
4+
<p><tmpl_var name="list_desc_txt"></p>
5+
6+
<p class="fieldset-legend"><tmpl_var name="list_head_txt"></p>
7+
<div class="table-wrapper marginTop15">
8+
<table class="table">
9+
<thead class="dark form-group-sm">
10+
<tr>
11+
<th data-column="domain"><tmpl_var name="domain_txt"></th>
12+
<th data-column="this_month"><tmpl_var name="this_month_txt"></th>
13+
<th data-column="last_month"><tmpl_var name="last_month_txt"></th>
14+
<th data-column="this_year"><tmpl_var name="this_year_txt"></th>
15+
<th data-column="last_year"><tmpl_var name="last_year_txt"></th>
16+
<th class="small-col text-right">{tmpl_var name='search_limit'}</th>
17+
</tr>
18+
<tr>
19+
<td><input class="form-control" type="text" name="search_domain" value="{tmpl_var name='search_domain'}" /></td>
20+
<td><tmpl_var name="in_out_txt"></td>
21+
<td><tmpl_var name="in_out_txt"></td>
22+
<td><tmpl_var name="in_out_txt"></td>
23+
<td><tmpl_var name="in_out_txt"></td>
24+
<td class="text-right">
25+
<button type="button" class="btn btn-default formbutton-default formbutton-narrow" name="Filter" id="Filter" value="{tmpl_var name="filter_txt"}" data-submit-form="pageForm" data-form-action="sites/ftp_sites_stats.php"><span class="icon icon-filter"></span></button>
26+
</td>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<tmpl_loop name="records">
31+
<tr>
32+
<td><a target="_blank" href="http://{tmpl_var name="domain"}/stats">{tmpl_var name="domain"}</a></td>
33+
<td><a href="#" data-load-content="sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if><tmpl_if name='type' op='==' value='vhostalias'>vhost_alias</tmpl_if>domain_edit.php?id={tmpl_var name='id'}">{tmpl_var name="this_month_in"}/{tmpl_var name="this_month_out"}</a></td>
34+
<td><a href="#" data-load-content="sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if><tmpl_if name='type' op='==' value='vhostalias'>vhost_alias</tmpl_if>domain_edit.php?id={tmpl_var name='id'}">{tmpl_var name="last_month_in"}/{tmpl_var name="last_month_out"}</a></td>
35+
<td><a href="#" data-load-content="sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if><tmpl_if name='type' op='==' value='vhostalias'>vhost_alias</tmpl_if>domain_edit.php?id={tmpl_var name='id'}">{tmpl_var name="this_year_in"}/{tmpl_var name="this_year_out"}</a></td>
36+
<td><a href="#" data-load-content="sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if><tmpl_if name='type' op='==' value='vhostalias'>vhost_alias</tmpl_if>domain_edit.php?id={tmpl_var name='id'}">{tmpl_var name="last_year_in"}/{tmpl_var name="last_year_out"}</a></td>
37+
<td class="text-right"></td>
38+
</tr>
39+
</tmpl_loop>
40+
<tmpl_unless name="records">
41+
<tr class="tbl_row_noresults tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
42+
<td colspan="6">{tmpl_var name='globalsearch_noresults_text_txt'}</td>
43+
</tr>
44+
</tmpl_unless>
45+
<tr>
46+
<td><a href="#" onclick="return false;" style="font-weight:bold;">{tmpl_var name="sum_txt"}</a></td>
47+
<td><a href="#" onclick="return false;" style="font-weight:bold;">{tmpl_var name="sum_this_month"}</a></td>
48+
<td><a href="#" onclick="return false;" style="font-weight:bold;">{tmpl_var name="sum_last_month"}</a></td>
49+
<td><a href="#" onclick="return false;" style="font-weight:bold;">{tmpl_var name="sum_this_year"}</a></td>
50+
<td><a href="#" onclick="return false;" style="font-weight:bold;">{tmpl_var name="sum_last_year"}</a></td>
51+
<td class="text-right"></td>
52+
</tr>
53+
</tbody>
54+
<tfoot>
55+
<tr>
56+
<td colspan="6"><tmpl_var name="paging"></td>
57+
</tr>
58+
</tfoot>
59+
</table>
60+
</div>

0 commit comments

Comments
 (0)