From: cajus Date: Wed, 8 Aug 2007 15:47:30 +0000 (+0000) Subject: Updated dhcp classes X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=aaf3d4bcac6fe5237fbe7937986f3392c852f2c6;p=gosa.git Updated dhcp classes git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7006 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpGroup.inc b/plugins/admin/systems/class_dhcpGroup.inc index 04b750e06..7a412665c 100644 --- a/plugins/admin/systems/class_dhcpGroup.inc +++ b/plugins/admin/systems/class_dhcpGroup.inc @@ -18,62 +18,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -class dhcpGroup extends plugin +class dhcpGroup extends dhcpPlugin { - /* Used attributes */ - var $cn= ""; - var $options= array(); - var $statements= array(); - var $orig_cn= ""; - var $network; - var $advanced; - /* attribute list for save action */ - var $attributes= array(); - var $objectclasses= array(); + var $objectclasses= array('top', 'dhcpGroup', 'dhcpOptions'); function dhcpGroup($attrs) { /* 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'])){ - 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; - - /* Save CN for later reference */ - $this->orig_cn= $this->cn; + dhcpPlugin::dhcpPlugin($attrs); } function execute() @@ -120,15 +73,8 @@ class dhcpGroup extends plugin $this->cn= validate($_POST['cn']); } - /* 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; - } + /* Handle global saving */ + dhcpPlugin::save_object(); } @@ -145,6 +91,18 @@ class dhcpGroup extends plugin $message[]= _("Field 'Name' contains illegal characters."); } + /* 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 host section is already used!"); + break; + } + } + } + + return $message; } @@ -152,41 +110,7 @@ class dhcpGroup extends plugin /* Save to LDAP */ function save() { - /* 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; - } - - /* 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['objectClass']= array('top', 'dhcpGroup', 'dhcpOptions'); - $this->attrs['MODIFIED']= TRUE; - + dhcpPlugin::save(); return ($this->attrs); } diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index 00f43bb29..ffc20e00c 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -18,74 +18,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -class dhcpHost extends plugin +class dhcpHost extends dhcpPlugin { /* Used attributes */ - var $cn= ""; - var $orig_cn= ""; var $dhcpHWAddress= ""; - var $options= array(); - var $statements= array(); - var $dn= ""; - - /* Subobjects */ - var $network; - var $advanced; /* attribute list for save action */ - var $attributes= array(); - var $objectclasses= array(); + var $objectclasses= array("top", "dhcpHost"); function dhcpHost($attrs) { - /* Load statements / options */ - if (is_array($attrs)){ - $this->dn= $attrs['dn']; - $this->new= FALSE; + dhcpPlugin::dhcpPlugin($attrs); + if (!$this->new){ /* Load attributes */ foreach (array("cn", "dhcpHWAddress") 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->setAutoOptions(array("host-name")); - $this->advanced->statements= $this->statements; $this->advanced->setAutoStatements(array("fixed-address")); - - /* Save CN for later reference */ - $this->orig_cn= $this->cn; } function execute() @@ -157,23 +112,7 @@ class dhcpHost extends plugin $this->options['host-name']= $this->cn; } - /* Strip network objects */ - foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ - unset($this->options[$toberemoved]); - } - foreach (array("filename", "next-server") as $toberemoved){ - unset($this->statements[$toberemoved]); - } - - /* 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; - } + dhcpPlugin::save_object(); } @@ -216,45 +155,12 @@ class dhcpHost extends plugin /* Save to LDAP */ function save() { - /* 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; - } - - /* 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); + dhcpPlugin::save(); 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_dhcpPlugin.inc b/plugins/admin/systems/class_dhcpPlugin.inc new file mode 100644 index 000000000..c0da9bf10 --- /dev/null +++ b/plugins/admin/systems/class_dhcpPlugin.inc @@ -0,0 +1,171 @@ +dn= $attrs['dn']; + $this->cn= $attrs['cn'][0]; + $this->new= FALSE; + + /* 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; + + /* Save CN for later reference */ + $this->orig_cn= $this->cn; + } + + function execute() + { + return (""); + } + + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + /* Strip network objects */ + foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ + unset($this->options[$toberemoved]); + } + foreach (array("filename", "next-server") as $toberemoved){ + unset($this->statements[$toberemoved]); + } + + /* 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($cache) + { + $message= array(); + + return $message; + } + + + /* Save to LDAP */ + function save() + { + /* 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; + } + + /* 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){ + if ($val != ""){ + $this->attrs['dhcpStatements'][]= "$key $val"; + } else { + $this->attrs['dhcpStatements'][]= "$key"; + } + } + } + + /* Move dn to the result */ + $this->attrs['dn']= $this->dn; + $this->attrs['cn']= array($this->cn); + $this->attrs['objectClass']= $this->objectclasses; + $this->attrs['MODIFIED']= TRUE; + + return ($this->attrs); + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpPool.inc b/plugins/admin/systems/class_dhcpPool.inc index cccbb90a5..5677322ff 100644 --- a/plugins/admin/systems/class_dhcpPool.inc +++ b/plugins/admin/systems/class_dhcpPool.inc @@ -18,72 +18,28 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -class dhcpPool extends plugin +class dhcpPool extends dhcpPlugin { /* Used attributes */ - var $cn= ""; var $dhcpRange= ""; var $range_start= ""; var $range_stop= ""; - var $options= array(); - var $statements= array(); - - /* Subobjects */ - var $network; - var $advanced; /* attribute list for save action */ - var $attributes= array(); - var $objectclasses= array(); + var $objectclasses= array('top', 'dhcpPool'); function dhcpPool($attrs) { - /* Load statements / options */ - if (is_array($attrs)){ - $this->dn= $attrs['dn']; - $this->new= FALSE; + dhcpPlugin::dhcpPlugin($attrs); - /* Load attributes */ - $this->cn= $attrs['cn'][0]; + /* Load attributes */ + if (!$this->new){ $this->dhcpRange= $attrs['dhcpRange'][0]; list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange); - - /* 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->setAutoOptions(array("host-name")); - $this->advanced->statements= $this->statements; $this->advanced->setAutoStatements(array("fixed-address")); - - /* Save CN for later reference */ - $this->orig_cn= $this->cn; } function execute() @@ -131,15 +87,7 @@ class dhcpPool extends plugin $this->range_stop= validate($_POST['range_stop']); } - /* 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; - } + dhcpPlugin::save_object(); /* Move range to internal variable */ $this->dhcpRange= $this->range_start." ".$this->range_stop; @@ -181,41 +129,8 @@ class dhcpPool extends plugin /* Save to LDAP */ function save() { - /* 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; - } - - /* 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); + dhcpPlugin::save(); $this->attrs['dhcpRange']= array($this->dhcpRange); - $this->attrs['objectClass']= array('top', 'dhcpPool'); - $this->attrs['MODIFIED']= TRUE; return ($this->attrs); } diff --git a/plugins/admin/systems/class_dhcpService.inc b/plugins/admin/systems/class_dhcpService.inc index 6118e7e57..940ea7109 100644 --- a/plugins/admin/systems/class_dhcpService.inc +++ b/plugins/admin/systems/class_dhcpService.inc @@ -18,66 +18,27 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -class dhcpService extends plugin +class dhcpService extends dhcpPlugin { /* Used attributes */ - var $cn= ""; - var $orig_cn= ""; var $dhcpPrimaryDN= ""; var $orig_dhcpPrimaryDN= ""; - var $options= array(); - var $statements= array(); var $ddns_styles= array('none', 'interim', 'ad-hoc'); - /* Subobjects */ - var $network; - var $advanced; - /* attribute list for save action */ - var $attributes= array(); - var $objectclasses= array(); + var $objectclasses= array('top', 'dhcpService'); function dhcpService($attrs) { - /* Load statements / options */ - if (is_array($attrs)){ - $this->dn= $attrs['dn']; - $this->new= FALSE; + dhcpPlugin::dhcpPlugin($attrs); + /* Load statements / options */ + if (!$this->new){ /* 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); - if ($idx == $opt){ - $value= ""; - } else { - $value= preg_replace('/^[^\s]+\s/', '', $opt); - } - $this->statements[$idx]= $value; - } - } - + $this->dhcpPrimaryDN= $attrs['dhcpPrimaryDN'][0]; } else { /* We keep the parent dn here if it's new */ - $this->dn= $attrs; - $this->new= TRUE; $this->statements['default-lease-time']= 600; $this->statements['max-lease-time']= 1700; $this->statements['authoritative']= TRUE; @@ -85,19 +46,11 @@ class dhcpService extends plugin $this->statements['ddns-update-style']= 'none'; } - /* 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", "get-lease-hostnames", "server-identifier", "ddns-update-style")); $this->advanced->setAutoOptions(array("server-name")); /* Save for later action */ $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN; - $this->orig_cn= $this->cn; } @@ -186,24 +139,7 @@ class dhcpService extends plugin $this->statements['get-lease-hostnames']= "off"; } - /* Strip network objects */ - foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ - unset($this->options[$toberemoved]); - } - foreach (array("filename", "next-server") as $toberemoved){ - unset($this->statements[$toberemoved]); - } - - /* 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; - } - + dhcpPlugin::save_object(); } @@ -227,39 +163,9 @@ class dhcpService extends plugin $res= $ldap->fetch(); $server_name= $res['cn'][0]; - /* 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; - } - - /* Assemble new entry - options */ - $this->attrs['dhcpOption']= array(); - if (isset ($this->options) && count ($this->options)){ - foreach ($this->options as $key => $val){ - if ($key != "server-name"){ - $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){ - if ($val != ""){ - $this->attrs['dhcpStatements'][]= "$key $val"; - } else { - $this->attrs['dhcpStatements'][]= "$key"; - } - } - } + dhcpPlugin::save(); - $this->attrs['dn']= $this->dn; - $this->attrs['cn']= array($this->cn); $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN); - $this->attrs['objectClass']= array('top', 'dhcpService'); - $this->attrs['MODIFIED']= TRUE; $this->attrs['dhcpOption'][]= "server-name $server_name"; return ($this->attrs);