Code

db458e56328c9519429e6bb1d8d63b715c60afda
[gosa.git] / plugins / admin / systems / class_termDNS.inc
1 <?php
3 class termDNS extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account = true;
7   var $autonet        = false;
9   /* Basic informations 
10    */
11   var $attributes     = array("ipHostNumber","macAddress");
12   var $objectclasses  = array("whatever");
14   var $ipHostNumber   = "";    // IP address 
15   var $macAddress     = "";    // Mac address 
16   var $cn             = "";    // CN of currently edited device 
17   var $OrigCn         = "";    // Initial cn
18   var $IPisMust       = false;
19   var $MACisMust      = false;
20   var $dialog;
22   /* DCHP Attributes 
23    */
24   var $dhcpAttributes           = array("dhcpParentNode");
25   var $dhcpEnabled              = FALSE;
26   var $dhcp_is_Account          = FALSE;
27   var $dhcpParentNodes          = array();
28   var $dhcpParentNode           = "";
29   var $dhcpHostEntry            = array();
30   var $initial_dhcpParentNode   = "";
31   var $initial_dhcpHostEntry    = array();
32   var $initial_dhcp_is_Account  = FALSE;
35   /* DNS attributes  
36    */
37   var $DNSattributes            = array("dNSClass","zoneName","dNSTTL");
38   var $DNS_is_account           = false;
39   var $initially_was_account = false;
40   var $dnsEntry                 = array();
41   var $DNSenabled               = false;
43   /*  Terminal dns 
44    */
45   function termDNS ($config, $dn,$objectClasses,$IPisMust = false)
46   {
47     /* We need to know which objectClasses are used, to store the ip/mac
48      * Because of different type of devices   
49      */
50     $this->objectclasses  =  $objectClasses;
51     $this->IPisMust       = $IPisMust;
53     plugin::plugin ($config, $dn);
55     if(isset($this->attrs['cn'][0])){
56       $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
57       $this->cn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
58     }
60  
61     /************
62      * DHCP 
63      ************/
65     /* Hide all dhcp specific code, if dhcp plugin is not present in config */
66     $dhcpEnabled = FALSE;
67     foreach($this->config->data['TABS']['SERVTABS'] as $tab){
68       if(preg_match("/^servdhcp$/",$tab['CLASS'])){
69         $this->dhcpEnabled = TRUE;
70       }
71     }
72     if($this->dhcpEnabled){
73       $this->dhcpParentNodes = $this->get_dhcp_parent_nodes();
74       $this->dhcpParentNode  = $this->get_dhcp_parent_node();
75       if($this->dhcpParentNode){
76         $this->dhcp_is_Account = TRUE;
77         $this->initial_dhcp_is_Account = TRUE;
78         $this->dhcpHostEntry  = $this->get_dhcp_host_entry();    
79       }
80       $this->initial_dhcpHostEntry = $this->dhcpHostEntry;
81       $this->initial_dhcpParentNode= $this->dhcpParentNode;
82     }
85     /************
86      * Autonetwork hook 
87      ************/
88  
89     /* Do we have autonet support? */
90     if (isset($this->config->data['MAIN']['AUTO_NETWORK_HOOK'])){
91       $this->autonet= true;
92     }
95     /************
96      * DNS
97      ************/
98  
99     /* Hide all dns specific code, if dns is not available 
100      */
101     $DNSenabled = false;
102     foreach($this->config->data['TABS']['SERVERSERVICE'] as $tab){
103       if(preg_match("/^servdns$/",$tab['CLASS'])){
104         $this->DNSenabled = true;
105       }
106     }
107     if(!$this->DNSenabled){
108       $this->DNS_is_account = false;
109       return;
110     }
112     if($this->DNSenabled){
114       /* Get Zones  
115        */
116       $this->Zones        = getAvailableZones($config);
118       /* Get Entry 
119        */
120       $this->dnsEntry     = getDNSHostEntries($config,$this->OrigCn);
122       /* Remove A record which equals $this->ipHostNumber
123        */
124       $ptr = $this->get_pTRRecord();
125       foreach($this->dnsEntry['RECORDS'] as $key => $rec){
126         if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){
127           unset($this->dnsEntry['RECORDS'][$key]);
128         }
129         if(($rec['type'] == "pTRRecord") && ($rec['value'] == $ptr)){
130           unset($this->dnsEntry['RECORDS'][$key]);
131         }
132       }
134       /* Get Record types 
135        */
136       $this->RecordTypes  = getDnsRecordTypes();
138       /* If there is at least one entry in this -> types, we have DNS enabled 
139        */
140       if($this->dnsEntry['exists']){
141         $this->DNS_is_account = true;
142       }else{
143         $this->DNS_is_account = false;
144       }
145     }
146  
147     /* Store initally account settings 
148      */
149     $this->initially_was_account = $this->DNS_is_account;
151     if($this->DNS_is_account){
152       new log("view","unknown/".get_class($this),$this->dn);
153     }
154   }
157   function netmaskIsCoherent($idZone) 
158   {
159     $netmask = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($idZone)));
160     if(!strstr($this->ipHostNumber, $netmask)){
161       return false;
162     }else{
163       return true;
164     }
165   }
168   function getVarsForSaving($attrs) 
169   {
170     foreach($this->attributes as $attr){
171       if(!empty($this->$attr)){
172         $attrs[$attr] = $this->$attr;
173       }
174     }
175     return($attrs); 
176   }
178   function execute()
179   {
180           /* Call parent execute */
181     $smarty= get_smarty();
183     $tmp = $this->plInfo();
184     foreach($tmp['plProvidedAcls'] as $name => $translation){
185       $smarty->assign($name."ACL",$this->getacl($name));
186     }
188     $display= "";
190     $smarty->assign("staticAddress", ""); 
191     $smarty->assign("autonet", "");
192  
193     /* Check for autonet button */
194     if ($this->autonet && isset($_POST['autonet'])){
195       $cmd= $this->config->data['MAIN']['AUTO_NETWORK_HOOK'];
196       if(!empty($cmd) && $this->cn != ""){
197         $res = shell_exec($cmd." ".$this->cn);
198         if(!$res){
199           print_red(sprintf(_("Can't execute specified AUTO_NETWORK_HOOK '%s'. Please check your gosa.conf."),$cmd));
200         } else {
201           $res= split(';', trim($res));
202           if (isset($res[0]) && $res[0] != ""){
203             $this->ipHostNumber= $res[0];
204           }
205           if (isset($res[1]) && $res[1] != ""){
206             $this->macAddress= $res[1];
207           }
208         }
209       }
210     }
212     
213   
214     /**********
215      * DHCP Handling
216      **********/
217  
218     if(isset($_POST['dhcpEditOptions'])){
220       if(count($this->dhcpHostEntry) == 0){
221         $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
222       }else{
223         $this->dialog = new dhcpHost($this->dhcpHostEntry,TRUE);
224       }
225       $this->dialog->cn = $this->cn; 
226       $this->dialog->dhcpHWAddress = $this->macAddress; 
227       if(!empty($this->ipHostNumber)){
228         $this->dialog->statements['fixed-address'] = $this->ipHostNumber; 
229       }
230     }
232     if(isset($_POST['cancel_dhcp'])){
233       $this->dialog = FALSE; 
234     }
236     if(isset($_POST['save_dhcp'])){
237       $this->dialog->save_object();
238       
239       $msgs = $this->dialog->check(array());
240       if(count($msgs)){
241         foreach($msgs as $msg){
242           print_red($msg);
243         }
244       }else{
245         $this->dhcpHostEntry = $this->dialog->save();
246         $this->dialog = FALSE; 
247       }
248     }
250     if(isset($this->dialog) && $this->dialog != FALSE){
251       $this->dialog->save_object();
252       return($this->dialog->execute());
253     }
254  
255     $smarty->assign("dhcpEnabled",    $this->dhcpEnabled);
256     $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account);
257     $smarty->assign("dhcpParentNode", $this->dhcpParentNode);
258     $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes);
260     /* There is no dns available
261      */
262     if($this->DNSenabled == false){
264       /* Is IP address must ? */
265       $smarty->assign("DNS_is_account",false);
266       $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
268       /* Assign smarty all non DNs attributes */
269       foreach($this->attributes as $attr){
270         $smarty->assign($attr,$this->$attr);
271       }
272       $smarty->assign("staticAddress","<font class=\"must\">*</font>");
274       $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
275     }else{
276       $smarty->assign("DNS_is_account",true);
278       /* Add new empty array to our record list */
279       if(isset($_POST['AddNewRecord'])){
280         $this->dnsEntry['RECORDS'][]  =array("type"=>"aRecord","value"=>"");
281       }
283       /* Handle all posts */
284       $only_once =true;
285       foreach($_POST as $name => $value){
287         /* Check if we have to delete a record entry */
288         if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
290           /* Avoid performing this once again */
291           $only_once = false;
293           /* Extract id for specified entry */
294           $id = preg_replace("/RemoveRecord_/","",$name);
295           $id = preg_replace("/_.*$/","",$id);
297           /* Delete this record, mark edited entries to be able to delete them */
298           if(isset($this->dnsEntry['RECORDS'][$id])){
299             unset($this->dnsEntry['RECORDS'][$id]);
300           }
301         }
302       }
303       /* Assign smarty all non DNs attributes */
304       foreach($this->attributes as $attr){
305         $smarty->assign($attr,$this->$attr);
306       }
308       /* Assign smarty all DNS attributes */
309       foreach($this->DNSattributes as $attr){
310         $smarty->assign($attr,$this->dnsEntry[$attr]);
311       }
313       /* Assign all needed vars */
314       $smarty->assign("DNSAccount",$this->DNS_is_account);
315       $smarty->assign("Zones",$this->Zones);
316       $smarty->assign("ZoneKeys",($this->Zones));
317       $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
319       /* Create zone array */
320       $idZones = array();
321       foreach($this->Zones as $id => $zone){
322         if($this->netmaskIsCoherent($id)) {
323           $idZones[$id] = $zone;
324         }else{
325           $idZones[$id] = $zone."&nbsp;("._("Not matching").")";
326         }
327       }
328       $smarty->assign("Zones",$idZones);
329       $smarty->assign("ZoneKeys", $this->Zones);
331       $tmp = $this->generateRecordsList();
333       $changeStateForRecords = $tmp['changeStateForRecords'];
335       $smarty->assign("records",$tmp['str']);
336       $smarty->assign("changeStateForRecords",$changeStateForRecords);
337       $smarty->assign("staticAddress","<font class=\"must\">*</font>");
339       $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
340     }
341     return($display);
342   }
345   function remove_from_parent()
346   {
347     if($this->initially_was_account){
349       $ldap = $this->config->get_ldap_link();
351       $tmp = array();
352       $this->dnsEntry['exists'] = false;
353       $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
355       /* Delete dns */
356       foreach($tmp['del'] as $dn => $del){
357         $ldap->cd($dn);
358         $ldap->rmdir_recursive($dn);
359         new log("remove","unknown/".get_class($this),$dn);
360       }
361     }
362   }
365   /* Save data to object */
366   function save_object()
367   {
369     if(isset($_POST['network_tpl_posted'])){
371       /* Save all posted vars */
372       plugin::save_object();
374       /* Handle DHCP Posts*/
375       if($this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
376         foreach($this->dhcpAttributes as $attr){
377           if(isset($_POST[$attr])){
378             $this->$attr = $_POST[$attr];
379           }
380         }
381         if(isset($_POST['dhcp_is_Account'])){
382           $this->dhcp_is_Account = TRUE;
383         }else{
384           $this->dhcp_is_Account = FALSE;
385         }
386       }
388       /* Ge all non dns attributes (IP/MAC)*/
389       foreach($this->attributes as $attr){
390         if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
391           $this->$attr = $_POST[$attr];
392         }
393       }
395       /* Check if DNS should be enabled / disabled */
396       if($this->DNS_is_account && $this->acl_is_removeable() && !isset($_POST['DNS_is_account'])){
397         $this->DNS_is_account = false;
398       }elseif(!$this->DNS_is_account && $this->acl_is_createable() && isset($_POST['DNS_is_account'])){
399         $this->DNS_is_account = true;
400       }
402       /* Get dns attributes */
403       if(($this->DNSenabled) && (isset($_POST['network_tpl_posted']))){
405         /* Check for posted record changes */
406         if(is_array($this->dnsEntry['RECORDS']) && $this->acl_is_writeable("Records")){
407           foreach($this->dnsEntry['RECORDS'] as $key => $value){
409             /* Check if type has changed */
410             if(isset($_POST['RecordTypeSelectedFor_'.$key])){
411               $this->dnsEntry['RECORDS'][$key]['type'] = $_POST['RecordTypeSelectedFor_'.$key];
412             }
413             /* Check if value has changed */
414             if(isset($_POST['RecordValue_'.$key])){
415               $this->dnsEntry['RECORDS'][$key]['value'] = $_POST['RecordValue_'.$key];
416             }
417           }
418         }
419         /* Get all basic DNS attributes (TTL, Clas ..)*/
420         foreach($this->DNSattributes as $attr){
421           if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
422             $this->dnsEntry[$attr] = $_POST[$attr];
423           }
424         }
427       }
428     }
429   }
432   /* Check supplied data */
433   function check()
434   {
435     /* Call common method to give check the hook */
436     $message= plugin::check();
438     if($this->dhcpEnabled && $this->dhcpParentNode != "" && count($this->dhcpHostEntry) == 0){
439       $message[] =_("You haven not configured your dhcp settings yet.");
440     }
442     /* Check if ip must be given
443      */  
444     if(($this->IPisMust)||($this->DNS_is_account)){
445       if (empty($this->ipHostNumber)){
446         $message[]= _("The required field 'IP-address' is not set.");
447       }
449       if (!is_ip($this->ipHostNumber)){
450         $message[]= _("Wrong IP format in field IP-address.");
451       }
452     }
454     /* Check if mac is empty 
455      */
456     if ($this->macAddress == "" ){
457       $message[]= _("The required field 'MAC-address' is not set.");
458     }
459     if(!is_mac($this->macAddress)){
460       $message[]=(_("The given macaddress is invalid. There must be 6 2byte segments seperated by ':'."));
461     }
463     /* only perfrom this checks if this is a valid DNS account */
464     if($this->DNS_is_account){
466       $checkArray = array();
467       $onlyOnce   = array();
469       //  $onlyOnce['cNAMERecord'] = 0;
470        $tmp = array_flip($this->Zones);
471        $tmp2 = $tmp[$this->dnsEntry['zoneName']];
472        if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){
473          $tmp2 = preg_replace("/^.*\//","",$tmp2);
474          $message[] =sprintf(_("The specified IP address '%s' is not matching the selected reverse zone entry '%s'."),$this->ipHostNumber,$tmp2);
475        }
477       /* Walk through all entries and detect duplicates or mismatches
478        */  
479       foreach($this->dnsEntry['RECORDS'] as $name => $values){
481         /* Count record values, to detect duplicate entries for a specific record
482          */
483         if(!isset($checkArray[$values['type']][$values['value']])){
484           $checkArray[$values['type']][$values['value']] = 0;
485         }else{
486           $message[] = sprintf(_("Found duplicate value for record type '%s'."),$values['type']);
487         }
489         /* Check if given entries in $onlyOnce are used more than once
490          */
491         if(isset($onlyOnce[$values['type']])){
492           $onlyOnce[$values['type']] ++;
493           if($onlyOnce[$values['type']] > 1){
494             $message[] = sprintf(_("Found more than one entry for the uniqe record type '%s'."),$values['type']);
495           }
496         }
498         /* Skip txt record ... 
499          */
500         if($values['type'] == "tXTRecord") continue;
502         /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress 
503          */
504         if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)){
505           $message[]=sprintf(_("The device IP '%s' is added as 'A Record', this will be done automatically, please remove the record."), 
506                $this->ipHostNumber);
507         }
509         /* only lower-case is allowed in record entries ... 
510          */
511         if($values['value'] != strtolower($values['value'])){
512           $message[] = sprintf(_("Only lowercase is allowed, please check your '%ss'."),$values['type']);
513         }
514       }
515     }
516     return ($message);
517   }
520   /* Save to LDAP */
521   function save($dn)
522   {
523     $ldap= $this->config->get_ldap_link();
524    
525     /*******************/ 
526     /* IP-MAC HANDLING */
527     /*******************/ 
529     /* $dn was posted as parameter */
530     $this->dn = $dn;
531     
532     /* Save DNS setting & ip/Mac*/
533     plugin::save();
535     /* Write back to ldap */
536     $ldap->cd($this->dn);
537     $this->cleanup();
538     $ldap->modify ($this->attrs); 
540     /****************/ 
541     /* DHCP HANDLING */
542     /****************/ 
543   
544     /* New entry */
545     if($this->dhcpEnabled){
547       /* Unset dhcpStatements if this attribute is empty  */
548       if(isset($this->dhcpHostEntry['dhcpStatements']) && 
549           ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){
550         unset($this->dhcpHostEntry['dhcpStatements']);
551       }
552   
553       /* DHCP removed */
554       if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){
555         $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
556         show_ldap_error($ldap->get_error(),_("Removing dhcp entry for this object failed."));
557       }
559       /* DHCP Added */
560       if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){
561         $attrs = $this->dhcpHostEntry;
562         unset($attrs['MODIFIED']);
563         unset($attrs['dn']);
564         $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
565         $res = $ldap->add($attrs);
566 #        print_a($attrs);
567 #        print("cn=".$this->cn.",".$this->dhcpParentNode);
568         show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
569       }
571       /* DHCP still activated */
572       if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){
574         /* DHCP node changed */
575         if(($this->initial_dhcpParentNode != $this->dhcpParentNode) || 
576            ($this->cn != $this->OrigCn)){
577           $attrs = $this->dhcpHostEntry;
578           $attrs['cn'] = $this->cn;
579           unset($attrs['dn']);
580           unset($attrs['MODIFIED']);
581           $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
582           $res = $ldap->add($attrs);
583           show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
584           if($res){
585             $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
586             show_ldap_error($ldap->get_error(),_("Removing old dhcp entry failed."));
587           }
588         }
589          
590         /* SAME node but modified */ 
591         if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1  && 
592             $this->initial_dhcpParentNode == $this->dhcpParentNode){
593           $attrs = $this->dhcpHostEntry;
594           unset($attrs['dn']);
595           unset($attrs['MODIFIED']);
596           $ldap->cd($this->dhcpHostEntry['dn']);
597           $ldap->modify($attrs);
598           show_ldap_error($ldap->get_error(),_("Modifying dhcp entry failed."));
599         }    
600       }
601     }
602       
604     /****************/ 
605     /* DNS HANDLING */
606     /****************/ 
608     /* If isn't DNS account but initially was DNS account 
609        remove all DNS entries 
610      */ 
611     if((!$this->DNSenabled) || ((!$this->DNS_is_account)&&(!$this->initially_was_account))){
612       return;
613     }else{
615       /* Add ipHostNumber to aRecords
616        */
617       $backup_dnsEntry = $this->dnsEntry;
618       if(!empty($this->ipHostNumber)){
619         $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber);
620         $ptr = $this->get_pTRRecord();
621         if(!empty($ptr)){
622           $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr);
623         } 
624       }
626       /* Create diff and follow instructions 
627        * If Account was disabled, remove account by setting exists to false
628        */
629       if((!$this->DNS_is_account)&&($this->initially_was_account)){  
630         $this->dnsEntry['exists'] = false;
631         $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
632       }else{
633         $this->dnsEntry['exists'] = $this->DNS_is_account;
634         $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
635       }   
637       /* move follwoing entries 
638        */
639       foreach($tmp['move'] as $src => $dst){
640         $this->recursive_move($src,$dst);
641       }
643       /* Delete dns */
644       foreach($tmp['del'] as $dn => $del){
645         $ldap->cd($dn);
646         $ldap->rmdir_recursive($dn);
647         new log("modify","unknown/".get_class($this),$dn,array("*"),$ldap->get_error());
648       }
650       /* Add || Update new DNS entries 
651        */
652       foreach($tmp['add'] as $dn => $attrs){
653         $ldap->cd($dn);
654         $ldap->cat($dn, array('dn'));
655         if(count($ldap->fetch())){
656           $ldap->cd($dn);
657           $ldap->modify ($attrs); 
658         }else{
659           $ldap->cd($dn);
660           $ldap->add($attrs);
661         }
662         new log("modify","unknown/".get_class($this),$dn,array_keys($attrs),$ldap->get_error());
663       }
666       /* Display errors 
667        */
668       if($ldap->get_error() != "Success"){
669         show_ldap_error($ldap->get_error(), sprintf(_("Saving of terminal/dns account with dn '%s' failed."),$this->dn));
670       }
672       $this->dnsEntry =  $backup_dnsEntry;
673     }
674   }
676   /*  Create html table with all used record types
677    */
678   function generateRecordsList()
679   {
680     $changeStateForRecords = "";
681     
682     if(!$this->DNS_is_account) {
683       $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled='disabled'>";
684       return $str;
685     }
686  
687     $str = "<table summary='' width='100%'>";
688     foreach($this->dnsEntry['RECORDS'] as $key => $entry){
690         $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
691         $changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
692         $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
694         $str.=" <tr>".
695           "   <td>".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key)."</td>".
696           "   <td><input type='text' value='".$entry['value']."' name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
697           "   <td><input type='submit' name='RemoveRecord_".$key."' value='"._("Delete")."' id='RemoveRecord_".$key."'></td>".
698           "</tr>";
699     }
701     $str.= "  <tr>".
702            "    <td colspan=2 width='50%'></td><td>".
703            "      <input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord'>".
704            "    </td>".
705            "  </tr>".
706            "</table>";
707      $ret =  array("str" => $str, "changeStateForRecords" => $changeStateForRecords);
708     return($ret);
709   }
712   /* Create a html select box which allows us to select different types of records 
713    */
714   function generateRecordListBox($selected,$name)
715   {
716     $str = "<select name='".$name."' id='".$name."'>";
717     foreach($this->RecordTypes as $type => $value){
718       $use = "";
719       if($type == $selected){
720         $use = " selected ";
721       }
722       $str.="\n <option value='".$type."' ".$use.">".strtoupper(preg_replace("/record/i","",$type))."</option>";
723     }
724     $str.="</select>";
725     return($str); 
726   }
729   /* Return plugin informations for acl handling  */ 
730   function plInfo()
731   {
732     $tmp =  array(
733         "plShortName"   => _("DNS"),
734         "plDescription" => _("DNS settings"),
735         "plSelfModify"  => FALSE,
736         "plDepends"     => array(),
737         "plPriority"    => 5,
738         "plSection"     => array("administration"),
739         "plCategory"    => array("workstation","terminal","phone","server","component","printer","winworkstation"),
741         "plProvidedAcls"=> array(
742           "ipHostNumber"  => _("IP address"),
743           "macAddress"    => _("MAC address"))
744         );
746     /* Hide all dns specific code, if dns is not available
747      */
748     foreach($_SESSION['config']->data['TABS']['SERVERSERVICE'] as $tab){
749       if(preg_match("/^servdns$/",$tab['CLASS'])){
750         $tmp['plProvidedAcls']["Records"]        = _("DNS records");
751         $tmp['plProvidedAcls']["zoneName"]       = _("Zone name");
752         $tmp['plProvidedAcls']["dNSTTL"]         = _("TTL");
753       }
754     }
755     return($tmp);
756   }
758   
759   function get_dhcp_host_entry()
760   {
761     $attrs = array();
762     $dn = $this->get_dhcp_host_entry_dn();
763     if($dn){
764       $ldap = $this->config->get_ldap_link();
765       $ldap->cd($this->config->current['BASE']);
766       $ldap->cat($dn,array("*"));
767       if($ldap->count()){
768         $attrs = $ldap->fetch();
769         foreach($attrs as $key => $value){
770           if(is_numeric($key) || ($key == "count")){
771             unset($attrs[$key]);
772           }
773           if(is_array($value) && isset($value['count'])){
774             unset($attrs[$key]['count']);
775           }
776         }
777       }
778     }
779     return($attrs);
780   }
783   function get_dhcp_host_entry_dn()
784   {
785     $ldap = $this->config->get_ldap_link();
786     $ldap->cd($this->config->current['BASE']);
787     $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("cn","dn"));
789     if($ldap->count()){
790       $attr = $ldap->fetch();
791       return($attr['dn']);
792     }else{
793       return("");
794     }
795   }  
798   function get_dhcp_parent_node()
799   {
800     return(preg_replace("/^cn=".normalizePreg($this->cn).",/","",$this->get_dhcp_host_entry_dn()));
801   }
804   function get_dhcp_parent_nodes()
805   {
806     $ldap = $this->config->get_ldap_link();
807     $ldap->cd($this->config->current['BASE']);
808     $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN"));
809     
810     $dhcp_dns = array();
811     while($attr = $ldap->fetch()){
812       $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0];
813     }
814  
815     foreach($dhcp_dns as $key => $pri_dns){
816       $ldap->cat($pri_dns,array("cn"));
817       $tmp = $ldap->fetch();
818       if(isset($tmp['cn'][0])){
819         $dhcp_dns[$key] = $tmp['cn'][0];
820       }else{
821         unset($dhcp_dns[$key]);
822       }
823     }
825     $tmp = $tmp2 = array();
826     foreach($dhcp_dns as $dn => $cn){
827       $ldap->cd($dn);
828       $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)".
829                     "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn"));
830       while($attr = $ldap->fetch()){
831         $tmp[$attr['dn']] = $attr['cn'][0];
832       }
833       $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.")&nbsp;"));
834     }
835     return($tmp2);
836   }
838   
839   /* this function returns the default ptr record entry */
840   function get_pTRRecord()
841   {
842     if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){
843       $ldap = $this->config->get_ldap_link();
844       $ldap->cat(getDNSZoneDN($this->config,$this->dnsEntry['zoneName']));
845       $attrs = $ldap->fetch();
846       $tmp = array_flip($this->Zones);
847       $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]);
848       $tmp = trim(preg_replace("/\.in-addr.arpa$/","",$tmp));
849       $ptr = preg_replace("/^".normalizePreg(FlipIp($tmp))."\./","",$this->ipHostNumber);
850       return($ptr);
851     }else{
852       return(FALSE);
853     }
854   }
856   
857   function create_tree($arr,$base,$current = "")
858   {
859     $ret = array();
860     foreach($arr as $r => $name){
861       $base_part = str_replace($base,"",$r);
862       if(preg_match("/^[a-z]*=".normalizePreg($name)."(|,)$/i",$base_part)){
863         $ret[$r] = $current.$name;
864         $tmp = $this->create_tree($arr,$r,$current.".&nbsp;");
865         foreach($tmp as $sub_key => $sub_name){
866           $ret[$sub_key] = $sub_name;
867         }
868       } 
869     }
870     return($ret);
871   }
874 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
875 ?>