source: branches/2.2/filemanager/inc/class.vfs_functions.inc.php @ 3913

Revision 3913, 11.4 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1659 - Exportar arquivo html, modificado para enviar como um POST.

Line 
1<?php
2        /**************************************************************************\
3        * -------------------------------------------------------------------------*
4        * This library is free software; you can redistribute it and/or modify it  *
5        * under the terms of the GNU Lesser General Public License as published by *
6        * the Free Software Foundation; either version 2.1 of the License,         *
7        * or any later version.                                                    *
8        * This library is distributed in the hope that it will be useful, but      *
9        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
10        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
11        * See the GNU Lesser General Public License for more details.              *
12        * You should have received a copy of the GNU Lesser General Public License *
13        * along with this library; if not, write to the Free Software Foundation,  *
14        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
15        \**************************************************************************/
16
17        /* $Id: class.vfs_functions.inc.php 2009-11-11 amuller $ */
18
19        class vfs_functions
20        {
21                var $public_functions = array(
22                        'touch' => True,
23                        'download'=>True,
24                        'setRestricted'=>True,
25                        'editComment'=> True,
26                        'rename'=>True,
27                        'delete'=>True,
28                        'archive'=>True,
29                        'unarchive'=>True,
30                        'copyto'=>True,
31                        'moveto'=>True,
32                        'summary' => True
33                );
34
35                //keep
36                var $bo;
37                var $dispath;
38                var $cwd;
39                var $lesspath;
40                var $dispsep;
41
42                var $target;
43
44                var $prefs;//array
45
46                var $current_config;
47                // this ones must be checked thorougly;
48                var $fileman = Array();
49                //var $fileman;
50                var $path;
51                var $file;
52                var $debug = false;
53                var $now;
54
55                function vfs_functions()
56                {
57                        $this->now = date('Y-m-d H:i:s');
58
59                        $this->bo = CreateObject('filemanager.bofilemanager');
60
61                        $c = CreateObject('phpgwapi.config','filemanager');
62                        $c->read_repository();
63                        $this->current_config = $c->config_data;
64
65
66                        // here local vars are created from the HTTP vars
67                        @reset($GLOBALS['HTTP_POST_VARS']);
68                        while( list($name,) = @each($GLOBALS['HTTP_POST_VARS']) )
69                        {
70                                $this->$name = base64_decode($GLOBALS['HTTP_POST_VARS'][$name]);
71                        }
72
73                        @reset($GLOBALS['HTTP_GET_VARS']);
74                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']) )
75                        {
76                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
77                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
78                        }
79
80                        $to_decode = array
81                        (
82                                'op'            => array('op' => ''),
83                                'path'  => array('path' => ''),
84                                'file'          => array('file' => ''),
85                                'sortby'        => array('sortby' => ''),
86                                'messages'      => array('messages'     => ''),
87                                'comment'       => array('comment' => ''),
88                                'from'  => array('from' => ''),
89                                'fileman'       => array('fileman' => ''),
90                                'to'    => array('to' => '')
91                        );
92
93                        reset($to_decode);
94                        while(list($var, $conditions) = each($to_decode))
95                        {
96                                while(list($condvar, $condvalue) = each($conditions))
97                                {
98                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
99                                        {
100                                                if(is_array($$var))
101                                                {
102                                                        $temp = array();
103                                                        while(list($varkey, $varvalue) = each($$var))
104                                                        {
105                                                                if(is_int($varkey))
106                                                                {
107                                                                        $temp[$varkey] = stripslashes(base64_decode($varvalue));
108                                                                }
109                                                                else
110                                                                {
111                                                                        $temp[stripslashes(base64_decode($varkey))] = $varvalue;
112                                                                }
113                                                        }
114                                                        $this->$var = $temp;
115                                                }
116                                                elseif(isset($$var))
117                                                {
118                                                        $this->$var = stripslashes(base64_decode($$var));
119                                                }
120                                        }
121                                }
122                        }
123                       
124                        // get appl. and user prefs
125                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
126                        $pref->read_repository();
127                        $pref->save_repository(True);
128                        $pref_array = $pref->read_repository();
129                        $this->prefs = $pref_array[$this->bo->appname];
130
131                        //always show name
132                        $this->prefs[name] =1;         
133                       
134                }
135               
136                // String format is YYYY-MM-DD HH:MM
137                function dateString2timeStamp($string)
138                {
139                        return mktime($string[11].$string[12],
140                                $string[14].$string[15],
141                                $string[17].$string[18],
142                                $string[5].$string[6],
143                                $string[8].$string[9],
144                                $string[0].$string[1].
145                                $string[2].$string[3]);
146                }
147               
148                function verifyLock($file,$relative){
149                        $ls_array = $this->bo->vfs->ls(array(
150                                'string'        => $file,
151                                'relatives'     => array($relative),
152                                'checksubdirs'  => False,
153                                'nofiles'       => True
154                        ));
155                        $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']);
156                        if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing
157                        {
158                                $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']);
159                                return False;
160
161                        }
162                        else
163                                return True;
164                }
165
166                function setRestricted(){
167                        $GLOBALS['phpgw_info']['flags'] = array
168                                (
169                                        'currentapp'    => 'filemanager',
170                                        'noheader'      => True,
171                                        'nonavbar' => True,
172                                        'nofooter'      => True,
173                                        'noappheader'   => True,
174                                        'enable_browser_class'  => True
175                                );
176
177                        if ($this->file)
178                        {
179                                $filename=$this->path.'/'.$this->file;
180                                if(!$this->verifyLock($filename,RELATIVE_NONE))
181                                {
182                                        echo "False";
183                                        return False;
184                                }
185                               
186                                $ls_array = $this->bo->vfs->ls(array(
187                                        'string'        => $filename,
188                                        'relatives'     => array(RELATIVE_NONE),
189                                        'checksubdirs'  => False,
190                                        'nofiles'       => True
191                                ));
192                                if (intval($ls_array[0]['type']) == 0)
193                                        $type = 1;
194                                else
195                                        $type = 0;
196
197                                if($this->bo->vfs->set_attributes (array(
198                                        'string'        => $filename,
199                                        'relatives'     => RELATIVE_NONE,
200                                        'attributes'    => array('type' => $type)
201                                        ))
202                                )
203                                {
204                                        echo "True|".$this->file;
205                                }
206                                else
207                                {
208                                        echo "False";
209                                }
210                        }
211
212                }
213                function touch(){
214                        if($this->file)
215                                if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL))))
216                                {
217                                        echo "True";
218                                        return True;
219                                }
220                                else
221                                        return False;
222
223                }
224                function summary()
225                {
226                        header('Content-Type: image/png');
227                        $expires = 60*60*24*15;
228                        header("Cache-Control: maxage=".$expires);
229                        header("Pragma: public");
230                        header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires));
231                        if($this->file)
232                        {       
233                                $content = $this->bo->vfs->summary(array('path' => $this->path,
234                                        'string' => $this->file
235                                ));
236                                if (strlen($content) < 1)
237                                {
238                                        $filename = './filemanager/templates/default/images/error.png';
239                                        $handle = fopen($filename,'rb');
240                                        $content = fread($handle,filesize($filename));
241                                        fclose($handle);
242                                }
243                                echo $content;
244                        }
245                        $GLOBALS['phpgw']->common->phpgw_exit();
246                }
247       
248                function delete(){
249                        foreach($this->fileman as $filename)
250                        {
251                                if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array(
252                                        'string' => $this->path.'/'.$filename,
253                                        'relatives' => array (RELATIVE_NONE)
254                                )))
255                                {
256                                        echo $filename."|";
257                                }
258                                else
259                                {
260                                        echo "False|".$filename;
261                                        return False;
262                                }
263                        }
264                }
265                function archive(){
266                        foreach($this->fileman as $filename)
267                        {
268                                if(!$this->verifyLock($filename,RELATIVE_ALL))
269                                {
270                                        echo "locked|".$filename;
271                                        return False;
272                                }
273                                $command .= " ".escapeshellarg($filename);
274                        }
275                        $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip";
276                        $zipFilePath=ini_get("session.save_path")."/".$zipFileName;
277                        $command = $zipFilePath.$command;
278
279                        if (strlen($this->pswd) > 0){
280                                $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command;
281                        }
282
283                        exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command),$output,$return_var);
284                        exec("history -c"); // privacy is good, we dont want get passwords!
285                        if ($return_var > 1){
286                                echo "False|".$return_var;
287                                return false;
288                        }
289
290                        $this->bo->vfs->cp(array(
291                                'from'=> $zipFilePath,
292                                'to'=> $zipFileName,
293                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
294                        ));
295                        $this->bo->vfs->set_attributes(array(
296                                'string'=> $zipFileName,
297                                'relatives'     => array(RELATIVE_ALL),
298                                'attributes'=> array(
299                                        'mime_type' => "application/zip"
300                                )
301                        ));
302                        exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath)));
303                        $this->delete();
304                }
305                function unarchive(){
306                        $command = escapeshellarg($this->file);
307                        if (strlen($this->pswd) > 0){
308                                $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command;
309                        }
310
311                        exec("cd ".escapeshellarg($this->bo->vfs->basedir.$this->path).";".escapeshellcmd("nice -n19 unzip ".$command),$output, $return_var);
312                        exec("history -c"); // privacy is good, we dont want get passwords!
313
314                        if ($return_var == 9 || $return_var == 5 || $return_var == 82){
315                                echo "wpasswd|";
316                                return false;
317                        }else if($return_var > 1){
318                                echo "False|";
319                        }
320
321                        $this->fileman[] = $this->file;
322                        $this->delete();
323                        $this->bo->vfs->update_real(array(
324                                        'string'        => $this->path,
325                                        'relatives'     => array(RELATIVE_NONE)
326                                ));
327                }
328                function editComment()
329                {
330                                if($badchar = $this->bo->bad_chars($this->comment, False, True))
331                                {
332                                        echo "False|badchar|".$badchar;
333                                        return False;
334                                }
335
336                                if ($this->bo->vfs->set_attributes(array(
337                                        'string'        => $this->file,
338                                        'relatives'     => array(RELATIVE_ALL),
339                                        'attributes'    => array(
340                                        'comment' => stripslashes($this->comment)
341                                        )
342                                )))
343                                {
344                                        echo "True|".$this->file;
345                                        return True;
346                                }
347                }
348                # Handle Moving Files and Directories
349                function moveto()
350                {
351                        if(!$this->to)
352                        {
353                                echo "NODIR|";
354                                return;
355                        }
356                        else
357                        {
358                                while(list($num, $file) = each($this->fileman))
359                                {
360                                        if($this->bo->vfs->mv(array(
361                                                'from'  => $this->from . '/' . $file,
362                                                'to'    => $this->to . '/' . $file,
363                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
364                                        )))
365                                                $moved++;
366                                        else
367                                                $error++;
368                                }
369                        }
370                        if($error > 0){
371                                echo "SOMEERROR|".$error;
372                                return;
373                        }
374                        if($moved > 0)
375                                echo "MOVED|".$moved;
376                }
377
378                // Handle Copying of Files and Directories
379                function copyto()
380                {
381                        if(!$this->to)
382                        {
383                                echo "NODIR|";
384                                return;
385                        }
386                        else
387                        {
388                                while(list($num, $file) = each($this->fileman))
389                                {
390                                        if($this->bo->vfs->cp(array(
391                                                'from'  => $this->from . '/' . $file,
392                                                'to'    => $this->to . '/' . $file,
393                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
394                                        )))
395                                                $copied++;
396                                        else
397                                                $error++;
398                                }
399                        }
400                        if($error > 0){
401                                echo "SOMEERROR|".$error;
402                                return;
403                        }
404                        if($copied > 0)
405                                echo "COPIED|".$copied;
406                }
407
408                # Handle Renaming Files and Directories
409                function rename()
410                {
411                        $_return = array();
412                       
413                        if ( $this->file )
414                        {
415                                if( $badchar = $this->bo->bad_chars($this->to, True, True) )
416                                {
417                                        $_return[] = array( "error" => $badchar);       
418                                }
419                                if(ereg("/", $this->to) || ereg("\\\\", $this->to))
420                                {
421                                        $_return[] = array( "error"=> "slashes");
422                                }
423                                elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT))
424                                {
425                                        $_return[] = array( "error" => "editing" );
426                                }
427                                elseif ($this->bo->vfs->mv(array(
428                                                'from'  => $this->path.'/'.$this->file,
429                                                'to'    => $this->path.'/'.$this->to,
430                                                'relatives' => array(RELATIVE_NONE,RELATIVE_NONE)
431                                )))
432                                {
433                                        $_return[] = array( "true" => lang('renamed %1 to %2', $this->file ,$this->to ) );
434                                }
435                                else
436                                {
437                                        $_return[] = array("error" => $this->file . " " . $this->to );
438                                }
439                        }
440                        else
441                                $_return[] = array("error" => "whitout file ");
442                       
443                        echo serialize( $_return );
444                }
445        }
Note: See TracBrowser for help on using the repository browser.