From 740948e5aadf5db9b7476287c00f504e4d80a363 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 4 Nov 2005 10:22:13 +0000 Subject: [PATCH] Added mailQueue listing git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1829 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/addons/mailqueue/class_mailqueue.inc | 115 ++++++++++-- .../addons/mailqueue/class_parseMailQueue.inc | 174 ++++++++++++++++++ plugins/addons/mailqueue/contents.tpl | 63 ++++++- plugins/addons/mailqueue/main.inc | 1 + plugins/admin/systems/class_servService.inc | 4 +- plugins/admin/systems/servservice.tpl | 8 + 6 files changed, 352 insertions(+), 13 deletions(-) create mode 100644 plugins/addons/mailqueue/class_parseMailQueue.inc diff --git a/plugins/addons/mailqueue/class_mailqueue.inc b/plugins/addons/mailqueue/class_mailqueue.inc index a07c53304..f14094f31 100644 --- a/plugins/addons/mailqueue/class_mailqueue.inc +++ b/plugins/addons/mailqueue/class_mailqueue.inc @@ -13,25 +13,118 @@ class mailqueue extends plugin var $QueryCommand = ""; var $RemoveCommand= ""; + var $Server = "none"; + var $Time = 0; + var $Search = "*"; + var $Page = 0; + var $EntriesPerPage = 20; + + var $OrderBy = "Arrival"; + var $SortType = "up"; + function mailqueue($config, $dn= NULL) { - /* Include config object */ - $this->config= $config; + /* Include config object */ + $this->config= $config; + + $this->QueryCommand = search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_QUERY_COMMAND"); + $this->RemoveCommand= search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_REMOVE_COMMAND"); - $this->QueryCommand = search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_QUERY_COMMAND"); - $this->RemoveCommand= search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_REMOVE_COMMAND"); + $this->Server = "none"; } function execute() { - /* Call parent execute */ - plugin::execute(); - $smarty= get_smarty(); - print search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_QUERY_COMMAND"); - print search_config($this->config->data['MENU'], "mailqueue", "MAILQUEUE_REMOVE_COMMAND"); - return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); + /* Call parent execute */ + plugin::execute(); + $smarty= get_smarty(); + + if($str = @shell_exec ($this->QueryCommand)){ + $mailQueueParser = new parseMailQueue($str); + $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_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); + 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))); } -} + function getServer() + { + $ret= array("none",_("none")); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(objectClass=goMailServer)",array("cn")); + while($tmp = $ldap->fetch()){ + $ret[$tmp['cn'][0]]= $tmp['cn'][0]; + } + return($ret); + } + function getTimes() + { + $ret = array("all"=>_("all")); + for($i = 0 ; $i < 10 ; $i ++ ){ + if($i == 1){ + $ret[$i] = $i." "._("day ago"); + }else{ + $ret[$i] = $i." "._("days ago"); + } + } + return($ret); + } + + function save_object($save_current= FALSE) + { + if(isset($_POST['p_server'])){ + $this->Server = $_POST['p_server']; + } + if(isset($_POST['p_time'])){ + $this->Time = $_POST['p_time']; + } + if(isset($_POST['search_for'])){ + $this->Search = $_POST['search_for']; + } + if((isset($_GET['start']))&&(is_numeric($_GET['start']))&&($_GET['start']>=0)){ + $this->Page = $_GET['start']; + } + + if((isset($_GET['sort']))&&(!empty($_GET['sort']))){ + $old = $this->OrderBy; + $this->OrderBy = $_GET['sort']; + if($this->OrderBy == $old) + { + if($this->SortType== "up"){ + $this->SortType = "down"; + }else{ + $this->SortType = "up"; + } + } + } + + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/addons/mailqueue/class_parseMailQueue.inc b/plugins/addons/mailqueue/class_parseMailQueue.inc new file mode 100644 index 000000000..49c78752a --- /dev/null +++ b/plugins/addons/mailqueue/class_parseMailQueue.inc @@ -0,0 +1,174 @@ +s_dataToParse = $s_data; + $this->_parse(); + } + + function OnlyDaysAgo($str) + { + $cur = time(); + if(is_numeric($str)){ + $cur = $cur - ($str*(60*60*24)); + foreach($this->a_parsedData as $key => $data){ + if($data['Arrival'] < $cur){ + unset($this->a_parsedData[$key]); + } + } + } + } + + function Search($filter,$fields) + { + foreach($this->a_parsedData as $key => $data){ + $found = false; + + foreach($fields as $attr){ + if(preg_match("/".str_replace("*",".*",$filter)."/i",$data[$attr])){ + $found= true; + } + } + if($found == false){ + unset($this->a_parsedData[$key]); + } + } + } + + function CreateDate() + { + foreach($this->a_parsedData as $key => $data){ + $this->a_parsedData[$key]['Arrival'] = date("d.m.Y H:i:s",$data['Arrival']); + } + } + + function OrderBy($str = "Arrival",$type = "up" ) + { + $tmp = array(); + if(!in_array($str,array("MailID","Size","Sender","Recipient","Arrival","Error"))){ + return(false); + } + + if($str == "Size"){ + foreach($this->a_parsedData as $data){ + $struse = ""; + for($i = strlen($data['Size']); $i < 10 ; $i++ ){ + $struse .="0"; + } + $struse .= $data[$str].$data['MailID']; + $tmp[$struse]= $data; + } + }else{ + foreach($this->a_parsedData as $data){ + $tmp[strtolower($data[$str]).$data['MailID']]= $data; + } + } + ksort($tmp); + if($type != "up"){ + $tmp = array_reverse($tmp); + } + $this->a_parsedData = array(); + foreach($tmp as $data){ + $this->a_parsedData[$data['MailID']] = $data; + } + } + + function GetAll() + { + return($this->a_parsedData); + } + + function IDExists($id) + { + return(((isset($this->a_parsedData[$id]))&&(is_array($this->a_parsedData[$id])))); + } + + /* This function parses the given data + * it creates an array with all given queue entries + */ + function _parse() + { + $i = 0; // Temp var + $entries = array(); // Contains an array with the raw data for every single entry + $s_tmp = ""; // Buffer + + $s_mailID = ""; // Queue ID + $s_Size = ""; // Mail size + $s_Arrival = ""; // Arrival time + $s_Sender = ""; // Sender + $s_Recipient = ""; // Recipient + $s_Error = ""; // Occured error + + /* Remove header + */ + $this->s_dataToParse = preg_replace("/^.*------\n/","",$this->s_dataToParse); + + /* Create array with single entries + */ + $entries = split("\n\n",$this->s_dataToParse); + + /* The last entry in this array is not realy an valid entry, its some kind of status. + * It would be something like this : -- 795 Kbytes in 124 Requests. + */ + $this->i_count = (count($entries))-1; + + for($i = 0 ; $i < $this->i_count; $i ++ ){ + + while(strstr($entries[$i]," ")){ + $entries[$i] = str_replace(" "," ",$entries[$i]); + } + + $s_buffer = split("\n",preg_replace("/[\\n\\r\\t]/s","\n",$entries[$i])); + + /* Get mailID */ + $tmp = split(" ",$s_buffer[0]); + + /* Get values */ + $s_mailID = $tmp[0]; + $s_Size = $tmp[1]; + $s_Sender = $tmp[6]; + + /* Parse time */ + $tmp3 = split(":",$tmp[5]); + $tmp2 = strtotime($tmp[4]." ".$tmp[3]." ".date("Y")); + $s_Arrival= mktime($tmp3[0],$tmp3[1],$tmp3[2],date("d",$tmp2),date("m",$tmp2),date("Y",$tmp2)); + + $s_Error = $s_buffer[1]; + $s_Recipient = $s_buffer[2]; + + $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); + } + return($this->a_parsedData); + } + + function _parseError($str) + { + $str = trim(preg_replace("/[()]/","",$str)); + $tmp2 = split(":",$str); + $tmp = array_reverse($tmp2); + $err = preg_replace("/#.*$/","",$tmp[0]); + $text = preg_replace("/said$/i","",trim($tmp2[0])); + return($err); + } + +} + + + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/addons/mailqueue/contents.tpl b/plugins/addons/mailqueue/contents.tpl index 527f9116b..438b861fa 100644 --- a/plugins/addons/mailqueue/contents.tpl +++ b/plugins/addons/mailqueue/contents.tpl @@ -1 +1,62 @@ -Class MailQueue +
 
+
+

[F]Filter

+
+
+

+ +  {t}Search for{/t} + +  in + +  {t}Select time periode{/t} + +   + +

+
+
+ + + + + + + + + + +{counter start=0 assign=i start=1} +{foreach from=$entries item=val key=key} + + {if ($i%2)== 0 } + + {else} + + {/if} + + + + + + + + {counter} +{/foreach} +
{t}ID{/t} {if $OrderBy == "MailID"} {$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}{t}Recipient{/t} {if $OrderBy == "Recipient"}{$SortType}{/if}{t}Error{/t} {if $OrderBy == "Error"} {$SortType}{/if}
{$entries[$key].MailID}{$entries[$key].Size}{$entries[$key].Arrival}{$entries[$key].Sender}{$entries[$key].Recipient}{$entries[$key].Error}
+ + + + + +
{$range_selector}
+

+   +

+ + diff --git a/plugins/addons/mailqueue/main.inc b/plugins/addons/mailqueue/main.inc index 1069618a6..1c0b3fcdc 100644 --- a/plugins/addons/mailqueue/main.inc +++ b/plugins/addons/mailqueue/main.inc @@ -29,6 +29,7 @@ if (!$remove_lock){ $mailqueue= $_SESSION['mailqueue']; /* Execute formular */ + $mailqueue->save_object(); $display.= $mailqueue->execute (); $display.= "\n"; diff --git a/plugins/admin/systems/class_servService.inc b/plugins/admin/systems/class_servService.inc index 66e2b5871..627cb5a95 100644 --- a/plugins/admin/systems/class_servService.inc +++ b/plugins/admin/systems/class_servService.inc @@ -18,19 +18,21 @@ class servservice extends plugin var $goTerminalServer = ""; var $goSyslogServer = ""; var $goCupsServer = ""; + var $goMailServer = ""; var $o_subWindow = NULL; /* attribute list for save action */ var $ignore_account= TRUE; var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath"); var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer", - "goTerminalServer", "goSyslogServer", "goCupsServer"); + "goTerminalServer", "goSyslogServer", "goCupsServer","goMailServer"); var $objectclasses = array( "top","goServer"); var $additionaloc = array( "goShareServer" => array("goExportEntry"), "goNtpServer" => array("goTimeSource"), "goLdapServer" => array("goLdapBase"), "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"), "goSyslogServer" => array(), + "goMailServer" => array(), "goCupsServer" => array()); function servservice ($config, $dn= NULL) diff --git a/plugins/admin/systems/servservice.tpl b/plugins/admin/systems/servservice.tpl index f0b1c5a21..8bde62432 100644 --- a/plugins/admin/systems/servservice.tpl +++ b/plugins/admin/systems/servservice.tpl @@ -99,6 +99,14 @@ {t}Print Service{/t} + +

 

+
+ + + + + {t}Mail server{/t} -- 2.30.2