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 $boudToHost = "",
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","boudToHost","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 /*
210 * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
211 * @param hostid Something like client_1.intranet.mydomain.de (optional).
212 * @param licensePoolId The name of the pool (optional).
213 */
214 function getLicenseUsage($hostId = "", $licensePoolId = "")
215 {
216 $data= array();
217 if(!empty($hostId)){
218 $data['hostId'] = htmlentities($hostId);
219 }
220 if(!empty($hostId)){
221 $data['licensePoolId'] = htmlentities($licensePoolId);
222 }
224 $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
225 if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
227 $items = array();
228 foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
229 $item = array();
230 foreach(array(
231 "HOSTID" => "hostId",
232 "LICENSEKEY" => "licenseKey",
233 "LICENSEPOOLID" => "licensePoolId",
234 "NOTES" => "notes",
235 "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){
236 if(isset($entry[$source])){
238 $item[$target] = array('count' => 0);
239 foreach($entry[$source] as $data){
240 $item[$target][] = $data['VALUE'];
241 }
242 $item[$target]['count'] = count($item[$target]) -1 ;
243 }
244 }
245 $items[] = $item;
246 }
247 return($items);
248 }
249 return(FALSE);
250 }
253 /* @brief Assigns a software license to a host
254 * @param hostId Something like client_1.intranet.mydomain.de
255 * @param licensePoolId The name of the pool.
256 */
257 function addLicenseToHost($licensePoolId,$hostId)
258 {
259 $data= array();
260 $data['licensePoolId'] = htmlentities($licensePoolId);
261 $data['hostId'] = htmlentities($hostId);
262 $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
263 if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
264 return(TRUE);
265 }
266 return(FALSE);
267 }
270 /*
271 * @brief Unassign a software license from a host.
272 * @param hostid Something like client_1.intranet.mydomain.de
273 * @param licensePoolId The name of the pool.
274 */
275 function removeLicenseFromHost($licensePoolId,$hostId)
276 {
277 $data= array();
278 $data['licensePoolId'] = htmlentities($licensePoolId);
279 $data['hostId'] = htmlentities($hostid);
280 $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
281 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
282 return(TRUE);
283 }
284 return(FALSE);
285 }
288 /*
289 * @brief Unassign all software licenses from a host
290 * @param hostid Something like client_1.intranet.mydomain.de
291 */
292 function removeAllLicensesFromHost($hostId)
293 {
294 $data= array();
295 $data['hostId'] = htmlentities($hostid);
296 $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
297 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
298 return(TRUE);
299 }
300 return(FALSE);
301 }
304 /* @brief
305 * Returns the assigned licensePoolId and licenses,
306 * how often the product is installed and at which host
307 * and the number of max and remaining installations for a given OPSI product.
308 * @param productId Identificator of an OPSI product.
309 */
310 function getLicensesForProduct($productId)
311 {
312 $data= array();
313 $data['productId'] = htmlentities($productId);
314 $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
315 if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
316 return($res['XML'][0]);
317 }
318 return(FALSE);
319 }
320 }
322 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
323 ?>