1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004-2007 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class dhcpNetwork extends plugin
22 {
23 /* Used attributes */
24 var $options= array();
25 var $statements= array();
27 /* attribute list for save action */
28 var $attributes= array();
29 var $objectclasses= array();
31 function dhcpNetwork()
32 {
33 /* This is always an account */
34 $this->is_account= TRUE;
35 }
37 function execute()
38 {
39 /* Check for iteraction */
40 if (isset($_POST['add_dns']) && $_POST['addserver'] != ""){
41 if (!preg_match('/^[0-9a-z.-]+$/', get_post('addserver'))){
42 print_red(_("The name of the DNS server your're going to add is not valid!"));
43 } else {
44 $servers= array();
45 if (isset($this->options['domain-name-servers'])){
46 foreach(split(",", $this->options['domain-name-servers']) as $val){
47 $servers[$val]= $val;
48 }
49 }
50 $servers[get_post('addserver')]= get_post('addserver');
51 $tmp= "";
52 foreach($servers as $val){
53 $tmp.= $val.",";
54 }
55 $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
56 }
57 }
58 if (isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
59 $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '',
60 $this->options['domain-name-servers']);
61 $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp);
62 if ($tmp != ""){
63 $this->options['domain-name-servers']= $tmp;
64 } else {
65 unset($this->options['domain-name-servers']);
66 }
67 }
69 /* Show main page */
70 $smarty= get_smarty();
72 /*
73 * Assemble options
74 */
76 /* Router */
77 if (isset($this->options['routers'])){
78 $smarty->assign("routers", $this->options['routers']);
79 } else {
80 $smarty->assign("routers", "");
81 }
83 /* DNS */
84 if (isset($this->options['domain-name'])){
85 $smarty->assign("domain", trim($this->options['domain-name'], '"'));
86 } else {
87 $smarty->assign("domain", "");
88 }
89 if (isset($this->options['domain-name-servers'])){
90 $servers= array();
91 foreach(split(",", $this->options['domain-name-servers']) as $val){
92 $servers[$val]= $val;
93 }
94 $smarty->assign("dnsservers", $servers);
95 } else {
96 $smarty->assign("dnsservers", "");
97 }
99 /* Netmask / Broadcast */
100 if (isset($this->options['subnet-mask'])){
101 $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
102 $smarty->assign("subnet_mask", $this->options['subnet-mask']);
103 } else {
104 $smarty->assign("subnet_mask", "");
105 }
106 if (isset($this->options['broadcast-address'])){
107 $smarty->assign("broadcast_address", $this->options['broadcast-address']);
108 } else {
109 $smarty->assign("broadcast_address", "");
110 }
112 /* Boot stuff */
113 if (isset($this->statements['filename'])){
114 $smarty->assign("filename", trim($this->statements['filename'], '"'));
115 } else {
116 $smarty->assign("filename", "");
117 }
118 if (isset($this->statements['next-server'])){
119 $smarty->assign("nextserver", $this->statements['next-server']);
120 } else {
121 $smarty->assign("nextserver", "");
122 }
124 /* Set flags */
125 $smarty->assign("autohost", "");
126 if (isset($this->statements['get-lease-hostnames'])){
127 if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
128 $smarty->assign("autohost", "checked");
129 }
130 }
131 $smarty->assign("autohostdecl", "");
132 if (isset($this->statements['use-host-decl-names'])){
133 if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
134 $smarty->assign("autohostdecl", "checked");
135 }
136 }
138 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE));
139 }
141 function remove_from_parent()
142 {
143 }
146 /* Save data to object */
147 function save_object()
148 {
149 /* Only save, if we are "active" */
150 if (isset($_POST['routers'])){
152 /*
153 * Assemble options
154 */
156 /* Options */
157 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
158 "broadcast-address" => "broadcast_address") as $key => $val){
160 if ($_POST["$val"] == ''){
161 unset($this->options["$key"]);
162 } else {
163 $this->options["$key"]= get_post("$val");
164 }
165 }
167 /* Statements */
168 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
169 if ($_POST["$val"] == ''){
170 unset($this->statements["$key"]);
171 } else {
173 /* Only quote filename values */
174 if(in_array($key,array("filename"))){
175 $this->statements["$key"]= '"'.get_post("$val").'"';
176 }else{
177 $this->statements["$key"]= get_post("$val");
178 }
179 }
180 }
182 /* Flags */
183 if (isset ($_POST['autohost'])){
184 $this->statements['get-lease-hostnames']= "true";
185 } else {
186 unset($this->statements['get-lease-hostnames']);
187 }
188 if (isset ($_POST['autohostdecl'])){
189 $this->statements['use-host-decl-names']= "on";
190 } else {
191 unset($this->statements['use-host-decl-names']);
192 }
193 }
194 }
197 /* Check values */
198 function check()
199 {
200 $message= array();
202 /* Check netmask and broadcast */
203 foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
204 if (!isset($this->options["$key"])){
205 continue;
206 }
207 $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
209 if (!is_ip($tmp)){
210 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
211 }
212 }
214 return $message;
215 }
218 /* Save to LDAP */
219 function save()
220 {
221 }
223 }
224 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
225 ?>