Exemple #1
0
 /**
  * perform requested action
  */
 function action()
 {
     global $msg;
     $fmMode = $_REQUEST['fmMode'];
     $fmName = $_REQUEST['fmName'];
     $this->getLanguageFile();
     if (!$this->ftpHost && $this->startDir == '') {
         $this->error = "SECURITY ALERT:<br>Please set a start directory or an FTP server!";
         $log = $this->error;
     } else {
         if ($fmMode == 'login' && $fmName == $this->loginPassword) {
             $this->access = true;
             $fmMode = 'refresh';
         } else {
             if ($this->loginPassword != '' && !$this->access) {
                 $this->viewLogin();
             }
         }
     }
     if (!$this->error && $this->access) {
         $fmObject = $_REQUEST['fmObject'];
         $fmPerms = $_REQUEST['fmPerms'];
         $this->getListing();
         switch ($fmMode) {
             case 'sort':
                 list($this->Listing->sortField, $this->Listing->sortOrder) = explode(',', $fmName);
                 $this->Listing->view();
                 break;
             case 'open':
                 if ($fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         if ($Entry->icon == 'dir') {
                             $this->Listing->prevDir = $this->Listing->curDir;
                             $this->Listing->curDir = $Entry->path;
                             $this->Listing->searchString = '';
                             $this->cleanUp($this->cacheDir);
                         }
                     }
                 }
                 if ($this->Listing->prevDir !== $this->Listing->curDir) {
                     $this->Listing->refresh();
                 } else {
                     $this->Listing->view();
                 }
                 break;
             case 'getFile':
                 if ($this->enableDownload && $fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         if (!$Entry->sendFile()) {
                             $this->error = $msg['errOpen'] . ": {$Entry->name}";
                         }
                     }
                 }
                 if (!$this->error) {
                     print 'READY';
                 }
                 break;
             case 'getThumbnail':
                 if ($fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         $Image = new Image($Entry->getImagePath(), $_REQUEST['width'], $_REQUEST['height']);
                         $Image->view();
                     }
                 }
                 break;
             case 'parent':
                 $this->Listing->prevDir = $this->Listing->curDir;
                 $this->Listing->curDir = ereg_replace('/[^/]+$', '', $this->Listing->curDir);
                 $this->Listing->searchString = '';
                 $this->cleanUp($this->cacheDir);
                 $this->Listing->refresh();
                 break;
             case 'rename':
                 if ($this->enableRename && $fmName != '' && $fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         $path = dirname($Entry->path);
                         if (get_magic_quotes_gpc()) {
                             $fmName = stripslashes($fmName);
                         }
                         $fmName = basename($fmName);
                         if (!$Entry->rename("{$path}/{$fmName}")) {
                             $this->error = $msg['errRename'] . ": {$Entry->name} &raquo; {$fmName}";
                         }
                     }
                 }
                 if (!$this->error) {
                     $this->Listing->refresh();
                 }
                 break;
             case 'delete':
                 if ($this->enableDelete && $fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         if ($Entry->icon == 'dir') {
                             if (!$this->Listing->remDir($Entry->path)) {
                                 $this->error = $msg['errDelete'] . ": {$Entry->name}";
                             }
                         } else {
                             if (!$Entry->deleteFile()) {
                                 $this->error = $msg['errDelete'] . ": {$Entry->name}";
                             }
                         }
                     }
                 }
                 if (!$this->error) {
                     $this->Listing->refresh();
                 }
                 break;
             case 'newDir':
                 if ($this->enableNewDir) {
                     if ($fmName != '') {
                         if (get_magic_quotes_gpc()) {
                             $fmName = stripslashes($fmName);
                         }
                         $fmName = str_replace('\\', '/', $fmName);
                         $dirs = explode('/', $fmName);
                         $dir = '';
                         for ($i = 0; $i < count($dirs); $i++) {
                             if ($dirs[$i] != '') {
                                 if ($dir != '') {
                                     $dir .= '/';
                                 }
                                 $dir .= $dirs[$i];
                                 $curDir = $this->Listing->curDir;
                                 if (!$this->Listing->mkDir("{$curDir}/{$dir}")) {
                                     $this->error = $msg['errDirNew'] . ": {$dir}";
                                     break;
                                 } else {
                                     if ($this->defaultDirPermissions) {
                                         $Entry =& $this->Listing->getEntryByName($dir);
                                         if (!$Entry || !$Entry->changePerms($this->defaultDirPermissions)) {
                                             $this->error = $msg['errPermChange'] . ": {$dir}";
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $this->Listing->refresh();
                 break;
             case 'newFile':
                 if ($this->enableUpload) {
                     $fmFile = $_FILES['fmFile'];
                     $fmReplSpaces = $_REQUEST['fmReplSpaces'];
                     $fmLowerCase = $_REQUEST['fmLowerCase'];
                     $errors = array();
                     if (is_array($fmFile)) {
                         for ($i = 0; $i < count($fmFile['size']); $i++) {
                             $newFile = $fmFile['name'][$i];
                             if ($fmFile['size'][$i]) {
                                 if ($this->hideSystemFiles && $newFile[0] == '.') {
                                     $errors[] = $msg['errAccess'] . ": {$newFile}";
                                 } else {
                                     if ($this->replSpacesUpload || $fmReplSpaces) {
                                         $newFile = str_replace(' ', '_', $newFile);
                                     }
                                     if ($this->lowerCaseUpload || $fmLowerCase) {
                                         $newFile = strtolower($newFile);
                                     }
                                     if (!$this->Listing->upload($fmFile['tmp_name'][$i], $newFile)) {
                                         $errors[] = $msg['errSave'] . ": {$newFile}";
                                     } else {
                                         if ($this->defaultFilePermissions) {
                                             $Entry =& $this->Listing->getEntryByName($newFile);
                                             if (!$Entry || !$Entry->changePerms($this->defaultFilePermissions)) {
                                                 $errors[] = $msg['errPermChange'] . ": {$newFile}";
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($newFile != '') {
                                     $errors[] = $msg['error'] . ": {$newFile} = 0 B";
                                     $maxFileSize = ini_get('upload_max_filesize');
                                     $postMaxSize = ini_get('post_max_size');
                                     $info = "PHP settings: upload_max_filesize = {$maxFileSize}, ";
                                     $info .= "post_max_size = {$postMaxSize}";
                                     $error = "Could not upload {$newFile} ({$info})";
                                     $this->Listing->FileSystem->addMsg($error, 'error');
                                 }
                             }
                         }
                     }
                     $this->Listing->refresh();
                     if (count($errors) > 0) {
                         $this->error .= join('<br/>', $errors);
                     }
                 } else {
                     $this->Listing->view();
                 }
                 break;
             case 'refresh':
                 $this->Listing->refresh();
                 break;
             case 'permissions':
                 if ($this->enablePermissions && is_array($fmPerms) && $fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         $mode = '';
                         for ($i = 0; $i < 9; $i++) {
                             $mode .= $fmPerms[$i] ? 1 : 0;
                         }
                         if (!$Entry->changePerms(bindec($mode))) {
                             $this->error = $msg['errPermChange'] . ": {$Entry->name}";
                         }
                     }
                 }
                 if (!$this->error) {
                     $this->Listing->refresh();
                 }
                 break;
             case 'edit':
                 if ($this->enableEdit && $fmObject != '') {
                     if ($Entry =& $this->Listing->getEntry($fmObject)) {
                         $fmText = $_POST['fmText'];
                         if ($fmText != '') {
                             if (!$Entry->saveFile($fmText)) {
                                 $this->error = $msg['errSave'] . ": {$Entry->name}";
                             } else {
                                 $this->Listing->refresh();
                             }
                         } else {
                             $Editor = new Editor($this);
                             $Editor->view($Entry);
                         }
                     }
                 }
                 break;
             case 'search':
                 $this->Listing->performSearch($fmName);
                 break;
             case 'switchView':
                 $this->Listing =& $this->Listing->switchView();
                 $this->Listing->refresh();
                 break;
             default:
                 if (!$this->error) {
                     $this->Listing->view();
                 }
         }
         if ($this->ftpHost) {
             $this->Listing->FileSystem->ftpClose();
         }
         $this->cleanUp();
         $log = $this->Listing->FileSystem->getMessages();
     }
     if ($this->error != '') {
         print '{{fmERROR}}' . $this->error . '{{/fmERROR}}';
         $this->error = '';
     }
     print '{{fmLOG}}' . $log . '{{/fmLOG}}';
     $this->save();
 }