From e63de8a4038af96046665136150cca0d503647e2 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Thu, 27 Mar 2014 11:16:31 +0000 Subject: [PATCH] Fix spoolsize pour le web --- .gitattributes | 1 + etc/alternc/alternc-sudoers | 2 +- src/quota_get_all | 29 +++++++++++++++++++++++++++++ src/spoolsize.php | 22 ++++++++++++++++------ 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 src/quota_get_all diff --git a/.gitattributes b/.gitattributes index 0f418af0..a57a8bcb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -664,6 +664,7 @@ src/quota-warning.sh -text src/quota_delete -text src/quota_edit -text src/quota_get -text +src/quota_get_all -text src/quota_init -text src/rebuild_all_webconf.sh -text src/sendmail -text diff --git a/etc/alternc/alternc-sudoers b/etc/alternc/alternc-sudoers index 2ca01f0b..82baf029 100644 --- a/etc/alternc/alternc-sudoers +++ b/etc/alternc/alternc-sudoers @@ -1,2 +1,2 @@ -alterncpanel ALL = NOPASSWD : /usr/bin/quota, /usr/sbin/setquota, /usr/lib/alternc/fixperms.sh, /usr/lib/alternc/mem_add, /usr/lib/alternc/mem_del, /usr/lib/alternc/quota_edit, /usr/lib/alternc/quota_get, /usr/lib/alternc/du.pl, /usr/lib/alternc/update_mails.sh +alterncpanel ALL = NOPASSWD : /usr/bin/quota, /usr/sbin/setquota, /usr/lib/alternc/fixperms.sh, /usr/lib/alternc/mem_add, /usr/lib/alternc/mem_del, /usr/lib/alternc/quota_edit, /usr/lib/alternc/quota_get, /usr/lib/alternc/du.pl, /usr/lib/alternc/update_mails.sh, /usr/sbin/repquota vmail ALL = NOPASSWD : /usr/lib/dovecot/deliver diff --git a/src/quota_get_all b/src/quota_get_all new file mode 100755 index 00000000..1a07770d --- /dev/null +++ b/src/quota_get_all @@ -0,0 +1,29 @@ +#!/bin/bash +# List quotas of all users in 3 columns : +# id used quota + +source /etc/alternc/local.sh + +#checking if quotas are installed +command -v /usr/sbin/repquota >/dev/null || { echo "Quotas uninstalled"; exit 0; } + +get_quota() { + quotadir="$1" + if [ "$quotadir" = "/" ] ; then + sudo repquota -g -v -n -p "$quotadir" 2>/dev/null || (echo "Error: can't get quota"; exit 1) + else + sudo repquota -g -v -n -p "$quotadir" 2>/dev/null || get_quota "$(dirname $quotadir)" + fi +} + +# Some help : this is what we must parse +# Block limits File limits +#Group used soft hard grace used soft hard grace +#---------------------------------------------------------------------- +#root -- 1612116 0 0 96181 0 0 +#adm -- 14532 0 0 226 0 0 + +get_quota "$ALTERNC_HTML" | egrep "^\#[0-9]+"|while read gid blank bused bsoft bhard bgrace fused fsoft fhard fgrace ; do + echo ${gid/\#/} $bused $bhard +done + diff --git a/src/spoolsize.php b/src/spoolsize.php index cbcef6a0..b5088a77 100644 --- a/src/spoolsize.php +++ b/src/spoolsize.php @@ -6,12 +6,22 @@ require_once("/usr/share/alternc/panel/class/config_nochk.php"); global $db; echo "\n---------------------------\n Generating size-cache for web accounts\n\n"; -$r=mysql_query("SELECT uid,login FROM membres;"); -while ($c=mysql_fetch_array($r)) { - echo $c["login"]; flush(); - $size=exec("sudo /usr/lib/alternc/du.pl ".ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"]); - $db->query("REPLACE INTO size_web SET uid='".$c["uid"]."',size='$size';"); - echo " done ($size KB) \n"; flush(); +exec("/usr/lib/alternc/quota_get_all", $list_quota_tmp); +$list_quota=array(); +foreach ($list_quota_tmp as $qt) { + $qt = explode(" ", $qt); + $list_quota[$qt[0]] = array('used'=>$qt[1], 'quota'=>$qt[2]); +} + +if ($db->query("SELECT uid,login FROM membres;")) { + $db2 = new DB_system(); + while ($db->next_record()) { + if (isset($list_quota[$db->f('uid')])) { + $qu=$list_quota[$db->f('uid')]; + $db2->query("INSERT OR REPLACE INTO size_web SET uid='".intval($db->f('uid'))."',size='".intval($qu['used'])."';"); + echo $db->f('login')." (".$qu['used']." B)\n"; + } + } } echo "\n---------------------------\n Generating size-cache for MySQL databases\n\n";