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, $parent,$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->parent = $parent;
51 $this->objectclasses = $objectClasses;
52 $this->IPisMust = $IPisMust;
54 plugin::plugin ($config, $parent->dn);
56 if(isset($this->attrs['cn'][0])){
57 $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
58 $this->cn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
59 }
62 /************
63 * DHCP
64 ************/
66 /* Hide all dhcp specific code, if dhcp plugin is not present in config */
67 $dhcpEnabled = FALSE;
68 foreach($this->config->data['TABS']['SERVTABS'] as $tab){
69 if(preg_match("/^servdhcp$/",$tab['CLASS'])){
70 $this->dhcpEnabled = TRUE;
71 }
72 }
73 if($this->dhcpEnabled){
74 $this->dhcpParentNodes = $this->get_dhcp_parent_nodes();
75 $this->dhcpParentNode = $this->get_dhcp_parent_node();
76 if($this->dhcpParentNode){
77 $this->dhcp_is_Account = TRUE;
78 $this->initial_dhcp_is_Account = TRUE;
79 $this->dhcpHostEntry = $this->get_dhcp_host_entry();
80 }
81 $this->initial_dhcpHostEntry = $this->dhcpHostEntry;
82 $this->initial_dhcpParentNode= $this->dhcpParentNode;
83 }
86 /************
87 * Autonetwork hook
88 ************/
90 /* Do we have autonet support? */
91 if (isset($this->config->data['MAIN']['AUTO_NETWORK_HOOK'])){
92 $this->autonet= true;
93 }
96 /************
97 * DNS
98 ************/
100 /* Hide all dns specific code, if dns is not available
101 */
102 $DNSenabled = false;
103 foreach($this->config->data['TABS']['SERVERSERVICE'] as $tab){
104 if(preg_match("/^servdns$/",$tab['CLASS'])){
105 $this->DNSenabled = true;
106 }
107 }
108 if(!$this->DNSenabled){
109 $this->DNS_is_account = false;
110 return;
111 }
113 if($this->DNSenabled){
115 /* Get Zones
116 */
117 $this->Zones = getAvailableZones($config);
119 /* Get Entry
120 */
121 $this->dnsEntry = getDNSHostEntries($config,$this->OrigCn);
123 /* Remove A record which equals $this->ipHostNumber
124 */
125 $ptr = $this->get_pTRRecord();
126 foreach($this->dnsEntry['RECORDS'] as $key => $rec){
127 if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){
128 unset($this->dnsEntry['RECORDS'][$key]);
129 }
130 if(($rec['type'] == "pTRRecord") && ($rec['value'] == $ptr)){
131 unset($this->dnsEntry['RECORDS'][$key]);
132 }
133 }
135 /* Get Record types
136 */
137 $this->RecordTypes = getDnsRecordTypes();
139 /* If there is at least one entry in this -> types, we have DNS enabled
140 */
141 if($this->dnsEntry['exists']){
142 $this->DNS_is_account = true;
143 }else{
144 $this->DNS_is_account = false;
145 }
146 }
148 /* Store initally account settings
149 */
150 $this->initially_was_account = $this->DNS_is_account;
152 if($this->DNS_is_account){
153 new log("view","unknown/".get_class($this),$this->dn);
154 }
155 }
158 function netmaskIsCoherent($idZone)
159 {
160 $netmask = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($idZone)));
161 if(!strstr($this->ipHostNumber, $netmask)){
162 return false;
163 }else{
164 return true;
165 }
166 }
169 function getVarsForSaving($attrs)
170 {
171 foreach($this->attributes as $attr){
172 if(!empty($this->$attr)){
173 $attrs[$attr] = $this->$attr;
174 }
175 }
176 return($attrs);
177 }
179 function execute()
180 {
181 /* Call parent execute */
182 $smarty= get_smarty();
184 $tmp = $this->plInfo();
185 foreach($tmp['plProvidedAcls'] as $name => $translation){
186 $smarty->assign($name."ACL",$this->getacl($name));
187 }
189 $display= "";
191 $smarty->assign("staticAddress", "");
192 $smarty->assign("autonet", "");
194 /* Check for autonet button */
195 if ($this->autonet && isset($_POST['autonet'])){
196 $cmd= $this->config->data['MAIN']['AUTO_NETWORK_HOOK'];
197 if(!empty($cmd) && $this->cn != ""){
198 $res = shell_exec($cmd." ".$this->cn);
199 if(!$res){
200 print_red(sprintf(_("Can't execute specified AUTO_NETWORK_HOOK '%s'. Please check your gosa.conf."),$cmd));
201 } else {
202 $res= split(';', trim($res));
203 if (isset($res[0]) && $res[0] != ""){
204 $this->ipHostNumber= $res[0];
205 }
206 if (isset($res[1]) && $res[1] != ""){
207 $this->macAddress= $res[1];
208 }
209 }
210 }
211 }
215 /**********
216 * DHCP Handling
217 **********/
219 if(isset($_POST['dhcpEditOptions'])){
221 if(count($this->dhcpHostEntry) == 0){
222 $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
223 }else{
224 $this->dialog = new dhcpHost($this->dhcpHostEntry,TRUE);
225 }
226 $this->dialog->cn = $this->cn;
227 $this->dialog->dhcpHWAddress = $this->macAddress;
228 if(!empty($this->ipHostNumber)){
229 $this->dialog->statements['fixed-address'] = $this->ipHostNumber;
230 }
231 }
233 if(isset($_POST['cancel_dhcp'])){
234 $this->dialog = FALSE;
235 }
237 if(isset($_POST['save_dhcp'])){
238 $this->dialog->save_object();
240 $msgs = $this->dialog->check(array());
241 if(count($msgs)){
242 foreach($msgs as $msg){
243 print_red($msg);
244 }
245 }else{
246 $this->dhcpHostEntry = $this->dialog->save();
247 $this->dialog = FALSE;
248 }
249 }
251 if(is_object($this->dialog)){
252 $this->dialog->save_object();
253 return($this->dialog->execute());
254 }
256 $smarty->assign("dhcpEnabled", $this->dhcpEnabled);
257 $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account);
258 $smarty->assign("dhcpParentNode", $this->dhcpParentNode);
259 $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes);
260 $smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes));
263 /* There is no dns available
264 */
265 if($this->DNSenabled == false){
267 /* Is IP address must ? */
268 $smarty->assign("DNS_is_account",false);
269 $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
271 /* Assign smarty all non DNs attributes */
272 foreach($this->attributes as $attr){
273 $smarty->assign($attr,$this->$attr);
274 }
275 $smarty->assign("staticAddress","<font class=\"must\">*</font>");
277 $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
278 }else{
279 $smarty->assign("DNS_is_account",true);
281 /* Add new empty array to our record list */
282 if(isset($_POST['AddNewRecord'])){
283 $this->dnsEntry['RECORDS'][] =array("type"=>"aRecord","value"=>"");
284 }
286 /* Handle all posts */
287 $only_once =true;
288 foreach($_POST as $name => $value){
290 /* Check if we have to delete a record entry */
291 if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
293 /* Avoid performing this once again */
294 $only_once = false;
296 /* Extract id for specified entry */
297 $id = preg_replace("/RemoveRecord_/","",$name);
298 $id = preg_replace("/_.*$/","",$id);
300 /* Delete this record, mark edited entries to be able to delete them */
301 if(isset($this->dnsEntry['RECORDS'][$id])){
302 unset($this->dnsEntry['RECORDS'][$id]);
303 }
304 }
305 }
306 /* Assign smarty all non DNs attributes */
307 foreach($this->attributes as $attr){
308 $smarty->assign($attr,$this->$attr);
309 }
311 /* Assign smarty all DNS attributes */
312 foreach($this->DNSattributes as $attr){
313 $smarty->assign($attr,$this->dnsEntry[$attr]);
314 }
316 /* Assign all needed vars */
317 $smarty->assign("DNSAccount",$this->DNS_is_account);
318 $smarty->assign("Zones",$this->Zones);
319 $smarty->assign("ZoneCnt",count($this->Zones));
320 $smarty->assign("ZoneKeys",($this->Zones));
321 $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
323 /* Create zone array */
324 $idZones = array();
325 foreach($this->Zones as $id => $zone){
326 if($this->netmaskIsCoherent($id)) {
327 $idZones[$id] = $zone;
328 }else{
329 $idZones[$id] = $zone." ("._("Not matching").")";
330 }
331 }
332 $smarty->assign("Zones",$idZones);
333 $smarty->assign("ZoneKeys", $this->Zones);
335 $tmp = $this->generateRecordsList();
337 $changeStateForRecords = $tmp['changeStateForRecords'];
339 $smarty->assign("records",$tmp['str']);
340 $smarty->assign("changeStateForRecords",$changeStateForRecords);
341 $smarty->assign("staticAddress","<font class=\"must\">*</font>");
343 $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
344 }
345 return($display);
346 }
349 function remove_from_parent()
350 {
351 if($this->initially_was_account){
353 $ldap = $this->config->get_ldap_link();
355 $tmp = array();
356 $this->dnsEntry['exists'] = false;
357 $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
359 /* Delete dns */
360 foreach($tmp['del'] as $dn => $del){
361 $ldap->cd($dn);
362 $ldap->rmdir_recursive($dn);
363 new log("remove","unknown/".get_class($this),$dn);
364 }
365 }
366 }
369 /* Save data to object */
370 function save_object()
371 {
373 if(isset($_POST['network_tpl_posted'])){
375 /* Save all posted vars */
376 plugin::save_object();
378 /* Handle DHCP Posts*/
379 if($this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
380 foreach($this->dhcpAttributes as $attr){
381 if(isset($_POST[$attr])){
382 $this->$attr = $_POST[$attr];
383 }
384 }
385 if(isset($_POST['dhcp_is_Account'])){
386 $this->dhcp_is_Account = TRUE;
387 }else{
388 $this->dhcp_is_Account = FALSE;
389 }
390 }
392 /* Ge all non dns attributes (IP/MAC)*/
393 foreach($this->attributes as $attr){
394 if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
395 $this->$attr = $_POST[$attr];
396 }
397 }
399 /* Check if DNS should be enabled / disabled */
400 if($this->DNS_is_account && $this->acl_is_removeable() && !isset($_POST['DNS_is_account'])){
401 $this->DNS_is_account = false;
402 }elseif(!$this->DNS_is_account && $this->acl_is_createable() && isset($_POST['DNS_is_account'])){
403 $this->DNS_is_account = true;
404 }
406 /* Get dns attributes */
407 if(($this->DNSenabled) && (isset($_POST['network_tpl_posted']))){
409 /* Check for posted record changes */
410 if(is_array($this->dnsEntry['RECORDS']) && $this->acl_is_writeable("Records")){
411 foreach($this->dnsEntry['RECORDS'] as $key => $value){
413 /* Check if type has changed */
414 if(isset($_POST['RecordTypeSelectedFor_'.$key])){
415 $this->dnsEntry['RECORDS'][$key]['type'] = $_POST['RecordTypeSelectedFor_'.$key];
416 }
417 /* Check if value has changed */
418 if(isset($_POST['RecordValue_'.$key])){
419 $this->dnsEntry['RECORDS'][$key]['value'] = $_POST['RecordValue_'.$key];
420 }
421 }
422 }
423 /* Get all basic DNS attributes (TTL, Clas ..)*/
424 foreach($this->DNSattributes as $attr){
425 if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
426 $this->dnsEntry[$attr] = $_POST[$attr];
427 }
428 }
431 }
432 }
433 }
436 /* Check supplied data */
437 function check()
438 {
439 /* Call common method to give check the hook */
440 $message= plugin::check();
442 if($this->dhcpEnabled && $this->dhcp_is_Account && $this->dhcpParentNode != "" && count($this->dhcpHostEntry) == 0){
443 $message[] =_("You have not configured your dhcp settings yet.");
444 }
446 /* Check if ip must be given
447 */
448 if(($this->IPisMust)||($this->DNS_is_account)){
449 if (empty($this->ipHostNumber)){
450 $message[]= _("The required field 'IP-address' is not set.");
451 }
453 if (!is_ip($this->ipHostNumber)){
454 $message[]= _("Wrong IP format in field IP-address.");
455 }
456 }
458 /* Check if mac is empty
459 */
460 if ($this->macAddress == "" ){
461 $message[]= _("The required field 'MAC-address' is not set.");
462 }
463 if(!is_mac($this->macAddress)){
464 $message[]=(_("The given macaddress is invalid. There must be 6 2byte segments seperated by ':'."));
465 }
467 /* only perfrom this checks if this is a valid DNS account */
468 if($this->DNS_is_account){
470 $checkArray = array();
471 $onlyOnce = array();
473 // $onlyOnce['cNAMERecord'] = 0;
474 $tmp = array_flip($this->Zones);
475 $tmp2 = $tmp[$this->dnsEntry['zoneName']];
476 if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){
477 $tmp2 = preg_replace("/^.*\//","",$tmp2);
478 $message[] =sprintf(_("The specified IP address '%s' is not matching the selected reverse zone entry '%s'."),$this->ipHostNumber,$tmp2);
479 }
481 /* Walk through all entries and detect duplicates or mismatches
482 */
483 foreach($this->dnsEntry['RECORDS'] as $name => $values){
485 /* Count record values, to detect duplicate entries for a specific record
486 */
487 if(!isset($checkArray[$values['type']][$values['value']])){
488 $checkArray[$values['type']][$values['value']] = 0;
489 }else{
490 $message[] = sprintf(_("Found duplicate value for record type '%s'."),$values['type']);
491 }
493 /* Check if given entries in $onlyOnce are used more than once
494 */
495 if(isset($onlyOnce[$values['type']])){
496 $onlyOnce[$values['type']] ++;
497 if($onlyOnce[$values['type']] > 1){
498 $message[] = sprintf(_("Found more than one entry for the uniqe record type '%s'."),$values['type']);
499 }
500 }
502 /* Skip txt record ...
503 */
504 if($values['type'] == "tXTRecord") continue;
506 /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress
507 */
508 if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)){
509 $message[]=sprintf(_("The device IP '%s' is added as 'A Record', this will be done automatically, please remove the record."),
510 $this->ipHostNumber);
511 }
513 /* only lower-case is allowed in record entries ...
514 */
515 if($values['value'] != strtolower($values['value'])){
516 $message[] = sprintf(_("Only lowercase is allowed, please check your '%ss'."),$values['type']);
517 }
518 }
519 }
520 return ($message);
521 }
524 /* Save to LDAP */
525 function save()
526 {
527 $ldap= $this->config->get_ldap_link();
529 $dn = $this->parent->dn;
531 /*******************/
532 /* IP-MAC HANDLING */
533 /*******************/
535 /* $dn was posted as parameter */
536 $this->dn = $dn;
538 /* Save DNS setting & ip/Mac*/
539 plugin::save();
541 /* Write back to ldap */
542 $ldap->cd($this->dn);
543 $this->cleanup();
544 $ldap->modify ($this->attrs);
546 /****************/
547 /* DHCP HANDLING */
548 /****************/
550 /* New entry */
551 if($this->dhcpEnabled){
553 /* Unset dhcpStatements if this attribute is empty */
554 if(isset($this->dhcpHostEntry['dhcpStatements']) &&
555 ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){
556 unset($this->dhcpHostEntry['dhcpStatements']);
557 }
559 /* DHCP removed */
560 if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){
561 $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
562 show_ldap_error($ldap->get_error(),_("Removing dhcp entry for this object failed."));
563 }
565 /* DHCP Added */
566 if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){
567 $attrs = $this->dhcpHostEntry;
568 unset($attrs['MODIFIED']);
569 unset($attrs['dn']);
570 $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
571 $res = $ldap->add($attrs);
572 # print_a($attrs);
573 # print("cn=".$this->cn.",".$this->dhcpParentNode);
574 show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
575 }
577 /* DHCP still activated */
578 if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){
580 /* DHCP node changed */
581 if(($this->initial_dhcpParentNode != $this->dhcpParentNode) ||
582 ($this->cn != $this->OrigCn)){
583 $attrs = $this->dhcpHostEntry;
584 $attrs['cn'] = $this->cn;
585 unset($attrs['dn']);
586 unset($attrs['MODIFIED']);
587 $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
588 $res = $ldap->add($attrs);
589 show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
590 if($res){
591 $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
592 show_ldap_error($ldap->get_error(),_("Removing old dhcp entry failed."));
593 }
594 }
596 /* SAME node but modified */
597 if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1 &&
598 $this->initial_dhcpParentNode == $this->dhcpParentNode){
599 $attrs = $this->dhcpHostEntry;
600 unset($attrs['dn']);
601 unset($attrs['MODIFIED']);
602 $ldap->cd($this->dhcpHostEntry['dn']);
603 $ldap->modify($attrs);
604 show_ldap_error($ldap->get_error(),_("Modifying dhcp entry failed."));
605 }
606 }
607 }
610 /****************/
611 /* DNS HANDLING */
612 /****************/
614 /* If isn't DNS account but initially was DNS account
615 remove all DNS entries
616 */
617 if((!$this->DNSenabled) || ((!$this->DNS_is_account)&&(!$this->initially_was_account))){
618 return;
619 }else{
621 /* Add ipHostNumber to aRecords
622 */
623 $backup_dnsEntry = $this->dnsEntry;
624 if(!empty($this->ipHostNumber)){
625 $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber);
626 $ptr = $this->get_pTRRecord();
627 if(!empty($ptr)){
628 $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr);
629 }
630 }
632 /* Create diff and follow instructions
633 * If Account was disabled, remove account by setting exists to false
634 */
635 if((!$this->DNS_is_account)&&($this->initially_was_account)){
636 $this->dnsEntry['exists'] = false;
637 $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
638 }else{
639 $this->dnsEntry['exists'] = $this->DNS_is_account;
640 $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
641 }
643 /* move follwoing entries
644 */
645 foreach($tmp['move'] as $src => $dst){
646 $this->recursive_move($src,$dst);
647 }
649 /* Delete dns */
650 foreach($tmp['del'] as $dn => $del){
651 $ldap->cd($dn);
652 $ldap->rmdir_recursive($dn);
653 new log("modify","unknown/".get_class($this),$dn,array("*"),$ldap->get_error());
654 }
656 /* Add || Update new DNS entries
657 */
658 foreach($tmp['add'] as $dn => $attrs){
659 $ldap->cd($dn);
660 $ldap->cat($dn, array('dn'));
661 if(count($ldap->fetch())){
662 $ldap->cd($dn);
663 $ldap->modify ($attrs);
664 }else{
665 $ldap->cd($dn);
666 $ldap->add($attrs);
667 }
668 new log("modify","unknown/".get_class($this),$dn,array_keys($attrs),$ldap->get_error());
669 }
672 /* Display errors
673 */
674 if($ldap->get_error() != "Success"){
675 show_ldap_error($ldap->get_error(), sprintf(_("Saving of terminal/dns account with dn '%s' failed."),$this->dn));
676 }
678 $this->dnsEntry = $backup_dnsEntry;
679 }
680 }
682 /* Create html table with all used record types
683 */
684 function generateRecordsList()
685 {
686 $changeStateForRecords = "";
688 if(!$this->DNS_is_account) {
689 $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled='disabled'>";
690 return(array("str" => $str, "changeStateForRecords"=> ""));
691 }
693 $str = "<table summary='' width='100%'>";
694 foreach($this->dnsEntry['RECORDS'] as $key => $entry){
696 $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
697 $changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
698 $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
700 $str.=" <tr>".
701 " <td>".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key)."</td>".
702 " <td><input type='text' value='".$entry['value']."' name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
703 " <td><input type='submit' name='RemoveRecord_".$key."' value='"._("Delete")."' id='RemoveRecord_".$key."'></td>".
704 "</tr>";
705 }
707 $str.= " <tr>".
708 " <td colspan=2 width='50%'></td><td>".
709 " <input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord'>".
710 " </td>".
711 " </tr>".
712 "</table>";
713 $ret = array("str" => $str, "changeStateForRecords" => $changeStateForRecords);
714 return($ret);
715 }
718 /* Create a html select box which allows us to select different types of records
719 */
720 function generateRecordListBox($selected,$name)
721 {
722 $str = "<select name='".$name."' id='".$name."'>";
723 foreach($this->RecordTypes as $type => $value){
724 $use = "";
725 if($type == $selected){
726 $use = " selected ";
727 }
728 $str.="\n <option value='".$type."' ".$use.">".strtoupper(preg_replace("/record/i","",$type))."</option>";
729 }
730 $str.="</select>";
731 return($str);
732 }
735 /* Return plugin informations for acl handling */
736 function plInfo()
737 {
738 $tmp = array(
739 "plShortName" => _("DNS"),
740 "plDescription" => _("DNS settings"),
741 "plSelfModify" => FALSE,
742 "plDepends" => array(),
743 "plPriority" => 5,
744 "plSection" => array("administration"),
745 "plCategory" => array("workstation","terminal","phone","server","component","printer","winworkstation"),
747 "plProvidedAcls"=> array(
748 "ipHostNumber" => _("IP address"),
749 "macAddress" => _("MAC address"))
750 );
752 /* Hide all dns specific code, if dns is not available
753 */
754 foreach($_SESSION['config']->data['TABS']['SERVERSERVICE'] as $tab){
755 if(preg_match("/^servdns$/",$tab['CLASS'])){
756 $tmp['plProvidedAcls']["Records"] = _("DNS records");
757 $tmp['plProvidedAcls']["zoneName"] = _("Zone name");
758 $tmp['plProvidedAcls']["dNSTTL"] = _("TTL");
759 }
760 }
761 return($tmp);
762 }
765 function get_dhcp_host_entry()
766 {
767 $attrs = array();
768 $dn = $this->get_dhcp_host_entry_dn();
769 if($dn){
770 $ldap = $this->config->get_ldap_link();
771 $ldap->cd($this->config->current['BASE']);
772 $ldap->cat($dn,array("*"));
773 if($ldap->count()){
774 $attrs = $ldap->fetch();
775 foreach($attrs as $key => $value){
776 if(is_numeric($key) || ($key == "count")){
777 unset($attrs[$key]);
778 }
779 if(is_array($value) && isset($value['count'])){
780 unset($attrs[$key]['count']);
781 }
782 }
783 }
784 }
785 return($attrs);
786 }
789 function get_dhcp_host_entry_dn()
790 {
791 $ldap = $this->config->get_ldap_link();
792 $ldap->cd($this->config->current['BASE']);
793 $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("cn","dn"));
795 if($ldap->count()){
796 $attr = $ldap->fetch();
797 return($attr['dn']);
798 }else{
799 return("");
800 }
801 }
804 function get_dhcp_parent_node()
805 {
806 return(preg_replace("/^cn=".normalizePreg($this->cn).",/","",$this->get_dhcp_host_entry_dn()));
807 }
810 function get_dhcp_parent_nodes()
811 {
812 $ldap = $this->config->get_ldap_link();
813 $ldap->cd($this->config->current['BASE']);
814 $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN"));
816 $dhcp_dns = array();
817 while($attr = $ldap->fetch()){
818 $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0];
819 }
821 foreach($dhcp_dns as $key => $pri_dns){
822 $ldap->cat($pri_dns,array("cn"));
823 $tmp = $ldap->fetch();
824 if(isset($tmp['cn'][0])){
825 $dhcp_dns[$key] = $tmp['cn'][0];
826 }else{
827 unset($dhcp_dns[$key]);
828 }
829 }
831 $tmp = $tmp2 = array();
832 foreach($dhcp_dns as $dn => $cn){
833 $ldap->cd($dn);
834 $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)".
835 "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn"));
836 while($attr = $ldap->fetch()){
837 $tmp[$attr['dn']] = $attr['cn'][0];
838 }
839 $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") "));
840 }
841 return($tmp2);
842 }
845 /* this function returns the default ptr record entry */
846 function get_pTRRecord()
847 {
848 if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){
849 $ldap = $this->config->get_ldap_link();
850 $ldap->cat(getDNSZoneDN($this->config,$this->dnsEntry['zoneName']));
851 $attrs = $ldap->fetch();
852 $tmp = array_flip($this->Zones);
853 $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]);
854 $tmp = trim(preg_replace("/\.in-addr.arpa$/","",$tmp));
855 $ptr = preg_replace("/^".normalizePreg(FlipIp($tmp))."\./","",$this->ipHostNumber);
856 return($ptr);
857 }else{
858 return(FALSE);
859 }
860 }
863 function create_tree($arr,$base,$current = "")
864 {
865 $ret = array();
866 foreach($arr as $r => $name){
867 $base_part = str_replace($base,"",$r);
868 if(preg_match("/^[a-z]*=".normalizePreg($name)."(|,)$/i",$base_part)){
869 $ret[$r] = $current.$name;
870 $tmp = $this->create_tree($arr,$r,$current.". ");
871 foreach($tmp as $sub_key => $sub_name){
872 $ret[$sub_key] = $sub_name;
873 }
874 }
875 }
876 return($ret);
877 }
878 }
880 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
881 ?>