summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0547824)
raw | patch | inline | side by side (parent: 0547824)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 9 Oct 2007 10:17:18 +0000 (10:17 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 9 Oct 2007 10:17:18 +0000 (10:17 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7465 594d385d-05f5-0310-b6e9-bd551577e9d8
plugins/admin/devices/class_deviceGeneric.inc | [new file with mode: 0644] | patch | blob |
plugins/admin/devices/class_deviceManagement.inc | [new file with mode: 0644] | patch | blob |
plugins/admin/devices/class_divListDevices.inc | [new file with mode: 0755] | patch | blob |
plugins/admin/devices/deviceGeneric.tpl | [new file with mode: 0644] | patch | blob |
plugins/admin/devices/main.inc | [new file with mode: 0755] | patch | blob |
plugins/admin/devices/paste_deviceGeneric.tpl | [new file with mode: 0644] | patch | blob |
plugins/admin/devices/remove.tpl | [new file with mode: 0755] | patch | blob |
plugins/admin/devices/tabs_devices.inc | [new file with mode: 0755] | patch | blob |
diff --git a/plugins/admin/devices/class_deviceGeneric.inc b/plugins/admin/devices/class_deviceGeneric.inc
--- /dev/null
@@ -0,0 +1,214 @@
+<?php
+
+class deviceGeneric extends plugin
+{
+ public $dn = "";
+ public $cn = "";
+ public $orig_cn = "";
+ public $description = "";
+ public $vendor = "";
+ public $dev_id = "";
+ public $serial = "";
+ public $base = "";
+
+ public $posts = array("description","dev_id","serial","vendor");
+ public $attributes = array("cn");
+ public $objectclasses = array("top","gotoDevice");
+
+ public $CopyPasteVars = array("orig_cn","description","vendor","dev_id","serial","base");
+
+ public function deviceGeneric(&$config,$dn = NULL)
+ {
+ plugin::plugin($config,$dn);
+
+ $this->is_account = TRUE;
+
+ /* Set class values */
+ if(isset($this->attrs['gotoHotplugDevice'][0])){
+ $tmp = preg_split("/\|/",$this->attrs['gotoHotplugDevice'][0]);
+ $this->cn = $this->attrs['cn'][0];
+ $this->description= $tmp[0];
+ $this->dev_id = $tmp[1];
+ $this->serial = $tmp[2];
+ $this->vendor = $tmp[3];
+ }
+
+ $this->orig_cn = $this->cn;
+
+ /* Set Base */
+ if ($this->dn == "new"){
+ if(isset($_SESSION['CurrentMainBase'])){
+ $this->base= $_SESSION['CurrentMainBase'];
+ }else{
+ $ui= get_userinfo();
+ $this->base= dn2base($ui->dn);
+ }
+ } else {
+ $this->base =preg_replace ("/^[^,]+,ou=devices,/","",$this->dn);
+ }
+ }
+
+
+ public function execute()
+ {
+ $smarty = get_smarty();
+ $smarty->assign("base",$this->base);
+ $smarty->assign("bases",$this->get_allowed_bases());
+ foreach($this->attributes as $attr){
+ $smarty->assign($attr,$this->$attr);
+ }
+ foreach($this->posts as $attr){
+ $smarty->assign($attr,$this->$attr);
+ }
+ return($smarty->fetch(get_template_path("deviceGeneric.tpl",TRUE,dirname(__FILE__))));
+ }
+
+
+ public function check()
+ {
+ $message = plugin::check();
+
+ if(empty($this->cn)||(preg_match("/[^a-z0-9]/i",$this->cn))){
+ $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
+ }
+ if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->description)){
+ $message[]=_("Invalid character in description. Please specify a valid description.");
+ }
+
+ /* Skip serial check if vendor and product id are given */
+ if(empty($this->dev_id) || preg_match("/[\|\*]/i",$this->dev_id)){
+ $message[]=_("Please specify a valid iSerial.");
+ }
+ if(empty($this->serial) || !$this->is_2byteHex($this->serial)){
+ $message[]=_("Please specify a valid vendor ID. (2 byte hex like '0xFFFF')");
+ }
+ if(empty($this->vendor) || !$this->is_2byteHex($this->vendor)){
+ $message[]=_("Please specify a valid product ID. (2 byte hex like '0xFFFF')");
+ }
+
+ /* Check if entry already exists */
+ if($this->cn != $this->orig_cn){
+ $ldap = $this->config->get_ldap_link();
+ $ldap->search("(&(objectClass=gotoDevice)(cn=".$this->cn."*))",array("cn"));
+ if($ldap->count()){
+ $message[]=_("An Entry with this name already exists.");
+ }
+ }
+
+ return($message);
+ }
+
+
+ public function save_object()
+ {
+ if(isset($_POST['deviceGeneric_posted'])){
+ plugin::save_object();
+
+ if(isset($_POST['base'])){
+ $tmp = $this->get_allowed_bases();
+ if(isset($tmp[get_post("base")])){
+ $this->base = get_post("base");
+ }
+ }
+
+ foreach($this->posts as $post){
+ if(isset($_POST[$post])){
+ $this->$post = get_post($post);
+ }
+ }
+ }
+ }
+
+
+ public function save()
+ {
+ plugin::save();
+
+ $this->attrs['gotoHotplugDevice'] = "";
+ foreach($this->posts as $post){
+ $this->attrs['gotoHotplugDevice'] .= $this->$post."|";
+ }
+ $this->attrs['gotoHotplugDevice'] = preg_replace("/\|$/","",$this->attrs['gotoHotplugDevice']);
+
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->cat($this->dn);
+ if($ldap->count()){
+ $ldap->cd($this->dn);
+ $ldap->modify($this->attrs);
+ }else{
+ $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$this->dn));
+ $ldap->cd($this->dn);
+ $ldap->add($this->attrs);
+ }
+ show_ldap_error($ldap->get_error(),_("Device could not be saved."));
+ }
+
+
+ /* check if given str in like this 0xffff*/
+ function is_2byteHex($str)
+ {
+ return !strlen($str) || preg_match("/^(0x|x|)[a-f0-9][a-f0-9][a-f0-9][a-f0-9]/i",$str);
+ }
+
+
+ function PrepareForCopyPaste($source)
+ {
+ plugin::PrepareForCopyPaste($source);
+ $source_o = new deviceGeneric($this->config,$source['dn']);
+ foreach($this->CopyPasteVars as $post){
+ $this->$post = $source_o->$post;
+ }
+ }
+
+
+ /* Return a dialog with all fields that must be changed,
+ if we want to copy this entry */
+ function getCopyDialog()
+ {
+ $str = "";
+ $smarty = get_smarty();
+ $smarty->assign("cn", $this->cn);
+ $str = $smarty->fetch(get_template_path("paste_deviceGeneric.tpl",TRUE,dirname(__FILE__)));
+
+ $ret = array();
+ $ret['string'] = $str;
+ $ret['status'] = "";
+ return($ret);
+ }
+
+
+ /* Save all */
+ function saveCopyDialog()
+ {
+ $attrs = array("cn");
+ foreach($attrs as $attr){
+ if(isset($_POST[$attr])){
+ $this->$attr = $_POST[$attr];
+ }
+ }
+ }
+
+
+
+ /* Return plugin informations for acl handling */
+ public function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Generic"),
+ "plDescription" => _("Device generic"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "plSection" => array("administration"),
+ "plCategory" => array("devices" => array("description" => _("Devices"),
+ "objectClass" => "gotoHotplugDevice")),
+ "plProvidedAcls"=> array(
+ "cn" => _("Name"))
+ ));
+
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/devices/class_deviceManagement.inc b/plugins/admin/devices/class_deviceManagement.inc
--- /dev/null
@@ -0,0 +1,533 @@
+<?php
+
+class deviceManagement extends plugin
+{
+
+ /* Definitions */
+ var $plHeadline = "Devices";
+ var $plDescription = "Manage devices";
+
+ /* Dialog attributes */
+ var $ui = NULL;
+ var $DivListDevices = NULL;
+ var $enableReleaseManagement = false;
+ var $devicetabs = NULL;
+ var $snapDialog = NULL;
+ var $CopyPasteHandler = NULL;
+ var $start_pasting_copied_objects;
+
+ function deviceManagement(&$config, $dn= NULL)
+ {
+ plugin::plugin ($config, $dn);
+ $this->ui = get_userinfo();
+
+ /* Check if copy & paste is activated */
+ if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
+ $this->CopyPasteHandler = new CopyPasteHandler($this->config);
+ }
+
+ /* Creat dialog object */
+ $this->DivListDevices = new divListDevices($this->config,$this);
+ }
+
+
+ function execute()
+ {
+ /* Call parent execute */
+ plugin::execute();
+
+ /****************
+ Variable init
+ ****************/
+
+ /* These vars will be stored if you try to open a locked device,
+ to be able to perform your last requests after showing a warning message */
+ $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^device_edit_/",
+ "/^device_del_/","/^item_selected/","/^remove_multiple_devices/");
+
+ $smarty = get_smarty(); // Smarty instance
+ $s_action = ""; // Contains the action to proceed
+ $s_entry = ""; // The value for s_action
+ $base_back = ""; // The Link for Backbutton
+
+ /* Test Posts */
+ foreach($_POST as $key => $val){
+
+ if(preg_match("/device_del.*/",$key)){
+ $s_action = "del";
+ $s_entry = preg_replace("/device_".$s_action."_/i","",$key);
+ }elseif(preg_match("/device_edit_.*/",$key)){
+ $s_action="edit";
+ $s_entry = preg_replace("/device_".$s_action."_/i","",$key);
+ }elseif(preg_match("/^copy_.*/",$key)){
+ $s_action="copy";
+ $s_entry = preg_replace("/^copy_/i","",$key);
+ }elseif(preg_match("/^cut_.*/",$key)){
+ $s_action="cut";
+ $s_entry = preg_replace("/^cut_/i","",$key);
+ }elseif(preg_match("/^device_new.*/",$key)){
+ $s_action="new";
+ }elseif(preg_match("/^remove_multiple_devices/",$key)){
+ $s_action="del_multiple";
+ }elseif(preg_match("/^editPaste.*/i",$key)){
+ $s_action="editPaste";
+ }elseif(preg_match("/^multiple_copy_devices/",$key)){
+ $s_action = "copy_multiple";
+ }elseif(preg_match("/^multiple_cut_devices/",$key)){
+ $s_action = "cut_multiple";
+ }
+ }
+
+ if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
+ $s_action ="edit";
+ $s_entry = $_GET['id'];
+ }
+
+ $s_entry = preg_replace("/_.$/","",$s_entry);
+
+
+ /****************
+ 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);
+ }
+
+
+ /****************
+ Create a new device type
+ ****************/
+
+ /* New device type? */
+ $ui = get_userinfo();
+ $acl = $ui->get_permissions($this->DivListDevices->selectedBase,"devices/deviceGeneric");
+ if (($s_action=="new") && preg_match("/c/",$acl)){
+
+ /* By default we set 'dn' to 'new', all relevant plugins will
+ react on this. */
+ $this->dn= "new";
+
+ /* Create new usertab object */
+ $this->devicetabs= new devicetabs($this->config, $this->config->data['TABS']['DEVICETABS'], $this->dn,"devices");
+ $this->devicetabs->set_acl_base($this->DivListDevices->selectedBase);
+ }
+
+
+ /****************
+ Edit entry canceled
+ ****************/
+
+ /* Cancel dialogs */
+ if (isset($_POST['edit_cancel'])){
+ del_lock ($this->devicetabs->dn);
+ unset ($this->devicetabs);
+ $this->devicetabs= NULL;
+ unset ($_SESSION['objectinfo']);
+ }
+
+
+ /****************
+ Edit entry finished
+ ****************/
+
+ /* Finish device edit is triggered by the tabulator dialog, so
+ the user wants to save edited data. Check and save at this point. */
+ if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->devicetabs->config))){
+
+ /* Check tabs, will feed message array */
+ $this->devicetabs->save_object();
+ $message= $this->devicetabs->check();
+
+ /* Save, or display error message? */
+ if (count($message) == 0){
+
+ /* Save data data to ldap */
+# $this->devicetabs->set_release($this->DivListDevices->selectedRelease);
+ $this->devicetabs->save();
+
+ if (!isset($_POST['edit_apply'])){
+ /* device type has been saved successfully, remove lock from LDAP. */
+ if ($this->dn != "new"){
+ del_lock ($this->dn);
+ }
+ unset ($this->devicetabs);
+ $this->devicetabs= NULL;
+ unset ($_SESSION['objectinfo']);
+ }
+ } else {
+ /* Ok. There seem to be errors regarding to the tab data,
+ show message and continue as usual. */
+ show_errors($message);
+ }
+ }
+
+
+ /****************
+ Edit entry
+ ****************/
+
+ /* User wants to edit data? */
+ if (($s_action=="edit") && (!isset($this->devicetabs->config))){
+
+ /* Get 'dn' from posted 'devicelist', must be unique */
+ $this->dn= $this->devices[$s_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));
+ }
+
+ /* Lock the current entry, so everyone will get the
+ above dialog */
+ add_lock ($this->dn, $this->ui->dn);
+
+
+ /* Register devicetabs to trigger edit dialog */
+ $this->devicetabs= new devicetabs($this->config,$this->config->data['TABS']['DEVICETABS'], $this->dn,"devices");
+ $this->devicetabs->set_acl_base($this->dn);
+ $_SESSION['objectinfo']= $this->dn;
+ }
+
+
+ /********************
+ Delete MULTIPLE entries requested, display confirm dialog
+ ********************/
+ if ($s_action=="del_multiple"){
+ $ids = $this->list_get_selected_items();
+
+ if(count($ids)){
+
+ foreach($ids as $id){
+ $dn = $this->devices[$id]['dn'];
+ if (($user= get_lock($dn)) != ""){
+ return(gen_locked_message ($user, $dn));
+ }
+ $this->dns[$id] = $dn;
+ }
+
+ $dns_names = "<br><pre>";
+ foreach($this->dns as $dn){
+ add_lock ($dn, $this->ui->dn);
+ $dns_names .= $dn."\n";
+ }
+ $dns_names .="</pre>";
+
+ /* Lock the current entry, so nobody will edit it during deletion */
+ if (count($this->dns) == 1){
+ $smarty->assign("intro", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
+ } else {
+ $smarty->assign("intro", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
+ }
+ $smarty->assign("multiple", true);
+ return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+ }
+ }
+
+
+ /********************
+ Delete MULTIPLE entries confirmed
+ ********************/
+
+ /* Confirmation for deletion has been passed. Users should be deleted. */
+ if (isset($_POST['delete_multiple_device_confirm'])){
+
+ $ui = get_userinfo();
+
+ /* Remove user by user and check acls before removeing them */
+ foreach($this->dns as $key => $dn){
+
+ $acl = $ui->get_permissions($dn,"devices/deviceGeneric");
+ if(preg_match("/d/",$acl)){
+
+ /* Delete request is permitted, perform LDAP action */
+ $this->devicetabs= new devicetabs($this->config, $this->config->data['TABS']['DEVICETABS'], $dn,"devices");
+ $this->devicetabs->set_acl_base($dn);
+ $this->devicetabs->delete ();
+ unset ($this->devicetabs);
+ $this->devicetabs= NULL;
+
+ } else {
+ /* Normally this shouldn't be reached, send some extra
+ logs to notify the administrator */
+ print_red (_("You are not allowed to delete this device type!"));
+ new log("security","devices/".get_class($this),$dn,array(),"Tried to trick deletion.");
+ }
+ /* Remove lock file after successfull deletion */
+ del_lock ($dn);
+ unset($this->dns[$key]);
+ }
+ }
+
+
+ /********************
+ Delete MULTIPLE entries Canceled
+ ********************/
+
+ /* Remove lock */
+ if(isset($_POST['delete_multiple_device_cancel'])){
+ foreach($this->dns as $key => $dn){
+ del_lock ($dn);
+ unset($this->dns[$key]);
+ }
+ }
+
+
+ /****************
+ Delete device type
+ ****************/
+
+ /* Remove user was requested */
+ if ($s_action == "del"){
+
+ /* Get 'dn' from posted 'uid' */
+ $this->dn= $this->devices[$s_entry]['dn'];
+
+ /* Load permissions for selected 'dn' and check if
+ we're allowed to remove this 'dn' */
+ $ui = get_userinfo();
+ $acl = $ui->get_permissions($this->dn,"devices/deviceGeneric");
+ if (preg_match("/d/",$acl)){
+
+ /* 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));
+ }
+
+ /* Lock the current entry, so nobody will edit it during deletion */
+ add_lock ($this->dn, $this->ui->dn);
+ $smarty= get_smarty();
+ $smarty->assign("intro", sprintf(_("You're about to delete the device '%s'."), @LDAP::fix($this->dn)));
+ $smarty->assign("multiple", false);
+ return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
+ } else {
+
+ /* Obviously the user isn't allowed to delete. Show message and
+ clean session. */
+ print_red (_("You are not allowed to delete this device!"));
+ }
+ }
+
+
+ /****************
+ Delete device confirmed
+ ****************/
+
+ /* Confirmation for deletion has been passed. Group should be deleted. */
+ if (isset($_POST['delete_device_confirm'])){
+
+ /* Some nice guy may send this as POST, so we've to check
+ for the permissions again. */
+ $ui = get_userinfo();
+ $acl = $ui->get_permissions($this->dn,"devices/deviceGeneric");
+ if(preg_match("/d/",$acl)){
+
+ /* Delete request is permitted, perform LDAP action */
+ $this->devicetabs= new devicetabs($this->config, $this->config->data['TABS']['DEVICETABS'], $this->dn,"devices");
+ $this->devicetabs->set_acl_base($this->dn);
+ $this->devicetabs->delete ();
+ unset ($this->devicetabs);
+ $this->devicetabs= NULL;
+
+ } else {
+
+ /* Normally this shouldn't be reached, send some extra
+ logs to notify the administrator */
+ print_red (_("You are not allowed to delete this device!"));
+ new log("security","devices/".get_class($this),$dn,array(),"Tried to trick deletion.");
+ }
+
+ /* Remove lock file after successfull deletion */
+ del_lock ($this->dn);
+ }
+
+
+ /****************
+ Delete device canceled
+ ****************/
+
+ /* Delete device canceled? */
+ if (isset($_POST['delete_cancel'])){
+ del_lock ($this->dn);
+ unset($_SESSION['objectinfo']);
+ }
+
+ /* Show tab dialog if object is present */
+ if (($this->devicetabs) && (isset($this->devicetabs->config))){
+ $display= $this->devicetabs->execute();
+
+ /* Don't show buttons if tab dialog requests this */
+ if (!$this->devicetabs->by_object[$this->devicetabs->current]->dialog){
+ $display.= "<p style=\"text-align:right\">\n";
+ $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
+ $display.= " \n";
+ if ($this->dn != "new"){
+ $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
+ $display.= " \n";
+ }
+ $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
+ $display.= "</p>";
+ }
+ return ($display);
+ }
+
+
+ /****************
+ Dialog display
+ ****************/
+
+ /* Check if there is a snapshot dialog open */
+ $base = $this->DivListDevices->selectedBase;
+ if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+ return($str);
+ }
+
+ /* Display dialog with system list */
+ $this->DivListDevices->parent = $this;
+ $this->DivListDevices->execute();
+ $this->DivListDevices->AddDepartments($this->DivListDevices->selectedBase,3,1);
+ $this->reload();
+ $this->DivListDevices->setEntries($this->devices);
+ return($this->DivListDevices->Draw());
+
+ }
+
+ function save_object() {
+ $this->DivListDevices->save_object();
+ }
+
+
+ /* Return departments, that will be included within snapshot detection */
+ function get_used_snapshot_bases()
+ {
+ return(array("ou=devices,".$this->DivListDevices->selectedBase));
+ }
+
+ function copyPasteHandling_from_queue($s_action,$s_entry)
+ {
+ /* Check if Copy & Paste is disabled */
+ if(!is_object($this->CopyPasteHandler)){
+ return("");
+ }
+
+ /* Add a single entry to queue */
+ if($s_action == "cut" || $s_action == "copy"){
+
+ /* Cleanup object queue */
+ $this->CopyPasteHandler->cleanup_queue();
+ $dn = $this->devices[$s_entry]['dn'];
+ $this->CopyPasteHandler->add_to_queue($dn,$s_action,"devicetabs","DEVICETABS","devices");
+ }
+
+ /* 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->devices[$id]['dn'];
+
+ if($s_action == "copy_multiple"){
+ $this->CopyPasteHandler->add_to_queue($dn,"copy","devicetabs","DEVICETABS","devices");
+ }
+ if($s_action == "cut_multiple"){
+ $this->CopyPasteHandler->add_to_queue($dn,"cut","devicetabs","DEVICETABS","devices");
+ }
+ }
+ }
+
+ /* 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()){
+
+ /* Load entry from queue and set base */
+ $this->CopyPasteHandler->load_entry_from_queue();
+ $this->CopyPasteHandler->SetVar("base",$this->DivListDevices->selectedBase);
+
+ /* Get dialog */
+ $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 reload()
+ {
+ /* Set base for all searches */
+ $base = $this->DivListDevices->selectedBase;
+ $Regex = $this->DivListDevices->Regex;
+ $SubSearch = $this->DivListDevices->SubSearch;
+ $Flags = GL_NONE | GL_SIZELIMIT;
+ $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=gotoDevice))";
+ $tmp = array();
+
+ /* In case of subsearch, add the subsearch flag */
+ if($SubSearch){
+ $Flags |= GL_SUBSEARCH;
+ }else{
+ $base ="ou=devices,".$base;
+ }
+
+ /* Get results and create index */
+ $res= get_list($Filter, "devices", $base, array("cn","description","dn","objectClass"), $Flags);
+ foreach ($res as $val){
+ $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
+ }
+
+ /* sort entries */
+ ksort($tmp);
+ $this->devices=array();
+ foreach($tmp as $val){
+ $this->devices[]=$val;
+ }
+ reset ($this->devices);
+ }
+
+ function remove_lock()
+ {
+ if (isset($this->devicetabs->dn)){
+ del_lock ($this->devicetabs->dn);
+ }
+ }
+
+ 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_from_parent()
+ {
+ /* This cannot be removed... */
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/devices/class_divListDevices.inc b/plugins/admin/devices/class_divListDevices.inc
--- /dev/null
@@ -0,0 +1,307 @@
+<?php
+
+class divListDevices extends MultiSelectWindow
+{
+ /* Current base */
+ var $selectedBase = "";
+ var $departments = array();
+ var $parent ;
+ var $ui ;
+
+ /* Regex */
+ var $Regex = "*";
+
+ /* Subsearch checkbox */
+ var $SubSearch;
+
+ function divListDevices (&$config, &$parent)
+ {
+ /* Create divlist and setup */
+ MultiSelectWindow::MultiSelectWindow($config, "Devices", "devices");
+
+ /* initialize required attributes */
+ $this->parent = &$parent;
+ $this->ui = get_userinfo();
+
+ /* set Page header */
+ $action_col_size = 80;
+ if($this->parent->snapshotEnabled()){
+ $action_col_size += 38;
+ }
+
+ /* Set list strings */
+ $this->SetTitle (_("List of defined devices"));
+ $this->SetSummary (_("List of defined devices"));
+ $this->SetInformation (_("This menu allows you to add, edit and remove selected devices. You may want to use the range selector on top of the device listbox, when working with a large number of devices."));
+
+ /* Result page will look like a headpage */
+ $this->SetHeadpageMode();
+ $this->EnableAplhabet(true);
+
+ /* Disable buttonsm */
+ $this->EnableCloseButton(false);
+ $this->EnableSaveButton (false);
+
+ /* Toggle all selected / deselected */
+ $chk = "<input type='checkbox' id='select_all' name='select_all'
+ onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
+ /* set Page header */
+ $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
+ $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
+ $this->AddHeader(array("string" => _("Device name")." / "._("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("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
+
+ /* Name ,Text ,Default , Connect with alphabet */
+ $this->AddRegex ("Regex", _("Display devices matching"),"*" , true);
+ }
+
+
+ /* Create list header, with create / copy & paste etc*/
+ function GenHeader()
+ {
+ /* Prepare departments,
+ which are shown in the listbox on top of the listbox
+ */
+ $options= "";
+
+ /* Get all departments within this subtree */
+ $ui= get_userinfo();
+ $first = "";
+ $found = FALSE;
+ $base = $this->config->current['BASE'];
+
+ /* Add base */
+ $tmp = array();
+ $tmp[] = array("dn"=>$this->config->current['BASE']);
+ $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+ array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
+
+ $deps = array();
+ foreach($tmp as $tm){
+ $deps[$tm['dn']] = $tm['dn'];
+ }
+
+ /* Load possible departments */
+ $ui= get_userinfo();
+ $tdeps= $ui->get_module_departments($this->module);
+ $ids = $this->config->idepartments;
+ $first = "";
+ $found = FALSE;
+ foreach($ids as $dep => $name){
+ if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
+
+ /* Keep first base dn in mind, we could need this
+ * info if no valid base was found
+ */
+ if(empty($first)) {
+ $first = $dep['dn'];
+ }
+
+ $value = $ids[$dep];
+ if ($this->selectedBase == $dep){
+ $found = TRUE;
+ $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+ } else {
+ $options.= "<option value='".$dep."'>$value</option>";
+ }
+ }
+ }
+
+ /* The currently used base is not visible with your acl setup.
+ * Set base to first useable base.
+ */
+ if(!$found){
+ $this->selectedBase = $first;
+ }
+
+ /* Get acls */
+ $ui = get_userinfo();
+ $acl = $ui->get_permissions("cn=dummy,ou=devices,".$this->selectedBase,"devices/deviceGeneric");
+ $acl_all = $ui->has_complete_category_acls($this->selectedBase,"devices") ;
+
+
+ /* If this is true we add an additional seperator. Just look a few lines below */
+ $add_sep = false;
+
+ /* Get copy & paste icon */
+ $Copy_Paste ="";
+ if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
+ $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
+ $add_sep = true;
+ }
+
+ /* Add default header */
+ $listhead = MultiSelectWindow::get_default_header();
+
+ /* Create snapshot icons */
+ if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+ $listhead .= $this->get_snapshot_header($this->selectedBase);
+ $add_sep = true;
+ }
+
+ /* Add create icon */
+ if(preg_match("/c/",$acl)){
+ $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_device.png' alt='"._("new").
+ "' title='"._("Create new device")."' name='device_new'> ";
+ $add_sep = true;
+ }
+
+ /* Add copy & paste icons */
+ $listhead .= $Copy_Paste;
+
+ /* Add a seperator ? */
+ if($add_sep) {
+ $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
+ }
+
+ /* And at least add a department selection box */
+ $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
+ " <input class='center' type='image' src='images/list_submit.png' align='middle'
+ title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
+
+ /* Multiple options */
+ $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
+ title='"._("Remove selected device")."' alt='"._("Remove device")."' name='remove_multiple_devices'> ";
+
+ /* Add multiple copy & cut icons */
+ if(is_object($this->parent->CopyPasteHandler)){
+ $listhead .= " <input class='center' type='image' align='middle' src='images/editcopy.png'
+ title='"._("Copy selected object")."' alt='"._("Copy object")."' name='multiple_copy_devices'> ";
+ $listhead .= " <input class='center' type='image' align='middle' src='images/editcut.png'
+ title='"._("cut selected object")."' alt='"._("Cut object")."' name='multiple_cut_devices'> ";
+ }
+
+ $listhead .="</div>";;
+
+ $this->SetListHeader($listhead);
+ }
+
+
+ /* Some basic settings */
+ function execute()
+ {
+ $this->ClearElementsList();
+ $this->GenHeader();
+ }
+
+
+ function setEntries($list)
+ {
+ /********************
+ Variable init
+ ********************/
+
+ /* Create links */
+ $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
+ $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
+ $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
+ $deviceimg = "<img class='center' src='images/select_device.png' alt='A' title='"._("Device")."'>";
+ $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
+
+ /* set Page header */
+ $action_col_size = 80;
+ if($this->parent->snapshotEnabled()){
+ $action_col_size += 38;
+ }
+
+ /********************
+ Attach objects
+ ********************/
+
+ foreach($list as $key => $val){
+
+ $ui = get_userinfo();
+ $acl = $ui->get_permissions($val['dn'],"devices/deviceGeneric");
+ $acl_all = $ui->has_complete_category_acls($val['dn'],"devices") ;
+
+ /* Create action icons */
+ $actions = "";
+ if(preg_match("/(c.*w|w.*c)/",$acl_all)){
+ $actions .= $this->GetSnapShotActions($val['dn']);
+ }
+
+ /* Get copy Paste icons */
+ if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
+ $actions.= "<input class='center' type='image'
+ src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
+ $actions.= "<input class='center' type='image'
+ src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
+ }
+
+ $actions.= "<input class='center' type='image'
+ src='images/edit.png' alt='"._("edit")."' name='device_edit_%KEY%' title='"._("Edit this entry")."'>";
+
+ /* Add delete button */
+ if(preg_match("/d/",$acl)){
+ $actions.= "<input class='center' type='image'
+ src='images/edittrash.png' alt='"._("delete")."' name='device_del_%KEY%' title='"._("Delete this entry")."'>";
+ }else{
+ $actions.= "<img src='images/empty.png' alt=' ' class='center'>";
+ }
+
+ $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
+
+ if(!isset($val['description'][0])){
+ $desc = "";
+ }else{
+ $desc = " - [ ".$val['description'][0]." ]";
+ }
+
+ /* Cutted objects should be displayed in light grey */
+ $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;
+ }
+ }
+ }
+
+
+ /* Create each field */
+ $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+ "attach" => "style='width:20px;'");
+ $field1 = array("string" => sprintf($deviceimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
+ $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
+ $field3 = 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,$field3));
+ }
+
+
+ /* Create summary string for list footer */
+ $num_deps=0;
+ if(!$this->SubSearch){
+ $num_deps = count($this->Added_Departments);
+ }
+ $num_objs = count($list);
+
+ $num_obj_str = _("Number of listed devices");
+ $num_dep_str = _("Number of listed departments");
+
+ $str = "<img class='center' src='images/select_devices.png'
+ title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
+ $str.= "<img class='center' src='images/folder.png'
+ title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
+
+ $this->set_List_Bottom_Info($str);
+ }
+
+ function Save()
+ {
+ MultiSelectWindow::Save();
+ }
+
+ function save_object()
+ {
+ /* Save automatic created POSTs like regex, checkboxes */
+ MultiSelectWindow::save_object();
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/devices/deviceGeneric.tpl b/plugins/admin/devices/deviceGeneric.tpl
--- /dev/null
@@ -0,0 +1,66 @@
+
+<h2>{t}Devices{/t}</h2>
+
+<table width="100%" summary="">
+ <tr>
+ <td width="50%" style="vertical-align:top">
+ <table style="border-right:1px solid #B0B0B0;width:100%">
+ <tr>
+ <td><LABEL for="base">{t}Base{/t}</LABEL>
+ </td>
+ <td>
+ <select name="base">
+ {html_options options=$bases selected=$base}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td><LABEL for="cn">{t}Device name{/t}</LABEL>{$must}
+ </td>
+ <td>
+ <input type="text" size=40 value="{$cn}" name="cn" id="cn">
+ </td>
+ </tr>
+ <tr>
+ <td><LABEL for="description">{t}Description{/t}</LABEL>
+ </td>
+ <td>
+ <input type="text" size=40 value="{$description}" name="description" id="description">
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td style="vertical-align:top">
+ <table summary="">
+ <tr>
+ <td><LABEL for="dev_id">{t}Serial number{/t} {t}(iSerial){/t}</LABEL>{$must}
+ </td>
+ <td>
+ <input type="text" value="{$dev_id}" name="dev_id" id="dev_id">
+ </td>
+ <td colspan="2"> </td>
+ </tr>
+ <tr>
+ <td><LABEL for="vendor">{t}Vendor-ID{/t} {t}(idVendor){/t}</LABEL>{$must}
+ </td>
+ <td>
+ <input type="text" value="{$vendor}" name="vendor" id="vendor">
+ </td>
+ </tr>
+ <tr>
+ <td><LABEL for="produkt">{t}Product-ID{/t} {t}(idProduct){/t}</LABEL>{$must}
+ </td>
+ <td>
+ <input type="text" value="{$serial}" name="serial" id="serial">
+ </td>
+ </tr>
+ </table>
+</table>
+<input type='hidden' value="1" name="deviceGeneric_posted">
+<script language="JavaScript" type="text/javascript">
+ <!-- // First input field on page
+ focus_field('name');
+ -->
+</script>
+
+
diff --git a/plugins/admin/devices/main.inc b/plugins/admin/devices/main.inc
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2003 Cajus Pollmeier
+
+ 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
+ */
+
+if ($remove_lock){
+ if(isset($_SESSION['DeviceManagement'])){
+ $DeviceManagement= $_SESSION['DeviceManagement'];
+ $DeviceManagement->remove_lock();
+ del_lock ($ui->dn);
+ sess_del ('DeviceManagement');
+ }
+} else {
+
+ /* Create DeviceManagement object on demand */
+ if (!isset($_SESSION['DeviceManagement']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
+ $_SESSION['DeviceManagement']= new deviceManagement ($config, $_SESSION['ui']);
+ }
+
+ /* Get object */
+ $DeviceManagement= $_SESSION['DeviceManagement'];
+ $DeviceManagement->save_object();
+ $output= $DeviceManagement->execute();
+
+ /* Page header*/
+ if (isset($_SESSION['objectinfo'])){
+ $display= print_header(get_template_path('images/device.png'), _("Device management"), "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png')."\"> ".@LDAP::fix($_SESSION['objectinfo']));
+ } else {
+ $display= print_header(get_template_path('images/device.png'), _("Device management"));
+ }
+
+ /* Reset requested? */
+ if (isset($_GET['reset']) && $_GET['reset'] == 1){
+ del_lock ($ui->dn);
+ sess_del ('DeviceManagement');
+ }
+
+ /* Show and save dialog */
+ $display.= $output;
+ $_SESSION['DeviceManagement']= $DeviceManagement;
+}
+?>
diff --git a/plugins/admin/devices/paste_deviceGeneric.tpl b/plugins/admin/devices/paste_deviceGeneric.tpl
--- /dev/null
@@ -0,0 +1,25 @@
+
+<h2>{t}Devices{/t}</h2>
+
+<table width="100%" summary="">
+ <tr>
+ <td width="50%" style="vertical-align:top">
+ <table style="border-right:1px solid #B0B0B0;width:100%">
+ <tr>
+ <td><LABEL for="cn">{t}Device name{/t}</LABEL>{$must}
+ </td>
+ <td>
+ <input type="text" size=40 value="{$cn}" name="cn" id="cn">
+ </td>
+ </tr>
+ </table>
+ </td>
+</table>
+<input type='hidden' value="1" name="deviceGeneric_posted">
+<script language="JavaScript" type="text/javascript">
+ <!-- // First input field on page
+ focus_field('name');
+ -->
+</script>
+
+
diff --git a/plugins/admin/devices/remove.tpl b/plugins/admin/devices/remove.tpl
--- /dev/null
@@ -0,0 +1,23 @@
+<div style="font-size:18px;">
+ <img alt="" src="images/button_cancel.png" align=top> {t}Warning{/t}
+</div>
+<p>
+ {$intro}
+ {t}This may be used by several users/groups. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t}
+</p>
+<p>
+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t}
+</p>
+
+<p class="plugbottom">
+ {if $multiple}
+ <input type=submit name="delete_multiple_device_confirm" value="{t}Delete{/t}">
+
+ <input type=submit name="delete_multiple_device_cancel" value="{t}Cancel{/t}">
+ {else}
+ <input type=submit name="delete_device_confirm" value="{t}Delete{/t}">
+
+ <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+ {/if}
+</p>
+
diff --git a/plugins/admin/devices/tabs_devices.inc b/plugins/admin/devices/tabs_devices.inc
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+class devicetabs extends tabs
+{
+ var $Release= "";
+
+ function devicetabs($config, $data, $dn,$category)
+ {
+ tabs::tabs($config, $data, $dn,$category);
+
+ /* Add references/acls/snapshots */
+ $this->addSpecialTabs();
+ }
+
+ function save($ignore_account= FALSE)
+ {
+ $baseobject= $this->by_object['deviceGeneric'];
+ $new_dn= "cn=".$baseobject->cn.",ou=devices,".$baseobject->base;
+
+ /* Move group? */
+ if ($this->dn != $new_dn){
+
+ /* Write entry on new 'dn' */
+ if ($this->dn != "new"){
+ $baseobject->move($this->dn, $new_dn);
+ $this->by_object['deviceGeneric']= $baseobject;
+ }
+
+ /* Happen to use the new one */
+ $this->dn= $new_dn;
+ }
+
+ tabs::save();
+
+ /* Fix tagging if needed */
+ $baseobject->dn= $this->dn;
+ $baseobject->handle_object_tagging();
+ $this->by_object['deviceGeneric'] = $baseobject;
+ }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>