Code

c0da9bf10bbcbd0fb1826e45f35e6a62cdf70fc1
[gosa.git] / include / class_dhcpPlugin.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 dhcpPlugin extends plugin
22 {
23   /* Used attributes */
24   var $cn= "";
25   var $orig_cn= "";
26   var $options= array();
27   var $statements= array();
29   /* Subobjects */
30   var $network;
31   var $advanced;
33   /* attribute list for save action */
34   var $attributes= array();
35   var $objectclasses= array();
37   function dhcpPlugin($attrs)
38   {
39     /* Load statements / options */
40     if (is_array($attrs)){
41       $this->dn= $attrs['dn'];
42       $this->cn= $attrs['cn'][0];
43       $this->new= FALSE;
45       /* Load options */
46       if (isset($attrs['dhcpOption'])){
47         foreach ($attrs['dhcpOption'] as $opt){
48           $idx= preg_replace('/\s.+$/', '', $opt);
49           $value= preg_replace('/^[^\s]+\s/', '', $opt);
50           $this->options[$idx]= $value;
51         }
52       }
54       /* Load statements */
55       if (isset($attrs['dhcpStatements'])){
56         foreach ($attrs['dhcpStatements'] as $opt){
57           $idx= preg_replace('/\s.+$/', '', $opt);
58           $value= preg_replace('/^[^\s]+\s/', '', $opt);
59           $this->statements[$idx]= $value;
60         }
61       }
63     } else {
64       /* We keep the parent dn here if it's new */
65       $this->dn= $attrs;
66       $this->new= TRUE;
67     }
69     /* Load network module */
70     $this->network= new dhcpNetwork();
71     $this->network->options= $this->options;
72     $this->network->statements= $this->statements;
73     $this->advanced= new dhcpAdvanced();
74     $this->advanced->options= $this->options;
75     $this->advanced->statements= $this->statements;
77     /* Save CN for later reference */
78     $this->orig_cn= $this->cn;
79   }
81   function execute()
82   {
83     return ("");
84   }
87   function remove_from_parent()
88   {
89   }
92   /* Save data to object */
93   function save_object()
94   {
95     /* Strip network objects */
96     foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){
97       unset($this->options[$toberemoved]);
98     }
99     foreach (array("filename", "next-server") as $toberemoved){
100       unset($this->statements[$toberemoved]);
101     }
103     /* Save sub-objects */
104     $this->network->save_object();
105     $this->advanced->save_object();
107     /* Merge arrays for advanced view */
108     foreach (array("options", "statements") as $type){
109       $tmp= array_merge($this->$type, $this->network->$type);
110       $this->advanced->$type= $tmp;
111     }
112   }
115   /* Check values */
116   function check($cache)
117   {
118     $message= array();
120     return $message;
121   }
124   /* Save to LDAP */
125   function save()
126   {
127     /* Merge arrays for network and advanced view */
128     foreach (array("options", "statements") as $type){
129       $tmp= array_merge($this->$type, $this->network->$type, $this->advanced->$type);
130       $this->$type= $tmp;
131     }
133     /* Add cn if we're new */
134     if ($this->new){
135       $this->dn= "cn=".$this->cn.",".$this->dn;
136     } else {
137       $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
138     }
140     /* Assemble new entry - options */
141     $this->attrs['dhcpOption']= array();
142     if (isset ($this->options) && count ($this->options)){
143       foreach ($this->options as $key => $val){
144         $this->attrs['dhcpOption'][]= "$key $val";
145       }
146     }
148     /* Assemble new entry - statements */
149     $this->attrs['dhcpStatements']= array();
150     if (isset ($this->statements) && count ($this->statements)){
151       foreach ($this->statements as $key => $val){
152         if ($val != ""){
153           $this->attrs['dhcpStatements'][]= "$key $val";
154         } else {
155           $this->attrs['dhcpStatements'][]= "$key";
156         }
157       }
158     }
160     /* Move dn to the result */
161     $this->attrs['dn']= $this->dn;
162     $this->attrs['cn']= array($this->cn);
163     $this->attrs['objectClass']= $this->objectclasses;
164     $this->attrs['MODIFIED']= TRUE;
166     return ($this->attrs);
167   }
171 ?>