95fe64bd990561767d71dc2805a2bf23793e3fc7
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("goMailServerStatus","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 $flag = $this->StatusFlag;
480 $fields['Status'] = $this->$flag;
481 $fields['Message'] = _("Postfix")." ["._("configured for")." ".$this->postfixMyhostname."] ";
482 $fields['AllowStart'] = true;
483 $fields['AllowStop'] = true;
484 $fields['AllowRestart'] = true;
485 $fields['AllowRemove']= true;
486 $fields['AllowEdit'] = true;
487 return($fields);
488 }
491 function remove_from_parent()
492 {
493 plugin::remove_from_parent();
494 /* Check if this is a new entry ... add/modify */
495 $ldap = $this->config->get_ldap_link();
496 $ldap->cat($this->dn,array("objectClass"));
497 if($ldap->count()){
498 $ldap->cd($this->dn);
499 $ldap->modify($this->attrs);
500 }else{
501 $ldap->cd($this->dn);
502 $ldap->add($this->attrs);
503 }
504 show_ldap_error($ldap->get_error());
505 $this->handle_post_events("remove");
506 }
509 function save()
510 {
511 $this->postfixMyDomain = preg_replace("/^[^\.]+\./","",$this->postfixMyhostname);
512 $this->postfixMyhostname = preg_replace("/\..*$/","",$this->postfixMyhostname);
514 plugin::save();
516 /* Fix transport table*/
517 $i = 0 ;
518 $this->attrs['postfixTransportTable'] = array();
519 foreach($this->postfixTransportTable as $key => $entry){
520 $this->attrs['postfixTransportTable'][] = $i.": ".$entry['src']." ".$entry['prt'].":".$entry['dst'];
521 $i ++;
522 }
525 /* Fix sender restrictions */
526 $i = 0;
527 $this->attrs['postfixSenderRestrictions'] =array();
528 foreach($this->postfixSenderRestrictions as $key => $entry){
529 $this->attrs['postfixSenderRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
530 $i ++;
531 }
534 /* Fix recipient restrictions */
535 $i = 0;
536 $this->attrs['postfixRecipientRestrictions'] =array();
537 foreach($this->postfixRecipientRestrictions as $key => $entry){
538 $this->attrs['postfixRecipientRestrictions'][] = $i.": ".$entry['src']." ".$entry['filter']." ".$entry['dst'];
539 $i ++;
540 }
543 /* Fix mydomains */
544 $this->attrs['postfixMyDestinations'] = array();
545 foreach($this->postfixMyDestinations as $entry){
546 $this->attrs['postfixMyDestinations'][] =$entry;
547 }
550 /* Fix mydomains */
551 if(count($this->postfixMyNetworks)){
552 $this->attrs['postfixMyNetworks'] = "";
553 foreach($this->postfixMyNetworks as $entry){
554 $this->attrs['postfixMyNetworks'] .=$entry.",";
555 }
556 $this->attrs['postfixMyNetworks'] = preg_replace("/,$/","",$this->attrs['postfixMyNetworks']);
557 }else{
558 $this->attrs['postfixMyNetworks'] = array();
559 }
562 /* Check if this is a new entry ... add/modify */
563 $ldap = $this->config->get_ldap_link();
564 $ldap->cat($this->dn,array("objectClass"));
565 if($ldap->count()){
566 $ldap->cd($this->dn);
567 $ldap->modify($this->attrs);
568 }else{
569 $ldap->cd($this->dn);
570 $ldap->add($this->attrs);
571 }
572 show_ldap_error($ldap->get_error());
573 if($this->initially_was_account){
574 $this->handle_post_events("modify");
575 }else{
576 $this->handle_post_events("add");
577 }
579 }
582 /* Directly save new status flag */
583 function setStatus($value)
584 {
585 if($value == "none") return;
586 if(!$this->initially_was_account) return;
587 $ldap = $this->config->get_ldap_link();
588 $ldap->cd($this->dn);
589 $ldap->cat($this->dn,array("objectClass"));
590 if($ldap->count()){
592 $tmp = $ldap->fetch();
593 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
594 $attrs['objectClass'][] = $tmp['objectClass'][$i];
595 }
596 $flag = $this->StatusFlag;
597 $attrs[$flag] = $value;
598 $this->$flag = $value;
599 $ldap->modify($attrs);
600 show_ldap_error($ldap->get_error());
601 $this->action_hook();
602 }
603 }
606 function check()
607 {
608 $message =plugin::check();
610 if(!is_numeric($this->postfixHeaderSizeLimit)){
611 $message[] = _("Please specify a numeric value for header size limit.");
612 }
614 if(!is_numeric($this->postfixMailboxSizeLimit)){
615 $message[] = _("Please specify a numeric value for mailbox size limit.");
616 }
618 if(!is_numeric($this->postfixMessageSizeLimit)){
619 $message[] = _("Please specify a numeric value for message size limit.");
620 }
622 return $message;
623 }
626 /* Combine new array */
627 function combineArrays($ar0,$ar1,$ar2)
628 {
629 $ret = array();
630 if(is_array($ar0))
631 foreach($ar0 as $ar => $a){
632 $ret[]=$a;
633 }
634 if(is_array($ar1))
635 foreach($ar1 as $ar => $a){
636 $ret[]=$a;
637 }
638 if(is_array($ar2))
639 foreach($ar2 as $ar => $a){
640 $ret[]=$a;
641 }
642 return($ret);
643 }
646 function getpos($atr,$attrs)
647 {
648 $i = 0;
649 foreach($attrs as $attr => $name) {
650 $i++;
651 if($attr == $atr){
652 return($i);
653 }
654 }
656 return(-1);
657 }
660 /* TRansports the geiven Arraykey one position up*/
661 function ArrayUp($atr,$attrs)
662 {
663 $ret = $attrs;
664 $pos = $this->getpos($atr,$attrs) ;
665 $cn = count($attrs);
666 if(!(($pos == -1)||($pos == 1))){
667 $before = array_slice($attrs,0,($pos-2));
668 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
669 $unten = array_slice($attrs,$pos);
670 $ret = array();
671 $ret = $this->combineArrays($before,$mitte,$unten);
672 }
673 return($ret);
674 }
677 /* TRansports the geiven Arraykey one position up*/
678 function ArrayDown($atr,$attrs)
679 {
680 $ret = $attrs;
681 $pos = $this->getpos($atr,$attrs) ;
682 $cn = count($attrs);
683 if(!(($pos == -1)||($pos == $cn))){
684 $before = array_slice($attrs,0,($pos-1));
685 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
686 $unten = array_slice($attrs,($pos+1));
687 $ret = array();
688 $ret = $this->combineArrays($before,$mitte,$unten);
689 }
690 return($ret);
691 }
694 function action_hook($add_attrs= array())
695 {
696 /* Find postcreate entries for this class */
697 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
698 if ($command == "" && isset($this->config->data['TABS'])){
699 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
700 }
701 if ($command != ""){
702 /* Walk through attribute list */
703 foreach ($this->attributes as $attr){
704 if (!is_array($this->$attr)){
705 $command= preg_replace("/%$attr/", $this->$attr, $command);
706 }
707 }
708 $command= preg_replace("/%dn/", $this->dn, $command);
709 /* Additional attributes */
710 foreach ($add_attrs as $name => $value){
711 $command= preg_replace("/%$name/", $value, $command);
712 }
714 /* If there are still some %.. in our command, try to fill these with some other class vars */
715 if(preg_match("/%/",$command)){
716 $attrs = get_object_vars($this);
717 foreach($attrs as $name => $value){
718 if(!is_string($value)) continue;
719 $command= preg_replace("/%$name/", $value, $command);
720 }
721 }
723 if (check_command($command)){
724 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
725 $command, "Execute");
727 exec($command);
728 } else {
729 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
730 print_red ($message);
731 }
732 }
733 }
735 function save_object()
736 {
737 plugin::save_object();
738 }
739 }
740 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
741 ?>