Code

Fixed acls for system management
[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 $DisplayName      = "";
14   var $dn               = NULL;
15   var $StatusFlag       = "goMailServerStatus";
16   var $attributes       = array("description","postfixHeaderSizeLimit",
17       "postfixMailboxSizeLimit","postfixMessageSizeLimit",
18       "postfixMyDestinations","postfixMyDomain","postfixMyhostname",
19       "postfixMyNetworks","postfixRelayhost","postfixTransportTable",
20       "postfixSenderRestrictions","postfixRecipientRestrictions");
22   var $goMailServerStatus               ;
23   var $postfixHeaderSizeLimit           = 0;
24   var $postfixMailboxSizeLimit          = 0;
25   var $postfixMessageSizeLimit          = 0;
26   var $postfixMyDestinations            = array();
27   var $postfixMyDomain                  = "";
28   var $postfixMyhostname                = "";
29   var $postfixMyNetworks                = array();
30   var $postfixRelayhost                 = "";
31   var $postfixTransportTable            = array();
32   var $postfixSenderRestrictions        = array();
33   var $postfixRecipientRestrictions     = array();
34   var $description                      = "";
35   var $RestrictionFilters               = array();
36   var $TransportProtocols               = array(); 
37   var $Actions                          = array();
38   var $cn                               = "";
39   var $conflicts                        = array("goMailServer","kolab");
41   function goMailServer($config,$dn)
42   {
43     plugin::plugin($config,$dn);
44     $this->DisplayName = _("Mail service (SMTP)");
46     $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
47                             SERVICE_STARTED => SERVICE_STARTED,
48                             SERVICE_RESTARTED=>SERVICE_RESTARTED); 
50     /* Fill  RestrictionFilters   TransportProtocols  from external hooks */
51     $str = $this->config->data['TABS']['SERVERSERVICE'];
52     $this->TransportProtocols =array("smtp"=>"SMTP");
53     $this->RestrictionFilters = array("FILTER"=>"FILTER"); 
54     foreach(array("ADDITIONALRESTRICTIONFILTERS"=>"RestrictionFilters",
55           "ADDITIONALPROTOCOLLS"        =>"TransportProtocols") as $file => $var){
56       if(isset($this->config->data['MAIN'][$file])){
57         $file = $this->config->data['MAIN'][$file];
58         if((isset($file)) && is_readable($file)){
59           $tmp = file_get_contents($file);
60           $tmp2= split("\n",$tmp);
61           foreach($tmp2 as $entry){
62             if(empty($entry)) continue;
63             if(preg_match("/:/",$entry)){
64               $tmp3 = split(":",$entry);
65               $r = $this->$var;
66               $r[$tmp3[0]]=$tmp3[1];
67               $this->$var = $r;
68             }else{
69               $r = $this->$var;
70               $r[$entry] =$entry;
71               $this->$var = $r;
72             }
73           }
74         }
75       }
76     }
79     /* Get postfix my networks */
80     $this->postfixMyNetworks = array();
81     $tmp = array();
82     if(isset($this->attrs['postfixMyNetworks'][0])){
83       $tmp = split(",",$this->attrs['postfixMyNetworks'][0]);
84       foreach($tmp as $str){
85         if(!empty($str)){
86           $this->postfixMyNetworks[base64_encode($str)] = $str;
87         }
88       }
89     }
92     /* Create full name */
93     if(isset($this->attrs['postfixMyDomain'][0])){
94       $this->postfixMyhostname .= ".".$this->attrs['postfixMyDomain'][0];
95     }
96   
98     /* Get postfix my domains */
99     $this->postfixMyDestinations = array(); 
100     if(isset($this->attrs['postfixMyDestinations'][0])){
101       unset($this->attrs['postfixMyDestinations']['count']);
102       foreach($this->attrs['postfixMyDestinations'] as $str){
103         $this->postfixMyDestinations[base64_encode($str)] = $str;
104       }
105     }
108     /* Get transport tables */
109     $tmp = array();
110     $this->postfixTransportTable = array();
111     if(isset($this->attrs['postfixTransportTable'])){
112       $tmp = array();
113       unset($this->attrs['postfixTransportTable']['count']);
114       foreach($this->attrs['postfixTransportTable'] as $entry){
116         //0: offshore.vip.ms-europa.lhsystems.com smtp:172.28.0.2
118         $Number   = preg_replace('/^([^:]+):.*$/', '\\1', $entry);
119         $Rest     = trim(preg_replace("/^[0-9]*:/","",$entry));
121         $Protocol_Destination = preg_replace("/^.*\ /","",$Rest);
122         $Source               = preg_replace("/\ .*$/","",$Rest);
124         $Protocol     = preg_replace ('/^([^:]+):.*$/', '\\1' ,trim($Protocol_Destination));
125         $Destination  = preg_replace ('/^[^:]+:(.*)$/', '\\1'    ,trim($Protocol_Destination));
127         $Destination  = preg_replace ("/[\[\]]/","",$Destination);
129         $tmp[$Number]['src'] = $Source;
130         $tmp[$Number]['dst'] = $Destination;
131         $tmp[$Number]['prt'] = $Protocol;
132       }
133       ksort($tmp);
134       foreach($tmp as $entry){
135         $this->postfixTransportTable[] = $entry;
136       }
137     }
138    
140     /* Get sender restrictions */
141     $tmp = array();
142     $this->postfixSenderRestrictions = array();
143     if(isset($this->attrs['postfixSenderRestrictions'])){
144       unset($this->attrs['postfixSenderRestrictions']['count']);
145       foreach($this->attrs['postfixSenderRestrictions'] as $entry){
146         $nr  = preg_replace("/:.*$/","",$entry);
147         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
148         $src = preg_replace("/ .*$/","",$rest);
149         $rest= preg_replace("/^[^ ]+ /","",$rest);
150         $dst = preg_replace("/^.* /","",$rest);
151         $prt = preg_replace("/ .*$/","",$rest);
152  
153         $tmp[$nr]['src'] = $src;
154         $tmp[$nr]['dst'] = $dst;
155         $tmp[$nr]['filter'] = $prt;
156       }
157       ksort($tmp);
158       foreach($tmp as $entry){
159         $this->postfixSenderRestrictions[] = $entry;
160       }
161     }
163  
164     /* Get sender restrictions */
165     $tmp = array();
166     $this->postfixRecipientRestrictions = array();
167     if(isset($this->attrs['postfixRecipientRestrictions'])){
168       unset($this->attrs['postfixRecipientRestrictions']['count']);
169       foreach($this->attrs['postfixRecipientRestrictions'] as $entry){
170         $nr  = preg_replace("/:.*$/","",$entry);
171         $rest= trim(preg_replace("/^[^:]+:/","",$entry));
172         $src = preg_replace("/ .*$/","",$rest);
173         $rest= preg_replace("/^[^ ]+ /","",$rest);
174         $dst = preg_replace("/^.* /","",$rest);
175         $prt = preg_replace("/ .*$/","",$rest);
176  
177         $tmp[$nr]['src'] = $src;
178         $tmp[$nr]['dst'] = $dst;
179         $tmp[$nr]['filter'] = $prt;
180       }
181       ksort($tmp);
182       foreach($tmp as $entry){
183         $this->postfixRecipientRestrictions[] = $entry;
184       }
185     }
187   }
189   function execute()
190   { 
191     $smarty   = get_smarty();
192     $delAr    = array( "TranslationDel_"=>"TranslationDel",
193                     "SenderRestrictDel_"=>"SenderRestrictDel",
194                     "RecipientRestrictDel_"=>"RecipientRestrictDel");
195  
196     $once     = true;
197     $s_action = "";
198     $s_entry  = "";
199   
200     /* Check posts for some intruductions */
201     foreach($_POST as $name => $value){
202       foreach($delAr as $preg => $type){
203         if((preg_match("/^".$preg."/",$name)) && ($once)){
204           $once = false;
205           $s_action = $type; 
206           $s_entry = preg_replace("/^".$preg."/","",$name);
207           $s_entry = preg_replace("/_[xy]$/","",$s_entry);
208         }
209       }
210   
212       if(preg_match("/^TranslationUp_/",$name) && $once){
213         $once = false;
214         $key = preg_replace("/^TranslationUp_/","",$name);
215         $key = preg_replace("/_[xy]$/","",$key);
216         $this->postfixTransportTable = $this->ArrayUp($key,$this->postfixTransportTable) ;
217       }
218       if(preg_match("/^TranslationDown_/",$name) && $once){
219         $once = false;
220         $key = preg_replace("/^TranslationDown_/","",$name);
221         $key = preg_replace("/_[xy]$/","",$key);
222         $this->postfixTransportTable = $this->ArrayDown($key,$this->postfixTransportTable) ;
223       }
224       if(preg_match("/^SenderRestrictUp_/",$name) && $once){
225         $once = false;
226         $key = preg_replace("/^SenderRestrictUp_/","",$name);
227         $key = preg_replace("/_[xy]$/","",$key);
228         $this->postfixSenderRestrictions = $this->ArrayUp($key,$this->postfixSenderRestrictions) ;
229       }
230       if(preg_match("/^SenderRestrictDown_/",$name) && $once){
231         $once = false;
232         $key = preg_replace("/^SenderRestrictDown_/","",$name);
233         $key = preg_replace("/_[xy]$/","",$key);
234         $this->postfixSenderRestrictions = $this->ArrayDown($key,$this->postfixSenderRestrictions) ;
235       }
236       if(preg_match("/^RecipientRestrictUp_/",$name) && $once){
237         $once = false;
238         $key = preg_replace("/^RecipientRestrictUp_/","",$name);
239         $key = preg_replace("/_[xy]$/","",$key);
240         $this->postfixRecipientRestrictions = $this->ArrayUp($key,$this->postfixRecipientRestrictions) ;
241       }
242       if(preg_match("/^RecipientRestrictDown_/",$name) && $once){
243         $once = false;
244         $key = preg_replace("/^RecipientRestrictDown_/","",$name);
245         $key = preg_replace("/_[xy]$/","",$key);
246         $this->postfixRecipientRestrictions = $this->ArrayDown($key,$this->postfixRecipientRestrictions) ;
247       }
248     }
251     /* Add delete my network entry */
252     if((isset($_POST['AddpostfixMyNetworks'])) && (!empty($_POST['NewString_postfixMyNetworks']))){
253       $str = $_POST['NewString_postfixMyNetworks'];
254       $this->postfixMyNetworks[base64_encode($str)] = $str;
255     }
257     if((isset($_POST['DelpostfixMyNetworks'])) && isset($_POST['Select_postfixMyNetworks']) &&(count($_POST['Select_postfixMyNetworks']))){
258       foreach($_POST['Select_postfixMyNetworks'] as $str ){
259         unset($this->postfixMyNetworks[$str]);
260       }
261     }
264     /* Add delete my domain entry */
265     if((isset($_POST['AddpostfixMyDestinations'])) && (!empty($_POST['NewString_postfixMyDestinations']))){
266       $str = $_POST['NewString_postfixMyDestinations'];
267       $this->postfixMyDestinations[base64_encode($str)] = $str;
268     }
270     if((isset($_POST['DelpostfixMyDestinations'])) && isset($_POST['Select_postfixMyDestinations']) &&(count($_POST['Select_postfixMyDestinations']))){
271       foreach($_POST['Select_postfixMyDestinations'] as $str ){
272         unset($this->postfixMyDestinations[$str]);
273       }
274     }
277     /* Add sender restriction */
278     if(($s_action == "SenderRestrictDel") && (isset($this->postfixSenderRestrictions[$s_entry]))){
279       unset($this->postfixSenderRestrictions[$s_entry]);
280     }
282     if(isset($_POST['AddpostfixSenderRestrictions'])){
283       $src      = $_POST['Source_postfixSenderRestrictions'];
284       $dst      = $_POST['Destination_postfixSenderRestrictions'];
285       $Filter   = $_POST['SenderRestrictionFilter'];
286       $tmp['src']     = $src;
287       $tmp['dst']     = $dst;
288       $tmp['filter']  = $Filter;
289       $this->postfixSenderRestrictions[] = $tmp;
290     }
293     /* Add sender restriction */
294     if(($s_action == "RecipientRestrictDel") && (isset($this->postfixRecipientRestrictions[$s_entry]))){
295       unset($this->postfixRecipientRestrictions[$s_entry]);
296     }
298     if(isset($_POST['AddpostfixRecipientRestrictions'])){
299       $src      = $_POST['Source_postfixRecipientRestrictions'];
300       $dst      = $_POST['Destination_postfixRecipientRestrictions'];
301       $Filter   = $_POST['RecipientRestrictionFilter'];
302       $tmp['src']     = $src;
303       $tmp['dst']     = $dst;
304       $tmp['filter']  = $Filter;
305       $this->postfixRecipientRestrictions[] = $tmp;
306     }
309     /* Handle transports */
310     if(($s_action == "TranslationDel") && (isset($this->postfixTransportTable[$s_entry]))){
311       unset($this->postfixTransportTable[$s_entry]);
312     }
313     
314     if(isset($_POST['AddpostfixTransportTable'])){
315       $src = trim($_POST['Source_postfixTransportTable']);  
316       $dst = trim($_POST['Destination_postfixTransportTable']);    
317       $prt = trim($_POST['TransportProtocol']);
319       if((!empty($src)) && (!empty($dst))){
320         if(preg_match("/:/",$dst)){
321           $tmp = split("\:",$dst);
322           $port = trim($tmp[1]);
323           $ip   = trim($tmp[0]);
324     
325           if((is_ip($ip)) && (is_numeric($port))){
326             $dst = "[".$ip."]:".$port;
327           }
328         }
329         if(is_ip($dst)){
330           $dst = "[".$dst."]";
331         }
332         $tmp2 ['src'] = $src;
333         $tmp2 ['dst'] = $dst;
334         $tmp2 ['prt'] = $prt;
336         $this->postfixTransportTable[] = $tmp2;  
337       } 
338     }
341     /* Set attributes */
342     foreach($this->attributes as $attr){
343       $smarty->assign($attr,$this->$attr);
344     }
347     /* Create divList for translation tables */
348     $divTranslation = new divSelectBox("TransportProtocols");
349     $divTranslation->SetHeight(90);
350     foreach($this->postfixTransportTable as $key => $entry){
351       $img = "";
353       if($key != 0){
354         $img.= "<input type='image' src='images/sort_up.png' name='TranslationUp_".$key."' class='center'>&nbsp;";      
355       }else{
356         $img.= "<img src='images/empty.png' style='width:10px;'>";
357       }
358       if(($key+1) < count($this->postfixTransportTable)){
359         $img.= "<input type='image' src='images/sort_down.png' name='TranslationDown_".$key."' class='center'>&nbsp;";      
360       }else{
361         $img.= "<img src='images/empty.png' style='width:10px;'>";
362       }
364       $img.= "<input type='image' src='images/edittrash.png' name='TranslationDel_".$key."' class='center'>&nbsp;";      
365       $field1 = array("string"=> $entry['src']);
366       $field2 = array("string"=> $entry['dst']);
367       $field3 = array("string"=> $entry['prt'],"attach"=>"style='width:120px;'");
368       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
369       $divTranslation->AddEntry(array($field1,$field2,$field3,$field4,));
370     }
371     $smarty->assign("Div_postfixTransportTable" ,$divTranslation->DrawList());
374     /* Create divList for sender restrictions */
375     $DivSenderRestrict = new divSelectBox("postfixSenderRestrictions");
376     $DivSenderRestrict->SetHeight(90);
377     foreach($this->postfixSenderRestrictions as $key => $entry){
378       $img ="";
380       if($key != 0){
381         $img.= "<input type='image' src='images/sort_up.png' name='SenderRestrictUp_".$key."' class='center'>&nbsp;";      
382       }else{
383         $img.= "<img src='images/empty.png' style='width:10px;'>";
384       }
385       if(($key+1) < count($this->postfixSenderRestrictions)){
386         $img.= "<input type='image' src='images/sort_down.png' name='SenderRestrictDown_".$key."' class='center'>&nbsp;";      
387       }else{
388         $img.= "<img src='images/empty.png' style='width:10px;'>";
389       }
391       $img.= "<input type='image' src='images/edittrash.png' name='SenderRestrictDel_".$key."' class='center'>&nbsp;";     
392  
393       $field1 = array("string"=> $entry['src']);
394       $field2 = array("string"=> $entry['dst']);
395       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
396       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
397       $DivSenderRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
398     }
399     $smarty->assign("Div_postfixSenderRestrictions" ,$DivSenderRestrict->DrawList());
402     /* Create divList for translation tables */
403     $DivRecipientRestrict = new divSelectBox("postfixRecipientRestrictions");
404     $DivRecipientRestrict->SetHeight(90);
406     foreach($this->postfixRecipientRestrictions as $key => $entry){
407       $img = "";
408       if($key != 0){
409         $img.= "<input type='image' src='images/sort_up.png' name='RecipientRestrictUp_".$key."' class='center'>&nbsp;";      
410       }else{
411         $img.= "<img src='images/empty.png' style='width:10px;'>";
412       }
413       if(($key+1) < count($this->postfixRecipientRestrictions)){
414         $img.= "<input type='image' src='images/sort_down.png' name='RecipientRestrictDown_".$key."' class='center'>&nbsp;";      
415       }else{
416         $img.= "<img src='images/empty.png' style='width:10px;'>";
417       }
418       $img.= "<input type='image' src='images/edittrash.png' name='RecipientRestrictDel_".$key."' class='center'>&nbsp;";      
419       $field1 = array("string"=> $entry['src']);
420       $field2 = array("string"=> $entry['dst']);
421       $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
422       $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
423       $DivRecipientRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
424     }
425     $smarty->assign("Div_postfixRecipientRestrictions" ,$DivRecipientRestrict->DrawList());
427     
428     /* set new status */
429     if(isset($_POST['ExecAction'])){
430       if(isset($this->Actions[$_POST['action']])){
431         $this->setStatus($_POST['action']);
432       }
433     }
436     $smarty->assign("is_new",                       $this->dn);
437     $smarty->assign("is_acc",                       $this->initially_was_account);
438     $smarty->assign("TransportProtocols",           $this->TransportProtocols);
439     $smarty->assign("Actions",                      $this->Actions);
440     $smarty->assign("RestrictionFilters",           $this->RestrictionFilters);
441     $smarty->assign("postfixTransportTable" ,       $this->getTransports());
442     $smarty->assign("postfixSenderRestrictions" ,   $this->getSenderRestrictions());
443     $smarty->assign("postfixRecipientRestrictions" ,$this->getRecipientRestrictions());
445     return($smarty->fetch(get_template_path("goMailServer.tpl",TRUE,dirname(__FILE__))));
446   }
448  
449   /* return transports formated for select box */ 
450   function getTransports()
451   {
452     $ret = array();
453     foreach($this->postfixTransportTable as $key => $vals){
454       $ret[$key] = $vals['src']." -> ".$vals['prt'].":".$vals['dst'];
455     }
456     return($ret);
457   }
460   /* return sender restriction formated for select box */ 
461   function getSenderRestrictions()
462   {
463     $ret = array();
464     foreach($this->postfixSenderRestrictions as $key => $vals){
465       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
466     }
467     return($ret);
468   }
471   /* return recipient restriction formated for select box */ 
472   function getRecipientRestrictions()
473   {
474     $ret = array();
475     foreach($this->postfixRecipientRestrictions as $key => $vals){
476       $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
477     }
478     return($ret);
479   }
482   /* Return list entry */
483   function getListEntry()
484   {
485     $this->updateStatusState();
486     $flag = $this->StatusFlag;
487     $fields['Status']     = $this->$flag;
488     $fields['Message']    = _("Postfix");
489     $fields['AllowStart'] = true;
490     $fields['AllowStop']  = true;
491     $fields['AllowRestart'] = true;
492     $fields['AllowRemove']= true;
493     $fields['AllowEdit']  = true;
494     return($fields);
495   }
498   function remove_from_parent()
499   {
500     plugin::remove_from_parent();
502     /* Remove status flag, it is not a memeber of 
503         this->attributes, so ensure that it is deleted too */
504     if(!empty($this->StatusFlag)){
505       $this->attrs[$this->StatusFlag] = array();
506     }
508     /* Check if this is a new entry ... add/modify */
509     $ldap = $this->config->get_ldap_link();
510     $ldap->cat($this->dn,array("objectClass"));
511     if($ldap->count()){
512       $ldap->cd($this->dn);
513       $ldap->modify($this->attrs);
514     }else{
515       $ldap->cd($this->dn);
516       $ldap->add($this->attrs);
517     }
518     show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/mail with dn '%s' failed."),$this->dn));
519     $this->handle_post_events("remove");
520   }
523   function save()
524   {
525     $this->postfixMyDomain   = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
526     $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
528     plugin::save();
530     /* Fix transport table*/
531     $i = 0 ; 
532     $this->attrs['postfixTransportTable'] = array();
533     foreach($this->postfixTransportTable as $key => $entry){
534       $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
535       $i ++;
536     }
539     /* Fix sender restrictions */
540     $i = 0;
541     $this->attrs['postfixSenderRestrictions'] =array();
542     foreach($this->postfixSenderRestrictions as $key => $entry){
543       $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
544       $i ++;  
545     }
546   
547   
548     /* Fix recipient restrictions */
549     $i = 0;
550     $this->attrs['postfixRecipientRestrictions'] =array();
551     foreach($this->postfixRecipientRestrictions as $key => $entry){
552       $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst']; 
553       $i ++;  
554     }
557     /* Fix mydomains */
558     $this->attrs['postfixMyDestinations']  = array();
559     foreach($this->postfixMyDestinations as $entry){
560       $this->attrs['postfixMyDestinations'][] =$entry;
561     }
564     /* Fix mydomains */
565     if(count($this->postfixMyNetworks)){
566       $this->attrs['postfixMyNetworks']  = "";
567       foreach($this->postfixMyNetworks as $entry){
568         $this->attrs['postfixMyNetworks'] .=$entry.",";
569       }
570       $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
571     }else{
572       $this->attrs['postfixMyNetworks']  = array();
573     }
575  
576     /* Check if this is a new entry ... add/modify */
577     $ldap = $this->config->get_ldap_link();
578     $ldap->cat($this->dn,array("objectClass"));
579     if($ldap->count()){
580       $ldap->cd($this->dn);
581       $ldap->modify($this->attrs);
582     }else{
583       $ldap->cd($this->dn);
584       $ldap->add($this->attrs);
585     }
586     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/mail with dn '%s' failed."),$this->dn));
587     if($this->initially_was_account){
588       $this->handle_post_events("modify");
589     }else{
590       $this->handle_post_events("add");
591     }
593   }
596   /* Directly save new status flag */
597   function setStatus($value)
598   {
599     if($value == "none") return;
600     if(!$this->initially_was_account) return;
601     $ldap = $this->config->get_ldap_link();
602     $ldap->cd($this->dn);
603     $ldap->cat($this->dn,array("objectClass"));
604     if($ldap->count()){
606       $tmp = $ldap->fetch();
607       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
608         $attrs['objectClass'][] = $tmp['objectClass'][$i];
609       }
610       $flag = $this->StatusFlag;
611       $attrs[$flag] = $value;
612       $this->$flag = $value;
613       $ldap->modify($attrs);
614       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/mail with dn '%s' failed."),$this->dn));
615       $this->action_hook();
616     }
617   }
620   function check()
621   { 
622     $message =plugin::check();
623   
624     if(!is_numeric($this->postfixHeaderSizeLimit)){
625       $message[] = _("Please specify a numeric value for header size limit.");
626     }
628     if(!is_numeric($this->postfixMailboxSizeLimit)){
629       $message[] = _("Please specify a numeric value for mailbox size limit.");
630     }
632     if(!is_numeric($this->postfixMessageSizeLimit)){
633       $message[] = _("Please specify a numeric value for message size limit.");
634     }
636     return $message;
637   }
640   /* Combine new array */
641   function combineArrays($ar0,$ar1,$ar2)
642   {
643     $ret = array();
644     if(is_array($ar0))
645     foreach($ar0 as $ar => $a){
646         $ret[]=$a;
647     }
648     if(is_array($ar1))
649     foreach($ar1 as $ar => $a){
650         $ret[]=$a;
651     }
652     if(is_array($ar2))
653     foreach($ar2 as $ar => $a){
654         $ret[]=$a;
655     }
656     return($ret);
657   }
660   function getpos($atr,$attrs)
661   {
662     $i = 0;
663     foreach($attrs as $attr => $name)    {
664       $i++;
665       if($attr == $atr){
666         return($i);
667       }
668     }
670     return(-1);
671   }
674   /* TRansports the geiven Arraykey one position up*/
675   function ArrayUp($atr,$attrs)
676   {
677     $ret = $attrs;
678     $pos = $this->getpos($atr,$attrs) ;
679     $cn = count($attrs);
680     if(!(($pos == -1)||($pos == 1))){
681       $before = array_slice($attrs,0,($pos-2));
682       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
683       $unten  = array_slice($attrs,$pos);
684       $ret = array();
685       $ret = $this->combineArrays($before,$mitte,$unten);
686     }
687     return($ret);
688   }
691   /* TRansports the geiven Arraykey one position up*/
692   function ArrayDown($atr,$attrs)
693   {
694     $ret = $attrs;
695     $pos = $this->getpos($atr,$attrs) ;
696     $cn = count($attrs);
697     if(!(($pos == -1)||($pos == $cn))){
698       $before = array_slice($attrs,0,($pos-1));
699       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
700       $unten  = array_slice($attrs,($pos+1));
701       $ret = array();
702       $ret = $this->combineArrays($before,$mitte,$unten);
703     }
704     return($ret);
705   }
707   
708   function action_hook($add_attrs= array())
709   {
710     /* Find postcreate entries for this class */
711     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
712     if ($command == "" && isset($this->config->data['TABS'])){
713       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
714     }
715     if ($command != ""){
716       /* Walk through attribute list */
717       foreach ($this->attributes as $attr){
718         if (!is_array($this->$attr)){
719           $command= preg_replace("/%$attr/", $this->$attr, $command);
720         }
721       }
722       $command= preg_replace("/%dn/", $this->dn, $command);
723       /* Additional attributes */
724       foreach ($add_attrs as $name => $value){
725         $command= preg_replace("/%$name/", $value, $command);
726       }
728       /* If there are still some %.. in our command, try to fill these with some other class vars */
729       if(preg_match("/%/",$command)){
730         $attrs = get_object_vars($this);
731         foreach($attrs as $name => $value){
732           if(!is_string($value)) continue;
733           $command= preg_replace("/%$name/", $value, $command);
734         }
735       }
737       if (check_command($command)){
738         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
739             $command, "Execute");
741         exec($command);
742       } else {
743         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
744         print_red ($message);
745       }
746     }
747   }
750   /* Get updates for status flag */
751   function updateStatusState()
752   {
753     if(empty($this->StatusFlag)) return;
755     $attrs = array();
756     $flag = $this->StatusFlag;
757     $ldap = $this->config->get_ldap_link();
758     $ldap->cd($this->cn);
759     $ldap->cat($this->dn,array($flag));
760     if($ldap->count()){
761       $attrs = $ldap->fetch();
762     }
763     if(isset($attrs[$flag][0])){
764       $this->$flag = $attrs[$flag][0];
765     }
766   }
768   function save_object()
769   {
770     plugin::save_object();  
771   }
775   /* Return plugin informations for acl handling */
776   function plInfo()
777   {
778     return (array(
779           "plShortName"   => _("Mail"),
780           "plDescription" => _("Mail service"),
781           "plSelfModify"  => FALSE,
782           "plDepends"     => array(),
783           "plPriority"    => 0,
784           "plSection"     => array("administration"),
785           "plCategory"    => array("server"),
787           "plProvidedAcls"=> array(
788             "description"                 => _("Description"), 
789             "postfixHeaderSizeLimit"      => _("Header size limit"), 
790             "postfixMailboxSizeLimit"     => _("Max mailbox size"), 
791             "postfixMessageSizeLimit"     => _("Max message size"), 
792             "postfixMyDestinations"       => _("Domains to accept mail for"), 
793             "postfixMyNetworks"           => _("Local networks"), 
794             "postfixRelayhost"            => _("Relay host"), 
795             "postfixTransportTable"       => _("Transport table"), 
796             "postfixSenderRestrictions"   => _("Restrictions for sender"), 
797             "postfixRecipientRestrictions"=> _("Restrictions for recipient"))
798             ));
799   }
801 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
802 ?>