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