Code

Added dhcp and fixes -r7231:7236
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Sep 2007 09:34:56 +0000 (09:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Sep 2007 09:34:56 +0000 (09:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7237 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index c6cc177d58cbac72a574d9f5e2467e0d720c6179..7d7feb2c5db12024193ec3fc2b4e458c253bb231 100644 (file)
@@ -19,6 +19,9 @@ class servdhcp extends goService
 
   var $orig_dn = "";
 
+  var $dhcp_server_list   = array("ENTRIES"=> array(),"FOR_LIST"=> array());
+  var $take_over_id       = -1;
+
   function servdhcp ($config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
@@ -49,6 +52,7 @@ class servdhcp extends goService
     $this->reload(); 
     if (!count($this->dhcpSections)){
       $this->is_account= FALSE;
+      $this->dhcp_server_list = $this->get_list_of_dhcp_servers();
     }
   }
 
@@ -60,8 +64,54 @@ class servdhcp extends goService
 
     /* 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']);
+    $smarty->assign("dhcp_server_list_cnt", count($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 +395,21 @@ class servdhcp extends goService
   /* 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){
@@ -424,6 +487,11 @@ class servdhcp extends goService
       $this->dhcpServiceDN= preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$this->dhcpServiceDN);
     }
 
+    /* Replace 'new' dn */ 
+    if(preg_match("/new$/",$this->dhcpServiceDN)){
+      $this->dhcpServiceDN = preg_replace("/new$/",$this->dn,$this->dhcpServiceDN);
+    }
+
     plugin::save();
     
     /* Save data to LDAP */
@@ -441,7 +509,16 @@ class servdhcp extends goService
     } 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();
+    }
   }
 
 
@@ -566,6 +643,49 @@ class servdhcp extends goService
     ));
   }
 
+
+  function take_over_service()
+  {
+
+  }
+
+
+  function get_list_of_dhcp_servers()
+  {
+    $ret = array("ENTRIES"=> array(),"FOR_LIST"=> 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()){
+
+      /* Skip own config */
+      if($this->dn != "new" && preg_match("/".normalizePreg($this->dn)."$/",$attrs['dn'])){
+        continue;
+      }
+
+      $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);
+  }
+
+
   function getListEntry()
   {
     $fields               = goService::getListEntry();
index 0fc2bb51bb28fb3ed473cdf3defd7bbbaf415ed3..61a463cb522afe7233565c2df84e5c1478b49562 100644 (file)
@@ -44,9 +44,8 @@
               <tr>
                 <td>
                   <input type='checkbox' name='dummy' class='center' disabled>
-                  {t}Enable DHCP for this device{/t}
-                  <input type='image' src='images/list_reload.png' class='center'><br>
-                  <i>{t}No dhcp service present in your ldap database, you will have to setup the dhcp service first.{/t}</i>
+                  {t}Enable DHCP for this device{/t} ({t}not configured{/t})
+                  <input type='image' src='images/list_reload.png' class='center'>
                 </td>
               </tr>
               {/if}
       </div>
     {else}        
       <input type="checkbox" name="dummy" value="1" disabled class='center'>
-      {t}Enable DNS for this device{/t}
-      <input type='image' src='images/list_reload.png' class='center'><br>
-      <i>{t}No dns service present in your ldap database, you will have to setup the dns service first.{/t}</i>
+      {t}Enable DNS for this device{/t} ({t}not configured{/t})
+      <input type='image' src='images/list_reload.png' class='center'>
     {/if}
 
                </td>
index 25c8682dfafefecd362ac77208dc35402dfb4296..5d79af70c1919c9ba176a8884fdd5e8bf04eea13 100644 (file)
@@ -1,16 +1,48 @@
-<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%">
+{if $dhcp_server_list_cnt}
+<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>
+{/if}
 <tr>
-       <td style="width:100%;vertical-align:top;">
-               {$DhcpList}
-<!--           <input type="submit" name="takeOver" value="{t}Take over{/t}" >-->
-       </td>
+    <td style="width:100%;vertical-align:top;">
+    <h2>{t}DHCP sections{/t}</h2>
+        {$DhcpList}
+    </td>
 </tr>
 </table>
+{/if}
 <p class='seperator'>&nbsp;</p>
 <div style="width:100%; text-align:right;padding-top:10px;padding-bottom:3px;">
     <input type='submit' name='SaveService' value='{t}Save{/t}'>
     &nbsp;
     <input type='submit' name='CancelService' value='{t}Cancel{/t}'>
-</div>
-
+</div