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
00143
00144
00151 function start($fileCmds) {
00152
00153
00154 if (TYPO3_OS=='WIN' || $GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
00155 $this->PHPFileFunctions = 1;
00156 $this->dont_use_exec_commands = 1;
00157 } else {
00158 $this->PHPFileFunctions = $GLOBALS['TYPO3_CONF_VARS']['BE']['usePHPFileFunctions'];
00159 }
00160
00161 $this->unzipPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'];
00162
00163 $maxFileSize = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize']);
00164 if ($maxFileSize>0) {
00165 $this->maxCopyFileSize = $maxFileSize;
00166 $this->maxMoveFileSize = $maxFileSize;
00167 $this->maxUploadFileSize = $maxFileSize;
00168 }
00169
00170
00171 $this->fileCmdMap = $fileCmds;
00172 }
00173
00181 function init_actionPerms($setup) {
00182 if (($setup&1)==1) {
00183 $this->actionPerms['uploadFile']=1;
00184 $this->actionPerms['copyFile']=1;
00185 $this->actionPerms['moveFile']=1;
00186 $this->actionPerms['deleteFile']=1;
00187 $this->actionPerms['renameFile']=1;
00188 $this->actionPerms['editFile']=1;
00189 $this->actionPerms['newFile']=1;
00190 }
00191 if (($setup&2)==2) {
00192 $this->actionPerms['unzipFile']=1;
00193 }
00194 if (($setup&4)==4) {
00195 $this->actionPerms['moveFolder']=1;
00196 $this->actionPerms['deleteFolder']=1;
00197 $this->actionPerms['renameFolder']=1;
00198 $this->actionPerms['newFolder']=1;
00199 }
00200 if (($setup&8)==8) {
00201 $this->actionPerms['copyFolder']=1;
00202 }
00203 if (($setup&16)==16) {
00204 $this->actionPerms['deleteFolderRecursively']=1;
00205 }
00206 }
00207
00213 function processData() {
00214 if (!$this->isInit) return FALSE;
00215
00216 if (is_array($this->fileCmdMap)) {
00217
00218
00219 foreach($this->fileCmdMap as $action => $actionData) {
00220
00221
00222 if (is_array($actionData)) {
00223 foreach($actionData as $cmdArr) {
00224
00225
00226 clearstatcache();
00227
00228
00229 switch ($action) {
00230 case 'delete':
00231 $this->func_delete($cmdArr);
00232 break;
00233 case 'copy':
00234 $this->func_copy($cmdArr);
00235 break;
00236 case 'move':
00237 $this->func_move($cmdArr);
00238 break;
00239 case 'rename':
00240 $this->func_rename($cmdArr);
00241 break;
00242 case 'newfolder':
00243 $this->func_newfolder($cmdArr);
00244 break;
00245 case 'newfile':
00246 $this->func_newfile($cmdArr);
00247 break;
00248 case 'editfile':
00249 $this->func_edit($cmdArr);
00250 break;
00251 case 'upload':
00252 $this->func_upload($cmdArr);
00253 break;
00254 case 'unzip':
00255 $this->func_unzip($cmdArr);
00256 break;
00257 }
00258 }
00259 }
00260 }
00261 }
00262 }
00263
00270 function printLogErrorMessages($redirect='') {
00271
00272 $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00273 '*',
00274 'sys_log',
00275 'type=2 AND userid='.intval($GLOBALS['BE_USER']->user['uid']).' AND tstamp='.intval($GLOBALS['EXEC_TIME']).' AND error!=0'
00276 );
00277 $errorJS = array();
00278 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) {
00279 $log_data = unserialize($row['log_data']);
00280 $errorJS[] = $row[error].': '.sprintf($row['details'], $log_data[0],$log_data[1],$log_data[2],$log_data[3],$log_data[4]);
00281 }
00282
00283 if (count($errorJS)) {
00284 $error_doc = t3lib_div::makeInstance('template');
00285 $error_doc->backPath = '';
00286
00287 $content.= $error_doc->startPage('tce_db.php Error output');
00288
00289 $lines[] = '
00290 <tr class="bgColor5">
00291 <td colspan="2" align="center"><strong>Errors:</strong></td>
00292 </tr>';
00293
00294 foreach($errorJS as $line) {
00295 $lines[] = '
00296 <tr class="bgColor4">
00297 <td valign="top"><img'.t3lib_iconWorks::skinImg('','gfx/icon_fatalerror.gif','width="18" height="16"').' alt="" /></td>
00298 <td>'.htmlspecialchars($line).'</td>
00299 </tr>';
00300 }
00301
00302 $lines[] = '
00303 <tr>
00304 <td colspan="2" align="center"><br />'.
00305 '<form action=""><input type="submit" value="Continue" onclick="'.htmlspecialchars('window.location.href=\''.$redirect.'\';return false;').'" /></form>'.
00306 '</td>
00307 </tr>';
00308
00309 $content.= '
00310 <br /><br />
00311 <table border="0" cellpadding="1" cellspacing="1" width="300" align="center">
00312 '.implode('',$lines).'
00313 </table>';
00314
00315 $content.= $error_doc->endPage();
00316 echo $content;
00317 exit;
00318 }
00319 }
00320
00328 function findRecycler($theFile) {
00329 if ($this->isPathValid($theFile)) {
00330 $theFile = $this->cleanDirectoryName($theFile);
00331 $fI = t3lib_div::split_fileref($theFile);
00332 $c = 0;
00333 while($this->checkPathAgainstMounts($fI['path']) && $c<20) {
00334 $rDir = $fI['path'].$this->recyclerFN;
00335 if (@is_dir($rDir) && $this->recyclerFN!=$fI['file']) {
00336 return $rDir;
00337 }
00338 $theFile = $fI['path'];
00339 $theFile = $this->cleanDirectoryName($theFile);
00340 $fI = t3lib_div::split_fileref($theFile);
00341 $c++;
00342 }
00343 }
00344 }
00345
00357 function writeLog($action,$error,$details_nr,$details,$data) {
00358 $type = 2;
00359 if (is_object($GLOBALS['BE_USER'])) {
00360 $GLOBALS['BE_USER']->writelog($type,$action,$error,$details_nr,$details,$data);
00361 }
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00384 function func_delete($cmds) {
00385 if (!$this->isInit) return FALSE;
00386
00387
00388 $theFile = $cmds['data'];
00389 if (!$this->isPathValid($theFile)) {
00390 $this->writelog(4,2,101,'Target "%s" had invalid path (".." and "//" is not allowed in path).',Array($theFile));
00391 return FALSE;
00392 }
00393
00394
00395 if ($this->useRecycler && $recyclerPath=$this->findRecycler($theFile)) {
00396
00397 $newCmds=Array();
00398 $newCmds['data']=$theFile;
00399 $newCmds['target']=$recyclerPath;
00400 $newCmds['altName']=1;
00401 $this->func_move($newCmds);
00402 $this->writelog(4,0,4,'Item "%s" moved to recycler at "%s"',Array($theFile,$recyclerPath));
00403 return TRUE;
00404 } elseif ($this->useRecycler != 2) {
00405 if (@is_file($theFile)) {
00406 if ($this->actionPerms['deleteFile']) {
00407 if ($this->checkPathAgainstMounts($theFile)) {
00408 if (@unlink($theFile)) {
00409 $this->writelog(4,0,1,'File "%s" deleted',Array($theFile));
00410 return TRUE;
00411 } else $this->writelog(4,1,110,'Could not delete file "%s". Write-permission problem?', Array($theFile));
00412 } else $this->writelog(4,1,111,'Target was not within your mountpoints! T="%s"',Array($theFile));
00413 } else $this->writelog(4,1,112,'You are not allowed to delete files','');
00414
00415
00416 } elseif (@is_dir($theFile)) {
00417 if ($this->actionPerms['deleteFolder']) {
00418 $theFile = $this->is_directory($theFile);
00419 if ($theFile) {
00420 if ($this->checkPathAgainstMounts($theFile)) {
00421 if ($this->actionPerms['deleteFolderRecursively'] && !$this->dont_use_exec_commands) {
00422
00423 $cmd = 'rm -Rf "'.$theFile.'"';
00424 exec($cmd);
00425 clearstatcache();
00426 if (!@file_exists($theFile)) {
00427 $this->writelog(4,0,2,'Directory "%s" deleted recursively!',Array($theFile));
00428 return TRUE;
00429 } else $this->writelog(4,2,119,'Directory "%s" WAS NOT deleted recursively! Write-permission problem?',Array($theFile));
00430 } else {
00431 if (@rmdir($theFile)) {
00432 $this->writelog(4,0,3,'Directory "%s" deleted',Array($theFile));
00433 return TRUE;
00434 } 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));
00435 }
00436 } else $this->writelog(4,1,121,'Target was not within your mountpoints! T="%s"',Array($theFile));
00437 } else $this->writelog(4,2,122,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00438 } else $this->writelog(4,1,123,'You are not allowed to delete directories','');
00439
00440
00441 } else $this->writelog(4,2,130,'The item was not a file or directory! "%s"',Array($theFile));
00442 } else $this->writelog(4,1,131,'No recycler found!','');
00443 }
00444
00451 function func_copy($cmds) {
00452 if (!$this->isInit) return FALSE;
00453
00454
00455 $theFile = $cmds['data'];
00456 $theDest = $this->is_directory($cmds['target']);
00457 $altName = $cmds['altName'];
00458 if (!$theDest) {
00459 $this->writelog(2,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00460 return FALSE;
00461 }
00462 if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
00463 $this->writelog(2,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00464 return FALSE;
00465 }
00466
00467
00468 if (@is_file($theFile)) {
00469 if ($this->actionPerms['copyFile']) {
00470 if (filesize($theFile) < ($this->maxCopyFileSize*1024)) {
00471 $fI = t3lib_div::split_fileref($theFile);
00472 if ($altName) {
00473 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00474 $fI = t3lib_div::split_fileref($theDestFile);
00475 } else {
00476 $theDestFile = $theDest.'/'.$fI['file'];
00477 }
00478 if ($theDestFile && !@file_exists($theDestFile)) {
00479 if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00480 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00481 if ($this->PHPFileFunctions) {
00482 copy ($theFile,$theDestFile);
00483 } else {
00484 $cmd = 'cp "'.$theFile.'" "'.$theDestFile.'"';
00485 exec($cmd);
00486 }
00487 t3lib_div::fixPermissions($theDestFile);
00488 clearstatcache();
00489 if (@is_file($theDestFile)) {
00490 $this->writelog(2,0,1,'File "%s" copied to "%s"',Array($theFile,$theDestFile));
00491 return $theDestFile;
00492 } else $this->writelog(2,2,109,'File "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00493 } else $this->writelog(2,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00494 } else $this->writelog(2,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00495 } else $this->writelog(2,1,112,'File "%s" already exists!',Array($theDestFile));
00496 } else $this->writelog(2,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxCopyFileSize*1024));
00497 } else $this->writelog(2,1,114,'You are not allowed to copy files','');
00498
00499
00500 } elseif (@is_dir($theFile) && !$this->dont_use_exec_commands) {
00501 if ($this->actionPerms['copyFolder']) {
00502 $theFile = $this->is_directory($theFile);
00503 if ($theFile) {
00504 $fI = t3lib_div::split_fileref($theFile);
00505 if ($altName) {
00506 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00507 $fI = t3lib_div::split_fileref($theDestFile);
00508 } else {
00509 $theDestFile = $theDest.'/'.$fI['file'];
00510 }
00511 if ($theDestFile && !@file_exists($theDestFile)) {
00512 if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/')) {
00513 if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile)) {
00514 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00515
00516 $cmd = 'cp -R "'.$theFile.'" "'.$theDestFile.'"';
00517 exec($cmd);
00518 clearstatcache();
00519 if (@is_dir($theDestFile)) {
00520 $this->writelog(2,0,2,'Directory "%s" copied to "%s"',Array($theFile,$theDestFile));
00521 return $theDestFile;
00522 } else $this->writelog(2,2,119,'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00523 } else $this->writelog(2,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00524 } else $this->writelog(2,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00525 } else $this->writelog(2,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00526 } else $this->writelog(2,1,123,'Target "%s" already exists!',Array($theDestFile));
00527 } else $this->writelog(2,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00528 } else $this->writelog(2,1,125,'You are not allowed to copy directories','');
00529
00530
00531 } else {
00532 $this->writelog(2,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00533 }
00534 }
00535
00542 function func_move($cmds) {
00543 if (!$this->isInit) return FALSE;
00544
00545
00546 $theFile = $cmds['data'];
00547 $theDest = $this->is_directory($cmds['target']);
00548 $altName = $cmds['altName'];
00549 if (!$theDest) {
00550 $this->writelog(3,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00551 return FALSE;
00552 }
00553 if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest)) {
00554 $this->writelog(3,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00555 return FALSE;
00556 }
00557
00558
00559 if (@is_file($theFile)) {
00560 if ($this->actionPerms['moveFile']) {
00561 if (filesize($theFile) < ($this->maxMoveFileSize*1024)) {
00562 $fI = t3lib_div::split_fileref($theFile);
00563 if ($altName) {
00564 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00565 $fI = t3lib_div::split_fileref($theDestFile);
00566 } else {
00567 $theDestFile = $theDest.'/'.$fI['file'];
00568 }
00569 if ($theDestFile && !@file_exists($theDestFile)) {
00570 if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00571 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00572 if ($this->PHPFileFunctions) {
00573 rename($theFile, $theDestFile);
00574 } else {
00575 $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00576 exec($cmd);
00577 }
00578 clearstatcache();
00579 if (@is_file($theDestFile)) {
00580 $this->writelog(3,0,1,'File "%s" moved to "%s"',Array($theFile,$theDestFile));
00581 return $theDestFile;
00582 } else $this->writelog(3,2,109,'File "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00583 } else $this->writelog(3,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00584 } else $this->writelog(3,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00585 } else $this->writelog(3,1,112,'File "%s" already exists!',Array($theDestFile));
00586 } else $this->writelog(3,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxMoveFileSize*1024));
00587 } else $this->writelog(3,1,114,'You are not allowed to move files','');
00588
00589
00590 } elseif (@is_dir($theFile)) {
00591 if ($this->actionPerms['moveFolder']) {
00592 $theFile = $this->is_directory($theFile);
00593 if ($theFile) {
00594 $fI = t3lib_div::split_fileref($theFile);
00595 if ($altName) {
00596 $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00597 $fI = t3lib_div::split_fileref($theDestFile);
00598 } else {
00599 $theDestFile = $theDest.'/'.$fI['file'];
00600 }
00601 if ($theDestFile && !@file_exists($theDestFile)) {
00602 if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/')) {
00603 if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile)) {
00604 if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile)) {
00605 if ($this->PHPFileFunctions) {
00606 rename($theFile, $theDestFile);
00607 } else {
00608 $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00609 $errArr = array();
00610 $retVar = 0;
00611 exec($cmd,$errArr,$retVar);
00612 }
00613 clearstatcache();
00614 if (@is_dir($theDestFile)) {
00615 $this->writelog(3,0,2,'Directory "%s" moved to "%s"',Array($theFile,$theDestFile));
00616 return $theDestFile;
00617 } else $this->writelog(3,2,119,'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00618 } else $this->writelog(3,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00619 } else $this->writelog(3,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00620 } else $this->writelog(3,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00621 } else $this->writelog(3,1,123,'Target "%s" already exists!',Array($theDestFile));
00622 } else $this->writelog(3,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00623 } else $this->writelog(3,1,125,'You are not allowed to move directories','');
00624
00625
00626 } else {
00627 $this->writelog(3,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00628 }
00629 }
00630
00637 function func_rename($cmds) {
00638 if (!$this->isInit) return FALSE;
00639
00640 $theNewName = $this->cleanFileName($cmds['data']);
00641 if ($theNewName) {
00642 if ($this->checkFileNameLen($theNewName)) {
00643 $theTarget = $cmds['target'];
00644 $type = filetype($theTarget);
00645 if ($type=='file' || $type=='dir') {
00646 $fileInfo = t3lib_div::split_fileref($theTarget);
00647 if ($fileInfo['file']!=$theNewName) {
00648 $theRenameName = $fileInfo['path'].$theNewName;
00649 if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00650 if (!@file_exists($theRenameName)) {
00651 if ($type=='file') {
00652 if ($this->actionPerms['renameFile']) {
00653 $fI = t3lib_div::split_fileref($theRenameName);
00654 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00655 if (@rename($theTarget, $theRenameName)) {
00656 $this->writelog(5,0,1,'File renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00657 return $theRenameName;
00658 } else $this->writelog(5,1,100,'File "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00659 } else $this->writelog(5,1,101,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00660 } else $this->writelog(5,1,102,'You are not allowed to rename files!','');
00661 } elseif ($type=='dir') {
00662 if ($this->actionPerms['renameFolder']) {
00663 if (@rename($theTarget, $theRenameName)) {
00664 $this->writelog(5,0,2,'Directory renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00665 return $theRenameName;
00666 } else $this->writelog(5,1,110,'Directory "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00667 } else $this->writelog(5,1,111,'You are not allowed to rename directories!','');
00668 }
00669 } else $this->writelog(5,1,120,'Destination "%s" existed already!',Array($theRenameName));
00670 } else $this->writelog(5,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00671 } else $this->writelog(5,1,122,'Old and new name is the same (%s)',Array($theNewName));
00672 } else $this->writelog(5,2,123,'Target "%s" was neither a directory nor a file!',Array($theTarget));
00673 } else $this->writelog(5,1,124,'New name "%s" was too long (max %s characters)',Array($theNewName,$this->maxInputNameLen));
00674 }
00675 }
00676
00683 function func_newfolder($cmds) {
00684 if (!$this->isInit) return FALSE;
00685
00686 $theFolder = $this->cleanFileName($cmds['data']);
00687 if ($theFolder) {
00688 if ($this->checkFileNameLen($theFolder)) {
00689 $theTarget = $this->is_directory($cmds['target']);
00690 if ($theTarget) {
00691 if ($this->actionPerms['newFolder']) {
00692 $theNewFolder = $theTarget.'/'.$theFolder;
00693 if ($this->checkPathAgainstMounts($theNewFolder)) {
00694 if (!@file_exists($theNewFolder)) {
00695 if (t3lib_div::mkdir($theNewFolder)){
00696 $this->writelog(6,0,1,'Directory "%s" created in "%s"',Array($theFolder,$theTarget.'/'));
00697 return $theNewFolder;
00698 } else $this->writelog(6,1,100,'Directory "%s" not created. Write-permission problem in "%s"?',Array($theFolder,$theTarget.'/'));
00699 } else $this->writelog(6,1,101,'File or directory "%s" existed already!',Array($theNewFolder));
00700 } else $this->writelog(6,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00701 } else $this->writelog(6,1,103,'You are not allowed to create directories!','');
00702 } else $this->writelog(6,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00703 } else $this->writelog(6,1,105,'New name "%s" was too long (max %s characters)',Array($theFolder,$this->maxInputNameLen));
00704 }
00705 }
00706
00713 function func_newfile($cmds) {
00714 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00715 if (!$this->isInit) return FALSE;
00716 $newName = $this->cleanFileName($cmds['data']);
00717 if ($newName) {
00718 if ($this->checkFileNameLen($newName)) {
00719 $theTarget = $this->is_directory($cmds['target']);
00720 $fileInfo = t3lib_div::split_fileref($theTarget);
00721 if ($theTarget) {
00722 if ($this->actionPerms['newFile']) {
00723 $theNewFile = $theTarget.'/'.$newName;
00724 if ($this->checkPathAgainstMounts($theNewFile)) {
00725 if (!@file_exists($theNewFile)) {
00726 $fI = t3lib_div::split_fileref($theNewFile);
00727 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00728 if (t3lib_div::inList($extList, $fI['fileext'])) {
00729 if (t3lib_div::writeFile($theNewFile,'')) {
00730 clearstatcache();
00731 $this->writelog(8,0,1,'File created: "%s"',Array($fI['file']));
00732 return $theNewFile;
00733 } else $this->writelog(8,1,100,'File "%s" was not created! Write-permission problem in "%s"?',Array($fI['file'], $theTarget));
00734 } else $this->writelog(8,1,107,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00735 } else $this->writelog(8,1,106,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00736 } else $this->writelog(8,1,101,'File "%s" existed already!',Array($theNewFile));
00737 } else $this->writelog(8,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00738 } else $this->writelog(8,1,103,'You are not allowed to create files!','');
00739 } else $this->writelog(8,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00740 } else $this->writelog(8,1,105,'New name "%s" was too long (max %s characters)',Array($newName,$this->maxInputNameLen));
00741 }
00742 }
00743
00750 function func_edit($cmds) {
00751 if (!$this->isInit) return FALSE;
00752 $theTarget = $cmds['target'];
00753 $content = $cmds['data'];
00754 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00755 $type = filetype($theTarget);
00756 if ($type=='file') {
00757 $fileInfo = t3lib_div::split_fileref($theTarget);
00758 $fI =$fileInfo;
00759 if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00760 if ($this->actionPerms['editFile']) {
00761 $fI = t3lib_div::split_fileref($theTarget);
00762 if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00763 if (t3lib_div::inList($extList, $fileInfo['fileext'])) {
00764 if (t3lib_div::writeFile($theTarget,$content)) {
00765 clearstatcache();
00766 $this->writelog(9,0,1,'File saved to "%s", bytes: %s, MD5: %s ',Array($fileInfo['file'],@filesize($theTarget),md5($content)));
00767 return TRUE;
00768 } else $this->writelog(9,1,100,'File "%s" was not saved! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00769 } else $this->writelog(9,1,102,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00770 } else $this->writelog(9,1,103,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00771 } else $this->writelog(9,1,104,'You are not allowed to edit files!','');
00772 } else $this->writelog(9,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00773 } else $this->writelog(9,2,123,'Target "%s" was not a file!',Array($theTarget));
00774 }
00775
00782 function func_upload($cmds) {
00783 if (!$this->isInit) return FALSE;
00784 $id = $cmds['data'];
00785 if ($_FILES['upload_'.$id]['name']) {
00786 $theFile = $_FILES['upload_'.$id]['tmp_name'];
00787 $theFileSize = $_FILES['upload_'.$id]['size'];
00788 $theName = $this->cleanFileName(stripslashes($_FILES['upload_'.$id]['name']));
00789 if (is_uploaded_file($theFile) && $theName) {
00790 if ($this->actionPerms['uploadFile']) {
00791 if ($theFileSize<($this->maxUploadFileSize*1024)) {
00792 $fI = t3lib_div::split_fileref($theName);
00793 $theTarget = $this->is_directory($cmds['target']);
00794 if ($theTarget && $this->checkPathAgainstMounts($theTarget.'/')) {
00795 if ($this->checkIfAllowed($fI['fileext'], $theTarget, $fI['file'])) {
00796 $theNewFile = $this->getUniqueName($theName, $theTarget, $this->dontCheckForUnique);
00797 if ($theNewFile) {
00798 t3lib_div::upload_copy_move($theFile,$theNewFile);
00799 clearstatcache();
00800 if (@is_file($theNewFile)) {
00801 $this->internalUploadMap[$id] = $theNewFile;
00802 $this->writelog(1,0,1,'Uploading file "%s" to "%s"',Array($theName,$theNewFile, $id));
00803 return $theNewFile;
00804 } else $this->writelog(1,1,100,'Uploaded file could not be moved! Write-permission problem in "%s"?',Array($theTarget.'/'));
00805 } else $this->writelog(1,1,101,'No unique filename available in "%s"!',Array($theTarget.'/'));
00806 } else $this->writelog(1,1,102,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theTarget.'/'));
00807 } else $this->writelog(1,1,103,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00808 } else $this->writelog(1,1,104,'The uploaded file exceeds the size-limit of %s bytes',Array($this->maxUploadFileSize*1024));
00809 } else $this->writelog(1,1,105,'You are not allowed to upload files!','');
00810 } else $this->writelog(1,2,106,'The uploaded file did not exist!','');
00811 }
00812 }
00813
00821 function func_unzip($cmds) {
00822 if (!$this->isInit || $this->dont_use_exec_commands) return FALSE;
00823
00824 $theFile = $cmds['data'];
00825 if (@is_file($theFile)) {
00826 $fI = t3lib_div::split_fileref($theFile);
00827 if (!isset($cmds['target'])) {
00828 $cmds['target'] = $fI['path'];
00829 }
00830 $theDest = $this->is_directory($cmds['target']);
00831 if ($theDest) {
00832 if ($this->actionPerms['unzipFile']) {
00833 if ($fI['fileext']=='zip') {
00834 if ($this->checkIfFullAccess($theDest)) {
00835 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest.'/')) {
00836
00837 $cmd = $this->unzipPath.'unzip -qq "'.$theFile.'" -d "'.$theDest.'"';
00838 exec($cmd);
00839 $this->writelog(7,0,1,'Unzipping file "%s" in "%s"',Array($theFile,$theDest));
00840 return TRUE;
00841 } else $this->writelog(7,1,100,'File "%s" or destination "%s" was not within your mountpoints!',Array($theFile,$theDest));
00842 } else $this->writelog(7,1,101,'You don\'t have full access to the destination directory "%s"!',Array($theDest));
00843 } else $this->writelog(7,1,102,'Fileextension is not "zip"','');
00844 } else $this->writelog(7,1,103,'You are not allowed to unzip files','');
00845 } else $this->writelog(7,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00846 } else $this->writelog(7,2,105,'The file "%s" did not exist!',Array($theFile));
00847 }
00848 }
00849
00850 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php']) {
00851 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extfilefunc.php']);
00852 }
00853 ?>