Code

Fixed save_object
[gosa.git] / plugins / admin / systems / class_goMailServer.inc
1 <?php
3 class goMailServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports mailqueue listings and so on.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goMailServer");
12   /* This class can't be assigned twice so it conflicts with itsself */
13   var $conflicts        = array("goMailServer");
15   var $DisplayName      = "";
16   var $dn               = NULL;
17   var $StatusFlag       = "goMailServerStatus";
18   var $attributes       = array("goMailServerStatus","description","postfixHeaderSizeLimit",
19       "postfixMailboxSizeLimit","postfixMessageSizeLimit",
20       "postfixMyDestinations","postfixMyDomain","postfixMyhostname",
21       "postfixMyNetworks","postfixRelayhost","postfixTransportTable",
22       "postfixSenderRestrictions","postfixRecipientRestrictions");
24   var $goMailServerStatus               ;
25   var $postfixHeaderSizeLimit           = 0;
26   var $postfixMailboxSizeLimit          = 0;
27   var $postfixMessageSizeLimit          = 0;
28   var $postfixMyDestinations            = array();
29   var $postfixMyDomain                  = "";
30   var $postfixMyhostname                = "";
31   var $postfixMyNetworks                = array();
32   var $postfixRelayhost                 = "";
33   var $postfixTransportTable            = array();
34   var $postfixSenderRestrictions        = array();
35   var $postfixRecipientRestrictions     = array();
36   var $description                      = "";
37   var $RestrictionFilters               = array();
38   var $TransportProtocols               = array(); 
39   var $Actions                          = array();
42   function goMailServer($config,$dn)
43   {
44     plugin::plugin($config,$dn);
45     $this->DisplayName = _("Mail service (SMTP)");
47     $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
48                             SERVICE_STARTED => SERVICE_STARTED,
49                             SERVICE_RESTARTED=>SERVICE_RESTARTED); 
51     /* Fill  RestrictionFilters   TransportProtocols  from external hooks */
52     $str = $this->config->data['TABS']['SERVERSERVICE'];
53     $this->TransportProtocols =array("smtp"=>"SMTP");
54     $this->RestrictionFilters = array("FILTER"=>"FILTER"); 
55     foreach(array("ADDITIONALRESTRICTIONFILTERS"=>"RestrictionFilters",
56           "ADDITIONALPROTOCOLLS"        =>"TransportProtocols") as $file => $var){
57       if(isset($this->config->data['MAIN'][$file])){
58         $file = $this->config->data['MAIN'][$file];
59         if((isset($file)) && is_readable($file)){
60           $tmp = file_get_contents($file);
61           $tmp2= split("\n",$tmp);
62           foreach($tmp2 as $entry){
63             if(empty($entry)) continue;
64             if(preg_match("/:/",$entry)){
65               $tmp3 = split(":",$entry);
66               $r = $this->$var;
67               $r[$tmp3[0]]=$tmp3[1];
68               $this->$var = $r;
69             }else{
70               $r = $this->$var;
71               $r[$entry] =$entry;
72               $this->$var = $r;
73             }
74           }
75         }
76       }
77     }
80     /* Get postfix my networks */
81     $this->postfixMyNetworks = array();
82     $tmp = array();
83     if(isset($this->attrs['postfixMyNetworks'][0])){
84       $tmp = split(",",$this->attrs['postfixMyNetworks'][0]);
85       foreach($tmp as $str){
86         if(!empty($str)){
87           $this->postfixMyNetworks[base64_encode($str)] = $str;
88         }
89       }
90     }
93     /* Create full name */
94     if(isset($this->attrs['postfixMyDomain'][0])){
95       $this->postfixMyhostname .= ".".$this->attrs['postfixMyDomain'][0];
96     }
97   
99     /* Get postfix my domains */
100     $this->postfixMyDestinations = array(); 
101     if(isset($this->attrs['postfixMyDestinations'][0])){
102       unset($this->attrs['postfixMyDestinations']['count']);
103       foreach($this->attrs['postfixMyDestinations'] as $str){
104         $this->postfixMyDestinations[base64_encode($str)] = $str;
105       }
106     }
109     /* Get transport tables */
110     $tmp = array();
111     $this->postfixTransportTable = array();
112     if(isset($this->attrs['postfixTransportTable'])){
113       $tmp = array();
114       unset($this->attrs['postfixTransportTable']['count']);
115       foreach($this->attrs['postfixTransportTable'] as $entry){ 
116         $nr  = preg_replace("/:.*$/","",$entry);
117         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
118         $src = preg_replace("/ .*$/","",$rest);
119         $rest= preg_replace("/^[^ ]+ /","",$rest);
120         $dst = preg_replace("/^.*:/","",$rest); 
121         $prt = preg_replace("/:.*$/","",$rest);
122       
123         $tmp[$nr]['src'] = $src;
124         $tmp[$nr]['dst'] = $dst;
125         $tmp[$nr]['prt'] = $prt;
126         
127       }
128       ksort($tmp);
129       foreach($tmp as $entry){
130         $this->postfixTransportTable[] = $entry;
131       }
132     }
133    
135     /* Get sender restrictions */
136     $tmp = array();
137     $this->postfixSenderRestrictions = array();
138     if(isset($this->attrs['postfixSenderRestrictions'])){
139       unset($this->attrs['postfixSenderRestrictions']['count']);
140       foreach($this->attrs['postfixSenderRestrictions'] as $entry){
141         $nr  = preg_replace("/:.*$/","",$entry);
142         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
143         $src = preg_replace("/ .*$/","",$rest);
144         $rest= preg_replace("/^[^ ]+ /","",$rest);
145         $dst = preg_replace("/^.* /","",$rest);
146         $prt = preg_replace("/ .*$/","",$rest);
147  
148         $tmp[$nr]['src'] = $src;
149         $tmp[$nr]['dst'] = $dst;
150         $tmp[$nr]['filter'] = $prt;
151       }
152       ksort($tmp);
153       foreach($tmp as $entry){
154         $this->postfixSenderRestrictions[] = $entry;
155       }
156     }
158  
159     /* Get sender restrictions */
160     $tmp = array();
161     $this->postfixRecipientRestrictions = array();
162     if(isset($this->attrs['postfixRecipientRestrictions'])){
163       unset($this->attrs['postfixRecipientRestrictions']['count']);
164       foreach($this->attrs['postfixRecipientRestrictions'] as $entry){
165         $nr  = preg_replace("/:.*$/","",$entry);
166         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
167         $src = preg_replace("/ .*$/","",$rest);
168         $rest= preg_replace("/^[^ ]+ /","",$rest);
169         $dst = preg_replace("/^.* /","",$rest);
170         $prt = preg_replace("/ .*$/","",$rest);
171  
172         $tmp[$nr]['src'] = $src;
173         $tmp[$nr]['dst'] = $dst;
174         $tmp[$nr]['filter'] = $prt;
175       }
176       ksort($tmp);
177       foreach($tmp as $entry){
178         $this->postfixRecipientRestrictions[] = $entry;
179       }
180     }
182   }
184   function execute()
185   { 
186     $smarty   = get_smarty();
187     $delAr    = array( "TranslationDel_"=>"TranslationDel",
188                     "SenderRestrictDel_"=>"SenderRestrictDel",
189                     "RecipientRestrictDel_"=>"RecipientRestrictDel");
190  
191     $once     = true;
192     $s_action = "";
193     $s_entry  = "";
194   
195     /* Check posts for some intruductions */
196     foreach($_POST as $name => $value){
197       foreach($delAr as $preg => $type){
198         if((preg_match("/^".$preg."/",$name)) && ($once)){
199           $once = false;
200           $s_action = $type; 
201           $s_entry = preg_replace("/^".$preg."/","",$name);
202           $s_entry = preg_replace("/_[xy]$/","",$s_entry);
203         }
204       }
205   
207       if(preg_match("/^TranslationUp_/",$name) && $once){
208         $once = false;
209         $key = preg_replace("/^TranslationUp_/","",$name);
210         $key = preg_replace("/_[xy]$/","",$key);
211         $this->postfixTransportTable = $this->ArrayUp($key,$this->postfixTransportTable) ;
212       }
213       if(preg_match("/^TranslationDown_/",$name) && $once){
214         $once = false;
215         $key = preg_replace("/^TranslationDown_/","",$name);
216         $key = preg_replace("/_[xy]$/","",$key);
217         $this->postfixTransportTable = $this->ArrayDown($key,$this->postfixTransportTable) ;
218       }
219       if(preg_match("/^SenderRestrictUp_/",$name) && $once){
220         $once = false;
221         $key = preg_replace("/^SenderRestrictUp_/","",$name);
222         $key = preg_replace("/_[xy]$/","",$key);
223         $this->postfixSenderRestrictions = $this->ArrayUp($key,$this->postfixSenderRestrictions) ;
224       }
225       if(preg_match("/^SenderRestrictDown_/",$name) && $once){
226         $once = false;
227         $key = preg_replace("/^SenderRestrictDown_/","",$name);
228         $key = preg_replace("/_[xy]$/","",$key);
229         $this->postfixSenderRestrictions = $this->ArrayDown($key,$this->postfixSenderRestrictions) ;
230       }
231       if(preg_match("/^RecipientRestrictUp_/",$name) && $once){
232         $once = false;
233         $key = preg_replace("/^RecipientRestrictUp_/","",$name);
234         $key = preg_replace("/_[xy]$/","",$key);
235         $this->postfixRecipientRestrictions = $this->ArrayUp($key,$this->postfixRecipientRestrictions) ;
236       }
237       if(preg_match("/^RecipientRestrictDown_/",$name) && $once){
238         $once = false;
239         $key = preg_replace("/^RecipientRestrictDown_/","",$name);
240         $key = preg_replace("/_[xy]$/","",$key);
241         $this->postfixRecipientRestrictions = $this->ArrayDown($key,$this->postfixRecipientRestrictions) ;
242       }
243     }
246     /* Add delete my network entry */
247     if((isset($_POST['AddpostfixMyNetworks'])) && (!empty($_POST['NewString_postfixMyNetworks']))){
248       $str = $_POST['NewString_postfixMyNetworks'];
249       $this->postfixMyNetworks[base64_encode($str)] = $str;
250     }
252     if((isset($_POST['DelpostfixMyNetworks'])) && isset($_POST['Select_postfixMyNetworks']) &&(count($_POST['Select_postfixMyNetworks']))){
253       foreach($_POST['Select_postfixMyNetworks'] as $str ){
254         unset($this->postfixMyNetworks[$str]);
255       }
256     }
259     /* Add delete my domain entry */
260     if((isset($_POST['AddpostfixMyDestinations'])) && (!empty($_POST['NewString_postfixMyDestinations']))){
261       $str = $_POST['NewString_postfixMyDestinations'];
262       $this->postfixMyDestinations[base64_encode($str)] = $str;
263     }
265     if((isset($_POST['DelpostfixMyDestinations'])) && isset($_POST['Select_postfixMyDestinations']) &&(count($_POST['Select_postfixMyDestinations']))){
266       foreach($_POST['Select_postfixMyDestinations'] as $str ){
267         unset($this->postfixMyDestinations[$str]);
268       }
269     }
272     /* Add sender restriction */
273     if(($s_action == "SenderRestrictDel") && (isset($this->postfixSenderRestrictions[$s_entry]))){
274       unset($this->postfixSenderRestrictions[$s_entry]);
275     }
277     if(isset($_POST['AddpostfixSenderRestrictions'])){
278       $src      = $_POST['Source_postfixSenderRestrictions'];
279       $dst      = $_POST['Destination_postfixSenderRestrictions'];
280       $Filter   = $_POST['SenderRestrictionFilter'];
281       $tmp['src']     = $src;
282       $tmp['dst']     = $dst;
283       $tmp['filter']  = $Filter;
284       $this->postfixSenderRestrictions[] = $tmp;
285     }
288     /* Add sender restriction */
289     if(($s_action == "RecipientRestrictDel") && (isset($this->postfixRecipientRestrictions[$s_entry]))){
290       unset($this->postfixRecipientRestrictions[$s_entry]);
291     }
293     if(isset($_POST['AddpostfixRecipientRestrictions'])){
294       $src      = $_POST['Source_postfixRecipientRestrictions'];
295       $dst      = $_POST['Destination_postfixRecipientRestrictions'];
296       $Filter   = $_POST['RecipientRestrictionFilter'];
297       $tmp['src']     = $src;
298       $tmp['dst']     = $dst;
299       $tmp['filter']  = $Filter;
300       $this->postfixRecipientRestrictions[] = $tmp;
301     }
304     /* Handle transports */
305     if(($s_action == "TranslationDel") && (isset($this->postfixTransportTable[$s_entry]))){
306       unset($this->postfixTransportTable[$s_entry]);
307     }
308     
309     if(isset($_POST['AddpostfixTransportTable'])){
310       $src = trim($_POST['Source_postfixTransportTable']);  
311       $dst = trim($_POST['Destination_postfixTransportTable']);    
312       $prt = trim($_POST['TransportProtocol']);
314       if((!empty($src)) && (!empty($dst))){
315         if(preg_match("/:/",$dst)){
316           $tmp = split("\:",$dst);
317           $port = trim($tmp[1]);
318           $ip   = trim($tmp[0]);
319     
320           if((is_ip($ip)) && (is_numeric($port))){
321             $dst = "[".$ip."]:".$port;
322           }
323         }
324         if(is_ip($dst)){
325           $dst = "[".$dst."]";
326         }
327         $tmp2 ['src'] = $src;
328         $tmp2 ['dst'] = $dst;
329         $tmp2 ['prt'] = $prt;
331         $this->postfixTransportTable[] = $tmp2;  
332       } 
333     }
336     /* Set attributes */
337     foreach($this->attributes as $attr){
338       $smarty->assign($attr,$this->$attr);
339     }
342     /* Create divList for translation tables */
343     $divTranslation = new divSelectBox("TransportProtocols");
344     $divTranslation->SetHeight(90);
345     foreach($this->postfixTransportTable as $key => $entry){
346       $img = "";
348       if($key != 0){
349         $img.= "<input type='image' src='images/sort_up.png' name='TranslationUp_".$key."' class='center'>&nbsp;";      
350       }else{
351         $img.= "<img src='images/empty.png' style='width:10px;'>";
352       }
353       if(($key+1) < count($this->postfixTransportTable)){
354         $img.= "<input type='image' src='images/sort_down.png' name='TranslationDown_".$key."' class='center'>&nbsp;";      
355       }else{
356         $img.= "<img src='images/empty.png' style='width:10px;'>";
357       }
359       $img.= "<input type='image' src='images/edittrash.png' name='TranslationDel_".$key."' class='center'>&nbsp;";      
360       $field1 = array("string"=> $entry['src']);
361       $field2 = array("string"=> $entry['dst']);
362       $field3 = array("string"=> $entry['prt'],"attach"=>"style='width:120px;'");
363       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
364       $divTranslation->AddEntry(array($field1,$field2,$field3,$field4,));
365     }
366     $smarty->assign("Div_postfixTransportTable" ,$divTranslation->DrawList());
369     /* Create divList for sender restrictions */
370     $DivSenderRestrict = new divSelectBox("postfixSenderRestrictions");
371     $DivSenderRestrict->SetHeight(90);
372     foreach($this->postfixSenderRestrictions as $key => $entry){
373       $img ="";
375       if($key != 0){
376         $img.= "<input type='image' src='images/sort_up.png' name='SenderRestrictUp_".$key."' class='center'>&nbsp;";      
377       }else{
378         $img.= "<img src='images/empty.png' style='width:10px;'>";
379       }
380       if(($key+1) < count($this->postfixSenderRestrictions)){
381         $img.= "<input type='image' src='images/sort_down.png' name='SenderRestrictDown_".$key."' class='center'>&nbsp;";      
382       }else{
383         $img.= "<img src='images/empty.png' style='width:10px;'>";
384       }
386       $img.= "<input type='image' src='images/edittrash.png' name='SenderRestrictDel_".$key."' class='center'>&nbsp;";     
387  
388       $field1 = array("string"=> $entry['src']);
389       $field2 = array("string"=> $entry['dst']);
390       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
391       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
392       $DivSenderRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
393     }
394     $smarty->assign("Div_postfixSenderRestrictions" ,$DivSenderRestrict->DrawList());
397     /* Create divList for translation tables */
398     $DivRecipientRestrict = new divSelectBox("postfixRecipientRestrictions");
399     $DivRecipientRestrict->SetHeight(90);
401     foreach($this->postfixRecipientRestrictions as $key => $entry){
402       $img = "";
403       if($key != 0){
404         $img.= "<input type='image' src='images/sort_up.png' name='RecipientRestrictUp_".$key."' class='center'>&nbsp;";      
405       }else{
406         $img.= "<img src='images/empty.png' style='width:10px;'>";
407       }
408       if(($key+1) < count($this->postfixRecipientRestrictions)){
409         $img.= "<input type='image' src='images/sort_down.png' name='RecipientRestrictDown_".$key."' class='center'>&nbsp;";      
410       }else{
411         $img.= "<img src='images/empty.png' style='width:10px;'>";
412       }
413       $img.= "<input type='image' src='images/edittrash.png' name='RecipientRestrictDel_".$key."' class='center'>&nbsp;";      
414       $field1 = array("string"=> $entry['src']);
415       $field2 = array("string"=> $entry['dst']);
416       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
417       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
418       $DivRecipientRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
419     }
420     $smarty->assign("Div_postfixRecipientRestrictions" ,$DivRecipientRestrict->DrawList());
422     
423     /* set new status */
424     if(isset($_POST['ExecAction'])){
425       if(isset($this->Actions[$_POST['action']])){
426         $this->setStatus($_POST['action']);
427       }
428     }
431     $smarty->assign("is_new",                       $this->dn);
432     $smarty->assign("is_acc",                       $this->initially_was_account);
433     $smarty->assign("TransportProtocols",           $this->TransportProtocols);
434     $smarty->assign("Actions",                      $this->Actions);
435     $smarty->assign("RestrictionFilters",           $this->RestrictionFilters);
436     $smarty->assign("postfixTransportTable" ,       $this->getTransports());
437     $smarty->assign("postfixSenderRestrictions" ,   $this->getSenderRestrictions());
438     $smarty->assign("postfixRecipientRestrictions" ,$this->getRecipientRestrictions());
440     return($smarty->fetch(get_template_path("goMailServer.tpl",TRUE,dirname(__FILE__))));
441   }
443  
444   /* return transports formated for select box */ 
445   function getTransports()
446   {
447     $ret = array();
448     foreach($this->postfixTransportTable as $key => $vals){
449       $ret[$key] = $vals['src']." -> ".$vals['prt'].":".$vals['dst'];
450     }
451     return($ret);
452   }
455   /* return sender restriction formated for select box */ 
456   function getSenderRestrictions()
457   {
458     $ret = array();
459     foreach($this->postfixSenderRestrictions as $key => $vals){
460       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
461     }
462     return($ret);
463   }
466   /* return recipient restriction formated for select box */ 
467   function getRecipientRestrictions()
468   {
469     $ret = array();
470     foreach($this->postfixRecipientRestrictions as $key => $vals){
471       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
472     }
473     return($ret);
474   }
477   /* Return list entry */
478   function getListEntry()
479   {
480     $flag = $this->StatusFlag;
481     $fields['Status']     = $this->$flag;
482     $fields['Message']    = _("Postfix")." ["._("configured for")." ".$this->postfixMyhostname."] ";
483     $fields['AllowStart'] = true;
484     $fields['AllowStop']  = true;
485     $fields['AllowRestart'] = true;
486     $fields['AllowRemove']= true;
487     $fields['AllowEdit']  = true;
488     return($fields);
489   }
492   function remove_from_parent()
493   {
494     plugin::remove_from_parent();
495     /* Check if this is a new entry ... add/modify */
496     $ldap = $this->config->get_ldap_link();
497     $ldap->cat($this->dn,array("objectClass"));
498     if($ldap->count()){
499       $ldap->cd($this->dn);
500       $ldap->modify($this->attrs);
501     }else{
502       $ldap->cd($this->dn);
503       $ldap->add($this->attrs);
504     }
505     show_ldap_error($ldap->get_error());
506   }
509   function save()
510   {
511     $this->postfixMyDomain   = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
512     $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
514     plugin::save();
516     /* Fix transport table*/
517     $i = 0 ; 
518     $this->attrs['postfixTransportTable'] = array();
519     foreach($this->postfixTransportTable as $key => $entry){
520       $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
521       $i ++;
522     }
525     /* Fix sender restrictions */
526     $i = 0;
527     $this->attrs['postfixSenderRestrictions'] =array();
528     foreach($this->postfixSenderRestrictions as $key => $entry){
529       $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
530       $i ++;  
531     }
532   
533   
534     /* Fix recipient restrictions */
535     $i = 0;
536     $this->attrs['postfixRecipientRestrictions'] =array();
537     foreach($this->postfixRecipientRestrictions as $key => $entry){
538       $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
539       $i ++;  
540     }
543     /* Fix mydomains */
544     $this->attrs['postfixMyDestinations']  = array();
545     foreach($this->postfixMyDestinations as $entry){
546       $this->attrs['postfixMyDestinations'][] =$entry;
547     }
550     /* Fix mydomains */
551     if(count($this->postfixMyNetworks)){
552       $this->attrs['postfixMyNetworks']  = "";
553       foreach($this->postfixMyNetworks as $entry){
554         $this->attrs['postfixMyNetworks'] .=$entry.",";
555       }
556       $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
557     }else{
558       $this->attrs['postfixMyNetworks']  = array();
559     }
561  
562     /* Check if this is a new entry ... add/modify */
563     $ldap = $this->config->get_ldap_link();
564     $ldap->cat($this->dn,array("objectClass"));
565     if($ldap->count()){
566       $ldap->cd($this->dn);
567       $ldap->modify($this->attrs);
568     }else{
569       $ldap->cd($this->dn);
570       $ldap->add($this->attrs);
571     }
572     show_ldap_error($ldap->get_error());
573   }
576   /* Directly save new status flag */
577   function setStatus($value)
578   {
579     if($value == "none") return;
580     if(!$this->initially_was_account) return;
581     $ldap = $this->config->get_ldap_link();
582     $ldap->cd($this->dn);
583     $ldap->cat($this->dn,array("objectClass"));
584     if($ldap->count()){
586       $tmp = $ldap->fetch();
587       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
588         $attrs['objectClass'][] = $tmp['objectClass'][$i];
589       }
590       $flag = $this->StatusFlag;
591       $attrs[$flag] = $value;
592       $this->$flag = $value;
593       $ldap->modify($attrs);
594       show_ldap_error($ldap->get_error());
595       $this->action_hook();
596     }
597   }
600   function check()
601   { 
602     $message =plugin::check();
603   
604     if(!is_numeric($this->postfixHeaderSizeLimit)){
605       $message[] = _("Please specify a numeric value for header size limit.");
606     }
608     if(!is_numeric($this->postfixMailboxSizeLimit)){
609       $message[] = _("Please specify a numeric value for mailbox size limit.");
610     }
612     if(!is_numeric($this->postfixMessageSizeLimit)){
613       $message[] = _("Please specify a numeric value for message size limit.");
614     }
616     return $message;
617   }
620   /* Combine new array */
621   function combineArrays($ar0,$ar1,$ar2)
622   {
623     $ret = array();
624     if(is_array($ar0))
625     foreach($ar0 as $ar => $a){
626         $ret[]=$a;
627     }
628     if(is_array($ar1))
629     foreach($ar1 as $ar => $a){
630         $ret[]=$a;
631     }
632     if(is_array($ar2))
633     foreach($ar2 as $ar => $a){
634         $ret[]=$a;
635     }
636     return($ret);
637   }
640   function getpos($atr,$attrs)
641   {
642     $i = 0;
643     foreach($attrs as $attr => $name)    {
644       $i++;
645       if($attr == $atr){
646         return($i);
647       }
648     }
650     return(-1);
651   }
654   /* TRansports the geiven Arraykey one position up*/
655   function ArrayUp($atr,$attrs)
656   {
657     $ret = $attrs;
658     $pos = $this->getpos($atr,$attrs) ;
659     $cn = count($attrs);
660     if(!(($pos == -1)||($pos == 1))){
661       $before = array_slice($attrs,0,($pos-2));
662       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
663       $unten  = array_slice($attrs,$pos);
664       $ret = array();
665       $ret = $this->combineArrays($before,$mitte,$unten);
666     }
667     return($ret);
668   }
671   /* TRansports the geiven Arraykey one position up*/
672   function ArrayDown($atr,$attrs)
673   {
674     $ret = $attrs;
675     $pos = $this->getpos($atr,$attrs) ;
676     $cn = count($attrs);
677     if(!(($pos == -1)||($pos == $cn))){
678       $before = array_slice($attrs,0,($pos-1));
679       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
680       $unten  = array_slice($attrs,($pos+1));
681       $ret = array();
682       $ret = $this->combineArrays($before,$mitte,$unten);
683     }
684     return($ret);
685   }
687   
688   function action_hook($add_attrs= array())
689   {
690     /* Find postcreate entries for this class */
691     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
692     if ($command == "" && isset($this->config->data['TABS'])){
693       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
694     }
695     if ($command != ""){
696       /* Walk through attribute list */
697       foreach ($this->attributes as $attr){
698         if (!is_array($this->$attr)){
699           $command= preg_replace("/%$attr/", $this->$attr, $command);
700         }
701       }
702       $command= preg_replace("/%dn/", $this->dn, $command);
703       /* Additional attributes */
704       foreach ($add_attrs as $name => $value){
705         $command= preg_replace("/%$name/", $value, $command);
706       }
707       if (check_command($command)){
708         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
709             $command, "Execute");
711         exec($command);
712       } else {
713         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
714         print_red ($message);
715       }
716     }
717   }
719   function save_object()
720   {
721     plugin::save_object();  
722   }
724 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
725 ?>