classe quota & fichiers section admin associés

This commit is contained in:
quenenni 2017-08-16 19:46:53 +02:00
parent 991b4b48e3
commit 8479d79bde
4 changed files with 79 additions and 51 deletions

View File

@ -37,9 +37,9 @@ include_once("head.php");
<?php <?php
$q=$quota->getquota(); $q=$quota->getquota();
if (!is_array($q) || empty($q) ) { if (!is_array($q) || empty($q) ) {
echo "<p class=\"alert alert-danger\">"._("No quotas for this account, or quotas currently unavailable!")."</p>"; $msg->raise('Alert', "quota", _("No quotas for this account, or quotas currently unavailable!"));
include_once("foot.php"); include_once("main.php");
die(); exit();
} }
echo "<table cellspacing=\"0\" cellpadding=\"4\" class='tlist'>"; echo "<table cellspacing=\"0\" cellpadding=\"4\" class='tlist'>";

View File

@ -8,10 +8,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
$mode = 0; $mode = 0;
} }
// $mode = 4; // Pour Debuguer le mode "graphique" des quotas // $mode = 4; // Pour Debuguer le mode "graphique" des quotas
// Si la var $usr existe, c'est qu'on appelle les quotas pour 1 user à partir des quotas généraux de l'admin
// Sinon, on récupère l'id du user à récupérer via $mem->user["login"]
if (isset($usr) && is_int($usr)) {
$id_usr=$usr;
$login=$admin->get_login_by_uid($id_usr);
} else {
$id_usr = $mem->user["uid"];
$login = $mem->user["login"];
}
?> ?>
<center> <center>
<h3 style="text-align:center;"><?php printf(_("<b>%s</b> account"),$mem->user["login"]); ?></h3> <h3 style="text-align:center;"><?php printf(_("<b>%s</b> account"),$login); ?></h3>
<div style="width: 600px"> <div style="width: 600px">
@ -30,6 +40,8 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<!-- Mails --> <!-- Mails -->
<p style="text-align: left; font-size:16px;"><b><?php __("Emails"); ?></b></p>
<table class="tedit" width="100%"> <table class="tedit" width="100%">
<thead> <thead>
<tr> <tr>
@ -41,7 +53,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody> <tbody>
<?php <?php
$domaines_user = $dom->enum_domains($mem->user["uid"]); $domaines_user = $dom->enum_domains($id_usr);
$totalmail=0; $totalmail=0;
foreach ($domaines_user as $domaine) { foreach ($domaines_user as $domaine) {
$mstmp = $quota->get_size_mail_sum_domain($domaine); $mstmp = $quota->get_size_mail_sum_domain($domaine);
@ -84,10 +96,10 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
$tpc = 0; $tpc = 0;
} }
if (count($alias_sizes) > 0) { if (count($alias_sizes) > 0) {
echo "<tr><td><i>". _('Total'). " {$domaine}</i></td><td></td>"; echo "<tr><td style=\"text-align: right\"><i><b>". _('Total'). " {$domaine}</b></i></td><td></td>";
echo "<td"; echo "<td";
if ($mode!=2) echo " style=\"text-align: right\""; if ($mode!=2) echo " style=\"text-align: right\"";
echo "><i>"; echo "><i><b>";
if ($mode==0) { if ($mode==0) {
echo sprintf("%.1f", $d['size'])."&nbsp;".$d['unit']; echo sprintf("%.1f", $d['size'])."&nbsp;".$d['unit'];
} elseif ($mode==1) { } elseif ($mode==1) {
@ -95,7 +107,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
} else { } else {
$quota->quota_displaybar($tpc); $quota->quota_displaybar($tpc);
} }
echo "</i></td></tr>"; echo "</b></i></td></tr>";
} }
} }
?> ?>
@ -106,12 +118,12 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<!-- Databases --> <!-- Databases -->
<?php <?php
$totaldb = $quota->get_size_db_sum_user($mem->user["login"]); $totaldb = $quota->get_size_db_sum_user($login);
$t = $quota->get_size_unit($totaldb); $t = $quota->get_size_unit($totaldb);
echo "<p>"._("Databases:")." ";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit']; echo "<p style=\"text-align: left; font-size:16px;\"><b>"._("Databases:")." ";
echo "</p>"; echo "</b></p>";
?> ?>
<table class="tedit" width="100%"> <table class="tedit" width="100%">
@ -124,7 +136,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody> <tbody>
<?php <?php
$db_sizes = $quota->get_size_db_details_user($mem->user["login"]); $db_sizes = $quota->get_size_db_details_user($login);
foreach ($db_sizes as $d) { foreach ($db_sizes as $d) {
echo "<tr><td>".$d["db"]."</td><td"; echo "<tr><td>".$d["db"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\""; if ($mode!=2) echo " style=\"text-align: right\"";
@ -140,10 +152,17 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
} elseif (isset($mode) &&$mode==1) { } elseif (isset($mode) &&$mode==1) {
echo sprintf("%.1f", $pc)."&nbsp;%"; echo sprintf("%.1f", $pc)."&nbsp;%";
} else { } else {
$quota->quota_displaybar(2*$pc, 0); $quota->quota_displaybar($pc, 0);
} }
echo "</td></tr>"; echo "</td></tr>";
} }
if (count($db_sizes) > 0 && $mode==0) {
echo "<tr><td style=\"text-align: right\"><i><b>". _('Total'). " " . _("Databases:")."</b></i></td>";
echo "<td style=\"text-align: right\"><i><b>";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</b></i></td></tr>";
}
?> ?>
</tbody> </tbody>
</table> </table>
@ -151,16 +170,16 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<!-- Mailing lists --> <!-- Mailing lists -->
<?php <?php
$totallist = $quota->get_size_mailman_sum_user($mem->user["uid"]); $totallist = $quota->get_size_mailman_sum_user($id_usr);
if ($totallist) { if ($totallist) {
// $totalweb is in KB, so we call get_size_unit() with it in Bytes // $totalweb is in KB, so we call get_size_unit() with it in Bytes
$t=$quota->get_size_unit($totallist * 1024); $t=$quota->get_size_unit($totallist * 1024);
echo "<p>"._("Mailman lists:")." ";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit']; echo "<p style=\"text-align: left; font-size:16px;\"><b>"._("Mailman lists:")." ";
echo "</p>"; echo "</b></p>";
?> ?>
<table class="tedit" width='60%'> <table class="tedit" width='100%'>
<thead> <thead>
<tr> <tr>
<th><?php __("Lists"); ?></th> <th><?php __("Lists"); ?></th>
@ -170,14 +189,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody> <tbody>
<?php <?php
$mailman_size = $quota->get_size_mailman_details_user($mem->user["uid"]); $mailman_size = $quota->get_size_mailman_details_user($id_usr);
foreach ($mailman_size as $d) { foreach ($mailman_size as $d) {
echo "<tr><td>".$d["list"]."</td><td"; echo "<tr><td>".$d["list"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\""; if ($mode!=2) echo " style=\"text-align: right\"";
echo ">"; echo ">";
$ds = $quota->get_size_unit($d["size"] * 1024); $ds = $quota->get_size_unit($d["size"] * 1024);
if ($totallist) { if ($totallist) {
$pc=intval(100*$ds['size']/$totallist); $pc=intval(100*$d['size']/$totallist);
} else { } else {
$pc=0; $pc=0;
} }
@ -190,10 +209,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
} }
echo "</td></tr>"; echo "</td></tr>";
} }
if (count($db_sizes) > 0 && $mode==0) {
echo "<tr><td style=\"text-align: right\"><i><b>". _('Total'). " " . _("Mailman lists:")."</b></i></td>";
echo "<td";
if ($mode!=2) echo " style=\"text-align: right\"";
echo "><i><b>";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</b></i></td></tr>";
}
?> ?>
</tbody> </tbody>
</table> </table>
<?php } /* totallist */ ?> <?php } /* totallist */ ?>
</div> </div>
<p>&nbsp;</p>
</center> </center>

View File

@ -11,7 +11,8 @@ $fields = array (
getFields($fields); getFields($fields);
if (!$admin->enabled) { if (!$admin->enabled) {
__("This page is restricted to authorized staff"); $msg->raise('Error', "admin", _("This page is restricted to authorized staff"));
echo $msg->msg_html_all();
exit(); exit();
} }
@ -22,9 +23,7 @@ include_once ("head.php");
<hr id="topbar"/> <hr id="topbar"/>
<br /> <br />
<?php <?php
if (isset($error) && $error) { echo $msg->msg_html_all();
echo "<p class=\"alert alert-warning\">$error</p>";
}
?> ?>
<p> <p>
<?php __("This page shows the space and service count of your AlternC server and each AlternC accounts."); <?php __("This page shows the space and service count of your AlternC server and each AlternC accounts.");
@ -279,7 +278,7 @@ foreach ($membres_list as $c) {
$mls+=$mlstmp; $mls+=$mlstmp;
} }
$one["mailsize"]=$ms; $one["mailsize"]=$ms;
$one["mailmainsize"]=$mls; $one["mailmansize"]=$mls;
// Mail Count // Mail Count
$maildomains_list = $mail->enum_domains($c["uid"]); $maildomains_list = $mail->enum_domains($c["uid"]);
@ -350,7 +349,7 @@ foreach ($all as $c) {
$mls=$c["mailmansize"]; $mls=$c["mailmansize"];
$mailsize=$quota->get_size_unit($ms); $mailsize=$quota->get_size_unit($ms);
$mailmansize=$quota->get_size_unit($mls); $mailmansize=$quota->get_size_unit($mls * 1024);
// Espace WEB // Espace WEB
$ws = $c["websize"]; $ws = $c["websize"];

View File

@ -137,8 +137,8 @@ class m_quota {
* the defaults value. * the defaults value.
*/ */
function synchronise_user_profile() { function synchronise_user_profile() {
global $db, $err; global $db, $msg;
$err->log("quota", "synchronise_user_profile"); $msg->log("quota", "synchronise_user_profile");
$q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);"; $q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
if (!$db->query($q)) { if (!$db->query($q)) {
return false; return false;
@ -153,8 +153,8 @@ class m_quota {
*/ */
function create_missing_quota_profile() { function create_missing_quota_profile() {
global $db, $quota, $err; global $db, $quota, $msg;
$err->log("quota", "create_missing_quota_profile"); $msg->log("quota", "create_missing_quota_profile");
$qt = $quota->getquota('', true); $qt = $quota->getquota('', true);
$type = $quota->listtype(); $type = $quota->listtype();
foreach ($type as $t) { foreach ($type as $t) {
@ -172,8 +172,8 @@ class m_quota {
* @Return array the quota used and total for this ressource (or for all ressource if unspecified) * @Return array the quota used and total for this ressource (or for all ressource if unspecified)
*/ */
function getquota($ressource = "", $recheck = false) { function getquota($ressource = "", $recheck = false) {
global $db, $err, $cuid, $get_quota_cache, $hooks, $mem; global $db, $msg, $cuid, $get_quota_cache, $hooks, $mem;
$err->log("quota", "getquota", $ressource); $msg->log("quota", "getquota", $ressource);
if ($recheck) { // rebuilding quota if ($recheck) { // rebuilding quota
$get_quota_cache = null; $get_quota_cache = null;
$this->quotas = array(); $this->quotas = array();
@ -240,8 +240,8 @@ class m_quota {
* @param integer size of the quota (available or used) * @param integer size of the quota (available or used)
*/ */
function setquota($ressource, $size) { function setquota($ressource, $size) {
global $err, $db, $cuid; global $msg, $db, $cuid;
$err->log("quota", "setquota", $ressource . "/" . $size); $msg->log("quota", "setquota", $ressource . "/" . $size);
if (floatval($size) == 0) { if (floatval($size) == 0) {
$size = "0"; $size = "0";
} }
@ -252,7 +252,7 @@ class m_quota {
$a = array(); $a = array();
exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a); exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
if (!isset($a[1]) || $size != $a[1]) { if (!isset($a[1]) || $size != $a[1]) {
$err->raise("quota", _("Error writing the quota entry!")); $msg->raise('Error', "quota", _("Error writing the quota entry!"));
return false; return false;
} }
} }
@ -272,8 +272,8 @@ class m_quota {
* Erase all quota information about the user. * Erase all quota information about the user.
*/ */
function delquotas() { function delquotas() {
global $db, $err, $cuid; global $db, $msg, $cuid;
$err->log("quota", "delquota"); $msg->log("quota", "delquota");
$db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid)); $db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid));
return true; return true;
} }
@ -327,14 +327,14 @@ class m_quota {
* @return boolean true if all went ok * @return boolean true if all went ok
*/ */
function addtype($type) { function addtype($type) {
global $db, $err; global $db, $msg;
$qlist = $this->qlist(); $qlist = $this->qlist();
if (empty($type)) { if (empty($type)) {
return false; return false;
} }
$type = strtolower($type); $type = strtolower($type);
if (!preg_match("#^[a-z0-9]*$#", $type)) { if (!preg_match("#^[a-z0-9]*$#", $type)) {
$err->raise("quota", "Type can only contains characters a-z and 0-9"); $msg->raise('Error', "quota", _("Type can only contains characters a-z and 0-9")); // à traduire
return false; return false;
} }
while (list($key, $val) = each($qlist)) { while (list($key, $val) = each($qlist)) {
@ -383,8 +383,8 @@ class m_quota {
* The user we are talking about is in the global $cuid. * The user we are talking about is in the global $cuid.
*/ */
function addquotas() { function addquotas() {
global $db, $err, $cuid; global $db, $msg, $cuid;
$err->log("quota", "addquota"); $msg->log("quota", "addquota");
$ql = $this->qlist(); $ql = $this->qlist();
reset($ql); reset($ql);
@ -478,7 +478,7 @@ class m_quota {
/* sum of mailbox sizes from all domains */ /* sum of mailbox sizes from all domains */
function get_size_mail_sum_all() { function get_size_mail_sum_all() {
return $this->_get_sum_sql("SELECT SUM(bytes) AS sum FROM mailbox WHERE delivery = 'dovecot';;"); return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_quota ;");
} }
/* sum of mailbox sizes for one domain */ /* sum of mailbox sizes for one domain */
@ -491,19 +491,19 @@ class m_quota {
/* count of mailbox sizes from all domains */ /* count of mailbox sizes from all domains */
function get_size_mail_count_all() { function get_size_mail_count_all() {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM mailbox WHERE delivery = 'dovecot';"); return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota;");
} }
/* count of mailbox for one domain */ /* count of mailbox for one domain */
function get_size_mail_count_domain($dom) { function get_size_mail_count_domain($dom) {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'"); return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota WHERE user LIKE '%@{$dom}'");
} }
/* get list of mailbox alias and size for one domain */ /* get list of mailbox alias and size for one domain */
function get_size_mail_details_domain($dom) { function get_size_mail_details_domain($dom) {
return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;"); return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_quota WHERE user LIKE '%@{$dom}' ORDER BY alias;");
} }
/* sum of mailman lists sizes from all domains */ /* sum of mailman lists sizes from all domains */
@ -515,7 +515,7 @@ class m_quota {
/* sum of mailman lists sizes for one domain */ /* sum of mailman lists sizes for one domain */
function get_size_mailman_sum_domain($dom) { function get_size_mailman_sum_domain($dom) {
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'"); return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman s INNER JOIN mailman m ON s.list = m.list AND s.uid = m.uid WHERE m.domain = '$dom'");
} }
/* sum of mailman lists for one user */ /* sum of mailman lists for one user */
@ -624,8 +624,8 @@ class m_quota {
* globals $cuid is the appropriate user * globals $cuid is the appropriate user
*/ */
function hook_admin_add_member() { function hook_admin_add_member() {
global $err; global $msg;
$err->log("quota", "hook_admin_add_member"); $msg->log("quota", "hook_admin_add_member");
$this->addquotas(); $this->addquotas();
$this->getquota('', true); // actualise quota $this->getquota('', true); // actualise quota
} }
@ -637,8 +637,8 @@ class m_quota {
* EXPERIMENTAL function ;) * EXPERIMENTAL function ;)
*/ */
function alternc_export_conf() { function alternc_export_conf() {
global $err; global $msg;
$err->log("quota", "export"); $msg->log("quota", "export");
$str = " <quota>"; $str = " <quota>";
$q = $this->getquota(); $q = $this->getquota();