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 | 'summary' => True |
---|
30 | ); |
---|
31 | |
---|
32 | //keep |
---|
33 | var $bo; |
---|
34 | var $dispath; |
---|
35 | var $cwd; |
---|
36 | var $lesspath; |
---|
37 | var $dispsep; |
---|
38 | |
---|
39 | var $target; |
---|
40 | |
---|
41 | var $prefs;//array |
---|
42 | |
---|
43 | var $current_config; |
---|
44 | // this ones must be checked thorougly; |
---|
45 | var $fileman = Array(); |
---|
46 | //var $fileman; |
---|
47 | var $path; |
---|
48 | var $file; |
---|
49 | var $debug = false; |
---|
50 | var $now; |
---|
51 | |
---|
52 | function vfs_functions() |
---|
53 | { |
---|
54 | $this->now = date('Y-m-d'); |
---|
55 | |
---|
56 | $this->bo = CreateObject('filemanager.bofilemanager'); |
---|
57 | |
---|
58 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
59 | $c->read_repository(); |
---|
60 | $this->current_config = $c->config_data; |
---|
61 | |
---|
62 | |
---|
63 | // here local vars are created from the HTTP vars |
---|
64 | @reset($GLOBALS['HTTP_POST_VARS']); |
---|
65 | while(list($name,) = @each($GLOBALS['HTTP_POST_VARS'])) |
---|
66 | { |
---|
67 | $this->$name = $GLOBALS['HTTP_POST_VARS'][$name]; |
---|
68 | } |
---|
69 | |
---|
70 | @reset($GLOBALS['HTTP_GET_VARS']); |
---|
71 | while(list($name,) = @each($GLOBALS['HTTP_GET_VARS'])) |
---|
72 | { |
---|
73 | $$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
74 | $this->$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | $to_decode = array |
---|
79 | ( |
---|
80 | 'op' => array('op' => ''), |
---|
81 | 'path' => array('path' => ''), |
---|
82 | 'file' => array('file' => ''), |
---|
83 | 'sortby' => array('sortby' => ''), |
---|
84 | 'messages' => array('messages' => ''), |
---|
85 | 'comment' => array('comment' => ''), |
---|
86 | 'to' => array('to' => '') |
---|
87 | ); |
---|
88 | |
---|
89 | reset($to_decode); |
---|
90 | while(list($var, $conditions) = each($to_decode)) |
---|
91 | { |
---|
92 | while(list($condvar, $condvalue) = each($conditions)) |
---|
93 | { |
---|
94 | if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue)) |
---|
95 | { |
---|
96 | if(is_array($$var)) |
---|
97 | { |
---|
98 | $temp = array(); |
---|
99 | while(list($varkey, $varvalue) = each($$var)) |
---|
100 | { |
---|
101 | if(is_int($varkey)) |
---|
102 | { |
---|
103 | $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue)))); |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue; |
---|
108 | } |
---|
109 | } |
---|
110 | $this->$var = $temp; |
---|
111 | } |
---|
112 | elseif(isset($$var)) |
---|
113 | { |
---|
114 | $this->$var = stripslashes(base64_decode(urldecode($$var))); |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | // get appl. and user prefs |
---|
121 | $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']); |
---|
122 | $pref->read_repository(); |
---|
123 | $pref->save_repository(True); |
---|
124 | $pref_array = $pref->read_repository(); |
---|
125 | $this->prefs = $pref_array[$this->bo->appname]; |
---|
126 | |
---|
127 | //always show name |
---|
128 | |
---|
129 | $this->prefs[name] =1; |
---|
130 | |
---|
131 | } |
---|
132 | // String format is YYYY-MM-DD HH:MM |
---|
133 | function dateString2timeStamp($string){ |
---|
134 | return mktime($string[11].$string[12], |
---|
135 | $string[14].$string[15], |
---|
136 | $string[17].$string[18], |
---|
137 | $string[5].$string[6], |
---|
138 | $string[8].$string[9], |
---|
139 | $string[0].$string[1]. |
---|
140 | $string[2].$string[3]); |
---|
141 | } |
---|
142 | function verifyLock($file,$relative){ |
---|
143 | $ls_array = $this->bo->vfs->ls(array( |
---|
144 | 'string' => $file, |
---|
145 | 'relatives' => array($relative), |
---|
146 | 'checksubdirs' => False, |
---|
147 | 'nofiles' => True |
---|
148 | )); |
---|
149 | $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']); |
---|
150 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing |
---|
151 | { |
---|
152 | $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); |
---|
153 | return False; |
---|
154 | |
---|
155 | } |
---|
156 | else |
---|
157 | return True; |
---|
158 | } |
---|
159 | |
---|
160 | function setRestricted(){ |
---|
161 | $GLOBALS['phpgw_info']['flags'] = array |
---|
162 | ( |
---|
163 | 'currentapp' => 'filemanager', |
---|
164 | 'noheader' => True, |
---|
165 | 'nonavbar' => True, |
---|
166 | 'nofooter' => True, |
---|
167 | 'noappheader' => True, |
---|
168 | 'enable_browser_class' => True |
---|
169 | ); |
---|
170 | |
---|
171 | if ($this->file) |
---|
172 | { |
---|
173 | $filename=$this->path.'/'.$this->file; |
---|
174 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
175 | { |
---|
176 | echo "False"; |
---|
177 | return False; |
---|
178 | } |
---|
179 | |
---|
180 | $ls_array = $this->bo->vfs->ls(array( |
---|
181 | 'string' => $filename, |
---|
182 | 'relatives' => array(RELATIVE_NONE), |
---|
183 | 'checksubdirs' => False, |
---|
184 | 'nofiles' => True |
---|
185 | )); |
---|
186 | if (intval($ls_array[0]['type']) == 0) |
---|
187 | $type = 1; |
---|
188 | else |
---|
189 | $type = 0; |
---|
190 | |
---|
191 | if($this->bo->vfs->set_attributes (array( |
---|
192 | 'string' => $filename, |
---|
193 | 'relatives' => RELATIVE_NONE, |
---|
194 | 'attributes' => array('type' => $type) |
---|
195 | )) |
---|
196 | ) |
---|
197 | { |
---|
198 | echo "True:".$this->file; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | echo "False"; |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | } |
---|
207 | function touch(){ |
---|
208 | if($this->file) |
---|
209 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
210 | { |
---|
211 | echo "True"; |
---|
212 | return True; |
---|
213 | } |
---|
214 | else |
---|
215 | return False; |
---|
216 | |
---|
217 | } |
---|
218 | function summary() |
---|
219 | { |
---|
220 | if($this->file) |
---|
221 | { |
---|
222 | header('Content-Type: image/gif'); |
---|
223 | $expires = 60*60*24*15; /* 15 days */ |
---|
224 | header("Cache-Control: maxage=".$expires); |
---|
225 | header("Pragma: public"); |
---|
226 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
227 | $content = $this->bo->vfs->summary(array('path' => $this->path, |
---|
228 | 'string' => $this->file |
---|
229 | )); |
---|
230 | if (strlen($content) > 0) |
---|
231 | echo $content; |
---|
232 | else |
---|
233 | { |
---|
234 | $filename = './filemanager/templates/default/images/error.gif'; |
---|
235 | $handle = fopen($filename,'rb'); |
---|
236 | echo fread($handle,filesize($filename)); |
---|
237 | fclose($handle); |
---|
238 | } |
---|
239 | |
---|
240 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | function delete(){ |
---|
245 | foreach($this->fileman as $filename) |
---|
246 | { |
---|
247 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array( |
---|
248 | 'string' => $this->path.'/'.$filename, |
---|
249 | 'relatives' => array (RELATIVE_NONE) |
---|
250 | ))) |
---|
251 | { |
---|
252 | echo $filename.":"; |
---|
253 | } |
---|
254 | else |
---|
255 | { |
---|
256 | echo "False:".$filename; |
---|
257 | return False; |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|
261 | function archive(){ |
---|
262 | foreach($this->fileman as $filename) |
---|
263 | { |
---|
264 | if(!$this->verifyLock($filename,RELATIVE_ALL)) |
---|
265 | { |
---|
266 | echo "locked:".$filename; |
---|
267 | return False; |
---|
268 | } |
---|
269 | $command .= " ".escapeshellarg($filename); |
---|
270 | } |
---|
271 | $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Ymd").".zip"; |
---|
272 | $zipFilePath=ini_get("session.save_path")."/".$zipFileName; |
---|
273 | $command = $zipFilePath.$command; |
---|
274 | |
---|
275 | if (strlen($this->pswd) > 0){ |
---|
276 | $command = " -P ".(base64_decode($this->pswd) ^ $this->path)." ".$command; |
---|
277 | } |
---|
278 | |
---|
279 | exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command)."; history -c"); |
---|
280 | |
---|
281 | $this->bo->vfs->cp(array( |
---|
282 | 'from'=> $zipFilePath, |
---|
283 | 'to'=> $zipFileName, |
---|
284 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
285 | )); |
---|
286 | $this->bo->vfs->set_attributes(array( |
---|
287 | 'string'=> $zipFileName, |
---|
288 | 'relatives' => array(RELATIVE_ALL), |
---|
289 | 'attributes'=> array( |
---|
290 | 'mime_type' => "application/zip" |
---|
291 | ) |
---|
292 | )); |
---|
293 | exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath))); |
---|
294 | $this->delete(); |
---|
295 | } |
---|
296 | function editComment() |
---|
297 | { |
---|
298 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
299 | { |
---|
300 | echo "False:badchar:".$badchar; |
---|
301 | return False; |
---|
302 | } |
---|
303 | |
---|
304 | if ($this->bo->vfs->set_attributes(array( |
---|
305 | 'string' => $this->file, |
---|
306 | 'relatives' => array(RELATIVE_ALL), |
---|
307 | 'attributes' => array( |
---|
308 | 'comment' => stripslashes($this->comment) |
---|
309 | ) |
---|
310 | ))) |
---|
311 | { |
---|
312 | echo "True:".$this->file; |
---|
313 | return True; |
---|
314 | } |
---|
315 | } |
---|
316 | # Handle Renaming Files and Directories |
---|
317 | function rename() |
---|
318 | { |
---|
319 | if ($this->file) |
---|
320 | { |
---|
321 | if($badchar = $this->bo->bad_chars($this->to, True, True)) |
---|
322 | { |
---|
323 | echo "Error:badchar:".$badchar; |
---|
324 | return false; |
---|
325 | } |
---|
326 | if(ereg("/", $this->to) || ereg("\\\\", $this->to)) |
---|
327 | { |
---|
328 | echo "Error:slashes"; |
---|
329 | return false; |
---|
330 | } |
---|
331 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
332 | echo "Error:editing"; |
---|
333 | elseif ($this->bo->vfs->mv(array( |
---|
334 | 'from' => $this->path.'/'.$this->file, |
---|
335 | 'to' => $this->path.'/'.$this->to, |
---|
336 | 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) |
---|
337 | ))) |
---|
338 | { |
---|
339 | echo "True:".$this->file.":".$this->to; |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | echo "Error:".$this->file.":".$this->to; |
---|
344 | } |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | } |
---|