00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00105 class t3lib_extFileFunctions extends t3lib_basicFileFunctions {
00106
00107
00108
00109 var $maxCopyFileSize = 10000;
00110 var $maxMoveFileSize = 10000;
00111 var $maxUploadFileSize = 10000;
00112 var $unzipPath = '';
00113 var $dontCheckForUnique = 0;
00114
00115 var $actionPerms = Array(
00116 'deleteFile' => 0,
00117 'deleteFolder' => 0,
00118 'deleteFolderRecursively' => 0,
00119 'moveFile' => 0,
00120 'moveFolder' => 0,
00121 'copyFile' => 0,
00122 'copyFolder' => 0,
00123 'newFolder' => 0,
00124 'newFile' => 0,
00125 'editFile' => 0,
00126 'unzipFile' => 0,
00127 'uploadFile' => 0,
00128 'renameFile' => 0,
00129 'renameFolder' => 0
00130 );
00131
00132 var $recyclerFN = '_recycler_';
00133 var $useRecycler = 1;
00134
00135
00136 var $PHPFileFunctions = 0;
00137 var $dont_use_exec_commands = 0;
00138
00139
00140 var $internalUploadMap = array();
00141
00142 var $lastError = '';
00143
00144
00145
00146
00153 function start($fileCmds) {
00154
00155
00156 if (TYPO3_OS=='WIN' || $GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
00157 $this->PHPFileFunctions = 1;
00158 $this->dont_use_exec_commands = 1;
00159 } else {
00160 $this->PHPFileFunctions = $GLOBALS['TYPO3_CONF_VARS']['BE']['usePHPFileFunctions'];
00161 }
00162
00163 $this->unzipPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'];
00164
00165 $maxFileSize = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize']);
00166 if ($maxFileSize>0) {
00167 $this->maxCopyFileSize = $maxFileSize;
00168 $this->maxMoveFileSize = $maxFileSize;
00169 $this->maxUploadFileSize = $maxFileSize;
00170 }
00171
00172
00173 $this->fileCmdMap = $fileCmds;
00174 }
00175
00183 function init_actionPerms($setup) {
00184 if (($setup&1)==1) {
00185 $this->actionPerms['uploadFile']=1;
00186 $this->actionPerms['copyFile']=1;
00187 $this->actionPerms['moveFile']=1;
00188 $this->actionPerms['deleteFile']=1;
00189 $this->actionPerms['renameFile']=1;
00190 $this->actionPerms['editFile']=1;
00191 $this->actionPerms['newFile']=1;
00192 }
00193 if (($setup&2)==2) {
00194 $this->actionPerms['unzipFile']=1;
00195 }
00196 if (($setup&4)==4) {
00197 $this->actionPerms['moveFolder']=1;
00198 $this->actionPerms['deleteFolder']=1;
00199 $this->actionPerms['renameFolder']=1;
00200 $this->actionPerms['newFolder']=1;
00201 }
00202 if (($setup&8)==8) {
00203 $this->actionPerms['copyFolder']=1;
00204 }
00205 if (($setup&16)==16) {
00206 $this->actionPerms['deleteFolderRecursively']=1;
00207 }
00208 }
00209
00215 function processData() {
00216 if (!$this->isInit) return FALSE;
00217
00218 if (is_array($this->fileCmdMap)) {
00219
00220
00221 if ($this->fileCmdMap['upload']) {
00222 $uploads = $this->fileCmdMap['upload'];
00223 foreach ($uploads as $arr) {
00224 if (!$_FILES['upload_'.$arr['data']]['name']) {
00225 unset($this->fileCmdMap['upload'][$arr['data']]);
00226 }
00227 }
00228 if (count($this->fileCmdMap['upload']) == 0) {
00229 $this->writelog(1,1,108,'No file was uploaded!','');
00230 }
00231 }
00232
00233
00234 foreach($this->fileCmdMap as $action => $actionData) {
00235
00236
00237 if (is_array($actionData)) {
00238 foreach($actionData as $cmdArr) {
00239
00240
00241 clearstatcache();
00242
00243
00244 switch ($action) {
00245 case 'delete':
00246 $this->func_delete($cmdArr);
00247 break;
00248 case 'copy':
00249 $this->func_copy($cmdArr);
00250 break;
00251 case 'move':
00252 $this->func_move($cmdArr);
00253 break;
00254 case 'rename':
00255 $this->func_rename($cmdArr);
00256 break;
00257 case 'newfolder':
00258 $this->func_newfolder($cmdArr);
00259 break;
00260 case 'newfile':
00261 $this->func_newfile($cmdArr);
00262 break;
00263 case 'editfile':
00264 $this->func_edit($cmdArr);
00265 break;
00266 case 'upload':
00267 $this->func_upload($cmdArr);
00268 break;
00269 case 'unzip':
00270 $this->func_unzip($cmdArr);
00271 break;
00272 }
00273 }
00274 }
00275 }
00276 }
00277 }
00278
00285 function printLogErrorMessages($redirect='') {
00286
00287 $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00288 '*',
00289 'sys_log',
00290 'type=2 AND userid='.intval($GLOBALS['BE_USER']->user['uid']).' AND tstamp='.intval($GLOBALS['EXEC_TIME']).' AND error!=0'
00291 );
00292 $errorJS = array();
00293 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) {
00294 $log_data = unserialize($row['log_data']);
00295 $errorJS[] = $row[error].': '.sprintf($row['details'], $log_data[0],$log_data[1],$log_data[2],$log_data[3],$log_data[4]);
00296 }
00297
00298 if (count($errorJS)) {
00299 $error_doc = t3lib_div::makeInstance('template');
00300 $error_doc->backPath = '';
00301
00302 $content.= $error_doc->startPage('tce_db.php Error output');
00303
00304 $lines[] = '
00305 <tr class="bgColor5">
00306 <td colspan="2" align="center"><strong>Errors:</strong></td>
00307 </tr>';
00308
00309 foreach($errorJS as $line) {
00310 $lines[] = '
00311 <tr class="bgColor4">
00312 <td valign="top"><img'.t3lib_iconWorks::skinImg('','gfx/icon_fatalerror.gif','width="18" height="16"').' alt="" /></td>
00313 <td>'.htmlspecialchars($line).'</td>
00314 </tr>';
00315 }
00316
00317 $lines[] = '
00318 <tr>
00319 <td colspan="2" align="center"><br />'.
00320 '<form action=""><input type="submit" value="Continue" onclick="'.htmlspecialchars('window.location.href=\''.$redirect.'\';return false;').'" /></form>'.
00321 '</td>
00322 </tr>';
00323
00324 $content.= '
00325 <br /><br />
00326 <table border="0" cellpadding="1" cellspacing="1" width="300" align="center">
00327 '.implode('',$lines).'
00328 </table>';
00329
00330 $content.= $error_doc->endPage();
00331 echo $content;
00332 exit;
00333 }
00334 }
00335
00343 function findRecycler($theFile) {
00344 if ($this->isPathValid($theFile)) {
00345 $theFile = $this->cleanDirectoryName($theFile);
00346 $fI = t3lib_div::split_fileref($theFile);
00347 $c = 0;
00348 while($this->checkPathAgainstMounts($fI['path']) && $c<20) {
00349 $rDir = $fI['path'].$this->recyclerFN;
00350 if (@is_dir($rDir) && $this->recyclerFN!=$fI['file']) {
00351 return $rDir;
00352 }
00353 $theFile = $fI['path'];
00354 $theFile = $this->cleanDirectoryName($theFile);
00355 $fI = t3lib_div::split_fileref($theFile);
00356 $c++;
00357 }
00358 }
00359 }
00360
00372 function writeLog($action,$error,$details_nr,$details,$data) {
00373 $type = 2;
00374 if (is_object($GLOBALS['BE_USER'])) {
00375 $GLOBALS['BE_USER']->writelog($type,$action,$error,$details_nr,$details,$data);
00376 }
00377 $this->lastError = vsprintf($details, $data);
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00400 function func_delete($cmds) {
00401 if (!$this->isInit) return FALSE;
00402
00403
00404 $theFile = $cmds['data'];
00405 if (!$this->isPathValid($theFile)) {
00406 $this->writelog(4,2,101,'Target "%s" had invalid path (".." and "//" is not allowed in path).',Array($theFile));
00407 return FALSE;
00408 }
00409
00410
00411 if ($this->useRecycler && $recyclerPath=$this->findRecycler($theFile)) {
00412
00413 $newCmds=Array();
00414 $newCmds['data']=$theFile;
00415 $newCmds['target']=$recyclerPath;
00416 $newCmds['altName']=1;
00417 $this->func_move($newCmds);
00418 $this->writelog(4,0,4,'Item "%s" moved to recycler at "%s"',Array($theFile,$recyclerPath));
00419 return TRUE;
00420 } elseif ($this->useRecycler != 2) {
00421 if (@is_file($theFile)) {
00422 if ($this->actionPerms['deleteFile']) {
00423 if ($this->checkPathAgainstMounts($theFile)) {
00424 if (@unlink($theFile)) {
00425 $this->writelog(4,0,1,'File "%s" deleted',Array($theFile));
00426 return TRUE;
00427 } else $this->writelog(4,1,110,'Could not delete file "%s". Write-permission problem?', Array($theFile));
00428 } else $this->writelog(4,1,111,'Target was not within your mountpoints! T="%s"',Array($theFile));
00429 } else $this->writelog(4,1,112,'You are not allowed to delete files','');
00430
00431
00432 } elseif (@is_dir($theFile)) {
00433 if ($this->actionPerms['deleteFolder']) {
00434 $theFile = $this->is_directory($theFile);
00435 if ($theFile) {
00436 if ($this->checkPathAgainstMounts($theFile)) {
00437 if ($this->actionPerms['deleteFolderRecursively'] && !$this->dont_use_exec_commands) {
00438
00439 $cmd = 'rm -Rf "'.$theFile.'"';
00440 exec($cmd);
00441 clearstatcache();
00442 if (!@file_exists($theFile)) {
00443 $this->writelog(4,0,2,'Directory "%s" deleted recursively!',Array($theFile));
00444 return TRUE;
00445 } else $this->writelog(4,2,119,'Directory "%s" WAS NOT deleted recursively! Write-permission problem?',Array($theFile));
00446 } else {
00447 if (@rmdir($theFile)) {
00448 $this->writelog(4,0,3,'Directory "%s" deleted',Array($theFile));
00449 return TRUE;
00450 } else $this->writelog(4,1,120,'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).',Array($theFile));
00451 }
00452 } else $this->writelog(4,1,121,'Target was not within your mountpoints! T="%s"',Array($theFile));
00453 } else $this->writelog(4,2,122,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00454 } else $this->writelog(4,1,123,'You are not allowed to delete directories','');
00455
00456
00457 } else $this->writelog(4,2,130,'The item was not a file or directory! "%s"',Array($theFile));
00458 } else $this->writelog(4,1,131,'No recycler found!','');
00459 }
00460
00467 function func_copy($cmds) {
00468 if (!$this->isInit) return FALSE;
00469
00470
00471 $theFile = $cmds['data'];
00472 $theDest = $this->is_directory($cmds['target']);
00473 $altName = $cmds['altName'];
00474 if (!$theDest) {
00475 $this->writelog(2,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00476 return FALSE;
00477 }
00478 if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
00479 $this->writelog(2,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00480 return FALSE;
00481 }
00482
00483
00484 if (@is_file($theFile)) {
00485 if ($this->actionPerms['copyFile']) {
00486 if (filesize($theFile) < ($this->maxCopyFileSize*1024)) {
00487 $fI = t3lib_div::split_fileref($theFile);
00488 if ($altName) {
00489 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00490 $fI = t3lib_div::split_fileref($theDestFile);
00491 } else {
00492 $theDestFile = $theDest.'/'.$fI['file'];
00493 }
00494 if ($theDestFile && !@file_exists($theDestFile)) {
00495 if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00496 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00497 if ($this->PHPFileFunctions) {
00498 copy ($theFile,$theDestFile);
00499 } else {
00500 $cmd = 'cp "'.$theFile.'" "'.$theDestFile.'"';
00501 exec($cmd);
00502 }
00503 t3lib_div::fixPermissions($theDestFile);
00504 clearstatcache();
00505 if (@is_file($theDestFile)) {
00506 $this->writelog(2,0,1,'File "%s" copied to "%s"',Array($theFile,$theDestFile));
00507 return $theDestFile;
00508 } else $this->writelog(2,2,109,'File "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00509 } else $this->writelog(2,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00510 } else $this->writelog(2,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00511 } else $this->writelog(2,1,112,'File "%s" already exists!',Array($theDestFile));
00512 } else $this->writelog(2,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxCopyFileSize*1024));
00513 } else $this->writelog(2,1,114,'You are not allowed to copy files','');
00514
00515
00516 } elseif (@is_dir($theFile) && !$this->dont_use_exec_commands) {
00517 if ($this->actionPerms['copyFolder']) {
00518 $theFile = $this->is_directory($theFile);
00519 if ($theFile) {
00520 $fI = t3lib_div::split_fileref($theFile);
00521 if ($altName) {
00522 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00523 $fI = t3lib_div::split_fileref($theDestFile);
00524 } else {
00525 $theDestFile = $theDest.'/'.$fI['file'];
00526 }
00527 if ($theDestFile && !@file_exists($theDestFile)) {
00528 if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/')) {
00529 if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile)) {
00530 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00531
00532 $cmd = 'cp -R "'.$theFile.'" "'.$theDestFile.'"';
00533 exec($cmd);
00534 clearstatcache();
00535 if (@is_dir($theDestFile)) {
00536 $this->writelog(2,0,2,'Directory "%s" copied to "%s"',Array($theFile,$theDestFile));
00537 return $theDestFile;
00538 } else $this->writelog(2,2,119,'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00539 } else $this->writelog(2,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00540 } else $this->writelog(2,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00541 } else $this->writelog(2,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00542 } else $this->writelog(2,1,123,'Target "%s" already exists!',Array($theDestFile));
00543 } else $this->writelog(2,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00544 } else $this->writelog(2,1,125,'You are not allowed to copy directories','');
00545
00546
00547 } else {
00548 $this->writelog(2,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00549 }
00550 }
00551
00558 function func_move($cmds) {
00559 if (!$this->isInit) return FALSE;
00560
00561
00562 $theFile = $cmds['data'];
00563 $theDest = $this->is_directory($cmds['target']);
00564 $altName = $cmds['altName'];
00565 if (!$theDest) {
00566 $this->writelog(3,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00567 return FALSE;
00568 }
00569 if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
00570 $this->writelog(3,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00571 return FALSE;
00572 }
00573
00574
00575 if (@is_file($theFile)) {
00576 if ($this->actionPerms['moveFile']) {
00577 if (filesize($theFile) < ($this->maxMoveFileSize*1024)) {
00578 $fI = t3lib_div::split_fileref($theFile);
00579 if ($altName) {
00580 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00581 $fI = t3lib_div::split_fileref($theDestFile);
00582 } else {
00583 $theDestFile = $theDest.'/'.$fI['file'];
00584 }
00585 if ($theDestFile && !@file_exists($theDestFile)) {
00586 if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00587 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00588 if ($this->PHPFileFunctions) {
00589 rename($theFile, $theDestFile);
00590 } else {
00591 $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00592 exec($cmd);
00593 }
00594 clearstatcache();
00595 if (@is_file($theDestFile)) {
00596 $this->writelog(3,0,1,'File "%s" moved to "%s"',Array($theFile,$theDestFile));
00597 return $theDestFile;
00598 } else $this->writelog(3,2,109,'File "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00599 } else $this->writelog(3,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00600 } else $this->writelog(3,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00601 } else $this->writelog(3,1,112,'File "%s" already exists!',Array($theDestFile));
00602 } else $this->writelog(3,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxMoveFileSize*1024));
00603 } else $this->writelog(3,1,114,'You are not allowed to move files','');
00604
00605
00606 } elseif (@is_dir($theFile)) {
00607 if ($this->actionPerms['moveFolder']) {
00608 $theFile = $this->is_directory($theFile);
00609 if ($theFile) {
00610 $fI = t3lib_div::split_fileref($theFile);
00611 if ($altName) {
00612 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00613 $fI = t3lib_div::split_fileref($theDestFile);
00614 } else {
00615 $theDestFile = $theDest.'/'.$fI['file'];
00616 }
00617 if ($theDestFile && !@file_exists($theDestFile)) {
00618 if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/')) {
00619 if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile)) {
00620 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00621 if ($this->PHPFileFunctions) {
00622 rename($theFile, $theDestFile);
00623 } else {
00624 $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00625 $errArr = array();
00626 $retVar = 0;
00627 exec($cmd,$errArr,$retVar);
00628 }
00629 clearstatcache();
00630 if (@is_dir($theDestFile)) {
00631 $this->writelog(3,0,2,'Directory "%s" moved to "%s"',Array($theFile,$theDestFile));
00632 return $theDestFile;
00633 } else $this->writelog(3,2,119,'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00634 } else $this->writelog(3,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00635 } else $this->writelog(3,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00636 } else $this->writelog(3,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00637 } else $this->writelog(3,1,123,'Target "%s" already exists!',Array($theDestFile));
00638 } else $this->writelog(3,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00639 } else $this->writelog(3,1,125,'You are not allowed to move directories','');
00640
00641
00642 } else {
00643 $this->writelog(3,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00644 }
00645 }
00646
00653 function func_rename($cmds) {
00654 if (!$this->isInit) return FALSE;
00655
00656 $theNewName = $this->cleanFileName($cmds['data']);
00657 if ($theNewName) {
00658 if ($this->checkFileNameLen($theNewName)) {
00659 $theTarget = $cmds['target'];
00660 $type = filetype($theTarget);
00661 if ($type=='file' || $type=='dir') {
00662 $fileInfo = t3lib_div::split_fileref($theTarget);
00663 if ($fileInfo['file']!=$theNewName) {
00664 $theRenameName = $fileInfo['path'].$theNewName;
00665 if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00666 if (!@file_exists($theRenameName)) {
00667 if ($type=='file') {
00668 if ($this->actionPerms['renameFile']) {
00669 $fI = t3lib_div::split_fileref($theRenameName);
00670 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00671 if (@rename($theTarget, $theRenameName)) {
00672 $this->writelog(5,0,1,'File renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00673 return $theRenameName;
00674 } else $this->writelog(5,1,100,'File "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00675 } else $this->writelog(5,1,101,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00676 } else $this->writelog(5,1,102,'You are not allowed to rename files!','');
00677 } elseif ($type=='dir') {
00678 if ($this->actionPerms['renameFolder']) {
00679 if (@rename($theTarget, $theRenameName)) {
00680 $this->writelog(5,0,2,'Directory renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00681 return $theRenameName;
00682 } else $this->writelog(5,1,110,'Directory "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00683 } else $this->writelog(5,1,111,'You are not allowed to rename directories!','');
00684 }
00685 } else $this->writelog(5,1,120,'Destination "%s" existed already!',Array($theRenameName));
00686 } else $this->writelog(5,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00687 } else $this->writelog(5,1,122,'Old and new name is the same (%s)',Array($theNewName));
00688 } else $this->writelog(5,2,123,'Target "%s" was neither a directory nor a file!',Array($theTarget));
00689 } else $this->writelog(5,1,124,'New name "%s" was too long (max %s characters)',Array($theNewName,$this->maxInputNameLen));
00690 }
00691 }
00692
00699 function func_newfolder($cmds) {
00700 if (!$this->isInit) return FALSE;
00701
00702 $theFolder = $this->cleanFileName($cmds['data']);
00703 if ($theFolder) {
00704 if ($this->checkFileNameLen($theFolder)) {
00705 $theTarget = $this->is_directory($cmds['target']);
00706 if ($theTarget) {
00707 if ($this->actionPerms['newFolder']) {
00708 $theNewFolder = $theTarget.'/'.$theFolder;
00709 if ($this->checkPathAgainstMounts($theNewFolder)) {
00710 if (!@file_exists($theNewFolder)) {
00711 if (t3lib_div::mkdir($theNewFolder)){
00712 $this->writelog(6,0,1,'Directory "%s" created in "%s"',Array($theFolder,$theTarget.'/'));
00713 return $theNewFolder;
00714 } else $this->writelog(6,1,100,'Directory "%s" not created. Write-permission problem in "%s"?',Array($theFolder,$theTarget.'/'));
00715 } else $this->writelog(6,1,101,'File or directory "%s" existed already!',Array($theNewFolder));
00716 } else $this->writelog(6,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00717 } else $this->writelog(6,1,103,'You are not allowed to create directories!','');
00718 } else $this->writelog(6,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00719 } else $this->writelog(6,1,105,'New name "%s" was too long (max %s characters)',Array($theFolder,$this->maxInputNameLen));
00720 }
00721 }
00722
00729 function func_newfile($cmds) {
00730 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00731 if (!$this->isInit) return FALSE;
00732 $newName = $this->cleanFileName($cmds['data']);
00733 if ($newName) {
00734 if ($this->checkFileNameLen($newName)) {
00735 $theTarget = $this->is_directory($cmds['target']);
00736 $fileInfo = t3lib_div::split_fileref($theTarget);
00737 if ($theTarget) {
00738 if ($this->actionPerms['newFile']) {
00739 $theNewFile = $theTarget.'/'.$newName;
00740 if ($this->checkPathAgainstMounts($theNewFile)) {
00741 if (!@file_exists($theNewFile)) {
00742 $fI = t3lib_div::split_fileref($theNewFile);
00743 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00744 if (t3lib_div::inList($extList, $fI['fileext'])) {
00745 if (t3lib_div::writeFile($theNewFile,'')) {
00746 clearstatcache();
00747 $this->writelog(8,0,1,'File created: "%s"',Array($fI['file']));
00748 return $theNewFile;
00749 } else $this->writelog(8,1,100,'File "%s" was not created! Write-permission problem in "%s"?',Array($fI['file'], $theTarget));
00750 } else $this->writelog(8,1,107,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00751 } else $this->writelog(8,1,106,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00752 } else $this->writelog(8,1,101,'File "%s" existed already!',Array($theNewFile));
00753 } else $this->writelog(8,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00754 } else $this->writelog(8,1,103,'You are not allowed to create files!','');
00755 } else $this->writelog(8,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00756 } else $this->writelog(8,1,105,'New name "%s" was too long (max %s characters)',Array($newName,$this->maxInputNameLen));
00757 }
00758 }
00759
00766 function func_edit($cmds) {
00767 if (!$this->isInit) return FALSE;
00768 $theTarget = $cmds['target'];
00769 $content = $cmds['data'];
00770 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00771 $type = filetype($theTarget);
00772 if ($type=='file') {
00773 $fileInfo = t3lib_div::split_fileref($theTarget);
00774 $fI =$fileInfo;
00775 if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00776 if ($this->actionPerms['editFile']) {
00777 $fI = t3lib_div::split_fileref($theTarget);
00778 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00779 if (t3lib_div::inList($extList, $fileInfo['fileext'])) {
00780 if (t3lib_div::writeFile($theTarget,$content)) {
00781 clearstatcache();
00782 $this->writelog(9,0,1,'File saved to "%s", bytes: %s, MD5: %s ',Array($fileInfo['file'],@filesize($theTarget),md5($content)));
00783 return TRUE;
00784 } else $this->writelog(9,1,100,'File "%s" was not saved! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00785 } else $this->writelog(9,1,102,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00786 } else $this->writelog(9,1,103,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00787 } else $this->writelog(9,1,104,'You are not allowed to edit files!','');
00788 } else $this->writelog(9,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00789 } else $this->writelog(9,2,123,'Target "%s" was not a file!',Array($theTarget));
00790 }
00791
00798 function func_upload($cmds) {
00799 if (!$this->isInit) return FALSE;
00800 $id = $cmds['data'];
00801 if ($_FILES['upload_'.$id]['name']) {
00802 $theFile = $_FILES['upload_'.$id]['tmp_name'];
00803 $theFileSize = $_FILES['upload_'.$id]['size'];
00804 $theName = $this->cleanFileName(stripslashes($_FILES['upload_'.$id]['name']));
00805 if (is_uploaded_file($theFile) && $theName) {
00806 if ($this->actionPerms['uploadFile']) {
00807 if ($theFileSize<($this->maxUploadFileSize*1024)) {
00808 $fI = t3lib_div::split_fileref($theName);
00809 $theTarget = $this->is_directory($cmds['target']);
00810 if ($theTarget && $this->checkPathAgainstMounts($theTarget.'/')) {
00811 if ($this->checkIfAllowed($fI['fileext'], $theTarget, $fI['file'])) {
00812 $theNewFile = $this->getUniqueName($theName, $theTarget, $this->dontCheckForUnique);
00813 if ($theNewFile) {
00814 t3lib_div::upload_copy_move($theFile,$theNewFile);
00815 clearstatcache();
00816 if (@is_file($theNewFile)) {
00817 $this->internalUploadMap[$id] = $theNewFile;
00818 $this->writelog(1,0,1,'Uploading file "%s" to "%s"',Array($theName,$theNewFile, $id));
00819 return $theNewFile;
00820 } else $this->writelog(1,1,100,'Uploaded file could not be moved! Write-permission problem in "%s"?',Array($theTarget.'/'));
00821 } else $this->writelog(1,1,101,'No unique filename available in "%s"!',Array($theTarget.'/'));
00822 } else $this->writelog(1,1,102,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theTarget.'/'));
00823 } else $this->writelog(1,1,103,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00824 } else $this->writelog(1,1,104,'The uploaded file exceeds the size-limit of %s bytes',Array($this->maxUploadFileSize*1024));
00825 } else $this->writelog(1,1,105,'You are not allowed to upload files!','');
00826 } else $this->writelog(1,2,106,'The uploaded file did not exist!','');
00827 } else $this->writelog(1,2,108,'No file was uploaded!','');
00828 }
00829
00837 function func_unzip($cmds) {
00838 if (!$this->isInit || $this->dont_use_exec_commands) return FALSE;
00839
00840 $theFile = $cmds['data'];
00841 if (@is_file($theFile)) {
00842 $fI = t3lib_div::split_fileref($theFile);
00843 if (!isset($cmds['target'])) {
00844 $cmds['target'] = $fI['path'];
00845 }
00846 $theDest = $this->is_directory($cmds['target']);
00847 if ($theDest) {
00848 if ($this->actionPerms['unzipFile']) {
00849 if ($fI['fileext']=='zip') {
00850 if ($this->checkIfFullAccess($theDest)) {
00851 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest.'/')) {
00852
00853 $cmd = $this->unzipPath.'unzip -qq "'.$theFile.'" -d "'.$theDest.'"';
00854 exec($cmd);
00855 $this->writelog(7,0,1,'Unzipping file "%s" in "%s"',Array($theFile,$theDest));
00856 return TRUE;
00857 } else $this->writelog(7,1,100,'File "%s" or destination "%s" was not within your mountpoints!',Array($theFile,$theDest));
00858 } else $this->writelog(7,1,101,'You don\'t have full access to the destination directory "%s"!',Array($theDest));
00859 } else $this->writelog(7,1,102,'Fileextension is not "zip"','');
00860 } else $this->writelog(7,1,103,'You are not allowed to unzip files','');
00861 } else $this->writelog(7,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00862 } else $this->writelog(7,2,105,'The file "%s" did not exist!',Array($theFile));
00863 }
00864 }
00865
00866 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php']) {
00867 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php']);
00868 }
00869 ?>