From: cajus Date: Fri, 3 Aug 2007 13:34:45 +0000 (+0000) Subject: Updated DHCP service X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=32689e1048292bd10c690efe9e4e612b544bda81;p=gosa.git Updated DHCP service git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6961 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index 2c710f986..cac159b2f 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -52,20 +52,24 @@ class dhcpHost extends plugin /* 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){ + 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'])){ - 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){ + if ($opt == "count"){ + continue; + } + $idx= preg_replace('/\s.+$/', '', $opt); + $value= preg_replace('/^[^\s]+\s/', '', $opt); $this->statements[$idx]= $value; } } @@ -119,6 +123,12 @@ class dhcpHost extends plugin $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.= "
". " 
"; @@ -179,7 +189,7 @@ class dhcpHost extends plugin if ($this->orig_cn != $this->cn || $this->new){ foreach($cache as $dn => $dummy){ - if (preg_match("/^cn=".$this->cn.",/", $dn)){ + if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){ $message[]= _("The name for this host section is already used!"); break; } @@ -218,16 +228,16 @@ class dhcpHost extends plugin } /* 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"; } } /* 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"; } @@ -235,6 +245,14 @@ class dhcpHost extends plugin /* Move dn to the result */ $this->attrs['dn']= $this->dn; + $this->attrs['cn']= array($this->cn); + if ($this->dhcpHWAddress != ""){ + $this->attrs['dhcpHWAddress']= array($this->dhcpHWAddress); + } else { + $this->attrs['dhcpHWAddress']= array(); + } + $this->attrs['objectClass']= array('top', 'dhcpHost'); + $this->attrs['MODIFIED']= TRUE; return ($this->attrs); } diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index 42dd962a3..752c5738e 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -11,11 +11,25 @@ class servdhcp extends plugin var $dhcpSections= array(); var $dhcpObjectCache= array(); var $current_object= ""; + var $types= array(); + var $serviceDN= ""; function servdhcp ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); + $this->types= array( "dhcpLog" => _("Logging"), + "dhcpService" => _("Global options"), + "dhcpClass" => _("Class"), + "dhcpSubClass" => _("Subclass"), + "dhcpLeases" => _("Lease"), + "dhcpHost" => _("Host"), + "dhcpGroup" => _("Group"), + "dhcpPool" => _("Pool"), + "dhcpSubnet" => _("Subnet"), + "dhcpFailOverPeer" => _("Failover peer"), + "dhcpSharedNetwork" => _("Shared network")); + /* Load information about available services */ $this->reload(); } @@ -34,7 +48,7 @@ class servdhcp extends plugin if (isset($_POST['create_section']) && isset($_POST['section'])){ $section= $_POST['section']; if (isset(dhcpNewSectionDialog::$sectionMap[$section])){ - $this->dialog= new $section($this->dn); + $this->dialog= new $section($this->current_object); $this->current_object= ""; } else { $this->dialog= NULL; @@ -54,16 +68,32 @@ class servdhcp extends plugin show_errors($messages); } else { $dn= $this->dialog->dn; + $class= get_class($this->dialog); + $type= $this->types[$class]; + $indent= substr_count(preg_replace("/".$this->serviceDN."/", '', $dn), ","); + $spaces= ""; + for ($i= 0; $i<$indent; $i++){ + $spaces.= "    "; + } $data= $this->dialog->save(); - if ($this->current_object= ""){ - echo "SAVE new entry"; + if ($this->current_object == ""){ + /* New object */ + $this->dhcpObjectCache[$data['dn']]= $data; + $spaces.= "    "; + $this->dhcpSections[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'"; } else { if ($dn != $data['dn']){ - echo "SAVE old entry with new 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'])."'"; } else { - echo "SAVE old entry"; + /* Old object, old name */ + $this->dhcpObjectCache[$data['dn']]= $data; } } + $this->dialog= NULL; } } @@ -206,10 +236,58 @@ class servdhcp extends plugin /* Save to LDAP */ function save() { - plugin::save(); + $ldap= $this->config->get_ldap_link(); + + foreach ($this->dhcpObjectCache as $dn => $data){ + + /* Remove entry? */ + if (count($data) == 0){ + /* Check if exists, then remove... */ + if($ldap->cat($dn)){ + $ldap->rmdir($dn); + show_ldap_error($ldap->get_error(), _("Can't remove DHCP object!")); + } + continue; + } + + /* Modify existing entry? */ + if (isset($data['MODIFIED'])){ - /* Optionally execute a command after we're done */ - #$this->handle_post_events($mode); + if($ldap->cat($dn)){ + $modify= TRUE; + } else { + $modify= FALSE; + } + + /* Build new entry */ + $attrs= array(); + foreach ($data as $attribute => $values){ + if ($attribute == "MODIFIED" || $attribute == "dn"){ + continue; + } + if (count($values)){ + if (count($values) == 1){ + $attrs[$attribute]= $values[0]; + } else { + $attrs[$attribute]= $values; + } + } else { + if ($modify){ + $attrs[$attribute]= array(); + } + } + } + + $ldap->cd($dn); + if ($modify){ + $ldap->modify($attrs); + show_ldap_error($ldap->get_error(), _("Can't save DHCP object!")); + } else { + $ldap->add($attrs); + show_ldap_error($ldap->get_error(), _("Can't save DHCP object!")); + } + } + } } @@ -234,28 +312,24 @@ 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()); + $this->serviceDN= $value['dn']; while ($attrs= $ldap->fetch()){ - $this->dhcpObjectCache[$ldap->getDN()]= $attrs; - $tmp= preg_replace("/".$value['dn']."/", "", $ldap->getDN()); + $sattrs= array(); + for ($i= 0; $i<$attrs['count']; $i++){ + $sattrs[$attrs[$i]]= $attrs[$attrs[$i]]; + unset($sattrs[$attrs[$i]]['count']); + } + $sattrs['dn']= $ldap->getDN(); + $this->dhcpObjectCache[$ldap->getDN()]= $sattrs; + $tmp= preg_replace("/".$this->serviceDN."/", "", $ldap->getDN()); $indent= substr_count($tmp, ","); $spaces= ""; for ($i= 0; $i<$indent; $i++){ $spaces.= "    "; } - $types= array( "dhcpLog" => _("Logging"), - "dhcpService" => _("Global options"), - "dhcpClass" => _("Class"), - "dhcpSubClass" => _("Subclass"), - "dhcpLeases" => _("Lease"), - "dhcpHost" => _("Host"), - "dhcpGroup" => _("Group"), - "dhcpPool" => _("Pool"), - "dhcpSubnet" => _("Subnet"), - "dhcpFailOverPeer" => _("Failover peer"), - "dhcpSharedNetwork" => _("Shared network")); - foreach ($types as $key => $val){ + foreach ($this->types as $key => $val){ if (in_array("$key", $attrs['objectClass'])){ $type= $val; break;