1 <?php
3 class goMailServer extends plugin{
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 }
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){
115 $nr = preg_replace("/:.*$/","",$entry);
116 $rest= trim(preg_replace("/^[^:]+:/","",$entry));
117 $src = preg_replace("/ .*$/","",$rest);
118 $rest= preg_replace("/^[^ ]+ /","",$rest);
119 $dst = preg_replace("/^.*:/","",$rest);
120 $prt = preg_replace("/:.*$/","",$rest);
122 $tmp[$nr]['src'] = $src;
123 $tmp[$nr]['dst'] = $dst;
124 $tmp[$nr]['prt'] = $prt;
126 }
127 ksort($tmp);
128 foreach($tmp as $entry){
129 $this->postfixTransportTable[] = $entry;
130 }
131 }
134 /* Get sender restrictions */
135 $tmp = array();
136 $this->postfixSenderRestrictions = array();
137 if(isset($this->attrs['postfixSenderRestrictions'])){
138 unset($this->attrs['postfixSenderRestrictions']['count']);
139 foreach($this->attrs['postfixSenderRestrictions'] as $entry){
140 $nr = preg_replace("/:.*$/","",$entry);
141 $rest= trim(preg_replace("/^[^:]+:/","",$entry));
142 $src = preg_replace("/ .*$/","",$rest);
143 $rest= preg_replace("/^[^ ]+ /","",$rest);
144 $dst = preg_replace("/^.* /","",$rest);
145 $prt = preg_replace("/ .*$/","",$rest);
147 $tmp[$nr]['src'] = $src;
148 $tmp[$nr]['dst'] = $dst;
149 $tmp[$nr]['filter'] = $prt;
150 }
151 ksort($tmp);
152 foreach($tmp as $entry){
153 $this->postfixSenderRestrictions[] = $entry;
154 }
155 }
158 /* Get sender restrictions */
159 $tmp = array();
160 $this->postfixRecipientRestrictions = array();
161 if(isset($this->attrs['postfixRecipientRestrictions'])){
162 unset($this->attrs['postfixRecipientRestrictions']['count']);
163 foreach($this->attrs['postfixRecipientRestrictions'] as $entry){
164 $nr = preg_replace("/:.*$/","",$entry);
165 $rest= trim(preg_replace("/^[^:]+:/","",$entry));
166 $src = preg_replace("/ .*$/","",$rest);
167 $rest= preg_replace("/^[^ ]+ /","",$rest);
168 $dst = preg_replace("/^.* /","",$rest);
169 $prt = preg_replace("/ .*$/","",$rest);
171 $tmp[$nr]['src'] = $src;
172 $tmp[$nr]['dst'] = $dst;
173 $tmp[$nr]['filter'] = $prt;
174 }
175 ksort($tmp);
176 foreach($tmp as $entry){
177 $this->postfixRecipientRestrictions[] = $entry;
178 }
179 }
181 }
183 function execute()
184 {
185 $smarty = get_smarty();
186 $delAr = array( "TranslationDel_"=>"TranslationDel",
187 "SenderRestrictDel_"=>"SenderRestrictDel",
188 "RecipientRestrictDel_"=>"RecipientRestrictDel");
190 $once = true;
191 $s_action = "";
192 $s_entry = "";
194 /* Check posts for some intruductions */
195 foreach($_POST as $name => $value){
196 foreach($delAr as $preg => $type){
197 if((preg_match("/^".$preg."/",$name)) && ($once)){
198 $once = false;
199 $s_action = $type;
200 $s_entry = preg_replace("/^".$preg."/","",$name);
201 $s_entry = preg_replace("/_[xy]$/","",$s_entry);
202 }
203 }
206 if(preg_match("/^TranslationUp_/",$name) && $once){
207 $once = false;
208 $key = preg_replace("/^TranslationUp_/","",$name);
209 $key = preg_replace("/_[xy]$/","",$key);
210 $this->postfixTransportTable = $this->ArrayUp($key,$this->postfixTransportTable) ;
211 }
212 if(preg_match("/^TranslationDown_/",$name) && $once){
213 $once = false;
214 $key = preg_replace("/^TranslationDown_/","",$name);
215 $key = preg_replace("/_[xy]$/","",$key);
216 $this->postfixTransportTable = $this->ArrayDown($key,$this->postfixTransportTable) ;
217 }
218 if(preg_match("/^SenderRestrictUp_/",$name) && $once){
219 $once = false;
220 $key = preg_replace("/^SenderRestrictUp_/","",$name);
221 $key = preg_replace("/_[xy]$/","",$key);
222 $this->postfixSenderRestrictions = $this->ArrayUp($key,$this->postfixSenderRestrictions) ;
223 }
224 if(preg_match("/^SenderRestrictDown_/",$name) && $once){
225 $once = false;
226 $key = preg_replace("/^SenderRestrictDown_/","",$name);
227 $key = preg_replace("/_[xy]$/","",$key);
228 $this->postfixSenderRestrictions = $this->ArrayDown($key,$this->postfixSenderRestrictions) ;
229 }
230 if(preg_match("/^RecipientRestrictUp_/",$name) && $once){
231 $once = false;
232 $key = preg_replace("/^RecipientRestrictUp_/","",$name);
233 $key = preg_replace("/_[xy]$/","",$key);
234 $this->postfixRecipientRestrictions = $this->ArrayUp($key,$this->postfixRecipientRestrictions) ;
235 }
236 if(preg_match("/^RecipientRestrictDown_/",$name) && $once){
237 $once = false;
238 $key = preg_replace("/^RecipientRestrictDown_/","",$name);
239 $key = preg_replace("/_[xy]$/","",$key);
240 $this->postfixRecipientRestrictions = $this->ArrayDown($key,$this->postfixRecipientRestrictions) ;
241 }
242 }
245 /* Add delete my network entry */
246 if((isset($_POST['AddpostfixMyNetworks'])) && (!empty($_POST['NewString_postfixMyNetworks']))){
247 $str = $_POST['NewString_postfixMyNetworks'];
248 $this->postfixMyNetworks[base64_encode($str)] = $str;
249 }
251 if((isset($_POST['DelpostfixMyNetworks'])) && isset($_POST['Select_postfixMyNetworks']) &&(count($_POST['Select_postfixMyNetworks']))){
252 foreach($_POST['Select_postfixMyNetworks'] as $str ){
253 unset($this->postfixMyNetworks[$str]);
254 }
255 }
258 /* Add delete my domain entry */
259 if((isset($_POST['AddpostfixMyDestinations'])) && (!empty($_POST['NewString_postfixMyDestinations']))){
260 $str = $_POST['NewString_postfixMyDestinations'];
261 $this->postfixMyDestinations[base64_encode($str)] = $str;
262 }
264 if((isset($_POST['DelpostfixMyDestinations'])) && isset($_POST['Select_postfixMyDestinations']) &&(count($_POST['Select_postfixMyDestinations']))){
265 foreach($_POST['Select_postfixMyDestinations'] as $str ){
266 unset($this->postfixMyDestinations[$str]);
267 }
268 }
271 /* Add sender restriction */
272 if(($s_action == "SenderRestrictDel") && (isset($this->postfixSenderRestrictions[$s_entry]))){
273 unset($this->postfixSenderRestrictions[$s_entry]);
274 }
276 if(isset($_POST['AddpostfixSenderRestrictions'])){
277 $src = $_POST['Source_postfixSenderRestrictions'];
278 $dst = $_POST['Destination_postfixSenderRestrictions'];
279 $Filter = $_POST['SenderRestrictionFilter'];
280 $tmp['src'] = $src;
281 $tmp['dst'] = $dst;
282 $tmp['filter'] = $Filter;
283 $this->postfixSenderRestrictions[] = $tmp;
284 }
287 /* Add sender restriction */
288 if(($s_action == "RecipientRestrictDel") && (isset($this->postfixRecipientRestrictions[$s_entry]))){
289 unset($this->postfixRecipientRestrictions[$s_entry]);
290 }
292 if(isset($_POST['AddpostfixRecipientRestrictions'])){
293 $src = $_POST['Source_postfixRecipientRestrictions'];
294 $dst = $_POST['Destination_postfixRecipientRestrictions'];
295 $Filter = $_POST['RecipientRestrictionFilter'];
296 $tmp['src'] = $src;
297 $tmp['dst'] = $dst;
298 $tmp['filter'] = $Filter;
299 $this->postfixRecipientRestrictions[] = $tmp;
300 }
303 /* Handle transports */
304 if(($s_action == "TranslationDel") && (isset($this->postfixTransportTable[$s_entry]))){
305 unset($this->postfixTransportTable[$s_entry]);
306 }
308 if(isset($_POST['AddpostfixTransportTable'])){
309 $src = trim($_POST['Source_postfixTransportTable']);
310 $dst = trim($_POST['Destination_postfixTransportTable']);
311 $prt = trim($_POST['TransportProtocol']);
313 if((!empty($src)) && (!empty($dst))){
314 if(preg_match("/:/",$dst)){
315 $tmp = split("\:",$dst);
316 $port = trim($tmp[1]);
317 $ip = trim($tmp[0]);
319 if((is_ip($ip)) && (is_numeric($port))){
320 $dst = "[".$ip."]:".$port;
321 }
322 }
323 if(is_ip($dst)){
324 $dst = "[".$dst."]";
325 }
326 $tmp2 ['src'] = $src;
327 $tmp2 ['dst'] = $dst;
328 $tmp2 ['prt'] = $prt;
330 $this->postfixTransportTable[] = $tmp2;
331 }
332 }
335 /* Set attributes */
336 foreach($this->attributes as $attr){
337 $smarty->assign($attr,$this->$attr);
338 }
341 /* Create divList for translation tables */
342 $divTranslation = new divSelectBox("TransportProtocols");
343 $divTranslation->SetHeight(90);
344 foreach($this->postfixTransportTable as $key => $entry){
345 $img = "";
347 if($key != 0){
348 $img.= "<input type='image' src='images/sort_up.png' name='TranslationUp_".$key."' class='center'> ";
349 }else{
350 $img.= "<img src='images/empty.png' style='width:10px;'>";
351 }
352 if(($key+1) < count($this->postfixTransportTable)){
353 $img.= "<input type='image' src='images/sort_down.png' name='TranslationDown_".$key."' class='center'> ";
354 }else{
355 $img.= "<img src='images/empty.png' style='width:10px;'>";
356 }
358 $img.= "<input type='image' src='images/edittrash.png' name='TranslationDel_".$key."' class='center'> ";
359 $field1 = array("string"=> $entry['src']);
360 $field2 = array("string"=> $entry['dst']);
361 $field3 = array("string"=> $entry['prt'],"attach"=>"style='width:120px;'");
362 $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
363 $divTranslation->AddEntry(array($field1,$field2,$field3,$field4,));
364 }
365 $smarty->assign("Div_postfixTransportTable" ,$divTranslation->DrawList());
368 /* Create divList for sender restrictions */
369 $DivSenderRestrict = new divSelectBox("postfixSenderRestrictions");
370 $DivSenderRestrict->SetHeight(90);
371 foreach($this->postfixSenderRestrictions as $key => $entry){
372 $img ="";
374 if($key != 0){
375 $img.= "<input type='image' src='images/sort_up.png' name='SenderRestrictUp_".$key."' class='center'> ";
376 }else{
377 $img.= "<img src='images/empty.png' style='width:10px;'>";
378 }
379 if(($key+1) < count($this->postfixSenderRestrictions)){
380 $img.= "<input type='image' src='images/sort_down.png' name='SenderRestrictDown_".$key."' class='center'> ";
381 }else{
382 $img.= "<img src='images/empty.png' style='width:10px;'>";
383 }
385 $img.= "<input type='image' src='images/edittrash.png' name='SenderRestrictDel_".$key."' class='center'> ";
387 $field1 = array("string"=> $entry['src']);
388 $field2 = array("string"=> $entry['dst']);
389 $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
390 $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
391 $DivSenderRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
392 }
393 $smarty->assign("Div_postfixSenderRestrictions" ,$DivSenderRestrict->DrawList());
396 /* Create divList for translation tables */
397 $DivRecipientRestrict = new divSelectBox("postfixRecipientRestrictions");
398 $DivRecipientRestrict->SetHeight(90);
400 foreach($this->postfixRecipientRestrictions as $key => $entry){
401 $img = "";
402 if($key != 0){
403 $img.= "<input type='image' src='images/sort_up.png' name='RecipientRestrictUp_".$key."' class='center'> ";
404 }else{
405 $img.= "<img src='images/empty.png' style='width:10px;'>";
406 }
407 if(($key+1) < count($this->postfixRecipientRestrictions)){
408 $img.= "<input type='image' src='images/sort_down.png' name='RecipientRestrictDown_".$key."' class='center'> ";
409 }else{
410 $img.= "<img src='images/empty.png' style='width:10px;'>";
411 }
412 $img.= "<input type='image' src='images/edittrash.png' name='RecipientRestrictDel_".$key."' class='center'> ";
413 $field1 = array("string"=> $entry['src']);
414 $field2 = array("string"=> $entry['dst']);
415 $field3 = array("string"=> $entry['filter'],"attach"=>"style='width:100px;'");
416 $field4 = array("string"=> $img, "attach"=>"style='border-right:0px;width:40px;'");
417 $DivRecipientRestrict->AddEntry(array($field1,$field2,$field3,$field4,));
418 }
419 $smarty->assign("Div_postfixRecipientRestrictions" ,$DivRecipientRestrict->DrawList());
422 /* set new status */
423 if(isset($_POST['ExecAction'])){
424 if(isset($this->Actions[$_POST['action']])){
425 $this->setStatus($_POST['action']);
426 }
427 }
430 $smarty->assign("is_new", $this->dn);
431 $smarty->assign("is_acc", $this->initially_was_account);
432 $smarty->assign("TransportProtocols", $this->TransportProtocols);
433 $smarty->assign("Actions", $this->Actions);
434 $smarty->assign("RestrictionFilters", $this->RestrictionFilters);
435 $smarty->assign("postfixTransportTable" , $this->getTransports());
436 $smarty->assign("postfixSenderRestrictions" , $this->getSenderRestrictions());
437 $smarty->assign("postfixRecipientRestrictions" ,$this->getRecipientRestrictions());
439 return($smarty->fetch(get_template_path("goMailServer.tpl",TRUE,dirname(__FILE__))));
440 }
443 /* return transports formated for select box */
444 function getTransports()
445 {
446 $ret = array();
447 foreach($this->postfixTransportTable as $key => $vals){
448 $ret[$key] = $vals['src']." -> ".$vals['prt'].":".$vals['dst'];
449 }
450 return($ret);
451 }
454 /* return sender restriction formated for select box */
455 function getSenderRestrictions()
456 {
457 $ret = array();
458 foreach($this->postfixSenderRestrictions as $key => $vals){
459 $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
460 }
461 return($ret);
462 }
465 /* return recipient restriction formated for select box */
466 function getRecipientRestrictions()
467 {
468 $ret = array();
469 foreach($this->postfixRecipientRestrictions as $key => $vals){
470 $ret[$key] = $vals['src']." ".$vals['filter']." ".$vals['dst'];
471 }
472 return($ret);
473 }
476 /* Return list entry */
477 function getListEntry()
478 {
479 $this->updateStatusState();
480 $flag = $this->StatusFlag;
481 $fields['Status'] = $this->$flag;
482 $fields['Message'] = _("Postfix");
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();
496 /* Remove status flag, it is not a memeber of
497 this->attributes, so ensure that it is deleted too */
498 if(!empty($this->StatusFlag)){
499 $this->attrs[$this->StatusFlag] = array();
500 }
502 /* Check if this is a new entry ... add/modify */
503 $ldap = $this->config->get_ldap_link();
504 $ldap->cat($this->dn,array("objectClass"));
505 if($ldap->count()){
506 $ldap->cd($this->dn);
507 $ldap->modify($this->attrs);
508 }else{
509 $ldap->cd($this->dn);
510 $ldap->add($this->attrs);
511 }
512 show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/mail with dn '%s' failed."),$this->dn));
513 $this->handle_post_events("remove");
514 }
517 function save()
518 {
519 $this->postfixMyDomain = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
520 $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
522 plugin::save();
524 /* Fix transport table*/
525 $i = 0 ;
526 $this->attrs['postfixTransportTable'] = array();
527 foreach($this->postfixTransportTable as $key => $entry){
528 $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
529 $i ++;
530 }
533 /* Fix sender restrictions */
534 $i = 0;
535 $this->attrs['postfixSenderRestrictions'] =array();
536 foreach($this->postfixSenderRestrictions as $key => $entry){
537 $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
538 $i ++;
539 }
542 /* Fix recipient restrictions */
543 $i = 0;
544 $this->attrs['postfixRecipientRestrictions'] =array();
545 foreach($this->postfixRecipientRestrictions as $key => $entry){
546 $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
547 $i ++;
548 }
551 /* Fix mydomains */
552 $this->attrs['postfixMyDestinations'] = array();
553 foreach($this->postfixMyDestinations as $entry){
554 $this->attrs['postfixMyDestinations'][] =$entry;
555 }
558 /* Fix mydomains */
559 if(count($this->postfixMyNetworks)){
560 $this->attrs['postfixMyNetworks'] = "";
561 foreach($this->postfixMyNetworks as $entry){
562 $this->attrs['postfixMyNetworks'] .=$entry.",";
563 }
564 $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
565 }else{
566 $this->attrs['postfixMyNetworks'] = array();
567 }
570 /* Check if this is a new entry ... add/modify */
571 $ldap = $this->config->get_ldap_link();
572 $ldap->cat($this->dn,array("objectClass"));
573 if($ldap->count()){
574 $ldap->cd($this->dn);
575 $ldap->modify($this->attrs);
576 }else{
577 $ldap->cd($this->dn);
578 $ldap->add($this->attrs);
579 }
580 show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/mail with dn '%s' failed."),$this->dn));
581 if($this->initially_was_account){
582 $this->handle_post_events("modify");
583 }else{
584 $this->handle_post_events("add");
585 }
587 }
590 /* Directly save new status flag */
591 function setStatus($value)
592 {
593 if($value == "none") return;
594 if(!$this->initially_was_account) return;
595 $ldap = $this->config->get_ldap_link();
596 $ldap->cd($this->dn);
597 $ldap->cat($this->dn,array("objectClass"));
598 if($ldap->count()){
600 $tmp = $ldap->fetch();
601 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
602 $attrs['objectClass'][] = $tmp['objectClass'][$i];
603 }
604 $flag = $this->StatusFlag;
605 $attrs[$flag] = $value;
606 $this->$flag = $value;
607 $ldap->modify($attrs);
608 show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/mail with dn '%s' failed."),$this->dn));
609 $this->action_hook();
610 }
611 }
614 function check()
615 {
616 $message =plugin::check();
618 if(!is_numeric($this->postfixHeaderSizeLimit)){
619 $message[] = _("Please specify a numeric value for header size limit.");
620 }
622 if(!is_numeric($this->postfixMailboxSizeLimit)){
623 $message[] = _("Please specify a numeric value for mailbox size limit.");
624 }
626 if(!is_numeric($this->postfixMessageSizeLimit)){
627 $message[] = _("Please specify a numeric value for message size limit.");
628 }
630 return $message;
631 }
634 /* Combine new array */
635 function combineArrays($ar0,$ar1,$ar2)
636 {
637 $ret = array();
638 if(is_array($ar0))
639 foreach($ar0 as $ar => $a){
640 $ret[]=$a;
641 }
642 if(is_array($ar1))
643 foreach($ar1 as $ar => $a){
644 $ret[]=$a;
645 }
646 if(is_array($ar2))
647 foreach($ar2 as $ar => $a){
648 $ret[]=$a;
649 }
650 return($ret);
651 }
654 function getpos($atr,$attrs)
655 {
656 $i = 0;
657 foreach($attrs as $attr => $name) {
658 $i++;
659 if($attr == $atr){
660 return($i);
661 }
662 }
664 return(-1);
665 }
668 /* TRansports the geiven Arraykey one position up*/
669 function ArrayUp($atr,$attrs)
670 {
671 $ret = $attrs;
672 $pos = $this->getpos($atr,$attrs) ;
673 $cn = count($attrs);
674 if(!(($pos == -1)||($pos == 1))){
675 $before = array_slice($attrs,0,($pos-2));
676 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
677 $unten = array_slice($attrs,$pos);
678 $ret = array();
679 $ret = $this->combineArrays($before,$mitte,$unten);
680 }
681 return($ret);
682 }
685 /* TRansports the geiven Arraykey one position up*/
686 function ArrayDown($atr,$attrs)
687 {
688 $ret = $attrs;
689 $pos = $this->getpos($atr,$attrs) ;
690 $cn = count($attrs);
691 if(!(($pos == -1)||($pos == $cn))){
692 $before = array_slice($attrs,0,($pos-1));
693 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
694 $unten = array_slice($attrs,($pos+1));
695 $ret = array();
696 $ret = $this->combineArrays($before,$mitte,$unten);
697 }
698 return($ret);
699 }
702 function action_hook($add_attrs= array())
703 {
704 /* Find postcreate entries for this class */
705 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
706 if ($command == "" && isset($this->config->data['TABS'])){
707 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
708 }
709 if ($command != ""){
710 /* Walk through attribute list */
711 foreach ($this->attributes as $attr){
712 if (!is_array($this->$attr)){
713 $command= preg_replace("/%$attr/", $this->$attr, $command);
714 }
715 }
716 $command= preg_replace("/%dn/", $this->dn, $command);
717 /* Additional attributes */
718 foreach ($add_attrs as $name => $value){
719 $command= preg_replace("/%$name/", $value, $command);
720 }
722 /* If there are still some %.. in our command, try to fill these with some other class vars */
723 if(preg_match("/%/",$command)){
724 $attrs = get_object_vars($this);
725 foreach($attrs as $name => $value){
726 if(!is_string($value)) continue;
727 $command= preg_replace("/%$name/", $value, $command);
728 }
729 }
731 if (check_command($command)){
732 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
733 $command, "Execute");
735 exec($command);
736 } else {
737 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
738 print_red ($message);
739 }
740 }
741 }
744 /* Get updates for status flag */
745 function updateStatusState()
746 {
747 if(empty($this->StatusFlag)) return;
749 $attrs = array();
750 $flag = $this->StatusFlag;
751 $ldap = $this->config->get_ldap_link();
752 $ldap->cd($this->cn);
753 $ldap->cat($this->dn,array($flag));
754 if($ldap->count()){
755 $attrs = $ldap->fetch();
756 }
757 if(isset($attrs[$flag][0])){
758 $this->$flag = $attrs[$flag][0];
759 }
760 }
762 function save_object()
763 {
764 plugin::save_object();
765 }
766 }
767 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
768 ?>