summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9a12d81)
raw | patch | inline | side by side (parent: 9a12d81)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 2 Aug 2007 14:58:33 +0000 (14:58 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 2 Aug 2007 14:58:33 +0000 (14:58 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6959 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/plugins/admin/systems/class_dhcpAdvanced.inc b/plugins/admin/systems/class_dhcpAdvanced.inc
index e9a40c15bd38bac7e9e32edf64588d5d370b787d..271c4ed6e2f8b92a3501042f4ba6fa0292df3720 100644 (file)
/* Used attributes */
var $options= array();
var $statements= array();
+ var $show_advanced= FALSE;
+ var $autoStatements= array();
+ var $autoOptions= array();
/* attribute list for save action */
var $attributes= array();
{
/* This is always an account */
$this->is_account= TRUE;
+ $this->setAutoStatements();
+ $this->setAutoOptions();
}
function execute()
}
if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
$key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpstatements']);
- unset($this->statements[$key]);
+ if (in_array($key, $this->autoStatements)){
+ print_red(_("Can't delete automatic statements. Please use the fields above."));
+ } else {
+ unset($this->statements[$key]);
+ }
}
if (isset($_POST['add_option']) && $_POST['addoption'] != ""){
$key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['addoption']);
}
if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
$key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpoptions']);
- unset($this->options[$key]);
+ if (in_array($key, $this->autoOptions)){
+ print_red(_("Can't delete automatic options. Please use the fields above."));
+ } else {
+ unset($this->options[$key]);
+ }
}
$smarty= get_smarty();
/* Assign arrays */
$statements= array();
foreach ($this->statements as $key => $val){
- $statements[$key]= "$key $val";
+ if (in_array($key, $this->autoStatements)){
+ $statements[$key]= "$key $val ["._("automatic")."]";
+ } else {
+ $statements[$key]= "$key $val";
+ }
}
$smarty->assign("dhcpstatements", $statements);
$options= array();
foreach ($this->options as $key => $val){
- $options[$key]= "$key $val";
+ if (in_array($key, $this->autoOptions)){
+ $options[$key]= "$key $val ["._("automatic")."]";
+ } else {
+ $options[$key]= "$key $val";
+ }
}
$smarty->assign("dhcpoptions", $options);
/* Show main page */
+ $smarty->assign("show_advanced", $this->show_advanced);
return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE)));
}
/* Save data to object */
function save_object()
{
+ if (isset($_POST['show_advanced'])){
+ $this->show_advanced= TRUE;
+ }
+ if (isset($_POST['hide_advanced'])){
+ $this->show_advanced= FALSE;
+ }
}
{
}
+
+ function setAutoOptions($addopt= array())
+ {
+ $options= array("routers", "domain-name", "subnet-mask", "broadcast-address");
+ $this->autoOptions= array_merge($options, $addopt);
+ }
+
+
+ function setAutoStatements($addstat= array())
+ {
+ $statements= array("filename", "next-server", "get-lease-hostnames", "use-host-decl-names");
+ $this->autoStatements= array_merge($statements, $addstat);
+ }
+
}
?>
index 2f65738567d1c1b537f9e690cda01e5571fe2016..2c710f986a20c0604129dac3a9d2446846239d88 100644 (file)
{
/* Used attributes */
var $cn= "";
+ var $orig_cn= "";
var $dhcpHWAddress= "";
var $options= array();
var $statements= array();
- var $dn= "new";
+ var $dn= "";
/* Subobjects */
var $network;
function dhcpHost($attrs)
{
/* Load statements / options */
- if ($attrs != NULL){
- $this->dn= "";
+ if (is_array($attrs)){
+ $this->dn= $attrs['dn'];
+ $this->new= FALSE;
/* Load attributes */
foreach (array("cn", "dhcpHWAddress") as $attr){
}
}
+ } else {
+ /* We keep the parent dn here if it's new */
+ $this->dn= $attrs;
+ $this->new= TRUE;
}
/* Load network module */
$this->advanced= new dhcpAdvanced();
$this->advanced->options= $this->options;
$this->advanced->statements= $this->statements;
+ $this->advanced->setAutoStatements(array("fixed-address"));
+
+ /* Save CN for later reference */
+ $this->orig_cn= $this->cn;
}
function execute()
$smarty->assign("hwtypes", array("ethernet" => _("Ethernet"),
"fddi" => _("FDDI"),
"token-ring" => _("Token Ring")));
-
/* Show main page */
- return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute().$this->advanced->execute());
+ $display= $smarty->fetch(get_template_path('dhcphost.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();
+
+ /* Add footer */
+ $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
+ " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
+
+
+ return ($display);
}
unset ($this->statements['fixed-address']);
}
}
+
+ /* 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;
+ }
}
/* Check values */
- function check()
+ function check($cache)
{
$message= array();
}
/* cn already used? */
- if ($this->dn != "new"){
- # Ask parents container object
- echo "FIXME: Need to check container object!";
- $message[]= _("The name for this host section is already used!");
+ if ($this->orig_cn != $this->cn || $this->new){
+
+ foreach($cache as $dn => $dummy){
+ if (preg_match("/^cn=".$this->cn.",/", $dn)){
+ $message[]= _("The name for this host section is already used!");
+ break;
+ }
+ }
}
/* Check syntax of MAC address */
$message[]= _("The hardware address specified by you is not valid!");
}
+ /* Check external plugins */
+ $net= $this->network->check();
+ $adv= $this->advanced->check();
+ $message= array_merge($message, $net, $adv);
+
return $message;
}
/* Save to LDAP */
function save()
{
- echo "FIXME: Need to implement modified save()!";
- return;
-
- # If this->dn == "new", create new entry
- # If this->dn != "new", modify existing entry and place a "modifyied" inside to notify
- # the parent to move/handle it.
- # If CN has changed from former CN, empty out old entry and
- # create a new one.
-
- #-------------------------------- Not yet modified from this line on -------------------------------
-
- /* Generate new dn */
- if ($this->parent->parent != NULL){
- $this->dn= "cn=".$this->cn.",".$this->parent->parent;
- } else {
- $tmp= preg_replace('/^cn=[^,]+/', '', $this->dn);
- $this->dn= "cn=".$this->cn.$tmp;
+ /* 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;
}
- /* Get ldap mode */
- if ($this->orig_dn != $this->dn){
- $mode= "add";
+ /* Add cn if we're new */
+ if ($this->new){
+ $this->dn= "cn=".$this->cn.",".$this->dn;
} else {
- $mode= "modify";
+ $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
}
/* Assemble new entry - options */
foreach ($this->options as $key => $val){
$this->attrs['dhcpOption'][]= "$key $val";
}
- } else {
- if ($mode == "modify"){
- $this->attrs['dhcpOption']= array();
- }
}
/* Assemble new entry - statements */
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());
-
- /* Name changed? Remove orig? */
- if ($this->orig_dn != $this->dn && $this->orig_dn != "new"){
- echo "Remove old<br>";
- $ldap->rmdir($this->orig_dn);
- show_ldap_error($ldap->get_error());
- }
+ /* Move dn to the result */
+ $this->attrs['dn']= $this->dn;
+
+ return ($this->attrs);
}
}
diff --git a/plugins/admin/systems/class_dhcpNetwork.inc b/plugins/admin/systems/class_dhcpNetwork.inc
index c3d97de4936b9f06bc56faa7cd46bfdd23e77605..9cef322e7e4eb4611d56565e62c5399974d8a3ef 100644 (file)
*/
/* Options */
- foreach (array("routers" => "routers", "domain-name" => "domain") as $key => $val){
+ foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
+ "broadcast-address" => "broadcast_address") as $key => $val){
if ($_POST["$val"] == ''){
unset($this->options["$key"]);
}
}
- /* Netmask / Broadcast */
- foreach (array("subnet-mask" => "nm", "broadcast-address" => "bc")
- as $key => $val){
-
- $tmp= "";
- for ($i= 0; $i<4; $i++){
- $tmp.= $_POST["$val$i"].".";
- }
- if ($tmp == "...."){
- unset($this->options["$key"]);
- } else {
- $this->options["$key"]= preg_replace('/\.$/', '', $tmp);
- }
- }
-
/* Flags */
if (isset ($_POST['autohost'])){
$this->statements['get-lease-hostnames']= "true";
}
$tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
- list($n0,$n1,$n2,$n3)= split('\.', $tmp);
- for ($i= 0; $i<4; $i++){
- $name= "n$i";
- if (preg_match('/^[0-9]+$/', $$name)){
- $val= (int)($$name);
- if ($val < 0 || $val > 255){
- $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
- break;
- }
- } else {
- $message[]= sprintf(_("Illegal characters in definition of '%s'!"), $typ);
- break;
- }
+ if (!is_ip($tmp)){
+ $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
}
}
- #FIXME: There are some more things we could test -> valid netmask, range
return $message;
}
index e0bd6988e62d35827ac475527e002c7dca5cdae3..42dd962a3663964761ca69943781f91e30ef1d78 100644 (file)
if (isset($_POST['create_section']) && isset($_POST['section'])){
$section= $_POST['section'];
if (isset(dhcpNewSectionDialog::$sectionMap[$section])){
- $this->dialog= new $section(NULL);
+ $this->dialog= new $section($this->dn);
+ $this->current_object= "";
} else {
$this->dialog= NULL;
}
}
/* Cancel section creation? */
- if (isset($_POST['cancel_section'])){
+ if (isset($_POST['cancel_section']) || isset($_POST['cancel_dhcp'])){
$this->dialog= NULL;
}
+ /* Save changes */
+ if (isset($_POST['save_dhcp'])){
+ $this->dialog->save_object();
+ $messages= $this->dialog->check($this->dhcpObjectCache);
+ if (count($messages)){
+ show_errors($messages);
+ } else {
+ $dn= $this->dialog->dn;
+ $data= $this->dialog->save();
+ if ($this->current_object= ""){
+ echo "SAVE new entry";
+ } else {
+ if ($dn != $data['dn']){
+ echo "SAVE old entry with new dn";
+ } else {
+ echo "SAVE old entry";
+ }
+ }
+ }
+ }
+
/* Remove section? */
if (isset($_POST['delete_dhcp_confirm'])){
if (chkacl($this->acl, "delete") == ""){
$dn= base64_decode(preg_replace('/^editDhcp_([^_]+)_x$/', '\1', $name));
if (isset($this->dhcpObjectCache[$dn])){
$section= $this->objectType($dn);
+ $this->current_object= $dn;
$this->dialog= new $section($this->dhcpObjectCache[$dn]);
}
}
index e155a4ca9e94c51861e369abcb367dfe3e1a765c..5ce0e4600e822cc3699af112f3fb74875c72470d 100644 (file)
{* GOsa dhcp sharedNetwork - smarty template *}
+<p class='seperator'></p>
+<br>
+
+{if $show_advanced}
+
+<input type='submit' name='hide_advanced' value='{t}Hide advanced settings{/t}'>
+
<table width="100%">
<tr>
<br>
<b>{t}DHCP statements{/t}</b>
<br>
- <select name='dhcpstatements' style="width:350px;" size="14">
+ <select name='dhcpstatements' style="width:100%;" size="14">
{html_options values=$dhcpstatements output=$dhcpstatements}
</select>
<br>
<br>
<b>{t}DHCP options{/t}</b>
<br>
- <select name='dhcpoptions' style="width:350px;" size="14">
+ <select name='dhcpoptions' style="width:100%;" size="14">
{html_options values=$dhcpoptions output=$dhcpoptions}
</select>
<br>
</tr>
</table>
+{else}
+
+<input type='submit' name='show_advanced' value='{t}Show advanced settings{/t}'>
+
+{/if}
+<p class='seperator'> </p>
index dc1b1912a0183b81d8589431d4e2b2a13b1936ff..a2a2915e0a3c2323ad891603be583daa765497b1 100644 (file)
<p class="seperator"></p>
-<!-- Include network settings -->
-
-<!-- Include advanced settings -->
-
-
-<div style='background-color:#F09090;width:100%;height:20px;text-align:right'>
-Temporary escape:
-<input type=submit name="cancel_section" value="{t}Escape{/t}">
-</div>
-
<!-- Place cursor in correct field -->
<script language="JavaScript" type="text/javascript">
<!-- // First input field on page