root/trunk/gui/reseller/domain_statistics.php

Revision 1327, 7.4 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('RESELLER_TEMPLATE_PATH') . '/domain_statistics.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', '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(array('TR_ADMIN_DOMAIN_STATISTICS_PAGE_TITLE' => tr('ispCP - Domain Statistics Data'),
37         'THEME_COLOR_PATH' => "../themes/$theme_color",
38         'THEME_CHARSET' => tr('encoding'),
39         'ISP_LOGO' => get_logo($_SESSION['user_id'])));
40
41 if (isset($_POST['domain_id'])) {
42     $domain_id = $_POST['domain_id'];
43 } else if (isset($_GET['domain_id'])) {
44     $domain_id = $_GET['domain_id'];
45 }
46
47 if (isset($_POST['month']) && isset($_POST['year'])) {
48     $year = intval($_POST['year']);
49     $month = intval($_POST['month']);
50 } else if (isset($_GET['month']) && isset($_GET['year'])) {
51     $month = intval($_GET['month']);
52     $year = intval($_GET['year']);
53 } else {
54     $month = date("m");
55     $year = date("Y");
56 }
57
58 if (!is_numeric($domain_id) || !is_numeric($month) || !is_numeric($year)) {
59     header("Location: reseller_statistics.php");
60     die();
61 }
62
63 function get_domain_trafic($from, $to, $domain_id)
64 {
65     $sql = Database::getInstance();
66     $reseller_id = $_SESSION['user_id'];
67     $query = <<<SQL_QUERY
68         select
69           domain_id
70         from
71           domain
72         where
73             domain_id = ? and domain_created_id = ?
74 SQL_QUERY;
75
76     $rs = exec_query($sql, $query, array($domain_id, $reseller_id));
77     if ($rs->RecordCount() == 0) {
78         set_page_message(tr('User does not exist or you do not have permission to access this interface!'));
79         header('Location: user_statistics.php');
80         die();
81     }
82
83     $query = <<<SQL_QUERY
84         select
85             IFNULL(sum(dtraff_web), 0) as web_dr,
86             IFNULL(sum(dtraff_ftp), 0) as ftp_dr,
87             IFNULL(sum(dtraff_mail), 0) as mail_dr,
88             IFNULL(sum(dtraff_pop), 0) as pop_dr
89         from
90             domain_traffic
91         where
92             domain_id = ? and dtraff_time >= ? and dtraff_time <= ?
93 SQL_QUERY;
94     $rs = exec_query($sql, $query, array($domain_id, $from, $to));
95
96     if ($rs->RecordCount() == 0) {
97         return array(0, 0, 0, 0);
98     } else {
99         return array($rs->fields['web_dr'],
100             $rs->fields['ftp_dr'],
101             $rs->fields['pop_dr'],
102             $rs->fields['mail_dr']);
103     }
104 }
105
106 function generate_page (&$tpl, $domain_id) {
107     $sql = Database::getInstance();
108     global $month, $year;
109     global $web_trf, $ftp_trf, $smtp_trf, $pop_trf,
110     $sum_web, $sum_ftp, $sum_mail, $sum_pop;
111
112     $fdofmnth = mktime(0, 0, 0, $month, 1, $year);
113     $ldofmnth = mktime(1, 0, 0, $month + 1, 0, $year);
114
115     if ($month == date('m') && $year == date('Y')) {
116         $curday = date('j');
117     } else {
118         $tmp = mktime(1, 0, 0, $month + 1, 0, $year);
119         $curday = date('j', $tmp);
120     }
121
122     $curtimestamp = time();
123     $firsttimestamp = mktime(0, 0, 0, $month, 1, $year);
124
125     $all[0] = 0;
126     $all[1] = 0;
127     $all[2] = 0;
128     $all[3] = 0;
129     $all[4] = 0;
130     $all[5] = 0;
131     $all[6] = 0;
132     $all[7] = 0;
133
134     $counter = 0;
135     for ($i = 1; $i <= $curday; $i++) {
136         $ftm = mktime(0, 0, 0, $month, $i, $year);
137         $ltm = mktime(23, 59, 59, $month, $i, $year);
138
139         $query = <<<SQL_QUERY
140             select
141                 dtraff_web,dtraff_ftp,dtraff_mail,dtraff_pop,dtraff_time
142             from
143                 domain_traffic
144             where
145                 domain_id = ? and dtraff_time >= ? and dtraff_time <= ?
146 SQL_QUERY;
147         $rs = exec_query($sql, $query, array($domain_id, $ftm, $ltm));
148
149         $has_data = false;
150         list($web_trf, $ftp_trf, $pop_trf, $smtp_trf) = get_domain_trafic($ftm, $ltm, $domain_id);
151
152         $date_formt = Config::get('DATE_FORMAT');
153         if ($web_trf == 0 && $ftp_trf == 0 && $smtp_trf == 0 && $pop_trf == 0) {
154             $tpl->assign(array('MONTH' => $month,
155                     'YEAR' => $year,
156                     'DOMAIN_ID' => $domain_id,
157                     'DATE' => date($date_formt, strtotime($year . "-" . $month . "-" . $i)),
158                     'WEB_TRAFFIC' => 0,
159                     'FTP_TRAFFIC' => 0,
160                     'SMTP_TRAFFIC' => 0,
161                     'POP3_TRAFFIC' => 0,
162                     'ALL_TRAFFIC' => 0));
163         } else {
164             if ($counter % 2 == 0) {
165                 $tpl->assign('ITEM_CLASS', 'content');
166             } else {
167                 $tpl->assign('ITEM_CLASS', 'content2');
168             }
169
170             $sum_web += $web_trf;
171             $sum_ftp += $ftp_trf;
172             $sum_mail += $smtp_trf;
173             $sum_pop += $pop_trf;
174
175             $tpl->assign(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             $tpl->parse('TRAFFIC_TABLE_ITEM', '.traffic_table_item');
182             $counter ++;
183         }
184
185         $tpl->assign(array('MONTH' => $month,
186                 'YEAR' => $year,
187                 'DOMAIN_ID' => $domain_id,
188                 'ALL_WEB_TRAFFIC' => sizeit($sum_web),
189                 'ALL_FTP_TRAFFIC' => sizeit($sum_ftp),
190                 'ALL_SMTP_TRAFFIC' => sizeit($sum_mail),
191                 'ALL_POP3_TRAFFIC' => sizeit($sum_pop),
192                 'ALL_ALL_TRAFFIC' => sizeit($sum_web + $sum_ftp + $sum_mail + $sum_pop)));
193
194         $tpl->parse('TRAFFIC_TABLE', 'traffic_table');
195     }
196 }
197
198 /*
199  *
200  * static page messages.
201  *
202  */
203
204 gen_reseller_mainmenu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/main_menu_statistics.tpl');
205 gen_reseller_menu($tpl, Config::get('RESELLER_TEMPLATE_PATH') . '/menu_statistics.tpl');
206
207 gen_logged_from($tpl);
208
209 $tpl->assign(array('TR_DOMAIN_STATISTICS' => tr('Domain statistics'),
210         'TR_MONTH' => tr('Month'),
211         'TR_YEAR' => tr('Year'),
212         'TR_SHOW' => tr('Show'),
213         'TR_WEB_TRAFFIC' => tr('Web traffic'),
214         'TR_FTP_TRAFFIC' => tr('FTP traffic'),
215         'TR_SMTP_TRAFFIC' => tr('SMTP traffic'),
216         'TR_POP3_TRAFFIC' => tr('POP3/IMAP traffic'),
217         'TR_ALL_TRAFFIC' => tr('All traffic'),
218         'TR_ALL' => tr('All'),
219         'TR_DAY' => tr('Day'))
220     );
221
222 gen_select_lists($tpl, $month, $year);
223 generate_page($tpl, $domain_id);
224 gen_page_message($tpl);
225
226 $tpl->parse('PAGE', 'page');
227 $tpl->prnt();
228
229 if (Config::get('DUMP_GUI_DEBUG'))
230     dump_gui_debug();
231
232 unset_messages();
233
234 ?>
Note: See TracBrowser for help on using the browser.