Code

Added initial dhcp take over
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Sep 2007 07:54:29 +0000 (07:54 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Sep 2007 07:54:29 +0000 (07:54 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7232 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDHCP.inc
plugins/admin/systems/servdhcp.tpl

index 168d7a8e85d03bafa5b7c84029cf9166f8bfa60c..351e2112c7f993bde1e4d1933a57f94891c64cda 100644 (file)
@@ -19,6 +19,9 @@ class servdhcp extends plugin
 
   var $orig_dn = "";
 
+  var $dhcp_server_list   = array();
+  var $take_over_id       = -1;
+
   function servdhcp ($config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
@@ -49,6 +52,43 @@ class servdhcp extends plugin
       $this->is_account= FALSE;
     }
                
+    $this->dhcp_server_list = $this->get_list_of_dhcp_servers();
+  }
+
+  
+  function take_over_service()
+  {
+    
+  }
+
+
+  function get_list_of_dhcp_servers()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=goServer)(dhcpServiceDN=*))",array("dn","cn","dhcpServiceDN"));
+    while($attrs = $ldap->fetch()){
+      $ret['ENTRIES'][] = $attrs;
+    }
+    foreach($ret['ENTRIES'] as $key => $data){
+      $ret['FOR_LIST'][$key] = $data['cn'][0];
+    }
+    return($ret);
+  }  
+
+
+  function get_dhcp_info_string($id)
+  {
+    $ret = "";
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd("cn=dhcp,".$this->dhcp_server_list['ENTRIES'][$id]['dn']);
+    $ldap->search("(|(objectClass=dhcpSharedNetwork)(objectClass=dhcpSubnet)(objectClass=dhcpPool)(objectClass=dhcpGroup)(objectClass=dhcpHost))",array("dn","cn"));
+    $ldap->search("(objectClass=*)",array("dn","cn"));
+    while($attrs = $ldap->fetch()){
+      $ret .= $attrs['dn']."\n";
+    }
+    return($ret);
   }
 
 
@@ -59,8 +99,53 @@ class servdhcp 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("dhcp_server_list", $this->dhcp_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->dhcp_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->dhcp_server_list = $this->get_list_of_dhcp_servers();
+    }
+
+    /* Display informartion about take over that will be started when saving this server 
+     *  and hide default dhcp output
+     */
+    if($this->take_over_id != -1){
+      $this->dialog = FALSE;
+      $id = $this->take_over_id;
+      $info = $this->get_dhcp_info_string($id);
+      $smarty->assign("dns_take_over",TRUE);
+      $smarty->assign("info",$info);
+      $warning = sprintf(_("You are going to take over the dhcp setup from server '%s'."),$this->dhcp_server_list['ENTRIES'][$id]['cn'][0]);
+      $warning2 = _("The take over will be startet when you save this system. To abort this action, use the cancel button below."); 
+      $smarty->assign("warning",$warning);
+      $smarty->assign("warning2",$warning2);
+      return($smarty->fetch(get_template_path('servdhcp.tpl', TRUE)));
+    }
+
+    
+    /*****************/
+    /* List handling  
+    /*****************/
+
     /* Section Creation? */
     if (isset($_POST['create_section']) && isset($_POST['section'])){
       $section= $_POST['section'];
@@ -345,8 +430,21 @@ class servdhcp extends plugin
   /* Save to LDAP */
   function save()
   {
-    $ldap= $this->config->get_ldap_link();
+    /* Take over handling 
+     * - Load servdhcp class and dhcpObjectCache for the source dhcp setup.
+     * - Assign dhcpObjectCache to this configuration. 
+     * - Save this setup and remove source setup from ldap.
+     */
+    if($this->take_over_id != -1){
+      $id = $this->take_over_id;
+      $src = preg_replace("/cn=dhcp,/","",$this->dhcp_server_list['ENTRIES'][$id]['dn']);
+      $tmp = new servdhcp ($this->config, $src);
+      $this->orig_dn = $src;
+      $this->dhcpObjectCache =  $tmp->dhcpObjectCache;
+    }
 
+    /* Save dhcp setttings */
+    $ldap= $this->config->get_ldap_link();
     foreach ($this->dhcpObjectCache as $dn => $data){
 
       if($this->dn != $this->orig_dn){
@@ -441,7 +539,16 @@ class servdhcp extends plugin
     } else {
       $this->handle_post_events("add");
     }
+
+    /* Take over handling
+     * - Remove old dhcp config from source server 
+     */
+    if($this->take_over_id != -1){
+      $id = $this->take_over_id;
+      $src = $this->dhcp_server_list['ENTRIES'][$id]['dn'];
+      $tmp = new servdhcp ($this->config, $src);
+      $tmp->remove_from_parent();
+    }
   }
 
 
index 76739f150700d4718b8d26640c964f873bfcdadb..69331f271063e26bd92017569d1f53ac0436674f 100644 (file)
@@ -1,9 +1,41 @@
-<h2>{t}DHCP sections{/t}</h2>
+{if $dns_take_over}
 <table summary="" width="100%">
+       <tr>
+               <td style="width:100%;vertical-align:top;">
+                       <h2>{t}DHCP take over initiated{/t}</h2>
+                       {$warning}
+                       {t}This includes 'all' DHCP subsections 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%">
+<tr>
+       <td style="width:100%;vertical-align:top;">
+               <b>{t}Take over dhcp configuration from following server{/t}</b>&nbsp;
+               <select name='take_over_src'>
+                       {html_options options=$dhcp_server_list}
+               </select>
+               <input type="submit" name="take_over" value="{t}Apply{/t}">
+       </td>
+</tr>
 <tr>
        <td style="width:100%;vertical-align:top;">
+       <h2>{t}DHCP sections{/t}</h2>
                {$DhcpList}
 <!--           <input type="submit" name="takeOver" value="{t}Take over{/t}" {$dhcpACL}>-->
        </td>
 </tr>
 </table>
+{/if}