From 00826f36f010b83a92eebddb217136d35bfe2c88 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 8 Apr 2008 10:49:55 +0000 Subject: [PATCH] Updated sudo stuff -Added copy & paste. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10279 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../sudo/admin/sudo/class_divListSudo.inc | 52 +++++++++- .../sudo/admin/sudo/class_sudoGeneric.inc | 65 ++++++++++++ .../sudo/admin/sudo/class_sudoManagement.inc | 99 ++++++++++++++++++- .../sudo/admin/sudo/class_sudoOption.inc | 24 ++++- 4 files changed, 230 insertions(+), 10 deletions(-) diff --git a/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc b/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc index de0371866..404a5a0e2 100644 --- a/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc +++ b/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc @@ -65,9 +65,12 @@ class divListSudo extends MultiSelectWindow $this->EnableSaveButton (false); /* Dynamic action col, depending on snapshot icons */ - $action_col_size = 50; + $action_col_size = 54; if($this->parent->snapshotEnabled()){ - $action_col_size += 38; + $action_col_size += 32; + } + if($this->parent->CopyPasteHandler){ + $action_col_size += 20; } /* Toggle all selected / deselected */ @@ -120,6 +123,24 @@ class divListSudo extends MultiSelectWindow " "._("Remove")."|"."del_role|\n"; } + /* Add multiple copy & cut icons */ + if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Copy")."|"."multiple_copy_systems|\n"; +# $s.= "..|". +# " "._("Cut")."|"."multiple_cut_systems|\n"; + + if($this->parent->CopyPasteHandler->entries_queued()){ + $img = ""; + $s.="..|".$img." "._("Paste")."|editPaste|\n"; + }else{ + $img = ""; + $s.="..|".$img." "._("Paste")."\n"; + } + } + + /* Add snapshot icons */ if(preg_match("/(c.*w|w.*c)/",$acl)){ $s .= "..|---|\n"; @@ -151,9 +172,12 @@ class divListSudo extends MultiSelectWindow $userimg = "Sudo"; $ui = get_userinfo(); - $action_col_size = 50; + $action_col_size = 54; if($this->parent->snapshotEnabled()){ - $action_col_size += 38; + $action_col_size += 32; + } + if($this->parent->CopyPasteHandler){ + $action_col_size += 20; } // Test Every Entry and generate divlist Array @@ -164,6 +188,16 @@ class divListSudo extends MultiSelectWindow /* Add edit icon */ $actions = ""; + + $actions= ""; + if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl)){ +# $actions.= " "; + $actions.= " "; + } + + $actions.= ""; @@ -191,6 +225,16 @@ class divListSudo extends MultiSelectWindow $display = "$display"; } + /* Cutted objects should be displayed in light grey */ + if($this->parent->CopyPasteHandler){ + foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ + if($queue_data['dn'] == $val['dn']) { + $display = "".$display.""; + break; + } + } + } + $field1 = array("string" => "" , "attach" => "style='width:20px;'"); $field2 = array("string" => sprintf($userimg,$val['dn']), diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc index 165459391..6f33477d1 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc @@ -683,6 +683,71 @@ class sudo extends plugin "trustModel" => _("Access control list")) )); } + + + /*! \brief This function will be called if an object gets copied. + This function adapts attributes from the source object. + @param Array The source object. + */ + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){ + $this->$attr = array(); + if(isset($source[$attr])){ + $tmp = array(); + for($i = 0 ; $i < $source[$attr]['count']; $i++){ + $tmp[] = $source[$attr][$i]; + } + $this->$attr = $tmp; + } + } + + /* Is this account a trustAccount? */ + if (isset($source['trustModel'])){ + $this->trustModel= $source['trustModel'][0]; + $this->was_trust_account= TRUE; + } else { + $this->was_trust_account= FALSE; + $this->trustModel= ""; + } + + $this->accessTo = array(); + if (isset($source['accessTo'])){ + for ($i= 0; $i<$source['accessTo']['count']; $i++){ + $tmp= $source['accessTo'][$i]; + $this->accessTo[$tmp]= $tmp; + } + } + } + + + /*! \brief Used for copy & paste. + Returns a HTML input mask, which allows to change the cn of this entry. + @param Array Array containing current status && a HTML template. + */ + function getCopyDialog() + { + $vars = array("cn"); + $smarty = get_smarty(); + $smarty->assign("cn" ,$this->cn); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + /*! \brief Used for copy & paste. + Some entries must be renamed to avaoid duplicate entries. + */ + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc b/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc index 835e3a224..9f13e3ab8 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc @@ -34,6 +34,8 @@ class sudoManagement extends plugin private $DivListSudo = NULL; private $sudotabs = NULL; private $base = ""; + + private $start_pasting_copied_objects = FALSE; /*! \brief */ public function __construct(&$config, &$ui) @@ -43,6 +45,11 @@ class sudoManagement extends plugin $this->ui = &$ui; $this->base = sudo::get_sudoers_ou($this->config); + /* Copy & Paste enabled ?*/ + if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){ + $this->CopyPasteHandler = new CopyPasteHandler($this->config); + } + /* Create dialog object */ $this->DivListSudo = new divListSudo($this->config,$this); } @@ -61,7 +68,7 @@ class sudoManagement extends plugin /* Store these posts if the current object is locked (used by somebody else)*/ session::set('LOCK_VARS_TO_USE',array( - "/^act$/","/^id$/","/^sudo_edit_/", + "/^act$/","/^id$/","/^sudo_edit_/","/^cut_/","/^copy_/", "/^sudo_del_/","/^item_selected/","/menu_action/")); @@ -76,6 +83,14 @@ class sudoManagement extends plugin if(preg_match("/^sudo_del_/",$name)){ $s_action = "del_role"; $s_entry = preg_replace("/^sudo_del_([0-9]*).*$/","\\1",$name); + }elseif(preg_match("/^editPaste.*/i",$name)){ + $s_action="editPaste"; + }elseif(preg_match("/^copy_.*/",$name)){ + $s_action="copy"; + $s_entry = preg_replace("/^copy_([0-9]*).*$/i","\\1",$name); +# }elseif(preg_match("/^cut_.*/",$name)){ +# $s_action="cut"; +# $s_entry = preg_replace("/^cut_([0-9]*).*$/i","\\1",$name); } } @@ -87,13 +102,26 @@ class sudoManagement extends plugin } } - if(isset($_POST['menu_action']) && in_array($_POST['menu_action'],array("new_role","del_role","new_default"))){ + if(isset($_POST['menu_action']) && in_array($_POST['menu_action'],array("new_role","del_role","new_default","editPaste"))){ $s_action = $_POST['menu_action']; } + + $smarty= get_smarty(); + /******************** + 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 sudo ... ********************/ @@ -371,6 +399,9 @@ class sudoManagement extends plugin public function save_object() { $this->DivListSudo->save_object(); + if(is_object($this->CopyPasteHandler)){ + $this->CopyPasteHandler->save_object(); + } } @@ -404,9 +435,71 @@ class sudoManagement extends plugin } } - function get_used_snapshot_bases(){ + function get_used_snapshot_bases() + { return(array(sudo::get_sudoers_ou($this->config))); } + + + 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->list[$s_entry]['dn']; + $this->CopyPasteHandler->add_to_queue($dn,$s_action,"sudotabs","SUDOTABS","sudo"); + } + + /* 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->list[$id]['dn']; + + if($s_action == "copy_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"copy","sudotabs","SUDOTABS","sudo"); + } + if($s_action == "cut_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"cut","sudotabs","SUDOTABS","sudo"); + } + } + } + + /* 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 */ + $data = $this->CopyPasteHandler->execute(); + $this->CopyPasteHandler->SetVar("base",$this->DivListSudo->selectedBase); + + /* 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(""); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc b/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc index 48d862f6a..e73ec41ff 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc @@ -105,6 +105,13 @@ class sudoOption extends plugin ksort($option); $this->options = $option; + $this->load_options(); + } + + + private function load_options() + { + /**** Parse given sudoOption attributes ****/ @@ -188,6 +195,7 @@ class sudoOption extends plugin } + /*! \brief Create HTML output for this plugin @return String HTML output for this plugin. */ @@ -459,7 +467,7 @@ class sudoOption extends plugin $ldap->modify($this->attrs);; } - + /*! \brief Checks input validity */ function check() @@ -477,13 +485,23 @@ class sudoOption extends plugin $message[] = msgPool::invalid($name,$option['VALUE'],"/[0-9]/"); } } break; - } } } - return ($message); } + + + /*! \brief This function will be called if an object gets copied. + This function adapts attributes from the source object. + @param Array The source object. + */ + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + $this->attrs['sudoOption'] = $source['sudoOption']; + $this->load_options(); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> -- 2.30.2