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 $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 }
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);
123 $tmp[$nr]['src'] = $src;
124 $tmp[$nr]['dst'] = $dst;
125 $tmp[$nr]['prt'] = $prt;
127 }
128 ksort($tmp);
129 foreach($tmp as $entry){
130 $this->postfixTransportTable[] = $entry;
131 }
132 }
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);
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 }
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);
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");
191 $once = true;
192 $s_action = "";
193 $s_entry = "";
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 }
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 }
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]);
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'> ";
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'> ";
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'> ";
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'> ";
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'> ";
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'> ";
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'> ";
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'> ";
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'> ";
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());
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 }
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 $this->handle_post_events("remove");
507 }
510 function save()
511 {
512 $this->postfixMyDomain = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
513 $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
515 plugin::save();
517 /* Fix transport table*/
518 $i = 0 ;
519 $this->attrs['postfixTransportTable'] = array();
520 foreach($this->postfixTransportTable as $key => $entry){
521 $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
522 $i ++;
523 }
526 /* Fix sender restrictions */
527 $i = 0;
528 $this->attrs['postfixSenderRestrictions'] =array();
529 foreach($this->postfixSenderRestrictions as $key => $entry){
530 $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
531 $i ++;
532 }
535 /* Fix recipient restrictions */
536 $i = 0;
537 $this->attrs['postfixRecipientRestrictions'] =array();
538 foreach($this->postfixRecipientRestrictions as $key => $entry){
539 $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
540 $i ++;
541 }
544 /* Fix mydomains */
545 $this->attrs['postfixMyDestinations'] = array();
546 foreach($this->postfixMyDestinations as $entry){
547 $this->attrs['postfixMyDestinations'][] =$entry;
548 }
551 /* Fix mydomains */
552 if(count($this->postfixMyNetworks)){
553 $this->attrs['postfixMyNetworks'] = "";
554 foreach($this->postfixMyNetworks as $entry){
555 $this->attrs['postfixMyNetworks'] .=$entry.",";
556 }
557 $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
558 }else{
559 $this->attrs['postfixMyNetworks'] = array();
560 }
563 /* Check if this is a new entry ... add/modify */
564 $ldap = $this->config->get_ldap_link();
565 $ldap->cat($this->dn,array("objectClass"));
566 if($ldap->count()){
567 $ldap->cd($this->dn);
568 $ldap->modify($this->attrs);
569 }else{
570 $ldap->cd($this->dn);
571 $ldap->add($this->attrs);
572 }
573 show_ldap_error($ldap->get_error());
574 if($this->initially_was_account){
575 $this->handle_post_events("modify");
576 }else{
577 $this->handle_post_events("add");
578 }
580 }
583 /* Directly save new status flag */
584 function setStatus($value)
585 {
586 if($value == "none") return;
587 if(!$this->initially_was_account) return;
588 $ldap = $this->config->get_ldap_link();
589 $ldap->cd($this->dn);
590 $ldap->cat($this->dn,array("objectClass"));
591 if($ldap->count()){
593 $tmp = $ldap->fetch();
594 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
595 $attrs['objectClass'][] = $tmp['objectClass'][$i];
596 }
597 $flag = $this->StatusFlag;
598 $attrs[$flag] = $value;
599 $this->$flag = $value;
600 $ldap->modify($attrs);
601 show_ldap_error($ldap->get_error());
602 $this->action_hook();
603 }
604 }
607 function check()
608 {
609 $message =plugin::check();
611 if(!is_numeric($this->postfixHeaderSizeLimit)){
612 $message[] = _("Please specify a numeric value for header size limit.");
613 }
615 if(!is_numeric($this->postfixMailboxSizeLimit)){
616 $message[] = _("Please specify a numeric value for mailbox size limit.");
617 }
619 if(!is_numeric($this->postfixMessageSizeLimit)){
620 $message[] = _("Please specify a numeric value for message size limit.");
621 }
623 return $message;
624 }
627 /* Combine new array */
628 function combineArrays($ar0,$ar1,$ar2)
629 {
630 $ret = array();
631 if(is_array($ar0))
632 foreach($ar0 as $ar => $a){
633 $ret[]=$a;
634 }
635 if(is_array($ar1))
636 foreach($ar1 as $ar => $a){
637 $ret[]=$a;
638 }
639 if(is_array($ar2))
640 foreach($ar2 as $ar => $a){
641 $ret[]=$a;
642 }
643 return($ret);
644 }
647 function getpos($atr,$attrs)
648 {
649 $i = 0;
650 foreach($attrs as $attr => $name) {
651 $i++;
652 if($attr == $atr){
653 return($i);
654 }
655 }
657 return(-1);
658 }
661 /* TRansports the geiven Arraykey one position up*/
662 function ArrayUp($atr,$attrs)
663 {
664 $ret = $attrs;
665 $pos = $this->getpos($atr,$attrs) ;
666 $cn = count($attrs);
667 if(!(($pos == -1)||($pos == 1))){
668 $before = array_slice($attrs,0,($pos-2));
669 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
670 $unten = array_slice($attrs,$pos);
671 $ret = array();
672 $ret = $this->combineArrays($before,$mitte,$unten);
673 }
674 return($ret);
675 }
678 /* TRansports the geiven Arraykey one position up*/
679 function ArrayDown($atr,$attrs)
680 {
681 $ret = $attrs;
682 $pos = $this->getpos($atr,$attrs) ;
683 $cn = count($attrs);
684 if(!(($pos == -1)||($pos == $cn))){
685 $before = array_slice($attrs,0,($pos-1));
686 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
687 $unten = array_slice($attrs,($pos+1));
688 $ret = array();
689 $ret = $this->combineArrays($before,$mitte,$unten);
690 }
691 return($ret);
692 }
695 function action_hook($add_attrs= array())
696 {
697 /* Find postcreate entries for this class */
698 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
699 if ($command == "" && isset($this->config->data['TABS'])){
700 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
701 }
702 if ($command != ""){
703 /* Walk through attribute list */
704 foreach ($this->attributes as $attr){
705 if (!is_array($this->$attr)){
706 $command= preg_replace("/%$attr/", $this->$attr, $command);
707 }
708 }
709 $command= preg_replace("/%dn/", $this->dn, $command);
710 /* Additional attributes */
711 foreach ($add_attrs as $name => $value){
712 $command= preg_replace("/%$name/", $value, $command);
713 }
714 if (check_command($command)){
715 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
716 $command, "Execute");
718 exec($command);
719 } else {
720 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
721 print_red ($message);
722 }
723 }
724 }
726 function save_object()
727 {
728 plugin::save_object();
729 }
730 }
731 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
732 ?>