root/trunk/gui/admin/domain_statistics.php

Revision 1327, 6.2 kB (checked in by rats, 4 months ago)

* Fixed: --scan-knownbad-files and --check-deleted are no longer supported by rkhunter
* Fixed #1471: chkrootkit should be in lenny / hardy
* Updated Chinese (simplified)
* Updated German
* Fixed #1475: typo on installation (ispcp-setup)
* Fixed: default user for rkhunter.log

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $tpl = new pTemplate();
26 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/domain_statistics.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('hosting_plans', 'page');
29 $tpl->define_dynamic('month_list', 'page');
30 $tpl->define_dynamic('year_list', 'page');
31 $tpl->define_dynamic('traffic_table', 'page');
32 $tpl->define_dynamic('traffic_table_item', 'traffic_table');
33
34 $theme_color = Config::get('USER_INITIAL_THEME');
35
36 $tpl->assign(
37     array('TR_ADMIN_DOMAIN_STATISTICS_PAGE_TITLE' => tr('ispCP - Domain Statistics Data'),
38         'THEME_COLOR_PATH' => "../themes/$theme_color",
39         'THEME_CHARSET' => tr('encoding'),
40         'ISP_LOGO' => get_logo($_SESSION['user_id'])
41         )
42     );
43
44 if (isset($_POST['domain_id'])) {
45     $domain_id = $_POST['domain_id'];
46 } else if (isset($_GET['domain_id'])) {
47     $domain_id = $_GET['domain_id'];
48 }
49
50 $year = 0;
51 $month = 0;
52
53 if (isset($_POST['month']) && isset($_POST['year'])) {
54     $year = $_POST['year'];
55
56     $month = $_POST['month'];
57 } else if (isset($_GET['month']) && isset($_GET['year'])) {
58     $month = $_GET['month'];
59
60     $year = $_GET['year'];
61 }
62
63 if (!is_numeric($domain_id) || !is_numeric($month) || !is_numeric($year)) {
64     header("Location: reseller_statistics.php");
65
66     die();
67 }
68
69 function get_domain_trafic($from, $to, $domain_id) {
70     $sql = Database::getInstance();
71     $query = <<<SQL_QUERY
72         select
73             IFNULL(sum(dtraff_web), 0) as web_dr,
74             IFNULL(sum(dtraff_ftp), 0) as ftp_dr,
75             IFNULL(sum(dtraff_mail), 0) as mail_dr,
76             IFNULL(sum(dtraff_pop), 0) as pop_dr
77         from
78             domain_traffic
79         where
80             domain_id=? and dtraff_time>=? and dtraff_time<=?
81 SQL_QUERY;
82
83     $rs = exec_query($sql, $query, array($domain_id, $from, $to));
84
85     if ($rs->RecordCount() == 0) {
86         return array(0, 0, 0, 0);
87     } else {
88         return
89         array($rs->fields['web_dr'], $rs->fields['ftp_dr'],
90
91             $rs->fields['pop_dr'], $rs->fields['mail_dr'],
92             );
93     }
94 }
95
96 function generate_page (&$tpl, $domain_id) {
97     $sql = Database::getInstance();
98     global $month, $year;
99     global $web_trf, $ftp_trf, $smtp_trf, $pop_trf,
100     $sum_web, $sum_ftp, $sum_mail, $sum_pop;
101
102     $fdofmnth = mktime(0, 0, 0, $month, 1, $year);
103     $ldofmnth = mktime(1, 0, 0, $month + 1, 0, $year);
104
105     if ($month == date('m') && $year == date('Y')) {
106         $curday = date('j');
107     } else {
108         $tmp = mktime(1, 0, 0, $month + 1, 0, $year);
109         $curday = date('j', $tmp);
110     }
111
112     $curtimestamp = time();
113     $firsttimestamp = mktime(0, 0, 0, $month, 1, $year);
114
115     $all[0] = 0;
116     $all[1] = 0;
117     $all[2] = 0;
118     $all[3] = 0;
119     $all[4] = 0;
120     $all[5] = 0;
121     $all[6] = 0;
122     $all[7] = 0;
123
124     $counter = 0;
125     for($i = 1;$i <= $curday;$i++) {
126         $ftm = mktime(0, 0, 0, $month, $i, $year);
127
128         $ltm = mktime(23, 59, 59, $month, $i, $year);
129
130         $query = <<<SQL_QUERY
131             select
132                 dtraff_web,dtraff_ftp,dtraff_mail,dtraff_pop,dtraff_time
133             from
134                 domain_traffic
135             where
136                 domain_id=? and dtraff_time>=? and dtraff_time<=?
137 SQL_QUERY;
138
139         $rs = exec_query($sql, $query, array($domain_id, $ftm, $ltm));
140
141         $has_data = false;
142
143         list($web_trf,
144             $ftp_trf,
145             $pop_trf,
146             $smtp_trf) = get_domain_trafic($ftm, $ltm, $domain_id);
147
148         $date_formt = Config::get('DATE_FORMAT');
149         if ($web_trf == 0 && $ftp_trf == 0 && $smtp_trf == 0 && $pop_trf == 0) {
150             $tpl->assign(
151                 array('MONTH' => $month,
152                     'YEAR' => $year,
153                     'DOMAIN_ID' => $domain_id,
154                     'DATE' => date($date_formt, strtotime($year . "-" . $month . "-" . $i)),
155                     'WEB_TRAFFIC' => 0,
156                     'FTP_TRAFFIC' => 0,
157                     'SMTP_TRAFFIC' => 0,
158                     'POP3_TRAFFIC' => 0,
159                     'ALL_TRAFFIC' => 0,
160
161                     )
162                 );
163         } else {
164             if ($counter % 2 == 0) {
165                 $tpl->assign('ITEM_CLASS', 'content');
166             } else {
167                 $tpl->assign('ITEM_CLASS', 'content2');
168             }
169             $sum_web += $web_trf;
170             $sum_ftp += $ftp_trf;
171             $sum_mail += $smtp_trf;
172             $sum_pop += $pop_trf;
173
174             $tpl->assign(
175                 array('DATE' => date($date_formt, strtotime($year . "-" . $month . "-" . $i)),
176                     'WEB_TRAFFIC' => sizeit($web_trf),
177                     'FTP_TRAFFIC' => sizeit($ftp_trf),
178                     'SMTP_TRAFFIC' => sizeit($smtp_trf),
179                     'POP3_TRAFFIC' => sizeit($pop_trf),
180                     'ALL_TRAFFIC' => sizeit($web_trf + $ftp_trf + $smtp_trf + $pop_trf),
181                     )
182                 );
183             $tpl->parse('TRAFFIC_TABLE_ITEM', '.traffic_table_item');
184
185             $counter ++;
186         }
187
188         $tpl->assign(
189             array('MONTH' => $month,
190                 'YEAR' => $year,
191                 'DOMAIN_ID' => $domain_id,
192
193                 'ALL_WEB_TRAFFIC' => sizeit($sum_web),
194                 'ALL_FTP_TRAFFIC' => sizeit($sum_ftp),
195                 'ALL_SMTP_TRAFFIC' => sizeit($sum_mail),
196                 'ALL_POP3_TRAFFIC' => sizeit($sum_pop),
197                 'ALL_ALL_TRAFFIC' => sizeit($sum_web + $sum_ftp + $sum_mail + $sum_pop),
198                 )
199             );
200
201         $tpl->parse('TRAFFIC_TABLE', 'traffic_table');
202     }
203 }
204
205 /*
206  *
207  * static page messages.
208  *
209  */
210
211 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_statistics.tpl');
212 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_statistics.tpl');
213
214 $tpl->assign(
215     array('TR_DOMAIN_STATISTICS' => tr('Domain statistics'),
216         'TR_MONTH' => tr('Month'),
217         'TR_YEAR' => tr('Year'),
218         'TR_SHOW' => tr('Show'),
219         'TR_WEB_TRAFFIC' => tr('Web traffic'),
220         'TR_FTP_TRAFFIC' => tr('FTP traffic'),
221         'TR_SMTP_TRAFFIC' => tr('SMTP traffic'),
222         'TR_POP3_TRAFFIC' => tr('POP3/IMAP traffic'),
223         'TR_ALL_TRAFFIC' => tr('All traffic'),
224         'TR_ALL' => tr('All'),
225         'TR_DAY' => tr('Day'),
226         )
227     );
228
229 gen_select_lists($tpl, $month, $year);
230
231 generate_page($tpl, $domain_id);
232
233 gen_page_message($tpl);
234
235 $tpl->parse('PAGE', 'page');
236
237 $tpl->prnt();
238
239 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
240
241 unset_messages();
242 ?>
243
Note: See TracBrowser for help on using the browser.