[3019] | 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']); |
---|
[3913] | 67 | while( list($name,) = @each($GLOBALS['HTTP_POST_VARS']) ) |
---|
[3019] | 68 | { |
---|
[3913] | 69 | $this->$name = base64_decode($GLOBALS['HTTP_POST_VARS'][$name]); |
---|
[3019] | 70 | } |
---|
| 71 | |
---|
| 72 | @reset($GLOBALS['HTTP_GET_VARS']); |
---|
[3913] | 73 | while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']) ) |
---|
[3019] | 74 | { |
---|
| 75 | $$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
| 76 | $this->$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | $to_decode = array |
---|
| 80 | ( |
---|
[3913] | 81 | 'op' => array('op' => ''), |
---|
[3019] | 82 | 'path' => array('path' => ''), |
---|
[3913] | 83 | 'file' => array('file' => ''), |
---|
[3019] | 84 | 'sortby' => array('sortby' => ''), |
---|
| 85 | 'messages' => array('messages' => ''), |
---|
| 86 | 'comment' => array('comment' => ''), |
---|
| 87 | 'from' => array('from' => ''), |
---|
[3913] | 88 | 'fileman' => array('fileman' => ''), |
---|
[3019] | 89 | 'to' => array('to' => '') |
---|
| 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($varvalue)); |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | $temp[stripslashes(base64_decode($varkey))] = $varvalue; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | $this->$var = $temp; |
---|
| 114 | } |
---|
| 115 | elseif(isset($$var)) |
---|
| 116 | { |
---|
| 117 | $this->$var = stripslashes(base64_decode($$var)); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
[3913] | 122 | |
---|
[3019] | 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 | $this->prefs[name] =1; |
---|
| 132 | |
---|
| 133 | } |
---|
[3913] | 134 | |
---|
[5038] | 135 | function convertDateForm($pDate) |
---|
| 136 | { |
---|
| 137 | /** |
---|
| 138 | * Recebe a data no formato : aaaa-mm-dd |
---|
| 139 | * Retorna a data no formato : dd/mm/aaaa |
---|
| 140 | **/ |
---|
| 141 | |
---|
| 142 | $cDate = date_parse($pDate); |
---|
| 143 | $day = ( strlen($cDate['day']) > 1 ) ? $cDate['day'] : "0".$cDate['day']; |
---|
| 144 | $month = ( strlen($cDate['month']) > 1 ) ? $cDate['month'] : "0".$cDate['month']; |
---|
| 145 | $year = $cDate['year']; |
---|
| 146 | |
---|
| 147 | return $day."/".$month."/".$year; |
---|
| 148 | } |
---|
| 149 | |
---|
[3913] | 150 | // String format is YYYY-MM-DD HH:MM |
---|
| 151 | function dateString2timeStamp($string) |
---|
| 152 | { |
---|
[5038] | 153 | /** |
---|
| 154 | * Recebe a data no formato : aaaa-mm-dd |
---|
| 155 | * Retorna a data no formato : dd/mm/aaaa |
---|
| 156 | **/ |
---|
| 157 | |
---|
| 158 | $cDate = date_parse($string); |
---|
| 159 | $day = ( strlen($cDate['day']) > 1 ) ? $cDate['day'] : "0".$cDate['day']; |
---|
| 160 | $month = ( strlen($cDate['month']) > 1 ) ? $cDate['month'] : "0".$cDate['month']; |
---|
| 161 | $year = $cDate['year']; |
---|
| 162 | |
---|
| 163 | return $day."/".$month."/".$year; |
---|
[3019] | 164 | } |
---|
[3913] | 165 | |
---|
[3019] | 166 | function verifyLock($file,$relative){ |
---|
| 167 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 168 | 'string' => $file, |
---|
| 169 | 'relatives' => array($relative), |
---|
| 170 | 'checksubdirs' => False, |
---|
| 171 | 'nofiles' => True |
---|
| 172 | )); |
---|
| 173 | $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']); |
---|
| 174 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing |
---|
| 175 | { |
---|
| 176 | $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); |
---|
| 177 | return False; |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | else |
---|
| 181 | return True; |
---|
| 182 | } |
---|
| 183 | |
---|
[3924] | 184 | function setRestricted() |
---|
| 185 | { |
---|
[3019] | 186 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 187 | ( |
---|
[3924] | 188 | 'currentapp' => 'filemanager', |
---|
| 189 | 'noheader' => True, |
---|
| 190 | 'nonavbar' => True, |
---|
| 191 | 'nofooter' => True, |
---|
| 192 | 'noappheader' => True, |
---|
[3019] | 193 | 'enable_browser_class' => True |
---|
| 194 | ); |
---|
| 195 | |
---|
| 196 | if ($this->file) |
---|
| 197 | { |
---|
| 198 | $filename=$this->path.'/'.$this->file; |
---|
| 199 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
| 200 | { |
---|
| 201 | echo "False"; |
---|
| 202 | return False; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 206 | 'string' => $filename, |
---|
| 207 | 'relatives' => array(RELATIVE_NONE), |
---|
| 208 | 'checksubdirs' => False, |
---|
| 209 | 'nofiles' => True |
---|
| 210 | )); |
---|
| 211 | if (intval($ls_array[0]['type']) == 0) |
---|
| 212 | $type = 1; |
---|
| 213 | else |
---|
| 214 | $type = 0; |
---|
| 215 | |
---|
| 216 | if($this->bo->vfs->set_attributes (array( |
---|
| 217 | 'string' => $filename, |
---|
| 218 | 'relatives' => RELATIVE_NONE, |
---|
| 219 | 'attributes' => array('type' => $type) |
---|
| 220 | )) |
---|
| 221 | ) |
---|
| 222 | { |
---|
| 223 | echo "True|".$this->file; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | echo "False"; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | } |
---|
| 232 | function touch(){ |
---|
| 233 | if($this->file) |
---|
| 234 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
| 235 | { |
---|
| 236 | echo "True"; |
---|
| 237 | return True; |
---|
| 238 | } |
---|
| 239 | else |
---|
| 240 | return False; |
---|
| 241 | |
---|
| 242 | } |
---|
| 243 | function summary() |
---|
| 244 | { |
---|
| 245 | header('Content-Type: image/png'); |
---|
| 246 | $expires = 60*60*24*15; |
---|
| 247 | header("Cache-Control: maxage=".$expires); |
---|
| 248 | header("Pragma: public"); |
---|
| 249 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
| 250 | if($this->file) |
---|
| 251 | { |
---|
| 252 | $content = $this->bo->vfs->summary(array('path' => $this->path, |
---|
| 253 | 'string' => $this->file |
---|
| 254 | )); |
---|
| 255 | if (strlen($content) < 1) |
---|
| 256 | { |
---|
| 257 | $filename = './filemanager/templates/default/images/error.png'; |
---|
| 258 | $handle = fopen($filename,'rb'); |
---|
| 259 | $content = fread($handle,filesize($filename)); |
---|
| 260 | fclose($handle); |
---|
| 261 | } |
---|
| 262 | echo $content; |
---|
| 263 | } |
---|
| 264 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | function delete(){ |
---|
| 268 | foreach($this->fileman as $filename) |
---|
| 269 | { |
---|
| 270 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array( |
---|
| 271 | 'string' => $this->path.'/'.$filename, |
---|
| 272 | 'relatives' => array (RELATIVE_NONE) |
---|
| 273 | ))) |
---|
| 274 | { |
---|
| 275 | echo $filename."|"; |
---|
| 276 | } |
---|
| 277 | else |
---|
| 278 | { |
---|
| 279 | echo "False|".$filename; |
---|
| 280 | return False; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | function archive(){ |
---|
| 285 | foreach($this->fileman as $filename) |
---|
| 286 | { |
---|
| 287 | if(!$this->verifyLock($filename,RELATIVE_ALL)) |
---|
| 288 | { |
---|
| 289 | echo "locked|".$filename; |
---|
| 290 | return False; |
---|
| 291 | } |
---|
| 292 | $command .= " ".escapeshellarg($filename); |
---|
| 293 | } |
---|
| 294 | $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip"; |
---|
| 295 | $zipFilePath=ini_get("session.save_path")."/".$zipFileName; |
---|
| 296 | $command = $zipFilePath.$command; |
---|
| 297 | |
---|
| 298 | if (strlen($this->pswd) > 0){ |
---|
| 299 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command),$output,$return_var); |
---|
| 303 | exec("history -c"); // privacy is good, we dont want get passwords! |
---|
| 304 | if ($return_var > 1){ |
---|
| 305 | echo "False|".$return_var; |
---|
| 306 | return false; |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | $this->bo->vfs->cp(array( |
---|
| 310 | 'from'=> $zipFilePath, |
---|
| 311 | 'to'=> $zipFileName, |
---|
| 312 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
| 313 | )); |
---|
| 314 | $this->bo->vfs->set_attributes(array( |
---|
| 315 | 'string'=> $zipFileName, |
---|
| 316 | 'relatives' => array(RELATIVE_ALL), |
---|
| 317 | 'attributes'=> array( |
---|
| 318 | 'mime_type' => "application/zip" |
---|
| 319 | ) |
---|
| 320 | )); |
---|
| 321 | exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath))); |
---|
| 322 | $this->delete(); |
---|
| 323 | } |
---|
| 324 | function unarchive(){ |
---|
| 325 | $command = escapeshellarg($this->file); |
---|
| 326 | if (strlen($this->pswd) > 0){ |
---|
| 327 | $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | exec("cd ".escapeshellarg($this->bo->vfs->basedir.$this->path).";".escapeshellcmd("nice -n19 unzip ".$command),$output, $return_var); |
---|
| 331 | exec("history -c"); // privacy is good, we dont want get passwords! |
---|
| 332 | |
---|
| 333 | if ($return_var == 9 || $return_var == 5 || $return_var == 82){ |
---|
| 334 | echo "wpasswd|"; |
---|
| 335 | return false; |
---|
| 336 | }else if($return_var > 1){ |
---|
| 337 | echo "False|"; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | $this->fileman[] = $this->file; |
---|
| 341 | $this->delete(); |
---|
| 342 | $this->bo->vfs->update_real(array( |
---|
| 343 | 'string' => $this->path, |
---|
| 344 | 'relatives' => array(RELATIVE_NONE) |
---|
| 345 | )); |
---|
| 346 | } |
---|
| 347 | function editComment() |
---|
| 348 | { |
---|
| 349 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
| 350 | { |
---|
| 351 | echo "False|badchar|".$badchar; |
---|
| 352 | return False; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | if ($this->bo->vfs->set_attributes(array( |
---|
| 356 | 'string' => $this->file, |
---|
| 357 | 'relatives' => array(RELATIVE_ALL), |
---|
| 358 | 'attributes' => array( |
---|
| 359 | 'comment' => stripslashes($this->comment) |
---|
| 360 | ) |
---|
| 361 | ))) |
---|
| 362 | { |
---|
| 363 | echo "True|".$this->file; |
---|
| 364 | return True; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | # Handle Moving Files and Directories |
---|
| 368 | function moveto() |
---|
| 369 | { |
---|
| 370 | if(!$this->to) |
---|
| 371 | { |
---|
| 372 | echo "NODIR|"; |
---|
| 373 | return; |
---|
| 374 | } |
---|
| 375 | else |
---|
| 376 | { |
---|
| 377 | while(list($num, $file) = each($this->fileman)) |
---|
| 378 | { |
---|
| 379 | if($this->bo->vfs->mv(array( |
---|
| 380 | 'from' => $this->from . '/' . $file, |
---|
| 381 | 'to' => $this->to . '/' . $file, |
---|
| 382 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
| 383 | ))) |
---|
[7655] | 384 | ++$moved; |
---|
[3019] | 385 | else |
---|
[7655] | 386 | ++$error; |
---|
[3019] | 387 | } |
---|
| 388 | } |
---|
| 389 | if($error > 0){ |
---|
| 390 | echo "SOMEERROR|".$error; |
---|
| 391 | return; |
---|
| 392 | } |
---|
| 393 | if($moved > 0) |
---|
| 394 | echo "MOVED|".$moved; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | // Handle Copying of Files and Directories |
---|
| 398 | function copyto() |
---|
| 399 | { |
---|
| 400 | if(!$this->to) |
---|
| 401 | { |
---|
| 402 | echo "NODIR|"; |
---|
| 403 | return; |
---|
| 404 | } |
---|
| 405 | else |
---|
| 406 | { |
---|
| 407 | while(list($num, $file) = each($this->fileman)) |
---|
| 408 | { |
---|
| 409 | if($this->bo->vfs->cp(array( |
---|
| 410 | 'from' => $this->from . '/' . $file, |
---|
| 411 | 'to' => $this->to . '/' . $file, |
---|
| 412 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
| 413 | ))) |
---|
[7655] | 414 | ++$copied; |
---|
[3019] | 415 | else |
---|
[7655] | 416 | ++$error; |
---|
[3019] | 417 | } |
---|
| 418 | } |
---|
| 419 | if($error > 0){ |
---|
| 420 | echo "SOMEERROR|".$error; |
---|
| 421 | return; |
---|
| 422 | } |
---|
| 423 | if($copied > 0) |
---|
| 424 | echo "COPIED|".$copied; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | # Handle Renaming Files and Directories |
---|
| 428 | function rename() |
---|
| 429 | { |
---|
[3913] | 430 | $_return = array(); |
---|
| 431 | |
---|
| 432 | if ( $this->file ) |
---|
[3019] | 433 | { |
---|
[3913] | 434 | if( $badchar = $this->bo->bad_chars($this->to, True, True) ) |
---|
[3019] | 435 | { |
---|
[3913] | 436 | $_return[] = array( "error" => $badchar); |
---|
[3019] | 437 | } |
---|
[5912] | 438 | if(preg_match('/\//', $this->to) || preg_match('/\\\\/', $this->to)) |
---|
[3019] | 439 | { |
---|
[3913] | 440 | $_return[] = array( "error"=> "slashes"); |
---|
[3019] | 441 | } |
---|
| 442 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
[3913] | 443 | { |
---|
| 444 | $_return[] = array( "error" => "editing" ); |
---|
| 445 | } |
---|
[3019] | 446 | elseif ($this->bo->vfs->mv(array( |
---|
[3913] | 447 | 'from' => $this->path.'/'.$this->file, |
---|
| 448 | 'to' => $this->path.'/'.$this->to, |
---|
| 449 | 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) |
---|
[3019] | 450 | ))) |
---|
| 451 | { |
---|
[3913] | 452 | $_return[] = array( "true" => lang('renamed %1 to %2', $this->file ,$this->to ) ); |
---|
[3924] | 453 | |
---|
| 454 | // Get Type Mime Type |
---|
| 455 | $mimeType = $this->bo->vfs->get_ext_mime_type(array ('string' => $this->to )); |
---|
| 456 | |
---|
| 457 | $this->bo->vfs->set_attributes( array( |
---|
| 458 | 'string' => $this->to, |
---|
| 459 | 'relatives' => array(RELATIVE_ALL), |
---|
| 460 | 'attributes' => array('mime_type' => $mimeType) |
---|
| 461 | )); |
---|
[3019] | 462 | } |
---|
| 463 | else |
---|
| 464 | { |
---|
[3924] | 465 | $_return[] = array( "error" => $this->file . " " . $this->to ); |
---|
[3019] | 466 | } |
---|
| 467 | } |
---|
[3913] | 468 | else |
---|
[3924] | 469 | { |
---|
[3913] | 470 | $_return[] = array("error" => "whitout file "); |
---|
[3924] | 471 | } |
---|
[3913] | 472 | |
---|
| 473 | echo serialize( $_return ); |
---|
[3019] | 474 | } |
---|
[3913] | 475 | } |
---|