From: cajus Date: Tue, 7 Aug 2007 12:21:20 +0000 (+0000) Subject: Updated dhcp stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c2fb95d8e0db9a9f5539f9373498150c43e38485;p=gosa.git Updated dhcp stuff git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6986 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index a6d10b73e..a88859c4d 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -140,8 +140,6 @@ class dhcpHost extends plugin /* Save data to object */ function save_object() { - plugin::save_object(); - /* Save remaining attributes */ if (isset($_POST['hwtype'])){ diff --git a/plugins/admin/systems/class_dhcpSubnet.inc b/plugins/admin/systems/class_dhcpSubnet.inc index 316763fe6..28ed6b79c 100644 --- a/plugins/admin/systems/class_dhcpSubnet.inc +++ b/plugins/admin/systems/class_dhcpSubnet.inc @@ -23,10 +23,17 @@ class dhcpSubnet extends plugin /* Used attributes */ var $cn= ""; var $orig_cn= ""; - var $dhcpNetMask= ""; + var $dhcpNetMask= 24; var $dhcpRange= ""; + var $range_start= ""; + var $range_stop= ""; var $options= array(); var $statements= array(); + var $use_range= FALSE; + + /* Subobjects */ + var $network; + var $advanced; /* attribute list for save action */ var $attributes= array(); @@ -36,7 +43,7 @@ class dhcpSubnet extends plugin { if (is_array($attrs)){ $this->dn= $attrs['dn']; - $this->new= FALSE; + /* Load attributes */ foreach (array("cn", "dhcpNetMask", "dhcpRange") as $attr){ @@ -44,6 +51,10 @@ class dhcpSubnet extends plugin $this->$attr= $attrs[$attr][0]; } } + if (isset($attrs['dhcpRange'])){ + $this->use_range= TRUE; + list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange); + } /* Load options */ if (isset($attrs['dhcpOption'])){ @@ -86,160 +97,162 @@ class dhcpSubnet extends plugin function execute() { - $smarty= get_smarty(); - $smarty->assign("cn", $this->cn); - - if ($this->dn != "new"){ - $smarty->assign("mode", "readonly"); - - list($na0, $na1, $na2, $na3)= split('\.', $this->cn); - for ($i= 0; $i<4; $i++){ - $name= "na$i"; - $smarty->assign("na$i", $$name); - } - - /* Assign netmask */ - list($nm0, $nm1, $nm2, $nm3)= split('\.', $this->dhcpNetMask); - for ($i= 0; $i<4; $i++){ - $name= "nm$i"; - $smarty->assign("nm$i", $$name); - } - - /* Prepare range */ - if ($this->dhcpRange != ""){ - list($r1, $r2)= preg_split('/\s+/', $this->dhcpRange); - list($r00, $r01, $r02, $r03)= split('\.', $r1); - for ($i= 0; $i<4; $i++){ - $name= "r0$i"; - $smarty->assign("r0$i", $$name); - } - list($r10, $r11, $r12, $r13)= split('\.', $r2); - for ($i= 0; $i<4; $i++){ - $name= "r1$i"; - $smarty->assign("r1$i", $$name); - } - } - } - - /* Show main page */ - return $smarty->fetch (get_template_path('dhcp_subnet.tpl', TRUE)); + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("dhcp_netmask", $this->dhcpNetMask); + + /* Prepare range */ + if ($this->use_range){ + $smarty->assign("use_range", "checked"); + $smarty->assign("range_disabled", ""); + } else { + $smarty->assign("use_range", ""); + $smarty->assign("range_disabled", "disabled"); + } + $smarty->assign("range_start", $this->range_start); + $smarty->assign("range_stop", $this->range_stop); + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_subnet.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $tmp= array_merge($this->$type, $this->network->$type); + $this->advanced->$type= $tmp; + } + + $display.= $this->advanced->execute(); + + /* Merge back for removals */ + foreach (array("options", "statements") as $type){ + $this->$type= $this->advanced->$type; + $this->network->$type= $this->advanced->$type; + } + + /* Add footer */ + $display.= "
". + " 
"; + + /* Show main page */ + return $display; } + function remove_from_parent() { - /* Just remove the dn from the ldap, then we're done. Host - entries do not have any entries below themselfes. */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->recursive_remove(); - show_ldap_error($ldap->get_error()); - - /* Optionally execute a command after we're done */ - $this->postremove(); } /* Save data to object */ function save_object() { - plugin::save_object(); + if (isset($_POST['cn'])){ + $this->cn= validate($_POST['cn']); + } + if (isset($_POST['dhcp_netmask'])){ + $this->dhcpNetMask= validate($_POST['dhcp_netmask']); + } + if (isset($_POST['use_range'])){ + $this->use_range= TRUE; + $this->range_start= validate($_POST['range_start']); + $this->range_stop= validate($_POST['range_stop']); + } else { + $this->use_range= FALSE; + } + + /* Save sub-objects */ + $this->network->save_object(); + $this->advanced->save_object(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $tmp= array_merge($this->$type, $this->network->$type); + $this->advanced->$type= $tmp; + } - if (isset($_POST['na0'])){ - $this->cn= $_POST['na0'].".".$_POST['na1'].".".$_POST['na2'].".".$_POST['na3']; - $this->dhcpNetMask= $_POST['nm0'].".".$_POST['nm1'].".".$_POST['nm2'].".".$_POST['nm3']; - $this->dhcpRange= $_POST['r00'].".".$_POST['r01'].".".$_POST['r02'].".".$_POST['r03']." ".$_POST['r10'].".".$_POST['r11'].".".$_POST['r12'].".".$_POST['r13']; - } } /* Check values */ - function check() + function check($cache) { - $message= array(); - - /* All required fields are set? */ - if ($this->cn == ""){ - $message[]= _("Required field 'Network address' is not filled."); - } - if ($this->dhcpNetMask == ""){ - $message[]= _("Required field 'Netmask' is not filled."); - } - - /* cn already used? */ - if ($this->dn != "new"){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=dhcpSubnet)(cn=".$this->cn."))"); - if ($ldap->count() >= 1){ - while ($attrs= $ldap->fetch()){ - if ($ldap->getDN() != $this->dn){ - $message[]= _("The network defined in this section is already used!"); - break; - } - - } - } - $ldap->fetch(); - } - - #FIXME: There are some more things we could test -> valid netmask, range - return $message; + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Network address' is not filled."); + } + if ($this->dhcpNetMask == ""){ + $message[]= _("Required field 'Netmask' is not filled."); + } + + /* cn already used? */ + if ($this->orig_cn != $this->cn || $this->new){ + + foreach($cache as $dn => $dummy){ + if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){ + $message[]= _("The name for this section is already used!"); + break; + } + } + } + + /* IP's? */ + foreach(array('dhcpNetMask' => _("Netmask"), 'cn' => _("Network address"), 'range_start' => _("Range"), 'range_stop' => _("Range")) as $attr => $str){ + if ($this->$attr != "" && !is_ip($this->$attr)){ + print_red(sprintf(_("The field '%s' contains an invalid IP address"), $str)); + } + } + + return $message; } /* Save to LDAP */ function save() { - plugin::save(); - - /* Get ldap mode */ - if ($this->dn == "new"){ - $mode= "add"; - } else { - $mode= "modify"; - } - - /* Generate new dn */ - if ($this->parent->parent != NULL && $this->dn == "new"){ - $this->dn= "cn=".$this->cn.",".$this->parent->parent; - } + /* Merge arrays for network and advanced view */ + foreach (array("options", "statements") as $type){ + $tmp= array_merge($this->$type, $this->network->$type, $this->advanced->$type); + $this->$type= $tmp; + } - /* Reconvert netmask to number of filled bits */ - $this->attrs['dhcpNetMask']= netmask_to_bits($this->dhcpNetMask); - - /* Assemble new entry - options */ - if (isset ($this->options) && count ($this->options)){ - $this->attrs['dhcpOption']= array(); - foreach ($this->options as $key => $val){ - $this->attrs['dhcpOption'][]= "$key $val"; - } - } else { - if ($mode == "modify"){ - $this->attrs['dhcpOption']= array(); - } - } - - /* Assemble new entry - statements */ - if (isset ($this->statements) && count ($this->statements)){ - $this->attrs['dhcpStatements']= array(); - foreach ($this->statements as $key => $val){ - $this->attrs['dhcpStatements'][]= "$key $val"; - } - } else { - if ($mode == "modify"){ - $this->attrs['dhcpStatements']= array(); - } - } - - /* Do LDAP action */ - $ldap= $this->config->get_ldap_link(); - if ($mode == "add"){ - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); - } - $ldap->cd($this->dn); - $ldap->$mode($this->attrs); - show_ldap_error($ldap->get_error()); + /* Add cn if we're new */ + if ($this->new){ + $this->dn= "cn=".$this->cn.",".$this->dn; + } else { + $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn); + } + + /* Assemble new entry - options */ + $this->attrs['dhcpOption']= array(); + if (isset ($this->options) && count ($this->options)){ + foreach ($this->options as $key => $val){ + $this->attrs['dhcpOption'][]= "$key $val"; + } + } + + /* Assemble new entry - statements */ + $this->attrs['dhcpStatements']= array(); + if (isset ($this->statements) && count ($this->statements)){ + foreach ($this->statements as $key => $val){ + $this->attrs['dhcpStatements'][]= "$key $val"; + } + } + + /* Move dn to the result */ + $this->attrs['dn']= $this->dn; + $this->attrs['cn']= array($this->cn); + $this->attrs['dhcpNetMask']= array(netmask_to_bits($this->dhcpNetMask)); + if ($this->dhcpRange != ""){ + $this->attrs['dhcpRange']= array($this->range_start." ".$this->range_stop); + } else { + $this->attrs['dhcpRange']= array(); + } + $this->attrs['objectClass']= array('top', 'dhcpSubnet', 'dhcpOptions'); + $this->attrs['MODIFIED']= TRUE; + + return ($this->attrs); } } diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index 37988c3a3..f4749767e 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -22,7 +22,6 @@ class servdhcp extends plugin "dhcpService" => _("Global options"), "dhcpClass" => _("Class"), "dhcpSubClass" => _("Subclass"), - "dhcpLeases" => _("Lease"), "dhcpHost" => _("Host"), "dhcpGroup" => _("Group"), "dhcpPool" => _("Pool"), @@ -334,7 +333,7 @@ class servdhcp extends plugin /* Read all sub entries to place here */ $ldap->cd($value['dn']); - $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpLeases)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array()); + $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array()); $this->serviceDN= $value['dn']; while ($attrs= $ldap->fetch()){ diff --git a/plugins/admin/systems/dhcp_network.tpl b/plugins/admin/systems/dhcp_network.tpl index b00ed71c5..a392861b7 100644 --- a/plugins/admin/systems/dhcp_network.tpl +++ b/plugins/admin/systems/dhcp_network.tpl @@ -1,10 +1,8 @@ {* GOsa dhcp sharedNetwork - smarty template *} -
- {t}Network base configuration{/t} -
+

{t}Network configuration{/t}

@@ -28,7 +26,7 @@
{t}Router{/t}


- {t}Bootup{/t} +

{t}Bootup{/t}

@@ -48,8 +46,7 @@
{t}Filename{/t} - {t}Domain Name Service{/t} -
+

{t}Domain Name Service{/t}

@@ -73,8 +70,7 @@
{t}Domain{/t}
-
- {t}Domain Name Service options{/t}
+

{t}Domain Name Service options{/t}

{t}Assign hostnames found via reverse mapping{/t}
{t}Assign hostnames from host declarations{/t} diff --git a/plugins/admin/systems/dhcp_subnet.tpl b/plugins/admin/systems/dhcp_subnet.tpl index 8a68a2b76..9174d152a 100644 --- a/plugins/admin/systems/dhcp_subnet.tpl +++ b/plugins/admin/systems/dhcp_subnet.tpl @@ -1,47 +1,41 @@ {* GOsa dhcp subnet - smarty template *} -
+

{t}Generic{/t}

- - +
- {t}Network address{/t}{$must}  - . - . - . - + + + + + + + + +
{t}Network address{/t}{$must}
{t}Netmask{/t}{$must}
- {t}Netmask{/t}{$must}  - . - . - . - + + + + + + + + + - -
{t}Range for dynamic address assignement{/t}
  +  -  +
- -

 

- - - - +
- {t}Range for dynamic address assignement{/t}  - . - . - . -  -  - . - . - . - +
-
+