commit | author | age
|
e8b329
|
1 |
<?php |
DM |
2 |
|
|
3 |
class quota_lib { |
f1c4cd
|
4 |
public function get_quota_data($clientid = null, $readable = true) { |
e8b329
|
5 |
global $app; |
DM |
6 |
|
|
7 |
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); |
|
8 |
$monitor_data = array(); |
|
9 |
if(is_array($tmp_rec)) { |
|
10 |
foreach ($tmp_rec as $tmp_mon) { |
|
11 |
$monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data']))); |
|
12 |
} |
|
13 |
} |
|
14 |
//print_r($monitor_data); |
|
15 |
|
b45479
|
16 |
// select all websites or websites belonging to client |
d2713e
|
17 |
$sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".(($clientid != null)?" AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)":''), $clientid); |
e8b329
|
18 |
|
DM |
19 |
//print_r($sites); |
|
20 |
if(is_array($sites) && !empty($sites)){ |
|
21 |
for($i=0;$i<sizeof($sites);$i++){ |
|
22 |
$username = $sites[$i]['system_user']; |
|
23 |
$sites[$i]['used'] = $monitor_data['user'][$username]['used']; |
|
24 |
$sites[$i]['soft'] = $monitor_data['user'][$username]['soft']; |
|
25 |
$sites[$i]['hard'] = $monitor_data['user'][$username]['hard']; |
|
26 |
$sites[$i]['files'] = $monitor_data['user'][$username]['files']; |
|
27 |
|
|
28 |
if (!is_numeric($sites[$i]['used'])){ |
|
29 |
if ($sites[$i]['used'][0] > $sites[$i]['used'][1]){ |
|
30 |
$sites[$i]['used'] = $sites[$i]['used'][0]; |
|
31 |
} else { |
|
32 |
$sites[$i]['used'] = $sites[$i]['used'][1]; |
|
33 |
} |
|
34 |
} |
|
35 |
if (!is_numeric($sites[$i]['soft'])) $sites[$i]['soft']=$sites[$i]['soft'][1]; |
|
36 |
if (!is_numeric($sites[$i]['hard'])) $sites[$i]['hard']=$sites[$i]['hard'][1]; |
|
37 |
if (!is_numeric($sites[$i]['files'])) $sites[$i]['files']=$sites[$i]['files'][1]; |
d2713e
|
38 |
|
MC |
39 |
$sites[$i]['used_raw'] = $sites[$i]['used']; |
|
40 |
$sites[$i]['soft_raw'] = $sites[$i]['soft']; |
|
41 |
$sites[$i]['hard_raw'] = $sites[$i]['hard']; |
|
42 |
$sites[$i]['files_raw'] = $sites[$i]['files']; |
|
43 |
$sites[$i]['used_percentage'] = ($sites[$i]['soft'] > 0 && $sites[$i]['used'] > 0 ? round($sites[$i]['used'] * 100 / $sites[$i]['soft']) : 0); |
|
44 |
|
e8b329
|
45 |
if ($readable) { |
DM |
46 |
// colours |
|
47 |
$sites[$i]['display_colour'] = '#000000'; |
|
48 |
if($sites[$i]['soft'] > 0){ |
|
49 |
$used_ratio = $sites[$i]['used']/$sites[$i]['soft']; |
|
50 |
} else { |
|
51 |
$used_ratio = 0; |
|
52 |
} |
|
53 |
if($used_ratio >= 0.8) $sites[$i]['display_colour'] = '#fd934f'; |
|
54 |
if($used_ratio >= 1) $sites[$i]['display_colour'] = '#cc0000'; |
|
55 |
|
|
56 |
if($sites[$i]['used'] > 1024) { |
|
57 |
$sites[$i]['used'] = round($sites[$i]['used'] / 1024, 2).' MB'; |
|
58 |
} else { |
|
59 |
if ($sites[$i]['used'] != '') $sites[$i]['used'] .= ' KB'; |
|
60 |
} |
|
61 |
|
|
62 |
if($sites[$i]['soft'] > 1024) { |
|
63 |
$sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 2).' MB'; |
|
64 |
} else { |
|
65 |
$sites[$i]['soft'] .= ' KB'; |
|
66 |
} |
|
67 |
|
|
68 |
if($sites[$i]['hard'] > 1024) { |
|
69 |
$sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 2).' MB'; |
|
70 |
} else { |
|
71 |
$sites[$i]['hard'] .= ' KB'; |
|
72 |
} |
|
73 |
|
|
74 |
if($sites[$i]['soft'] == " KB") $sites[$i]['soft'] = $app->lng('unlimited'); |
|
75 |
if($sites[$i]['hard'] == " KB") $sites[$i]['hard'] = $app->lng('unlimited'); |
|
76 |
|
|
77 |
if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = $app->lng('unlimited'); |
|
78 |
if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = $app->lng('unlimited'); |
|
79 |
|
|
80 |
/* |
|
81 |
if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B'; |
|
82 |
if(!strstr($sites[$i]['soft'],'M') && !strstr($sites[$i]['soft'],'K')) $sites[$i]['soft'].= ' B'; |
|
83 |
if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B'; |
|
84 |
*/ |
|
85 |
} |
|
86 |
else { |
|
87 |
if (empty($sites[$i]['soft'])) $sites[$i]['soft'] = -1; |
|
88 |
if (empty($sites[$i]['hard'])) $sites[$i]['hard'] = -1; |
|
89 |
|
|
90 |
if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = -1; |
|
91 |
if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = -1; |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
return $sites; |
|
97 |
} |
a641dd
|
98 |
|
D |
99 |
public function get_trafficquota_data($clientid = null, $lastdays = 0) { |
|
100 |
global $app; |
|
101 |
|
|
102 |
$traffic_data = array(); |
|
103 |
|
|
104 |
// select vhosts (belonging to client) |
|
105 |
if($clientid != null){ |
cc7a82
|
106 |
$sql_where = " AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)"; |
a641dd
|
107 |
} |
cc7a82
|
108 |
$sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')".$sql_where, $clientid); |
a641dd
|
109 |
|
D |
110 |
$hostnames = array(); |
|
111 |
$traffic_data = array(); |
|
112 |
|
|
113 |
foreach ($sites as $site) { |
|
114 |
$hostnames[] = $site['domain']; |
|
115 |
$traffic_data[$site['domain']]['domain_id'] = $site['domain_id']; |
|
116 |
} |
|
117 |
|
|
118 |
// fetch all traffic-data of selected vhosts |
|
119 |
if (!empty($hostnames)) { |
|
120 |
$tmp_year = date('Y'); |
|
121 |
$tmp_month = date('m'); |
|
122 |
// This Month |
cc7a82
|
123 |
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames); |
a641dd
|
124 |
foreach ($tmp_recs as $tmp_rec) { |
7105a0
|
125 |
$traffic_data[$tmp_rec['hostname']]['this_month'] = $tmp_rec['t']; |
a641dd
|
126 |
} |
D |
127 |
// This Year |
cc7a82
|
128 |
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames); |
a641dd
|
129 |
foreach ($tmp_recs as $tmp_rec) { |
D |
130 |
$traffic_data[$tmp_rec['hostname']]['this_year'] = $tmp_rec['t']; |
|
131 |
} |
|
132 |
|
|
133 |
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); |
|
134 |
$tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); |
|
135 |
// Last Month |
cc7a82
|
136 |
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames); |
a641dd
|
137 |
foreach ($tmp_recs as $tmp_rec) { |
D |
138 |
$traffic_data[$tmp_rec['hostname']]['last_month'] = $tmp_rec['t']; |
|
139 |
} |
|
140 |
|
|
141 |
$tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1)); |
|
142 |
// Last Year |
cc7a82
|
143 |
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames); |
a641dd
|
144 |
foreach ($tmp_recs as $tmp_rec) { |
D |
145 |
$traffic_data[$tmp_rec['hostname']]['last_year'] = $tmp_rec['t']; |
|
146 |
} |
|
147 |
|
|
148 |
if (is_int($lastdays) && ($lastdays > 0)) { |
|
149 |
// Last xx Days |
cc7a82
|
150 |
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE (traffic_date >= DATE_SUB(NOW(), INTERVAL ? DAY)) AND hostname IN ? GROUP BY hostname", $lastdays, $hostnames); |
a641dd
|
151 |
foreach ($tmp_recs as $tmp_rec) { |
D |
152 |
$traffic_data[$tmp_rec['hostname']]['lastdays'] = $tmp_rec['t']; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
return $traffic_data; |
|
158 |
} |
|
159 |
|
f1c4cd
|
160 |
public function get_mailquota_data($clientid = null, $readable = true) { |
e8b329
|
161 |
global $app; |
DM |
162 |
|
|
163 |
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC"); |
|
164 |
$monitor_data = array(); |
|
165 |
if(is_array($tmp_rec)) { |
|
166 |
foreach ($tmp_rec as $tmp_mon) { |
|
167 |
//$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data']))); |
|
168 |
$tmp_array = unserialize($app->db->unquote($tmp_mon['data'])); |
|
169 |
if(is_array($tmp_array)) { |
|
170 |
foreach($tmp_array as $username => $data) { |
|
171 |
if(!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used']; |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
//print_r($monitor_data); |
|
177 |
|
b45479
|
178 |
// select all email accounts or email accounts belonging to client |
d2713e
|
179 |
$emails = $app->db->queryAllRecords("SELECT * FROM mail_user".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid); |
e8b329
|
180 |
|
DM |
181 |
//print_r($emails); |
|
182 |
if(is_array($emails) && !empty($emails)){ |
|
183 |
for($i=0;$i<sizeof($emails);$i++){ |
|
184 |
$email = $emails[$i]['email']; |
|
185 |
|
|
186 |
$emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0); |
|
187 |
|
|
188 |
if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1]; |
3eefd1
|
189 |
|
d2713e
|
190 |
$emails[$i]['quota_raw'] = $emails[$i]['quota']; |
MC |
191 |
$emails[$i]['used_raw'] = $emails[$i]['used']; |
|
192 |
$emails[$i]['used_percentage'] = ($emails[$i]['quota'] > 0 && $emails[$i]['used'] > 0 ? round($emails[$i]['used'] * 100 / $emails[$i]['quota']) : 0); |
|
193 |
|
|
194 |
|
3eefd1
|
195 |
if ($readable) { |
DM |
196 |
// colours |
|
197 |
$emails[$i]['display_colour'] = '#000000'; |
|
198 |
if($emails[$i]['quota'] > 0){ |
|
199 |
$used_ratio = $emails[$i]['used']/$emails[$i]['quota']; |
|
200 |
} else { |
|
201 |
$used_ratio = 0; |
|
202 |
} |
|
203 |
if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; |
|
204 |
if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; |
|
205 |
|
|
206 |
if($emails[$i]['quota'] == 0){ |
|
207 |
$emails[$i]['quota'] = $app->lng('unlimited'); |
|
208 |
} else { |
|
209 |
$emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB'; |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
if($emails[$i]['used'] < 1544000) { |
|
214 |
$emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB'; |
|
215 |
} else { |
|
216 |
$emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB'; |
|
217 |
} |
e8b329
|
218 |
} |
DM |
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
return $emails; |
|
223 |
} |
e9a084
|
224 |
|
D |
225 |
public function get_databasequota_data($clientid = null, $readable = true) { |
|
226 |
global $app; |
|
227 |
|
|
228 |
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC"); |
|
229 |
$monitor_data = array(); |
|
230 |
if(is_array($tmp_rec)) { |
|
231 |
foreach ($tmp_rec as $tmp_mon) { |
|
232 |
$tmp_array = unserialize($app->db->unquote($tmp_mon['data'])); |
|
233 |
if(is_array($tmp_array)) { |
|
234 |
foreach($tmp_array as $key => $data) { |
|
235 |
if(!isset($monitor_data[$data['database_name']]['size'])) $monitor_data[$data['database_name']]['size'] = $data['size']; |
|
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
//print_r($monitor_data); |
|
241 |
|
|
242 |
// select all databases belonging to client |
|
243 |
$databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid); |
|
244 |
|
|
245 |
//print_r($databases); |
|
246 |
if(is_array($databases) && !empty($databases)){ |
|
247 |
for($i=0;$i<sizeof($databases);$i++){ |
|
248 |
$databasename = $databases[$i]['database_name']; |
|
249 |
|
|
250 |
$databases[$i]['used'] = isset($monitor_data[$databasename]['size']) ? $monitor_data[$databasename]['size'] : 0; |
|
251 |
|
|
252 |
$databases[$i]['quota_raw'] = $databases[$i]['database_quota']; |
|
253 |
$databases[$i]['used_raw'] = $databases[$i]['used']; |
|
254 |
$databases[$i]['used_percentage'] = (($databases[$i]['database_quota'] > 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used'] * 100 / $databases[$i]['database_quota']) : 0; |
|
255 |
|
|
256 |
if ($readable) { |
|
257 |
// colours |
|
258 |
$databases[$i]['display_colour'] = '#000000'; |
|
259 |
if($databases[$i]['database_quota'] > 0){ |
|
260 |
$used_ratio = $databases[$i]['used']/$databases[$i]['database_quota']; |
|
261 |
} else { |
|
262 |
$used_ratio = 0; |
|
263 |
} |
|
264 |
if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f'; |
|
265 |
if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000'; |
|
266 |
|
|
267 |
if($databases[$i]['database_quota'] == 0){ |
|
268 |
$databases[$i]['database_quota'] = $app->lng('unlimited'); |
|
269 |
} else { |
|
270 |
$databases[$i]['database_quota'] = round($databases[$i]['database_quota'] / 1048576, 4).' MB'; |
|
271 |
} |
|
272 |
|
|
273 |
|
|
274 |
if($databases[$i]['used'] < 1544000) { |
|
275 |
$databases[$i]['used'] = round($databases[$i]['used'] / 1024, 4).' KB'; |
|
276 |
} else { |
|
277 |
$databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 4).' MB'; |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
return $databases; |
|
284 |
} |
|
285 |
|
e8b329
|
286 |
} |