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;
47 protected $use_alternative_xml_parse_method = TRUE;
49 /*! \brief Create opsi object.
50 @param
51 @return
52 */
53 public function __construct($config)
54 {
55 $this->config = $config;
56 gosaSupportDaemon::__construct($config);
57 $this->target = "00:01:6c:9d:b9:fa";
58 }
61 /******************
62 Opsi handling
63 ******************/
65 function get_hosts_for_system_management()
66 {
67 $res = $this->list_clients();
69 $data = array();
70 foreach($res as $entry){
71 if(!isset($entry['MAC'][0]['VALUE'])) $entry['MAC'][0]['VALUE'] = "";
72 $data[] = array(
73 "dn" => "opsi:=".$entry['NAME'][0]['VALUE'].",".get_ou("winstations").$this->config->current['BASE'],
74 "objectClass" => array("gosa_opsi_client"),
75 "cn" => array(0 => $entry['NAME'][0]['VALUE']),
76 "description" => array(0 => $entry['DESCRIPTION'][0]['VALUE']),
77 "macAddress" => array(0 => $entry['MAC'][0]['VALUE']),
78 "opsi_notes" => array(0 => $entry['NOTES'][0]['VALUE']));
80 }
82 return($data);
83 }
86 private function xml_to_array($xml,$alternative_method = FALSE)
87 {
88 echo "asd";
89 return(gosaSupportDaemon::xml_to_array($xml,TRUE));
90 }
92 /******************
93 SI Communication functions
94 ******************/
97 /*! \brief Returns a list of netboot products.
98 @param
99 @return
100 */
101 public function get_netboot_products($host = "")
102 {
103 $data = array();
105 /* Append host attribute to query data
106 */
107 if(!empty($host)){
108 $data['hostId'] = trim($host);
109 }
111 $res = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE);
112 $items = array();
113 if(isset($res['XML'][0]['ITEM']['PRODUCTID'])){
114 if(!is_array($res['XML'][0]['ITEM']['PRODUCTID'])){
115 $items[$res['XML'][0]['ITEM']['PRODUCTID']]['NAME'] = $res['XML'][0]['ITEM']['PRODUCTID'];
116 $items[$res['XML'][0]['ITEM']['PRODUCTID']]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'];
117 }else{
118 foreach($res['XML'][0]['ITEM']['PRODUCTID'] as $id => $name){
119 $items[$name]['NAME'] = $name;
120 $items[$name]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'][$id];
121 }
122 }
123 }
124 return($items);
125 }
128 /*! \brief Returns a list of all local products.
129 @param
130 @return
131 */
132 public function get_local_products($host = "")
133 {
134 $data = array();
136 /* Append host attribute to query data
137 */
138 if(!empty($host)){
139 $data['hostId'] = trim($host);
140 }
142 $res = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE);
143 $items = array();
144 if(isset($res['XML'][0]['ITEM']['PRODUCTID'])){
145 if(!is_array($res['XML'][0]['ITEM']['PRODUCTID'])){
146 $items[$res['XML'][0]['ITEM']['PRODUCTID']]['NAME'] = $res['XML'][0]['ITEM']['PRODUCTID'];
147 $items[$res['XML'][0]['ITEM']['PRODUCTID']]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'];
148 }else{
149 foreach($res['XML'][0]['ITEM']['PRODUCTID'] as $id => $name){
150 $items[$name]['NAME'] = $name;
151 $items[$name]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'][$id];
152 }
153 }
154 }
155 return($items);
156 }
159 /*! \brief Returns a list of all product properties. \
160 . Additionally you can specify the host parameter to \
161 . get host specific product properties
162 @param
163 @return
164 */
165 public function get_product_properties($productId,$hostId = "")
166 {
167 $data = array("productId" => $productId);
169 /* Append host attribute to query data
170 */
171 if(!empty($hostId)){
172 $data['hostId'] = trim($hostId);
173 }
175 /* Check parameter */
176 if(empty($productId)){
177 trigger_error("No valid product id given, check parameter 1.");
178 return(array());
179 }
181 /* Query SI server */
182 $res = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE);
183 if(isset($res['XML'][0]['ITEM'])){
184 return($res['XML'][0]['ITEM']);
185 }
186 return(array());
187 }
190 /*! \brief Set product properties, globally or per host.
191 @param
192 @return
193 */
194 public function set_product_properties($productId,$cfg,$hostId = "")
195 {
196 $data = array("productId" => $productId);
198 /* Append host attribute to query data
199 */
200 if(!empty($hostId)){
201 $data['hostId'] = trim($hostId);
202 }
204 /* Check parameter */
205 if(empty($productId)){
206 trigger_error("No valid product id given, check parameter 1.");
207 return(array());
208 }
210 if(!count($cfg)) return;
212 /* Add properties */
213 $data['item'] = array();
214 foreach($cfg as $name => $value){
215 $data['item'][] = "<name>".$name."</name><value>".$value."</value>";
216 }
218 /* Query SI server */
219 $res = $this->send_data("gosa_opsi_set_product_properties",$this->target,$data,TRUE);
220 }
223 /*! \brief Adds a given product to a client.
224 @param
225 @return
226 */
227 public function add_product_to_client($productId,$hostId)
228 {
229 $data = array("productId" => $productId,"hostId" => $hostId);
231 /* Check parameter */
232 if(empty($productId)){
233 trigger_error("No valid product id given, check parameter 1.");
234 return;
235 }
236 if(empty($hostId)){
237 trigger_error("No valid host id given, check parameter 2.");
238 return;
239 }
241 /* Query SI server */
242 $res = $this->send_data("gosa_opsi_add_product_to_client",$this->target,$data,TRUE);
243 }
246 /*! \brief Removes a given product from a client.
247 @param
248 @return
249 */
250 public function del_product_from_client($productId,$hostId)
251 {
252 $data = array("productId" => $productId,"hostId" => $hostId);
254 /* Check parameter */
255 if(empty($productId)){
256 trigger_error("No valid product id given, check parameter 1.");
257 return;
258 }
259 if(empty($hostId)){
260 trigger_error("No valid host id given, check parameter 2.");
261 return;
262 }
264 /* Query SI server */
265 $res = $this->send_data("gosa_opsi_del_product_from_client",$this->target,$data,TRUE);
266 }
269 /*! \brief Returns the clients hardware setup.
270 @param
271 @return
272 */
273 public function get_client_hardware($hostId)
274 {
275 $data = array("hostId" => $hostId);
277 /* Check parameter */
278 if(empty($hostId)){
279 trigger_error("No valid host id given, check parameter 1.");
280 return;
281 }
283 /* Query SI server */
284 $res = $this->send_data("gosa_opsi_get_client_hardware",$this->target,$data,TRUE);
285 print_a($res);
286 }
289 /*! \brief Returns the clients software setup.
290 @param
291 @return
292 */
293 public function get_client_software()
294 {
295 /* <xml>
296 <header>gosa_opsi_get_client_software</header>
297 <source>GOSA</source>
298 <target>GOSA</target>
299 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
300 </xml> i
301 */
302 }
307 /*! \brief Returns a list of all opsi clients.
308 @param
309 @return
310 */
311 public function list_clients()
312 {
313 $data = array();
314 $res = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
315 $items = array();
316 if(isset($res['XML'][0]['ITEM'])){
317 $items = $res['XML'][0]['ITEM'];
318 }
319 return($items);
320 }
323 /*! \brief Deletes the given opsi client.
324 @param
325 @return
326 */
327 public function del_client()
328 {
329 /* <xml>
330 <header>gosa_opsi_del_client</header>
331 <source>GOSA</source>
332 <target>00:01:6c:9d:b9:fa</target>
333 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
334 </xml>
335 */
336 }
339 /*! \brief Triggers install/reinstall of an opsi client.
340 @param
341 @return
342 */
343 public function job_opsi_install_client()
344 {
345 /* <xml>
346 <header>job_opsi_install_client</header>
347 <source>GOSA</source>
348 <target>00:01:6c:9d:b9:fa</target>
349 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
350 <macaddress>00:11:25:4b:8c:e5</macaddress>
351 </xml>
352 */
353 }
356 /*! \brief Adds a new opsi client.
357 @param
358 @return
359 */
360 public function add_client($hostId,$ip,$macaddress,$notes,$description)
361 {
362 $data = array("hostId" => $hostId,"ip" => $ip,"macaddress" => $macaddress);
364 if(empty($hostId)){
365 trigger_error("No valid host id given, check parameter 1.");
366 return;
367 }
368 if(empty($ip)){
369 trigger_error("No valid ip address given, check parameter 2.");
370 return;
371 }
373 /* Add optional attributes */
374 foreach(array("notes","description") as $attr) {
375 if(!empty($$attr)){
376 $data[$attr] = $$attr;
377 }
378 }
380 /* Query SI server */
381 $res = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
382 }
385 }
386 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
387 ?>