From: hickert Date: Tue, 9 Oct 2007 10:17:18 +0000 (+0000) Subject: Added device Management X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=560cf6941c534d5ae854f578827c88f446e5551a;p=gosa.git Added device Management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7465 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/devices/class_deviceGeneric.inc b/plugins/admin/devices/class_deviceGeneric.inc new file mode 100644 index 000000000..4ed86e7f2 --- /dev/null +++ b/plugins/admin/devices/class_deviceGeneric.inc @@ -0,0 +1,214 @@ +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 new file mode 100644 index 000000000..93083f58d --- /dev/null +++ b/plugins/admin/devices/class_deviceManagement.inc @@ -0,0 +1,533 @@ +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 = "
";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="
"; + + /* 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.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

"; + } + 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 new file mode 100755 index 000000000..d95c65da6 --- /dev/null +++ b/plugins/admin/devices/class_divListDevices.inc @@ -0,0 +1,307 @@ +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 = ""; + + /* 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.= ""; + } else { + $options.= ""; + } + } + } + + /* 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 .= "  "; + $add_sep = true; + } + + /* Add copy & paste icons */ + $listhead .= $Copy_Paste; + + /* Add a seperator ? */ + if($add_sep) { + $listhead .= "  "; + } + + /* And at least add a department selection box */ + $listhead .= _("Base")." ". + "  "; + + /* Multiple options */ + $listhead .= "  "; + + /* Add multiple copy & cut icons */ + if(is_object($this->parent->CopyPasteHandler)){ + $listhead .= "  "; + $listhead .= "  "; + } + + $listhead .="";; + + $this->SetListHeader($listhead); + } + + + /* Some basic settings */ + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + } + + + function setEntries($list) + { + /******************** + Variable init + ********************/ + + /* Create links */ + $linkopen = "%s"; + $editlink = "%s"; + $userimg = "User"; + $deviceimg = "A"; + $empty = ""; + + /* 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.= " "; + $actions.= " "; + } + + $actions.= ""; + + /* Add delete button */ + if(preg_match("/d/",$acl)){ + $actions.= ""; + }else{ + $actions.= " "; + } + + $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 = "".$display.""; + break; + } + } + } + + + /* Create each field */ + $field0 = array("string" => "" , + "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 = "".$num_obj_str." ".$num_objs."    "; + $str.= "".$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 new file mode 100644 index 000000000..59f7b9c18 --- /dev/null +++ b/plugins/admin/devices/deviceGeneric.tpl @@ -0,0 +1,66 @@ + +

{t}Devices{/t}

+ + + + +
+ + + + + + + + + + + + + +
+ + +
{$must} + + +
+ + +
+
+ + + + + + + + + + + + + + +
{$must} + + +  
{$must} + + +
{$must} + + +
+
+ + + + diff --git a/plugins/admin/devices/main.inc b/plugins/admin/devices/main.inc new file mode 100755 index 000000000..53cd73c61 --- /dev/null +++ b/plugins/admin/devices/main.inc @@ -0,0 +1,57 @@ +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"), "\"\" ".@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 new file mode 100644 index 000000000..44d688246 --- /dev/null +++ b/plugins/admin/devices/paste_deviceGeneric.tpl @@ -0,0 +1,25 @@ + +

{t}Devices{/t}

+ + + + +
+ + + + + +
{$must} + + +
+
+ + + + diff --git a/plugins/admin/devices/remove.tpl b/plugins/admin/devices/remove.tpl new file mode 100755 index 000000000..643056cd3 --- /dev/null +++ b/plugins/admin/devices/remove.tpl @@ -0,0 +1,23 @@ +
+  {t}Warning{/t} +
+

+ {$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} +

+

+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ {if $multiple} + +   + + {else} + +   + + {/if} +

+ diff --git a/plugins/admin/devices/tabs_devices.inc b/plugins/admin/devices/tabs_devices.inc new file mode 100755 index 000000000..9cb2e9017 --- /dev/null +++ b/plugins/admin/devices/tabs_devices.inc @@ -0,0 +1,43 @@ +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: +?>