X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_CopyPasteHandler.inc;h=1d6a1f04ac07b87f3308f9074ec63a0eea69e489;hb=6bc38be280f4dd4b0386b2c256749934cb37e86e;hp=81cabc2fe4f2014a2cca5570d80af49cee04618f;hpb=4ebac9cc4182bb5425873aebd91f2764ef57338f;p=gosa.git diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc index 81cabc2fe..1d6a1f04a 100644 --- a/include/class_CopyPasteHandler.inc +++ b/include/class_CopyPasteHandler.inc @@ -7,22 +7,20 @@ class CopyPasteHandler { var $config; var $current; - var $copyCurrent = false; - var $cutCurrent = false; - var $dialogOpen = false; - var $objectdn = false; - - var $was_successfull = false; - - /* this array contains all dns of the currently copyied objects */ + /* This array contains all dns of the currently copyied objects */ var $queue = array(); + + /* Attributes that should be overwritten */ var $setvar_array= array(); + + /* The dn of the last edited object */ var $lastdn = ""; + /* Create CP handler */ - function CopyPasteHandler($config) + function CopyPasteHandler(&$config) { - $this->config = $config; + $this->config = &$config; $this->current= NULL; $this->queue = array(); $this->setvar_array = array(); @@ -37,7 +35,7 @@ class CopyPasteHandler { * array['tab_class'] - Tab object that should be used to initialize the new object * array['tab_object'] - Tab object name used to initialize correct object Type like USERTABS */ - function add_to_queue($dn,$action,$tab_class,$tab_object) + function add_to_queue($dn,$action,$tab_class,$tab_object,$tab_acl_category) { if(!class_exists($tab_class)){ trigger_error(sprintf("Specified class object '%s' does not exists.",$tab_class)); @@ -48,7 +46,7 @@ class CopyPasteHandler { trigger_error(sprintf("Specified tab object '%s' does not exists.",$tab_object)); return(FALSE); } - + if(!in_array($action,array("cut","copy"))){ trigger_error(sprintf("Specified action '%s' does not exists for copy & paste.",$action)); return(FALSE); @@ -61,11 +59,12 @@ class CopyPasteHandler { $tmp['dn'] = $dn; $tmp['tab_class'] = $tab_class; $tmp['tab_object']= $tab_object; + $tmp['tab_acl_category']= $tab_acl_category; $this->queue[] = $tmp; } } - + /* This removes all objects from queue. * Remove hdd dumps of current entries too. * Remove entries older than 24 hours. @@ -81,6 +80,19 @@ class CopyPasteHandler { unset($this->queue[$key]); } + /* Create patch if it doesn't exists */ + if(!is_dir(LDAP_DUMP_PATH)){ + @mkdir(LDAP_DUMP_PATH); + } + + /* check if we are able to create a new file the given directory */ + if(!is_writeable(LDAP_DUMP_PATH)){ + print_red(sprintf(_("Could not cleanup copy & paste queue. We are not allowed to save ldap dump to '%s', please check permissions."),LDAP_DUMP_PATH)); + new log("copy","all/all","copy & paste, event queue.",array(), + sprintf("Could not cleanup copy & paste queue. We are not allowed to save ldap dump to '%s', please check permissions.",LDAP_DUMP_PATH)); + return(FALSE); + } + /* Remove entries from hdd that are older than24 hours */ $fp = opendir(LDAP_DUMP_PATH); while($file = readdir($fp)){ @@ -104,7 +116,7 @@ class CopyPasteHandler { $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); $res = $ldap->cat($dn); - + /* Check if given dn is valid and ldap search was succesfull */ if(!$res){ print_red(sprintf(_("Specified object '%s' is not a valid ldap object, please check copy & paste methods."))); @@ -115,7 +127,7 @@ class CopyPasteHandler { /* Create data to save given ldap dump on the hdd */ $filename = "gosa_copy-paste_dump_".preg_replace("/[^0-9]/","",microtime()); $path = LDAP_DUMP_PATH; - + /* Create patch if it doesn't exists */ if(!is_dir($path)){ @mkdir($path); @@ -125,7 +137,7 @@ class CopyPasteHandler { if(!is_writeable($path)){ print_red(sprintf(_("We are not allowed to save ldap dump to '%s', please check permissions."),$path)); new log("copy","all/all",$dn,array(), - sprintf("We are not allowed to save ldap dump to '%s', please check permissions.",$path)); + sprintf("We are not allowed to save ldap dump to '%s', please check permissions.",$path)); return(FALSE); } @@ -134,14 +146,14 @@ class CopyPasteHandler { if(!$fp){ print_red(sprintf(_("We are not allowed to save ldap dump to '%s/%s', please check permissions."),$path,$filename)); new log("copy","all/all",$dn,array(), - sprintf("We are not allowed to save ldap dump to '%s/%s', please check permissions.",$path,$filename)); + sprintf("We are not allowed to save ldap dump to '%s/%s', please check permissions.",$path,$filename)); return(FALSE); } $data = serialize($ldap->fetch()); fwrite($fp,$data,strlen($data)); fclose($fp); - + /* Only the webserver should be able to read those files */ @chmod($path."/".$filename,0600); return($path."/".$filename); @@ -170,15 +182,14 @@ class CopyPasteHandler { $entry = $this->queue[$key]; $tab_c = $entry['tab_class']; $tab_o = $entry['tab_object']; - + $tab_a = $entry['tab_acl_category']; + if($entry['method'] == "copy"){ - $entry['object'] = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],"new"); + $entry['object'] = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],"new",$tab_a); }else{ - $entry['object'] = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],$entry['dn'],"users"); + $entry['object'] = new $tab_c($this->config,$this->config->data['TABS'][$tab_o],$entry['dn'],$tab_a); } - - $entry['source_data'] = $this->load_attributes_from_hdd($entry['file_name']); if($entry['method'] == "copy"){ @@ -204,7 +215,7 @@ class CopyPasteHandler { } } - + /* Load dumped ldap entry specified by $filename and * return data an unserailized data array */ @@ -220,7 +231,7 @@ class CopyPasteHandler { }else{ print_red(sprintf(_("Could not load dumped file '%s', from hard disk drive."),$filename)); new log("copy","all/all",$dn,array(), - sprintf(sprintf("Could not load dumped file '%s', from hard disk drive.",$filename))); + sprintf(sprintf("Could not load dumped file '%s', from hard disk drive.",$filename))); return(FALSE); } } @@ -230,6 +241,7 @@ class CopyPasteHandler { Create unique names, ids, or what ever */ function execute() { + $ui = get_userinfo(); $type = $this->current['method']; if($type == "cut"){ if(isset($_POST['PerformCopyPaste'])){ @@ -237,17 +249,22 @@ class CopyPasteHandler { $this->load_entry_from_queue(); $this->_update_vars(); - $msgs = $this->check(); - if(count ($msgs) ){ - foreach( $msgs as $msg){ - print_red($msg); - } - }else{ + $msgs = $this->check(); + $acl = $ui->get_category_permissions($this->current['dn'], $this->current['tab_acl_category']); + + /* Check permissions */ + if(!preg_match("/((c|w)|(w|c))/",$acl)){ + print_red(sprintf(_("You are not allowed to cut and paste the following object '%s'."),$this->current['dn'])); + }elseif(count ($msgs) ){ + foreach( $msgs as $msg){ + print_red($msg); + } + }else{ - /* Load next queue entry */ - $this->lastdn = $this->current['object']->dn; - $this->current['object']->save(); - } + /* Load next queue entry */ + $this->lastdn = $this->current['object']->dn; + $this->current['object']->save(); + } $this->current =FALSE; } @@ -273,7 +290,13 @@ class CopyPasteHandler { if(isset($_POST['PerformCopyPaste'])){ $this->_update_vars(); $msgs = $this->check(); - if(count ($msgs) ){ + + $acl = $ui->get_category_permissions($this->current['dn'], $this->current['tab_acl_category']); + + /* Check permissions */ + if(!preg_match("/((c|w)|(w|c))/",$acl)){ + print_red(sprintf(_("You are not allowed to copy and paste the following object '%s'."),$this->current['dn'])); + }elseif(count ($msgs) ){ foreach( $msgs as $msg){ print_red($msg); } @@ -281,7 +304,7 @@ class CopyPasteHandler { $this->current['object']->save(); $this->lastdn = $this->current['object']->dn; $this->current =FALSE; - + /* Load next queue entry */ $this->load_entry_from_queue(); } @@ -300,6 +323,7 @@ class CopyPasteHandler { } + /* Return the dn of the last edited entry */ function last_entry() { return($this->lastdn); @@ -317,7 +341,7 @@ class CopyPasteHandler { $this->cleanup_queue(); $this->current = FALSE; } - + /* Assign posted var to all tabs */ if($this->current){ @@ -344,7 +368,7 @@ class CopyPasteHandler { $this->setvar_array[$name]=$value; } - + /* Update current object attributes, collected via SetVar */ function _update_vars() { @@ -356,7 +380,7 @@ class CopyPasteHandler { $this->current['object']->$name = $value; } } - + /* Walk through tabs */ foreach($this->current['object']->by_object as $key => $obj){ @@ -383,7 +407,7 @@ class CopyPasteHandler { return($ret); } - + /* returns the paste icon for headpages */ function generatePasteIcon() { @@ -395,121 +419,8 @@ class CopyPasteHandler { }else{ $Copy_Paste.= "\""._("Can't "; } - return ($Copy_Paste); } - - - - - - - - - - - - - - - - - - - /******** Functions below are unused and will be rewritten **********/ - - - - - - /* Add Object which should be cutted */ - function Cut_old($obj) - { - $this->cutCurrent = true; - $this->current = $obj; - $this->objectdn = $obj->dn; - if($this->isCurrentObjectPastAble()){ - return(true); - }else{ - $this->cutCurrent = $this->copyCurrent = false; - $this->obj = NULL; - } - return(false); - } - - - /* Displays a dialog which allows the user to fix all dependencies of this object. - Create unique names, ids, or what ever */ - function execute_old() - { - return; - /* Cut & paste - */ - if($this->cutCurrent){ - - if(isset($_POST['PerformCopyPaste'])){ - $msgs = $this->check(); - if(count ($msgs) ){ - foreach( $msgs as $msg){ - print_red($msg); - } - }else{ - $this->current->save(); - $this->dialogOpen =false; - $this->Clear(); - } - } - if($this->current){ - $smarty = get_smarty(); - $smarty->assign("type","cut"); - $smarty->assign("Complete",false); - $smarty->assign("AttributesToFix"," "); - $smarty->assign("SubDialog",$this->current->SubDialog); - $smarty->assign("objectDN" ,$this->objectdn); - $smarty->assign("message", sprintf(_("You are going to paste the cutted entry '%s'."), $this->objectdn)); - return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); - } - - /* Copy & paste - */ - }else{ - if(isset($_POST['PerformCopyPaste'])){ - $msgs = $this->check(); - if(count ($msgs) ){ - foreach( $msgs as $msg){ - print_red($msg); - } - }else{ - $this->current->save(); - $this->lastdn = $this->current->dn; - $this->dialogOpen =false; - $this->Clear(); - } - } - if($this->current){ - $smarty = get_smarty(); - $smarty->assign("type","copy"); - $smarty->assign("Complete",false); - $smarty->assign("AttributesToFix",$this->generateAttributesToFix()); - $smarty->assign("SubDialog",$this->current->SubDialog); - $smarty->assign("objectDN" ,$this->objectdn); - $smarty->assign("message", sprintf(_("You are going to paste the copied entry '%s'."), $this->objectdn)); - return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); - } - } - } - - /* Save new values posted by copy & paste dialog */ - function save_object_2() - { - /* Assign posted var to all tabs - */ - if($this->current){ - $this->current->saveCopyDialog(); - } - } - - } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>