From ae37c5e3ea9b1c924a3beef22055baac1ac695ec Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 29 Aug 2007 07:39:51 +0000 Subject: [PATCH] Added dhcp plugin. Not working now !! git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7161 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_dhcpPlugin.inc | 200 +++++++ plugins/admin/systems/class_dhcpAdvanced.inc | 146 +++++ plugins/admin/systems/class_dhcpGroup.inc | 123 +++++ plugins/admin/systems/class_dhcpHost.inc | 176 ++++++ plugins/admin/systems/class_dhcpNetwork.inc | 225 ++++++++ .../systems/class_dhcpNewSectionDialog.inc | 80 +++ plugins/admin/systems/class_dhcpPool.inc | 188 +++++++ plugins/admin/systems/class_dhcpService.inc | 180 +++++++ .../admin/systems/class_dhcpSharedNetwork.inc | 185 +++++++ plugins/admin/systems/class_dhcpSubnet.inc | 197 +++++++ plugins/admin/systems/class_servDHCP.inc | 499 +++++++++++++++++- .../class_servDNSeditZoneEntries.inc.rej | 21 + plugins/admin/systems/dhcpNewSection.tpl | 25 + plugins/admin/systems/dhcp_advanced.tpl | 46 ++ plugins/admin/systems/dhcp_group.tpl | 22 + plugins/admin/systems/dhcp_host.tpl | 52 ++ plugins/admin/systems/dhcp_network.tpl | 90 ++++ plugins/admin/systems/dhcp_pool.tpl | 26 + plugins/admin/systems/dhcp_service.tpl | 43 ++ plugins/admin/systems/dhcp_sharedNetwork.tpl | 107 ++++ plugins/admin/systems/dhcp_subnet.tpl | 41 ++ plugins/admin/systems/remove_dhcp.tpl | 17 + plugins/admin/systems/servdhcp.tpl | 10 +- 23 files changed, 2678 insertions(+), 21 deletions(-) create mode 100644 include/class_dhcpPlugin.inc create mode 100644 plugins/admin/systems/class_dhcpAdvanced.inc create mode 100644 plugins/admin/systems/class_dhcpGroup.inc create mode 100644 plugins/admin/systems/class_dhcpHost.inc create mode 100644 plugins/admin/systems/class_dhcpNetwork.inc create mode 100644 plugins/admin/systems/class_dhcpNewSectionDialog.inc create mode 100644 plugins/admin/systems/class_dhcpPool.inc create mode 100644 plugins/admin/systems/class_dhcpService.inc create mode 100644 plugins/admin/systems/class_dhcpSharedNetwork.inc create mode 100644 plugins/admin/systems/class_dhcpSubnet.inc create mode 100644 plugins/admin/systems/class_servDNSeditZoneEntries.inc.rej create mode 100644 plugins/admin/systems/dhcpNewSection.tpl create mode 100644 plugins/admin/systems/dhcp_advanced.tpl create mode 100644 plugins/admin/systems/dhcp_group.tpl create mode 100644 plugins/admin/systems/dhcp_host.tpl create mode 100644 plugins/admin/systems/dhcp_network.tpl create mode 100644 plugins/admin/systems/dhcp_pool.tpl create mode 100644 plugins/admin/systems/dhcp_service.tpl create mode 100644 plugins/admin/systems/dhcp_sharedNetwork.tpl create mode 100644 plugins/admin/systems/dhcp_subnet.tpl create mode 100644 plugins/admin/systems/remove_dhcp.tpl diff --git a/include/class_dhcpPlugin.inc b/include/class_dhcpPlugin.inc new file mode 100644 index 000000000..b9d48b25f --- /dev/null +++ b/include/class_dhcpPlugin.inc @@ -0,0 +1,200 @@ +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); + if ($idx == $opt){ + $value= ""; + } else { + $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; + } + } + + } 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){ + $this->advanced->$type= $this->$type + $this->network->$type;; + } + } + + + /* 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){ + $this->$type= $this->$type + $this->network->$type + $this->advanced->$type; + } + + /* 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); + } + + + function removeAttrs($name, $type) + { + $new= array(); + foreach ($this->attrs[$type] as $value){ + if (!preg_match("/^$name /", $value)){ + $new[]= $value; + } + } + $this->attrs[$type]= $new; + } + + + function removeOption($name) + { + $this->removeAttrs($name, 'dhcpOption'); + } + + + function removeStatement($name) + { + $this->removeAttrs($name, 'dhcpStatement'); + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpAdvanced.inc b/plugins/admin/systems/class_dhcpAdvanced.inc new file mode 100644 index 000000000..74094f73c --- /dev/null +++ b/plugins/admin/systems/class_dhcpAdvanced.inc @@ -0,0 +1,146 @@ +is_account= TRUE; + $this->setAutoStatements(); + $this->setAutoOptions(); + } + + function execute() + { + /* Check for interaction */ + if (isset($_POST['add_statement']) && $_POST['addstatement'] != ""){ + $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addstatement')); + $val= preg_replace("/^$key\s*/", '', get_post('addstatement')); + $this->statements[$key]= $val; + } + if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){ + $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpstatements')); + 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', get_post('addoption')); + $val= preg_replace("/^$key\s*/", '', get_post('addoption')); + $this->options[$key]= $val; + } + if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){ + $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions')); + 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){ + 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){ + 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))); + } + + function remove_from_parent() + { + } + + + /* 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; + } + } + + + /* Check values */ + function check() + { + /* Nothing to check here */ + $message= array(); + return $message; + } + + + /* Save to LDAP */ + function save() + { + } + + + 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); + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpGroup.inc b/plugins/admin/systems/class_dhcpGroup.inc new file mode 100644 index 000000000..47369286e --- /dev/null +++ b/plugins/admin/systems/class_dhcpGroup.inc @@ -0,0 +1,123 @@ +assign("cn", $this->cn); + + /* Show main page */ + $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $this->advanced->$type= $this->$type + $this->network->$type; + } + + $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() + { + } + + + /* Save data to object */ + function save_object() + { + /* Save cn */ + if (isset($_POST['cn'])){ + $this->cn= validate(get_post('cn')); + } + + /* Handle global saving */ + dhcpPlugin::save_object(); + } + + + /* Check values */ + function check($cache) + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + if (!preg_match('/^[a-z0-9_-]*$/i', $this->cn)){ + $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; + } + } + } + + /* Check external plugins */ + $net= $this->network->check(); + $adv= $this->advanced->check(); + $message= array_merge($message, $net, $adv); + + return $message; + } + + + /* Save to LDAP */ + function save() + { + dhcpPlugin::save(); + return ($this->attrs); + } + + +} + +?> diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc new file mode 100644 index 000000000..c6ce4dacf --- /dev/null +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -0,0 +1,176 @@ +new){ + $this->dhcpHWAddress= $attrs['dhcpHWAddress'][0]; + } + + $this->advanced->setAutoOptions(array("host-name")); + $this->advanced->setAutoStatements(array("fixed-address")); + + $this->realGosaHost = $host_exists_in_gosa; + } + + function execute() + { + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("dhcpHWAddress", preg_replace('/^[^ ]+ /', '', $this->dhcpHWAddress)); + $smarty->assign("realGosaHost",$this->realGosaHost); + + /* Create fixed address */ + if (isset($this->statements['fixed-address'])){ + $smarty->assign("fixedaddr", $this->statements['fixed-address']); + } else { + $smarty->assign("fixedaddr", ""); + } + + /* Prepare hw type selector */ + $hwtype= preg_replace('/\s.*$/', '', $this->dhcpHWAddress); + $smarty->assign("hwtype", $hwtype); + $smarty->assign("hwtypes", array("ethernet" => _("Ethernet"), + "fddi" => _("FDDI"), + "token-ring" => _("Token Ring"))); + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_host.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $this->advanced->$type= $this->$type + $this->network->$type; + } + + $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() + { + } + + + /* Save data to object */ + function save_object() + { + /* Save remaining attributes */ + if (isset($_POST['dhcp_host_posted'])){ + + /* Assemble hwAddress */ + if (isset($_POST['dhcpHWAddress'])){ + $this->dhcpHWAddress= get_post('hwtype')." ".get_post('dhcpHWAddress'); + } + + if(!$this->realGosaHost){ + $this->cn= validate(get_post('cn')); + } + + /* Save fixed address */ + if(!$this->realGosaHost){ + if ($_POST['fixedaddr'] != ""){ + $this->statements['fixed-address']= get_post('fixedaddr'); + } else { + unset ($this->statements['fixed-address']); + } + } + $this->options['host-name']= $this->cn; + } + + dhcpPlugin::save_object(); + } + + + /* Check values */ + function check($cache) + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + + /* 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; + } + } + } + + /* Check syntax of MAC address */ + $check= preg_replace('/^[^\s]*\s/', '', $this->dhcpHWAddress); + if (!preg_match('/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/', $check)){ + $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() + { + dhcpPlugin::save(); + if ($this->dhcpHWAddress != ""){ + $this->attrs['dhcpHWAddress']= array($this->dhcpHWAddress); + } else { + $this->attrs['dhcpHWAddress']= array(); + } + + return ($this->attrs); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_dhcpNetwork.inc b/plugins/admin/systems/class_dhcpNetwork.inc new file mode 100644 index 000000000..a8c751a72 --- /dev/null +++ b/plugins/admin/systems/class_dhcpNetwork.inc @@ -0,0 +1,225 @@ +is_account= TRUE; + } + + function execute() + { + /* Check for iteraction */ + if (isset($_POST['add_dns']) && $_POST['addserver'] != ""){ + if (!preg_match('/^[0-9a-z.-]+$/', get_post('addserver'))){ + print_red(_("The name of the DNS server your're going to add is not valid!")); + } else { + $servers= array(); + if (isset($this->options['domain-name-servers'])){ + foreach(split(",", $this->options['domain-name-servers']) as $val){ + $servers[$val]= $val; + } + } + $servers[get_post('addserver')]= get_post('addserver'); + $tmp= ""; + foreach($servers as $val){ + $tmp.= $val.","; + } + $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp); + } + } + if (isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){ + $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '', + $this->options['domain-name-servers']); + $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp); + if ($tmp != ""){ + $this->options['domain-name-servers']= $tmp; + } else { + unset($this->options['domain-name-servers']); + } + } + + /* Show main page */ + $smarty= get_smarty(); + + /* + * Assemble options + */ + + /* Router */ + if (isset($this->options['routers'])){ + $smarty->assign("routers", $this->options['routers']); + } else { + $smarty->assign("routers", ""); + } + + /* DNS */ + if (isset($this->options['domain-name'])){ + $smarty->assign("domain", trim($this->options['domain-name'], '"')); + } else { + $smarty->assign("domain", ""); + } + if (isset($this->options['domain-name-servers'])){ + $servers= array(); + foreach(split(",", $this->options['domain-name-servers']) as $val){ + $servers[$val]= $val; + } + $smarty->assign("dnsservers", $servers); + } else { + $smarty->assign("dnsservers", ""); + } + + /* Netmask / Broadcast */ + if (isset($this->options['subnet-mask'])){ + $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']); + $smarty->assign("subnet_mask", $this->options['subnet-mask']); + } else { + $smarty->assign("subnet_mask", ""); + } + if (isset($this->options['broadcast-address'])){ + $smarty->assign("broadcast_address", $this->options['broadcast-address']); + } else { + $smarty->assign("broadcast_address", ""); + } + + /* Boot stuff */ + if (isset($this->statements['filename'])){ + $smarty->assign("filename", trim($this->statements['filename'], '"')); + } else { + $smarty->assign("filename", ""); + } + if (isset($this->statements['next-server'])){ + $smarty->assign("nextserver", $this->statements['next-server']); + } else { + $smarty->assign("nextserver", ""); + } + + /* Set flags */ + $smarty->assign("autohost", ""); + if (isset($this->statements['get-lease-hostnames'])){ + if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){ + $smarty->assign("autohost", "checked"); + } + } + $smarty->assign("autohostdecl", ""); + if (isset($this->statements['use-host-decl-names'])){ + if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){ + $smarty->assign("autohostdecl", "checked"); + } + } + + return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE)); + } + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + /* Only save, if we are "active" */ + if (isset($_POST['routers'])){ + + /* + * Assemble options + */ + + /* Options */ + 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"]); + } else { + $this->options["$key"]= get_post("$val"); + } + } + + /* Statements */ + foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){ + if ($_POST["$val"] == ''){ + unset($this->statements["$key"]); + } else { + + /* Only quote filename values */ + if(in_array($key,array("filename"))){ + $this->statements["$key"]= '"'.get_post("$val").'"'; + }else{ + $this->statements["$key"]= get_post("$val"); + } + } + } + + /* Flags */ + if (isset ($_POST['autohost'])){ + $this->statements['get-lease-hostnames']= "true"; + } else { + unset($this->statements['get-lease-hostnames']); + } + if (isset ($_POST['autohostdecl'])){ + $this->statements['use-host-decl-names']= "on"; + } else { + unset($this->statements['use-host-decl-names']); + } + } + } + + + /* Check values */ + function check() + { + $message= array(); + + /* Check netmask and broadcast */ + foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){ + if (!isset($this->options["$key"])){ + continue; + } + $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]); + + if (!is_ip($tmp)){ + $message[]= sprintf(_("Error in definition of '%s'!"), $typ); + } + } + + return $message; + } + + + /* Save to LDAP */ + function save() + { + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_dhcpNewSectionDialog.inc b/plugins/admin/systems/class_dhcpNewSectionDialog.inc new file mode 100644 index 000000000..e2235d372 --- /dev/null +++ b/plugins/admin/systems/class_dhcpNewSectionDialog.inc @@ -0,0 +1,80 @@ + array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/), + #"dhcpClass" => array("dhcpSubClass"), + "dhcpSubClass" => array(), + "dhcpHost" => array(), + "dhcpGroup" => array("dhcpHost"), + "dhcpPool" => array(), + "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/), + "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool")); + + + + function dhcpNewSectionDialog($type) + { + $this->types= array( "dhcpService" => _("Global options"), + /*"dhcpClass" => _("Class"),*/ + "dhcpSubClass" => _("Subclass"), + "dhcpHost" => _("Host"), + "dhcpGroup" => _("Group"), + "dhcpPool" => _("Pool"), + "dhcpSubnet" => _("Subnet"), + "dhcpSharedNetwork" => _("Shared network")); + + $this->classtype= $type; + } + + function execute() + { + /* Fill templating stuff */ + $smarty = get_smarty(); + $display= ""; + + $sections= $this->sectionMap[$this->classtype]; + $t_sections= array(); + foreach ($sections as $section){ + $t_sections[$section]= $this->types[$section]; + } + asort($t_sections); + $smarty->assign("sections", $t_sections); + $smarty->assign("dhcpSectionACL", chkacl($this->acl,"DHCP")); + $display.= $smarty->fetch(get_template_path('dhcpNewSection.tpl', TRUE)); + return($display); + } + + /* Get posts and set class name + */ + function save_object() + { + } + + /* Check given class name */ + function check() + { + /* Call common method to give check the hook */ + $message= ""; + + return ($message); + } + + + /* Return the class name */ + function save() + { + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_dhcpPool.inc b/plugins/admin/systems/class_dhcpPool.inc new file mode 100644 index 000000000..d001c0663 --- /dev/null +++ b/plugins/admin/systems/class_dhcpPool.inc @@ -0,0 +1,188 @@ +new){ + $this->dhcpRange= $attrs['dhcpRange'][0]; + list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange); + } + + $this->advanced->setAutoOptions(array("host-name")); + $this->advanced->setAutoStatements(array("fixed-address")); + } + + function execute() + { + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("range_start", $this->range_start); + $smarty->assign("range_stop", $this->range_stop); + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_pool.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $this->advanced->$type= $this->$type + $this->network->$type;; + } + + $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() + { + } + + + /* Save data to object */ + function save_object() + { + if (isset($_POST['cn'])){ + $this->cn= validate(get_post('cn')); + $this->range_start= validate(get_post('range_start')); + $this->range_stop= validate(get_post('range_stop')); + } + + dhcpPlugin::save_object(); + + /* Move range to internal variable */ + $this->dhcpRange= $this->range_start." ".$this->range_stop; + } + + + /* Check values */ + function check($cache) + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + + /* 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 section is already used!"); + break; + } + } + } + + if ($this->dhcpRange == ""){ + $message[]= _("Required field 'Range' is not filled."); + } + + if (!is_ip($this->range_start) || !is_ip($this->range_stop)){ + $message[]= _("Field 'Range' contains invalid IP addresses."); + } + + if(!is_ip_range($this->range_start,$this->range_stop)){ + $message[] = _("Field 'Range' contains invalid IP range."); + } + + /* Check if range is in the network */ + $dn= $this->dn; + while (preg_match('/,/', $dn)){ + $type= $this->objectType($cache, $dn); + + /* Check for subnet */ + if ($type == 'dhcpSubnet'){ + $network= $cache[$dn]['cn'][0]; + $netmask= normalize_netmask($cache[$dn]['dhcpNetMask'][0]); + if (!is_in_network($network, $netmask, $this->range_start) || + !is_in_network($network, $netmask, $this->range_stop)){ + $message[] = _("'Range' is not inside the configured network."); + } + } + + /* Stop if we've examined the service base object */ + if ($type == 'dhcpService'){ + break; + } + $dn= preg_replace('/^[^,]+,/', '', $dn); + } + + /* Check external plugins */ + $net= $this->network->check(); + $adv= $this->advanced->check(); + $message= array_merge($message, $net, $adv); + + return $message; + } + + /* Save to LDAP */ + function save() + { + dhcpPlugin::save(); + $this->attrs['dhcpRange']= array($this->dhcpRange); + + return ($this->attrs); + } + + + function objectType($cache, $dn) + { + $type= ""; + $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost", + "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork"); + + foreach ($cache[$dn]['objectClass'] as $oc){ + if (in_array($oc, $types)){ + $type= $oc; + break; + } + } + + return ($type); + } + + +} + +?> diff --git a/plugins/admin/systems/class_dhcpService.inc b/plugins/admin/systems/class_dhcpService.inc new file mode 100644 index 000000000..477accb7e --- /dev/null +++ b/plugins/admin/systems/class_dhcpService.inc @@ -0,0 +1,180 @@ +new){ + /* Load attributes */ + $this->dhcpPrimaryDN= $attrs['dhcpPrimaryDN'][0]; + } else { + /* We keep the parent dn here if it's new */ + $this->statements['default-lease-time']= 600; + $this->statements['max-lease-time']= 1700; + $this->statements['authoritative']= TRUE; + $this->statements['ddns-update-style']= 'none'; + } + + $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "server-identifier", "ddns-update-style")); + $this->advanced->setAutoOptions(array("server-name")); + + /* Save for later action */ + $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN; + } + + + function execute() + { + /* Show main page */ + $smarty= get_smarty(); + + $smarty->assign('ddns_styles', $this->ddns_styles); + foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){ + if (isset($this->statements[preg_replace('/_/', '-', $value)])){ + $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]); + } else { + $smarty->assign("$value", ""); + } + } + + if (isset($this->statements['authoritative'])){ + $smarty->assign("authoritative", "checked"); + } else { + $smarty->assign("authoritative", ""); + } + + /* 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){ + $this->advanced->$type= $this->$type + $this->network->$type;; + } + + $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() + { + } + + + /* Save data to object */ + function save_object() + { + /* No need to save in the first time */ + if (!isset($_POST['ddns_update_style'])){ + return; + } + + /* Save remaining attributes */ + foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){ + $tval= preg_replace('/_/', '-', $val); + if ($_POST[$val] != ""){ + $this->statements[$tval]= validate(get_post($val)); + } else { + unset ($this->statements[$tval]); + } + } + if (isset($_POST['authoritative'])){ + $this->statements['authoritative']= ""; + } else { + unset($this->statements['authoritative']); + } + + dhcpPlugin::save_object(); + } + + + /* Check values */ + function check() + { + $message= array(); + + if (!is_id($this->statements['default-lease-time'])){ + $message[]= _('Default lease time needs to be numeric.'); + } + if (!is_id($this->statements['max-lease-time'])){ + $message[]= _('Maximum lease time needs to be numeric.'); + } + if ($this->statements['default-lease-time'] > $this->statements['max-lease-time']){ + $message[]= _('Default lease time needs to smaller than the maximum lease time.'); + } + + /* Check external plugins */ + $net= $this->network->check(); + $adv= $this->advanced->check(); + $message= array_merge($message, $net, $adv); + + return $message; + } + + + /* Save to LDAP */ + function save() + { + global $config; + $this->attrs= array(); + + /* Get and set server name */ + $ldap= $config->get_ldap_link(); + $ldap->cat($this->dhcpPrimaryDN, array('cn')); + $res= $ldap->fetch(); + $server_name= $res['cn'][0]; + + dhcpPlugin::save(); + + $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN); + $this->removeOption('server-name'); + $this->attrs['dhcpOption'][]= "server-name $server_name"; + + return ($this->attrs); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_dhcpSharedNetwork.inc b/plugins/admin/systems/class_dhcpSharedNetwork.inc new file mode 100644 index 000000000..9e1f7e43b --- /dev/null +++ b/plugins/admin/systems/class_dhcpSharedNetwork.inc @@ -0,0 +1,185 @@ +advanced->setAutoStatements(array("server-identifier", "default-lease-time", + "max-lease-time", "min-lease-time", "authoritative", "deny-unknown-clients", + "deny-bootp", "deny-booting")); + } + + + function execute() + { + $smarty= get_smarty(); + + /* Fill template */ + $smarty->assign ("cn", $this->cn); + foreach (array("server-identifier", "default-lease-time", "max-lease-time", "min-lease-time") as $attr){ + if (isset($this->statements[$attr])){ + $smarty->assign(preg_replace('/-/', '_', $attr), $this->statements[$attr]); + } else { + $smarty->assign(preg_replace('/-/', '_', $attr), ""); + } + } + if (isset($this->statements["authoritative"])){ + $smarty->assign("authoritative", "checked"); + } else { + $smarty->assign("authoritative", ""); + } + if (!isset($this->statements["deny unknown-clients"])){ + $smarty->assign("allow_unknown_state", "checked"); + } else { + $smarty->assign("allow_unknown_state", ""); + } + if (!isset($this->statements["deny bootp"])){ + $smarty->assign("allow_bootp_state", "checked"); + } else { + $smarty->assign("allow_bootp_state", ""); + } + if (!isset($this->statements["deny booting"])){ + $smarty->assign("allow_booting_state", "checked"); + } else { + $smarty->assign("allow_booting_state", ""); + } + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $this->advanced->$type= $this->$type + $this->network->$type; + } + + $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() + { + } + + + /* Save data to object */ + function save_object() + { + if (isset($_POST['cn'])){ + $this->cn= validate(get_post('cn')); + dhcpPlugin::save_object(); + + foreach (array("server-identifier", "default-lease-time", + "max-lease-time", "min-lease-time") as $attr){ + if (isset($_POST[$attr]) && $_POST[$attr] != ""){ + $this->statements[$attr]= get_post($attr); + } else { + unset($this->statements[$attr]); + } + } + + if (isset($_POST["authoritative"])){ + $this->statements["authoritative"]= ""; + } else { + unset ($this->statements["authoritative"]); + } + + foreach(array("unknown-clients", "bootp", "booting") as $name){ + if (isset($_POST[$name])){ + $this->statements["allow $name"]= ""; + unset($this->statements["deny $name"]); + } else { + $this->statements["deny $name"]= ""; + unset($this->statements["allow $name"]); + } + } + } + } + + + /* Check values */ + function check($cache) + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + + /* Check lease times */ + foreach (array("default-lease-time" => _("Default lease time"), + "max-lease-time" => _("Max. lease time"), + "min-lease-time" => _("Min. lease time")) as $key => $val){ + if (isset($this->statements[$key]) && $this->statements[$key] != "" && + !is_id($this->statements[$key])){ + $message[]= sprintf(_("The value specified as '%s' is not numeric!"), $val); + } + } + + /* 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; + } + } + } + + /* Check external plugins */ + $net= $this->network->check(); + $adv= $this->advanced->check(); + $message= array_merge($message, $net, $adv); + + return $message; + } + + + /* Save to LDAP */ + function save() + { + dhcpPlugin::save(); + + return ($this->attrs); + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpSubnet.inc b/plugins/admin/systems/class_dhcpSubnet.inc new file mode 100644 index 000000000..ce1c4c164 --- /dev/null +++ b/plugins/admin/systems/class_dhcpSubnet.inc @@ -0,0 +1,197 @@ +new){ + /* Load attributes */ + foreach (array("dhcpNetMask", "dhcpRange") as $attr){ + if (isset($attrs[$attr][0])){ + $this->$attr= $attrs[$attr][0]; + } + } + if (isset($attrs['dhcpRange']) && count($attrs['dhcpRange'])){ + $this->use_range= TRUE; + list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange); + } + } + + $this->dhcpNetMask= normalize_netmask($this->dhcpNetMask); + } + + + function execute() + { + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("dhcp_netmask", $this->dhcpNetMask); + + /* Prepare range */ + if ($this->use_range){ + $smarty->assign("use_range", "checked"); + $smarty->assign("range_disabled", ""); + } else { + $smarty->assign("use_range", ""); + $smarty->assign("range_disabled", "disabled"); + } + $smarty->assign("range_start", $this->range_start); + $smarty->assign("range_stop", $this->range_stop); + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_subnet.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $this->advanced->$type= $this->$type + $this->network->$type; + } + + $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.= "
". + " 
"; + + /* Show main page */ + return $display; + } + + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + if(isset($_POST['dhcp_subnet_posted'])){ + if (isset($_POST['cn'])){ + $this->cn= validate(get_post('cn')); + } + if (isset($_POST['dhcp_netmask'])){ + $this->dhcpNetMask= validate(get_post('dhcp_netmask')); + } + if (isset($_POST['use_range'])){ + $this->use_range= TRUE; + $this->range_start= validate(get_post('range_start')); + $this->range_stop= validate(get_post('range_stop')); + } else { + $this->use_range= FALSE; + } + + /* Move range to internal variable */ + $this->dhcpRange= $this->range_start." ".$this->range_stop; + dhcpPlugin::save_object(); + } + } + + + /* Check values */ + function check($cache) + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Network address' is not filled."); + } + if ($this->dhcpNetMask == ""){ + $message[]= _("Required field 'Netmask' is not filled."); + } + + /* 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 section is already used!"); + break; + } + } + } + + /* IP's? */ + foreach(array('dhcpNetMask' => _("Netmask"), 'cn' => _("Network address"), 'range_start' => _("Range"), 'range_stop' => _("Range")) as $attr => $str){ + if ($this->$attr != "" && !is_ip($this->$attr)){ + $message[]= sprintf(_("The field '%s' contains an invalid IP address"), $str); + } + } + + /* Check ip range */ + if ($this->use_range){ + if(!is_ip_range($this->range_start,$this->range_stop)){ + $message[] = _("Field 'Range' contains invalid IP range."); + } + + /* Check if range is in the network */ + if (!is_in_network($this->cn, $this->dhcpNetMask, $this->range_start) || + !is_in_network($this->cn, $this->dhcpNetMask, $this->range_stop)){ + $message[] = _("'Range' is not inside the configured network."); + } + } + + /* Check external plugins */ + $net= $this->network->check(); + $adv= $this->advanced->check(); + $message= array_merge($message, $net, $adv); + + return $message; + } + + + /* Save to LDAP */ + function save() + { + dhcpPlugin::save(); + + /* Move dn to the result */ + $this->attrs['dhcpNetMask']= array(netmask_to_bits($this->dhcpNetMask)); + if ($this->use_range && !empty($this->dhcpRange)){ + $this->attrs['dhcpRange']= array($this->range_start." ".$this->range_stop); + } else { + $this->attrs['dhcpRange']= array(); + } + + return ($this->attrs); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index 42eaf2b9c..168d7a8e8 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -2,36 +2,208 @@ class servdhcp extends plugin { - /* CLI vars */ - var $cli_summary= "Manage server basic objects"; - var $cli_description= "Some longer text\nfor help"; - var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array(); - var $objectclasses= array("whatever"); - var $view_logged = FALSE; + var $attributes= array("dhcpServiceDN"); + var $objectclasses= array("dhcpServer"); + + var $dhcpServiceDN= ""; + + /* Section storage */ + var $dhcpSections= array(); + var $dhcpObjectCache= array(); + var $current_object= ""; + var $types= array(); + var $serviceDN= ""; + + var $quote_option = array("domain-name"); + + var $orig_dn = ""; function servdhcp ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); + + $this->serviceDN = "cn=dhcp,".$dn; + $this->orig_dn = $dn; + + $this->types= array( "dhcpLog" => _("Logging"), + "dhcpService" => _("Global options"), + "dhcpClass" => _("Class"), + "dhcpSubClass" => _("Subclass"), + "dhcpHost" => _("Host"), + "dhcpGroup" => _("Group"), + "dhcpPool" => _("Pool"), + "dhcpSubnet" => _("Subnet"), + "dhcpFailOverPeer" => _("Failover peer"), + "dhcpSharedNetwork" => _("Shared network")); + + + /* Backport: PHP4 compatibility */ + foreach($this->types as $type => $translation){ + $this->types[strtolower($type)] = $translation; + } + + /* Load information about available services */ + $this->reload(); + if (!count($this->dhcpSections)){ + $this->is_account= FALSE; + } + } + function execute() { /* Call parent execute */ plugin::execute(); - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","server/".get_class($this),$this->dn); - } - /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; + /* Section Creation? */ + if (isset($_POST['create_section']) && isset($_POST['section'])){ + $section= $_POST['section']; + $tmp = new dhcpNewSectionDialog(NULL); + if (isset($tmp->sectionMap[$section])){ + $this->dialog= new $section($this->current_object); + $this->current_object= ""; + } else { + $this->dialog= NULL; + } + } + + /* Cancel section creation? */ + 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; + $class= get_class($this->dialog); + $type= $this->types[$class]; + if(empty($this->serviceDN)){ + $indent= substr_count(preg_replace("/".$this->dn."/", '', $dn), ",") -1; + }else{ + $indent= substr_count(preg_replace("/".$this->serviceDN."/", '', $dn), ","); + } + $spaces= ""; + for ($i= 0; $i<$indent; $i++){ + $spaces.= "    "; + } + $data= $this->dialog->save(); + if ($this->current_object == ""){ + /* New object */ + $newsects= array(); + foreach ($this->dhcpSections as $key => $dsc){ + $newsects[$key]= $dsc; + if ($key == $dn){ + $spaces.= "    "; + $newsects[$data['dn']]= "$spaces$type '".preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $data['dn'])."'"; + } + } + $this->dhcpObjectCache[$data['dn']]= $data; + $this->dhcpSections= $newsects; + } else { + if ($dn != $data['dn']){ + /* Old object, new name */ + $this->dhcpObjectCache[$dn]= array(); + $this->dhcpObjectCache[$data['dn']]= $data; + + /* 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; + } + } + $this->dialog= NULL; + } + } + + /* Remove section? */ + if (isset($_POST['delete_dhcp_confirm'])){ + if (chkacl($this->acl, "delete") == ""){ + unset($this->dhcpSections[$this->current_object]); + unset($this->dhcpObjectCache[$this->current_object]); + $this->dhcpObjectCache[$this->current_object]= array(); + foreach ($this->dhcpSections as $key => $value){ + if (preg_match("/".$this->current_object."$/", $key)){ + unset($this->dhcpSections[$key]); + unset($this->dhcpObjectCache[$key]); + $this->dhcpObjectCache[$key]= array(); + } + } + } else { + print_red(_("You're not allowed to remove DHCP sections!")); + } + $this->dialog= NULL; + } + + /* Look for post entries */ + foreach($_POST as $name => $value){ + + /* Insert new section? */ + if (preg_match('/^insertDhcp_.*_x$/', $name)){ + $dn= base64_decode(preg_replace('/^insertDhcp_([^_]+)_x$/', '\1', $name)); + if (isset($this->dhcpObjectCache[$dn])){ + $this->dialog= new dhcpNewSectionDialog($this->objectType($dn)); + $this->current_object= $dn; + $this->dialog->acl= $this->acl; + } + } + + /* Edit section? */ + if (preg_match('/^editDhcp_.*_x$/', $name)){ + $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]); + } + } + + /* Remove section? */ + if (preg_match('/^delDhcp_.*_x$/', $name)){ + $dn= base64_decode(preg_replace('/^delDhcp_([^_]+)_x$/', '\1', $name)); + if (isset($this->dhcpObjectCache[$dn])){ + $this->current_object= $dn; + $this->dialog= 1; + $smarty->assign("warning", sprintf(_("You're about to delete the DHCP section '%s'."), $dn)); + return($smarty->fetch(get_template_path('remove_dhcp.tpl', TRUE))); + } + } + + } + /* Do we need to flip is_account state? */ if (isset($_POST['modify_state'])){ $this->is_account= !$this->is_account; @@ -39,22 +211,117 @@ class servdhcp extends plugin /* Show tab dialog headers */ if ($this->is_account){ - $display= $this->show_disable_header(_("Remove DHCP service"), + $display= $this->show_header(_("Remove DHCP service"), _("This server has DHCP features enabled. You can disable them by clicking below.")); + + if (!count($this->dhcpObjectCache)){ + $attrs= array(); + $attrs['dn']= 'cn=dhcp,'.$this->dn; + $attrs['cn']= array('dhcp'); + $attrs['objectClass']= array('top', 'dhcpService'); + $attrs['dhcpPrimaryDN']= array($this->dn); + $attrs['dhcpStatements']= array("default-lease-time 600", + "max-lease-time 1200", + "authoritative", + "ddns-update-style none"); + $attrs['MODIFIED']= TRUE; + $this->dhcpSections['cn=dhcp,'.$this->dn]= _("Global options"); + $this->dhcpObjectCache['cn=dhcp,'.$this->dn]= $attrs; + } + } else { - $display= $this->show_enable_header(_("Add DHCP service"), + $display= $this->show_header(_("Add DHCP service"), _("This server has DHCP features disabled. You can enable them by clicking below.")); return ($display); } + + /* Show dialog + */ + if($this->dialog != NULL && !is_int($this->dialog)){ + $this->dialog->save_object(); + $this->dialog->parent = $this; + return($this->dialog->execute()); + } + + /* Create Listbox with existing Zones + */ + $DhcpList = new divSelectBox("dhcpSections"); + $DhcpList->SetHeight(400); + + /* Add entries to divlist + */ + $editImgIns = "". + "". + ""; + $editImgInsNoDel = "". + ""; + $editImg = "". + ""; + + $tmp = new dhcpNewSectionDialog(NULL); + foreach($this->dhcpSections as $section => $values ){ + + if (count($tmp->sectionMap[$this->objectType($section)])){ + 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), + array("string" => str_replace("%s",base64_encode($section),$editImg), "attach" => "style='text-align:right;'") + )); + } + } + + $smarty->assign("dhcpACL",chkacl($this->acl,"servdhcp")); + + /* Display tempalte */ + $smarty->assign("DhcpList",$DhcpList->DrawList()); $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE)); return($display); } + function remove_from_parent() { - /* This cannot be removed... */ - new log("remove","unknown/".get_class($this),$this->dn); + /* Cancel if there's nothing to do here */ + if (!$this->initially_was_account){ + return; + } + + /* Remove subtrees */ + $ldap= $this->config->get_ldap_link(); + foreach ($this->dhcpObjectCache as $dn => $content){ + if ($this->objectType($dn) == 'dhcpService'){ + $ldap->rmdir_recursive($dn); + show_ldap_error($ldap->get_error(), _("Removing DHCP entries failed")); + } + } + + /* Remove from self */ + $ldap= $this->config->get_ldap_link(); + + /* Remove and write to LDAP */ + plugin::remove_from_parent(); + + @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->attributes, "Save"); + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + show_ldap_error($ldap->get_error(), _("Removing DHCP entries failed")); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove"); } @@ -78,11 +345,203 @@ class servdhcp extends plugin /* Save to LDAP */ function save() { + $ldap= $this->config->get_ldap_link(); + + foreach ($this->dhcpObjectCache as $dn => $data){ + + if($this->dn != $this->orig_dn){ + $dn = preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$dn); + } + + /* Remove entry? */ + if (count($data) == 0){ + /* Check if exists, then remove... */ + if($ldap->cat($dn)){ + $ldap->rmdir_recursive($dn); + show_ldap_error($ldap->get_error(), _("Can't remove DHCP object!")); + } + continue; + } + + /* Modify existing entry? */ + if (isset($data['MODIFIED']) || $this->orig_dn != $this->dn){ + + 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(in_array($attribute,array("dhcpPrimaryDN","dhcpSecondaryDN","dhcpServerDN","dhcpFailOverPeerDN"))){ + foreach($values as $v_key => $value){ + $values[$v_key] = preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$value); + } + } + + if (count($values)){ + + if($attribute == "dhcpOption"){ + foreach($values as $key => $value){ + $option_name = trim(preg_replace("/[^ ]*$/","",$value)); + $option_value= trim(preg_replace("/^[^ ]*/","",$value)); + if(in_array($option_name,$this->quote_option)){ + $values[$key] = $option_name." \"".$option_value."\""; + } + } + } + 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!")); + } + } + } + + $this->dhcpServiceDN= $this->serviceDN; + if($this->dn != $this->orig_dn){ + $this->dhcpServiceDN= preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$this->dhcpServiceDN); + } + plugin::save(); - new log("modfiy","unknown/".get_class($this),$this->dn); + + /* Save data to LDAP */ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + show_ldap_error($ldap->get_error(), _("Saving DHCP service failed")); /* Optionally execute a command after we're done */ - #$this->handle_post_events($mode); + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } + + } + + + function reload() + { + /* Init LDAP and load list */ + $ldap= $this->config->get_ldap_link(); + $ui= get_userinfo(); + $me= $this->dn; + + $list= get_list("(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))", $ui->subtreeACL, $this->config->current['BASE'], array("cn")); + $final= array(); + foreach ($list as $value){ + + /* Set header */ + $sortpart= split(",", $value['dn']); + $sortpart= array_reverse($sortpart); + $tmp= implode(",", $sortpart); + + $final[$value['dn']]= $tmp."!"._("Global options"); + + /* Read all sub entries to place here */ + $ldap->cd($value['dn']); + $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(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()){ + $sattrs= array(); + for ($i= 0; $i<$attrs['count']; $i++){ + $sattrs[$attrs[$i]]= $attrs[$attrs[$i]]; + unset($sattrs[$attrs[$i]]['count']); + } + $sattrs['dn']= $ldap->getDN(); + + foreach($sattrs as $name => $values){ + if($name == "dhcpOption"){ + foreach($values as $key => $value){ + $value_name = trim(preg_replace("/[^ ]*$/","",$value)); + $value_value= trim(preg_replace("/^[^ ]*/","",$value)); + if(in_array($value_name,$this->quote_option)){ + $value_value = preg_replace("/^\"/","",$value_value); + $value_value = preg_replace("/\"$/","",$value_value); + $sattrs[$name][$key] = $value_name." ".$value_value; + } + } + } + } + + $this->dhcpObjectCache[$ldap->getDN()]= $sattrs; + $tmp= preg_replace("/".$this->serviceDN."/", "", $ldap->getDN()); + $indent= substr_count($tmp, ","); + $spaces= ""; + for ($i= 0; $i<$indent; $i++){ + $spaces.= "    "; + } + + foreach ($this->types as $key => $val){ + if (in_array("$key", $attrs['objectClass'])){ + $type= $val; + break; + } + } + + /* Prepare for sorting... */ + $sortpart= split(",", $ldap->getDN()); + $sortpart= array_reverse($sortpart); + $tmp= implode(",", $sortpart); + $final[$ldap->getDN()]= $tmp."!".$spaces.$type." '".$attrs['cn'][0]."'"; + } + } + + /* Sort it... */ + natsort($final); + $this->dhcpSections= array(); + foreach ($final as $key => $val){ + $this->dhcpSections[$key]= preg_replace('/^[^!]+!(.*)$/', '\\1', $val); + } + + } + + + function objectType($dn) + { + $type= ""; + $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost", + "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork"); + + foreach ($this->dhcpObjectCache[$dn]['objectClass'] as $oc){ + if (in_array($oc, $types)){ + $type= $oc; + break; + } + } + + /* That should not happen... */ + if ($type == ""){ + print_red(_("DHCP configuration set is unknown. Please contact your system administrator.")); + } + + return ($type); } } diff --git a/plugins/admin/systems/class_servDNSeditZoneEntries.inc.rej b/plugins/admin/systems/class_servDNSeditZoneEntries.inc.rej new file mode 100644 index 000000000..191a87c0f --- /dev/null +++ b/plugins/admin/systems/class_servDNSeditZoneEntries.inc.rej @@ -0,0 +1,21 @@ +*************** +*** 24,29 **** + /* Initialise class + */ + $this->RecordTypes = getDnsRecordTypes(); + $this->dn = "zoneName=".getNameFromMix($zoneObject['InitialzoneName']).",".$dn; + $this->zoneName = $zoneObject['InitialzoneName']; + $this->reverseName = $zoneObject['InitialReverseZone']; +--- 24,35 ---- + /* Initialise class + */ + $this->RecordTypes = getDnsRecordTypes(); ++ ++ /* Remove nSRecord from listed types */ ++ if(isset($this->RecordTypes['nSRecord'])){ ++ unset($this->RecordTypes['nSRecord']); ++ } ++ + $this->dn = "zoneName=".getNameFromMix($zoneObject['InitialzoneName']).",".$dn; + $this->zoneName = $zoneObject['InitialzoneName']; + $this->reverseName = $zoneObject['InitialReverseZone']; diff --git a/plugins/admin/systems/dhcpNewSection.tpl b/plugins/admin/systems/dhcpNewSection.tpl new file mode 100644 index 000000000..3d48e07cc --- /dev/null +++ b/plugins/admin/systems/dhcpNewSection.tpl @@ -0,0 +1,25 @@ +
+ {t}Create new DHCP section{/t} +
+
+

+{t}Please choose one of the following DHCP section types.{/t} +

+
+{t}Section{/t}  + + +

+ +   + +

+ + + diff --git a/plugins/admin/systems/dhcp_advanced.tpl b/plugins/admin/systems/dhcp_advanced.tpl new file mode 100644 index 000000000..5ce0e4600 --- /dev/null +++ b/plugins/admin/systems/dhcp_advanced.tpl @@ -0,0 +1,46 @@ +{* GOsa dhcp sharedNetwork - smarty template *} + +

+
+ +{if $show_advanced} + + + + + + + + + + +
+
+ {t}DHCP statements{/t} +
+ +
+   +   + +
+
+ {t}DHCP options{/t} +
+ +
+   +   + +
+ +{else} + + + +{/if} +

 

diff --git a/plugins/admin/systems/dhcp_group.tpl b/plugins/admin/systems/dhcp_group.tpl new file mode 100644 index 000000000..930fc05ee --- /dev/null +++ b/plugins/admin/systems/dhcp_group.tpl @@ -0,0 +1,22 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ {t}Name{/t}{$must} + + +
+ +

 

+ + + diff --git a/plugins/admin/systems/dhcp_host.tpl b/plugins/admin/systems/dhcp_host.tpl new file mode 100644 index 000000000..602c51255 --- /dev/null +++ b/plugins/admin/systems/dhcp_host.tpl @@ -0,0 +1,52 @@ +{* GOsa dhcp host - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ + + + + + + + + +
{t}Name{/t}{$must} + +
{t}Fixed address{/t} + +
+
+ + + + + + + + + +
{t}Hardware type{/t} + +
{t}Hardware address{/t}{$must} + +
+
+ +

+ + + diff --git a/plugins/admin/systems/dhcp_network.tpl b/plugins/admin/systems/dhcp_network.tpl new file mode 100644 index 000000000..5645a63ac --- /dev/null +++ b/plugins/admin/systems/dhcp_network.tpl @@ -0,0 +1,90 @@ +{* GOsa dhcp sharedNetwork - smarty template *} + + + + + +
+

{t}Network configuration{/t}

+ + + + + + + + + + + + + +
{t}Router{/t} + +
{t}Netmask{/t} + +
{t}Broadcast{/t} + +
+
+
+

{t}Bootup{/t}

+ + + + + + + + + +
{t}Filename{/t} + +
{t}Next server{/t} + +
+ +
+

{t}Domain Name Service{/t}

+ + + + + + + + + + + +
{t}Domain{/t} + +
+
+ {t}DNS server{/t}
+ +
+   + + +
+

{t}Domain Name Service options{/t}

+ {t}Assign hostnames found via reverse mapping{/t} +
+ {t}Assign hostnames from host declarations{/t} +
+ +
+ + + diff --git a/plugins/admin/systems/dhcp_pool.tpl b/plugins/admin/systems/dhcp_pool.tpl new file mode 100644 index 000000000..dcbd05c3d --- /dev/null +++ b/plugins/admin/systems/dhcp_pool.tpl @@ -0,0 +1,26 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ {t}Name{/t}{$must}  + + + {t}Range{/t}{$must}  + +  -  + +
+ +

 

+ + + diff --git a/plugins/admin/systems/dhcp_service.tpl b/plugins/admin/systems/dhcp_service.tpl new file mode 100644 index 000000000..6ca515e67 --- /dev/null +++ b/plugins/admin/systems/dhcp_service.tpl @@ -0,0 +1,43 @@ +

{t}Generic{/t}

+ + + + + + + + +
+ {t}Authoritative service{/t}
+
+ {t}Dynamic DNS update{/t} + +
+ + + + + + + + + + +
{t}Default lease time (s){/t} + +
{t}Maximum lease time (s){/t} + +
+ +
+ +

+ + + diff --git a/plugins/admin/systems/dhcp_sharedNetwork.tpl b/plugins/admin/systems/dhcp_sharedNetwork.tpl new file mode 100644 index 000000000..374da3500 --- /dev/null +++ b/plugins/admin/systems/dhcp_sharedNetwork.tpl @@ -0,0 +1,107 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

+ + + + + + + + +
+ + + + + + + + + + +
{t}Name{/t}{$must} + +
{t}Server identifier{/t} + +
+ +
+ + + + +
+ {t}Authoritative server{/t} +
+
+ +

 

+ + + + + + + + +
+ +

{t}Leases{/t}

+ + + + + + + + + + + + + +
{t}Default lease time{/t} +  {t}seconds{/t} +
{t}Max. lease time{/t} +  {t}seconds{/t} +
{t}Min. lease time{/t} +  {t}seconds{/t} +
+ +
+

{t}Access control{/t}

+ + + + + + + + + + +
+ {t}Allow unknown clients{/t} +
+ {t}Allow bootp clients{/t} +
+ {t}Allow booting{/t} +
+
+ +

 

+ + + diff --git a/plugins/admin/systems/dhcp_subnet.tpl b/plugins/admin/systems/dhcp_subnet.tpl new file mode 100644 index 000000000..05425fbdc --- /dev/null +++ b/plugins/admin/systems/dhcp_subnet.tpl @@ -0,0 +1,41 @@ +{* GOsa dhcp subnet - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ + + + + + + + +
{t}Network address{/t}{$must}
{t}Netmask{/t}{$must}
+
+ + + + + + + + + +
{t}Range for dynamic address assignment{/t}
  +  -  + +
+
+ +

+ + + diff --git a/plugins/admin/systems/remove_dhcp.tpl b/plugins/admin/systems/remove_dhcp.tpl new file mode 100644 index 000000000..39fb19bb6 --- /dev/null +++ b/plugins/admin/systems/remove_dhcp.tpl @@ -0,0 +1,17 @@ +
+ {t}Warning{/t} +
+

+ {$warning} + {t}This includes 'all' DHCP subsections that are located within this section. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}Best thing to do before performing this action would be to save the current contents of your LDAP tree in a file. So - if you've done so - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ +   + +

diff --git a/plugins/admin/systems/servdhcp.tpl b/plugins/admin/systems/servdhcp.tpl index de9e44474..76739f150 100644 --- a/plugins/admin/systems/servdhcp.tpl +++ b/plugins/admin/systems/servdhcp.tpl @@ -1 +1,9 @@ -DHCP functionality here.. +

{t}DHCP sections{/t}

+ + + + +
+ {$DhcpList} + +
-- 2.30.2