From: cajus Date: Wed, 1 Aug 2007 16:22:29 +0000 (+0000) Subject: Updated (still non-working) dhcp service plugin X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ba1060f285624a1563165d7d1ef40a9866ef3e83;p=gosa.git Updated (still non-working) dhcp service plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6955 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpAdvanced.inc b/plugins/admin/systems/class_dhcpAdvanced.inc new file mode 100644 index 000000000..e9a40c15b --- /dev/null +++ b/plugins/admin/systems/class_dhcpAdvanced.inc @@ -0,0 +1,104 @@ +is_account= TRUE; + } + + function execute() + { + /* Check for interaction */ + if (isset($_POST['add_statement']) && $_POST['addstatement'] != ""){ + $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['addstatement']); + $val= preg_replace("/^$key\s*/", '', $_POST['addstatement']); + $this->statements[$key]= $val; + } + if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){ + $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpstatements']); + unset($this->statements[$key]); + } + if (isset($_POST['add_option']) && $_POST['addoption'] != ""){ + $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['addoption']); + $val= preg_replace("/^$key\s*/", '', $_POST['addoption']); + $this->options[$key]= $val; + } + if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){ + $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpoptions']); + unset($this->options[$key]); + } + + $smarty= get_smarty(); + + /* Assign arrays */ + $statements= array(); + foreach ($this->statements as $key => $val){ + $statements[$key]= "$key $val"; + } + $smarty->assign("dhcpstatements", $statements); + $options= array(); + foreach ($this->options as $key => $val){ + $options[$key]= "$key $val"; + } + $smarty->assign("dhcpoptions", $options); + + /* Show main page */ + return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE))); + } + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + } + + + /* Check values */ + function check() + { + /* Nothing to check here */ + $message= array(); + return $message; + } + + + /* Save to LDAP */ + function save() + { + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index 6a3092dc5..2f6573856 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -74,6 +74,9 @@ class dhcpHost extends plugin $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; } function execute() @@ -97,7 +100,7 @@ class dhcpHost extends plugin "token-ring" => _("Token Ring"))); /* Show main page */ - return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute()); + return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute().$this->advanced->execute()); } diff --git a/plugins/admin/systems/class_dhcpNetwork.inc b/plugins/admin/systems/class_dhcpNetwork.inc new file mode 100644 index 000000000..c3d97de49 --- /dev/null +++ b/plugins/admin/systems/class_dhcpNetwork.inc @@ -0,0 +1,245 @@ +is_account= TRUE; + } + + function execute() + { + /* Check for iteraction */ + if (isset($_POST['add_dns']) && $_POST['addserver'] != ""){ + if (!preg_match('/^[0-9a-z.-]+$/', $_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[$_POST['addserver']]= $_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*)?".$_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", trim($this->statements['next-server'], '"')); + } else { + $smarty->assign("nextserver", ""); + } + + /* Set flags */ + $smarty->assign("autohost", ""); + if (isset($this->statements['get-lease-hostnames'])){ + if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){ + $smarty->assign("autohost", "checked"); + } + } + $smarty->assign("autohostdecl", ""); + if (isset($this->statements['use-host-decl-names'])){ + if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){ + $smarty->assign("autohostdecl", "checked"); + } + } + + return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE)); + } + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + /* Only save, if we are "active" */ + if (isset($_POST['routers'])){ + + /* + * Assemble options + */ + + /* Options */ + foreach (array("routers" => "routers", "domain-name" => "domain") as $key => $val){ + + if ($_POST["$val"] == ''){ + unset($this->options["$key"]); + } else { + $this->options["$key"]= $_POST["$val"]; + } + } + + /* Statements */ + foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){ + if ($_POST["$val"] == ''){ + unset($this->statements["$key"]); + } else { + $this->statements["$key"]= '"'.$_POST["$val"].'"'; + } + } + + /* Netmask / Broadcast */ + foreach (array("subnet-mask" => "nm", "broadcast-address" => "bc") + as $key => $val){ + + $tmp= ""; + for ($i= 0; $i<4; $i++){ + $tmp.= $_POST["$val$i"]."."; + } + if ($tmp == "...."){ + unset($this->options["$key"]); + } else { + $this->options["$key"]= preg_replace('/\.$/', '', $tmp); + } + } + + /* 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"]); + + list($n0,$n1,$n2,$n3)= split('\.', $tmp); + for ($i= 0; $i<4; $i++){ + $name= "n$i"; + if (preg_match('/^[0-9]+$/', $$name)){ + $val= (int)($$name); + if ($val < 0 || $val > 255){ + $message[]= sprintf(_("Error in definition of '%s'!"), $typ); + break; + } + } else { + $message[]= sprintf(_("Illegal characters in definition of '%s'!"), $typ); + break; + } + } + } + + #FIXME: There are some more things we could test -> valid netmask, range + return $message; + } + + + /* Save to LDAP */ + function save() + { + } + +} + +?> diff --git a/plugins/admin/systems/dhcp_advanced.tpl b/plugins/admin/systems/dhcp_advanced.tpl new file mode 100644 index 000000000..e155a4ca9 --- /dev/null +++ b/plugins/admin/systems/dhcp_advanced.tpl @@ -0,0 +1,33 @@ +{* GOsa dhcp sharedNetwork - smarty template *} + + + + + + + + +
+
+ {t}DHCP statements{/t} +
+ +
+   +   + +
+
+ {t}DHCP options{/t} +
+ +
+   +   + +
+ diff --git a/plugins/admin/systems/dhcp_network.tpl b/plugins/admin/systems/dhcp_network.tpl new file mode 100644 index 000000000..b00ed71c5 --- /dev/null +++ b/plugins/admin/systems/dhcp_network.tpl @@ -0,0 +1,88 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +
+ + + + + +
+ {t}Network base 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}Server{/t}
+ +
+   + + +
+
+ {t}Domain Name Service options{/t}
+ {t}Assign hostnames found via reverse mapping{/t} +
+ {t}Assign hostnames from host declarations{/t} +
+ +
+ diff --git a/plugins/admin/systems/dhcphost.tpl b/plugins/admin/systems/dhcphost.tpl index 21511c0d4..dc1b1912a 100644 --- a/plugins/admin/systems/dhcphost.tpl +++ b/plugins/admin/systems/dhcphost.tpl @@ -48,9 +48,10 @@ +
Temporary escape: - +