1 <?php
3 class opsiLicenceHandler extends opsi {
7 /*******************
8 * POOLs
9 *******************/
11 protected $use_alternative_xml_parse_method = TRUE;
14 /* @brief Returns licensePoolId, description, productIds and windowsSoftwareIds
15 * for all found license pools.
16 */
17 function listPools()
18 {
19 $data= array();
20 $res = $this->send_data("gosa_opsi_getLicensePools_listOfHashes",$this->target,$data,TRUE);
21 $items = array();
22 if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
23 $items = $res['XML'][0]['RESULT'][0]['HIT'];
24 $data =array();
25 foreach($items as $item){
26 $entry = array();
27 foreach(
28 array(
29 "DESCRIPTION" => "description",
30 "LICENSEPOOLID" => "cn",
31 "PRODUCTIDS" => "productId",
32 "WINDOWSSOFTWAREIDS"=> "softwareId") as $source => $dest){
34 if(isset($item[$source])){
35 $entry[$dest] = array('count' => 0);
36 foreach($item[$source] as $obj){
37 $entry[$dest][] = $obj['VALUE'];
38 }
39 $entry[$dest]['count'] = (count($entry[$dest]) -1 );
40 }
41 }
42 $data[] =$entry;
43 }
44 return($data);
45 }
46 return(FALSE);
47 }
50 /* @brief Create a license pool at Opsi server.
51 * @param licensePoolId The name of the pool (optional).
52 * @param description The description of the pool (optional).
53 * @param productIds A list of assigned porducts of the pool (optional).
54 * @param windowsSoftwareIds A list of windows software Ids associated to the pool (optional).
55 */
56 function createPool($poolId,$desc = "",$products = array(),$softwareIds = array())
57 {
58 $data= array();
59 $data['licensePoolId'] = htmlentities($poolId);
60 if(!empty($desc)){
61 $data['description'] = htmlentities($desc);
62 }
63 if(count($products)){
64 $data['productIds'] = $products;
65 }
66 if(count($softwareIds)){
67 $data['windowsSoftwareIds'] = $softwareIds;
68 }
70 $res = $this->send_data("gosa_opsi_createLicensePool",$this->target,$data,TRUE);
71 if(isset($res['XML'][0]['ANSWER_OPSI_CREATELICENSEPOOL'])){
72 return(TRUE);
73 }
74 return(FALSE);
75 }
78 /*
79 * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
80 * @param licensePoolId The name of the pool.
81 */
82 function getPool($licensePoolId)
83 {
84 $data= array();
85 $data['licensePoolId'] = htmlentities($licensePoolId);
86 $res = $this->send_data("gosa_opsi_getPool",$this->target,$data,TRUE);
88 if(isset($res['XML'][0]['ANSWER_OPSI_GETPOOL'])){
89 $item = array();
90 foreach(array("LICENSEPOOLID" => "cn",
91 "DESCRIPTION" => "description",
92 "LICENSES" => "licenses",
93 "LICENSECONTRACTDATA" => "contract",
94 "WINDOWSSOFTWAREIDS" => "softwareId",
95 "PRODUCTIDS" => "productId") as $source => $target){
96 if(isset($res['XML'][0][$source])){
97 $item[$target] = array('count' => 0);
100 foreach($res['XML'][0][$source] as $data){
101 if(isset($data['VALUE'])){
102 $item[$target][] = $data['VALUE'];
103 }elseif(isset($data['HIT'])){
104 $item[$target] = array_merge($item[$target],$data['HIT']);
105 }
106 }
107 $item[$target]['count'] = count($item[$target]) -1 ;
108 }
109 }
110 return($item);
111 }
112 return(FALSE);
113 }
116 /*
117 * @brief
118 * Delete licnese pool by license pool Id.
119 * A pool can only be deleted if there are no software licenses bound to the pool.
120 * The fixed parameter deleteLicenses=True specifies that
121 * all software licenses bound to the pool are being deleted.
122 * @param licensePoolId The name of the pool.
123 */
124 function deletePool($poolId, $force = FALSE)
125 {
126 $data= array();
127 $data['licensePoolId'] = htmlentities($poolId);
128 if($force){
129 $data['deleteLicenses'] = 'TRUE';
130 }
131 $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
132 if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
133 return(TRUE);
134 }
135 return(FALSE);
136 }
139 /*******************
140 * LICENSES
141 *******************/
143 /*
144 * @brief
145 * Create a license contract, create a software
146 * license and add the software license to the license pool
147 * @param licensePoolId The name of the pool the license should be assigned.
148 * @param licenseKey The license key.
149 * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL"
150 * @param partner Name of the license partner (optional).
151 * @param conclusionDate Date of conclusion of license contract (optional)
152 * @param notificationDate Date of notification that license is running out soon (optional).
153 * @param notes This is the place for some notes (optional)
154 * @param softwareLicenseId Identificator of a license (optional).
155 * @param maxInstallations The number of clients use this license (optional).
156 * @param boundToHost The name of the client the license is bound to (optional).
157 * @param expirationDate The date when the license is running down (optional).
158 */
159 function createLicense($poolId, $licenseId, $licenseKey,$licenseType = "",
160 $partner = "",
161 $conclusionDate = "",
162 $notificationDate ="",
163 $notes = "",
164 $softwareLicenseId = "",
165 $maxInstallations = "",
166 $boundToHost = "",
167 $expirationDate = "")
168 {
170 $data= array();
171 $data['licensePoolId'] = htmlentities($poolId);
172 $data['licenseKey'] = htmlentities($licenseKey);
173 $data['licenseId'] = htmlentities($licenseId);
175 // Append optional attributes
176 foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
177 "licenseType","maxInstallations","boundToHost","expirationDate") as $attr){
178 if(!empty($$attr)){
179 $data[$attr] = $$attr;
180 }
181 }
183 $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
184 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
185 return(TRUE);
186 }
187 return(FALSE);
188 }
191 /* @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp,
192 * licensePoolIds and licenseKeys for a given softwareLicense Id.
193 * @param softwareLicenseId Identificator of a license.
194 */
195 function getLicense($softwareLicenseId)
196 {
197 $data= array();
198 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
199 $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
201 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
202 return($res);
203 }
204 return(FALSE);
205 }
208 function getReservedLicensesForHost($hostId)
209 {
210 $data= array();
211 if(!empty($hostId)){
212 $data['hostId'] = htmlentities($hostId);
213 }
214 $res = $this->send_data("gosa_opsi_getReservedLicenses",$this->target,$data,TRUE);
215 if(isset($res['XML'][0]['ANSWER_OPSI_GETRESERVEDLICENSES'])){
217 $items = array();
218 if(isset($res['XML'][0]['LICENSES'][0]['HIT'])){
219 foreach($res['XML'][0]['LICENSES'][0]['HIT'] as $entry){
220 $item = array();
221 foreach(array(
222 "LICENSEPOOLIDS" => "licensePoolId",
223 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
224 if(isset($entry[$source])){
226 $item[$target] = array('count' => 0);
227 foreach($entry[$source] as $data){
228 $item[$target][] = $data['VALUE'];
229 }
230 $item[$target]['count'] = count($item[$target]) -1 ;
231 }
232 }
233 $items[] = $item;
234 }
235 }
236 return($items);
237 }
238 return(FALSE);
239 }
242 /*
243 * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
244 * @param hostid Something like client_1.intranet.mydomain.de (optional).
245 * @param licensePoolId The name of the pool (optional).
246 */
247 function getLicenseUsage($hostId = "", $licensePoolId = "")
248 {
249 $data= array();
250 if(!empty($hostId)){
251 $data['hostId'] = htmlentities($hostId);
252 }
253 if(!empty($hostId)){
254 $data['licensePoolId'] = htmlentities($licensePoolId);
255 }
257 $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages",$this->target,$data,TRUE);
258 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES'])){
260 $items = array();
261 if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
262 foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
263 $item = array();
264 foreach(array(
265 "HOSTID" => "hostId",
266 "LICENSEKEY" => "licenseKey",
267 "LICENSEPOOLID" => "licensePoolId",
268 "NOTES" => "notes",
269 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
270 if(isset($entry[$source])){
272 $item[$target] = array('count' => 0);
273 foreach($entry[$source] as $data){
274 $item[$target][] = $data['VALUE'];
275 }
276 $item[$target]['count'] = count($item[$target]) -1 ;
277 }
278 }
279 $items[] = $item;
280 }
281 }
282 return($items);
283 }
284 return(FALSE);
285 }
288 /* @brief Assigns a software license to a host
289 * @param hostId Something like client_1.intranet.mydomain.de
290 * @param licensePoolId The name of the pool.
291 */
292 function addLicenseToHost($licensePoolId,$hostId)
293 {
294 $data= array();
295 $data['licensePoolId'] = htmlentities($licensePoolId);
296 $data['hostId'] = htmlentities($hostId);
297 $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
298 if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
299 return(TRUE);
300 }
301 return(FALSE);
302 }
305 /* @brief Reserve a software license to a host
306 * @param softwareLicenseId
307 * @param hostId Something like client_1.intranet.mydomain.de
308 */
309 function reserverLicenseForHost($softwareLicenseId,$hostId)
310 {
311 $data= array();
312 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
313 $data['hostId'] = htmlentities($hostId);
314 $res = $this->send_data("gosa_opsi_boundHostToLicense",$this->target,$data,TRUE);
315 if(isset($res['XML'][0]['ANSWER_OPSI_BOUNDHOSTTOLICENSE'])){
316 return(TRUE);
317 }
318 return(FALSE);
319 }
322 /*
323 * @brief Remove software licnese reservation for a host.
324 * @param softwareLicenseId
325 * @param hostid Something like client_1.intranet.mydomain.de
326 */
327 function removeLicenseReservationFromHost($softwareLicenseId,$hostId)
328 {
329 $data= array();
330 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
331 $data['hostId'] = htmlentities($hostId);
332 $res = $this->send_data("gosa_opsi_unboundHostFromLicense",$this->target,$data,TRUE);
333 if(isset($res['XML'][0]['ANSWER_OPSI_UNBOUNDHOSTFROMLICENSE'])){
334 return(TRUE);
335 }
336 return(FALSE);
337 }
340 /*
341 * @brief Unassign a software license from a host.
342 * @param hostid Something like client_1.intranet.mydomain.de
343 * @param licensePoolId The name of the pool.
344 */
345 function removeLicenseFromHost($licensePoolId,$hostId)
346 {
347 $data= array();
348 $data['licensePoolId'] = htmlentities($licensePoolId);
349 $data['hostId'] = htmlentities($hostId);
350 $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
351 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
352 return(TRUE);
353 }
354 return(FALSE);
355 }
358 /*
359 * @brief Removes a single license from a license pool
360 * Attention, the software license has to exists
361 * otherwise it will lead to an Opsi internal server error.
362 * @param softwareLicenseId
363 * @param licensePoolId
364 */
365 function removeLicenseFromPool($licensePoolId,$softwareLicenseId)
366 {
367 $data= array();
368 $data['licensePoolId'] = htmlentities($licensePoolId);
369 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
370 $res = $this->send_data("gosa_opsi_removeLicense",$this->target,$data,TRUE);
371 if(isset($res['XML'][0]['ANSWER_OPSI_REMOVELICENSE'])){
372 return(TRUE);
373 }
374 return(FALSE);
375 }
378 /*
379 * @brief Unassign all software licenses from a host
380 * @param hostid Something like client_1.intranet.mydomain.de
381 */
382 function removeAllLicensesFromHost($hostId)
383 {
384 $data= array();
385 $data['hostId'] = htmlentities($hostid);
386 $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
387 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
388 return(TRUE);
389 }
390 return(FALSE);
391 }
394 /* @brief
395 * Returns the assigned licensePoolId and licenses,
396 * how often the product is installed and at which host
397 * and the number of max and remaining installations for a given OPSI product.
398 * @param productId Identificator of an OPSI product.
399 */
400 function getLicensesForProduct($productId)
401 {
402 $data= array();
403 $data['productId'] = htmlentities($productId);
404 $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
405 if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEINFORMATIONFORPRODUCT'])){
406 return($res['XML'][0]);
407 }
408 return(FALSE);
409 }
410 }
412 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
413 ?>