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