Ejemplo n.º 1
0
 /**
  * Get root dir
  *
  * @access  public
  * @return  string  The root directory
  */
 function GetFileBrowserRootDir()
 {
     static $root_dir;
     if (!isset($root_dir)) {
         $root_dir = trim($this->gadget->registry->fetch('root_dir'));
         $root_dir = JAWS_DATA . trim($root_dir, "\\/");
         $root_dir = str_replace('..', '', $root_dir);
         require_once PEAR_PATH . 'File/Util.php';
         $root_dir = File_Util::realpath($root_dir) . '/';
         if (!File_Util::pathInRoot($root_dir, JAWS_DATA)) {
             Jaws_Error::Fatal(_t('FILEBROWSER_ERROR_DIRECTORY_DOES_NOT_EXISTS'), __FILE__, __LINE__);
         }
     }
     return $root_dir;
 }
Ejemplo n.º 2
0
 /**
  * Creates a directory
  *
  * @access  public
  * @param   string  $path       Where to create it
  * @param   string  $dir_name   Which name
  * @return  bool    Returns true if the directory was created, if not, returns false
  */
 function MakeDir($path, $dir_name)
 {
     $path = trim($path, '/');
     $path = str_replace('..', '', $path);
     $fModel = $this->gadget->model->load('Files');
     $dir = $fModel->GetFileBrowserRootDir() . $path . '/' . $dir_name;
     require_once PEAR_PATH . 'File/Util.php';
     $realpath = File_Util::realpath($dir);
     $blackList = explode(',', $this->gadget->registry->fetch('black_list'));
     $blackList = array_map('strtolower', $blackList);
     if (!File_Util::pathInRoot($realpath, $fModel->GetFileBrowserRootDir()) || in_array(strtolower(basename($realpath)), $blackList) || !Jaws_Utils::mkdir($realpath)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_ERROR_CANT_CREATE_DIRECTORY', $realpath), RESPONSE_ERROR);
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Uploads a new file
  *
  * @access  public
  */
 function UploadFile()
 {
     $this->gadget->CheckPermission('UploadFiles');
     $fModel = $this->gadget->model->load('Files');
     $fModelAdmin = $this->gadget->model->loadAdmin('Files');
     $post = jaws()->request->fetch(array('path', 'file_title', 'file_description', 'file_fast_url', 'oldname', 'extra_params'), 'post');
     $uploaddir = $fModel->GetFileBrowserRootDir() . $post['path'];
     require_once PEAR_PATH . 'File/Util.php';
     $uploaddir = File_Util::realpath($uploaddir) . DIRECTORY_SEPARATOR;
     if (!File_Util::pathInRoot($uploaddir, $fModel->GetFileBrowserRootDir())) {
         $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_UPLOAD'), RESPONSE_ERROR);
     } else {
         $res = Jaws_Utils::UploadFiles($_FILES, $uploaddir, '');
         if (Jaws_Error::IsError($res)) {
             $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR);
         } elseif (empty($res)) {
             $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_UPLOAD_4'), RESPONSE_ERROR);
         } else {
             $post['oldname'] = preg_replace('/[^[:alnum:]_\\.\\-]*/', '', $post['oldname']);
             if (!empty($post['oldname']) && $res['uploadfile'][0]['host_filename'] != $post['oldname']) {
                 $fModelAdmin->Delete($post['path'], $post['oldname']);
             }
             $fModelAdmin->UpdateDBFileInfo($post['path'], $res['uploadfile'][0]['host_filename'], empty($post['file_title']) ? $res['uploadfile'][0]['user_filename'] : $post['file_title'], $post['file_description'], $post['file_fast_url'], $post['oldname']);
         }
     }
     if (empty($post['extra_params'])) {
         Jaws_Header::Location(BASE_SCRIPT . '?gadget=FileBrowser&action=Files&path=' . $post['path']);
     } else {
         Jaws_Header::Location(BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile&path=' . $post['path'] . html_entity_decode($post['extra_params']));
     }
 }
Ejemplo n.º 4
0
 /**
  * Rename a given file or directory
  *
  * @access  public
  * @param   string  $type             file or dir
  * @param   string  $old_filename     Filename to rename
  * @param   string  $new_filename     New Filename
  * @return  bool    Returns file if file/directory was renamed without problems, if not, returns false
  */
 function Rename($path, $old, $new)
 {
     $path = trim($path, '/');
     $path = str_replace('..', '', $path);
     $fModel = $this->gadget->model->load('Files');
     $oldfile = $fModel->GetFileBrowserRootDir() . $path . '/' . $old;
     $newfile = $fModel->GetFileBrowserRootDir() . $path . '/' . $new;
     require_once PEAR_PATH . 'File/Util.php';
     $oldfile = File_Util::realpath($oldfile);
     $newfile = File_Util::realpath($newfile);
     $blackList = explode(',', $this->gadget->registry->fetch('black_list'));
     $blackList = array_map('strtolower', $blackList);
     if (!File_Util::pathInRoot($oldfile, $fModel->GetFileBrowserRootDir()) || !File_Util::pathInRoot($newfile, $fModel->GetFileBrowserRootDir()) || in_array(strtolower(basename($oldfile)), $blackList) || in_array(strtolower(basename($newfile)), $blackList)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_ERROR_CANT_RENAME', $old, $new), RESPONSE_ERROR);
         return false;
     }
     $return = @rename($oldfile, $newfile);
     if ($return) {
         $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_RENAMED', $old, $new), RESPONSE_NOTICE);
         return true;
     }
     $msgError = _t('FILEBROWSER_ERROR_CANT_RENAME', $old, $new);
     $GLOBALS['app']->Session->PushLastResponse($msgError, RESPONSE_ERROR);
     return false;
 }