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,$licenseTyp = "",
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 "licenseTyp","maxInstallations","boundToHost","expirationDate") as $attr){
179 if(!empty($$attr)){
180 $data[$attr] = $$attr;
181 }
182 }
184 print_a($data);
186 $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
187 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
188 return(TRUE);
189 }
190 return(FALSE);
191 }
194 /* @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp,
195 * licensePoolIds and licenseKeys for a given softwareLicense Id.
196 * @param softwareLicenseId Identificator of a license.
197 */
198 function getLicense($softwareLicenseId)
199 {
200 $data= array();
201 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
202 $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
204 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
205 return($res);
206 }
207 return(FALSE);
208 }
211 /*
212 * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
213 * @param hostid Something like client_1.intranet.mydomain.de (optional).
214 * @param licensePoolId The name of the pool (optional).
215 */
216 function getLicenseUsage($hostId = "", $licensePoolId = "")
217 {
218 $data= array();
219 if(!empty($hostId)){
220 $data['hostId'] = htmlentities($hostId);
221 }
222 if(!empty($hostId)){
223 $data['licensePoolId'] = htmlentities($licensePoolId);
224 }
226 $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
227 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
229 $items = array();
230 foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
231 $item = array();
232 foreach(array(
233 "HOSTID" => "hostId",
234 "LICENSEKEY" => "licenseKey",
235 "LICENSEPOOLID" => "licensePoolId",
236 "NOTES" => "notes",
237 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
238 if(isset($entry[$source])){
240 $item[$target] = array('count' => 0);
241 foreach($entry[$source] as $data){
242 $item[$target][] = $data['VALUE'];
243 }
244 $item[$target]['count'] = count($item[$target]) -1 ;
245 }
246 }
247 $items[] = $item;
248 }
249 return($items);
250 }
251 return(FALSE);
252 }
255 /* @brief Assigns a software license to a host
256 * @param hostId Something like client_1.intranet.mydomain.de
257 * @param licensePoolId The name of the pool.
258 */
259 function addLicenseToHost($licensePoolId,$hostId)
260 {
261 $data= array();
262 $data['licensePoolId'] = htmlentities($licensePoolId);
263 $data['hostId'] = htmlentities($hostId);
264 $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
265 if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
266 return(TRUE);
267 }
268 return(FALSE);
269 }
272 /*
273 * @brief Unassign a software license from a host.
274 * @param hostid Something like client_1.intranet.mydomain.de
275 * @param licensePoolId The name of the pool.
276 */
277 function removeLicenseFromHost($licensePoolId,$hostId)
278 {
279 $data= array();
280 $data['licensePoolId'] = htmlentities($licensePoolId);
281 $data['hostId'] = htmlentities($hostid);
282 $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
283 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
284 return(TRUE);
285 }
286 return(FALSE);
287 }
289 /*
290 * @brief Removes a single license from a license pool
291 * Attention, the software license has to exists
292 * otherwise it will lead to an Opsi internal server error.
293 * @param softwareLicenseId
294 * @param licensePoolId
295 */
296 function removeLicenseFromPool($licensePoolId,$softwareLicenseId)
297 {
298 $data= array();
299 $data['licensePoolId'] = htmlentities($licensePoolId);
300 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
301 $res = $this->send_data("gosa_opsi_removeLicense",$this->target,$data,TRUE);
302 if(isset($res['XML'][0]['ANSWER_OPSI_REMOVELICENSE'])){
303 return(TRUE);
304 }
305 return(FALSE);
306 }
309 /*
310 * @brief Unassign all software licenses from a host
311 * @param hostid Something like client_1.intranet.mydomain.de
312 */
313 function removeAllLicensesFromHost($hostId)
314 {
315 $data= array();
316 $data['hostId'] = htmlentities($hostid);
317 $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
318 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
319 return(TRUE);
320 }
321 return(FALSE);
322 }
325 /* @brief
326 * Returns the assigned licensePoolId and licenses,
327 * how often the product is installed and at which host
328 * and the number of max and remaining installations for a given OPSI product.
329 * @param productId Identificator of an OPSI product.
330 */
331 function getLicensesForProduct($productId)
332 {
333 $data= array();
334 $data['productId'] = htmlentities($productId);
335 $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
336 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
337 return($res['XML'][0]);
338 }
339 return(FALSE);
340 }
341 }
343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
344 ?>