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 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),htmlentities(get_post('addserver')),"/[0-9a-z.-]/"), ERROR_DIALOG);
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');
52 $tmp= "";
53 foreach($servers as $val){
54 $tmp.= $val.",";
55 }
56 $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
57 }
58 }
59 if (isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
60 $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '',
61 $this->options['domain-name-servers']);
62 $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp);
63 if ($tmp != ""){
64 $this->options['domain-name-servers']= $tmp;
65 } else {
66 unset($this->options['domain-name-servers']);
67 }
68 }
70 /* Show main page */
71 $smarty= get_smarty();
73 /*
74 * Assemble options
75 */
77 /* Router */
78 if (isset($this->options['routers'])){
79 $smarty->assign("routers", $this->options['routers']);
80 } else {
81 $smarty->assign("routers", "");
82 }
84 /* DNS */
85 if (isset($this->options['domain-name'])){
86 $smarty->assign("domain", trim($this->options['domain-name'], '"'));
87 } else {
88 $smarty->assign("domain", "");
89 }
90 if (isset($this->options['domain-name-servers'])){
91 $servers= array();
92 foreach(split(",", $this->options['domain-name-servers']) as $val){
93 $servers[$val]= $val;
94 }
95 $smarty->assign("dnsservers", $servers);
96 } else {
97 $smarty->assign("dnsservers", "");
98 }
100 /* Netmask / Broadcast */
101 if (isset($this->options['subnet-mask'])){
102 $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
103 $smarty->assign("subnet_mask", $this->options['subnet-mask']);
104 } else {
105 $smarty->assign("subnet_mask", "");
106 }
107 if (isset($this->options['broadcast-address'])){
108 $smarty->assign("broadcast_address", $this->options['broadcast-address']);
109 } else {
110 $smarty->assign("broadcast_address", "");
111 }
113 /* Boot stuff */
114 if (isset($this->statements['filename'])){
115 $smarty->assign("filename", trim($this->statements['filename'], '"'));
116 } else {
117 $smarty->assign("filename", "");
118 }
119 if (isset($this->statements['next-server'])){
120 $smarty->assign("nextserver", $this->statements['next-server']);
121 } else {
122 $smarty->assign("nextserver", "");
123 }
125 /* Set flags */
126 $smarty->assign("autohost", "");
127 if (isset($this->statements['get-lease-hostnames'])){
128 if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
129 $smarty->assign("autohost", "checked");
130 }
131 }
132 $smarty->assign("autohostdecl", "");
133 if (isset($this->statements['use-host-decl-names'])){
134 if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
135 $smarty->assign("autohostdecl", "checked");
136 }
137 }
139 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE,dirname(__FILE__)));
140 }
142 function remove_from_parent()
143 {
144 }
147 /* Save data to object */
148 function save_object()
149 {
150 /* Only save, if we are "active" */
151 if (isset($_POST['routers'])){
153 /*
154 * Assemble options
155 */
157 /* Options */
158 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
159 "broadcast-address" => "broadcast_address") as $key => $val){
161 if ($_POST["$val"] == ''){
162 unset($this->options["$key"]);
163 } else {
164 $this->options["$key"]= get_post("$val");
165 }
166 }
168 /* Statements */
169 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
170 if ($_POST["$val"] == ''){
171 unset($this->statements["$key"]);
172 } else {
174 /* Only quote filename values */
175 if(in_array($key,array("filename"))){
176 $this->statements["$key"]= '"'.get_post("$val").'"';
177 }else{
178 $this->statements["$key"]= get_post("$val");
179 }
180 }
181 }
183 /* Flags */
184 if (isset ($_POST['autohost'])){
185 $this->statements['get-lease-hostnames']= "true";
186 } else {
187 unset($this->statements['get-lease-hostnames']);
188 }
189 if (isset ($_POST['autohostdecl'])){
190 $this->statements['use-host-decl-names']= "on";
191 } else {
192 unset($this->statements['use-host-decl-names']);
193 }
194 }
195 }
198 /* Check values */
199 function check()
200 {
201 $message= array();
203 /* Check netmask and broadcast */
204 foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
205 if (!isset($this->options["$key"])){
206 continue;
207 }
208 $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
210 if (!tests::is_ip($tmp)){
211 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
212 }
213 }
215 return $message;
216 }
219 /* Save to LDAP */
220 function save()
221 {
222 }
224 }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>