Commit 4e444d92 authored by Benjamin Sonntag's avatar Benjamin Sonntag

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

parent 11b5e1a1
......@@ -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
......
......@@ -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);
......
......@@ -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"));
......
......@@ -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
......@@ -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 mmorisation 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.';
......@@ -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)
......
<?php
require_once("/var/alternc/bureau/class/config_nochk.php");
// On dverrouile 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 );
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment