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")." ["._("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 }
715 /* If there are still some %.. in our command, try to fill these with some other class vars */
716 if(preg_match("/%/",$command)){
717 $attrs = get_object_vars($this);
718 foreach($attrs as $name => $value){
719 if(!is_string($value)) continue;
720 $command= preg_replace("/%$name/", $value, $command);
721 }
722 }
724 if (check_command($command)){
725 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
726 $command, "Execute");
728 exec($command);
729 } else {
730 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
731 print_red ($message);
732 }
733 }
734 }
737 /* Get updates for status flag */
738 function updateStatusState()
739 {
740 if(empty($this->StatusFlag)) return;
742 $attrs = array();
743 $flag = $this->StatusFlag;
744 $ldap = $this->config->get_ldap_link();
745 $ldap->cd($this->cn);
746 $ldap->cat($this->dn,array($flag));
747 if($ldap->count()){
748 $attrs = $ldap->fetch();
749 }
750 if(isset($attrs[$flag][0])){
751 $this->$flag = $attrs[$flag][0];
752 }
753 }
755 function save_object()
756 {
757 plugin::save_object();
758 }
759 }
760 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
761 ?>