From: hickert Date: Tue, 8 Nov 2005 06:56:32 +0000 (+0000) Subject: mailQueue is now able to handle more than one server X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fd410aa13c9111e587f2a00ed363504f965a10c2;p=gosa.git mailQueue is now able to handle more than one server git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1858 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/addons/mailqueue/class_mailqueue.inc b/plugins/addons/mailqueue/class_mailqueue.inc index 1828e3ad7..086bfc158 100644 --- a/plugins/addons/mailqueue/class_mailqueue.inc +++ b/plugins/addons/mailqueue/class_mailqueue.inc @@ -39,33 +39,100 @@ class mailqueue extends plugin /* Call parent execute */ plugin::execute(); $smarty= get_smarty(); - - $q_cmd = preg_replace("/%server/",$this->Server,$this->QueryCommand); - - /* Only display this if the query cmd is executeable */ - if($str = @shell_exec ($q_cmd)){ - - /* Parse returned data */ - $mailQueueParser = new parseMailQueue($str); - - /* Delete entry if requested */ - if(isset($_GET['del'])){ - if($mailQueueParser->IDExists($_GET['del'])){ - $r_cmd = preg_replace("/%server/", $this->Server,$this->RemoveCommand); - $r_cmd = preg_replace("/%id/", $_GET['del'] ,$r_cmd); - print $r_cmd; + + $error =false; + + if(empty($this->QueryCommand)){ + print_red(_("Please check your 'gosa.conf', there is no 'MAILQUEUE_QUERY_COMMAND' specified.")); + $error = true; + }else{ + + /* tell smarty to display the search results*/ + $smarty->assign("all_ok" , "true"); + + /* A single server is selected */ + if($this->Server != "all"){ + + /* Create Query cmd */ + $q_cmd = preg_replace("/%server/",$this->Server,$this->QueryCommand); + + /* Only display this if the query cmd is executeable */ + if($str = @shell_exec ($q_cmd)){ + + /* Parse returned data */ + $mailQueueParser = new parseMailQueue($str,$this->Server); + + }else{ + + /* Can't Execute cmd */ + print_red(sprintf(_("Please check your 'gosa.conf' the given '%s' can't be executed."),$q_cmd)); + $error = true; } - } - /* Filter data with the given */ - $mailQueueParser->OrderBy($this->OrderBy,$this->SortType); - $mailQueueParser->OnlyDaysAgo($this->Time); - $mailQueueParser->CreateDate(); - $mailQueueParser->Search($this->Search,array("MailID","Size","Sender","Recipient","Error","Arrival")); + }else{ + + $mailQueueParser = NULL; + foreach($this->getServer() as $ServerID=>$ServerName){ + if($ServerID == "all") continue; + + $q_cmd = preg_replace("/%server/",$ServerName,$this->QueryCommand); + + if($str = @shell_exec ($q_cmd)){ + if($mailQueueParser == NULL){ + $mailQueueParser = new parseMailQueue($str,$ServerID); + }else{ + $mailQueueParser->parseAdditionalQueue($str,$ServerID); + } + }else{ + print_red(sprintf(_("Please check your 'gosa.conf' the given '%s' can't be executed."),$q_cmd)); + $error = true; + } + } + + } + + if(!$error){ + + /* Delete entry if requested */ + if(isset($_GET['del'])){ + if($mailQueueParser->IDExists($_GET['del'])){ + $r_cmd = preg_replace("/%server/", $this->Server,$this->RemoveCommand); + $r_cmd = preg_replace("/%id/", $_GET['del'] ,$r_cmd); + print $r_cmd; + } + } + + /* Filter data with the given */ + $mailQueueParser->OrderBy($this->OrderBy,$this->SortType); + $mailQueueParser->OnlyDaysAgo($this->Time); + $mailQueueParser->CreateDate(); + $mailQueueParser->Search($this->Search,array("MailID","Size","Sender","Recipient","Error","Arrival")); + + /* */ + $entries = $mailQueueParser->GetAll(); + $smarty->assign("entries" , array_slice($entries,$this->Page,20)); + $smarty->assign("plug" , "?plug=".$_GET['plug']); + $smarty->assign("p_server" , $this->Server); + $smarty->assign("p_servers" , $this->getServer()); + $smarty->assign("p_serverKeys" , array_flip($this->getServer())); + $smarty->assign("p_time" , $this->Time); + $smarty->assign("p_times" , $this->getTimes()); + $smarty->assign("p_timeKeys" , array_flip($this->getTimes())); + $smarty->assign("search_for" , $this->Search); + $smarty->assign("range_selector", range_selector(count($entries), $this->Page, 20)); + $smarty->assign("OrderBy" , $this->OrderBy); + + /* Display sort arrow */ + if($this->SortType == "up"){ + $smarty->assign("SortType",""._("up").""); + }else{ + $smarty->assign("SortType",""._("down").""); + } + } + } - /* */ - $entries = $mailQueueParser->GetAll(); - $smarty->assign("entries" , array_slice($entries,$this->Page,20)); + if($error){ + $smarty->assign("all_ok" , "false"); $smarty->assign("plug" , "?plug=".$_GET['plug']); $smarty->assign("p_server" , $this->Server); $smarty->assign("p_servers" , $this->getServer()); @@ -74,19 +141,7 @@ class mailqueue extends plugin $smarty->assign("p_times" , $this->getTimes()); $smarty->assign("p_timeKeys" , array_flip($this->getTimes())); $smarty->assign("search_for" , $this->Search); - $smarty->assign("range_selector", range_selector(count($entries), $this->Page, 20)); $smarty->assign("OrderBy" , $this->OrderBy); - - /* Display sort arrow */ - if($this->SortType == "up"){ - $smarty->assign("SortType",""._("up").""); - }else{ - $smarty->assign("SortType",""._("down").""); - } - - }else{ - $smarty->assign("entries",array()); - print_red(_("Please check your 'gosa.conf' the value for 'MAILQUEUE_QUERY_COMMAND' can't be executed.")); } return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); } diff --git a/plugins/addons/mailqueue/class_parseMailQueue.inc b/plugins/addons/mailqueue/class_parseMailQueue.inc index eabba97a7..c7f687e8d 100644 --- a/plugins/addons/mailqueue/class_parseMailQueue.inc +++ b/plugins/addons/mailqueue/class_parseMailQueue.inc @@ -9,10 +9,11 @@ class parseMailQueue /* Contructor * $s_data specifies the data that shuold be parse */ - function parseMailQueue($s_data) + function parseMailQueue($s_data,$server) { $this->s_dataToParse = $s_data; - $this->_parse(); + $this->a_parsedData = array(); + $this->_parse($s_data,$server); } @@ -75,9 +76,8 @@ class parseMailQueue function OrderBy($str = "Arrival",$type = "up" ) { $tmp = array(); - /* If the given field is not valid */ - if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error"))){ + if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error","Server"))){ return(false); } @@ -89,12 +89,12 @@ class parseMailQueue for($i = strlen($data['Size']); $i < 10 ; $i++ ){ $struse .="0"; } - $struse .= $data[$str].$data['MailID']; + $struse .= $data[$str].$data['MailID'].$data['Server']; $tmp[$struse]= $data; } }else{ foreach($this->a_parsedData as $data){ - $tmp[strtolower($data[$str]).$data['MailID']]= $data; + $tmp[strtolower($data[$str]).$data['MailID']."-".$data['Server']]= $data; } } ksort($tmp); @@ -103,8 +103,9 @@ class parseMailQueue } $this->a_parsedData = array(); foreach($tmp as $data){ - $this->a_parsedData[$data['MailID']] = $data; + $this->a_parsedData[$data['MailID']."-".$data['Server']] = $data; } + return(true); } function GetAll() @@ -118,10 +119,15 @@ class parseMailQueue return(((isset($this->a_parsedData[$id]))&&(is_array($this->a_parsedData[$id])))); } + function parseAdditionalQueue($str, $server) + { + $this->_parse($str, $server); + } + /* This function parses the given data * it creates an array with all given queue entries */ - function _parse() + function _parse($str, $server) { $i = 0; // Temp var $entries = array(); // Contains an array with the raw data for every single entry @@ -136,7 +142,7 @@ class parseMailQueue /* Remove header */ - $this->s_dataToParse = preg_replace("/^.*------\n/","",$this->s_dataToParse); + $this->s_dataToParse = preg_replace("/^.*------\n/","",$str); /* Create array with single entries */ @@ -172,12 +178,13 @@ class parseMailQueue $s_Recipient = $s_buffer[2]; /* Append data */ - $this->a_parsedData[$s_mailID]['MailID'] = $s_mailID; - $this->a_parsedData[$s_mailID]['Size'] = $s_Size; - $this->a_parsedData[$s_mailID]['Arrival'] = $s_Arrival; - $this->a_parsedData[$s_mailID]['Sender'] = $s_Sender; - $this->a_parsedData[$s_mailID]['Recipient'] = $s_Recipient; - $this->a_parsedData[$s_mailID]['Error'] = $this->_parseError($s_Error); + $this->a_parsedData[$s_mailID."-".$server]['Server'] = $server; + $this->a_parsedData[$s_mailID."-".$server]['MailID'] = $s_mailID; + $this->a_parsedData[$s_mailID."-".$server]['Size'] = $s_Size; + $this->a_parsedData[$s_mailID."-".$server]['Arrival'] = $s_Arrival; + $this->a_parsedData[$s_mailID."-".$server]['Sender'] = $s_Sender; + $this->a_parsedData[$s_mailID."-".$server]['Recipient'] = $s_Recipient; + $this->a_parsedData[$s_mailID."-".$server]['Error'] = $this->_parseError($s_Error); } return($this->a_parsedData); } diff --git a/plugins/addons/mailqueue/contents.tpl b/plugins/addons/mailqueue/contents.tpl index 29fb6401d..947270e4c 100644 --- a/plugins/addons/mailqueue/contents.tpl +++ b/plugins/addons/mailqueue/contents.tpl @@ -20,10 +20,16 @@


+ +{if $all_ok != "true"} +{t}Search returned no results{/t}... +{else} + + @@ -41,12 +47,13 @@ {/if} + - + {counter} {/foreach} @@ -61,4 +68,5 @@  

+{/if}
{t}ID{/t} {if $OrderBy == "MailID"} {$SortType}{/if}{t}Server{/t} {if $OrderBy == "Server"} {$SortType}{/if} {t}Size{/t} {if $OrderBy == "Size"} {$SortType}{/if} {t}Arrival{/t} {if $OrderBy == "Arrival"} {$SortType}{/if} {t}Sender{/t} {if $OrderBy == "Sender"} {$SortType}{/if}
{$entries[$key].MailID}{$entries[$key].Server} {$entries[$key].Size} {$entries[$key].Arrival} {$entries[$key].Sender} {$entries[$key].Recipient} {$entries[$key].Error}deleteddeleted