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