Adding spoolsize to cache the size of web / mail / db contents, Closes 569

This commit is contained in:
Benjamin Sonntag 2006-04-26 14:26:21 +00:00
parent 11b5e1a1c2
commit 4e444d92e0
7 changed files with 80 additions and 6 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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);

View File

@ -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"));

View File

@ -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

View File

@ -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.';

View File

@ -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)

39
src/spoolsize.php Normal file
View File

@ -0,0 +1,39 @@
<?php
require_once("/var/alternc/bureau/class/config_nochk.php");
// On déverrouile le bureau AlternC :)
alternc_shutdown();
echo "<pre>";
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 );
?>