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