From: hickert Date: Tue, 11 Sep 2007 10:23:53 +0000 (+0000) Subject: Added dns take over X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=91aca4d86548e4878add5cb20337a30974849a3f;p=gosa.git Added dns take over git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7253 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc index ae6d5999b..89d2f3f36 100644 --- a/plugins/admin/systems/class_servDNS.inc +++ b/plugins/admin/systems/class_servDNS.inc @@ -28,6 +28,10 @@ class servdns extends goService var $StatusFlag = ""; var $view_logged = FALSE; + var $dns_server_list = array("ENTRIES"=> array(),"FOR_LIST"=> array()); + var $take_over_id = -1; + + function servdns ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); @@ -48,6 +52,7 @@ class servdns extends goService */ if(count($this->Zones) == 0){ $this->is_account = false; + $this->dns_server_list = $this->get_list_of_dns_servers(); }else{ $this->is_account = true; } @@ -55,6 +60,50 @@ class servdns extends goService } + function get_list_of_dns_servers() + { + $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array()); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=dNSZone)(zoneName=*))",array("dn","zoneName")); + $dns = array(); + while($attrs = $ldap->fetch()){ + /* Skip own config */ + if($this->dn != "new" && preg_match("/".normalizePreg($this->dn)."$/",$attrs['dn'])){ + continue; + } + $dn = preg_replace("/^zoneName=[^,]+,/","",$attrs['dn']); + if(preg_match("/^cn=/",$dn) && !in_array($dn,$dns)){ + $dns[] = $dn; + } + } + $i = 0; + foreach($dns as $dn){ + $ldap->cat($dn,array('*')); + if($ldap->count()){ + $i ++; + $attrs = $ldap->fetch(); + $ret['ENTRIES'][$i] = $attrs; + $ret['FOR_LIST'][$i] = $attrs['cn'][0]; + } + } + return($ret); + } + + + function get_dns_info_string($id) + { + $ret=""; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dns_server_list['ENTRIES'][$id]['dn']); + $ldap->search("(|(zoneName=*)(relativeDomainName=*))",array("dn")); + while($attrs = $ldap->fetch()){ + $ret .= $attrs['dn']."\n"; + } + return($ret); + } + + function execute() { /* Call parent execute @@ -69,9 +118,52 @@ class servdns extends goService /* Fill templating stuff */ $smarty= get_smarty(); + $smarty->assign("dns_take_over",FALSE); $smarty->assign("is_createable",$this->acl_is_createable()); $display= ""; + + $this->initially_was_account= $this->is_account; + /*****************/ + /* Handle Take Over Actions + /*****************/ + + /* Give smarty the required informations */ + $smarty->assign("dns_server_list", $this->dns_server_list['FOR_LIST']); + $smarty->assign("dns_server_list_cnt", count($this->dns_server_list['FOR_LIST'])); + + /* Take over requested, save id */ + if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){ + $id = $_POST['take_over_src']; + if(isset($this->dns_server_list['ENTRIES'][$id])){ + $this->take_over_id = $id; + } + } + + /* Abort take over action */ + if(isset($_POST['cancel_take_over'])){ + $this->dialog =false; + $this->take_over_id = -1; + $this->dns_server_list = $this->get_list_of_dns_servers(); + } + + /* Display informartion about take over that will be started when saving this server + * and hide default dns output + */ + if($this->take_over_id != -1){ + $this->dialog = FALSE; + $id = $this->take_over_id; + $info = $this->get_dns_info_string($id); + $smarty->assign("dns_take_over",TRUE); + $smarty->assign("info",$info); + $warning = sprintf(_("You are going to migrate the DNS setup from server '%s'."),$this->dns_server_list['ENTRIES'][$id]['cn'][0]); + $warning2 = _("The migration will be startet when you save this system. To cancel this action, use the cancel button below."); + $smarty->assign("warning",$warning); + $smarty->assign("warning2",$warning2); + return($smarty->fetch(get_template_path('servdns.tpl', TRUE))); + } + + /* Do we need to flip is_account state? */ if (isset($_POST['modify_state'])){ @@ -301,6 +393,34 @@ class servdns extends goService /* Save to LDAP */ function save() { + + /* Take over handling + * - Create list of zones managed by source server + * - Copy ldap entries to destination server + * - Remove old zone entries from source + */ + if($this->take_over_id != -1){ + $del = array(); + $id = $this->take_over_id; + $src = $this->dns_server_list['ENTRIES'][$id]['dn']; + $ldap = $this->config->get_ldap_link(); + $ldap->ls("(objectClass=dnsZone)",$src,array('cn')); + while($attrs = $ldap->fetch()){ + $src_zone = $attrs['dn']; + $dst_zone = preg_replace("/".normalizePreg($src)."$/",$this->dn,$src_zone); + $res = plugin::recursive_move($src_zone, $dst_zone); + + if($res){ + $del [] = $src_zone; + } + } + foreach($del as $src_zone){ + $ldap->rmdir_recursive($src_zone); + } + return; + } + + $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); diff --git a/plugins/admin/systems/servdns.tpl b/plugins/admin/systems/servdns.tpl index d19027c72..26a78341e 100644 --- a/plugins/admin/systems/servdns.tpl +++ b/plugins/admin/systems/servdns.tpl @@ -1,22 +1,58 @@ -

{t}Zones{/t}

+{if $dns_take_over} + + + + +
+

{t}DNS take over initiated{/t}

+ {$warning} + {t}This includes 'all' DNS zones that are located within this server. Please double check if your really want to do this.{/t} +

+ {$warning2} +
+ +

+

+ {t}Following objects will be taken over{/t} : +

+

+

{$info}
+

+
+{else} +{if $dns_server_list_cnt} + + + +{/if} - +
+ {t}Take over DHCP configuration from{/t}  + + +
- {$ZoneList} - {if $is_createable} - - {else} - - {/if} - +

{t}Zones{/t}

+ {$ZoneList} + {if $is_createable} + + {else} + + {/if} +
+ + +{/if}