summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1496b24)
raw | patch | inline | side by side (parent: 1496b24)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 10:27:22 +0000 (10:27 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 22 Sep 2009 10:27:22 +0000 (10:27 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14304 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc
--- /dev/null
@@ -0,0 +1,232 @@
+<?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id: class_divListRole.inc 12852 2008-10-31 16:19:40Z cajus $$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+class divListRole extends MultiSelectWindow
+{
+
+ // Current base
+ var $selectedBase = "";
+ var $departments = array();
+
+ // Regex
+ var $Regex = "*";
+
+ // Subsearch checkbox
+ var $SubSearch ;
+ var $parent ;
+ var $ui ;
+
+ function divListRole (&$config,$parent)
+ {
+ MultiSelectWindow::MultiSelectWindow($config, "Licenses", "licenses");
+
+ $this->parent = $parent;
+ $this->ui = get_userinfo();
+
+ // Dynamic action col, depending on snapshot icons
+ $action_col_size = 90;
+ if($this->parent->snapshotEnabled()){
+ $action_col_size += 38;
+ }
+
+ // Set list strings
+ $this->SetTitle(_("List of licenses"));
+ $this->SetSummary(_("List of licenses"));
+ $this->EnableAplhabet(true);
+
+ // Result page will look like a headpage
+ $this->SetHeadpageMode();
+
+ // Disable buttonsm
+ $this->EnableCloseButton(false);
+ $this->EnableSaveButton (false);
+
+ // Add checkbox: Toggle all selected / deselected
+ $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
+ onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
+ // Set Page col headers
+ $this->AddHeader(array("string" => $chk,"attach"=>"style='width:20px;'"));
+ $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
+ $this->AddHeader(array("string" => _("Role")." / "._("Department"), "attach" => "style=''"));
+ $this->AddHeader(array("string" => _("Actions"),
+ "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
+
+ // Add SubSearch checkbox
+ //$this->AddCheckBox(SEPERATOR);
+ $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"),
+ msgPool::selectToView("","subsearch_small"), false);
+
+ // Add regex user input field
+ $this->AddRegex ("Regex", _("Regular expression for matching license names"), "*" , true);
+ }
+
+
+ function GenHeader()
+ {
+ /* Get all departments within this subtree */
+ $ui= get_userinfo();
+ $first = "";
+ $found = FALSE;
+ $base = $this->config->current['BASE'];
+ $options = $this->create_department_list($this->module);
+
+ /* Add a seperator after displaying c&p and snapshot icons ? */
+ $add_sep = false;
+
+ /* Get copy & paste icon */
+ $acls = $ui->get_permissions($this->selectedBase,"licenses/licenseGeneric");
+ $acl_all= $ui->has_complete_category_acls($this->selectedBase,"licenses");
+
+ /* Add default header */
+ $listhead = MultiSelectWindow::get_default_header();
+
+ /* Add department selector */
+ $listhead .= _("Base")." <select name='CurrentMainBase'
+ onChange='mainform.submit()' class='center'>$options</select>".
+ " <input class='center' type='image' src='images/lists/submit.png' align='middle'
+ title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
+
+ /* Create Layers menu */
+ $s = ".|"._("Actions")."|\n";
+
+ /* Append create options */
+ if(preg_match("/c/",$acls)) {
+ $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
+ " "._("Create")."|\n";
+ $s.= "...|<input class='center' type='image' src='plugins/licensemanagement/images/new.png' alt=''>".
+ " "._("Role")."|license_new|\n";
+ }
+
+ /* Multiple options */
+ $s.= "..|---|\n";
+ $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
+ " "._("Remove")."|"."remove_multiple_licenses|\n";
+
+ /* Add Copy & Paste header */
+ $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
+
+ /* Add snapshot icons */
+ $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
+
+ $this->SetDropDownHeaderMenu($s);
+ $this->SetListHeader($listhead);
+ }
+
+
+ function execute()
+ {
+ $this->ClearElementsList();
+ $this->GenHeader();
+ }
+
+ function setEntries($list)
+ {
+ // Defining Links
+ $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
+
+ // Dynamic action col, depending on snapshot icons
+ $action_col_size = 90;
+ if($this->parent->snapshotEnabled()){
+ $action_col_size += 38;
+ }
+
+ $ui = get_userinfo();
+
+ // Assigning licenses
+ foreach($list as $key => $val){
+
+ // Get object permissions
+ $acl = $ui->get_permissions($val['dn'],"licenses/licenseGeneric");
+ $acl_all= $ui->has_complete_category_acls($val['dn'],"licenses");
+
+
+ // Add copy & cut functionality */
+ $actions = $this->parent->get_copypaste_action($val['dn'],"ogroups","ogroup");
+
+ // Create edit and remove icon buttons
+ $actions.= "<input class='center' type='image'
+ src='images/lists/edit.png' alt='"._("edit")."'
+ name='license_edit_%KEY%' title='"._("Edit this entry")."'>";
+
+ $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
+ if(preg_match("/d/",$acl)){
+ $actions.= "<input class='center' type='image'
+ src='images/lists/trash.png' alt='"._("delete")."'
+ name='license_del_%KEY%' title='"._("Delete this entry")."'>";
+ }else{
+ $actions.= "<img class='center' src='images/empty.png' alt=' '
+ title='".msgPool::permDelete()."'>";
+ }
+
+ // Append license descriptio, if available
+ $title = "title='".preg_replace('/ /', ' ', LDAP::fix($val['dn']))."'";
+ if(!isset($val['description'][0])){
+ $desc = "";
+ }else{
+ $desc = " - [ ".$val['description'][0]." ]";
+ }
+
+ // Cutted entry are displayed in a light grey as indication.
+ $display = $val['cn'][0].$desc;
+ if($this->parent->CopyPasteHandler){
+ foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
+ if($queue_data['dn'] == $val['dn']) {
+ $display = "<font color='#999999'>".$display."</font>";
+ break;
+ }
+ }
+ }
+
+ // Append the entry to the divlist
+ $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."'
+ name='item_selected_".$key."'>" ,
+ "attach" => "style='width:20px;'");
+ $field1 = array("string" => "<img src='plugins/licensemanagement/images/license.png'
+ alt='"._("Role")."' ".$title.">",
+ "attach" => "style='text-align:center;width: 20px;'");
+ $field2 = array("string" => sprintf($editlink,$key,$display),
+ "attach" => "style='' ".$title);
+ $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions),
+ "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
+
+ $this->AddElement(array($field0,$field1,$field2,$field4));
+ }
+
+
+ // Create the list summary
+ $num_deps=0;
+ if(!$this->SubSearch){
+ $num_deps = count($this->Added_Departments);
+ }
+ $num_objs = count($list);
+ $num_obj_str = _("Number of listed licenses");
+ $num_dep_str = _("Number of listed departments");
+ $str = "<img class='center' src='plugins/licensemanagement/images/license.png'
+ title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
+ $str.= "<img class='center' src='images/lists/folder.png'
+ title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
+ $this->set_List_Bottom_Info($str);
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc
index b7b7cbd20441239645bde927b50273a40b3cabd1..e0b0857ea1bea5497b6eb9c9b9fda858478f49c5 100644 (file)
var $objectclasses = array("top","organizationalRole");
// The list of occupants ([dn])
- var $roleOccupant = array();
+ var $licenseOccupant = array();
- // The roleOccupant cache, dn=>attrs
- var $roleOccCache = array();
+ // The licenseOccupant cache, dn=>attrs
+ var $licenseOccCache = array();
// A list of attributes managed by this plugin
var $attributes = array("cn","description",
- "telephoneNumber","facsimileTelephoneNumber","roleOccupant");
+ "telephoneNumber","facsimileTelephoneNumber","licenseOccupant");
/* Initialize the class
$this->is_account = TRUE;
// Initialize list of occupants
- $this->roleOccupant = array();
- if(isset($this->attrs['roleOccupant'])){
- for($i=0;$i<$this->attrs['roleOccupant']['count']; $i++){
- $this->roleOccupant[] = $this->attrs['roleOccupant'][$i];
+ $this->licenseOccupant = array();
+ if(isset($this->attrs['licenseOccupant'])){
+ for($i=0;$i<$this->attrs['licenseOccupant']['count']; $i++){
+ $this->licenseOccupant[] = $this->attrs['licenseOccupant'][$i];
}
}
if ($this->dn == "new"){
$this->base = session::get('CurrentMainBase');
} else {
- $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("roleRDN"), '/i')."/","",$this->dn);
+ $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("licenseRDN"), '/i')."/","",$this->dn);
}
// Keep track of naming attribute modifications
{
// Entries can't be added twice.
$attrs = array("description", "objectClass", "uid","cn");
- $this->roleOccupant = array_unique($this->roleOccupant);
- $this->roleOccupant = array_values($this->roleOccupant);
+ $this->licenseOccupant = array_unique($this->licenseOccupant);
+ $this->licenseOccupant = array_values($this->licenseOccupant);
$ldap = $this->config->get_ldap_link();
- foreach($this->roleOccupant as $dn){
- if(!isset($this->roleOccCache[$dn])){
+ foreach($this->licenseOccupant as $dn){
+ if(!isset($this->licenseOccCache[$dn])){
if($ldap->dn_exists($dn)){
$ldap->cat($dn, $attrs);
$tmp['cn'][0] = $cn;
}
- $this->roleOccCache[$dn] = $tmp;
+ $this->licenseOccCache[$dn] = $tmp;
}
}
}
function getOccupants(){
- return($this->roleOccupant);
+ return($this->licenseOccupant);
}
/* Generate HTML output of this plugin.
if(isset($_POST['delete_membership']) && !$this->dialog instanceOf plugin){
if(isset($_POST['members'])){
foreach($_POST['members'] as $id){
- if(isset($this->roleOccupant[$id])){
- unset($this->roleOccupant[$id]);
+ if(isset($this->licenseOccupant[$id])){
+ unset($this->licenseOccupant[$id]);
}
}
$this->reload();
if(isset($_POST['add_object_finish']) && $this->dialog instanceOf plugin){
$ret = $this->dialog->save();
foreach($ret as $key => $entry){
- $this->roleOccupant[] = $entry['dn'];
- $this->roleOccCache[$entry['dn']] = $entry['attrs'];
+ $this->licenseOccupant[] = $entry['dn'];
+ $this->licenseOccCache[$entry['dn']] = $entry['attrs'];
}
$this->reload();
$this->dialog = NULL;
foreach($tmp['plProvidedAcls'] as $attr => $desc){
$smarty->assign($attr."ACL",$this->getacl($attr));
}
- return($smarty->fetch(get_template_path('roleGeneric.tpl',TRUE,dirname(__FILE__))));
+ return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
}
$message[]= msgPool::required(_("Name"));
}
- // Check if this name is uniq for roles.
+ // Check if this name is uniq for licenses.
$ldap= $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(&(objectClass=organizationalRole)(cn=$this->cn))", array("cn"));
{
$temp= "";
$icon = " style=\"background-image:url('plugins/generic/images/head.png');\" ";
- foreach ($this->roleOccupant as $key => $dn){
- if(isset($this->roleOccCache[$dn])){
- $entry = $this->roleOccCache[$dn];
+ foreach ($this->licenseOccupant as $key => $dn){
+ if(isset($this->licenseOccCache[$dn])){
+ $entry = $this->licenseOccCache[$dn];
$name = $entry['cn']['0'];
if(isset($entry['description'][0])){
$name .= " [".$entry['description'][0]."]";
}
// Log action.
- new log("remove","roles/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+ new log("remove","licenses/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
// Trigger remove signal
$this->handle_post_events("remove");
plugin::PrepareForCopyPaste($source);
/* Load member objects */
- $this->roleOccupant = array();
- if (isset($source['roleOccupant'])){
- foreach ($source['roleOccupant'] as $key => $value){
+ $this->licenseOccupant = array();
+ if (isset($source['licenseOccupant'])){
+ foreach ($source['licenseOccupant'] as $key => $value){
if ("$key" != "count"){
$value= @LDAP::convert($value);
- $this->roleOccupant["$value"]= "$value";
+ $this->licenseOccupant["$value"]= "$value";
}
}
}
"plDepends" => array(),
"plPriority" => 1,
"plSection" => array("administration"),
- "plCategory" => array("roles" => array("description" => _("Roles"),
+ "plCategory" => array("licenses" => array("description" => _("Licenses"),
"objectClass" => "organizationalRole")),
"plProvidedAcls"=> array(
"cn" => _("Name"),
"base" => _("Base"),
"telephoneNumber" => _("Telefon number"),
"facsimileTelephoneNumber" => _("Fax number"),
- "roleOccupant" => _("Occupants"))
+ "licenseOccupant" => _("Occupants"))
));
}
}
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenceHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenceHandler.inc
index b8ce0afd20c39aad7a452a3735ce41b7d5441f6a..f835c0fdabaf3cba91b23e6e3d566398e5225c9a 100644 (file)
<?php
-class opsiLicenceHandler extends gosaSupportDaemon {
+class opsiLicenceHandler extends opsi {
- function listLicenses()
- {
- $data = "<header>opsi_getLicensePools_listOfHashes</header>".
- "<source>GOSA</source>".
- "<target>GOSA</target></header>";
- $res = $this->_send($data, TRUE);
+ /*******************
+ * POOLs
+ *******************/
+
+ protected $use_alternative_xml_parse_method = TRUE;
+
+ /* @brief Returns licensePoolId, description, productIds and windowsSoftwareIds
+ * for all found license pools.
+ */
+ function listPools()
+ {
+ $data= array();
+ $res = $this->send_data("gosa_opsi_getLicensePools_listOfHashes",$this->target,$data,TRUE);
+ $items = array();
+ if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
+ $items = $res['XML'][0]['RESULT'][0]['HIT'];
+ }
+ return($items);
}
* @param licensePoolId The name of the pool (optional).
* @param description The description of the pool (optional).
* @param productIds A list of assigned porducts of the pool (optional).
- * @param windowsSoftwareIds A list of windows software IDs associated to the pool (optional).
+ * @param windowsSoftwareIds A list of windows software Ids associated to the pool (optional).
*/
- function opsi_createLicensePool()
+ function createPool($poolId,$desc = "",$products = array(),$softwareIds = array())
{
+ $data= array();
+ $data['licensePoolId'] = htmlentities($poolId);
+ if(!empty($desc)){
+ $data['description'] = htmlentities($desc);
+ }
+ if(count($products)){
+ $data['productIds'] = $products;
+ }
+ if(count($softwareIds)){
+ $data['windowsSoftwareIds'] = $softwareIds;
+ }
+
+ $res = $this->send_data("gosa_opsi_createLicensePool",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_CREATELICENSEPOOL'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
+
+ /*
+ * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
+ * @param licensePoolId The name of the pool.
+ */
+ function getPool($licensePoolId)
+ {
+ $data= array();
+ $data['licensePoolId'] = htmlentities($licensePoolId);
+ $res = $this->send_data("gosa_opsi_getLicensePool_hash",$this->target,$data,TRUE);
+
+ print_a($res);
+
+ if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEPOOL_HASH'])){
+ $item = array();
+ foreach(array("LICENSEPOOLID" => "licensePoolId",
+ "DESCRIPTION" => "description",
+ "WINDOWSSOFTWAREIDS" => "windowsSoftwareIds",
+ "PRODUCTIDS" => "productIds") as $source => $target){
+ if(isset($res['XML'][0][$source])){
+ foreach($res['XML'][0][$source] as $data){
+ $item[$target][] = $res['XML'][0][$source][0]['VALUE'];
+ }
+ }
+ }
+ return($item);
+ }
+ return(FALSE);
}
+
/*
* @brief
- * Delete licnese pool by license pool ID.
+ * Delete licnese pool by license pool Id.
* A pool can only be deleted if there are no software licenses bound to the pool.
* The fixed parameter deleteLicenses=True specifies that
* all software licenses bound to the pool are being deleted.
* @param licensePoolId The name of the pool.
*/
- function opsi_deleteLicensePool()
+ function deletePool($poolId, $force = FALSE)
{
-
+ $data= array();
+ $data['licensePoolId'] = htmlentities($poolId);
+ if($force){
+ $data['deleteLicenses'] = 'TRUE';
+ }
+ $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
+ return(TRUE);
+ }
+ return(FALSE);
}
+ /*******************
+ * LICENSES
+ *******************/
+
/*
* @brief
* Create a license contract, create a software
* license and add the software license to the license pool
* @param licensePoolId The name of the pool the license should be assigned.
* @param licenseKey The license key.
+ * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL"
* @param partner Name of the license partner (optional).
* @param conclusionDate Date of conclusion of license contract (optional)
* @param notificationDate Date of notification that license is running out soon (optional).
* @param notes This is the place for some notes (optional)
* @param softwareLicenseId Identificator of a license (optional).
- * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL" (optional).
* @param maxInstallations The number of clients use this license (optional).
* @param boundToHost The name of the client the license is bound to (optional).
* @param expirationDate The date when the license is running down (optional).
*/
- function opsi_createLicense()
+ function createLicense($poolId, $licenseKey,$licenseTyp = "",
+ $partner = "",
+ $conclusionDate = "",
+ $notificationDate ="",
+ $notes = "",
+ $softwareLicenseId = "",
+ $maxInstallations = "",
+ $boudToHost = "",
+ $expirationDate = "")
{
+ $data= array();
+ $data['licensePoolId'] = htmlentities($poolId);
+ $data['licenseKey'] = htmlentities($licenseKey);
+
+ // Append optional attributes
+ foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
+ "licenseTyp","maxInstallations","boudToHost","expirationDate") as $attr){
+ if(!empty($$attr)){
+ $data[$attr] = $$attr;
+ }
+ }
+
+ $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
+ return(TRUE);
+ }
+ return(FALSE);
}
- /*
- * @brief Assign a software license to a host
- * @param hostid Something like client_1.intranet.mydomain.de
- * @param licensePoolId The name of the pool.
+ /* @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp,
+ * licensePoolIds and licenseKeys for a given softwareLicense Id.
+ * @param softwareLicenseId Identificator of a license.
*/
- function opsi_assignSoftwareLicenseToHost()
+ function getLicense($softwareLicenseId)
{
-
+ $data= array();
+ $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
+ $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
+
+ if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
+ return($res);
+ }
+ return(FALSE);
}
/*
- * @brief Unassign a software license from a host.
- * @param hostid Something like client_1.intranet.mydomain.de
- * @param licensePoolId The name of the pool.
- */
- function opsi_unassignSoftwareLicenseFromHost()
- {}
-
-
- /*
- * @brief Unassign all software licenses from a host
- * @param hostid Something like client_1.intranet.mydomain.de
- */
- function opsi_unassignAllSoftwareLicensesFromHost()
- {}
-
-
- /*
- * @brief Returns expirationDate, boundToHost, maxInstallation, licenseTyp, licensePoolIds and licenseKeys for a given softwareLicense ID.
- * @param softwareLicenseId Identificator of a license.
+ * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
+ * @param hostid Something like client_1.intranet.mydomain.de (optional).
+ * @param licensePoolId The name of the pool (optional).
*/
- function opsi_getSoftwareLicense_hash()
- {}
+ function getLicenseUsage($hostId = "", $licensePoolId = "")
+ {
+ $data= array();
+ if(!empty($hostId)){
+ $data['hostId'] = htmlentities($hostId);
+ }
+ if(!empty($hostId)){
+ $data['licensePoolId'] = htmlentities($licensePoolId);
+ }
+
+ $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
+ return($res['XML'][0]['RESULT']);
+ }
+ return(FALSE);
+ }
- /*
- * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
- * @param licensePoolId The name of the pool.
+ /* @brief Assigns a software license to a host
+ * @param hostId Something like client_1.intranet.mydomain.de
+ * @param licensePoolId The name of the pool.
*/
- function opsi_getLicensePool_hash()
- {}
+ function addLicenseToHost($licensePoolId,$hostId)
+ {
+ $data= array();
+ $data['licensePoolId'] = htmlentities($licensePoolId);
+ $data['hostId'] = htmlentities($hostId);
+ $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
/*
- * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
- * @param hostid Something like client_1.intranet.mydomain.de (optional).
- * @param licensePoolId The name of the pool (optional).
+ * @brief Unassign a software license from a host.
+ * @param hostid Something like client_1.intranet.mydomain.de
+ * @param licensePoolId The name of the pool.
*/
- function opsi_getSoftwareLicenseUsages_listOfHashes()
- {}
+ function removeLicenseFromHost($licensePoolId,$hostId)
+ {
+ $data= array();
+ $data['licensePoolId'] = htmlentities($licensePoolId);
+ $data['hostId'] = htmlentities($hostid);
+ $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
/*
- * @brief Return licensePoolId, description, productIds and windowsSoftwareIds for all found license pools.
+ * @brief Unassign all software licenses from a host
+ * @param hostid Something like client_1.intranet.mydomain.de
*/
- function opsi_getLicensePools_listOfHashes()
- {}
+ function removeAllLicensesFromHost($hostId)
+ {
+ $data= array();
+ $data['hostId'] = htmlentities($hostid);
+ $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
/* @brief
* and the number of max and remaining installations for a given OPSI product.
* @param productId Identificator of an OPSI product.
*/
- function opsi_getLicenseInformationForProduct()
- {}
-
-
-
+ function getLicensesForProduct($productId)
+ {
+ $data= array();
+ $data['productId'] = htmlentities($productId);
+ $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicences.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicences.inc
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/*
-* This code is part of GOsa (http://www.gosa-project.org)
-* Copyright (C) 2003-2008 GONICUS GmbH
-*
-* ID: $$Id: class_opsiLicenses.inc 13520 2009-03-09 14:54:13Z hickert $$
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-class opsiLicenses extends management
-{
- var $plHeadline= "Opsi";
- var $plDescription= "Opsi licenses";
-
- var $ignore_account = TRUE;
-
- function execute()
- {
- $this->ignore_account = TRUE;
- $si = new opsiLicenceHandler();
- $res = $si->listLicenses();
- print_a($res);
-
- if($si->is_error()){
- echo $si->get_error();
- }
-
- }
-
- function remove_lock() {}
-}
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc
--- /dev/null
@@ -0,0 +1,488 @@
+<?php
+/*
+* This code is part of GOsa (http://www.gosa-project.org)
+* Copyright (C) 2003-2008 GONICUS GmbH
+*
+* ID: $$Id: class_licenseManagement.inc 13520 2009-03-09 14:54:13Z hickert $$
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+class opsiLicenses extends plugin
+{
+ /* Definitions */
+ var $plHeadline= "Opsi";
+ var $plDescription= "Opsi licenses";
+
+ // Copy and paste handler
+ var $CopyPasteHandler = NULL;
+
+ // The headpage list handler.
+ var $DivListLicenses = NULL;
+
+ // A list of currently visible licenses
+ var $licenses = array();
+
+ // A list of currently edited/removed/aso licenses.
+ var $dns = array();
+
+ // Permission modules to use.
+ var $acl_module = array("licenses");
+
+ // Internal: Is truw while objects are pasted.
+ var $start_pasting_copied_objects = FALSE;
+
+
+ // Construct and initialize the plugin
+ function __construct (&$config, $dn= NULL)
+ {
+ // Include config object
+ $this->config= &$config;
+ $this->ui= get_userinfo();
+
+ // Copy & Paste enabled ?
+ if ($this->config->get_cfg_value("copyPaste") == "true"){
+ $this->CopyPasteHandler = new CopyPasteHandler($this->config);
+ }
+
+ // Initialize the corresponding list class.
+ $this->DivListLicenses = new divListRole($this->config,$this);
+ }
+
+
+ function execute()
+ {
+ // Call parent execute
+ plugin::execute();
+
+ // Variables to restore after 'entry locked' warning was displayed
+ session::set('LOCK_VARS_TO_USE',array('/^copy/','/^cut/','/^license_/','/^act/',
+ '/^id/','/^menu_action/','/^item/'));
+
+ $smarty = get_smarty();
+
+ /***************
+ * Handle _POST/_GET variables
+ ***************/
+
+ // Get entry related posts
+ $s_action = "";
+ $s_entry = "";
+ foreach($_POST as $name => $value){
+ if(preg_match("/^cut_/",$name)){
+ $s_action = "cut";
+ $s_entry = preg_replace("/^cut_([0-9]*)_.*$/","\\1",$name);
+ break;
+ }
+ if(preg_match("/^copy_/",$name)){
+ $s_action = "copy";
+ $s_entry = preg_replace("/^copy_([0-9]*)_.*$/","\\1",$name);
+ break;
+ }
+ if(preg_match("/^license_edit_/",$name)){
+ $s_action = "edit";
+ $s_entry = preg_replace("/^license_edit_([0-9]*)_.*$/","\\1",$name);
+ break;
+ }
+ if(preg_match("/^license_del_/",$name)){
+ $s_action = "remove";
+ $s_entry = preg_replace("/^license_del_([0-9]*)_.*$/","\\1",$name);
+ break;
+ }
+ }
+
+ if(isset($_GET['act']) && $_GET['act'] == "edit_entry" && isset($_GET['id'])){
+ $id = $_GET['id'];
+ if(isset($this->licenses[$id])){
+ $s_action = "edit";
+ $s_entry = $id;
+ }
+ }
+
+ // Get menu related posts
+ if(isset($_POST['menu_action'])) {
+ if($_POST['menu_action'] == "editPaste"){
+ $s_action = "editPaste";
+ }elseif($_POST['menu_action'] == "license_new"){
+ $s_action = "new";
+ }elseif($_POST['menu_action'] == "remove_multiple_licenses"){
+ $s_action = "remove_multiple";
+ }
+ }
+
+ /***************
+ * Copy & Paste handling
+ ***************/
+
+ /* Display the copy & paste dialog, if it is currently open */
+ $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
+ if($ret){
+ return($ret);
+ }
+
+
+ /***************
+ * Remove handling
+ ***************/
+
+ if($s_action == "remove_multiple" || $s_action == "remove"){
+
+ if($s_action == "remove_multiple"){
+ $ids = $this->list_get_selected_items();
+ }else{
+ $ids = array($s_entry);
+ }
+
+ if(count($ids)){
+ $this->dns = array();
+ $disallowed = array();
+ foreach($ids as $id){
+ $dn = $this->licenses[$id]['dn'];
+ $acl = $this->ui->get_permissions($dn, "licenses/licenseGeneric");
+ if(preg_match("/d/",$acl)){
+ $this->dns[$id] = $dn;
+ }else{
+ $disallowed[] = $dn;
+ }
+ }
+
+ if(count($disallowed)){
+ msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
+ }
+
+
+ if(count($this->dns)){
+ if ($user= get_multiple_locks($this->dns)){
+ return(gen_locked_message($user,$this->dns));
+ }
+ $dns_names = array();
+ foreach($this->dns as $dn){
+ $dns_names[] = LDAP::fix($dn);
+ }
+
+ /* Lock the current entry, so nobody will edit it during deletion */
+ add_lock ($this->dns, $this->ui->dn);
+
+ $smarty->assign("info", msgPool::deleteInfo($dns_names,_("Role")));
+ $smarty->assign("multiple", true);
+ return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+ }
+ }
+ }
+
+
+ /* Remove lock */
+ if(isset($_POST['delete_multiple_licenses_cancel'])){
+
+ /* Remove lock file after successfull deletion */
+ $this->remove_lock();
+ $this->dns = array();
+ }
+
+
+ /* Confirmation for deletion has been passed. Users should be deleted. */
+ if (isset($_POST['delete_multiple_licenses_confirm'])){
+
+ /* Remove user by user and check acls before removeing them */
+ foreach($this->dns as $key => $dn){
+
+ $acl = $this->ui->get_permissions($dn, "licenses/licenseGeneric");
+ if (preg_match('/d/', $acl)){
+
+ /* Delete request is permitted, perform LDAP action */
+ $this->dialog= new licensetabs($this->config,$this->config->data['TABS']['LICENSETABS'], $dn);
+ $this->dialog->delete();
+ $this->dialog= NULL;
+ } else {
+
+ /* Normally this shouldn't be reached, send some extra
+ logs to notify the administrator */
+ msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
+ new log("security","licenses/".get_class($this),$dn,array(),"Tried to trick deletion.");
+ }
+ }
+
+ /* Remove lock file after successfull deletion */
+ $this->remove_lock();
+ $this->dns = array();
+ }
+
+
+ /***************
+ * New handling
+ ***************/
+
+ if($s_action == "new" && !$this->dialog instanceOf tabs){
+ $this->dialog = new licensetabs($this->config, $this->config->data['TABS']['LICENSETABS'], "new");
+ $this->dialog->set_acl_base($this->DivListLicenses->selectedBase);
+ }
+
+ /***************
+ * Edit handling
+ ***************/
+
+ if($s_action == "edit" && !$this->dialog instanceOf tabs){
+ if(!isset($this->licenses[$s_entry])){
+ trigger_error("Unknown entry!");
+ }else{
+
+ $entry = $this->licenses[$s_entry];
+ $this->dn = $entry['dn'];
+
+ /* Check locking, save current plugin in 'back_plugin', so
+ the dialog knows where to return. */
+ if (($user= get_lock($this->dn)) != ""){
+ return(gen_locked_message ($user, $this->dn,TRUE));
+ }
+
+ /* Lock the current entry, so everyone will get the above dialog */
+ add_lock ($this->dn, $this->ui->dn);
+
+ /* Open the dialog */
+ $this->dialog = new licensetabs($this->config, $this->config->data['TABS']['LICENSETABS'],
+ $entry['dn'], "licenses");
+ $this->dialog->set_acl_base($this->dn);
+ set_object_info($this->dn);
+ }
+ }
+
+
+ /***************
+ * Dialog handling
+ ***************/
+
+ if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && $this->dialog instanceOf tabs){
+ $this->dialog->save_object();
+ $msgs = $this->dialog->check();
+ if(count($msgs)){
+ msg_dialog::displayChecks($msgs);
+ }else{
+ $this->dialog->save();
+ if (!isset($_POST['edit_apply'])){
+ $this->remove_lock();
+ $this->dialog= NULL;
+ set_object_info();
+ }else{
+ $this->dialog->re_init();
+ }
+ }
+ }
+
+ if (isset($_POST['edit_cancel']) && $this->dialog instanceOf tabs){
+ $this->remove_lock();
+ $this->dialog= NULL;
+ set_object_info();
+ }
+
+ if($this->dialog instanceOf tabs){
+ $display= $this->dialog->execute();
+
+ $dialog_opened = ($this->dialog->by_object[$this->dialog->current]->dialog instanceOf plugin);
+
+ if(!$dialog_opened){
+ if($this->dialog->read_only == TRUE){
+ $display.= "<p style=\"text-align:right\">
+ <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
+ </p>";
+ }else{
+
+ $display.= "<p style=\"text-align:right\">\n";
+ $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\"
+ value=\"".msgPool::okButton(). "\">\n";
+ $display.= " \n";
+ if ($this->dn != "new"){
+ $display.= "<input type=submit name=\"edit_apply\"
+ value=\"".msgPool::applyButton()."\">\n";
+ $display.= " \n";
+ }
+ $display.= "<input type=submit name=\"edit_cancel\"
+ value=\"".msgPool::cancelButton()."\">\n";
+ $display.= "</p>";
+ }
+ }
+ return ($display);
+ }
+
+
+ /***************
+ * List handling
+ ***************/
+
+ // Check if there is a snapshot dialog open
+ $base = $this->DivListLicenses->selectedBase;
+ if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
+ return($str);
+ }
+
+ // Display dialog with group list
+ $this->DivListLicenses->parent = $this;
+ $this->DivListLicenses->execute();
+
+ // Add departments if subsearch is disabled
+ if(!$this->DivListLicenses->SubSearch){
+ $this->DivListLicenses->AddDepartments($this->DivListLicenses->selectedBase,3,1);
+ }
+ $this->reload ();
+ $this->DivListLicenses->setEntries($this->licenses);
+ return($this->DivListLicenses->Draw());
+ }
+
+
+ // Refreshes the list of known license objects.
+ function reload()
+ {
+
+ // Get current ldap base and filter settings.
+ $base = $this->DivListLicenses->selectedBase;
+ $Regex = $this->DivListLicenses->Regex;
+
+ // Search and fetch all matching license objects.
+ $this->licenses = array();
+ $ldap = $this->config->get_ldap_link();
+ $filter= "(&(objectClass=organizationalRole)(cn=$Regex))";
+ $attrs = array("cn","description","objectClass");
+
+ if($this->DivListLicenses->SubSearch){
+ $res= get_sub_list($filter, "licenses",array(), $base, $attrs, GL_SIZELIMIT | GL_SUBSEARCH);
+ }else{
+ $res= get_sub_list($filter, "licenses",get_ou('licenseRDN'), get_ou('licenseRDN').$base, $attrs, GL_SIZELIMIT );
+ }
+
+ $tmp = array();
+ foreach($res as $attrs){
+ $tmp[$attrs['cn'][0].$attrs['dn']] = $attrs;
+ }
+
+ uksort($tmp, 'strnatcasecmp');
+ $this->licenses = array_values($tmp);
+ }
+
+
+ /* \brief Returns a list of selected entry ids.
+ * E.g. remove multiple entries.
+ * @return Array A list of entry IDs
+ */
+ function list_get_selected_items()
+ {
+ $ids = array();
+ foreach($_POST as $name => $value){
+ if(preg_match("/^item_selected_[0-9]*$/",$name)){
+ $id = preg_replace("/^item_selected_/","",$name);
+ $ids[$id] = $id;
+ }
+ }
+ return($ids);
+ }
+
+
+ function remove_lock()
+ {
+ if (isset($this->dialog->dn)){
+ del_lock ($this->dialog->dn);
+ }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+ del_lock($this->dn);
+ }
+ if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+ del_lock($this->dns);
+ }
+ }
+
+
+ /* Return departments, that will be included within snapshot detection
+ */
+ function get_used_snapshot_bases()
+ {
+ return(array(get_ou('licenseRDN').$this->DivListLicenses->selectedBase));
+ }
+
+
+ function copyPasteHandling_from_queue($s_action,$s_entry)
+ {
+ /* Check if Copy & Paste is disabled */
+ if(!is_object($this->CopyPasteHandler)){
+ return("");
+ }
+
+ $ui = get_userinfo();
+
+ /* Add a single entry to queue */
+ if($s_action == "cut" || $s_action == "copy"){
+
+ /* Cleanup object queue */
+ $this->CopyPasteHandler->cleanup_queue();
+ $dn = $this->licenses[$s_entry]['dn'];
+ if($s_action == "copy" && $ui->is_copyable($dn,"licenses","licenseGeneric")){
+ $this->CopyPasteHandler->add_to_queue($dn,$s_action,"licensetabs","LICENSETABS","licenses");
+ }
+ if($s_action == "cut" && $ui->is_cutable($dn,"licenses","licenseGeneric")){
+ $this->CopyPasteHandler->add_to_queue($dn,$s_action,"licensetabs","LICENSETABS","licenses");
+ }
+ }
+
+ /* Add entries to queue */
+ if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
+
+ /* Cleanup object queue */
+ $this->CopyPasteHandler->cleanup_queue();
+
+ /* Add new entries to CP queue */
+ foreach($this->list_get_selected_items() as $id){
+ $dn = $this->licenses[$id]['dn'];
+
+ if($s_action == "copy_multiple" && $ui->is_copyable($dn,"licenses","licenseGeneric")){
+ $this->CopyPasteHandler->add_to_queue($dn,"copy","licensetabs","LICENSETABS","licenses");
+ }
+ if($s_action == "cut_multiple" && $ui->is_cutable($dn,"licenses","licenseGeneric")){
+ $this->CopyPasteHandler->add_to_queue($dn,"cut","licensetabs","LICENSETABS","licenses");
+ }
+ }
+ }
+
+ /* Start pasting entries */
+ if($s_action == "editPaste"){
+ $this->start_pasting_copied_objects = TRUE;
+ }
+
+ /* Return C&P dialog */
+ if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
+
+ /* Get dialog */
+ $this->CopyPasteHandler->SetVar("base",$this->DivListLicenses->selectedBase);
+ $data = $this->CopyPasteHandler->execute();
+
+ /* Return dialog data */
+ if(!empty($data)){
+ return($data);
+ }
+ }
+ /* Automatically disable status for pasting */
+ if(!$this->CopyPasteHandler->entries_queued()){
+ $this->start_pasting_copied_objects = FALSE;
+ }
+ return("");
+ }
+
+
+ function save_object()
+ {
+ $this->DivListLicenses->save_object();
+ if(is_object($this->CopyPasteHandler)){
+ $this->CopyPasteHandler->save_object();
+ }
+ }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/generic.tpl b/gosa-plugins/opsi/admin/opsiLicenses/generic.tpl
index 3f74097fe258c7b3d2ff7774ed299b38b9ddb3f9..bdf10f45722290b4a6be77ea11bb66619c4e64f4 100644 (file)
<tr>
<td style='width:50%; vertical-align:top; border-right:1px solid #A0A0A0; padding-right:10px;'>
- <h2><img src='plugins/rolemanagement/images/role.png' alt='' class='center'>
+ <h2><img src='plugins/licensemanagement/images/license.png' alt='' class='center'>
{t}Generic{/t}
</h2>
</td>
<td style=' vertical-align:top; padding-left:10px;'>
- <h2><img src='plugins/rolemanagement/images/occupant.png' alt='' class='center'>
+ <h2><img src='plugins/licensemanagement/images/occupant.png' alt='' class='center'>
{t}Occupants{/t}
</h2>
-{render acl=$roleOccupantACL}
+{render acl=$licenseOccupantACL}
<select style="width:100%; height:450px;" id="members" name="members[]" size="15" multiple>
{$members}
</select>
{/render}
<br>
-{render acl=$roleOccupantACL}
+{render acl=$licenseOccupantACL}
<input type=submit value="{msgPool type=addButton}" name="edit_membership">
{/render}
-{render acl=$roleOccupantACL}
+{render acl=$licenseOccupantACL}
<input type=submit value="{msgPool type=delButton}" name="delete_membership">
{/render}
</td>
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/main.inc b/gosa-plugins/opsi/admin/opsiLicenses/main.inc
index 03a0f1c5ca3ab599809a69b8139a9442875748c2..9ace47e5802b7aeb894d2e7bfbe0b5388c7a8793 100644 (file)
/* Page header*/
if (get_object_info() != ""){
- $display= print_header(get_template_path('plugins/rolemanagement/images/plugin.png'),
- _("Roles"),
+ $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'),
+ _("Licenses"),
"<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png')."\"> ".
LDAP::fix(get_object_info()));
} else {
- $display= print_header(get_template_path('plugins/rolemanagement/images/plugin.png'), _("Role management"));
+ $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'), _("Role management"));
}
$display.= $output;