source: trunk/filemanager/inc/class.vfs_functions.inc.php @ 2857

Revision 2857, 11.3 KB checked in by amuller, 14 years ago (diff)

Ticket #1086 - Corrigindo caminho de inclusão do rsa.inc.php

  • Property svn:executable set to *
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                        'setRestricted'=>True,
24                        'editComment'=> True,
25                        'rename'=>True,
26                        'delete'=>True,
27                        'archive'=>True,
28                        'unarchive'=>True,
29                        'copyto'=>True,
30                        'moveto'=>True,
31                        'summary' => True
32                );
33
34                //keep
35                var $bo;
36                var $dispath;
37                var $cwd;
38                var $lesspath;
39                var $dispsep;
40
41                var $target;
42
43                var $prefs;//array
44
45                var $current_config;
46                // this ones must be checked thorougly;
47                var $fileman = Array();
48                //var $fileman;
49                var $path;
50                var $file;
51                var $debug = false;
52                var $now;
53
54                function vfs_functions()
55                {
56                        $this->now = date('Y-m-d H:i:s');
57
58                        $this->bo = CreateObject('filemanager.bofilemanager');
59
60                        $c = CreateObject('phpgwapi.config','filemanager');
61                        $c->read_repository();
62                        $this->current_config = $c->config_data;
63
64
65                        // here local vars are created from the HTTP vars
66                        @reset($GLOBALS['HTTP_POST_VARS']);
67                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
68                        {
69                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
70                        }
71
72                        @reset($GLOBALS['HTTP_GET_VARS']);
73                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
74                        {
75                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
76                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
77
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
133                        $this->prefs[name] =1;         
134                       
135                }
136        // String format is YYYY-MM-DD HH:MM
137                function dateString2timeStamp($string){
138                        return mktime($string[11].$string[12],
139                                $string[14].$string[15],
140                                $string[17].$string[18],
141                                $string[5].$string[6],
142                                $string[8].$string[9],
143                                $string[0].$string[1].
144                                $string[2].$string[3]);
145                }
146                function verifyLock($file,$relative){
147                        $ls_array = $this->bo->vfs->ls(array(
148                                'string'        => $file,
149                                'relatives'     => array($relative),
150                                'checksubdirs'  => False,
151                                'nofiles'       => True
152                        ));
153                        $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']);
154                        if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing
155                        {
156                                $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']);
157                                return False;
158
159                        }
160                        else
161                                return True;
162                }
163
164                function setRestricted(){
165                        $GLOBALS['phpgw_info']['flags'] = array
166                                (
167                                        'currentapp'    => 'filemanager',
168                                        'noheader'      => True,
169                                        'nonavbar' => True,
170                                        'nofooter'      => True,
171                                        'noappheader'   => True,
172                                        'enable_browser_class'  => True
173                                );
174
175                        if ($this->file)
176                        {
177                                $filename=$this->path.'/'.$this->file;
178                                if(!$this->verifyLock($filename,RELATIVE_NONE))
179                                {
180                                        echo "False";
181                                        return False;
182                                }
183                               
184                                $ls_array = $this->bo->vfs->ls(array(
185                                        'string'        => $filename,
186                                        'relatives'     => array(RELATIVE_NONE),
187                                        'checksubdirs'  => False,
188                                        'nofiles'       => True
189                                ));
190                                if (intval($ls_array[0]['type']) == 0)
191                                        $type = 1;
192                                else
193                                        $type = 0;
194
195                                if($this->bo->vfs->set_attributes (array(
196                                        'string'        => $filename,
197                                        'relatives'     => RELATIVE_NONE,
198                                        'attributes'    => array('type' => $type)
199                                        ))
200                                )
201                                {
202                                        echo "True|".$this->file;
203                                }
204                                else
205                                {
206                                        echo "False";
207                                }
208                        }
209
210                }
211                function touch(){
212                        if($this->file)
213                                if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL))))
214                                {
215                                        echo "True";
216                                        return True;
217                                }
218                                else
219                                        return False;
220
221                }
222                function summary()
223                {
224                        header('Content-Type: image/png');
225                        $expires = 60*60*24*15;
226                        header("Cache-Control: maxage=".$expires);
227                        header("Pragma: public");
228                        header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires));
229                        if($this->file)
230                        {       
231                                $content = $this->bo->vfs->summary(array('path' => $this->path,
232                                        'string' => $this->file
233                                ));
234                                if (strlen($content) < 1)
235                                {
236                                        $filename = './filemanager/templates/default/images/error.png';
237                                        $handle = fopen($filename,'rb');
238                                        $content = fread($handle,filesize($filename));
239                                        fclose($handle);
240                                }
241                                echo $content;
242                        }
243                        $GLOBALS['phpgw']->common->phpgw_exit();
244                }
245       
246                function delete(){
247                        foreach($this->fileman as $filename)
248                        {
249                                if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array(
250                                        'string' => $this->path.'/'.$filename,
251                                        'relatives' => array (RELATIVE_NONE)
252                                )))
253                                {
254                                        echo $filename."|";
255                                }
256                                else
257                                {
258                                        echo "False|".$filename;
259                                        return False;
260                                }
261                        }
262                }
263                function archive(){
264                        foreach($this->fileman as $filename)
265                        {
266                                if(!$this->verifyLock($filename,RELATIVE_ALL))
267                                {
268                                        echo "locked|".$filename;
269                                        return False;
270                                }
271                                $command .= " ".escapeshellarg($filename);
272                        }
273                        $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip";
274                        $zipFilePath=ini_get("session.save_path")."/".$zipFileName;
275                        $command = $zipFilePath.$command;
276                        require_once(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.rsa.inc.php');
277                        $rsa = new rsa();
278
279                        if (strlen($this->pswd) > 0){
280                                $command = " -P ".$rsa->decode(base64_decode($this->pswd))." ".$command;
281                        }
282                        exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command),$output,$return_var);
283                        exec("history -c"); // privacy is good, we dont want get passwords!
284                        if ($return_var > 1){
285                                echo "False|".$return_var;
286                                return false;
287                        }
288
289                        $this->bo->vfs->cp(array(
290                                'from'=> $zipFilePath,
291                                'to'=> $zipFileName,
292                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
293                        ));
294                        $this->bo->vfs->set_attributes(array(
295                                'string'=> $zipFileName,
296                                'relatives'     => array(RELATIVE_ALL),
297                                'attributes'=> array(
298                                        'mime_type' => "application/zip"
299                                )
300                        ));
301                        exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath)));
302                        $this->delete();
303                }
304                function unarchive(){
305                        $command = escapeshellarg($this->file);
306                        require_once(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.rsa.inc.php');
307                        $rsa = new rsa();
308
309                        if (strlen($this->pswd) > 0){
310                                $command = " -P ".$rsa->decode(base64_decode($this->pswd))." ".$command;
311                        }
312
313                        exec("cd ".escapeshellarg($this->bo->vfs->basedir.$this->path).";".escapeshellcmd("nice -n19 unzip ".$command),$output, $return_var);
314                        exec("history -c"); // privacy is good, we dont want get passwords!
315
316                        if ($return_var == 9 || $return_var == 5 || $return_var == 82){
317                                echo "wpasswd|";
318                                return false;
319                        }else if($return_var > 1){
320                                echo "False|";
321                        }
322
323                        $this->fileman[] = $this->file;
324                        $this->delete();
325                        $this->bo->vfs->update_real(array(
326                                        'string'        => $this->path,
327                                        'relatives'     => array(RELATIVE_NONE)
328                                ));
329                }
330                function editComment()
331                {
332                                if($badchar = $this->bo->bad_chars($this->comment, False, True))
333                                {
334                                        echo "False|badchar|".$badchar;
335                                        return False;
336                                }
337
338                                if ($this->bo->vfs->set_attributes(array(
339                                        'string'        => $this->file,
340                                        'relatives'     => array(RELATIVE_ALL),
341                                        'attributes'    => array(
342                                        'comment' => stripslashes($this->comment)
343                                        )
344                                )))
345                                {
346                                        echo "True|".$this->file;
347                                        return True;
348                                }
349                }
350                # Handle Moving Files and Directories
351                function moveto()
352                {
353                        if(!$this->to)
354                        {
355                                echo "NODIR|";
356                                return;
357                        }
358                        else
359                        {
360                                while(list($num, $file) = each($this->fileman))
361                                {
362                                        if($this->bo->vfs->mv(array(
363                                                'from'  => $this->from . '/' . $file,
364                                                'to'    => $this->to . '/' . $file,
365                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
366                                        )))
367                                                $moved++;
368                                        else
369                                                $error++;
370                                }
371                        }
372                        if($error > 0){
373                                echo "SOMEERROR|".$error;
374                                return;
375                        }
376                        if($moved > 0)
377                                echo "MOVED|".$moved;
378                }
379
380                // Handle Copying of Files and Directories
381                function copyto()
382                {
383                        if(!$this->to)
384                        {
385                                echo "NODIR|";
386                                return;
387                        }
388                        else
389                        {
390                                while(list($num, $file) = each($this->fileman))
391                                {
392                                        if($this->bo->vfs->cp(array(
393                                                'from'  => $this->from . '/' . $file,
394                                                'to'    => $this->to . '/' . $file,
395                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
396                                        )))
397                                                $copied++;
398                                        else
399                                                $error++;
400                                }
401                        }
402                        if($error > 0){
403                                echo "SOMEERROR|".$error;
404                                return;
405                        }
406                        if($copied > 0)
407                                echo "COPIED|".$copied;
408                }
409
410                # Handle Renaming Files and Directories
411                function rename()
412                {
413                        if ($this->file)
414                        {
415                                if($badchar = $this->bo->bad_chars($this->to, True, True))
416                                {
417                                        echo "Error|badchar|".$badchar;
418                                        return false;
419                                }
420                                if(ereg("/", $this->to) || ereg("\\\\", $this->to))
421                                {
422                                        echo "Error|slashes";
423                                        return false;
424                                }
425                                elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT))
426                                        echo "Error|editing";
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                                        echo "True|".$this->file."|".$this->to;
434                                }
435                                else
436                                {
437                                        echo "Error|".$this->file."|".$this->to;
438                                }
439                        }
440                }
441
442        }
Note: See TracBrowser for help on using the repository browser.