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->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($this->options->exists('domain-name-servers')){
50 foreach(split(",", $this->options->get('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->removeAll('domain-name-servers');
61 $this->options->set('domain-name-servers',preg_replace('/,$/', '', $tmp));
62 }
63 }
65 if ($acl_writeable && isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
66 $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '',
67 $this->options->get('domain-name-servers'));
68 $tmp= trim(preg_replace("/(\s*)?,(\s*)?$/", '', $tmp),",");
72 if ($tmp != ""){
73 $this->options->set('domain-name-servers', $tmp);
74 } else {
75 $this->options->remove('domain-name-servers');
76 }
77 }
79 /* Show main page */
80 $smarty= get_smarty();
82 /* Assign ACLs */
83 $smarty->assign("acl",$this->parent->getacl(""));
85 /*
86 * Assemble options
87 */
89 /* Router */
90 $smarty->assign("routers", $this->options->get('routers'));
92 /* DNS */
93 $smarty->assign("domain",$this->options->get('domain-name'));
95 if($this->options->exists('domain-name-servers')){
96 $servers= array();
97 foreach(split(",", $this->options->get('domain-name-servers')) as $val){
98 $servers[$val]= $val;
99 }
100 $smarty->assign("dnsservers", $servers);
101 } else {
102 $smarty->assign("dnsservers", "");
103 }
105 /* Netmask / Broadcast */
106 if ($this->options->exists('subnet-mask')){
107 $this->options->set('subnet-mask',normalize_netmask($this->options->get('subnet-mask')));
108 }
109 $smarty->assign("subnet_mask", $this->options->get('subnet-mask'));
110 $smarty->assign("broadcast_address", $this->options->get('broadcast-address'));
112 /* Boot stuff */
113 $smarty->assign("filename", $this->statements->get('filename'));
114 $smarty->assign("nextserver", $this->statements->get('next-server'));
116 /* Set flags */
117 $smarty->assign("autohost", "");
118 if ($this->statements->exists('get-lease-hostnames')){
119 if (preg_match('/^(true|on|yes)$/', $this->statements->get('get-lease-hostnames'))){
120 $smarty->assign("autohost", "checked");
121 }
122 }
123 $smarty->assign("autohostdecl", "");
124 if ($this->statements->exists('use-host-decl-names')){
125 if (preg_match('/^(true|on|yes)$/', $this->statements->get('use-host-decl-names'))){
126 $smarty->assign("autohostdecl", "checked");
127 }
128 }
130 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE,dirname(__FILE__)));
131 }
133 function remove_from_parent()
134 {
135 }
138 /* Save data to object */
139 function save_object()
140 {
141 /* Only save, if we are "active" */
142 if (isset($_POST['routers']) && preg_match("/w/",$this->parent->getacl(""))){
144 /*
145 * Assemble options
146 */
148 /* Options */
149 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
150 "broadcast-address" => "broadcast_address") as $key => $val){
151 if ($_POST["$val"] == ''){
152 $this->options->remove($key);
153 } else {
154 $this->options->set($key,get_post($val));
155 }
156 }
158 /* Statements */
159 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
160 if ($_POST["$val"] == ''){
161 $this->statements->removeAll($key);
162 } else {
164 /* Only quote filename values */
165 if(in_array($key,array("filename"))){
166 $this->statements->set($key,'"'.trim(get_post($val),"\"").'"');
167 }else{
168 $this->statements->set($key,get_post($val));
169 }
170 }
171 }
173 /* Flags */
174 if (isset ($_POST['autohost'])){
175 $this->statements->set('get-lease-hostnames',"true");
176 } else {
177 $this->statements->removeAll('get-lease-hostnames');
178 }
179 if (isset ($_POST['autohostdecl'])){
180 $this->statements->set('use-host-decl-names', "on");
181 } else {
182 $this->statements->removeAll('use-host-decl-names');
183 }
184 }
185 }
188 /* Check values */
189 function check()
190 {
191 $message= array();
193 /* Check netmask and broadcast */
194 foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
195 if (!$this->options->exists("$key")){
196 continue;
197 }
198 if (!tests::is_ip($this->options->get($key))){
199 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
200 }
201 }
202 return $message;
203 }
206 /* Save to LDAP */
207 function save()
208 {
209 }
211 }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>