Code

Updated opsi classes
[gosa.git] / gosa-plugins / opsi / admin / opsi / class_opsi.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2008  Fabian Hickert
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 3 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, see <http://www.gnu.org/licenses/>.
18  */
21 /********
23   __construct($config)
24   get_hosts_for_system_management()
25   get_netboot_products($host = "")
26   get_local_products($host = "")
27   get_product_properties()
28   set_product_properties()
29   get_client_hardware()
30   get_client_software()
31   list_clients()
32   del_client()
33   job_opsi_install_client()
34   add_client()
35   add_product_to_client()
36   del_product_from_client()
38  ********/
41 /*! \brief  This is the opsi base class, it handles 
42   .          gosa daemon requests and prepares data for opsi plugins.
43  */
44 class opsi extends gosaSupportDaemon 
45 {
46   private $config = NULL;
48   /*! \brief            Create opsi object.
49     @param
50     @return             
51    */
52   public function __construct($config)
53   {
54     $this->config = $config;
55     gosaSupportDaemon::__construct($config);
56     $this->target = "00:01:6c:9d:b9:fa";
57   }
59   /******************
60     Opsi handling 
61    ******************/
63   function get_hosts_for_system_management()
64   {
65     $res = $this->list_clients();
67     $data = array();
68     foreach($res as $entry){
69       $data[] = array(
70         "dn"          => "opsi:=".$entry['NAME'].",".get_ou("winstations").$this->config->current['BASE'],
71         "objectClass" => array("gosa_opsi_client"),
72         "cn"          => array(0 => $entry['NAME']),
73         "description" => array(0 => $entry['DESCRIPTION']),
74         "macAddress"  => array(0 => $entry['MAC']),
75         "opsi_notes"  => array(0 => $entry['NOTES']));
76         
77     }
78   
79     return($data);
80   }
83   /******************
84     SI Communication functions
85    ******************/
88   /*! \brief            Returns a list of netboot products.
89     @param
90     @return             
91    */
92   public function get_netboot_products($host = "")
93   {
94     $data = array();
96     /* Append host attribute to query data 
97      */
98     if(!empty($host)){
99       $data['hostId'] = trim($host);
100     }
102     $res    = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE);
103     $items  = array();
104     if($res['XML']['ITEM']['PRODUCTID']){
105       if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
106         $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
107         $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
108       }else{
109         foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
110           $items[$name]['NAME'] = $name;
111           $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
112         }
113       } 
114     }
115     return($items);
116   }
119   /*! \brief            Returns a list of all local products.
120     @param
121     @return             
122    */
123   public function get_local_products($host = "")
124   {
125     $data = array();
127     /* Append host attribute to query data 
128      */
129     if(!empty($host)){
130       $data['hostId'] = trim($host);
131     }
133     $res    = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE);
134     $items  = array();
135     if($res['XML']['ITEM']['PRODUCTID']){
136       if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
137         $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
138         $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
139       }else{
140         foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
141           $items[$name]['NAME'] = $name;
142           $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
143         }
144       } 
145     }
146     return($items);
147   }
150   /*! \brief            Returns a list of all product properties. \ 
151     .           Additionally you can specify the host parameter to \
152     .           get host specific product properties
153     @param
154     @return             
155    */
156   public function get_product_properties($productId,$hostId = "")
157   {
158     $data = array("productId" => $productId);
160     /* Append host attribute to query data 
161      */
162     if(!empty($hostId)){
163       $data['hostId'] = trim($hostId);
164     }
165    
166     /* Check parameter */ 
167     if(empty($productId)){
168       trigger_error("No valid product id given, check parameter 1.");
169       return(array());
170     }
172     /* Query SI server */
173     $res    = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE);
174     if(isset($res['XML']['ITEM'])){   
175       return($res['XML']['ITEM']);
176     }
177     return(array());
178   }
181   /*! \brief            Set product properties, globally or per host. 
182     @param
183     @return             
184    */
185   public function set_product_properties()
186   {
187     /*  <xml> 
188         <header>gosa_opsi_set_product_properties</header> 
189         <source>GOSA</source> 
190         <target>00:01:6c:9d:b9:fa</target> 
191         <productId>firefox</productId> 
192         <item>
193         <name>askbeforeinst</name>
194         <value>false</value>
195         </item>
196         </xml>
197         <xml> 
198         <header>gosa_opsi_set_product_properties</header> 
199         <source>GOSA</source> 
200         <target>00:01:6c:9d:b9:fa</target> 
201         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
202         <productId>firefox</productId> 
203         <item> 
204         <name>askbeforeinst</name> 
205         <value>false</value> 
206         </item> 
207         </xml> 
208      */
209   }
212   /*! \brief            Returns the clients hardware setup.
213     @param
214     @return             
215    */
216   public function get_client_hardware()
217   {
218     /*  <xml> 
219         <header>gosa_opsi_get_client_hardware</header> 
220         <source>GOSA</source> 
221         <target>GOSA</target> 
222         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
223         </xml> 
224      */
225   }
228   /*! \brief            Returns the clients software setup.
229     @param
230     @return             
231    */
232   public function get_client_software()
233   {
234     /*  <xml> 
235         <header>gosa_opsi_get_client_software</header> 
236         <source>GOSA</source> 
237         <target>GOSA</target> 
238         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
239         </xml> i
240      */
241   }
244   /*! \brief            Returns a list of all opsi clients.
245     @param
246     @return             
247    */
248   public function list_clients()
249   {
250     $data   = array();
251     $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
252     $items  = array();
253     if(isset($res['XML']['ITEM'])){
254       if(!is_array($res['XML']['ITEM']['NAME'])){
255         $obj = $res['XML']['ITEM'];
256         $items[$obj['NAME']] = $obj;
257       }else{
258         foreach($res['XML']['ITEM'] as $type => $val){
259           foreach($val as $key => $value){
260             $items[$key][$type] = $value;
261           }
262         }
263       }
264     }
265     return($items);
266   }
269   /*! \brief            Deletes the given opsi client.
270     @param
271     @return             
272    */
273   public function del_client()
274   {
275     /*  <xml> 
276         <header>gosa_opsi_del_client</header> 
277         <source>GOSA</source> 
278         <target>00:01:6c:9d:b9:fa</target> 
279         <hostId>limux-cl-2.intranet.gonicus.de</hostId>
280         </xml>
281      */
282   }
285   /*! \brief            Triggers install/reinstall of an opsi client.
286     @param
287     @return             
288    */
289   public function job_opsi_install_client()
290   {
291     /*  <xml> 
292         <header>job_opsi_install_client</header> 
293         <source>GOSA</source> 
294         <target>00:01:6c:9d:b9:fa</target> 
295         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
296         <macaddress>00:11:25:4b:8c:e5</macaddress> 
297         </xml>
298      */
299   }
302   /*! \brief            Adds a new opsi client.
303     @param
304     @return             
305    */
306   public function add_client()
307   {
308     /*  <xml> 
309         <header>gosa_opsi_add_client</header> 
310         <source>GOSA</source> 
311         <target>00:01:6c:9d:b9:fa</target> 
312         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
313         <macaddress>00:11:25:4b:8c:e5</macaddress> 
314         <description>Test halt</description> 
315         <ip>1.2.3.4</ip> 
316         <notes>Im a note</notes> 
317         </xml>
318      */
319   }
322   /*! \brief            Adds a given product to a client.
323     @param
324     @return             
325    */
326   public function add_product_to_client()
327   {
328     /*  <xml> 
329         <header>gosa_opsi_add_product_to_client</header> 
330         <source>GOSA</source> 
331         <target>00:01:6c:9d:b9:fa</target> 
332         <macaddress>00:11:25:4b:8c:e5</macaddress> 
333         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
334         <productId>winxppro</productId> 
335         </xml>
336      */
337   }
340   /*! \brief      Removes a given product from a client.
341     @param
342     @return
343    */
344   public function del_product_from_client()
345   {
346     /* <xml> 
347        <header>gosa_opsi_del_product_from_client</header> 
348        <source>GOSA</source> 
349        <target>00:01:6c:9d:b9:fa</target> 
350        <hostId>limux-cl-1.intranet.gonicus.de</hostId> 
351        <macaddress>00:11:25:4b:8c:e5</macaddress> 
352        <productId>softprod</productId>  
353        </xml>
354      */
355   }
357 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
358 ?>