summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 70dadae)
raw | patch | inline | side by side (parent: 70dadae)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 6 Aug 2007 15:22:24 +0000 (15:22 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 6 Aug 2007 15:22:24 +0000 (15:22 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6972 594d385d-05f5-0310-b6e9-bd551577e9d8
index 8560650cd50d87a3297cc4450d7699287f442591..bce7875c8e57297015d6dbc1632202650aba30e5 100644 (file)
/* Load statements / options */
if (is_array($attrs)){
$this->dn= $attrs['dn'];
+ $this->cn= $attrs['cn'][0];
$this->new= FALSE;
-
/* Load options */
if (isset($attrs['dhcpOption'])){
- for($i= 0; $i<$attrs['dhcpOption']['count']; $i++){
- $tmp= $attrs['dhcpOption'][$i];
- $idx= preg_replace('/\s.+$/', '', $tmp);
- $value= preg_replace('/^[^\s]+\s/', '', $tmp);
+ 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'])){
- for($i= 0; $i<$attrs['dhcpStatements']['count']; $i++){
- $tmp= $attrs['dhcpStatements'][$i];
- $idx= preg_replace('/\s.+$/', '', $tmp);
- $value= preg_replace('/^[^\s]+\s/', '', $tmp);
+ foreach ($attrs['dhcpStatements'] as $opt){
+ $idx= preg_replace('/\s.+$/', '', $opt);
+ $value= preg_replace('/^[^\s]+\s/', '', $opt);
$this->statements[$idx]= $value;
}
}
$smarty= get_smarty();
$smarty->assign("cn", $this->cn);
- if ($this->dn != "new"){
- $smarty->assign("mode", "readonly");
- }
-
/* Show main page */
$display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE)).$this->network->execute();
/* Save data to object */
function save_object()
{
+ /* Save cn */
+ if (isset($_POST['cn'])){
+ $this->cn= validate($_POST['cn']);
+ }
+
/* Save sub-objects */
$this->network->save_object();
$this->advanced->save_object();
/* Check values */
- function check()
+ function check($cache)
{
$message= array();
if ($this->cn == ""){
$message[]= _("Required field 'Name' is not filled.");
}
-
- /* cn already used? */
- echo "TODO: no ldap check";
- if ($this->dn != "new"){
- $ldap= $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=dhcpGroup)(cn=".$this->cn."))");
- if ($ldap->count() >= 1){
- while ($attrs= $ldap->fetch()){
- if ($ldap->getDN() != $this->dn){
- $message[]= _("The name for this group section is already used!");
- break;
- }
-
- }
- }
- $ldap->fetch();
+ if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){
+ $message[]= _("Field 'Name' contains illegal characters.");
}
return $message;
/* Save to LDAP */
function save()
{
- echo "TODO: save";
- return;
-
- /* Get ldap mode */
- if ($this->dn == "new"){
- $mode= "add";
- } else {
- $mode= "modify";
+ /* 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;
}
- /* Generate new dn */
- if ($this->parent->parent != NULL && $this->dn == "new"){
- $this->dn= "cn=".$this->cn.",".$this->parent->parent;
+ /* 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)){
- $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 */
+ $this->attrs['dhcpStatements']= array();
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());
+ /* Move dn to the result */
+ $this->attrs['dn']= $this->dn;
+ $this->attrs['cn']= array($this->cn);
+ $this->attrs['objectClass']= array('top', 'dhcpGroup', 'dhcpOptions');
+ $this->attrs['MODIFIED']= TRUE;
+
+ return ($this->attrs);
}
+
}
?>
index 499e417fc51428287d13509650d9a0d40c0293de..a6d10b73efe58a57c0107dee1366b3ecd1414e38 100644 (file)
/* Load options */
if (isset($attrs['dhcpOption'])){
foreach ($attrs['dhcpOption'] as $opt){
- if ($opt == "count"){
- continue;
- }
$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){
- if ($opt == "count"){
- continue;
- }
$idx= preg_replace('/\s.+$/', '', $opt);
$value= preg_replace('/^[^\s]+\s/', '', $opt);
$this->statements[$idx]= $value;
index 752c5738ef84202541e53384c1ab15cf2ed8aff0..37988c3a3c83707096bcc31e8f179c07ae046de3 100644 (file)
if ($dn != $data['dn']){
/* Old object, new name */
$this->dhcpObjectCache[$dn]= array();
- unset($this->dhcpSections[$dn]);
$this->dhcpObjectCache[$data['dn']]= $data;
- $this->dhcpSections[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'";
+
+ /* If we renamed a section, we've to rename a couple of objects, too */
+ foreach ($this->dhcpObjectCache as $key => $dsc){
+ if (preg_match("/,$dn$/", $key)){
+ $new_dn= preg_replace("/,$dn$/", ",".$data['dn'], $key);
+ $dsc['MODIFIED']= TRUE;
+ $this->dhcpObjectCache[$new_dn]= $dsc;
+ unset($this->dhcpObjectCache[$key]);
+ }
+ }
+ $newsects= array();
+ foreach ($this->dhcpSections as $key => $dsc){
+ if ($key == $dn){
+ $newsects[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'";
+ continue;
+ }
+ if (preg_match("/,$dn$/", $key)){
+ $new_dn= preg_replace("/,$dn$/", ",".$data['dn'], $key);
+ $newsects[$new_dn]= $dsc;
+ } else {
+ $newsects[$key]= $dsc;
+ }
+ }
+ $this->dhcpSections= $newsects;
+
} else {
/* Old object, old name */
$this->dhcpObjectCache[$data['dn']]= $data;
if (count($data) == 0){
/* Check if exists, then remove... */
if($ldap->cat($dn)){
- $ldap->rmdir($dn);
+ $ldap->rmdir_recursive($dn);
show_ldap_error($ldap->get_error(), _("Can't remove DHCP object!"));
}
continue;
index d3725178a95cd35f22f100f6d7f9b0b0073c1a72..3d6a4d15d33a7fe95a372eae47101793403ff32f 100644 (file)
</td>
<td>
<input type='text' name='cn' size='25' maxlength='80' value='{$cn}'
- {$mode} title='{t}Name of group{/t}'>
+ title='{t}Name of group{/t}'>
</td>
</tr>
</table>