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= null;
25 var $statements= null;
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->initTime = microtime(TRUE);
35 $this->is_account= TRUE;
37 // Create statistic table entry
38 stats::log('plugin', $class = get_class($this), $category = array($this->acl_category), $action = 'open',
39 $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
40 }
42 function execute()
43 {
44 plugin::execute();
46 $acl_writeable = preg_match("/w/",$this->parent->getacl(""));
48 /* Check for iteraction */
49 if ($acl_writeable && isset($_POST['add_dns']) && $_POST['addserver'] != ""){
50 if (!preg_match('/^[0-9a-z.-]+$/', get_post('addserver'))){
51 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),
52 htmlentities(get_post('addserver')),"/[0-9a-z.-]/"), ERROR_DIALOG);
53 } else {
54 $servers= array();
55 if($this->options->exists('domain-name-servers')){
56 foreach(explode(",", $this->options->get('domain-name-servers')) as $val){
57 $servers[$val]= $val;
58 }
59 }
60 $servers[get_post('addserver')]= get_post('addserver');
62 $tmp= "";
63 foreach($servers as $val){
64 $tmp.= $val.",";
65 }
66 $this->options->removeAll('domain-name-servers');
67 $this->options->set('domain-name-servers',preg_replace('/,$/', '', $tmp));
68 }
69 }
71 if ($acl_writeable && isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
72 $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '',
73 $this->options->get('domain-name-servers'));
74 $tmp= trim(preg_replace("/(\s*)?,(\s*)?$/", '', $tmp),",");
78 if ($tmp != ""){
79 $this->options->set('domain-name-servers', $tmp);
80 } else {
81 $this->options->remove('domain-name-servers');
82 }
83 }
85 /* Show main page */
86 $smarty= get_smarty();
88 /* Assign ACLs */
89 $smarty->assign("acl",$this->parent->getacl(""));
91 /*
92 * Assemble options
93 */
95 /* Router */
96 $smarty->assign("routers", set_post($this->options->get('routers')));
98 /* DNS */
99 $smarty->assign("domain", set_post($this->options->get('domain-name')));
101 if($this->options->exists('domain-name-servers')){
102 $servers= array();
103 foreach(explode(",", $this->options->get('domain-name-servers')) as $val){
104 $servers[$val]= $val;
105 }
106 $smarty->assign("dnsservers", set_post($servers));
107 } else {
108 $smarty->assign("dnsservers", array());
109 }
111 /* Netmask / Broadcast */
112 if ($this->options->exists('subnet-mask')){
113 $this->options->set('subnet-mask',normalize_netmask($this->options->get('subnet-mask')));
114 }
115 $smarty->assign("subnet_mask", set_post($this->options->get('subnet-mask')));
116 $smarty->assign("broadcast_address",set_post($this->options->get('broadcast-address')));
118 /* Boot stuff */
119 $smarty->assign("filename", set_post($this->statements->get('filename')));
120 $smarty->assign("nextserver", set_post($this->statements->get('next-server')));
122 /* Set flags */
123 $smarty->assign("autohost", "");
124 if ($this->statements->exists('get-lease-hostnames')){
125 if (preg_match('/^(true|on|yes)$/', $this->statements->get('get-lease-hostnames'))){
126 $smarty->assign("autohost", "checked");
127 }
128 }
129 $smarty->assign("autohostdecl", "");
130 if ($this->statements->exists('use-host-decl-names')){
131 if (preg_match('/^(true|on|yes)$/', $this->statements->get('use-host-decl-names'))){
132 $smarty->assign("autohostdecl", "checked");
133 }
134 }
136 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE,dirname(__FILE__)));
137 }
139 function remove_from_parent()
140 {
141 }
144 /* Save data to object */
145 function save_object()
146 {
147 /* Only save, if we are "active" */
148 if (isset($_POST['routers']) && preg_match("/w/",$this->parent->getacl(""))){
150 /*
151 * Assemble options
152 */
154 /* Options */
155 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
156 "broadcast-address" => "broadcast_address") as $key => $val){
157 if ($_POST["$val"] == ''){
158 $this->options->remove($key);
159 } else {
160 $this->options->set($key,get_post($val));
161 }
162 }
164 /* Statements */
165 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
166 if ($_POST["$val"] == ''){
167 $this->statements->removeAll($key);
168 } else {
170 /* Only quote filename values */
171 if(in_array_strict($key,array("filename"))){
172 $this->statements->set($key,'"'.trim(get_post($val),"\"").'"');
173 }else{
174 $this->statements->set($key,get_post($val));
175 }
176 }
177 }
179 /* Flags */
180 if (isset ($_POST['autohost'])){
181 $this->statements->set('get-lease-hostnames',"true");
182 } else {
183 $this->statements->removeAll('get-lease-hostnames');
184 }
185 if (isset ($_POST['autohostdecl'])){
186 $this->statements->set('use-host-decl-names', "on");
187 } else {
188 $this->statements->removeAll('use-host-decl-names');
189 }
190 }
191 }
194 /* Check values */
195 function check()
196 {
197 $message= array();
199 /* Check netmask and broadcast */
200 foreach(array("subnet-mask" => _("Net mask"), "broadcast-address" => _("Broadcast address")) as $key => $typ){
201 if (!$this->options->exists("$key")){
202 continue;
203 }
204 if (!tests::is_ip($this->options->get($key))){
205 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
206 }
207 }
208 return $message;
209 }
212 /* Save to LDAP */
213 function save()
214 {
215 }
217 }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>