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 | { |
---|
168 | $GLOBALS['phpgw_info']['flags'] = array |
---|
169 | ( |
---|
170 | 'currentapp' => 'filemanager', |
---|
171 | 'noheader' => True, |
---|
172 | 'nonavbar' => True, |
---|
173 | 'nofooter' => True, |
---|
174 | 'noappheader' => True, |
---|
175 | 'enable_browser_class' => True |
---|
176 | ); |
---|
177 | |
---|
178 | if ($this->file) |
---|
179 | { |
---|
180 | $filename=$this->path.'/'.$this->file; |
---|
181 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
182 | { |
---|
183 | echo "False"; |
---|
184 | return False; |
---|
185 | } |
---|
186 | |
---|
187 | $ls_array = $this->bo->vfs->ls(array( |
---|
188 | 'string' => $filename, |
---|
189 | 'relatives' => array(RELATIVE_NONE), |
---|
190 | 'checksubdirs' => False, |
---|
191 | 'nofiles' => True |
---|
192 | )); |
---|
193 | if (intval($ls_array[0]['type']) == 0) |
---|
194 | $type = 1; |
---|
195 | else |
---|
196 | $type = 0; |
---|
197 | |
---|
198 | if($this->bo->vfs->set_attributes (array( |
---|
199 | 'string' => $filename, |
---|
200 | 'relatives' => RELATIVE_NONE, |
---|
201 | 'attributes' => array('type' => $type) |
---|
202 | )) |
---|
203 | ) |
---|
204 | { |
---|
205 | echo "True|".$this->file; |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | echo "False"; |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | } |
---|
214 | function touch(){ |
---|
215 | if($this->file) |
---|
216 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
217 | { |
---|
218 | echo "True"; |
---|
219 | return True; |
---|
220 | } |
---|
221 | else |
---|
222 | return False; |
---|
223 | |
---|
224 | } |
---|
225 | function summary() |
---|
226 | { |
---|
227 | header('Content-Type: image/png'); |
---|
228 | $expires = 60*60*24*15; |
---|
229 | header("Cache-Control: maxage=".$expires); |
---|
230 | header("Pragma: public"); |
---|
231 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
232 | if($this->file) |
---|
233 | { |
---|
234 | $content = $this->bo->vfs->summary(array('path' => $this->path, |
---|
235 | 'string' => $this->file |
---|
236 | )); |
---|
237 | if (strlen($content) < 1) |
---|
238 | { |
---|
239 | $filename = './filemanager/templates/default/images/error.png'; |
---|
240 | $handle = fopen($filename,'rb'); |
---|
241 | $content = fread($handle,filesize($filename)); |
---|
242 | fclose($handle); |
---|
243 | } |
---|
244 | echo $content; |
---|
245 | } |
---|
246 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
247 | } |
---|
248 | |
---|
249 | function delete(){ |
---|
250 | foreach($this->fileman as $filename) |
---|
251 | { |
---|
252 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array( |
---|
253 | 'string' => $this->path.'/'.$filename, |
---|
254 | 'relatives' => array (RELATIVE_NONE) |
---|
255 | ))) |
---|
256 | { |
---|
257 | echo $filename."|"; |
---|
258 | } |
---|
259 | else |
---|
260 | { |
---|
261 | echo "False|".$filename; |
---|
262 | return False; |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | function archive(){ |
---|
267 | foreach($this->fileman as $filename) |
---|
268 | { |
---|
269 | if(!$this->verifyLock($filename,RELATIVE_ALL)) |
---|
270 | { |
---|
271 | echo "locked|".$filename; |
---|
272 | return False; |
---|
273 | } |
---|
274 | $command .= " ".escapeshellarg($filename); |
---|
275 | } |
---|
276 | $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip"; |
---|
277 | $zipFilePath=ini_get("session.save_path")."/".$zipFileName; |
---|
278 | $command = $zipFilePath.$command; |
---|
279 | |
---|
280 | if (strlen($this->pswd) > 0){ |
---|
281 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
282 | } |
---|
283 | |
---|
284 | exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command),$output,$return_var); |
---|
285 | exec("history -c"); // privacy is good, we dont want get passwords! |
---|
286 | if ($return_var > 1){ |
---|
287 | echo "False|".$return_var; |
---|
288 | return false; |
---|
289 | } |
---|
290 | |
---|
291 | $this->bo->vfs->cp(array( |
---|
292 | 'from'=> $zipFilePath, |
---|
293 | 'to'=> $zipFileName, |
---|
294 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
295 | )); |
---|
296 | $this->bo->vfs->set_attributes(array( |
---|
297 | 'string'=> $zipFileName, |
---|
298 | 'relatives' => array(RELATIVE_ALL), |
---|
299 | 'attributes'=> array( |
---|
300 | 'mime_type' => "application/zip" |
---|
301 | ) |
---|
302 | )); |
---|
303 | exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath))); |
---|
304 | $this->delete(); |
---|
305 | } |
---|
306 | function unarchive(){ |
---|
307 | $command = escapeshellarg($this->file); |
---|
308 | if (strlen($this->pswd) > 0){ |
---|
309 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
310 | } |
---|
311 | |
---|
312 | exec("cd ".escapeshellarg($this->bo->vfs->basedir.$this->path).";".escapeshellcmd("nice -n19 unzip ".$command),$output, $return_var); |
---|
313 | exec("history -c"); // privacy is good, we dont want get passwords! |
---|
314 | |
---|
315 | if ($return_var == 9 || $return_var == 5 || $return_var == 82){ |
---|
316 | echo "wpasswd|"; |
---|
317 | return false; |
---|
318 | }else if($return_var > 1){ |
---|
319 | echo "False|"; |
---|
320 | } |
---|
321 | |
---|
322 | $this->fileman[] = $this->file; |
---|
323 | $this->delete(); |
---|
324 | $this->bo->vfs->update_real(array( |
---|
325 | 'string' => $this->path, |
---|
326 | 'relatives' => array(RELATIVE_NONE) |
---|
327 | )); |
---|
328 | } |
---|
329 | function editComment() |
---|
330 | { |
---|
331 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
332 | { |
---|
333 | echo "False|badchar|".$badchar; |
---|
334 | return False; |
---|
335 | } |
---|
336 | |
---|
337 | if ($this->bo->vfs->set_attributes(array( |
---|
338 | 'string' => $this->file, |
---|
339 | 'relatives' => array(RELATIVE_ALL), |
---|
340 | 'attributes' => array( |
---|
341 | 'comment' => stripslashes($this->comment) |
---|
342 | ) |
---|
343 | ))) |
---|
344 | { |
---|
345 | echo "True|".$this->file; |
---|
346 | return True; |
---|
347 | } |
---|
348 | } |
---|
349 | # Handle Moving Files and Directories |
---|
350 | function moveto() |
---|
351 | { |
---|
352 | if(!$this->to) |
---|
353 | { |
---|
354 | echo "NODIR|"; |
---|
355 | return; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | while(list($num, $file) = each($this->fileman)) |
---|
360 | { |
---|
361 | if($this->bo->vfs->mv(array( |
---|
362 | 'from' => $this->from . '/' . $file, |
---|
363 | 'to' => $this->to . '/' . $file, |
---|
364 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
365 | ))) |
---|
366 | $moved++; |
---|
367 | else |
---|
368 | $error++; |
---|
369 | } |
---|
370 | } |
---|
371 | if($error > 0){ |
---|
372 | echo "SOMEERROR|".$error; |
---|
373 | return; |
---|
374 | } |
---|
375 | if($moved > 0) |
---|
376 | echo "MOVED|".$moved; |
---|
377 | } |
---|
378 | |
---|
379 | // Handle Copying of Files and Directories |
---|
380 | function copyto() |
---|
381 | { |
---|
382 | if(!$this->to) |
---|
383 | { |
---|
384 | echo "NODIR|"; |
---|
385 | return; |
---|
386 | } |
---|
387 | else |
---|
388 | { |
---|
389 | while(list($num, $file) = each($this->fileman)) |
---|
390 | { |
---|
391 | if($this->bo->vfs->cp(array( |
---|
392 | 'from' => $this->from . '/' . $file, |
---|
393 | 'to' => $this->to . '/' . $file, |
---|
394 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
395 | ))) |
---|
396 | $copied++; |
---|
397 | else |
---|
398 | $error++; |
---|
399 | } |
---|
400 | } |
---|
401 | if($error > 0){ |
---|
402 | echo "SOMEERROR|".$error; |
---|
403 | return; |
---|
404 | } |
---|
405 | if($copied > 0) |
---|
406 | echo "COPIED|".$copied; |
---|
407 | } |
---|
408 | |
---|
409 | # Handle Renaming Files and Directories |
---|
410 | function rename() |
---|
411 | { |
---|
412 | $_return = array(); |
---|
413 | |
---|
414 | if ( $this->file ) |
---|
415 | { |
---|
416 | if( $badchar = $this->bo->bad_chars($this->to, True, True) ) |
---|
417 | { |
---|
418 | $_return[] = array( "error" => $badchar); |
---|
419 | } |
---|
420 | if(ereg("/", $this->to) || ereg("\\\\", $this->to)) |
---|
421 | { |
---|
422 | $_return[] = array( "error"=> "slashes"); |
---|
423 | } |
---|
424 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
425 | { |
---|
426 | $_return[] = array( "error" => "editing" ); |
---|
427 | } |
---|
428 | elseif ($this->bo->vfs->mv(array( |
---|
429 | 'from' => $this->path.'/'.$this->file, |
---|
430 | 'to' => $this->path.'/'.$this->to, |
---|
431 | 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) |
---|
432 | ))) |
---|
433 | { |
---|
434 | $_return[] = array( "true" => lang('renamed %1 to %2', $this->file ,$this->to ) ); |
---|
435 | |
---|
436 | // Get Type Mime Type |
---|
437 | $mimeType = $this->bo->vfs->get_ext_mime_type(array ('string' => $this->to )); |
---|
438 | |
---|
439 | $this->bo->vfs->set_attributes( array( |
---|
440 | 'string' => $this->to, |
---|
441 | 'relatives' => array(RELATIVE_ALL), |
---|
442 | 'attributes' => array('mime_type' => $mimeType) |
---|
443 | )); |
---|
444 | } |
---|
445 | else |
---|
446 | { |
---|
447 | $_return[] = array( "error" => $this->file . " " . $this->to ); |
---|
448 | } |
---|
449 | } |
---|
450 | else |
---|
451 | { |
---|
452 | $_return[] = array("error" => "whitout file "); |
---|
453 | } |
---|
454 | |
---|
455 | echo serialize( $_return ); |
---|
456 | } |
---|
457 | } |
---|