From 4e444d92e073142ab563e8400147cae7c15a2317 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Wed, 26 Apr 2006 14:26:21 +0000 Subject: [PATCH] Adding spoolsize to cache the size of web / mail / db contents, Closes 569 --- .gitattributes | 1 + bureau/class/m_bro.php | 2 +- bureau/class/m_mail.php | 7 +++---- debian/alternc.cron.d | 4 ++++ install/upgrades/0.9.5.sql | 31 ++++++++++++++++++++++++++++++ src/Makefile | 2 +- src/spoolsize.php | 39 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 src/spoolsize.php diff --git a/.gitattributes b/.gitattributes index c27f2adb..4ba78e2b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -428,6 +428,7 @@ src/quota_init -text src/rawstat.daily -text src/sendmail -text src/slave_dns -text +src/spoolsize.php -text src/sqlbackup.sh -text src/update_domains.sh -text tools/get_account_by_domain -text diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index 50339045..d80ca1fe 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -126,7 +126,7 @@ class m_bro { if ($dir = @opendir($absolute)) { while (($file = readdir($dir)) !== false) { if ($file!="." && $file!="..") { - $c[]=array("name"=>$file, "size"=>$size, "date"=>filemtime($absolute."/".$file), "type"=> (!is_dir($absolute."/".$file)) ); + $c[]=array("name"=>$file, "size"=>$this->fsize($absolute."/".$file), "date"=>filemtime($absolute."/".$file), "type"=> (!is_dir($absolute."/".$file)) ); } } closedir($dir); diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index ae6fd7d8..a300dc31 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -109,11 +109,10 @@ class m_mail { $res=array(); $i=0; while ($db->next_record()) { if ($db->f("pop")) { - /* - $size=exec("/usr/lib/alternc/du.pl /var/alternc/mail/".substr($info[$i]["mail"][0],0,1)."/".str_replace("@","_",$info[$i]["mail"][0])); - $size=$size*1024; - */ $size=0; + $r=mysql_query("SELECT size FROM size_mail WHERE alias='".str_replace("@","_",$db->f("mail"))."';"); + list($size)=@mysql_fetch_array($r); + $size=$size*1024; } else $size=0; if ($db->f("pop")) { $login=str_replace("@","_",$db->f("mail")); diff --git a/debian/alternc.cron.d b/debian/alternc.cron.d index 5efcf2d0..6f5a65f1 100644 --- a/debian/alternc.cron.d +++ b/debian/alternc.cron.d @@ -10,3 +10,7 @@ # Every hour, check for slave_dns refreshes 5 * * * * root /usr/lib/alternc/slave_dns + +# Every day at 2am, compute web, mail and db space usage per account. +# You may put this computing every week only or on your filer on busy services. +0 2 * * * www-data /usr/lib/alternc/spoolsize.php diff --git a/install/upgrades/0.9.5.sql b/install/upgrades/0.9.5.sql index 03a359e9..2b0c807d 100644 --- a/install/upgrades/0.9.5.sql +++ b/install/upgrades/0.9.5.sql @@ -9,3 +9,34 @@ UPDATE ftpusers SET encrypted_password=ENCRYPT(password) WHERE password!=''; -- Force le bureau https si voulu : INSERT INTO variable SET name='force_https', value='0', comment='Shall we force the users to access the managment desktop through HTTPS only ? If this value is true, HTTPS access will be forced. '; + +-- -------------------------------------------------------- +-- TABLES de mémorisation de la taille des dossiers web/mail/db + +CREATE TABLE IF NOT EXISTS `size_db` ( + `db` varchar(255) NOT NULL default '', + `size` int(10) unsigned NOT NULL default '0', + `ts` timestamp(14) NOT NULL, + PRIMARY KEY (`db`), + KEY `ts` (`ts`) +) TYPE=MyISAM COMMENT='MySQL Database used space'; + + +-- -------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `size_mail` ( + `alias` varchar(255) NOT NULL default '', + `size` int(10) unsigned NOT NULL default '0', + `ts` timestamp(14) NOT NULL, + PRIMARY KEY (`alias`), + KEY `ts` (`ts`) +) TYPE=MyISAM COMMENT='Mail space used by pop accounts.'; + +-- -------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `size_web` ( + `uid` int(10) unsigned NOT NULL default '0', + `size` int(10) unsigned NOT NULL default '0', + `ts` timestamp(14) NOT NULL, + PRIMARY KEY (`uid`), + KEY `ts` (`ts`) +) TYPE=MyISAM COMMENT='Web space used by accounts.'; + diff --git a/src/Makefile b/src/Makefile index ebee8700..55756632 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,7 +28,7 @@ CC?=cc CC+=$(CFLAGS) PROGS=mail_add mail_del quota_edit quota_get mem_add mem_del db_create -SCRIPTS=quota_edit.sh quota_get.sh basedir_prot.sh sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail +SCRIPTS=quota_edit.sh quota_get.sh basedir_prot.sh sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php BIN=$(DESTDIR)/usr/lib/alternc/ all: $(PROGS) diff --git a/src/spoolsize.php b/src/spoolsize.php new file mode 100644 index 00000000..50b8c07b --- /dev/null +++ b/src/spoolsize.php @@ -0,0 +1,39 @@ +"; + +echo "---------------------------\n Generating size-cache for mail accounts\n\n"; +$r=mysql_query("SELECT * FROM mail_users WHERE alias NOT LIKE '%@%' AND alias LIKE '%\_%';"); +while ($c=mysql_fetch_array($r)) { + echo $c["alias"]; flush(); + $size=exec("/usr/lib/alternc/du.pl ".$c["path"]); + mysql_query("REPLACE INTO size_mail SET alias='".addslashes($c["alias"])."',size='$size';"); + echo " done ($size KB)\n"; flush(); +} + +echo "---------------------------\n Generating size-cache for db accounts\n\n"; +$r=mysql_query("SELECT db FROM db;"); +while ($c=mysql_fetch_array($r)) { + echo $c["db"]; flush(); + $size=$mysql->get_db_size($c["db"]) { + mysql_query("REPLACE INTO size_db SET db='".addslashes($c["db"])."',size='$size';"); + echo " done ($size KB) \n"; flush(); +} + +echo "---------------------------\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("/usr/lib/alternc/du.pl /var/alternc/html/".substr($c["login"],0,1)."/".$c["login"]); + mysql_query("REPLACE INTO size_web SET uid='".$c["uid"]."',size='$size';"); + echo " done ($size KB) \n"; flush(); +} + +// On relocke le bureau pour éviter un msg d'erreur. +sem_acquire( $alternc_sem ); + +?> \ No newline at end of file