From b758a5c083ac9678ceca8169d96a53402c78e5b6 Mon Sep 17 00:00:00 2001 From: Steven Mondji-Lerider Date: Thu, 13 Mar 2014 14:56:34 +0000 Subject: [PATCH] Script to correct mailboxes sizes. --- .gitattributes | 1 + src/fix_dovecot_quota.php | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 src/fix_dovecot_quota.php diff --git a/.gitattributes b/.gitattributes index 9505dac3..30c14cf7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -643,6 +643,7 @@ src/delete_logs.sh -text src/do_actions.php -text src/du.pl -text src/export_account.php -text +src/fix_dovecot_quota.php -text src/fixperms.sh -text src/functions.sh -text src/functions_dns.sh -text diff --git a/src/fix_dovecot_quota.php b/src/fix_dovecot_quota.php new file mode 100755 index 00000000..8562da96 --- /dev/null +++ b/src/fix_dovecot_quota.php @@ -0,0 +1,91 @@ +#!/usr/bin/php5 -q + $val){ + $nb2=count($options[$opt]); +} + +if ( $nb2 != 1 ){ + echo "usage : script -[m|l|d]\n"; + exit(1); +} + + +#function taking a query used to select the mailbox(es) root and updating their quotas into the mailbox table +function FixQuotaDovecot($query){ + global $db; + $db2=new DB_System(); + + if(!$db->query($query)){ + echo "failed"; + exit(1); + } + while ($db->next_record()) { + $dir=$db->f("dir"); + $id=$db->f("id"); + $size = exec ( "/usr/bin/du -sb $dir|cut -f1" ); + if(!$db2->query("UPDATE mailbox set bytes=$size where id=$id;")){ + echo "fail updating quota for mailbox :".$id."\n"; + } + } + +} + +#We construct a sql query to get the mailbox root based on the option. +switch($opt){ + case "m": + if (!filter_var($val,FILTER_VALIDATE_EMAIL)) { + echo " the email you entered is syntaxically incorrect\n"; + exit(1); + } + $query="select mailbox.id,concat(path, '/Maildir/') as dir from mailbox + join address on address.id = mailbox.address_id + join domaines on domaines.id = address.domain_id + where concat(address.address,'@',domaines.domaine) ='".$val."';"; + break; + case "l": + $login=strtolower($val); + if (!preg_match("#^[a-z0-9]+$#",$login)) { //$ + echo " the login you entered is syntaxically incorrect\n"; + exit(1); + } + $query=("select mailbox.id,concat(path, '/Maildir/') as dir from mailbox + join address on mailbox.address_id = address.id + join domaines on address.domain_id = domaines.id + join membres on domaines.compte = membres.uid where membres.login = '".$login."';"); + break; + case "d": + if(checkfqdn($val) != 0){ + echo " the domain you entered is syntaxically incorrect\n"; + exit(1); + } + $query="select mailbox.id,concat(path, '/Maildir/') as dir from mailbox + join address on mailbox.address_id = address.id + join domaines on address.domain_id = domaines.id where domaines.domaine = '".$val."' ;"; + print_r($query); + break; + default: + echo "usage : script -[m|l|d]\n"; + exit(1); +} + +FixQuotaDovecot($query); + +exit(0); + +?>