[1627] | 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 | |
---|
[1704] | 17 | /* $Id: class.vfs_functions.inc.php 2009-11-11 amuller $ */ |
---|
[1627] | 18 | |
---|
| 19 | class vfs_functions |
---|
| 20 | { |
---|
| 21 | var $public_functions = array( |
---|
| 22 | 'touch' => True, |
---|
| 23 | 'download'=>True, |
---|
[1648] | 24 | 'setRestricted'=>True, |
---|
[1654] | 25 | 'editComment'=> True, |
---|
| 26 | 'rename'=>True, |
---|
[1829] | 27 | 'delete'=>True, |
---|
[1854] | 28 | 'archive'=>True, |
---|
[1865] | 29 | 'unarchive'=>True, |
---|
[1889] | 30 | 'copyto'=>True, |
---|
| 31 | 'moveto'=>True, |
---|
[1829] | 32 | 'summary' => True |
---|
[1627] | 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 | { |
---|
[1869] | 57 | $this->now = date('Y-m-d H:i:s'); |
---|
[1627] | 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 = $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 | |
---|
| 81 | $to_decode = array |
---|
| 82 | ( |
---|
| 83 | 'op' => array('op' => ''), |
---|
| 84 | 'path' => array('path' => ''), |
---|
| 85 | 'file' => array('file' => ''), |
---|
| 86 | 'sortby' => array('sortby' => ''), |
---|
| 87 | 'messages' => array('messages' => ''), |
---|
[1654] | 88 | 'comment' => array('comment' => ''), |
---|
| 89 | 'to' => array('to' => '') |
---|
[1627] | 90 | ); |
---|
| 91 | |
---|
| 92 | reset($to_decode); |
---|
| 93 | while(list($var, $conditions) = each($to_decode)) |
---|
| 94 | { |
---|
| 95 | while(list($condvar, $condvalue) = each($conditions)) |
---|
| 96 | { |
---|
| 97 | if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue)) |
---|
| 98 | { |
---|
| 99 | if(is_array($$var)) |
---|
| 100 | { |
---|
| 101 | $temp = array(); |
---|
| 102 | while(list($varkey, $varvalue) = each($$var)) |
---|
| 103 | { |
---|
| 104 | if(is_int($varkey)) |
---|
| 105 | { |
---|
| 106 | $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue)))); |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | $this->$var = $temp; |
---|
| 114 | } |
---|
| 115 | elseif(isset($$var)) |
---|
| 116 | { |
---|
| 117 | $this->$var = stripslashes(base64_decode(urldecode($$var))); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | // get appl. and user prefs |
---|
| 124 | $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']); |
---|
| 125 | $pref->read_repository(); |
---|
| 126 | $pref->save_repository(True); |
---|
| 127 | $pref_array = $pref->read_repository(); |
---|
| 128 | $this->prefs = $pref_array[$this->bo->appname]; |
---|
| 129 | |
---|
| 130 | //always show name |
---|
| 131 | |
---|
| 132 | $this->prefs[name] =1; |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | // String format is YYYY-MM-DD HH:MM |
---|
| 136 | function dateString2timeStamp($string){ |
---|
| 137 | return mktime($string[11].$string[12], |
---|
| 138 | $string[14].$string[15], |
---|
| 139 | $string[17].$string[18], |
---|
| 140 | $string[5].$string[6], |
---|
| 141 | $string[8].$string[9], |
---|
| 142 | $string[0].$string[1]. |
---|
| 143 | $string[2].$string[3]); |
---|
| 144 | } |
---|
| 145 | function verifyLock($file,$relative){ |
---|
| 146 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 147 | 'string' => $file, |
---|
| 148 | 'relatives' => array($relative), |
---|
| 149 | 'checksubdirs' => False, |
---|
| 150 | 'nofiles' => True |
---|
| 151 | )); |
---|
| 152 | $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']); |
---|
| 153 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing |
---|
| 154 | { |
---|
| 155 | $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); |
---|
| 156 | return False; |
---|
| 157 | |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | return True; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | function setRestricted(){ |
---|
| 164 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 165 | ( |
---|
| 166 | 'currentapp' => 'filemanager', |
---|
| 167 | 'noheader' => True, |
---|
| 168 | 'nonavbar' => True, |
---|
| 169 | 'nofooter' => True, |
---|
| 170 | 'noappheader' => True, |
---|
| 171 | 'enable_browser_class' => True |
---|
| 172 | ); |
---|
| 173 | |
---|
| 174 | if ($this->file) |
---|
| 175 | { |
---|
| 176 | $filename=$this->path.'/'.$this->file; |
---|
| 177 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
| 178 | { |
---|
| 179 | echo "False"; |
---|
| 180 | return False; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 184 | 'string' => $filename, |
---|
| 185 | 'relatives' => array(RELATIVE_NONE), |
---|
| 186 | 'checksubdirs' => False, |
---|
| 187 | 'nofiles' => True |
---|
| 188 | )); |
---|
| 189 | if (intval($ls_array[0]['type']) == 0) |
---|
| 190 | $type = 1; |
---|
| 191 | else |
---|
| 192 | $type = 0; |
---|
| 193 | |
---|
| 194 | if($this->bo->vfs->set_attributes (array( |
---|
| 195 | 'string' => $filename, |
---|
| 196 | 'relatives' => RELATIVE_NONE, |
---|
| 197 | 'attributes' => array('type' => $type) |
---|
| 198 | )) |
---|
| 199 | ) |
---|
| 200 | { |
---|
[1869] | 201 | echo "True|".$this->file; |
---|
[1627] | 202 | } |
---|
| 203 | else |
---|
| 204 | { |
---|
| 205 | echo "False"; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | } |
---|
| 210 | function touch(){ |
---|
| 211 | if($this->file) |
---|
| 212 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
| 213 | { |
---|
| 214 | echo "True"; |
---|
| 215 | return True; |
---|
| 216 | } |
---|
| 217 | else |
---|
| 218 | return False; |
---|
| 219 | |
---|
| 220 | } |
---|
[1829] | 221 | function summary() |
---|
[1627] | 222 | { |
---|
[1893] | 223 | header('Content-Type: text/html'); |
---|
| 224 | $expires = 60*60*24*15; |
---|
| 225 | header("Cache-Control: maxage=".$expires); |
---|
| 226 | header("Pragma: public"); |
---|
| 227 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
| 228 | echo '<img src="data:image/gif;base64,'; |
---|
[1693] | 229 | if($this->file) |
---|
[1829] | 230 | { |
---|
[1838] | 231 | $content = $this->bo->vfs->summary(array('path' => $this->path, |
---|
[1829] | 232 | 'string' => $this->file |
---|
| 233 | )); |
---|
[1893] | 234 | if (strlen($content) < 1) |
---|
[1838] | 235 | { |
---|
| 236 | $filename = './filemanager/templates/default/images/error.gif'; |
---|
| 237 | $handle = fopen($filename,'rb'); |
---|
[1893] | 238 | $content = fread($handle,filesize($filename)); |
---|
[1838] | 239 | fclose($handle); |
---|
| 240 | } |
---|
[1893] | 241 | echo base64_encode($content); |
---|
[1627] | 242 | } |
---|
[1893] | 243 | echo '">'; |
---|
| 244 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
[1627] | 245 | } |
---|
[1829] | 246 | |
---|
[1654] | 247 | function delete(){ |
---|
[1869] | 248 | foreach($this->fileman as $filecode) |
---|
[1654] | 249 | { |
---|
[1869] | 250 | $filename = base64_decode($filecode); |
---|
[1854] | 251 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array( |
---|
| 252 | 'string' => $this->path.'/'.$filename, |
---|
| 253 | 'relatives' => array (RELATIVE_NONE) |
---|
| 254 | ))) |
---|
[1654] | 255 | { |
---|
[1869] | 256 | echo $filename."|"; |
---|
[1654] | 257 | } |
---|
| 258 | else |
---|
| 259 | { |
---|
[1869] | 260 | echo "False|".$filename; |
---|
[1654] | 261 | return False; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | } |
---|
[1854] | 265 | function archive(){ |
---|
[1869] | 266 | foreach($this->fileman as $filecode) |
---|
[1854] | 267 | { |
---|
[1869] | 268 | $filename = base64_decode($filecode); |
---|
[1854] | 269 | if(!$this->verifyLock($filename,RELATIVE_ALL)) |
---|
| 270 | { |
---|
[1869] | 271 | echo "locked|".$filename; |
---|
[1854] | 272 | return False; |
---|
| 273 | } |
---|
| 274 | $command .= " ".escapeshellarg($filename); |
---|
| 275 | } |
---|
[1869] | 276 | $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip"; |
---|
[1854] | 277 | $zipFilePath=ini_get("session.save_path")."/".$zipFileName; |
---|
| 278 | $command = $zipFilePath.$command; |
---|
| 279 | |
---|
| 280 | if (strlen($this->pswd) > 0){ |
---|
[1880] | 281 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
[1854] | 282 | } |
---|
| 283 | |
---|
[1869] | 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 | } |
---|
[1854] | 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 | } |
---|
[1865] | 306 | function unarchive(){ |
---|
| 307 | $command = escapeshellarg($this->file); |
---|
| 308 | if (strlen($this->pswd) > 0){ |
---|
[1880] | 309 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
[1865] | 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){ |
---|
[1869] | 316 | echo "wpasswd|"; |
---|
[1865] | 317 | return false; |
---|
| 318 | }else if($return_var > 1){ |
---|
[1869] | 319 | echo "False|"; |
---|
[1865] | 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 | } |
---|
[1648] | 329 | function editComment() |
---|
| 330 | { |
---|
[1654] | 331 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
[1648] | 332 | { |
---|
[1869] | 333 | echo "False|badchar|".$badchar; |
---|
[1648] | 334 | return False; |
---|
| 335 | } |
---|
| 336 | |
---|
[1654] | 337 | if ($this->bo->vfs->set_attributes(array( |
---|
| 338 | 'string' => $this->file, |
---|
[1648] | 339 | 'relatives' => array(RELATIVE_ALL), |
---|
| 340 | 'attributes' => array( |
---|
[1654] | 341 | 'comment' => stripslashes($this->comment) |
---|
[1648] | 342 | ) |
---|
[1654] | 343 | ))) |
---|
| 344 | { |
---|
[1869] | 345 | echo "True|".$this->file; |
---|
[1654] | 346 | return True; |
---|
| 347 | } |
---|
| 348 | } |
---|
[1889] | 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 | $this->from = base64_decode($this->from); |
---|
| 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 | $this->from = base64_decode($this->from); |
---|
| 391 | while(list($num, $file) = each($this->fileman)) |
---|
| 392 | { |
---|
| 393 | if($this->bo->vfs->cp(array( |
---|
| 394 | 'from' => $this->from . '/' . $file, |
---|
| 395 | 'to' => $this->to . '/' . $file, |
---|
| 396 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
| 397 | ))) |
---|
| 398 | $copied++; |
---|
| 399 | else |
---|
| 400 | $error++; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | if($error > 0){ |
---|
| 404 | echo "SOMEERROR|".$error; |
---|
| 405 | return; |
---|
| 406 | } |
---|
| 407 | if($copied > 0) |
---|
| 408 | echo "COPIED|".$copied; |
---|
| 409 | } |
---|
| 410 | |
---|
[1654] | 411 | # Handle Renaming Files and Directories |
---|
| 412 | function rename() |
---|
| 413 | { |
---|
| 414 | if ($this->file) |
---|
| 415 | { |
---|
| 416 | if($badchar = $this->bo->bad_chars($this->to, True, True)) |
---|
| 417 | { |
---|
[1869] | 418 | echo "Error|badchar|".$badchar; |
---|
[1654] | 419 | return false; |
---|
| 420 | } |
---|
| 421 | if(ereg("/", $this->to) || ereg("\\\\", $this->to)) |
---|
| 422 | { |
---|
[1869] | 423 | echo "Error|slashes"; |
---|
[1654] | 424 | return false; |
---|
| 425 | } |
---|
| 426 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
[1869] | 427 | echo "Error|editing"; |
---|
[1654] | 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 | { |
---|
[1869] | 434 | echo "True|".$this->file."|".$this->to; |
---|
[1654] | 435 | } |
---|
| 436 | else |
---|
| 437 | { |
---|
[1869] | 438 | echo "Error|".$this->file."|".$this->to; |
---|
[1654] | 439 | } |
---|
[1648] | 440 | } |
---|
| 441 | } |
---|
[1654] | 442 | |
---|
[1627] | 443 | } |
---|