Code

Updated take over for dns zones
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 11 Sep 2007 07:34:59 +0000 (07:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 11 Sep 2007 07:34:59 +0000 (07:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7246 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDHCP.inc
plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/servdns.tpl

index 33c7acf77aa89e29a005434faa0d973d13917fa0..da5a12a289d495b0d930351b724dac0f9539b8fa 100644 (file)
@@ -55,12 +55,6 @@ class servdhcp extends plugin
   }
 
   
-  function take_over_service()
-  {
-    
-  }
-
-
   function get_list_of_dhcp_servers()
   {
     $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array());
index 703f3d30312a90ae909e1b2c58ddc2dc781c5fa4..44bfd42eaa978351307913b7e93c4007677dc5d1 100644 (file)
@@ -15,6 +15,9 @@ class servdns extends plugin
 
   var $DNSinitially_was_account;
 
+  var $dns_server_list   = array("ENTRIES"=> array(),"FOR_LIST"=> array());
+  var $take_over_id       = -1;
+
 
   function servdns ($config, $dn= NULL, $parent= NULL)
   {
@@ -34,6 +37,7 @@ class servdns extends plugin
      */
     if(count($this->Zones) == 0){
       $this->is_account = false;
+      $this->dns_server_list = $this->get_list_of_dns_servers();
     }else{
       $this->is_account = true;
     }
@@ -41,6 +45,50 @@ class servdns extends plugin
   }
 
 
+  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 
@@ -50,8 +98,50 @@ class servdns extends plugin
     /* Fill templating stuff 
      */
     $smarty= get_smarty();
+    $smarty->assign("dns_take_over",FALSE);
     $display= "";
 
+
+    /*****************/
+    /* 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->dhcp_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'])){
@@ -283,6 +373,34 @@ class servdns extends plugin
   /* 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']);  
   
index f9b0cb329f0bce538a2770622189d1969d2c6d6f..2b5300c1d5c6eb09c7fb56afe60d961062be2e02 100644 (file)
@@ -1,10 +1,42 @@
-<h2>{t}Zones{/t}</h2>
+{if $dns_take_over}
+<table summary="" width="100%">
+    <tr>
+        <td style="width:100%;vertical-align:top;">
+            <h2>{t}DNS take over initiated{/t}</h2>
+            {$warning}
+            {t}This includes 'all' DNS zones that are located within this server. Please double check if your really want to do this.{/t}
+            <p>
+            {$warning2}
+            <br>
+            <input type='submit' name='cancel_take_over' value='{t}Cancel{/t}'>
+            </p>
+            <p>
+            {t}Following objects will be taken over{/t}&nbsp;:
+            </p>
+            <p>
+            <pre>{$info}</pre>
+            </p>
+        </td>
+    </tr>
+</table>
+{else}
 <table summary="" width="100%">
+{if $dns_server_list_cnt}
+<tr>
+    <td style="width:100%;vertical-align:top;">
+        <b>{t}Take over DHCP configuration from{t}</b>&nbsp;
+        <select name='take_over_src'>
+            {html_options options=$dns_server_list}
+        </select>
+        <input type="submit" name="take_over" value="{t}Take over{/t}">
+    </td>
+</tr>
+{/if}
 <tr>
        <td style="width:100%;vertical-align:top;">
+<h2>{t}Zones{/t}</h2>
                {$ZoneList}
                <input type="submit" name="AddZone" value="{t}Add{/t}" {$servdnsACL}>
-<!--           <input type="submit" name="TakeOver" value="{t}Take over{/t}" {$servdnsACL}>-->
        </td>
 </tr>
 </table>
@@ -13,3 +45,4 @@
        focus_field('AddZone');
   -->
 </script>
+{/if}