Alternc  latest
Alternc logiel libre pour l'hébergement
quotas_users.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  LICENSE
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License (GPL)
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  To read the license please visit http://www.gnu.org/copyleft/gpl.html
17  ----------------------------------------------------------------------
18 */
19 
20 /**
21  * Display the quotas of one or some users
22  *
23  * @copyright AlternC-Team 2000-2017 https://alternc.com/
24  */
25 
26 require_once("../class/config.php");
27 
28 $fields = array (
29  "mode" => array ("request", "integer" ,0),
30  "sd" => array ("request", "integer" ,0),
31  "usr" => array ("request", "integer" ,0),
32  "order" => array ("request", "integer" ,0),
33 );
35 
36 if (!$admin->enabled) {
37  $msg->raise("ERROR", "admin", _("This page is restricted to authorized staff"));
38  echo $msg->msg_html_all();
39  exit();
40 }
41 
42 include_once ("head.php");
43 
44 ?>
45 <h3><?php __("Quotas status"); ?></h3>
46 <hr id="topbar"/>
47 <br />
48 <?php
49 echo $msg->msg_html_all();
50 ?>
51 <p>
52 <?php __("This page shows the space and service count of your AlternC server and each AlternC accounts.");
53 echo "<br /><br />"; printf(_("If you want to manage them, go to")."&nbsp;<a href=\"adm_list.php\">"._("Administration -> Manage the Alternc accounts")."</a>"); ?>
54 </p>
55 <p>
56 <?php printf(_("Sizes are shown as %s"),($mode==0 || $mode==4)?_("MB."):_("% of the total.")); ?>
57 </p>
58 <p>
59 <?php __("Server-side view:"); ?> <span class="ina <?php if ($mode==4) { echo 'ina-active'; } ?>"><a href="quotas_users.php?mode=4"><?php __("Global"); ?></a></span><br /><br />
60 <?php __("Detailed view:"); ?>
61  <span class="ina <?php if ($mode==0) { echo 'ina-active'; } ?>"><a href="quotas_users.php?mode=0&amp;sd=<?php echo $sd; ?>&amp;usr=<?php echo $usr; ?>"><?php __("In MB"); ?></a></span>
62  <span class="ina <?php if ($mode==1) { echo 'ina-active'; } ?>"><a href="quotas_users.php?mode=1&amp;sd=<?php echo $sd; ?>&amp;usr=<?php echo $usr; ?>"><?php __("Percentage"); ?></a></span>
63  <span class="ina <?php if ($mode==2) { echo 'ina-active'; } ?>"><a href="quotas_users.php?mode=2&amp;sd=<?php echo $sd; ?>&amp;usr=<?php echo $usr; ?>"><?php __("Graphical"); ?></a></span>
64 <?php if ($mode != 4) { ?>
65 <?php if ($usr==0) { if ($sd==0) { ?>
66  <span class="ina"><a href="quotas_users.php?mode=<?php echo $mode; ?>&amp;sd=1&amp;usr=<?php echo $usr; ?>"><?php __("Show the domain names"); ?></a></span>
67  <?php } else { ?>
68  <span class="ina"><a href="quotas_users.php?mode=<?php echo $mode; ?>&amp;sd=0&amp;usr=<?php echo $usr; ?>"><?php __("Hide the domain names"); ?></a></span>
69  <?php } } ?>
70 <?php if ($usr) { ?>
71  <span class="ina"><a href="quotas_users.php?mode=<?php echo $mode; ?>&amp;sd=<?php echo $sd; ?>"><?php __("All accounts"); ?></a></span>
72 <?php } ?>
73 <?php } ?>
74 </p>
75 
76 <?php if ($mode == 4) {
77  // Mode : global display
78 
79  if ($cuid != 2000)
80  {
81  $mList = array();
82  $membres_list = $admin->get_list(0, $cuid);
83  foreach ($membres_list as $n) {
84  $domList = $dom->enum_domains($n["uid"]);
85  $mList[$n["uid"]] = array (
86  "login" => $n["login"],
87  "domaines" => $domList,
88  );
89  }
90 
91  $totalweb = 0; $totalmail = 0; $totallist = 0; $totaldb = 0;
92  $dc = 0; $mc = 0; $mlc = 0; $dbc = 0;
93 
94  foreach ($mList as $mUID => $mData)
95  {
96  $tmpweb = $quota->get_size_web_sum_user($mUID);
97  $totalweb += $tmpweb;
98 
99  if (!empty($mData["domaines"]))
100  {
101  foreach ($mData["domaines"] as $domaine)
102  {
103  $dc++;
104 
105  $tmpmail = $quota->get_size_mail_sum_domain($domaine);
106  $totalmail += $tmpmail;
107  $mc = $quota->get_size_mail_count_domain($domaine);
108 
109  $tmplist = $quota->get_size_mailman_sum_domain($domaine);
110  $totallist += $tmplist;
111  }
112  }
113 
114  $mlc = $quota->get_size_mailman_count_user($mUID);
115  $tmpdb = $quota->get_size_db_sum_user($mData["login"]);
116  $totaldb += $tmpdb;
117  $dbc = $quota->get_size_db_count_user($mData["login"]);
118  }
119 
120  $tmptotal=$totalweb+$totallist+$totalmail+($totaldb/1024);
121  $totaltotal=$quota->get_size_unit($tmptotal);
122  }
123  else
124  {
125  $tmptotalweb = $quota->get_size_web_sum_all(); // In KB
126  $totalweb=$quota->get_size_unit($tmptotalweb * 1024);
127 
128  $tmptotalmail = $quota->get_size_mail_sum_all(); // In B
129  $totalmail=$quota->get_size_unit($tmptotalmail);
130 
131  $tmptotallist = $quota->get_size_mailman_sum_all(); // IN KB
132  $totallist=$quota->get_size_unit($tmptotallist * 1024);
133 
134  $tmptotaldb = $quota->get_size_db_sum_all(); // IN B
135  $totaldb=$quota->get_size_unit($tmptotaldb);
136 
137  $tmptotaltotal=($tmptotalweb*1024)+($tmptotallist*1024)+$tmptotalmail+$tmptotaldb; // IN B
138  $totaltotal=$quota->get_size_unit($tmptotaltotal);
139 
140  $dc = $dom->count_domains_all();
141  $mc = $quota->get_size_mail_count_all();
142  $mlc = $quota->get_size_mailman_count_all();
143  $dbc = $quota->get_size_db_count_all();
144  }
145 
146 ?>
147 <center>
148 <div>
149 <table class="tedit" width="100%">
150 <thead>
151  <tr><th>&nbsp;</th><th><?php __("Count"); ?></th><th><?php __("Space"); ?></th></tr>
152 </thead>
153 <tbody>
154 <tr>
155  <th><?php __("Domains"); ?></th>
156  <td><?php echo $dc; ?></td>
157  <td><?php echo sprintf("%.1f", $totalweb['size'])."&nbsp;".$totalweb['unit']; ?></td>
158 </tr>
159 <tr>
160  <th><?php __("Email addresses"); ?></th>
161  <td><?php echo $mc; ?></td>
162  <td><?php echo sprintf("%.1f", $totalmail['size'])."&nbsp;".$totalmail['unit']; ?></td>
163 </tr>
164 <?php if ($mlc) { ?>
165 <tr>
166  <th><?php __("Mailman lists"); ?></th>
167  <td><?php echo $mlc; ?></td>
168  <td><?php echo sprintf("%.1f", $totallist['size'])."&nbsp;".$totallist['unit']; ?></td>
169 </tr>
170  <?php } ?>
171 <tr>
172  <th><?php __("MySQL Databases"); ?></th>
173  <td><?php echo $dbc; ?></td>
174  <td><?php echo sprintf("%.1f", $totaldb['size'])."&nbsp;".$totaldb['unit']; ?></td>
175 </tr>
176 <tr>
177  <th colspan="2"><?php __("Total"); ?></th>
178  <td><?php echo sprintf("%.1f", $totaltotal['size'])."&nbsp;".$totaltotal['unit']; ?></td>
179 </tr>
180 </tbody>
181 </table>
182 </div>
183 </center>
184 <?php } elseif ($usr==0) {
185  // Mode : display all accounts
186 
187  function sortlink($txt,$asc,$desc) {
188  global $order,$mode,$sd,$usr;
189  if ($order==$asc) $neworder=$desc; else $neworder=$asc;
190  echo "<th";
191  if ($order==$asc) echo " class=\"headerSortUp\"";
192  if ($order==$desc) echo " class=\"headerSortDown\"";
193  echo ">";
194  echo "<a href=\"quotas_users.php?order=".$neworder."&mode=".$mode."&sd=".$sd."&usr=".$usr."\">";
195  echo $txt;
196  echo "</a>";
197  echo "</th>";
198  }
199 
200 ?>
201 <center>
202 
203 <div>
204 <table class="tedit" width="100%">
205 <thead>
206  <tr><th rowspan="2"><?php sortlink(_("Account"),0,1); ?></th><th colspan="3"><?php __("Count"); ?></th><th colspan="5"><?php __("Space"); ?></th></tr>
207 <tr>
208 <?php sortlink(_("Dom"),2,3); ?>
209 <?php sortlink(_("Mails"),4,5); ?>
210 <?php sortlink(_("Lists"),6,7); ?>
211 <?php sortlink(_("Web"),8,9); ?>
212 <?php sortlink(_("Mails"),10,11); ?>
213 <?php sortlink(_("Lists"),12,13); ?>
214 <?php sortlink(_("DB"),14,15); ?>
215 <?php sortlink(_("Total"),16,17); ?>
216 </tr>
217 </thead>
218 <tbody>
219 <?php
220 
221  $afields=array("login","domaincount","mailcount","mailmancount","websize","mailsize","mailmansize","dbsize","totalsize");
222 
223 if ($cuid != 2000)
224 {
225  $mList = array();
226  $membres_list = $admin->get_list(0, $cuid);
227  foreach ($membres_list as $minfo) {
228  $domList = $dom->enum_domains($minfo['uid']);
229  $mList[$muid] = array (
230  "login" => $minfo['login'],
231  "domaines" => $domList,
232  );
233  }
234 
235  $totalweb = 0; $totalmail = 0; $totallist = 0; $totaldb = 0;
236  $dc = 0; $mc = 0; $mlc = 0; $dbc = 0;
237 
238  foreach ($mList as $mUID => $mData)
239  {
240  $tmpweb = $quota->get_size_web_sum_user($mUID);
241  $totalweb += $tmpweb;
242 
243  if (!empty($mData["domaines"]))
244  {
245  foreach ($mData["domaines"] as $domaine)
246  {
247  $dc++;
248 
249  $tmpmail = $quota->get_size_mail_sum_domain($domaine);
250  $totalmail += $tmpmail;
251  $mc = $quota->get_size_mail_count_domain($domaine);
252 
253  $tmplist = $quota->get_size_mailman_sum_domain($domaine);
254  $totallist += $tmplist;
255  }
256  }
257 
258  $mlc = $quota->get_size_mailman_count_user($mUID);
259  $tmpdb = $quota->get_size_db_sum_user($mData["login"]);
260  $totaldb += $tmpdb;
261  $dbc = $quota->get_size_db_count_user($mData["login"]);
262  }
263 
264 }
265 else
266 {
267  $totalweb = $quota->get_size_web_sum_all();
268  $totalmail = $quota->get_size_mail_sum_all();
269  $totallist = $quota->get_size_mailman_sum_all();
270  $totaldb = $quota->get_size_db_sum_all();
271 }
272 
273 $totaltotal=$totalweb+$totallist+($totalmail/1024)+($totaldb/1024); // In KB
274 if ($totaltotal==0) $totaltotal=1;
275 
276 if ($cuid != 2000) {
277  $membres_list = $admin->get_list(0, $cuid);
278 } else {
279  $membres_list = $admin->get_list(1);
280 }
281 
282 
283 
284 // ------------------------------------------------------------
285 // LOOP ON EACH MEMBER
286 $all=array();
287 foreach ($membres_list as $c) {
288 
289  $one=$c;
290 
291  // We show account AND domains
292  $domaines_list = $dom->enum_domains($c["uid"]);
293  $dc=0; // Domain Count
294  $ms=0; // Mail Space
295  $mls=0;
296  $one["domains"]=array();
297  foreach ($domaines_list as $d) {
298  $dc++;
299  $one["domains"][]=$d;
300  $mstmp = $quota->get_size_mail_sum_domain($d);
301  $ms+=$mstmp;
302  $mlstmp = $quota->get_size_mailman_sum_domain($d);
303  $mls+=$mlstmp;
304  }
305  $one["mailsize"]=$ms;
306  $one["mailmansize"]=$mls;
307 
308  // Mail Count
309  $maildomains_list = $mail->enum_domains($c["uid"]);
310  $mc = 0;
311  foreach ($maildomains_list as $md) {
312  $mc += $md['nb_mail'];
313  }
314 
315  $one["mailcount"]=$mc;
316  $one["domaincount"]=$dc;
317 
318  // Mailman List Count
319  if (isset($mailman)) {
320  $mlc = $mailman->count_ml_user($c["uid"]);
321  $one["mailmancount"]=$mlc;
322  }
323 
324  // Espace WEB
325  $ws = $quota->get_size_web_sum_user($c["uid"]);
326  $one["websize"]=$ws;
327  // Espace Mail :
328 
329  // Espace DB :
330 $ds = $quota->get_size_db_sum_user($c["login"]);
331 $one["dbsize"]=$ds;
332 
333 $ts=$ds/1024+$ws+$ms/1024+$mls; // In KB
334 $one["totalsize"]=$ts;
335 $all[]=$one;
336 }
337 
338 // SORT this $all array
339 $asc=(($order%2)==0);
340 $fie=$afields[intval($order/2)];
341 function mysort($a,$b) {
342  global $fie,$asc;
343  if ($asc) {
344  if ($a[$fie]<$b[$fie]) return -1;
345  if ($a[$fie]>$b[$fie]) return 1;
346  return 0;
347  } else {
348  if ($a[$fie]<$b[$fie]) return 1;
349  if ($a[$fie]>$b[$fie]) return -1;
350  return 0;
351  }
352 
353 }
354 usort($all,"mysort");
355 
356 
357 // ------------------------------------------------------------
358 // LOOP ON EACH MEMBER
359 foreach ($all as $c) {
360 
361  echo "<tr><td>";
362 
363  // We show all accounts and domains
364  echo "<b><a href=\"quotas_users.php?mode=".$mode."&sd=".$sd."&usr=".$c["uid"]."\">".$c["login"]."</a></b><br />\n";
365  $domaines_list = $dom->enum_domains($c["uid"]);
366  $dc=0; // Domain Count
367  $ms=0; // Mail Space
368  $mls=0;
369  foreach ($c["domains"] as $d) {
370  if ($sd) echo "&nbsp;&nbsp;&nbsp;-&nbsp;{$d}<br />\n";
371  }
372 
373  $ms=$c["mailsize"];
374  $mls=$c["mailmansize"];
375 
376  $mailsize=$quota->get_size_unit($ms);
377  $mailmansize=$quota->get_size_unit($mls * 1024);
378 
379  // WEB space quota
380  $ws = $c["websize"];
381  $webspace=$quota->get_size_unit($ws * 1024);
382  if (isset($totalweb) && $totalweb){
383  $pc=intval(100*$ws/$totalweb);
384  } else {
385  $pc=0;
386  }
387  $dc=$c["domaincount"];
388  $mc=$c["mailcount"];
389  $mlc=$c["mailmancount"];
390 
391  echo "</td><td>$dc</td><td>$mc</td><td>$mlc</td><td";
392  if ($mode!=2) echo " style=\"text-align: right\"";
393  echo ">";
394 
395 if ($mode==0) {
396  echo sprintf("%.1f", $webspace['size'])."&nbsp;".$webspace['unit'];
397 } elseif ($mode==1) {
398  echo sprintf("%.1f",$pc)."&nbsp;%";
399 } else {
400  $quota->quota_displaybar($pc);
401 }
402  echo "</td><td";
403  if ($mode!=2) echo " style=\"text-align: right\"";
404  echo ">";
405 
406  // Mail space quota
407 
408 if ($totalmail)
409  $pc=intval(100*$ms/$totalmail);
410 else
411  $pc=0;
412 
413 if ($mode==0) {
414  echo sprintf("%.1f", $mailsize['size'])."&nbsp;".$mailsize['unit'];
415 } elseif ($mode==1) {
416  echo sprintf("%.1f",$pc)."&nbsp;%";
417 } else {
418  $quota->quota_displaybar($pc);
419 }
420 
421  echo "</td><td";
422  if ($mode!=2) echo " style=\"text-align: right\"";
423  echo ">";
424 
425  // Mailman space quota
426 if ($totallist)
427  $pc=intval(100*$mls/$totallist);
428 else
429  $pc=0;
430 
431 if ($mode==0) {
432  echo sprintf("%.1f", $mailmansize['size'])."&nbsp;".$mailmansize['unit'];
433 } elseif ($mode==1) {
434  echo sprintf("%.1f",$pc)."&nbsp;%";
435 } else {
436  $quota->quota_displaybar($pc);
437 }
438 
439 echo "</td><td";
440 if ($mode!=2) echo " style=\"text-align: right\"";
441 echo ">";
442 
443 // MySQL db space
444 $ds = $c["dbsize"];
445 $dbsize=$quota->get_size_unit($ds);
446 
447 if ($totaldb)
448  $pc=intval(100*$ds/$totaldb);
449 else
450  $pc=0;
451 
452 if ($mode==0) {
453  echo sprintf("%.1f", $dbsize['size'])."&nbsp;".$dbsize['unit'];
454 } elseif ($mode==1) {
455  echo sprintf("%.1f",$pc)."&nbsp;%";
456 } else {
457  $quota->quota_displaybar($pc);
458 }
459 
460 echo "</td><td";
461 if ($mode!=2) echo " style=\"text-align: right\"";
462 echo ">";
463 
464 // Total space
465 $ts=$c["totalsize"];
466 $totalsize=$quota->get_size_unit($ts * 1024);
467 if ($mode==0) {
468  echo sprintf("%.1f", $totalsize['size'])."&nbsp;".$totalsize['unit'];
469 } elseif ($mode==1) {
470  echo sprintf("%.1f",(100*$ts/$totaltotal))."&nbsp;%";
471 } else {
472  if ($totaltotal) {
473  $pc=intval(100*$ts/$totaltotal);
474  } else {
475  $pc=0;
476  }
477  $quota->quota_displaybar($pc);
478 }
479 
480 
481 echo "</td>";
482 
483 echo "</tr>";
484 
485 }
486 
487 ?>
488 </tbody>
489 
490 
491 </table>
492 </div>
493 </center>
494 <?php
495  } else { // Display only ONE accoutn
496 
497  $oneuser_ok = false;
498  if ($cuid != 2000) {
499  $c = $admin->get($usr);
500  $mcreator = $admin->get_creator($c['uid']);
501  if ($mcreator['uid'] == $cuid) {
502  $oneuser_ok = true;
503  }
504  } else {
505  $c = $admin->get($usr);
506  if ($c != false) {
507  $oneuser_ok = true;
508  }
509  }
510 
511  if ($oneuser_ok) { // quotas_oneuser.php will used prefilled $c
512  define("QUOTASONE","1");
513  require_once("quotas_oneuser.php");
514  }
515 
516  } // endif only one account
517 ?>
518 <?php include_once("foot.php"); ?>
exit
Definition: adm_doadd.php:70
$mode
Definition: adm_tldedit.php:40
$msg
Definition: bootstrap.php:75
$c
Definition: bootstrap.php:47
$cuid
Definition: bootstrap.php:43
$d
__($str)
Definition: functions.php:404
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
Definition: functions.php:688
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))
$totalsize
Definition: quota_show.php:45
foreach($db_sizes as $d) if(count($db_sizes) > 0 && $mode==0) $totallist
foreach($domaines_user as $domaine) $totaldb
$totalmail
$totalweb
$fields
Display the quotas of one or some users.
$dom
Definition: whois_test.php:10