693ad6f444f064b007bc581dee55387351ec30bd
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 $DNSinitially_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 }
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 ************/
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 ************/
99 /* Hide all dns specific code, if dns is not available
100 */
101 $DNSenabled = false;
102 foreach($this->config->data['TABS']['SERVTABS'] 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 }
146 }
148 /* Store initally account settings
149 */
150 $this->DNSinitially_was_account = $this->DNS_is_account;
151 }
154 function netmaskIsCoherent($idZone)
155 {
156 $netmask = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($idZone)));
157 if(!strstr($this->ipHostNumber, $netmask)){
158 return false;
159 }else{
160 return true;
161 }
162 }
165 function getVarsForSaving($attrs)
166 {
167 foreach($this->attributes as $attr){
168 if(!empty($this->$attr)){
169 $attrs[$attr] = $this->$attr;
170 }
171 }
172 return($attrs);
173 }
175 function execute()
176 {
177 /* Call parent execute */
178 $smarty= get_smarty();
179 $display= "";
181 $smarty->assign("staticAddress", "");
182 $smarty->assign("autonet", $this->autonet);
184 /* Check for autonet button */
185 if ($this->autonet && isset($_POST['autonet'])){
186 $cmd= $this->config->data['MAIN']['AUTO_NETWORK_HOOK'];
187 if(!empty($cmd) && $this->cn != ""){
188 $res = shell_exec($cmd." ".$this->cn);
189 if(!$res){
190 print_red(sprintf(_("Can't execute specified AUTO_NETWORK_HOOK '%s'. Please check your gosa.conf."),$cmd));
191 } else {
192 $res= split(';', trim($res));
193 if (isset($res[0]) && $res[0] != ""){
194 $this->ipHostNumber= $res[0];
195 }
196 if (isset($res[1]) && $res[1] != ""){
197 $this->macAddress= $res[1];
198 }
199 }
200 }
201 }
205 /**********
206 * DHCP Handling
207 **********/
209 if(isset($_POST['dhcpEditOptions'])){
211 if(count($this->dhcpHostEntry) == 0){
212 $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
213 }else{
214 $this->dialog = new dhcpHost($this->dhcpHostEntry,TRUE);
215 }
216 $this->dialog->cn = $this->cn;
217 $this->dialog->dhcpHWAddress = $this->macAddress;
218 if(!empty($this->ipHostNumber)){
219 $this->dialog->statements['fixed-address'] = $this->ipHostNumber;
220 }
221 }
223 if(isset($_POST['cancel_dhcp'])){
224 $this->dialog = FALSE;
225 }
227 if(isset($_POST['save_dhcp'])){
228 $this->dialog->save_object();
230 $msgs = $this->dialog->check(array());
231 if(count($msgs)){
232 foreach($msgs as $msg){
233 print_red($msg);
234 }
235 }else{
236 $this->dhcpHostEntry = $this->dialog->save();
237 $this->dialog = FALSE;
238 }
239 }
241 if(isset($this->dialog) && $this->dialog != FALSE){
242 $this->dialog->save_object();
243 return($this->dialog->execute());
244 }
246 $smarty->assign("dhcpEnabled", $this->dhcpEnabled);
247 $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account);
248 $smarty->assign("dhcpParentNode", $this->dhcpParentNode);
249 $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes);
250 $smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes));
252 /* There is no dns available
253 */
254 if($this->DNSenabled == false){
256 /* Is IP address must ? */
257 $smarty->assign("DNS_is_account",false);
258 $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
260 /* Assign smarty all non DNs attributes */
261 foreach($this->attributes as $attr){
262 $smarty->assign($attr,$this->$attr);
263 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
264 }
265 $smarty->assign("staticAddress","<font class=\"must\">*</font>");
267 $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
268 }else{
269 $smarty->assign("DNS_is_account",true);
271 /* Add new empty array to our record list */
272 if(isset($_POST['AddNewRecord'])){
273 $this->dnsEntry['RECORDS'][] =array("type"=>"aRecord","value"=>"");
274 }
276 /* Handle all posts */
277 $only_once =true;
278 foreach($_POST as $name => $value){
280 /* Check if we have to delete a record entry */
281 if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
283 /* Avoid performing this once again */
284 $only_once = false;
286 /* Extract id for specified entry */
287 $id = preg_replace("/RemoveRecord_/","",$name);
288 $id = preg_replace("/_.*$/","",$id);
290 /* Delete this record, mark edited entries to be able to delete them */
291 if(isset($this->dnsEntry['RECORDS'][$id])){
292 unset($this->dnsEntry['RECORDS'][$id]);
293 }
294 }
295 }
297 /* Assign smarty all non DNs attributes */
298 foreach($this->attributes as $attr){
299 $smarty->assign($attr,$this->$attr);
300 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
301 }
303 /* Assign smarty all DNS attributes */
304 foreach($this->DNSattributes as $attr){
305 $smarty->assign($attr,$this->dnsEntry[$attr]);
306 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
307 }
309 /* Assign all needed vars */
310 $smarty->assign("DNSaccountACL",chkacl($this->acl,"termDNS"));
312 $smarty->assign("DNSAccount",$this->DNS_is_account);
313 $smarty->assign("Zones",$this->Zones);
314 $smarty->assign("ZoneCnt",count($this->Zones));
315 $smarty->assign("ZoneKeys",($this->Zones));
316 $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
318 /* Create zone array */
319 $idZones = array();
320 foreach($this->Zones as $id => $zone){
321 if($this->netmaskIsCoherent($id)) {
322 $idZones[$id] = $zone;
323 }else{
324 $idZones[$id] = $zone." ("._("Not matching").")";
325 }
326 }
327 $smarty->assign("Zones",$idZones);
328 $smarty->assign("ZoneKeys", $this->Zones);
330 $tmp = $this->generateRecordsList();
332 $changeStateForRecords = $tmp['changeStateForRecords'];
334 $smarty->assign("records",$tmp['str']);
335 $smarty->assign("changeStateForRecords",$changeStateForRecords);
336 $smarty->assign("staticAddress","<font class=\"must\">*</font>");
338 $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
339 }
340 return($display);
341 }
343 function remove_from_parent()
344 {
345 /*
346 $ldap = $this->config->get_ldap_link();
347 $ldap->cd($this->orig_dn);
348 $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("relativeDomainName","zoneName"));
349 while($attr = $ldap->fetch()){
350 $ldap->cd($attr['dn']);
351 $ldap->rmDir($attr['dn']);
352 show_ldap_error("Record:".$ldap->get_error(), _("Removing terminal from DNS object failed"));
353 }
354 */
355 }
357 /* Save data to object */
358 function save_object()
359 {
360 /* Save all posted vars */
361 plugin::save_object();
364 /* Handle DHCP Posts*/
365 if($this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
366 foreach($this->dhcpAttributes as $attr){
367 if(isset($_POST[$attr])){
368 $this->$attr = $_POST[$attr];
369 }
370 }
371 if(isset($_POST['dhcp_is_Account'])){
372 $this->dhcp_is_Account = TRUE;
373 }else{
374 $this->dhcp_is_Account = FALSE;
375 }
376 }
379 /* Get dns attributes */
380 if(($this->DNSenabled) && (isset($_POST['network_tpl_posted'])) && chkacl($this->acl,"termDNS") == ""){
382 /* Check for posted record changes */
383 if(is_array($this->dnsEntry['RECORDS'])){
384 foreach($this->dnsEntry['RECORDS'] as $key => $value){
386 /* Check if type has changed */
387 if(isset($_POST['RecordTypeSelectedFor_'.$key])){
388 $this->dnsEntry['RECORDS'][$key]['type'] = $_POST['RecordTypeSelectedFor_'.$key];
389 }
390 /* Check if value has changed */
391 if(isset($_POST['RecordValue_'.$key])){
392 $this->dnsEntry['RECORDS'][$key]['value'] = $_POST['RecordValue_'.$key];
393 }
394 }
395 }
396 /* Get all basic DNS attributes (TTL, Clas ..)*/
397 foreach($this->DNSattributes as $attr){
398 if(isset($_POST[$attr])){
399 $this->dnsEntry[$attr] = $_POST[$attr];
400 }
401 }
403 /* Enable diable DNS */
404 if(isset($_POST['enableDNS'])){
405 $this->DNS_is_account = true;
406 }else{
407 $this->DNS_is_account = false;
408 }
409 }
410 }
413 /* Check supplied data */
414 function check()
415 {
416 /* Call common method to give check the hook */
417 $message= plugin::check();
419 if($this->dhcpEnabled && $this->dhcp_is_Account && $this->dhcpParentNode != "" && count($this->dhcpHostEntry) == 0){
420 $message[] =_("You haven not configured your dhcp settings yet.");
421 }
423 /* Check if ip must be given
424 */
425 if(($this->IPisMust)||($this->DNS_is_account)){
427 /* Check if ip is empty
428 */
429 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
430 $message[]= _("The required field 'IP-address' is not set.");
431 }
433 }
435 /* check if given ip is valid ip */
436 if ($this->ipHostNumber != "" && !is_ip($this->ipHostNumber)){
437 $message[]= _("Wrong IP format in field IP-address.");
438 }
440 /* Check if mac is empty
441 */
442 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
443 $message[]= _("The required field 'MAC-address' is not set.");
444 }
446 /* Check if given mac is valid mac
447 */
448 if(!is_mac($this->macAddress)){
449 $message[]=(_("The given macaddress is invalid. There must be 6 2byte segments seperated by ':'."));
450 }
452 /* only perfrom this checks if this is a valid DNS account */
453 if($this->DNS_is_account){
455 $checkArray = array();
456 $onlyOnce = array();
458 $tmp = array_flip($this->Zones);
459 $tmp2 = $tmp[$this->dnsEntry['zoneName']];
460 if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){
461 $tmp2 = preg_replace("/^.*\//","",$tmp2);
462 $message[] =sprintf(_("The specified IP address '%s' is not matching the selected reverse zone entry '%s'."),$this->ipHostNumber,$tmp2);
463 }
465 // There can be many CNAME records
466 //$onlyOnce['cNAMERecord'] = 0;
468 /* Walk through all entries and detect duplicates or mismatches
469 */
470 foreach($this->dnsEntry['RECORDS'] as $name => $values){
472 /* Count record values, to detect duplicate entries for a specific record
473 */
474 if(!isset($checkArray[$values['type']][$values['value']])){
475 $checkArray[$values['type']][$values['value']] = 0;
476 }else{
477 $message[] = sprintf(_("Found duplicate value for record type '%s'."),$values['type']);
478 }
480 /* Check if given entries in $onlyOnce are used more than once
481 */
482 if(isset($onlyOnce[$values['type']])){
483 $onlyOnce[$values['type']] ++;
484 if($onlyOnce[$values['type']] > 1){
485 $message[] = sprintf(_("Found more than one entry for the uniqe record type '%s'."),$values['type']);
486 }
487 }
489 /* Skip txt record ...
490 */
491 if($values['type'] == "tXTRecord") continue;
493 /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress
494 */
495 if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)){
496 $message[]=sprintf(_("The device IP '%s' is added as 'A Record', this will be done automatically, please remove the record."),
497 $this->ipHostNumber);
498 }
500 /* only lower-case is allowed in record entries ...
501 */
502 if($values['value'] != strtolower($values['value'])){
503 $message[] = sprintf(_("Only lowercase is allowed, please check your '%ss'."),$values['type']);
504 }
505 }
506 }
507 return ($message);
508 }
511 /* Save to LDAP */
512 function save($dn)
513 {
514 $ldap= $this->config->get_ldap_link();
516 /*******************/
517 /* IP-MAC HANDLING */
518 /*******************/
520 /* $dn was posted as parameter */
521 $this->dn = $dn;
523 /* Save DNS setting & ip/Mac*/
524 plugin::save();
526 /* Write back to ldap */
527 $ldap->cd($this->dn);
528 $this->cleanup();
529 $ldap->modify ($this->attrs);
531 /****************/
532 /* DHCP HANDLING */
533 /****************/
535 /* New entry */
536 if($this->dhcpEnabled){
538 /* Unset dhcpStatements if this attribute is empty */
539 if(isset($this->dhcpHostEntry['dhcpStatements']) &&
540 ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){
541 unset($this->dhcpHostEntry['dhcpStatements']);
542 }
544 /* DHCP removed */
545 if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){
546 $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
547 show_ldap_error($ldap->get_error(),_("Removing dhcp entry for this object failed."));
548 }
550 /* DHCP Added */
551 if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){
552 $attrs = $this->dhcpHostEntry;
553 unset($attrs['MODIFIED']);
554 unset($attrs['dn']);
555 $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
556 $res = $ldap->add($attrs);
557 # print_a($attrs);
558 # print("cn=".$this->cn.",".$this->dhcpParentNode);
559 show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
560 }
562 /* DHCP still activated */
563 if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){
565 /* DHCP node changed */
566 if(($this->initial_dhcpParentNode != $this->dhcpParentNode) ||
567 ($this->cn != $this->OrigCn)){
568 $attrs = $this->dhcpHostEntry;
569 $attrs['cn'] = $this->cn;
570 unset($attrs['dn']);
571 unset($attrs['MODIFIED']);
572 $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
573 $res = $ldap->add($attrs);
574 show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
575 if($res){
576 $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
577 show_ldap_error($ldap->get_error(),_("Removing old dhcp entry failed."));
578 }
579 }
581 /* SAME node but modified */
582 if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1 &&
583 $this->initial_dhcpParentNode == $this->dhcpParentNode){
584 $attrs = $this->dhcpHostEntry;
585 unset($attrs['dn']);
586 unset($attrs['MODIFIED']);
587 $ldap->cd($this->dhcpHostEntry['dn']);
588 $ldap->modify($attrs);
589 show_ldap_error($ldap->get_error(),_("Modifying dhcp entry failed."));
590 }
591 }
592 }
595 /****************/
596 /* DNS HANDLING */
597 /****************/
599 /* If isn't DNS account but initially was DNS account
600 remove all DNS entries
601 */
602 if((!$this->DNSenabled) || (!$this->DNS_is_account && !$this->DNSinitially_was_account)){
603 return;
604 }else{
606 /* Add ipHostNumber to aRecords
607 */
608 if(!empty($this->ipHostNumber)){
609 $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber);
610 $ptr = $this->get_pTRRecord();
611 if(!empty($ptr)){
612 $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr);
613 }
614 }
616 /* Create diff and follow instructions
617 * If Account was disabled, remove account by setting exists to false
618 */
619 if((!$this->DNS_is_account)&&($this->DNSinitially_was_account)){
620 $this->dnsEntry['exists'] = false;
621 $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
622 }else{
623 $this->dnsEntry['exists'] = $this->DNS_is_account;
624 $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
625 }
627 /* move follwoing entries
628 */
629 foreach($tmp['move'] as $src => $dst){
630 $this->recursive_move($src,$dst);
631 }
633 /* Delete dns */
634 foreach($tmp['del'] as $dn => $del){
635 $ldap->cd($dn);
636 $ldap->rmdir_recursive($dn);
637 }
639 /* Add || Update new DNS entries
640 */
641 foreach($tmp['add'] as $dn => $attrs){
642 $ldap->cd($dn);
643 $ldap->cat($dn, array('dn'));
644 if(count($ldap->fetch())){
645 $ldap->cd($dn);
646 $ldap->modify ($attrs);
647 }else{
648 $ldap->cd($dn);
649 $ldap->add($attrs);
650 }
651 }
653 /* Display errors
654 */
655 if($ldap->get_error() != "Success"){
656 show_ldap_error("Record:".$ldap->get_error(), _("Saving terminal to DNS object failed"));
657 }
658 }
659 }
661 /* Create html table with all used record types
662 */
663 function generateRecordsList()
664 {
665 $changeStateForRecords = "";
667 if(!$this->DNS_is_account) {
668 $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled='disabled'>";
669 return $str;
670 }
672 $str = "<table summary='' width='100%'>";
673 foreach($this->dnsEntry['RECORDS'] as $key => $entry){
675 $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
676 $changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
677 $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
679 $str.=" <tr>".
680 " <td>".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key)."</td>".
681 " <td><input ".chkacl($this->acl,"termDNS")." type='text' value='".$entry['value']."' name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
682 " <td><input ".chkacl($this->acl,"termDNS")." type='submit' name='RemoveRecord_".$key."' value='"._("Delete")."' id='RemoveRecord_".$key."'></td>".
683 "</tr>";
684 }
686 $str.= " <tr>".
687 " <td colspan=2 width='50%'></td><td>".
688 " <input type='submit' value='"._("Add")."' name='AddNewRecord' ".chkacl($this->acl,"termDNS")." >".
689 " </td>".
690 " </tr>".
691 "</table>";
692 $ret = array("str" => $str, "changeStateForRecords" => $changeStateForRecords);
693 return($ret);
694 }
697 /* Create a html select box which allows us to select different types of records
698 */
699 function generateRecordListBox($selected,$name)
700 {
701 $str = "<select ".chkacl($this->acl,"termDNS")." name='".$name."' id='".$name."'>";
702 foreach($this->RecordTypes as $type => $value){
703 $use = "";
704 if($type == $selected){
705 $use = " selected ";
706 }
707 $str.="\n <option value='".$type."' ".$use.">".strtoupper(preg_replace("/record/i","",$type))."</option>";
708 }
709 $str.="</select>";
710 return($str);
711 }
714 function get_dhcp_host_entry()
715 {
716 $attrs = array();
717 $dn = $this->get_dhcp_host_entry_dn();
718 if($dn){
719 $ldap = $this->config->get_ldap_link();
720 $ldap->cd($this->config->current['BASE']);
721 $ldap->cat($dn,array("*"));
722 if($ldap->count()){
723 $attrs = $ldap->fetch();
724 foreach($attrs as $key => $value){
725 if(is_numeric($key) || ($key == "count")){
726 unset($attrs[$key]);
727 }
728 if(is_array($value) && isset($value['count'])){
729 unset($attrs[$key]['count']);
730 }
731 }
732 }
733 }
734 return($attrs);
735 }
738 function get_dhcp_host_entry_dn()
739 {
740 $ldap = $this->config->get_ldap_link();
741 $ldap->cd($this->config->current['BASE']);
742 $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("cn","dn"));
744 if($ldap->count()){
745 $attr = $ldap->fetch();
746 return($attr['dn']);
747 }else{
748 return("");
749 }
750 }
753 function get_dhcp_parent_node()
754 {
755 return(preg_replace("/^cn=".normalizePreg($this->cn).",/","",$this->get_dhcp_host_entry_dn()));
756 }
759 function get_dhcp_parent_nodes()
760 {
761 $ldap = $this->config->get_ldap_link();
762 $ldap->cd($this->config->current['BASE']);
763 $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN"));
765 $dhcp_dns = array();
766 while($attr = $ldap->fetch()){
767 $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0];
768 }
770 foreach($dhcp_dns as $key => $pri_dns){
771 $ldap->cat($pri_dns,array("cn"));
772 $tmp = $ldap->fetch();
773 if(isset($tmp['cn'][0])){
774 $dhcp_dns[$key] = $tmp['cn'][0];
775 }else{
776 unset($dhcp_dns[$key]);
777 }
778 }
780 $tmp = $tmp2 = array();
781 foreach($dhcp_dns as $dn => $cn){
782 $ldap->cd($dn);
783 $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)".
784 "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn"));
785 while($attr = $ldap->fetch()){
786 $tmp[$attr['dn']] = $attr['cn'][0];
787 }
788 $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") "));
789 }
790 return($tmp2);
791 }
794 /* this function returns the default ptr record entry */
795 function get_pTRRecord()
796 {
797 if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){
798 $ldap = $this->config->get_ldap_link();
799 $ldap->cat(getDNSZoneDN($this->config,$this->dnsEntry['zoneName']));
800 $attrs = $ldap->fetch();
801 $tmp = array_flip($this->Zones);
802 $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]);
803 $tmp = trim(preg_replace("/\.in-addr.arpa$/","",$tmp));
804 $ptr = preg_replace("/^".normalizePreg(FlipIp($tmp))."\./","",$this->ipHostNumber);
805 return($ptr);
806 }else{
807 return(FALSE);
808 }
809 }
812 function create_tree($arr,$base,$current = "")
813 {
814 $ret = array();
815 foreach($arr as $r => $name){
816 $base_part = str_replace($base,"",$r);
817 if(preg_match("/^[a-z]*=".normalizePreg($name)."(|,)$/i",$base_part)){
818 $ret[$r] = $current.$name;
819 $tmp = $this->create_tree($arr,$r,$current.". ");
820 foreach($tmp as $sub_key => $sub_name){
821 $ret[$sub_key] = $sub_name;
822 }
823 }
824 }
825 return($ret);
826 }
827 }
829 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
830 ?>