From 17932d77f348776d6090bed67d60f79b32a1ecd5 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 10 Sep 2007 09:34:56 +0000 Subject: [PATCH] Added dhcp and fixes -r7231:7236 git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7237 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_servDHCP.inc | 124 ++++++++++++++++++++++- plugins/admin/systems/network.tpl | 10 +- plugins/admin/systems/servdhcp.tpl | 46 +++++++-- 3 files changed, 165 insertions(+), 15 deletions(-) diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index c6cc177d5..7d7feb2c5 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -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(); diff --git a/plugins/admin/systems/network.tpl b/plugins/admin/systems/network.tpl index 0fc2bb51b..61a463cb5 100644 --- a/plugins/admin/systems/network.tpl +++ b/plugins/admin/systems/network.tpl @@ -44,9 +44,8 @@ - {t}Enable DHCP for this device{/t} -
- {t}No dhcp service present in your ldap database, you will have to setup the dhcp service first.{/t} + {t}Enable DHCP for this device{/t} ({t}not configured{/t}) + {/if} @@ -129,9 +128,8 @@ {else} - {t}Enable DNS for this device{/t} -
- {t}No dns service present in your ldap database, you will have to setup the dns service first.{/t} + {t}Enable DNS for this device{/t} ({t}not configured{/t}) + {/if} diff --git a/plugins/admin/systems/servdhcp.tpl b/plugins/admin/systems/servdhcp.tpl index 25c8682df..5d79af70c 100644 --- a/plugins/admin/systems/servdhcp.tpl +++ b/plugins/admin/systems/servdhcp.tpl @@ -1,16 +1,48 @@ -

{t}DHCP sections{/t}

+{if $dns_take_over} + + + +
+

{t}DHCP take over initiated{/t}

+ {$warning} + {t}This includes 'all' DHCP subsections 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 $dhcp_server_list_cnt} + + + +{/if} - +
+ {t}Take over dhcp configuration from following server{/t}  + + +
- {$DhcpList} - - +

{t}DHCP sections{/t}

+ {$DhcpList} +
+{/if}

 

  -
- +