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 /* Assign ACLs */
74 $smarty->assign("acl",$this->parent->getacl(""));
76 /*
77 * Assemble options
78 */
80 /* Router */
81 if (isset($this->options['routers'])){
82 $smarty->assign("routers", $this->options['routers']);
83 } else {
84 $smarty->assign("routers", "");
85 }
87 /* DNS */
88 if (isset($this->options['domain-name'])){
89 $smarty->assign("domain", trim($this->options['domain-name'], '"'));
90 } else {
91 $smarty->assign("domain", "");
92 }
93 if (isset($this->options['domain-name-servers'])){
94 $servers= array();
95 foreach(split(",", $this->options['domain-name-servers']) as $val){
96 $servers[$val]= $val;
97 }
98 $smarty->assign("dnsservers", $servers);
99 } else {
100 $smarty->assign("dnsservers", "");
101 }
103 /* Netmask / Broadcast */
104 if (isset($this->options['subnet-mask'])){
105 $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
106 $smarty->assign("subnet_mask", $this->options['subnet-mask']);
107 } else {
108 $smarty->assign("subnet_mask", "");
109 }
110 if (isset($this->options['broadcast-address'])){
111 $smarty->assign("broadcast_address", $this->options['broadcast-address']);
112 } else {
113 $smarty->assign("broadcast_address", "");
114 }
116 /* Boot stuff */
117 if (isset($this->statements['filename'])){
118 $smarty->assign("filename", trim($this->statements['filename'], '"'));
119 } else {
120 $smarty->assign("filename", "");
121 }
122 if (isset($this->statements['next-server'])){
123 $smarty->assign("nextserver", $this->statements['next-server']);
124 } else {
125 $smarty->assign("nextserver", "");
126 }
128 /* Set flags */
129 $smarty->assign("autohost", "");
130 if (isset($this->statements['get-lease-hostnames'])){
131 if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
132 $smarty->assign("autohost", "checked");
133 }
134 }
135 $smarty->assign("autohostdecl", "");
136 if (isset($this->statements['use-host-decl-names'])){
137 if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
138 $smarty->assign("autohostdecl", "checked");
139 }
140 }
142 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE,dirname(__FILE__)));
143 }
145 function remove_from_parent()
146 {
147 }
150 /* Save data to object */
151 function save_object()
152 {
153 /* Only save, if we are "active" */
154 if (isset($_POST['routers'])){
156 /*
157 * Assemble options
158 */
160 /* Options */
161 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
162 "broadcast-address" => "broadcast_address") as $key => $val){
164 if ($_POST["$val"] == ''){
165 unset($this->options["$key"]);
166 } else {
167 $this->options["$key"]= get_post("$val");
168 }
169 }
171 /* Statements */
172 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
173 if ($_POST["$val"] == ''){
174 unset($this->statements["$key"]);
175 } else {
177 /* Only quote filename values */
178 if(in_array($key,array("filename"))){
179 $this->statements["$key"]= '"'.get_post("$val").'"';
180 }else{
181 $this->statements["$key"]= get_post("$val");
182 }
183 }
184 }
186 /* Flags */
187 if (isset ($_POST['autohost'])){
188 $this->statements['get-lease-hostnames']= "true";
189 } else {
190 unset($this->statements['get-lease-hostnames']);
191 }
192 if (isset ($_POST['autohostdecl'])){
193 $this->statements['use-host-decl-names']= "on";
194 } else {
195 unset($this->statements['use-host-decl-names']);
196 }
197 }
198 }
201 /* Check values */
202 function check()
203 {
204 $message= array();
206 /* Check netmask and broadcast */
207 foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
208 if (!isset($this->options["$key"])){
209 continue;
210 }
211 $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
213 if (!tests::is_ip($tmp)){
214 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
215 }
216 }
218 return $message;
219 }
222 /* Save to LDAP */
223 function save()
224 {
225 }
227 }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>