From: cajus Date: Tue, 7 Aug 2007 14:21:18 +0000 (+0000) Subject: * Avoid removing of the service X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a1a3d93222452677760c9b2f8a122f81fe7ba017;p=gosa.git * Avoid removing of the service * Add first non working version of the service plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6989 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpGroup.inc b/plugins/admin/systems/class_dhcpGroup.inc index bce7875c8..04b750e06 100644 --- a/plugins/admin/systems/class_dhcpGroup.inc +++ b/plugins/admin/systems/class_dhcpGroup.inc @@ -71,7 +71,6 @@ class dhcpGroup extends plugin $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; diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index a88859c4d..00f43bb29 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -80,6 +80,7 @@ class dhcpHost extends plugin $this->network->statements= $this->statements; $this->advanced= new dhcpAdvanced(); $this->advanced->options= $this->options; + $this->advanced->setAutoOptions(array("host-name")); $this->advanced->statements= $this->statements; $this->advanced->setAutoStatements(array("fixed-address")); @@ -153,6 +154,7 @@ class dhcpHost extends plugin } else { unset ($this->statements['fixed-address']); } + $this->options['host-name']= $this->cn; } /* Strip network objects */ diff --git a/plugins/admin/systems/class_dhcpService.inc b/plugins/admin/systems/class_dhcpService.inc new file mode 100644 index 000000000..742c8ddae --- /dev/null +++ b/plugins/admin/systems/class_dhcpService.inc @@ -0,0 +1,280 @@ +dn= $attrs['dn']; + $this->new= FALSE; + + /* Load attributes */ + foreach (array("cn", "dhcpPrimaryDN") as $attr){ + if (isset($attrs[$attr][0])){ + $this->$attr= $attrs[$attr][0]; + } + } + + /* Load options */ + if (isset($attrs['dhcpOption'])){ + foreach ($attrs['dhcpOption'] as $opt){ + $idx= preg_replace('/\s.+$/', '', $opt); + $value= preg_replace('/^[^\s]+\s/', '', $opt); + $this->options[$idx]= $value; + } + } + + /* Load statements */ + if (isset($attrs['dhcpStatements'])){ + foreach ($attrs['dhcpStatements'] as $opt){ + $idx= preg_replace('/\s.+$/', '', $opt); + $value= preg_replace('/^[^\s]+\s/', '', $opt); + $this->statements[$idx]= $value; + } + } + + } else { + /* We keep the parent dn here if it's new */ + $this->dn= $attrs; + $this->new= TRUE; + } + + /* Load network module */ + $this->network= new dhcpNetwork(); + $this->network->options= $this->options; + $this->network->statements= $this->statements; + $this->advanced= new dhcpAdvanced(); + $this->advanced->options= $this->options; + $this->advanced->statements= $this->statements; + $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "server-name", "get-lease-hostnames", "server-identifier", "ddns-update-style")); + + /* Save for later action */ + $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN; + $this->orig_cn= $this->cn; + } + + function execute() + { + /* Show main page */ + $smarty= get_smarty(); + + $smarty->assign('ddns_styles', $this->ddns_styles); + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_service.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.= "
". + " 
"; + + + 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()); + + $ldap->cat($this->dhcpPrimaryDN); + $attrs= $ldap->fetch(); + $objectclasses= array(); + for($i= 0; $i<$attrs['objectClass']['count']; $i++){ + if ($attrs['objectClass'][$i] != "dhcpServer"){ + $objectclasses[]= $attrs['objectClass'][$i]; + } + } + $attrs= array(); + $attrs['dhcpServiceDN']= array(); + $attrs['objectClass']= $objectclasses; + $ldap->cd($this->dhcpPrimaryDN); + $ldap->modify($attrs); + 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(); + + /* Save base */ + if (isset($_POST['base'])){ + $this->base= $_POST['base']; + } + } + + + /* Check values */ + function check() + { + $message= array(); + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + if ($this->dhcpPrimaryDN == ""){ + $message[]= _("No server specified to host dhcp service!"); + } + + return $message; + } + + + /* Save to LDAP */ + function save() + { +echo "server-name"; +echo "server-identifier"; + plugin::save(); + + /* Get ldap mode */ + if ($this->dn == "new"){ + $mode= "add"; + $this->dn= "cn=".$this->cn.",ou=dhcp,ou=configs,ou=systems,".$this->base; + } else { + $mode= "modify"; + } + + /* 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()); + + /* Modify server entry to keep our 'dn' */ + $ldap->cat($this->dhcpPrimaryDN); + $attrs= $ldap->fetch(); + $objectclasses= array(); + for($i= 0; $i<$attrs['objectClass']['count']; $i++){ + if ($attrs['objectClass'][$i] != "dhcpServer"){ + $objectclasses[]= $attrs['objectClass'][$i]; + } + } + $objectclasses[]= "dhcpServer"; + $attrs= array(); + $attrs['dhcpServiceDN']= $this->dn; + $attrs['objectClass']= $objectclasses; + $ldap->cd($this->dhcpPrimaryDN); + $ldap->modify($attrs); + show_ldap_error($ldap->get_error()); + + /* Modify old server entry */ + if ( ($this->orig_dhcpPrimaryDN != "") + && ($this->orig_dhcpPrimaryDN != $this->dhcpPrimaryDN)){ + + $ldap->cat($this->orig_dhcpPrimaryDN); + $attrs= $ldap->fetch(); + if (isset($attrs['dhcpServiceDN'])){ + $objectclasses= array(); + for($i= 0; $i<$attrs['objectClass']['count']; $i++){ + if ($attrs['objectClass'][$i] != "dhcpServer"){ + $objectclasses[]= $attrs['objectClass'][$i]; + } + } + $attrs= array(); + $attrs['dhcpServiceDN']= array(); + $attrs['objectClass']= $objectclasses; + $ldap->cd($this->orig_dhcpPrimaryDN); + $ldap->modify($attrs); + show_ldap_error($ldap->get_error()); + } + } + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpSubnet.inc b/plugins/admin/systems/class_dhcpSubnet.inc index 28ed6b79c..3734e2d4e 100644 --- a/plugins/admin/systems/class_dhcpSubnet.inc +++ b/plugins/admin/systems/class_dhcpSubnet.inc @@ -87,7 +87,6 @@ class dhcpSubnet extends plugin $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; diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index 30ebc6f7c..c3ee2fbb5 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -215,14 +215,23 @@ class servdhcp extends plugin $editImgIns = "". "". ""; + $editImgInsNoDel = "". + ""; $editImg = "". ""; foreach($this->dhcpSections as $section => $values ){ if (count(dhcpNewSectionDialog::$sectionMap[$this->objectType($section)])){ - $DhcpList->AddEntry(array( + if ($this->objectType($section) == "dhcpService"){ + $DhcpList->AddEntry(array( + array("string" => $values), + array("string" => str_replace("%s",base64_encode($section),$editImgInsNoDel), "attach" => "style='text-align:right;'") + )); + } else { + $DhcpList->AddEntry(array( array("string" => $values), array("string" => str_replace("%s",base64_encode($section),$editImgIns), "attach" => "style='text-align:right;'") )); + } } else { $DhcpList->AddEntry(array( array("string" => $values), diff --git a/plugins/admin/systems/dhcp_service.tpl b/plugins/admin/systems/dhcp_service.tpl new file mode 100644 index 000000000..33d4fd904 --- /dev/null +++ b/plugins/admin/systems/dhcp_service.tpl @@ -0,0 +1,44 @@ +

{t}Generic{/t}

+ + + + + + + + +
+ {t}Autoritative service{/t}
+ {t}Assign hostnames via DNS{/t}
+
+ {t}Dynamic DNS update{/t} + +
+ + + + + + + + + + +
{t}Default lease time (s){/t} + +
{t}Maximum lease time (s){/t} + +
+ +
+ +

+ + +