summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 670cb12)
raw | patch | inline | side by side (parent: 670cb12)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 4 Sep 2008 08:05:33 +0000 (08:05 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 4 Sep 2008 08:05:33 +0000 (08:05 +0000) |
-Removed old parser class.
-Updated mailqueue to use si functions.
-Added new mail queue si function library
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12359 594d385d-05f5-0310-b6e9-bd551577e9d8
-Updated mailqueue to use si functions.
-Added new mail queue si function library
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12359 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/mail/addons/mailqueue/class_mailqueue.inc | patch | blob | history | |
gosa-plugins/mail/addons/mailqueue/class_parseMailQueue.inc | [deleted file] | patch | blob | history |
gosa-plugins/mail/addons/mailqueue/class_si_mailqueue.inc | [new file with mode: 0644] | patch | blob |
gosa-plugins/mail/addons/mailqueue/contents.tpl | patch | blob | history |
diff --git a/gosa-plugins/mail/addons/mailqueue/class_mailqueue.inc b/gosa-plugins/mail/addons/mailqueue/class_mailqueue.inc
index 7865d50a14034a06c4220196e3f252f29b66e9d1..4d6a8df3f11acc0cef20929413dac2df295f2f32 100644 (file)
class mailqueue extends plugin
{
/* Definitions */
- var $plHeadline= "Mail queue";
- var $plDescription= "This does something";
- var $plIcon = "plugins/mail/images/mailqueue.png";
+ var $plHeadline = "Mail queue";
+ var $plDescription = "This does something";
+ var $plIcon = "plugins/mail/images/mailqueue.png";
/* attribute list for save action */
var $attributes = array();
var $objectclasses = array();
- var $mailQueueScript= "";
+
var $Server = "all";
- var $Time = 0;
+ var $ServerList = array(); // The list of all available servers.
var $Search = "*";
+ var $Time = 0;
var $Page = 0;
var $Stat = "all";
var $OrderBy = "Arrival";
var $SortType = "up";
var $disp_header = false;
var $range = 20;
- var $view_logged = FALSE;
-
- function mailqueue(&$config, $dn= NULL)
- {
- $this->config = &$config;
- if (isset($this->config->current['MAILQUEUESCRIPTPATH'])){
- $this->mailQueueScript = $this->config->current['MAILQUEUESCRIPTPATH'];
- }
-
- if(isset($this->config->data['MAIN']['MAILQUEUESCRIPTPATH'])){
- $this->mailQueueScript = $this->config->data['MAIN']['MAILQUEUESCRIPTPATH'];
- }
-
- $this->Server = "all";
- }
+ /* Logging detection */
+ var $view_logged = FALSE;
- function pass_cmd($str)
+ function mailqueue(&$config, $dn= NULL)
{
- return(shell_exec($str));
+ $this->config = &$config;
+ $this->si_queue = new si_mailqueue($this->config);
+ $this->getServer();
}
new log("view","mailqueue/".get_class($this),$this->dn);
}
- if(isset($_POST['EntriesPerPage'])){
- $this->range = $_POST['EntriesPerPage'];
- }
-
$smarty= get_smarty();
$error =false;
- if(empty($this->mailQueueScript)){
- #FIXME This will be provided by the gosa-si server later, then this message becomes obsolete.
- msg_dialog::display(_("Configuration error"),
- sprintf(_("Missing '%s' directive in configuration!"), "mailqueuescriptpath"), ERROR_DIALOG);
- $error = true;
- }else{
-
- /* If we have more than one server selected (all),
- create a string with all servers separated by ', '
- */
- if($this->Server=="all"){
- $se = $this->getServer();
-
- unset($se['all']);
- $se_str = "";
- foreach($se as $server) {
- $se_str .= $server." ";
+ /******************
+ Handle options
+ ******************/
+
+ $action = $server = $entry = "";
+ $types = array("delete","hold","unhold","header","requeue");
+ foreach($_POST as $name => $value){
+ foreach($types as $type){
+ if(preg_match("/^".$type."__/",$name)){
+ $action = $type;
+ $entry = preg_replace("/^".$type."__([^_]*)__.*/","\\1",$name);
+ $server = preg_replace("/^".$type."__[^_]*__([^_]*)_.*/","\\1",$name);
+ break;
}
- }else{
- /* We have only one server selected */
- $se_str = $this->Server;
}
+ }
- /* Check all post that will effect all entries */
- $only_once = true;
- foreach(array("unhold_all","hold_all","del_all","requeue_all") as $attr){
- foreach($_POST as $name => $value){
- if((preg_match("/".$attr."/",$name))&&($only_once)){
- if(!$this->acl_is_readable($attr)){
- $only_once = false;
- msg_dialog::display(_("Permission error"),
- sprintf(_("You have no permission to submit a '%s' command!"), $attr), ERROR_DIALOG);
- }else{
- $only_once = false;
- $act = preg_replace("/_.*$/i","",$attr);
- $r_cmd = preg_replace("/%action/" , $act ,$this->mailQueueScript);
- $r_cmd = preg_replace("/%server/" , $se_str ,$r_cmd);
- $r_cmd = preg_replace("/%id/" , "ALL" ,$r_cmd);
- if($this->pass_cmd($r_cmd)==false){
- msg_dialog::display(_("Configuration error"),
- msgPool::cmdnotfound("mailqueuescriptpath",_("Mail queue addon")), ERROR_DIALOG);
- }
- }
- }
- }
- }
-
- /* Check single entry manipulation posts */
- $only_once = true;
-
- /* act specifies the command to execute */
- if(isset($_GET['act'])){
- $opt = $_GET['act'];
-
- /* The option to exec should be one of these */
- if(in_array($opt,array("unhold","hold","del","requeue","query","header"))){
- $only_once = false;
-
- if(!$this->acl_is_readable($opt)){
- msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to submit a '%s' command!"), $opt), ERROR_DIALOG);
- }else{
- /* Create cmd */
- $r_cmd = preg_replace("/%action/" , $opt ,$this->mailQueueScript);
- $r_cmd = preg_replace("/%server/" , $this->Server ,$r_cmd);
- $r_cmd = preg_replace("/%id/" , $_GET['id'] ,$r_cmd);
-
- /* Execute cmd */
- if(!$str = $this->pass_cmd($r_cmd)){
- #FIXME This will be provided by the gosa-si server later, then this message becomes obsolete.
- msg_dialog::display(_("Configuration error"),
- sprintf(_("'%s' defined for the '%s' directive cannot be executed!"), $r_cmd, "mailqueuescriptpath"), ERROR_DIALOG);
- }else{
-
- /* Special handling for option='header' */
- if($opt == "header"){
-
- /* Create table which displays the header informations */
- $this->disp_header ="\n<table width='80%'>";
- foreach(split("\n",$str) as $line){
- $line = trim($line);
- if(empty($line)) {
- continue;
- }
- $this->disp_header .= "\n<tr>";
- $tmp0 = preg_replace("/:.*$/","",$line);
- $tmp1 = preg_replace("/^.*:/","",$line);
- $this->disp_header .= "\n<td style='background-color:#EEEEEE;'>".$tmp0."</td><td>".$tmp1."</td>";
- $this->disp_header .= "\n</tr>";
- }
- $this->disp_header .= "\n</table>";
- }
- }
- }
- }
- }
+ /* Send action for given mail id */
+ if(in_array($action,array("hold","unhold","requeue"))){
+ $this->si_queue->send_queue_action(array($entry),$server,$action);
+ }
- /* Back is posted from the header display page */
- if(isset($_POST['back'])){
- $this->disp_header = false;
- }
+ /******************
+ Display mail header
+ ******************/
- /* If there is a header in disp_header, then display it */
- if($this->disp_header){
- $smarty->assign("header",$this->disp_header);
- return ($smarty->fetch (get_template_path('header.tpl', TRUE)));
- }
+ if($action == "header"){
- /* 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("/%action/" ,"query" ,$this->mailQueueScript);
- $q_cmd = preg_replace("/%server/" ,$this->Server,$q_cmd);
- $q_cmd = preg_replace("/%id/" ,"all" ,$q_cmd);
-
- if(!$this->acl_is_readable("query")){
- msg_dialog::display(_("Permission error"),
- sprintf(_("You have no permission to submit a '%s' command!"), "query"), ERROR_DIALOG);
- $mailQueueParser = new parseMailQueue("",$this->Server);
- }else{
+ /* Create table which displays the header informations */
+ $this->disp_header = $this->si_queue->header($entry);
+ }
- /* Only display this if the query cmd is executeable */
- if($str = @$this->pass_cmd ($q_cmd)){
- /* Parse returned data */
- $mailQueueParser = new parseMailQueue($str,$this->Server);
- }else{
- /* On error/ no return value / false return value */
- msg_dialog::display(_("Configuration error"),
- sprintf(_("'%s' defined for the '%s' directive cannot be executed!"), $q_cmd, "mailqueuescriptpath"), ERROR_DIALOG);
- $error = true;
- }
- }
- }else{
- $mailQueueParser = NULL;
- foreach($this->getServer() as $ServerID=>$ServerName){
-
- /* Don't query the server named all :) */
- if($ServerID == "all") continue;
-
- /* Prepare query cmd */
- $q_cmd = preg_replace("/%action/" ,"query" ,$this->mailQueueScript);
- $q_cmd = preg_replace("/%server/" ,$ServerName ,$q_cmd);
- $q_cmd = preg_replace("/%id/" ,"ALL" ,$q_cmd);
-
-
- if(!$this->acl_is_readable("query")){
- msg_dialog::display(_("Permission error"),
- sprintf(_("You have no permission to submit a '%s' command!"), "query"), ERROR_DIALOG);
- $mailQueueParser = new parseMailQueue("",$this->Server);
- }else{
-
- /* Shell exec this cmd */
- if($str = @$this->pass_cmd ($q_cmd)){
-
- /* If there is no parser available, create one */
- if($mailQueueParser === NULL){
- $mailQueueParser = new parseMailQueue($str,$ServerID);
- }else{
- $mailQueueParser->parseAdditionalQueue($str,$ServerID);
- }
- /* On error/ no return value / false return value */
- }else{
- msg_dialog::display(_("Configuration error"),
- sprintf(_("'%s' defined for the '%s' directive cannot be executed!"), $q_cmd, "mailqueuescriptpath"), ERROR_DIALOG);
- $error = true;
- }
- }
- }
- }
-
- /* Check for existing servers
- objectClass=goMailServer is required at least for one server.
- Else display error */
- $server = $this->getServer();
- if((count($server) == 1 ) && (isset($server['all']))){
- msg_dialog::display(_("Configuration error"), _("No mail servers specified!"), ERROR_DIALOG);
- $error = true;
- }
+ /* Back is posted from the header display page */
+ if(isset($_POST['back'])){
+ $this->disp_header = false;
+ }
- if(!$error){
+ /* If there is a header in disp_header, then display it */
+ if($this->disp_header){
+ $smarty->assign("header",$this->disp_header);
+ return ($smarty->fetch (get_template_path('header.tpl', TRUE)));
+ }
- /* Filter data with the given */
- $mailQueueParser->OrderBy($this->OrderBy,$this->SortType);
- $mailQueueParser->OnlyDaysAgo($this->Time);
- $mailQueueParser->CreateDate();
-
- if($this->Stat == "hold"){
- $mailQueueParser->Search(true,array("Hold"),true);
- }
- if($this->Stat == "unhold"){
- $mailQueueParser->Search(false,array("Hold"),true);
- }
- if($this->Stat == "active"){
- $mailQueueParser->Search(true,array("Active"),true);
- }
- if($this->Stat == "nonactive"){
- $mailQueueParser->Search(false,array("Active"),true);
- }
- $mailQueueParser->Search($this->Search,array("MailID","Size","Sender","Recipient","Error","Arrival"));
+ /******************
+ Query mailqueues
+ ******************/
- /* */
- $entries = $mailQueueParser->GetAll();
-
- if(count($entries) ==0 ){
- $smarty->assign("all_ok",false);
- }
-
- $smarty->assign("entries" , array_slice($entries,$this->Page,$this->range));
- $smarty->assign("plug" , "?plug=".$_GET['plug']);
- $smarty->assign("r_stats" , $this->getStats());
- $smarty->assign("stats" , array_flip($this->getStats()));
- $smarty->assign("stat" , $this->Stat);
- $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, $this->range,"EntriesPerPage"));
- $smarty->assign("OrderBy" , $this->OrderBy);
-
- /* Display sort arrow */
- if($this->SortType == "up"){
- $smarty->assign("SortType","<img src='images/lists/sort-up.png' alt='"._("up")."' border='0'>");
- }else{
- $smarty->assign("SortType","<img src='images/lists/sort-down.png' alt='"._("down")."' border='0'>");
+ if($this->Server == "all"){
+ $entries = array();
+ foreach($this->ServerList as $mac => $name){
+ if(!tests::is_mac($mac)) continue;
+ $entries = array_merge($entries,$this->si_queue->query_mailqueue($mac,$this->OrderBy,$this->SortType,$this->range));
+ if($this->si_queue->is_error()){
+ unset($this->ServerList[$mac]);
+ msg_dialog::display(_("Error"),sprintf(_("The server '%s' from server list, due to daemon communication problems, the error was: %s"),$name,"<b>".msgPool::siError($this->si_queue->get_error()."</b>")),ERROR_DIALOG);
}
}
+ }else{
+ $entries = $this->si_queue->query_mailqueue($this->Server,$this->OrderBy,$this->SortType,$this->Limit);
+ if($this->si_queue->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si_queue->get_error()),ERROR_DIALOG);
+ }
}
- /* In case of an error */
- if($error){
- $smarty->assign("all_ok" , "false");
- $smarty->assign("r_stats" , $this->getStats());
- $smarty->assign("stats" , array_flip($this->getStats()));
- $smarty->assign("stat" , $this->Stat);
- $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("OrderBy" , $this->OrderBy);
+
+ /******************
+ create html output
+ ******************/
+
+ $smarty->assign("all_ok" , count($entries));
+ $smarty->assign("entries" , $entries);
+ $smarty->assign("plug" , "?plug=".$_GET['plug']);
+
+ $smarty->assign("r_stats" , $this->getStats());
+ $smarty->assign("stats" , array_flip($this->getStats()));
+
+ $smarty->assign("stat" , $this->Stat);
+ $smarty->assign("p_server" , $this->Server);
+ $smarty->assign("p_servers" , $this->ServerList);
+ $smarty->assign("p_serverKeys" , array_flip($this->ServerList));
+ $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, $this->range,"EntriesPerPage"));
+ $smarty->assign("OrderBy" , $this->OrderBy);
+
+ /* Display sort arrow */
+ if($this->SortType == "up"){
+ $smarty->assign("SortType","<img src='images/lists/sort-up.png' alt='"._("up")."' border='0'>");
+ }else{
+ $smarty->assign("SortType","<img src='images/lists/sort-down.png' alt='"._("down")."' border='0'>");
}
return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
}
- /* return selectable server */
+ /* return selectable server
+ */
function getServer()
{
$ret= array("all"=>_("All"));
- $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];
+
+ /* First of all, detect all servers that supports the mailqueue extension
+ -If this fails, the mailqueue(s) can't be queried.
+ */
+ $hosts = $this->si_queue->get_hosts_with_module("mailqueue_com");
+ $this->si_error = $this->si_queue->is_error();
+ if(!count($hosts)){
+ return(array());
+ }
+
+ /* Create search filter and try to resolv mac to hostname
+ */
+ $filter = "";
+ foreach($hosts as $mac){
+ $filter .= "(macAddress=".$mac.")";
}
- return($ret);
+ $filter = "(&(objectClass=GOhard)(|".$filter."))";
+ $res = get_list($filter,"no_acls",$this->config->current['BASE'],
+ array("cn","macAddress"),GL_SUBSEARCH | GL_NO_ACL_CHECK);
+
+ /* Create result array
+ */
+ foreach($hosts as $mac){
+ $found = FALSE;
+ foreach($res as $entry){
+ if(preg_match("/^".normalizePreg($mac)."$/i",$entry['macAddress'][0])){
+ $ret[$mac] = $entry['cn'][0];
+ $found = TRUE;
+ break;
+ }
+ }
+ if(!$found){
+ $ret[$mac] = $mac;
+ }
+ }
+ $this->ServerList = $ret;
}
/* Save post values*/
function save_object($save_current= FALSE)
{
- if(isset($_POST['p_server'])){
+ /* Update amount of entries displayed */
+ if(isset($_POST['EntriesPerPage'])){
+ $this->range = $_POST['EntriesPerPage'];
+ }
+
+ if(isset($_POST['p_server']) && isset($this->ServerList[$_POST['p_server']])){
$this->Server = $_POST['p_server'];
}
+
if(isset($_POST['p_time'])){
$this->Time = $_POST['p_time'];
}
diff --git a/gosa-plugins/mail/addons/mailqueue/class_parseMailQueue.inc b/gosa-plugins/mail/addons/mailqueue/class_parseMailQueue.inc
+++ /dev/null
@@ -1,237 +0,0 @@
-<?php
-
-class parseMailQueue
-{
- var $s_dataToParse;
- var $a_parsedData;
- var $i_count;
-
- /* Contructor
- * $s_data specifies the data that shuold be parse
- */
- function parseMailQueue($s_data,$server)
- {
- $this->s_dataToParse = $s_data;
- $this->a_parsedData = array();
- $this->_parse($s_data,$server);
- }
-
-
- /* Remove all entries which are older than the last x hours
- */
- function OnlyDaysAgo($str)
- {
- /* Get current time */
- $cur = time();
-
- /* Only perform this filter, if the given parameter is valid */
- if((is_numeric($str))&&($str != 0)){
-
- /* hours are given as parameter */
- $cur = $cur - ($str*(60*60));
-
- /* Remove old entries */
- foreach($this->a_parsedData as $key => $data){
- if($data['Arrival'] < $cur){
- unset($this->a_parsedData[$key]);
- }
- }
- }
- }
-
-
- /* Only keep entries that contains the $filter
- * in any of the given $fields
- */
- function Search($filter,$fields,$bool = false)
- {
- /* Go through all entries */
- foreach($this->a_parsedData as $key => $data){
-
- /* not found yet */
- $found = false;
-
- foreach($fields as $attr){
- if(($bool)&&($data[$attr]==$filter)){
- $found = true;
- }elseif(preg_match("/".str_replace("*",".*",$filter)."/i",$data[$attr])){
- $found= true;
- }
- }
-
- /* if nothing found, delete this entry */
- if($found == false){
- unset($this->a_parsedData[$key]);
- }
- }
- }
-
- /* Convert date from timestamp to human readable */
- function CreateDate()
- {
- foreach($this->a_parsedData as $key => $data){
- $this->a_parsedData[$key]['Arrival'] = date("d.m.Y H:i:s",$data['Arrival']);
- }
- }
-
- /* Order by specified field */
- 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","Server"))){
- return(false);
- }
-
- /* Size need special handling, cause it contains numbers
- */
- 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'].$data['Server'];
- $tmp[$struse]= $data;
- }
- }else{
- foreach($this->a_parsedData as $data){
- $tmp[strtolower($data[$str]).$data['MailID']."-".$data['Server']]= $data;
- }
- }
- ksort($tmp);
- if($type != "up"){
- $tmp = array_reverse($tmp);
- }
- $this->a_parsedData = array();
- foreach($tmp as $data){
- $this->a_parsedData[$data['MailID']."-".$data['Server']] = $data;
- }
- return(true);
- }
-
- function GetAll()
- {
- return($this->a_parsedData);
- }
-
- /* Checks if the given MailID exists */
- function IDExists($id)
- {
- foreach($this->a_parsedData as $entry){
- if($entry['MailID'] == $id) return(true);
- }
- return(false);
- }
-
- 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($str, $server)
- {
- $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/","",$str);
-
- /* 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];
-
- /*
- * The message is in the active queue, i.e. the message is
- selected for delivery.
-
- ! The message is in the hold queue, i.e. no further deliv-delivery
- ery attempt will be made until the mail is taken off
- hold.
- */
-
- $s_Hold = false;
- if(preg_match("/\!/",$s_mailID)){
- $s_mailID = preg_replace("/\!/","",$s_mailID);
- $s_Hold = "true";
- }
-
- $s_Active = false;
- if(preg_match("/\*/",$s_mailID)){
- $s_mailID = preg_replace("/\*/","",$s_mailID);
- $s_Active = true;
- }
-
- /* Append data */
- $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]['Hold'] = $s_Hold;
- $this->a_parsedData[$s_mailID."-".$server]['Active'] = $s_Active;
- $this->a_parsedData[$s_mailID."-".$server]['Error'] = $this->_parseError($s_Error);
- }
- return($this->a_parsedData);
- }
-
- /* Parse Error part of the entry */
- 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/gosa-plugins/mail/addons/mailqueue/class_si_mailqueue.inc b/gosa-plugins/mail/addons/mailqueue/class_si_mailqueue.inc
--- /dev/null
@@ -0,0 +1,145 @@
+<?php
+
+/*! \brief This is the opsi base class, it handles
+ . gosa daemon requests and prepares data for opsi plugins.
+ */
+class si_mailqueue extends gosaSupportDaemon
+{
+ private $config = NULL;
+ protected $use_alternative_xml_parse_method = TRUE;
+
+ /*! \brief Create opsi object.
+ @param
+ @return
+ */
+ public function __construct($config)
+ {
+ $this->config = $config;
+ gosaSupportDaemon::__construct($config);
+ $this->target = "00:01:6c:9d:b9:fa";
+ }
+
+
+ /*! \brief Returns TRUE or FALSE, whether the plugin is enabled or disabled .
+ @return Boolean s.a.
+ */
+ public function enabled()
+ {
+ return(TRUE);
+ }
+
+
+ /*! \brief Returns a list of all mail queue entries
+ @return Array s.a.
+ */
+ public function query_mailqueue($server,$sortby,$direction, $Limit)
+ {
+ $attrs = array("Size","Recipient","Sender","Arrival","MailID","Hold","Active","Error","Server");
+
+ /* Check sorting paramter
+ */
+ if(!in_array($sortby,$attrs)){
+ trigger_error("Invalid sorting option '".$sortby."'.");
+ $sortby = "Arrival";
+ }
+
+ /* Check sorting direction
+ */
+ if(!in_array($direction,array("down","up"))){
+ trigger_error("Invalid sorting direction '".$direction."'.");
+ $direction = "down";
+ }
+
+ /* Check entry limit
+ */
+ if(!is_numeric($Limit) || $Limit < 1){
+ trigger_error("Invalid entry limt '".$Limit."'.");
+ $Limit = 20;
+ }
+
+ /* Query mailqueue
+ */
+ $res = $this->send_data("gosa_mailqueue_query",$server,array(),TRUE);
+ $items = array();
+ if(isset($res['XML'][0])){
+ foreach($res['XML'][0] as $name => $entry){
+ if(preg_match("/^ANSWER[0-9]*$/",$name)){
+ $attrs = array(
+ "MSG_SIZE" => "Size",
+ "RECIPIENT" => "Recipient",
+ "SENDER" => "Sender",
+ "ARRIVAL_TIME" => "Arrival",
+ "MSG_ID" => "MailID");
+ $val = array();
+ foreach($attrs as $source => $dest){
+ $val[$dest] = $entry[0][$source][0]['VALUE'];
+ }
+ $attrs = array(
+ "MSG_HOLD" => "Hold",
+ "MSG_ACTIVE" => "Active",
+ "ERROR" => "Error");
+ foreach($attrs as $source => $dest){
+ if(isset($entry[0][$source][0]['VALUE'])){
+ $val[$dest] = $entry[0][$source][0]['VALUE'];
+ }else{
+ $val[$dest] = FALSE;
+ }
+ }
+
+ $val['Server'] = $server;
+ $val['Arrival'] = strtotime($val['Arrival']);
+ $items[$val[$sortby]] = $val;
+ }
+ }
+ }
+
+ /* Sort entries by given direction
+ */
+ if($direction == "down"){
+ ksort($items);
+ }else{
+ krsort($items);
+ }
+
+ return($items);
+ }
+
+
+ public function header($msg_id, $server)
+ {
+ $data = array();
+ $data['msg_id'] = $msg_id;
+ $res = $this->send_data("gosa_mailqueue_header",$this->target,$data,TRUE);
+ print_a($res);
+ }
+
+
+ /*! \brief Returns a list of all mail queue entries
+ @return Array s.a.
+ */
+ public function send_queue_action($msg_ids,$server, $action)
+ {
+ $data = array();
+
+ /* Check given msg_ids, must be array.
+ */
+ if(!is_array($msg_ids)){
+ trigger_error("Invalid msg_id given. Array expected.");
+ return(FALSE);
+ }
+
+ /* Check triggered action
+ */
+ $allowed_actions = array("hold","unhold","requeue","del");
+ if(!in_array($action,$allowed_actions)){
+ trigger_error("Unknown queue action triggered '".$action."'. Request aborted.");
+ return(FALSE);
+ }
+
+ $data['msg_id'] = $msg_ids;
+ $this->send_data("gosa_mailqueue_".$action,$this->target,$data,FALSE);
+ // There is no answer for this requests
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/mail/addons/mailqueue/contents.tpl b/gosa-plugins/mail/addons/mailqueue/contents.tpl
index 4356dacd551d22f90a24bcf033f703ae77fae4db..5afe743cf51997b51a920e66ddf910b7ead8e4a2 100644 (file)
<br>
-{if $all_ok != "true"}
+{if $all_ok != true}
<b>{t}Search returned no results{/t}...</b>
{else}
{$entries[$key].Recipient}</td>
<td >{$entries[$key].Error}</td>
<td style="text-align:right">
- <a href="{$plug}&act=del&id={$entries[$key].MailID}&server={$entries[$key].Server}">
- <img class="center" src="images/lists/trash.png" border=0 alt="{t}delete{/t}" title="{t}Delete this message{/t}">
- </a>
- {if $entries[$key].Hold == true}
- <a href="{$plug}&act=unhold&id={$entries[$key].MailID}&server={$entries[$key].Server}">
- <img class="center" src="plugins/mail/images/mailq_unhold.png" border=0 alt="{t}unhold{/t}" title="{t}Release message{/t}">
- </a>
- {else}
- <a href="{$plug}&act=hold&id={$entries[$key].MailID}&server={$entries[$key].Server}">
- <img class="center" src="plugins/mail/images/mailq_hold.png" border=0 alt="{t}hold{/t}" title="{t}Hold message{/t}">
- </a>
- {/if}
- <a href="{$plug}&act=requeue&id={$entries[$key].MailID}&server={$entries[$key].Server}">
- <img class="center" src="images/lists/reload.png" border=0 alt="{t}requeue{/t}" title="{t}Requeue this message{/t}">
- </a>
- <a href="{$plug}&act=header&id={$entries[$key].MailID}&server={$entries[$key].Server}">
- <img class="center" src="plugins/mail/images/mailq_header.png" border=0 alt="{t}header{/t}" title="{t}Display header from this message{/t}">
- </a>
+ <input type='image' name='delete__{$entries[$key].MailID}__{$entries[$key].Server}' class="center"
+ src="images/lists/trash.png" alt="{t}delete{/t}" title="{t}Delete this message{/t}">
+ {if $entries[$key].Hold == true}
+ <input type='image' name='unhold__{$entries[$key].MailID}__{$entries[$key].Server}' class="center"
+ src="plugins/mail/images/mailq_unhold.png" alt="{t}unhold{/t}" title="{t}Release message{/t}">
+ {else}
+ <input type='image' name='hold__{$entries[$key].MailID}__{$entries[$key].Server}' class="center"
+ src="plugins/mail/images/mailq_hold.png" alt="{t}hold{/t}" title="{t}Hold message{/t}">
+ {/if}
+ <input type='image' name='requeue__{$entries[$key].MailID}__{$entries[$key].Server}' class="center"
+ src="images/lists/reload.png" alt="{t}requeue{/t}" title="{t}Requeue this message{/t}">
+ <input type='image' name='header__{$entries[$key].MailID}__{$entries[$key].Server}' class="center"
+ src="plugins/mail/images/mailq_header.png" alt="{t}header{/t}" title="{t}Display header of this message{/t}">
</td>
</tr>
{counter}