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);
88 if(isset($res['XML'][0]['ANSWER_OPSI_GETPOOL'])){
89 $item = array();
90 foreach(array("LICENSEPOOLID" => "cn",
91 "DESCRIPTION" => "description",
92 "LICENSES" => "licenses",
93 "WINDOWSSOFTWAREIDS" => "softwareId",
94 "PRODUCTIDS" => "productId") as $source => $target){
95 if(isset($res['XML'][0][$source])){
96 $item[$target] = array('count' => 0);
99 foreach($res['XML'][0][$source] as $data){
100 if(isset($data['VALUE'])){
101 $item[$target][] = $data['VALUE'];
102 }elseif(isset($data['HIT'])){
103 $item[$target] = array_merge($item[$target],$data['HIT']);
104 }
105 }
106 $item[$target]['count'] = count($item[$target]) -1 ;
107 }
108 }
109 return($item);
110 }
111 return(FALSE);
112 }
115 /*
116 * @brief
117 * Delete licnese pool by license pool Id.
118 * A pool can only be deleted if there are no software licenses bound to the pool.
119 * The fixed parameter deleteLicenses=True specifies that
120 * all software licenses bound to the pool are being deleted.
121 * @param licensePoolId The name of the pool.
122 */
123 function deletePool($poolId, $force = FALSE)
124 {
125 $data= array();
126 $data['licensePoolId'] = htmlentities($poolId);
127 if($force){
128 $data['deleteLicenses'] = 'TRUE';
129 }
130 $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
131 if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
132 return(TRUE);
133 }
134 return(FALSE);
135 }
138 /*******************
139 * LICENSES
140 *******************/
142 /*
143 * @brief
144 * Create a license contract, create a software
145 * license and add the software license to the license pool
146 * @param licensePoolId The name of the pool the license should be assigned.
147 * @param licenseKey The license key.
148 * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL"
149 * @param partner Name of the license partner (optional).
150 * @param conclusionDate Date of conclusion of license contract (optional)
151 * @param notificationDate Date of notification that license is running out soon (optional).
152 * @param notes This is the place for some notes (optional)
153 * @param softwareLicenseId Identificator of a license (optional).
154 * @param maxInstallations The number of clients use this license (optional).
155 * @param boundToHost The name of the client the license is bound to (optional).
156 * @param expirationDate The date when the license is running down (optional).
157 */
158 function createLicense($poolId, $licenseKey,$licenseTyp = "",
159 $partner = "",
160 $conclusionDate = "",
161 $notificationDate ="",
162 $notes = "",
163 $softwareLicenseId = "",
164 $maxInstallations = "",
165 $boudToHost = "",
166 $expirationDate = "")
167 {
169 $data= array();
170 $data['licensePoolId'] = htmlentities($poolId);
171 $data['licenseKey'] = htmlentities($licenseKey);
173 // Append optional attributes
174 foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
175 "licenseTyp","maxInstallations","boudToHost","expirationDate") as $attr){
176 if(!empty($$attr)){
177 $data[$attr] = $$attr;
178 }
179 }
181 $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
182 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
183 return(TRUE);
184 }
185 return(FALSE);
186 }
189 /* @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp,
190 * licensePoolIds and licenseKeys for a given softwareLicense Id.
191 * @param softwareLicenseId Identificator of a license.
192 */
193 function getLicense($softwareLicenseId)
194 {
195 $data= array();
196 $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
197 $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
199 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
200 return($res);
201 }
202 return(FALSE);
203 }
206 /*
207 * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
208 * @param hostid Something like client_1.intranet.mydomain.de (optional).
209 * @param licensePoolId The name of the pool (optional).
210 */
211 function getLicenseUsage($hostId = "", $licensePoolId = "")
212 {
213 $data= array();
214 if(!empty($hostId)){
215 $data['hostId'] = htmlentities($hostId);
216 }
217 if(!empty($hostId)){
218 $data['licensePoolId'] = htmlentities($licensePoolId);
219 }
221 $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
222 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
224 $items = array();
225 foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
226 $item = array();
227 foreach(array(
228 "HOSTID" => "hostId",
229 "LICENSEKEY" => "licenseKey",
230 "LICENSEPOOLID" => "licensePoolId",
231 "NOTES" => "notes",
232 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
233 if(isset($entry[$source])){
235 $item[$target] = array('count' => 0);
236 foreach($entry[$source] as $data){
237 $item[$target][] = $data['VALUE'];
238 }
239 $item[$target]['count'] = count($item[$target]) -1 ;
240 }
241 }
242 $items[] = $item;
243 }
244 return($items);
245 }
246 return(FALSE);
247 }
250 /* @brief Assigns a software license to a host
251 * @param hostId Something like client_1.intranet.mydomain.de
252 * @param licensePoolId The name of the pool.
253 */
254 function addLicenseToHost($licensePoolId,$hostId)
255 {
256 $data= array();
257 $data['licensePoolId'] = htmlentities($licensePoolId);
258 $data['hostId'] = htmlentities($hostId);
259 $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
260 if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
261 return(TRUE);
262 }
263 return(FALSE);
264 }
267 /*
268 * @brief Unassign a software license from a host.
269 * @param hostid Something like client_1.intranet.mydomain.de
270 * @param licensePoolId The name of the pool.
271 */
272 function removeLicenseFromHost($licensePoolId,$hostId)
273 {
274 $data= array();
275 $data['licensePoolId'] = htmlentities($licensePoolId);
276 $data['hostId'] = htmlentities($hostid);
277 $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
278 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
279 return(TRUE);
280 }
281 return(FALSE);
282 }
285 /*
286 * @brief Unassign all software licenses from a host
287 * @param hostid Something like client_1.intranet.mydomain.de
288 */
289 function removeAllLicensesFromHost($hostId)
290 {
291 $data= array();
292 $data['hostId'] = htmlentities($hostid);
293 $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
294 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
295 return(TRUE);
296 }
297 return(FALSE);
298 }
301 /* @brief
302 * Returns the assigned licensePoolId and licenses,
303 * how often the product is installed and at which host
304 * and the number of max and remaining installations for a given OPSI product.
305 * @param productId Identificator of an OPSI product.
306 */
307 function getLicensesForProduct($productId)
308 {
309 $data= array();
310 $data['productId'] = htmlentities($productId);
311 $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
312 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
313 return($res['XML'][0]);
314 }
315 return(FALSE);
316 }
317 }
319 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
320 ?>