Code

Updated dhcp plugin
[gosa.git] / gosa-plugins / dhcp / admin / systems / services / dhcp / class_dhcpNetwork.inc
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= 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($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     if (isset($this->statements['filename'])){
110       $smarty->assign("filename", trim($this->statements['filename'], '"'));
111     } else {
112       $smarty->assign("filename", "");
113     }
114     if (isset($this->statements['next-server'])){
115       $smarty->assign("nextserver", $this->statements['next-server']);
116     } else {
117       $smarty->assign("nextserver", "");
118     }
120     /* Set flags */
121     $smarty->assign("autohost", "");
122     if (isset($this->statements['get-lease-hostnames'])){
123       if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
124         $smarty->assign("autohost", "checked");
125       }
126     }
127     $smarty->assign("autohostdecl", "");
128     if (isset($this->statements['use-host-decl-names'])){
129       if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
130         $smarty->assign("autohostdecl", "checked");
131       }
132     }
134     return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE,dirname(__FILE__)));
135   }
137   function remove_from_parent()
138   {
139   }
142   /* Save data to object */
143   function save_object()
144   {
145     /* Only save, if we are "active" */
146     if (isset($_POST['routers']) && preg_match("/w/",$this->parent->getacl(""))){
148       /*
149        * Assemble options
150        */
152       /* Options */
153       foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
154                      "broadcast-address" => "broadcast_address") as $key => $val){
155         if ($_POST["$val"] == ''){
156           $this->options->remove($key);
157         } else {
158           $this->options->set($key,get_post($val));
159         }
160       }
162       /* Statements */
163       foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
164         if ($_POST["$val"] == ''){
165           unset($this->statements["$key"]);
166         } else {
167     
168           /* Only quote filename values */
169           if(in_array($key,array("filename"))){
170             $this->statements["$key"]= '"'.get_post("$val").'"';
171           }else{
172             $this->statements["$key"]= get_post("$val");
173           }
174         }
175       }
177       /* Flags */
178       if (isset ($_POST['autohost'])){
179         $this->statements['get-lease-hostnames']= "true";
180       } else {
181         unset($this->statements['get-lease-hostnames']);
182       }
183       if (isset ($_POST['autohostdecl'])){
184         $this->statements['use-host-decl-names']= "on";
185       } else {
186         unset($this->statements['use-host-decl-names']);
187       }
188     }
189   }
192   /* Check values */
193   function check()
194   {
195     $message= array();
197     /* Check netmask and broadcast */
198     foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
199       if (!$this->options->exists("$key")){
200         continue;
201       }
202       if (!tests::is_ip($this->options->get($key))){
203         $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
204       }
205     }
206     return $message;
207   }
210   /* Save to LDAP */
211   function save()
212   {
213   }
214   
216 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
217 ?>