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 if(!isset($entry['MAC'])) $entry['MAC'] = "";;
70 $data[] = array(
71 "dn" => "opsi:=".$entry['NAME'].",".get_ou("winstations").$this->config->current['BASE'],
72 "objectClass" => array("gosa_opsi_client"),
73 "cn" => array(0 => $entry['NAME']),
74 "description" => array(0 => $entry['DESCRIPTION']),
75 "macAddress" => array(0 => $entry['MAC']),
76 "opsi_notes" => array(0 => $entry['NOTES']));
78 }
80 return($data);
81 }
84 /******************
85 SI Communication functions
86 ******************/
89 /*! \brief Returns a list of netboot products.
90 @param
91 @return
92 */
93 public function get_netboot_products($host = "")
94 {
95 $data = array();
97 /* Append host attribute to query data
98 */
99 if(!empty($host)){
100 $data['hostId'] = trim($host);
101 }
103 $res = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE);
104 $items = array();
105 if(isset($res['XML']['ITEM']['PRODUCTID'])){
106 if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
107 $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
108 $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
109 }else{
110 foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
111 $items[$name]['NAME'] = $name;
112 $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
113 }
114 }
115 }
116 return($items);
117 }
120 /*! \brief Returns a list of all local products.
121 @param
122 @return
123 */
124 public function get_local_products($host = "")
125 {
126 $data = array();
128 /* Append host attribute to query data
129 */
130 if(!empty($host)){
131 $data['hostId'] = trim($host);
132 }
134 $res = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE);
135 $items = array();
136 if($res['XML']['ITEM']['PRODUCTID']){
137 if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
138 $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
139 $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
140 }else{
141 foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
142 $items[$name]['NAME'] = $name;
143 $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
144 }
145 }
146 }
147 return($items);
148 }
151 /*! \brief Returns a list of all product properties. \
152 . Additionally you can specify the host parameter to \
153 . get host specific product properties
154 @param
155 @return
156 */
157 public function get_product_properties($productId,$hostId = "")
158 {
159 $data = array("productId" => $productId);
161 /* Append host attribute to query data
162 */
163 if(!empty($hostId)){
164 $data['hostId'] = trim($hostId);
165 }
167 /* Check parameter */
168 if(empty($productId)){
169 trigger_error("No valid product id given, check parameter 1.");
170 return(array());
171 }
173 /* Query SI server */
174 $res = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE);
175 if(isset($res['XML']['ITEM'])){
176 return($res['XML']['ITEM']);
177 }
178 return(array());
179 }
182 /*! \brief Set product properties, globally or per host.
183 @param
184 @return
185 */
186 public function set_product_properties($productId,$cfg,$hostId = "")
187 {
188 $data = array("productId" => $productId);
190 /* Append host attribute to query data
191 */
192 if(!empty($hostId)){
193 $data['hostId'] = trim($hostId);
194 }
196 /* Check parameter */
197 if(empty($productId)){
198 trigger_error("No valid product id given, check parameter 1.");
199 return(array());
200 }
202 if(!count($cfg)) return;
204 /* Add properties */
205 $data['item'] = array();
206 foreach($cfg as $name => $value){
207 $data['item'][] = "<name>".$name."</name><value>".$value."</value>";
208 }
210 /* Query SI server */
211 $res = $this->send_data("gosa_opsi_set_product_properties",$this->target,$data,TRUE);
212 }
215 /*! \brief Adds a given product to a client.
216 @param
217 @return
218 */
219 public function add_product_to_client($productId,$hostId)
220 {
221 $data = array("productId" => $productId,"hostId" => $hostId);
223 /* Check parameter */
224 if(empty($productId)){
225 trigger_error("No valid product id given, check parameter 1.");
226 return;
227 }
228 if(empty($hostId)){
229 trigger_error("No valid host id given, check parameter 2.");
230 return;
231 }
233 /* Query SI server */
234 $res = $this->send_data("gosa_opsi_add_product_to_client",$this->target,$data,TRUE);
235 }
238 /*! \brief Removes a given product from a client.
239 @param
240 @return
241 */
242 public function del_product_from_client($productId,$hostId)
243 {
244 $data = array("productId" => $productId,"hostId" => $hostId);
246 /* Check parameter */
247 if(empty($productId)){
248 trigger_error("No valid product id given, check parameter 1.");
249 return;
250 }
251 if(empty($hostId)){
252 trigger_error("No valid host id given, check parameter 2.");
253 return;
254 }
256 /* Query SI server */
257 $res = $this->send_data("gosa_opsi_del_product_from_client",$this->target,$data,TRUE);
258 }
261 /*! \brief Returns the clients hardware setup.
262 @param
263 @return
264 */
265 public function get_client_hardware()
266 {
267 /* <xml>
268 <header>gosa_opsi_get_client_hardware</header>
269 <source>GOSA</source>
270 <target>GOSA</target>
271 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
272 </xml>
273 */
274 }
277 /*! \brief Returns the clients software setup.
278 @param
279 @return
280 */
281 public function get_client_software()
282 {
283 /* <xml>
284 <header>gosa_opsi_get_client_software</header>
285 <source>GOSA</source>
286 <target>GOSA</target>
287 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
288 </xml> i
289 */
290 }
295 /*! \brief Returns a list of all opsi clients.
296 @param
297 @return
298 */
299 public function list_clients()
300 {
301 $data = array();
302 $res = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
303 $items = array();
304 if(isset($res['XML']['ITEM'])){
305 if(!is_array($res['XML']['ITEM']['NAME'])){
306 $obj = $res['XML']['ITEM'];
307 $items[$obj['NAME']] = $obj;
308 }else{
309 foreach($res['XML']['ITEM'] as $type => $val){
310 foreach($val as $key => $value){
311 $items[$key][$type] = $value;
312 }
313 }
314 }
315 }
316 return($items);
317 }
320 /*! \brief Deletes the given opsi client.
321 @param
322 @return
323 */
324 public function del_client()
325 {
326 /* <xml>
327 <header>gosa_opsi_del_client</header>
328 <source>GOSA</source>
329 <target>00:01:6c:9d:b9:fa</target>
330 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
331 </xml>
332 */
333 }
336 /*! \brief Triggers install/reinstall of an opsi client.
337 @param
338 @return
339 */
340 public function job_opsi_install_client()
341 {
342 /* <xml>
343 <header>job_opsi_install_client</header>
344 <source>GOSA</source>
345 <target>00:01:6c:9d:b9:fa</target>
346 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
347 <macaddress>00:11:25:4b:8c:e5</macaddress>
348 </xml>
349 */
350 }
353 /*! \brief Adds a new opsi client.
354 @param
355 @return
356 */
357 public function add_client()
358 {
359 /* <xml>
360 <header>gosa_opsi_add_client</header>
361 <source>GOSA</source>
362 <target>00:01:6c:9d:b9:fa</target>
363 <hostId>limux-cl-2.intranet.gonicus.de</hostId>
364 <macaddress>00:11:25:4b:8c:e5</macaddress>
365 <description>Test halt</description>
366 <ip>1.2.3.4</ip>
367 <notes>Im a note</notes>
368 </xml>
369 */
370 }
373 }
374 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
375 ?>