Some cleanup
This commit is contained in:
parent
5b10a1d1b7
commit
eac0be49d2
|
@ -1,90 +1,93 @@
|
||||||
#!/usr/bin/php5 -q
|
#!/usr/bin/php
|
||||||
<?php
|
<?php
|
||||||
require_once("/usr/share/alternc/panel/class/config_nochk.php");
|
require_once("/usr/share/alternc/panel/class/config_nochk.php");
|
||||||
|
|
||||||
#arguments can be a mailbox or a domain or a login
|
function usage($msg=null) {
|
||||||
|
if ($msg) {
|
||||||
|
echo "Error:\n$msg";
|
||||||
|
}
|
||||||
|
echo "usage : script -[m|l|d]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#arguments can be a mailbox or a domain or a login
|
||||||
$options = getopt('m:l:d:');
|
$options = getopt('m:l:d:');
|
||||||
|
|
||||||
print_r($options);
|
|
||||||
#parser les arguments correctement.
|
#parser les arguments correctement.
|
||||||
#We check that only onei type of option is specified
|
#We check that only one type of option is specified
|
||||||
$nb=count($options);
|
$nb=count($options);
|
||||||
|
|
||||||
if ( $nb != 1 ){
|
if ( $nb != 1 ){
|
||||||
echo "usage : script -[m|l|d]\n";
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#we check that for that type only one option is specified
|
#we check that for that type only one option is specified
|
||||||
foreach($options as $opt => $val){
|
foreach($options as $opt => $val){
|
||||||
$nb2=count($options[$opt]);
|
$nb2=count($options[$opt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $nb2 != 1 ){
|
if ( $nb2 != 1 ){
|
||||||
echo "usage : script -[m|l|d]\n";
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#function taking a query used to select the mailbox(es) root and updating their quotas into the mailbox table
|
#function taking a query used to select the mailbox(es) root and updating their quotas into the mailbox table
|
||||||
function FixQuotaDovecot($query){
|
function FixQuotaDovecot($conditions){
|
||||||
global $db;
|
global $db;
|
||||||
$db2=new DB_System();
|
$db2=new DB_System();
|
||||||
|
$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 $conditions ;";
|
||||||
|
|
||||||
if(!$db->query($query)){
|
if(!$db->query($query)){
|
||||||
echo "failed";
|
usage("failed"); // FIXME real error
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$dir=$db->f("dir");
|
$dir=$db->f("dir");
|
||||||
$id=$db->f("id");
|
$id=$db->f("id");
|
||||||
$size = exec ( "/usr/bin/du -sb $dir|cut -f1" );
|
$size = exec ( "/usr/bin/du -sb $dir|cut -f1" ); // FIXME check return value
|
||||||
if(!$db2->query("UPDATE mailbox set bytes=$size where id=$id;")){
|
if(!$db2->query("UPDATE mailbox set bytes=".intval($size)." where id=".intval($id).";")){
|
||||||
echo "fail updating quota for mailbox :".$id."\n";
|
echo "Fail updating quota for mailbox : $id\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#We construct a sql query to get the mailbox root based on the option.
|
#We construct a sql query to get the mailbox root based on the option.
|
||||||
switch($opt){
|
switch($opt){
|
||||||
case "m":
|
case "m":
|
||||||
if (!filter_var($val,FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($val,FILTER_VALIDATE_EMAIL)) {
|
||||||
echo " the email you entered is syntaxically incorrect\n";
|
usage("The email you entered is syntaxically incorrect");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
$query="select mailbox.id,concat(path, '/Maildir/') as dir from mailbox
|
$cond = "concat(address.address,'@',domaines.domaine) ='".$val ;
|
||||||
join address on address.id = mailbox.address_id
|
break;
|
||||||
join domaines on domaines.id = address.domain_id
|
case "l":
|
||||||
where concat(address.address,'@',domaines.domaine) ='".$val."';";
|
$login=strtolower($val);
|
||||||
break;
|
if (!preg_match("#^[a-z0-9]+$#",$login)) { //FIXME use an alternc function for that
|
||||||
case "l":
|
usage("the login you entered is syntaxically incorrect");
|
||||||
$login=strtolower($val);
|
exit(1);
|
||||||
if (!preg_match("#^[a-z0-9]+$#",$login)) { //$
|
}
|
||||||
echo " the login you entered is syntaxically incorrect\n";
|
$cond = "membres.login = ".mysql_real_escape_string($login) );
|
||||||
exit(1);
|
break;
|
||||||
}
|
case "d":
|
||||||
$query=("select mailbox.id,concat(path, '/Maildir/') as dir from mailbox
|
if(checkfqdn($val) != 0){
|
||||||
join address on mailbox.address_id = address.id
|
usage("The domain you entered is syntaxically incorrect");
|
||||||
join domaines on address.domain_id = domaines.id
|
exit(1);
|
||||||
join membres on domaines.compte = membres.uid where membres.login = '".$login."';");
|
}
|
||||||
break;
|
$cond = "domaines.domaine = ".mysql_real_escape_string($val) ;
|
||||||
case "d":
|
break;
|
||||||
if(checkfqdn($val) != 0){
|
default:
|
||||||
echo " the domain you entered is syntaxically incorrect\n";
|
usage();
|
||||||
exit(1);
|
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);
|
FixQuotaDovecot($cond);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue