Code

Udpated gotomasses
[gosa.git] / plugins / admin / systems / class_dhcpService.inc
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2003-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 dhcpService extends dhcpPlugin
22 {
23   /* Used attributes */
24   var $dhcpPrimaryDN= "";
25   var $orig_dhcpPrimaryDN= "";
26   var $ddns_styles= array('none', 'interim', 'ad-hoc');
28   /* attribute list for save action */
29   var $objectclasses= array('top', 'dhcpService');
32   function dhcpService($attrs)
33   {
34     dhcpPlugin::dhcpPlugin($attrs);
36     /* Load statements / options */
37     if (!$this->new){
38       /* Load attributes */
39       $this->dhcpPrimaryDN= $attrs['dhcpPrimaryDN'][0];
40     } else {
41       /* We keep the parent dn here if it's new */
42       $this->statements['default-lease-time']= 600;
43       $this->statements['max-lease-time']= 1700;
44       $this->statements['authoritative']= TRUE;
45       $this->statements['ddns-update-style']= 'none';
46     }
48     $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "server-identifier", "ddns-update-style"));
49     $this->advanced->setAutoOptions(array("server-name"));
51     /* Save for later action */
52     $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN;
53   }
56   function execute()
57   {
58     /* Show main page */
59     $smarty= get_smarty();
61     $smarty->assign('ddns_styles', $this->ddns_styles);
62     foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){
63       if (isset($this->statements[preg_replace('/_/', '-', $value)])){
64         $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]);
65       } else {
66         $smarty->assign("$value", "");
67       }
68     }
70     if (isset($this->statements['authoritative'])){
71       $smarty->assign("authoritative", "checked");
72     } else {
73       $smarty->assign("authoritative", "");
74     }
76     /* Show main page */
77     $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE)).$this->network->execute();
79     /* Merge arrays for advanced view */
80     $this->fix_options();
81     foreach (array("options", "statements") as $type){
82       $this->advanced->$type= $this->$type + $this->network->$type;;
83     }
85     $display.= $this->advanced->execute();
87     /* Merge back for removals */
88     foreach (array("options", "statements") as $type){
89       $this->$type= $this->advanced->$type;
90       $this->network->$type= $this->advanced->$type;
91     }
93     /* Add footer */
94     $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
95       "&nbsp;<input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
98     return ($display);
100   }
102   function remove_from_parent()
103   {
104   }
107   /* Save data to object */
108   function save_object()
109   {
110     /* No need to save in the first time */
111     if (!isset($_POST['ddns_update_style'])){
112       return;
113     }
115     /* Save remaining attributes */
116     foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){
117       $tval= preg_replace('/_/', '-', $val);
118       if ($_POST[$val] != ""){
119         $this->statements[$tval]= validate(get_post($val));
120       } else {
121         unset ($this->statements[$tval]);
122       }
123     }
124     if (isset($_POST['authoritative'])){
125       $this->statements['authoritative']= "";
126     } else {
127       unset($this->statements['authoritative']);
128     }
130     dhcpPlugin::save_object();
131   }
134   /* Check values */
135   function check()
136   {
137     $message= array();
139     if (!is_id($this->statements['default-lease-time'])){
140       $message[]= _('Default lease time needs to be numeric.');
141     }
142     if (!is_id($this->statements['max-lease-time'])){
143       $message[]= _('Maximum lease time needs to be numeric.');
144     }
145     if ($this->statements['default-lease-time'] > $this->statements['max-lease-time']){
146       $message[]= _('Default lease time needs to smaller than the maximum lease time.');
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   }
158   /* Save to LDAP */
159   function save()
160   {
161     global $config;
162     $this->attrs= array();
164     /* Get and set server name */
165     $ldap= $config->get_ldap_link();
166     $ldap->cat($this->dhcpPrimaryDN, array('cn'));
167     $res= $ldap->fetch();
168     $server_name= $res['cn'][0];
169     
170     dhcpPlugin::save();
172     $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN);
173     $this->removeOption('server-name');
174 #    $this->attrs['dhcpOption'][]= "server-name $server_name";
176     return ($this->attrs);
177   }
178   
180 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
181 ?>