Code

Udpated logging
[gosa.git] / plugins / admin / systems / class_goMailServer.inc
1 <?php
3 require_once("class_goService.inc");
5 class goMailServer extends goService{
6         
7   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports mailqueue listings and so on.";
8   var $cli_description  = "Some longer text\nfor help";
9   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
11   /* This plugin only writes its objectClass */
12   var $objectclasses    = array("goMailServer");
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $DisplayName      = "";
16   var $dn               = NULL;
17   var $StatusFlag       = "goMailServerStatus";
18   var $attributes       = array("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();
40   var $cn                               = "";
41   var $conflicts                        = array("goMailServer","kolab");
42   var $view_logged  =FALSE;
44   function goMailServer($config,$dn)
45   {
46     goService::goService($config,$dn);
47     $this->DisplayName = _("Mail smtp service (Postfix)");
49     $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
50                             SERVICE_STARTED => SERVICE_STARTED,
51                             SERVICE_RESTARTED=>SERVICE_RESTARTED); 
53     /* Fill  RestrictionFilters   TransportProtocols  from external hooks */
54     $str = $this->config->data['TABS']['SERVERSERVICE'];
55     $this->TransportProtocols =array("smtp"=>"SMTP");
56     $this->RestrictionFilters = array("FILTER"=>"FILTER"); 
57     foreach(array("ADDITIONALRESTRICTIONFILTERS"=>"RestrictionFilters",
58           "ADDITIONALPROTOCOLLS"        =>"TransportProtocols") as $file => $var){
59       if(isset($this->config->data['MAIN'][$file])){
60         $file = $this->config->data['MAIN'][$file];
61         if((isset($file)) && is_readable($file)){
62           $tmp = file_get_contents($file);
63           $tmp2= split("\n",$tmp);
64           foreach($tmp2 as $entry){
65             if(empty($entry)) continue;
66             if(preg_match("/:/",$entry)){
67               $tmp3 = split(":",$entry);
68               $r = $this->$var;
69               $r[$tmp3[0]]=$tmp3[1];
70               $this->$var = $r;
71             }else{
72               $r = $this->$var;
73               $r[$entry] =$entry;
74               $this->$var = $r;
75             }
76           }
77         }
78       }
79     }
82     /* Get postfix my networks */
83     $this->postfixMyNetworks = array();
84     $tmp = array();
85     if(isset($this->attrs['postfixMyNetworks'][0])){
86       $tmp = split(",",$this->attrs['postfixMyNetworks'][0]);
87       foreach($tmp as $str){
88         if(!empty($str)){
89           $this->postfixMyNetworks[base64_encode($str)] = $str;
90         }
91       }
92     }
95     /* Create full name */
96     if(isset($this->attrs['postfixMyDomain'][0])){
97       $this->postfixMyhostname .= ".".$this->attrs['postfixMyDomain'][0];
98     }
99   
101     /* Get postfix my domains */
102     $this->postfixMyDestinations = array(); 
103     if(isset($this->attrs['postfixMyDestinations'][0])){
104       unset($this->attrs['postfixMyDestinations']['count']);
105       foreach($this->attrs['postfixMyDestinations'] as $str){
106         $this->postfixMyDestinations[base64_encode($str)] = $str;
107       }
108     }
111     /* Get transport tables */
112     $tmp = array();
113     $this->postfixTransportTable = array();
114     if(isset($this->attrs['postfixTransportTable'])){
115       $tmp = array();
116       unset($this->attrs['postfixTransportTable']['count']);
117       foreach($this->attrs['postfixTransportTable'] as $entry){
119         //0: offshore.vip.ms-europa.lhsystems.com smtp:172.28.0.2
121         $Number   = preg_replace('/^([^:]+):.*$/', '\\1', $entry);
122         $Rest     = trim(preg_replace("/^[0-9]*:/","",$entry));
124         $Protocol_Destination = preg_replace("/^.*\ /","",$Rest);
125         $Source               = preg_replace("/\ .*$/","",$Rest);
127         $Protocol     = preg_replace ('/^([^:]+):.*$/', '\\1' ,trim($Protocol_Destination));
128         $Destination  = preg_replace ('/^[^:]+:(.*)$/', '\\1'    ,trim($Protocol_Destination));
130         $Destination  = preg_replace ("/[\[\]]/","",$Destination);
132         $tmp[$Number]['src'] = $Source;
133         $tmp[$Number]['dst'] = $Destination;
134         $tmp[$Number]['prt'] = $Protocol;
135       }
136       ksort($tmp);
137       foreach($tmp as $entry){
138         $this->postfixTransportTable[] = $entry;
139       }
140     }
141    
143     /* Get sender restrictions */
144     $tmp = array();
145     $this->postfixSenderRestrictions = array();
146     if(isset($this->attrs['postfixSenderRestrictions'])){
147       unset($this->attrs['postfixSenderRestrictions']['count']);
148       foreach($this->attrs['postfixSenderRestrictions'] as $entry){
149         $nr  = preg_replace("/:.*$/","",$entry);
150         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
151         $src = preg_replace("/ .*$/","",$rest);
152         $rest= preg_replace("/^[^ ]+ /","",$rest);
153         $dst = preg_replace("/^.* /","",$rest);
154         $prt = preg_replace("/ .*$/","",$rest);
155  
156         $tmp[$nr]['src'] = $src;
157         $tmp[$nr]['dst'] = $dst;
158         $tmp[$nr]['filter'] = $prt;
159       }
160       ksort($tmp);
161       foreach($tmp as $entry){
162         $this->postfixSenderRestrictions[] = $entry;
163       }
164     }
166  
167     /* Get sender restrictions */
168     $tmp = array();
169     $this->postfixRecipientRestrictions = array();
170     if(isset($this->attrs['postfixRecipientRestrictions'])){
171       unset($this->attrs['postfixRecipientRestrictions']['count']);
172       foreach($this->attrs['postfixRecipientRestrictions'] as $entry){
173         $nr  = preg_replace("/:.*$/","",$entry);
174         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
175         $src = preg_replace("/ .*$/","",$rest);
176         $rest= preg_replace("/^[^ ]+ /","",$rest);
177         $dst = preg_replace("/^.* /","",$rest);
178         $prt = preg_replace("/ .*$/","",$rest);
179  
180         $tmp[$nr]['src'] = $src;
181         $tmp[$nr]['dst'] = $dst;
182         $tmp[$nr]['filter'] = $prt;
183       }
184       ksort($tmp);
185       foreach($tmp as $entry){
186         $this->postfixRecipientRestrictions[] = $entry;
187       }
188     }
190   }
192   function execute()
193   { 
194     $smarty   = get_smarty();
196     if($this->is_account && !$this->view_logged){
197       $this->view_logged = TRUE;
198       new log("view","server/".get_class($this),$this->dn);
199     }
201     $tmp = $this->plInfo();
202     foreach($tmp['plProvidedAcls'] as $name => $translation){
203       $smarty->assign($name."ACL",$this->getacl($name));
204     }
206     $delAr    = array( 
207                     "TranslationDel_"=>"TranslationDel",
208                     "SenderRestrictDel_"=>"SenderRestrictDel",
209                     "RecipientRestrictDel_"=>"RecipientRestrictDel");
210  
211     $once     = true;
212     $s_action = "";
213     $s_entry  = "";
214   
215     /* Check posts for some intruductions */
216     foreach($_POST as $name => $value){
217       foreach($delAr as $preg => $type){
218         if((preg_match("/^".$preg."/",$name)) && ($once)){
219           $once = false;
220           $s_action = $type; 
221           $s_entry = preg_replace("/^".$preg."/","",$name);
222           $s_entry = preg_replace("/_[xy]$/","",$s_entry);
223         }
224       }
225   
227       if(preg_match("/^TranslationUp_/",$name) && $once && ($this->acl_is_writeablei("postfixTransportTableACL"))){
228         $once = false;
229         $key = preg_replace("/^TranslationUp_/","",$name);
230         $key = preg_replace("/_[xy]$/","",$key);
231         $this->postfixTransportTable = $this->ArrayUp($key,$this->postfixTransportTable) ;
232       }
233       if(preg_match("/^TranslationDown_/",$name) && $once && ($this->acl_is_writeable("postfixTransportTableACL"))){
234         $once = false;
235         $key = preg_replace("/^TranslationDown_/","",$name);
236         $key = preg_replace("/_[xy]$/","",$key);
237         $this->postfixTransportTable = $this->ArrayDown($key,$this->postfixTransportTable) ;
238       }
239       if(preg_match("/^SenderRestrictUp_/",$name) && $once && ($this->acl_is_writeable("postfixSenderRestrictionsACL"))){
240         $once = false;
241         $key = preg_replace("/^SenderRestrictUp_/","",$name);
242         $key = preg_replace("/_[xy]$/","",$key);
243         $this->postfixSenderRestrictions = $this->ArrayUp($key,$this->postfixSenderRestrictions) ;
244       }
245       if(preg_match("/^SenderRestrictDown_/",$name) && $once && ($this->acl_is_writeable("postfixSenderRestrictionsACL"))){
246         $once = false;
247         $key = preg_replace("/^SenderRestrictDown_/","",$name);
248         $key = preg_replace("/_[xy]$/","",$key);
249         $this->postfixSenderRestrictions = $this->ArrayDown($key,$this->postfixSenderRestrictions) ;
250       }
251       if(preg_match("/^RecipientRestrictUp_/",$name) && $once && ($this->acl_is_writeable("postfixRecipientRestrictionsACL"))){
252         $once = false;
253         $key = preg_replace("/^RecipientRestrictUp_/","",$name);
254         $key = preg_replace("/_[xy]$/","",$key);
255         $this->postfixRecipientRestrictions = $this->ArrayUp($key,$this->postfixRecipientRestrictions) ;
256       }
257       if(preg_match("/^RecipientRestrictDown_/",$name) && $once && ($this->acl_is_writeable("postfixRecipientRestrictionsACL"))){
258         $once = false;
259         $key = preg_replace("/^RecipientRestrictDown_/","",$name);
260         $key = preg_replace("/_[xy]$/","",$key);
261         $this->postfixRecipientRestrictions = $this->ArrayDown($key,$this->postfixRecipientRestrictions) ;
262       }
263     }
266     /* Add delete my network entry */
267     if((isset($_POST['AddpostfixMyNetworks'])) && (!empty($_POST['NewString_postfixMyNetworks']))){
268       $str = $_POST['NewString_postfixMyNetworks'];
269       $this->postfixMyNetworks[base64_encode($str)] = $str;
270     }
272     if((isset($_POST['DelpostfixMyNetworks'])) && isset($_POST['Select_postfixMyNetworks']) &&(count($_POST['Select_postfixMyNetworks']))){
273       foreach($_POST['Select_postfixMyNetworks'] as $str ){
274         unset($this->postfixMyNetworks[$str]);
275       }
276     }
279     /* Add delete my domain entry */
280     if($this->acl_is_writeable("postfixMyDestinations")){
281       if((isset($_POST['AddpostfixMyDestinations'])) && (!empty($_POST['NewString_postfixMyDestinations']))){
282         $str = $_POST['NewString_postfixMyDestinations'];
283         $this->postfixMyDestinations[base64_encode($str)] = $str;
284       }
286       if((isset($_POST['DelpostfixMyDestinations'])) && isset($_POST['Select_postfixMyDestinations']) &&(count($_POST['Select_postfixMyDestinations']))){
287         foreach($_POST['Select_postfixMyDestinations'] as $str ){
288           unset($this->postfixMyDestinations[$str]);
289         }
290       }
291     }
294     /* Add sender restriction */
295     if($this->acl_is_writeable("postfixSenderRestrictions")){
296       if(($s_action == "SenderRestrictDel") && (isset($this->postfixSenderRestrictions[$s_entry]))){
297         unset($this->postfixSenderRestrictions[$s_entry]);
298       }
300       if(isset($_POST['AddpostfixSenderRestrictions'])){
301         $src      = $_POST['Source_postfixSenderRestrictions'];
302         $dst      = $_POST['Destination_postfixSenderRestrictions'];
303         $Filter   = $_POST['SenderRestrictionFilter'];
304         $tmp['src']     = $src;
305         $tmp['dst']     = $dst;
306         $tmp['filter']  = $Filter;
307         $this->postfixSenderRestrictions[] = $tmp;
308       }
309     }
312     /* Add sender restriction */
313     if($this->acl_is_writeable("postfixRecipientRestrictions")){
314       if(($s_action == "RecipientRestrictDel") && (isset($this->postfixRecipientRestrictions[$s_entry]))){
315         unset($this->postfixRecipientRestrictions[$s_entry]);
316       }
318       if(isset($_POST['AddpostfixRecipientRestrictions'])){
319         $src      = $_POST['Source_postfixRecipientRestrictions'];
320         $dst      = $_POST['Destination_postfixRecipientRestrictions'];
321         $Filter   = $_POST['RecipientRestrictionFilter'];
322         $tmp['src']     = $src;
323         $tmp['dst']     = $dst;
324         $tmp['filter']  = $Filter;
325         $this->postfixRecipientRestrictions[] = $tmp;
326       }
327     }
329     /* Handle transports */
330     if($this->acl_is_writeable("postfixTransportTable")){
331       if(($s_action == "TranslationDel") && (isset($this->postfixTransportTable[$s_entry]))){
332         unset($this->postfixTransportTable[$s_entry]);
333       }
335       if(isset($_POST['AddpostfixTransportTable'])){
336         $src = trim($_POST['Source_postfixTransportTable']);  
337         $dst = trim($_POST['Destination_postfixTransportTable']);    
338         $prt = trim($_POST['TransportProtocol']);
340         if((!empty($src)) && (!empty($dst))){
341           if(preg_match("/:/",$dst)){
342             $tmp = split("\:",$dst);
343             $port = trim($tmp[1]);
344             $ip   = trim($tmp[0]);
346             if((is_ip($ip)) && (is_numeric($port))){
347               $dst = "[".$ip."]:".$port;
348             }
349           }
350           if(is_ip($dst)){
351             $dst = "[".$dst."]";
352           }
353           $tmp2 ['src'] = $src;
354           $tmp2 ['dst'] = $dst;
355           $tmp2 ['prt'] = $prt;
357           $this->postfixTransportTable[] = $tmp2;  
358         } 
359       }
360     }
362     /* Set attributes */
363     foreach($this->attributes as $attr){
364       $smarty->assign($attr,$this->$attr);
365     }
368     /* Create divList for translation tables */
369     $divTranslation = new divSelectBox("TransportProtocols");
370     $divTranslation->SetHeight(90);
371     foreach($this->postfixTransportTable as $key => $entry){
372       $img = "";
374       if($key != 0 && $this->acl_is_writeable("postfixTransportTable")){
375         $img.= "<input type='image' src='images/sort_up.png' name='TranslationUp_".$key."' class='center'>&nbsp;";      
376       }else{
377         $img.= "<img src='images/empty.png' style='width:10px;'>";
378       }
379       if(($key+1) < count($this->postfixTransportTable) && $this->acl_is_writeable("postfixTransportTable")){
380         $img.= "<input type='image' src='images/sort_down.png' name='TranslationDown_".$key."' class='center'>&nbsp;";      
381       }else{
382         $img.= "<img src='images/empty.png' style='width:10px;'>";
383       }
385       if($this->acl_is_writeable("postfixTransportTable")){
386         $img.= "<input type='image' src='images/edittrash.png' name='TranslationDel_".$key."' class='center'>&nbsp;";      
387       }
388       $field1 = array("string"=> $entry['src']);
389       $field2 = array("string"=> $entry['dst']);
390       $field3 = array("string"=> $entry['prt'],"attach"=>"style='width:120px;'");
391       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
392       $divTranslation->AddEntry(array($field1,$field2,$field3,$field4,));
393     }
394     $smarty->assign("Div_postfixTransportTable" ,$divTranslation->DrawList());
397     /* Create divList for sender restrictions */
398     $DivSenderRestrict = new divSelectBox("postfixSenderRestrictions");
399     $DivSenderRestrict->SetHeight(90);
400     foreach($this->postfixSenderRestrictions as $key => $entry){
401       $img ="";
403       if($key != 0 && $this->acl_is_writeable("postfixSenderRestrictions")){
404         $img.= "<input type='image' src='images/sort_up.png' name='SenderRestrictUp_".$key."' class='center'>&nbsp;";      
405       }else{
406         $img.= "<img src='images/empty.png' style='width:10px;'>";
407       }
408       if(($key+1) < count($this->postfixSenderRestrictions) && $this->acl_is_writeable("postfixSenderRestrictions")){
409         $img.= "<input type='image' src='images/sort_down.png' name='SenderRestrictDown_".$key."' class='center'>&nbsp;";      
410       }else{
411         $img.= "<img src='images/empty.png' style='width:10px;'>";
412       }
414       if($this->acl_is_writeable("postfixSenderRestrictions")){
415         $img.= "<input type='image' src='images/edittrash.png' name='SenderRestrictDel_".$key."' class='center'>&nbsp;";     
416       }
417  
418       $field1 = array("string"=> $entry['src']);
419       $field2 = array("string"=> $entry['dst']);
420       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
421       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
422       $DivSenderRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
423     }
424     $smarty->assign("Div_postfixSenderRestrictions" ,$DivSenderRestrict->DrawList());
427     /* Create divList for translation tables */
428     $DivRecipientRestrict = new divSelectBox("postfixRecipientRestrictions");
429     $DivRecipientRestrict->SetHeight(90);
431     foreach($this->postfixRecipientRestrictions as $key => $entry){
432       $img = "";
433       if($key != 0 && $this->acl_is_writeable("postfixRecipientRestrictions")){
434         $img.= "<input type='image' src='images/sort_up.png' name='RecipientRestrictUp_".$key."' class='center'>&nbsp;";      
435       }else{
436         $img.= "<img src='images/empty.png' style='width:10px;'>";
437       }
438       if(($key+1) < count($this->postfixRecipientRestrictions) && $this->acl_is_writeable("postfixRecipientRestrictions")){
439         $img.= "<input type='image' src='images/sort_down.png' name='RecipientRestrictDown_".$key."' class='center'>&nbsp;";      
440       }else{
441         $img.= "<img src='images/empty.png' style='width:10px;'>";
442       }
444       if($this->acl_is_writeable("postfixRecipientRestrictions")){
445         $img.= "<input type='image' src='images/edittrash.png' name='RecipientRestrictDel_".$key."' class='center'>&nbsp;";      
446       }
447       $field1 = array("string"=> $entry['src']);
448       $field2 = array("string"=> $entry['dst']);
449       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
450       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
451       $DivRecipientRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
452     }
453     $smarty->assign("Div_postfixRecipientRestrictions" ,$DivRecipientRestrict->DrawList());
455     
456     /* set new status */
457     if(isset($_POST['ExecAction'])){
458       if(isset($this->Actions[$_POST['action']])){
459         $this->setStatus($_POST['action']);
460       }
461     }
464     $smarty->assign("is_new",                       $this->dn);
465     $smarty->assign("is_acc",                       $this->initially_was_account);
466     $smarty->assign("TransportProtocols",           $this->TransportProtocols);
467     $smarty->assign("Actions",                      $this->Actions);
468     $smarty->assign("RestrictionFilters",           $this->RestrictionFilters);
469     $smarty->assign("postfixTransportTable" ,       $this->getTransports());
470     $smarty->assign("postfixSenderRestrictions" ,   $this->getSenderRestrictions());
471     $smarty->assign("postfixRecipientRestrictions" ,$this->getRecipientRestrictions());
473     return($smarty->fetch(get_template_path("goMailServer.tpl",TRUE,dirname(__FILE__))));
474   }
476  
477   /* return transports formated for select box */ 
478   function getTransports()
479   {
480     $ret = array();
481     foreach($this->postfixTransportTable as $key => $vals){
482       $ret[$key] = $vals['src']." -> ".$vals['prt'].":".$vals['dst'];
483     }
484     return($ret);
485   }
488   /* return sender restriction formated for select box */ 
489   function getSenderRestrictions()
490   {
491     $ret = array();
492     foreach($this->postfixSenderRestrictions as $key => $vals){
493       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
494     }
495     return($ret);
496   }
499   /* return recipient restriction formated for select box */ 
500   function getRecipientRestrictions()
501   {
502     $ret = array();
503     foreach($this->postfixRecipientRestrictions as $key => $vals){
504       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
505     }
506     return($ret);
507   }
510   /* Return list entry */
511   function getListEntry()
512   {
513     $fields               = goService::getListEntry();
514     $fields['Message']    = _("Mail smtp service (Postfix)");
515     $fields['AllowEdit']  = true;
516     return($fields);
517   }
520   function save()
521   {
522     $this->postfixMyDomain   = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
523     $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
525     plugin::save();
527     /* Fix transport table*/
528     $i = 0 ; 
529     $this->attrs['postfixTransportTable'] = array();
530     foreach($this->postfixTransportTable as $key => $entry){
531       $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
532       $i ++;
533     }
536     /* Fix sender restrictions */
537     $i = 0;
538     $this->attrs['postfixSenderRestrictions'] =array();
539     foreach($this->postfixSenderRestrictions as $key => $entry){
540       $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
541       $i ++;  
542     }
543   
544   
545     /* Fix recipient restrictions */
546     $i = 0;
547     $this->attrs['postfixRecipientRestrictions'] =array();
548     foreach($this->postfixRecipientRestrictions as $key => $entry){
549       $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
550       $i ++;  
551     }
554     /* Fix mydomains */
555     $this->attrs['postfixMyDestinations']  = array();
556     foreach($this->postfixMyDestinations as $entry){
557       $this->attrs['postfixMyDestinations'][] =$entry;
558     }
561     /* Fix mydomains */
562     if(count($this->postfixMyNetworks)){
563       $this->attrs['postfixMyNetworks']  = "";
564       foreach($this->postfixMyNetworks as $entry){
565         $this->attrs['postfixMyNetworks'] .=$entry.",";
566       }
567       $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
568     }else{
569       $this->attrs['postfixMyNetworks']  = array();
570     }
572  
573     /* Check if this is a new entry ... add/modify */
574     $ldap = $this->config->get_ldap_link();
575     $ldap->cat($this->dn,array("objectClass"));
576     if($ldap->count()){
577       $ldap->cd($this->dn);
578       $ldap->modify($this->attrs);
579     }else{
580       $ldap->cd($this->dn);
581       $ldap->add($this->attrs);
582     }
583     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/mail with dn '%s' failed."),$this->dn));
584     if($this->initially_was_account){
585       $this->handle_post_events("modify");
586       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());  
587     }else{
588       $this->handle_post_events("add");
589       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());  
590     }
592   }
595   function check()
596   { 
597     $message =plugin::check();
598   
599     if(!is_numeric($this->postfixHeaderSizeLimit)){
600       $message[] = _("Please specify a numeric value for header size limit.");
601     }
603     if(!is_numeric($this->postfixMailboxSizeLimit)){
604       $message[] = _("Please specify a numeric value for mailbox size limit.");
605     }
607     if(!is_numeric($this->postfixMessageSizeLimit)){
608       $message[] = _("Please specify a numeric value for message size limit.");
609     }
611     return $message;
612   }
615   /* Combine new array */
616   function combineArrays($ar0,$ar1,$ar2)
617   {
618     $ret = array();
619     if(is_array($ar0))
620     foreach($ar0 as $ar => $a){
621         $ret[]=$a;
622     }
623     if(is_array($ar1))
624     foreach($ar1 as $ar => $a){
625         $ret[]=$a;
626     }
627     if(is_array($ar2))
628     foreach($ar2 as $ar => $a){
629         $ret[]=$a;
630     }
631     return($ret);
632   }
635   function getpos($atr,$attrs)
636   {
637     $i = 0;
638     foreach($attrs as $attr => $name)    {
639       $i++;
640       if($attr == $atr){
641         return($i);
642       }
643     }
645     return(-1);
646   }
649   /* TRansports the geiven Arraykey one position up*/
650   function ArrayUp($atr,$attrs)
651   {
652     $ret = $attrs;
653     $pos = $this->getpos($atr,$attrs) ;
654     $cn = count($attrs);
655     if(!(($pos == -1)||($pos == 1))){
656       $before = array_slice($attrs,0,($pos-2));
657       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
658       $unten  = array_slice($attrs,$pos);
659       $ret = array();
660       $ret = $this->combineArrays($before,$mitte,$unten);
661     }
662     return($ret);
663   }
666   /* TRansports the geiven Arraykey one position up*/
667   function ArrayDown($atr,$attrs)
668   {
669     $ret = $attrs;
670     $pos = $this->getpos($atr,$attrs) ;
671     $cn = count($attrs);
672     if(!(($pos == -1)||($pos == $cn))){
673       $before = array_slice($attrs,0,($pos-1));
674       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
675       $unten  = array_slice($attrs,($pos+1));
676       $ret = array();
677       $ret = $this->combineArrays($before,$mitte,$unten);
678     }
679     return($ret);
680   }
682   function save_object()
683   {
684     plugin::save_object();  
685   }
689   /* Return plugin informations for acl handling */
690   function plInfo()
691   {
692     return (array(
693           "plShortName"   => _("Mail smtp (Postfix)"),
694           "plDescription" => _("Mail smtp - Postfix")." ("._("Services").")",
695           "plSelfModify"  => FALSE,
696           "plDepends"     => array(),
697           "plPriority"    => 98,
698           "plSection"     => array("administration"),
699           "plCategory"    => array("server"),
701           "plProvidedAcls"=> array(
702             "postfixMyhostname"           => _("Visible full qualified hostname"),
703             "description"                 => _("Description"), 
704             "postfixHeaderSizeLimit"      => _("Header size limit"), 
705             "postfixMailboxSizeLimit"     => _("Max mailbox size"), 
706             "postfixMessageSizeLimit"     => _("Max message size"), 
707             "postfixMyDestinations"       => _("Domains to accept mail for"), 
708             "postfixMyNetworks"           => _("Local networks"), 
709             "postfixRelayhost"            => _("Relay host"), 
710             "postfixTransportTable"       => _("Transport table"), 
711             "postfixSenderRestrictions"   => _("Restrictions for sender"), 
712             "postfixRecipientRestrictions"=> _("Restrictions for recipient"))
713             ));
714   }
716 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
717 ?>