From: cajus Date: Thu, 17 Jan 2008 16:42:44 +0000 (+0000) Subject: Moved dhcp X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=db36f84183b95b464435a88b1897d9561cbc9c1f;p=gosa.git Moved dhcp git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8478 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpAdvanced.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpAdvanced.inc deleted file mode 100644 index 43f583152..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpAdvanced.inc +++ /dev/null @@ -1,146 +0,0 @@ -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,dirname(__FILE__)))); - } - - 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", "domain-name-servers", "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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpGroup.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpGroup.inc deleted file mode 100644 index cbe987da8..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpGroup.inc +++ /dev/null @@ -1,126 +0,0 @@ -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 */ - $this->fix_options(); - 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() - { - $message= array(); - - $cache = $this->parent->dhcpObjectCache; - - /* 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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpHost.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpHost.inc deleted file mode 100644 index e8aab5c95..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpHost.inc +++ /dev/null @@ -1,181 +0,0 @@ -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,dirname(__FILE__))).$this->network->execute(); - - /* Merge arrays for advanced view */ - $this->fix_options(); - 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() - { - $message= array(); - - $cache = array(); - if(isset($this->parent)){ - $cache = $this->parent->dhcpObjectCache; - } - - /* 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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNetwork.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNetwork.inc deleted file mode 100644 index 146b0e21b..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNetwork.inc +++ /dev/null @@ -1,226 +0,0 @@ -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,dirname(__FILE__))); - } - - 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 (!tests::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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc deleted file mode 100644 index 756a97893..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc +++ /dev/null @@ -1,80 +0,0 @@ - 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); - $ui = get_userinfo(); - $smarty->assign("sections", $t_sections); - $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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc deleted file mode 100644 index 628260522..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc +++ /dev/null @@ -1,208 +0,0 @@ -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() - { - $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'); - } - - - function fix_options() - { - foreach (array('domain-name-servers') as $key){ - unset ($this->options[$key]); - } - } - -} - -?> diff --git a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPool.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPool.inc deleted file mode 100644 index eae26ddeb..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPool.inc +++ /dev/null @@ -1,191 +0,0 @@ -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 */ - $this->fix_options(); - 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() - { - $message= array(); - - $cache = $this->parent->dhcpObjectCache; - - /* 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 (!tests::is_ip($this->range_start) || !tests::is_ip($this->range_stop)){ - $message[]= _("Field 'Range' contains invalid IP addresses."); - } - - if(!tests::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 (!tests::is_in_network($network, $netmask, $this->range_start) || - !tests::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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpService.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpService.inc deleted file mode 100644 index 4989c43fc..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpService.inc +++ /dev/null @@ -1,181 +0,0 @@ -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 */ - $this->fix_options(); - 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 (!tests::is_id($this->statements['default-lease-time'])){ - $message[]= _('Default lease time needs to be numeric.'); - } - if (!tests::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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc deleted file mode 100644 index 5dfd47703..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc +++ /dev/null @@ -1,188 +0,0 @@ -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 */ - $this->fix_options(); - 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() - { - $message= array(); - - $cache = $this->parent->dhcpObjectCache; - - /* 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] != "" && - !tests::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/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSubnet.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSubnet.inc deleted file mode 100644 index 7fa9e9823..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpSubnet.inc +++ /dev/null @@ -1,200 +0,0 @@ -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 */ - $this->fix_options(); - 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() - { - $message= array(); - - $cache = $this->parent->dhcpObjectCache; - - /* 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 != "" && !tests::is_ip($this->$attr)){ - $message[]= sprintf(_("The field '%s' contains an invalid IP address"), $str); - } - } - - /* Check ip range */ - if ($this->use_range){ - if(!tests::is_ip_range($this->range_start,$this->range_stop)){ - $message[] = _("Field 'Range' contains invalid IP range."); - } - - /* Check if range is in the network */ - if (!tests::is_in_network($this->cn, $this->dhcpNetMask, $this->range_start) || - !tests::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/gosa-core/plugins/admin/systems/services/dhcp/class_servDHCP.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_servDHCP.inc deleted file mode 100644 index c804ec2bc..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/class_servDHCP.inc +++ /dev/null @@ -1,739 +0,0 @@ - array(),"FOR_LIST"=> array()); - var $take_over_id = -1; - var $display_warning = TRUE; - - function servdhcp (&$config, $dn= NULL, $parent= NULL) - { - plugin::plugin ($config, $dn, $parent); - - $this->serviceDN = "cn=dhcp,".$dn; - $this->orig_dn = $dn; - - $this->DisplayName = _("DHCP service"); - - $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; - $this->dhcp_server_list = $this->get_list_of_dhcp_servers(); - } - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty= get_smarty(); - $smarty->assign("dns_take_over",FALSE); - $display= ""; - - - /*****************/ - /* Handle Take Over Actions - /*****************/ - - /* Give smarty the required informations */ - $smarty->assign("dhcp_server_list", $this->dhcp_server_list['FOR_LIST']); - $smarty->assign("dhcp_server_list_cnt", count($this->dhcp_server_list['FOR_LIST'])); - - /* Take over requested, save id */ - if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){ - $id = $_POST['take_over_src']; - if(isset($this->dhcp_server_list['ENTRIES'][$id])){ - $this->take_over_id = $id; - } - } - - /* Abort take over action */ - if(isset($_POST['cancel_take_over'])){ - $this->dialog =false; - $this->take_over_id = -1; - $this->dhcp_server_list = $this->get_list_of_dhcp_servers(); - } - - /* Display informartion about take over that will be started when saving this server - * and hide default dhcp output - */ - if($this->take_over_id != -1){ - - $this->dialog = FALSE; - $id = $this->take_over_id; - $smarty->assign("dns_take_over",TRUE); - $warning = sprintf(_("You are going to migrate the DHCP setup from server '%s'."), - $this->dhcp_server_list['ENTRIES'][$id]['cn'][0]); - $warning.= " "._("The migration will be started when you save this system. To cancel this action, use the cancel button below."); - - if($this->display_warning){ - print_red($warning); - $this->display_warning = FALSE; - } - return($smarty->fetch(get_template_path('servdhcp.tpl', TRUE))); - } - - - /*****************/ - /* List handling - /*****************/ - - /* 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= FALSE; - } - } - - /* Cancel section creation? */ - if (isset($_POST['cancel_section']) || isset($_POST['cancel_dhcp'])){ - $this->dialog= FALSE; - } - - /* Save changes */ - if (isset($_POST['save_dhcp'])){ - $this->dialog->save_object(); - $messages= $this->dialog->check(); - 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= FALSE; - } - } - - /* Remove section? */ - if (isset($_POST['delete_dhcp_confirm'])){ - if ($this->acl_is_removeable()){ - 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= FALSE; - } - - /* 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))); - } - } - - } - - if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){ - $dn = base64_decode($_GET['id']); - if (isset($this->dhcpObjectCache[$dn])){ - $section= $this->objectType($dn); - $this->current_object= $dn; - $this->dialog= new $section($this->dhcpObjectCache[$dn]); - } - } - - - if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){ - $dn = base64_decode($_GET['id']); - if (isset($this->dhcpObjectCache[$dn])){ - $section= $this->objectType($dn); - $this->current_object= $dn; - $this->dialog= new $section($this->dhcpObjectCache[$dn]); - } - } - - - /* Do we need to flip is_account state? */ - if (isset($_POST['modify_state'])){ - $this->is_account= !$this->is_account; - } - - /* Show tab dialog headers */ - if ($this->is_account){ -# $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_header(_("Add DHCP service"), - -# _("This server has DHCP features disabled. You can enable them by clicking below.")); - return ($display); - } - - - /* Show dialog - */ - if(isset($this->dialog) && is_object($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 ){ - - $values = "".$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;'") - )); - } - } - - /* Display tempalte */ - $smarty->assign("DhcpList",$DhcpList->DrawList()); - $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE)); - return($display); - } - - - function remove_from_parent() - { - /* 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"); - } - - - /* Save data to object */ - function save_object() - { - plugin::save_object(); - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - /* Save to LDAP */ - function save() - { - /* Take over handling - * - Load servdhcp class and dhcpObjectCache for the source dhcp setup. - * - Assign dhcpObjectCache to this configuration. - * - Save this setup and remove source setup from ldap. - */ - if($this->take_over_id != -1){ - $id = $this->take_over_id; - $src = preg_replace("/cn=dhcp,/","",$this->dhcp_server_list['ENTRIES'][$id]['dn']); - $tmp = new servdhcp ($this->config, $src); - $this->orig_dn = $src; - $this->dhcpObjectCache = $tmp->dhcpObjectCache; - } - - /* Save dhcp setttings */ - $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; - } - - /* Opdate dhcp option 'server-name' to actual server name */ - if($this->dn != $this->orig_dn){ - $fixed = FALSE; - foreach(array("dhcpHost","dhcpSubnet","dhcpGroup","dhcpSharedNetwork") as $object){ - if(in_array($object,$data['objectClass']) && isset($data['dhcpOption'])){ - foreach($data['dhcpOption'] as $key => $option){ - if(preg_match("/^server-name /",$option)){ - $data['dhcpOption'][$key] = "server-name ".$this->cn; - $data['MODIFIED'] = TRUE; - break; - } - } - } - - /* Skip next loops if entry is updated */ - if($fixed){ - break; - } - } - } - - /* 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!")); - - /* Optionally execute a command after we're done */ - $this->handle_post_events("modify"); - } else { - $ldap->add($attrs); - show_ldap_error($ldap->get_error(), _("Can't save DHCP object!")); - - /* Optionally execute a command after we're done */ - $this->handle_post_events("create"); - } - } - } - - $this->dhcpServiceDN= $this->serviceDN; - if($this->dn != $this->orig_dn){ - $this->dhcpServiceDN= preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$this->dhcpServiceDN); - } - - /* Replace 'new' dn */ - if(preg_match("/new$/",$this->dhcpServiceDN)){ - $this->dhcpServiceDN = preg_replace("/new$/",$this->dn,$this->dhcpServiceDN); - } - - plugin::save(); - - /* 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 */ - if ($this->initially_was_account == $this->is_account){ - if ($this->is_modified){ - $this->handle_post_events("modify"); - } - } else { - $this->handle_post_events("add"); - } - - /* Take over handling - * - Remove old dhcp config from source server - */ - if($this->take_over_id != -1){ - $id = $this->take_over_id; - $src = $this->dhcp_server_list['ENTRIES'][$id]['dn']; - $tmp = new servdhcp ($this->config, $src); - $tmp->remove_from_parent(); - } - } - - - function reload() - { - /* Init LDAP and load list */ - $ldap= $this->config->get_ldap_link(); - $ui= get_userinfo(); - $me= $this->dn; - - $filter = "(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))"; - - $list= get_list($filter, array("server"), $this->config->current['BASE'], array("cn"),GL_SIZELIMIT | GL_SUBSEARCH); - $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); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("DHCP service"), - "plDescription" => _("DHCP service")." ("._("Services").")", - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 84, - "plSection" => array("administration"), - "plCategory" => array("server"), - - "plProvidedAcls"=> array( - - ) - )); - } - - - function take_over_service() - { - - } - - - function get_list_of_dhcp_servers() - { - $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array()); - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=goServer)(dhcpServiceDN=*))",array("dn","cn","dhcpServiceDN")); - while($attrs = $ldap->fetch()){ - - /* Skip own config */ - if($this->dn != "new" && preg_match("/".normalizePreg($this->dn)."$/",$attrs['dn'])){ - continue; - } - - $ret['ENTRIES'][] = $attrs; - } - foreach($ret['ENTRIES'] as $key => $data){ - $ret['FOR_LIST'][$key] = $data['cn'][0]; - } - return($ret); - } - - - function getListEntry() - { - $fields = goService::getListEntry(); - $fields['Message'] = _("DHCP service"); - $fields['AllowEdit'] = true; - return($fields); - } - -} - -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/systems/services/dhcp/dhcpNewSection.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcpNewSection.tpl deleted file mode 100644 index 517c3b403..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcpNewSection.tpl +++ /dev/null @@ -1,25 +0,0 @@ -
- {t}Create new DHCP section{/t} -
-
-

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

-
-{t}Section{/t}  - - -

- -   - -

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

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

 

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

{t}Generic{/t}

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

 

- - - diff --git a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_host.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcp_host.tpl deleted file mode 100644 index 602c51255..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_host.tpl +++ /dev/null @@ -1,52 +0,0 @@ -{* 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/gosa-core/plugins/admin/systems/services/dhcp/dhcp_network.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcp_network.tpl deleted file mode 100644 index 5645a63ac..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_network.tpl +++ /dev/null @@ -1,90 +0,0 @@ -{* 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/gosa-core/plugins/admin/systems/services/dhcp/dhcp_pool.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcp_pool.tpl deleted file mode 100644 index dcbd05c3d..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_pool.tpl +++ /dev/null @@ -1,26 +0,0 @@ -{* GOsa dhcp sharedNetwork - smarty template *} -

{t}Generic{/t}

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

 

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

{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/gosa-core/plugins/admin/systems/services/dhcp/dhcp_sharedNetwork.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcp_sharedNetwork.tpl deleted file mode 100644 index 374da3500..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_sharedNetwork.tpl +++ /dev/null @@ -1,107 +0,0 @@ -{* 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/gosa-core/plugins/admin/systems/services/dhcp/dhcp_subnet.tpl b/gosa-core/plugins/admin/systems/services/dhcp/dhcp_subnet.tpl deleted file mode 100644 index 05425fbdc..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/dhcp_subnet.tpl +++ /dev/null @@ -1,41 +0,0 @@ -{* 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/gosa-core/plugins/admin/systems/services/dhcp/remove_dhcp.tpl b/gosa-core/plugins/admin/systems/services/dhcp/remove_dhcp.tpl deleted file mode 100644 index 39fb19bb6..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/remove_dhcp.tpl +++ /dev/null @@ -1,17 +0,0 @@ -
- {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/gosa-core/plugins/admin/systems/services/dhcp/servdhcp.tpl b/gosa-core/plugins/admin/systems/services/dhcp/servdhcp.tpl deleted file mode 100644 index 846af22ff..000000000 --- a/gosa-core/plugins/admin/systems/services/dhcp/servdhcp.tpl +++ /dev/null @@ -1,35 +0,0 @@ -{if $dns_take_over} - - - - -
-

{t}DHCP take over will take place when saving this entry. Choose 'Cancel' to abort.{/t}

-
-{else} - -{if $dhcp_server_list_cnt} - - - -{/if} - - - -
- {t}Take over dhcp configuration from following server{/t}  - - -
-

{t}DHCP sections{/t}

- {$DhcpList} -
-{/if} -

 

-
- -   - -
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,dirname(__FILE__)))); + } + + 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", "domain-name-servers", "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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc new file mode 100644 index 000000000..cbe987da8 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc @@ -0,0 +1,126 @@ +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 */ + $this->fix_options(); + 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() + { + $message= array(); + + $cache = $this->parent->dhcpObjectCache; + + /* 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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc new file mode 100644 index 000000000..e8aab5c95 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc @@ -0,0 +1,181 @@ +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,dirname(__FILE__))).$this->network->execute(); + + /* Merge arrays for advanced view */ + $this->fix_options(); + 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() + { + $message= array(); + + $cache = array(); + if(isset($this->parent)){ + $cache = $this->parent->dhcpObjectCache; + } + + /* 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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc new file mode 100644 index 000000000..146b0e21b --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc @@ -0,0 +1,226 @@ +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,dirname(__FILE__))); + } + + 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 (!tests::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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc new file mode 100644 index 000000000..756a97893 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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); + $ui = get_userinfo(); + $smarty->assign("sections", $t_sections); + $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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc new file mode 100644 index 000000000..628260522 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc @@ -0,0 +1,208 @@ +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() + { + $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'); + } + + + function fix_options() + { + foreach (array('domain-name-servers') as $key){ + unset ($this->options[$key]); + } + } + +} + +?> diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc new file mode 100644 index 000000000..eae26ddeb --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc @@ -0,0 +1,191 @@ +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 */ + $this->fix_options(); + 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() + { + $message= array(); + + $cache = $this->parent->dhcpObjectCache; + + /* 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 (!tests::is_ip($this->range_start) || !tests::is_ip($this->range_stop)){ + $message[]= _("Field 'Range' contains invalid IP addresses."); + } + + if(!tests::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 (!tests::is_in_network($network, $netmask, $this->range_start) || + !tests::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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc new file mode 100644 index 000000000..4989c43fc --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc @@ -0,0 +1,181 @@ +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 */ + $this->fix_options(); + 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 (!tests::is_id($this->statements['default-lease-time'])){ + $message[]= _('Default lease time needs to be numeric.'); + } + if (!tests::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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc new file mode 100644 index 000000000..5dfd47703 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc @@ -0,0 +1,188 @@ +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 */ + $this->fix_options(); + 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() + { + $message= array(); + + $cache = $this->parent->dhcpObjectCache; + + /* 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] != "" && + !tests::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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc new file mode 100644 index 000000000..7fa9e9823 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc @@ -0,0 +1,200 @@ +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 */ + $this->fix_options(); + 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() + { + $message= array(); + + $cache = $this->parent->dhcpObjectCache; + + /* 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 != "" && !tests::is_ip($this->$attr)){ + $message[]= sprintf(_("The field '%s' contains an invalid IP address"), $str); + } + } + + /* Check ip range */ + if ($this->use_range){ + if(!tests::is_ip_range($this->range_start,$this->range_stop)){ + $message[] = _("Field 'Range' contains invalid IP range."); + } + + /* Check if range is in the network */ + if (!tests::is_in_network($this->cn, $this->dhcpNetMask, $this->range_start) || + !tests::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/gosa-plugins/dhcp/admin/systems/services/dhcp/class_servDHCP.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_servDHCP.inc new file mode 100644 index 000000000..c804ec2bc --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_servDHCP.inc @@ -0,0 +1,739 @@ + array(),"FOR_LIST"=> array()); + var $take_over_id = -1; + var $display_warning = TRUE; + + function servdhcp (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + $this->serviceDN = "cn=dhcp,".$dn; + $this->orig_dn = $dn; + + $this->DisplayName = _("DHCP service"); + + $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; + $this->dhcp_server_list = $this->get_list_of_dhcp_servers(); + } + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty= get_smarty(); + $smarty->assign("dns_take_over",FALSE); + $display= ""; + + + /*****************/ + /* Handle Take Over Actions + /*****************/ + + /* Give smarty the required informations */ + $smarty->assign("dhcp_server_list", $this->dhcp_server_list['FOR_LIST']); + $smarty->assign("dhcp_server_list_cnt", count($this->dhcp_server_list['FOR_LIST'])); + + /* Take over requested, save id */ + if(isset($_POST['take_over_src']) && isset($_POST['take_over'])){ + $id = $_POST['take_over_src']; + if(isset($this->dhcp_server_list['ENTRIES'][$id])){ + $this->take_over_id = $id; + } + } + + /* Abort take over action */ + if(isset($_POST['cancel_take_over'])){ + $this->dialog =false; + $this->take_over_id = -1; + $this->dhcp_server_list = $this->get_list_of_dhcp_servers(); + } + + /* Display informartion about take over that will be started when saving this server + * and hide default dhcp output + */ + if($this->take_over_id != -1){ + + $this->dialog = FALSE; + $id = $this->take_over_id; + $smarty->assign("dns_take_over",TRUE); + $warning = sprintf(_("You are going to migrate the DHCP setup from server '%s'."), + $this->dhcp_server_list['ENTRIES'][$id]['cn'][0]); + $warning.= " "._("The migration will be started when you save this system. To cancel this action, use the cancel button below."); + + if($this->display_warning){ + print_red($warning); + $this->display_warning = FALSE; + } + return($smarty->fetch(get_template_path('servdhcp.tpl', TRUE))); + } + + + /*****************/ + /* List handling + /*****************/ + + /* 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= FALSE; + } + } + + /* Cancel section creation? */ + if (isset($_POST['cancel_section']) || isset($_POST['cancel_dhcp'])){ + $this->dialog= FALSE; + } + + /* Save changes */ + if (isset($_POST['save_dhcp'])){ + $this->dialog->save_object(); + $messages= $this->dialog->check(); + 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= FALSE; + } + } + + /* Remove section? */ + if (isset($_POST['delete_dhcp_confirm'])){ + if ($this->acl_is_removeable()){ + 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= FALSE; + } + + /* 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))); + } + } + + } + + if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){ + $dn = base64_decode($_GET['id']); + if (isset($this->dhcpObjectCache[$dn])){ + $section= $this->objectType($dn); + $this->current_object= $dn; + $this->dialog= new $section($this->dhcpObjectCache[$dn]); + } + } + + + if(isset($_GET['act']) && $_GET['act']=="edit" && isset($_GET['id'])){ + $dn = base64_decode($_GET['id']); + if (isset($this->dhcpObjectCache[$dn])){ + $section= $this->objectType($dn); + $this->current_object= $dn; + $this->dialog= new $section($this->dhcpObjectCache[$dn]); + } + } + + + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } + + /* Show tab dialog headers */ + if ($this->is_account){ +# $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_header(_("Add DHCP service"), + +# _("This server has DHCP features disabled. You can enable them by clicking below.")); + return ($display); + } + + + /* Show dialog + */ + if(isset($this->dialog) && is_object($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 ){ + + $values = "".$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;'") + )); + } + } + + /* Display tempalte */ + $smarty->assign("DhcpList",$DhcpList->DrawList()); + $display.= $smarty->fetch(get_template_path('servdhcp.tpl', TRUE)); + return($display); + } + + + function remove_from_parent() + { + /* 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"); + } + + + /* Save data to object */ + function save_object() + { + plugin::save_object(); + } + + + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + /* Save to LDAP */ + function save() + { + /* Take over handling + * - Load servdhcp class and dhcpObjectCache for the source dhcp setup. + * - Assign dhcpObjectCache to this configuration. + * - Save this setup and remove source setup from ldap. + */ + if($this->take_over_id != -1){ + $id = $this->take_over_id; + $src = preg_replace("/cn=dhcp,/","",$this->dhcp_server_list['ENTRIES'][$id]['dn']); + $tmp = new servdhcp ($this->config, $src); + $this->orig_dn = $src; + $this->dhcpObjectCache = $tmp->dhcpObjectCache; + } + + /* Save dhcp setttings */ + $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; + } + + /* Opdate dhcp option 'server-name' to actual server name */ + if($this->dn != $this->orig_dn){ + $fixed = FALSE; + foreach(array("dhcpHost","dhcpSubnet","dhcpGroup","dhcpSharedNetwork") as $object){ + if(in_array($object,$data['objectClass']) && isset($data['dhcpOption'])){ + foreach($data['dhcpOption'] as $key => $option){ + if(preg_match("/^server-name /",$option)){ + $data['dhcpOption'][$key] = "server-name ".$this->cn; + $data['MODIFIED'] = TRUE; + break; + } + } + } + + /* Skip next loops if entry is updated */ + if($fixed){ + break; + } + } + } + + /* 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!")); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("modify"); + } else { + $ldap->add($attrs); + show_ldap_error($ldap->get_error(), _("Can't save DHCP object!")); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("create"); + } + } + } + + $this->dhcpServiceDN= $this->serviceDN; + if($this->dn != $this->orig_dn){ + $this->dhcpServiceDN= preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$this->dhcpServiceDN); + } + + /* Replace 'new' dn */ + if(preg_match("/new$/",$this->dhcpServiceDN)){ + $this->dhcpServiceDN = preg_replace("/new$/",$this->dn,$this->dhcpServiceDN); + } + + plugin::save(); + + /* 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 */ + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } + + /* Take over handling + * - Remove old dhcp config from source server + */ + if($this->take_over_id != -1){ + $id = $this->take_over_id; + $src = $this->dhcp_server_list['ENTRIES'][$id]['dn']; + $tmp = new servdhcp ($this->config, $src); + $tmp->remove_from_parent(); + } + } + + + function reload() + { + /* Init LDAP and load list */ + $ldap= $this->config->get_ldap_link(); + $ui= get_userinfo(); + $me= $this->dn; + + $filter = "(&(objectClass=dhcpService)(|(dhcpPrimaryDN=$me)(dhcpSecondaryDN=$me)(dhcpServerDN=$me)(dhcpFailOverPeerDN=$me)))"; + + $list= get_list($filter, array("server"), $this->config->current['BASE'], array("cn"),GL_SIZELIMIT | GL_SUBSEARCH); + $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); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("DHCP service"), + "plDescription" => _("DHCP service")." ("._("Services").")", + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 84, + "plSection" => array("administration"), + "plCategory" => array("server"), + + "plProvidedAcls"=> array( + + ) + )); + } + + + function take_over_service() + { + + } + + + function get_list_of_dhcp_servers() + { + $ret = array("ENTRIES"=> array(),"FOR_LIST"=> array()); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=goServer)(dhcpServiceDN=*))",array("dn","cn","dhcpServiceDN")); + while($attrs = $ldap->fetch()){ + + /* Skip own config */ + if($this->dn != "new" && preg_match("/".normalizePreg($this->dn)."$/",$attrs['dn'])){ + continue; + } + + $ret['ENTRIES'][] = $attrs; + } + foreach($ret['ENTRIES'] as $key => $data){ + $ret['FOR_LIST'][$key] = $data['cn'][0]; + } + return($ret); + } + + + function getListEntry() + { + $fields = goService::getListEntry(); + $fields['Message'] = _("DHCP service"); + $fields['AllowEdit'] = true; + return($fields); + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcpNewSection.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcpNewSection.tpl new file mode 100644 index 000000000..517c3b403 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl new file mode 100644 index 000000000..5ce0e4600 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_group.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_group.tpl new file mode 100644 index 000000000..930fc05ee --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_group.tpl @@ -0,0 +1,22 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

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

 

+ + + diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_host.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_host.tpl new file mode 100644 index 000000000..602c51255 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_network.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_network.tpl new file mode 100644 index 000000000..5645a63ac --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_pool.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_pool.tpl new file mode 100644 index 000000000..dcbd05c3d --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_service.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_service.tpl new file mode 100644 index 000000000..6ca515e67 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_sharedNetwork.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_sharedNetwork.tpl new file mode 100644 index 000000000..374da3500 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_subnet.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_subnet.tpl new file mode 100644 index 000000000..05425fbdc --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/remove_dhcp.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/remove_dhcp.tpl new file mode 100644 index 000000000..39fb19bb6 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/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/gosa-plugins/dhcp/admin/systems/services/dhcp/servdhcp.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/servdhcp.tpl new file mode 100644 index 000000000..846af22ff --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/servdhcp.tpl @@ -0,0 +1,35 @@ +{if $dns_take_over} + + + + +
+

{t}DHCP take over will take place when saving this entry. Choose 'Cancel' to abort.{/t}

+
+{else} + +{if $dhcp_server_list_cnt} + + + +{/if} + + + +
+ {t}Take over dhcp configuration from following server{/t}  + + +
+

{t}DHCP sections{/t}

+ {$DhcpList} +
+{/if} +

 

+
+ +   + +