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);
22 $items = array();
23 if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
24 $items = $res['XML'][0]['RESULT'][0]['HIT'];
25 $data =array();
26 foreach($items as $item){
27 $entry = array();
28 foreach(
29 array(
30 "DESCRIPTION" => "description",
31 "LICENSEPOOLID" => "cn",
32 "PRODUCTIDS" => "productId",
33 "WINDOWSSOFTWAREIDS"=> "softwareId") as $source => $dest){
35 if(isset($item[$source])){
36 $entry[$dest] = array('count' => 0);
37 foreach($item[$source] as $obj){
38 $entry[$dest][] = $obj['VALUE'];
39 }
40 $entry[$dest]['count'] = (count($entry[$dest]) -1 );
41 }
42 }
43 $data[] =$entry;
44 }
45 return($data);
46 }
47 return(FALSE);
48 }
51 /* @brief Create a license pool at Opsi server.
52 * @param licensePoolId The name of the pool (optional).
53 * @param description The description of the pool (optional).
54 * @param productIds A list of assigned porducts of the pool (optional).
55 * @param windowsSoftwareIds A list of windows software Ids associated to the pool (optional).
56 */
57 function createPool($poolId,$desc = "",$products = array(),$softwareIds = array())
58 {
59 $data= array();
60 $data['licensePoolId'] = htmlentities($poolId);
61 if(!empty($desc)){
62 $data['description'] = htmlentities($desc);
63 }
64 if(count($products)){
65 $data['productIds'] = $products;
66 }
67 if(count($softwareIds)){
68 $data['windowsSoftwareIds'] = $softwareIds;
69 }
71 $res = $this->send_data("gosa_opsi_createLicensePool",$this->target,$data,TRUE);
72 if(isset($res['XML'][0]['ANSWER_OPSI_CREATELICENSEPOOL'])){
73 return(TRUE);
74 }
75 return(FALSE);
76 }
79 /*
80 * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
81 * @param licensePoolId The name of the pool.
82 */
83 function getPool($licensePoolId)
84 {
85 $data= array();
86 $data['licensePoolId'] = htmlentities($licensePoolId);
87 $res = $this->send_data("gosa_opsi_getPool",$this->target,$data,TRUE);
89 if(isset($res['XML'][0]['ANSWER_OPSI_GETPOOL'])){
90 $item = array();
91 foreach(array("LICENSEPOOLID" => "cn",
92 "DESCRIPTION" => "description",
93 "LICENSES" => "licenses",
94 "LICENSECONTRACTDATA" => "contract",
95 "WINDOWSSOFTWAREIDS" => "softwareId",
96 "PRODUCTIDS" => "productId") as $source => $target){
97 if(isset($res['XML'][0][$source])){
98 $item[$target] = array('count' => 0);
101 foreach($res['XML'][0][$source] as $data){
102 if(isset($data['VALUE'])){
103 $item[$target][] = $data['VALUE'];
104 }elseif(isset($data['HIT'])){
105 $item[$target] = array_merge($item[$target],$data['HIT']);
106 }
107 }
108 $item[$target]['count'] = count($item[$target]) -1 ;
109 }
110 }
111 return($item);
112 }
113 return(FALSE);
114 }
117 /*
118 * @brief
119 * Delete licnese pool by license pool Id.
120 * A pool can only be deleted if there are no software licenses bound to the pool.
121 * The fixed parameter deleteLicenses=True specifies that
122 * all software licenses bound to the pool are being deleted.
123 * @param licensePoolId The name of the pool.
124 */
125 function deletePool($poolId, $force = FALSE)
126 {
127 $data= array();
128 $data['licensePoolId'] = htmlentities($poolId);
129 if($force){
130 $data['deleteLicenses'] = 'TRUE';
131 }
132 $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
133 if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
134 return(TRUE);
135 }
136 return(FALSE);
137 }
140 /*******************
141 * LICENSES
142 *******************/
144 /*
145 * @brief
146 * Create a license contract, create a software
147 * license and add the software license to the license pool
148 * @param licensePoolId The name of the pool the license should be assigned.
149 * @param licenseKey The license key.
150 * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL"
151 * @param partner Name of the license partner (optional).
152 * @param conclusionDate Date of conclusion of license contract (optional)
153 * @param notificationDate Date of notification that license is running out soon (optional).
154 * @param notes This is the place for some notes (optional)
155 * @param softwareLicenseId Identificator of a license (optional).
156 * @param maxInstallations The number of clients use this license (optional).
157 * @param boundToHost The name of the client the license is bound to (optional).
158 * @param expirationDate The date when the license is running down (optional).
159 */
160 function createLicense($poolId, $licenseId, $licenseKey,$licenseType = "",
161 $partner = "",
162 $conclusionDate = "",
163 $notificationDate ="",
164 $notes = "",
165 $softwareLicenseId = "",
166 $maxInstallations = "",
167 $boundToHost = "",
168 $expirationDate = "")
169 {
171 $data= array();
172 $data['licensePoolId'] = htmlentities($poolId);
173 $data['licenseKey'] = htmlentities($licenseKey);
174 $data['licenseId'] = htmlentities($licenseId);
176 // Append optional attributes
177 foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
178 "licenseType","maxInstallations","boundToHost","expirationDate") as $attr){
179 if(!empty($$attr)){
180 $data[$attr] = $$attr;
181 }
182 }
184 $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
185 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
186 return(TRUE);
187 }
188 return(FALSE);
189 }
192 /* @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp,
193 * licensePoolIds and licenseKeys for a given softwareLicense Id.
194 * @param softwareLicenseId Identificator of a license.
195 */
196 function getLicense($softwareLicenseId)
197 {
198 $data= array();
199 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
200 $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
202 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
203 return($res);
204 }
205 return(FALSE);
206 }
209 function getReservedLicensesForHost($hostId)
210 {
211 $data= array();
212 if(!empty($hostId)){
213 $data['hostId'] = htmlentities($hostId);
214 }
215 $res = $this->send_data("gosa_opsi_getReservedLicenses",$this->target,$data,TRUE);
216 if(isset($res['XML'][0]['ANSWER_OPSI_GETRESERVEDLICENSES'])){
218 $items = array();
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 return($items);
236 }
237 return(FALSE);
238 }
241 /*
242 * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
243 * @param hostid Something like client_1.intranet.mydomain.de (optional).
244 * @param licensePoolId The name of the pool (optional).
245 */
246 function getLicenseUsage($hostId = "", $licensePoolId = "")
247 {
248 $data= array();
249 if(!empty($hostId)){
250 $data['hostId'] = htmlentities($hostId);
251 }
252 if(!empty($hostId)){
253 $data['licensePoolId'] = htmlentities($licensePoolId);
254 }
256 $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages",$this->target,$data,TRUE);
257 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES'])){
259 $items = array();
260 foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
261 $item = array();
262 foreach(array(
263 "HOSTID" => "hostId",
264 "LICENSEKEY" => "licenseKey",
265 "LICENSEPOOLID" => "licensePoolId",
266 "NOTES" => "notes",
267 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
268 if(isset($entry[$source])){
270 $item[$target] = array('count' => 0);
271 foreach($entry[$source] as $data){
272 $item[$target][] = $data['VALUE'];
273 }
274 $item[$target]['count'] = count($item[$target]) -1 ;
275 }
276 }
277 $items[] = $item;
278 }
279 return($items);
280 }
281 return(FALSE);
282 }
285 /* @brief Assigns a software license to a host
286 * @param hostId Something like client_1.intranet.mydomain.de
287 * @param licensePoolId The name of the pool.
288 */
289 function addLicenseToHost($licensePoolId,$hostId)
290 {
291 $data= array();
292 $data['licensePoolId'] = htmlentities($licensePoolId);
293 $data['hostId'] = htmlentities($hostId);
294 $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
295 if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
296 return(TRUE);
297 }
298 return(FALSE);
299 }
302 /*
303 * @brief Unassign a software license from a host.
304 * @param hostid Something like client_1.intranet.mydomain.de
305 * @param licensePoolId The name of the pool.
306 */
307 function removeLicenseFromHost($licensePoolId,$hostId)
308 {
309 $data= array();
310 $data['licensePoolId'] = htmlentities($licensePoolId);
311 $data['hostId'] = htmlentities($hostId);
312 $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
313 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
314 return(TRUE);
315 }
316 return(FALSE);
317 }
319 /*
320 * @brief Removes a single license from a license pool
321 * Attention, the software license has to exists
322 * otherwise it will lead to an Opsi internal server error.
323 * @param softwareLicenseId
324 * @param licensePoolId
325 */
326 function removeLicenseFromPool($licensePoolId,$softwareLicenseId)
327 {
328 $data= array();
329 $data['licensePoolId'] = htmlentities($licensePoolId);
330 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
331 $res = $this->send_data("gosa_opsi_removeLicense",$this->target,$data,TRUE);
332 if(isset($res['XML'][0]['ANSWER_OPSI_REMOVELICENSE'])){
333 return(TRUE);
334 }
335 return(FALSE);
336 }
339 /*
340 * @brief Unassign all software licenses from a host
341 * @param hostid Something like client_1.intranet.mydomain.de
342 */
343 function removeAllLicensesFromHost($hostId)
344 {
345 $data= array();
346 $data['hostId'] = htmlentities($hostid);
347 $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
348 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
349 return(TRUE);
350 }
351 return(FALSE);
352 }
355 /* @brief
356 * Returns the assigned licensePoolId and licenses,
357 * how often the product is installed and at which host
358 * and the number of max and remaining installations for a given OPSI product.
359 * @param productId Identificator of an OPSI product.
360 */
361 function getLicensesForProduct($productId)
362 {
363 $data= array();
364 $data['productId'] = htmlentities($productId);
365 $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
366 if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEINFORMATIONFORPRODUCT'])){
367 return($res['XML'][0]);
368 }
369 return(FALSE);
370 }
371 }
373 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
374 ?>