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.-]+$/', $_POST['addserver'])){
42 print_red(_("The name of the DNS server your're going to add is not valid!"));
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[$_POST['addserver']]= $_POST['addserver'];
51 $tmp= "";
52 foreach($servers as $val){
53 $tmp.= $val.",";
54 }
55 $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
56 }
57 }
58 if (isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
59 $tmp= preg_replace("/(\s*,\s*)?".$_POST['dnsserver']."/i", '',
60 $this->options['domain-name-servers']);
61 $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp);
62 if ($tmp != ""){
63 $this->options['domain-name-servers']= $tmp;
64 } else {
65 unset($this->options['domain-name-servers']);
66 }
67 }
69 /* Show main page */
70 $smarty= get_smarty();
72 /*
73 * Assemble options
74 */
76 /* Router */
77 if (isset($this->options['routers'])){
78 $smarty->assign("routers", $this->options['routers']);
79 } else {
80 $smarty->assign("routers", "");
81 }
83 /* DNS */
84 if (isset($this->options['domain-name'])){
85 $smarty->assign("domain", trim($this->options['domain-name'], '"'));
86 } else {
87 $smarty->assign("domain", "");
88 }
89 if (isset($this->options['domain-name-servers'])){
90 $servers= array();
91 foreach(split(",", $this->options['domain-name-servers']) as $val){
92 $servers[$val]= $val;
93 }
94 $smarty->assign("dnsservers", $servers);
95 } else {
96 $smarty->assign("dnsservers", "");
97 }
99 /* Netmask / Broadcast */
100 if (isset($this->options['subnet-mask'])){
101 $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
102 $smarty->assign("subnet_mask", $this->options['subnet-mask']);
103 } else {
104 $smarty->assign("subnet_mask", "");
105 }
106 if (isset($this->options['broadcast-address'])){
107 $smarty->assign("broadcast_address", $this->options['broadcast-address']);
108 } else {
109 $smarty->assign("broadcast_address", "");
110 }
112 /* Boot stuff */
113 if (isset($this->statements['filename'])){
114 $smarty->assign("filename", trim($this->statements['filename'], '"'));
115 } else {
116 $smarty->assign("filename", "");
117 }
118 if (isset($this->statements['next-server'])){
119 $smarty->assign("nextserver", trim($this->statements['next-server'], '"'));
120 } else {
121 $smarty->assign("nextserver", "");
122 }
124 /* Set flags */
125 $smarty->assign("autohost", "");
126 if (isset($this->statements['get-lease-hostnames'])){
127 if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
128 $smarty->assign("autohost", "checked");
129 }
130 }
131 $smarty->assign("autohostdecl", "");
132 if (isset($this->statements['use-host-decl-names'])){
133 if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
134 $smarty->assign("autohostdecl", "checked");
135 }
136 }
138 return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE));
139 }
141 function remove_from_parent()
142 {
143 }
146 /* Save data to object */
147 function save_object()
148 {
149 /* Only save, if we are "active" */
150 if (isset($_POST['routers'])){
152 /*
153 * Assemble options
154 */
156 /* Options */
157 foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
158 "broadcast-address" => "broadcast_address") as $key => $val){
160 if ($_POST["$val"] == ''){
161 unset($this->options["$key"]);
162 } else {
163 $this->options["$key"]= $_POST["$val"];
164 }
165 }
167 /* Statements */
168 foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
169 if ($_POST["$val"] == ''){
170 unset($this->statements["$key"]);
171 } else {
172 $this->statements["$key"]= '"'.$_POST["$val"].'"';
173 }
174 }
176 /* Flags */
177 if (isset ($_POST['autohost'])){
178 $this->statements['get-lease-hostnames']= "true";
179 } else {
180 unset($this->statements['get-lease-hostnames']);
181 }
182 if (isset ($_POST['autohostdecl'])){
183 $this->statements['use-host-decl-names']= "on";
184 } else {
185 unset($this->statements['use-host-decl-names']);
186 }
187 }
188 }
191 /* Check values */
192 function check()
193 {
194 $message= array();
196 /* Check netmask and broadcast */
197 foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
198 if (!isset($this->options["$key"])){
199 continue;
200 }
201 $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
203 if (!is_ip($tmp)){
204 $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
205 }
206 }
208 return $message;
209 }
212 /* Save to LDAP */
213 function save()
214 {
215 }
217 }
219 ?>