Code

Replaced in_array calls with in_array_strict
[gosa.git] / gosa-plugins / dhcp / admin / systems / services / dhcp / class_dhcpPool.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  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 dhcpPool extends dhcpPlugin
22 {
23     /* Used attributes */
24     var $dhcpRange= "";
25     var $range_start= "";
26     var $range_stop= "";
28     /* attribute list for save action */
29     var $objectclasses= array('top', 'dhcpPool');
31     function dhcpPool($parent,$attrs)
32     {
33         dhcpPlugin::dhcpPlugin($parent,$attrs);
35         /* Load attributes */
36         if (!$this->new){
37             $this->dhcpRange= $attrs['dhcpRange'][0];
38             list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange);
39         }
41         $this->advanced->setAutoOptions(array("host-name"));
42         $this->advanced->setAutoStatements(array("fixed-address"));
43     }
45     function execute()
46     {
47         $smarty= get_smarty();
48         $smarty->assign("cn", set_post($this->cn));
49         $smarty->assign("range_start", set_post($this->range_start));
50         $smarty->assign("range_stop", set_post($this->range_stop));
52         /* Assign ACLs */
53         $smarty->assign("acl",$this->parent->getacl(""));
55         /* Show main page */
56         $display= $smarty->fetch(get_template_path('dhcp_pool.tpl', TRUE, dirname(__FILE__))).$this->network->execute();
58         $display.= $this->advanced->execute();
60         /* Add footer */
61         $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
62         if(preg_match("/w/",$this->parent->getacl(""))){
63             $display.=   "<button type='submit' name='save_dhcp'>".msgPool::saveButton()."</button>&nbsp;";
64         }
65         $display.=   "<button type='submit' name='cancel_dhcp'>".msgPool::cancelButton()."</button>";
66         $display.= "</div>";
68         return ($display);
69     }
71     function remove_from_parent()
72     {
73     }
76     /* Save data to object */
77     function save_object()
78     {
79         if (isset($_POST['cn'])){
80             $this->cn= get_post('cn');
81             $this->range_start= get_post('range_start');
82             $this->range_stop= get_post('range_stop');
83         }
85         dhcpPlugin::save_object();
87         /* Move range to internal variable */
88         $this->dhcpRange= $this->range_start." ".$this->range_stop;
89     }
92     /* Check values */
93     function check()
94     {
95         $message= array();
97         $cache = $this->parent->dhcpObjectCache;
99         /* All required fields are set? */
100         if ($this->cn == ""){
101             $message[]= msgPool::required(_("Name"));
102         }
104         /* cn already used? */
105         if ($this->orig_cn != $this->cn || $this->new){
107             foreach($cache as $dn => $dummy){
108                 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
109                     $message[]= msgPool::duplicated(_("Name"));
110                     break;
111                 }
112             }
113         }
115         if ($this->dhcpRange == ""){
116             $message[]= msgPool::required(_("Range"));
117         }
119         if (!tests::is_ip($this->range_start) || !tests::is_ip($this->range_stop)){
120             $message[]= msgPool::invalid(_("Range"));
121         }
123         if(!tests::is_ip_range($this->range_start,$this->range_stop)){
124             $message[]= msgPool::invalid(_("Range"));
125         }
127         /* Check if range is in the network */
128         $dn= $this->dn;
129         while (preg_match('/,/', $dn)){
130             $type= $this->objectType($cache, $dn);
132             /* Check for subnet */
133             if ($type == 'dhcpSubnet'){
134                 $network= $cache[$dn]['cn'][0];
135                 $netmask= normalize_netmask($cache[$dn]['dhcpNetMask'][0]);
136                 if (!tests::is_in_network($network, $netmask, $this->range_start) ||
137                         !tests::is_in_network($network, $netmask, $this->range_stop)){
138                     $message[] = _("'Range' is not inside the configured network.");
139                 }
140             }
142             /* Stop if we've examined the service base object */
143             if ($type == 'dhcpService'){
144                 break;
145             }
146             $dn= preg_replace('/^[^,]+,/', '', $dn);
147         }
149         /* Check external plugins */
150         $net= $this->network->check();
151         $adv= $this->advanced->check();
152         $message= array_merge($message, $net, $adv);
154         return $message;
155     }
157     /* Save to LDAP */
158     function save()
159     {
160         dhcpPlugin::save();
161         $this->attrs['dhcpRange']= array($this->dhcpRange);
163         return ($this->attrs);
164     }
167     function objectType($cache, $dn)
168     {
169         $type= "";
170         $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost",
171                 "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork");
173         foreach ($cache[$dn]['objectClass'] as $oc){
174             if (in_array_strict($oc, $types)){
175                 $type= $oc;
176                 break;
177             }
178         }
180         return ($type);
181     }
186 ?>