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
$q=$quota->getquota();
if (!is_array($q) || empty($q) ) {
echo "<p class=\"alert alert-danger\">"._("No quotas for this account, or quotas currently unavailable!")."</p>";
include_once("foot.php");
die();
$msg->raise('Alert', "quota", _("No quotas for this account, or quotas currently unavailable!"));
include_once("main.php");
exit();
}
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 = 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>
<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">
@ -30,6 +40,8 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<!-- Mails -->
<p style="text-align: left; font-size:16px;"><b><?php __("Emails"); ?></b></p>
<table class="tedit" width="100%">
<thead>
<tr>
@ -41,7 +53,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody>
<?php
$domaines_user = $dom->enum_domains($mem->user["uid"]);
$domaines_user = $dom->enum_domains($id_usr);
$totalmail=0;
foreach ($domaines_user as $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;
}
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";
if ($mode!=2) echo " style=\"text-align: right\"";
echo "><i>";
echo "><i><b>";
if ($mode==0) {
echo sprintf("%.1f", $d['size'])."&nbsp;".$d['unit'];
} elseif ($mode==1) {
@ -95,7 +107,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
} else {
$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 -->
<?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);
echo "<p>"._("Databases:")." ";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
echo "<p style=\"text-align: left; font-size:16px;\"><b>"._("Databases:")." ";
echo "</b></p>";
?>
<table class="tedit" width="100%">
@ -124,7 +136,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody>
<?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) {
echo "<tr><td>".$d["db"]."</td><td";
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) {
echo sprintf("%.1f", $pc)."&nbsp;%";
} else {
$quota->quota_displaybar(2*$pc, 0);
$quota->quota_displaybar($pc, 0);
}
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>
</table>
@ -151,16 +170,16 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<!-- Mailing lists -->
<?php
$totallist = $quota->get_size_mailman_sum_user($mem->user["uid"]);
$totallist = $quota->get_size_mailman_sum_user($id_usr);
if ($totallist) {
// $totalweb is in KB, so we call get_size_unit() with it in Bytes
$t=$quota->get_size_unit($totallist * 1024);
echo "<p>"._("Mailman lists:")." ";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
echo "<p style=\"text-align: left; font-size:16px;\"><b>"._("Mailman lists:")." ";
echo "</b></p>";
?>
<table class="tedit" width='60%'>
<table class="tedit" width='100%'>
<thead>
<tr>
<th><?php __("Lists"); ?></th>
@ -170,14 +189,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
<tbody>
<?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) {
echo "<tr><td>".$d["list"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\"";
echo ">";
$ds = $quota->get_size_unit($d["size"] * 1024);
if ($totallist) {
$pc=intval(100*$ds['size']/$totallist);
$pc=intval(100*$d['size']/$totallist);
} else {
$pc=0;
}
@ -190,10 +209,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
}
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>
</table>
<?php } /* totallist */ ?>
</div>
<p>&nbsp;</p>
</center>

View File

@ -11,7 +11,8 @@ $fields = array (
getFields($fields);
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();
}
@ -22,9 +23,7 @@ include_once ("head.php");
<hr id="topbar"/>
<br />
<?php
if (isset($error) && $error) {
echo "<p class=\"alert alert-warning\">$error</p>";
}
echo $msg->msg_html_all();
?>
<p>
<?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;
}
$one["mailsize"]=$ms;
$one["mailmainsize"]=$mls;
$one["mailmansize"]=$mls;
// Mail Count
$maildomains_list = $mail->enum_domains($c["uid"]);
@ -350,7 +349,7 @@ foreach ($all as $c) {
$mls=$c["mailmansize"];
$mailsize=$quota->get_size_unit($ms);
$mailmansize=$quota->get_size_unit($mls);
$mailmansize=$quota->get_size_unit($mls * 1024);
// Espace WEB
$ws = $c["websize"];

View File

@ -137,8 +137,8 @@ class m_quota {
* the defaults value.
*/
function synchronise_user_profile() {
global $db, $err;
$err->log("quota", "synchronise_user_profile");
global $db, $msg;
$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);";
if (!$db->query($q)) {
return false;
@ -153,8 +153,8 @@ class m_quota {
*/
function create_missing_quota_profile() {
global $db, $quota, $err;
$err->log("quota", "create_missing_quota_profile");
global $db, $quota, $msg;
$msg->log("quota", "create_missing_quota_profile");
$qt = $quota->getquota('', true);
$type = $quota->listtype();
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)
*/
function getquota($ressource = "", $recheck = false) {
global $db, $err, $cuid, $get_quota_cache, $hooks, $mem;
$err->log("quota", "getquota", $ressource);
global $db, $msg, $cuid, $get_quota_cache, $hooks, $mem;
$msg->log("quota", "getquota", $ressource);
if ($recheck) { // rebuilding quota
$get_quota_cache = null;
$this->quotas = array();
@ -240,8 +240,8 @@ class m_quota {
* @param integer size of the quota (available or used)
*/
function setquota($ressource, $size) {
global $err, $db, $cuid;
$err->log("quota", "setquota", $ressource . "/" . $size);
global $msg, $db, $cuid;
$msg->log("quota", "setquota", $ressource . "/" . $size);
if (floatval($size) == 0) {
$size = "0";
}
@ -252,7 +252,7 @@ class m_quota {
$a = array();
exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
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;
}
}
@ -272,8 +272,8 @@ class m_quota {
* Erase all quota information about the user.
*/
function delquotas() {
global $db, $err, $cuid;
$err->log("quota", "delquota");
global $db, $msg, $cuid;
$msg->log("quota", "delquota");
$db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid));
return true;
}
@ -327,14 +327,14 @@ class m_quota {
* @return boolean true if all went ok
*/
function addtype($type) {
global $db, $err;
global $db, $msg;
$qlist = $this->qlist();
if (empty($type)) {
return false;
}
$type = strtolower($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;
}
while (list($key, $val) = each($qlist)) {
@ -383,8 +383,8 @@ class m_quota {
* The user we are talking about is in the global $cuid.
*/
function addquotas() {
global $db, $err, $cuid;
$err->log("quota", "addquota");
global $db, $msg, $cuid;
$msg->log("quota", "addquota");
$ql = $this->qlist();
reset($ql);
@ -478,7 +478,7 @@ class m_quota {
/* sum of mailbox sizes from all domains */
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 */
@ -491,19 +491,19 @@ class m_quota {
/* count of mailbox sizes from all domains */
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 */
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 */
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 */
@ -515,7 +515,7 @@ class m_quota {
/* sum of mailman lists sizes for one domain */
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 */
@ -624,8 +624,8 @@ class m_quota {
* globals $cuid is the appropriate user
*/
function hook_admin_add_member() {
global $err;
$err->log("quota", "hook_admin_add_member");
global $msg;
$msg->log("quota", "hook_admin_add_member");
$this->addquotas();
$this->getquota('', true); // actualise quota
}
@ -637,8 +637,8 @@ class m_quota {
* EXPERIMENTAL function ;)
*/
function alternc_export_conf() {
global $err;
$err->log("quota", "export");
global $msg;
$msg->log("quota", "export");
$str = " <quota>";
$q = $this->getquota();