Code

Update of 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(isset($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($productId,$cfg,$hostId = "")
186   {
187     $data = array("productId" => $productId);
189     /* Append host attribute to query data 
190      */
191     if(!empty($hostId)){
192       $data['hostId'] = trim($hostId);
193     }
194    
195     /* Check parameter */ 
196     if(empty($productId)){
197       trigger_error("No valid product id given, check parameter 1.");
198       return(array());
199     }
201     if(!count($cfg)) return;
202     
203     /* Add properties */
204     $data['item'] = array();
205     foreach($cfg as $name => $value){
206       $data['item'][] = "<name>".$name."</name><value>".$value."</value>";
207     }  
209     /* Query SI server */
210     $res    = $this->send_data("gosa_opsi_set_product_properties",$this->target,$data,TRUE);
211   }
214   /*! \brief            Adds a given product to a client.
215     @param
216     @return             
217    */
218   public function add_product_to_client($productId,$hostId)
219   {
220     $data = array("productId" => $productId,"hostId" => $hostId);
222     /* Check parameter */ 
223     if(empty($productId)){
224       trigger_error("No valid product id given, check parameter 1.");
225       return;
226     }
227     if(empty($hostId)){
228       trigger_error("No valid host id given, check parameter 2.");
229       return;
230     }
232     /* Query SI server */
233     $res    = $this->send_data("gosa_opsi_add_product_to_client",$this->target,$data,TRUE);
234   }
237   /*! \brief      Removes a given product from a client.
238     @param
239     @return
240    */
241   public function del_product_from_client($productId,$hostId)
242   {
243     $data = array("productId" => $productId,"hostId" => $hostId);
245     /* Check parameter */ 
246     if(empty($productId)){
247       trigger_error("No valid product id given, check parameter 1.");
248       return;
249     }
250     if(empty($hostId)){
251       trigger_error("No valid host id given, check parameter 2.");
252       return;
253     }
255     /* Query SI server */
256     $res    = $this->send_data("gosa_opsi_del_product_from_client",$this->target,$data,TRUE);
257   }
260   /*! \brief            Returns the clients hardware setup.
261     @param
262     @return             
263    */
264   public function get_client_hardware()
265   {
266     /*  <xml> 
267         <header>gosa_opsi_get_client_hardware</header> 
268         <source>GOSA</source> 
269         <target>GOSA</target> 
270         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
271         </xml> 
272      */
273   }
276   /*! \brief            Returns the clients software setup.
277     @param
278     @return             
279    */
280   public function get_client_software()
281   {
282     /*  <xml> 
283         <header>gosa_opsi_get_client_software</header> 
284         <source>GOSA</source> 
285         <target>GOSA</target> 
286         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
287         </xml> i
288      */
289   }
294   /*! \brief            Returns a list of all opsi clients.
295     @param
296     @return             
297    */
298   public function list_clients()
299   {
300     $data   = array();
301     $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
302     $items  = array();
303     if(isset($res['XML']['ITEM'])){
304       if(!is_array($res['XML']['ITEM']['NAME'])){
305         $obj = $res['XML']['ITEM'];
306         $items[$obj['NAME']] = $obj;
307       }else{
308         foreach($res['XML']['ITEM'] as $type => $val){
309           foreach($val as $key => $value){
310             $items[$key][$type] = $value;
311           }
312         }
313       }
314     }
315     return($items);
316   }
319   /*! \brief            Deletes the given opsi client.
320     @param
321     @return             
322    */
323   public function del_client()
324   {
325     /*  <xml> 
326         <header>gosa_opsi_del_client</header> 
327         <source>GOSA</source> 
328         <target>00:01:6c:9d:b9:fa</target> 
329         <hostId>limux-cl-2.intranet.gonicus.de</hostId>
330         </xml>
331      */
332   }
335   /*! \brief            Triggers install/reinstall of an opsi client.
336     @param
337     @return             
338    */
339   public function job_opsi_install_client()
340   {
341     /*  <xml> 
342         <header>job_opsi_install_client</header> 
343         <source>GOSA</source> 
344         <target>00:01:6c:9d:b9:fa</target> 
345         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
346         <macaddress>00:11:25:4b:8c:e5</macaddress> 
347         </xml>
348      */
349   }
352   /*! \brief            Adds a new opsi client.
353     @param
354     @return             
355    */
356   public function add_client()
357   {
358     /*  <xml> 
359         <header>gosa_opsi_add_client</header> 
360         <source>GOSA</source> 
361         <target>00:01:6c:9d:b9:fa</target> 
362         <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
363         <macaddress>00:11:25:4b:8c:e5</macaddress> 
364         <description>Test halt</description> 
365         <ip>1.2.3.4</ip> 
366         <notes>Im a note</notes> 
367         </xml>
368      */
369   }
373 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
374 ?>