예제 #1
0
 /**
  * Download post attachment
  *
  * @access  public
  * @return  string   Requested file content or HTML error page
  */
 function Attachment()
 {
     $rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'attach'), 'get');
     $pModel = $this->gadget->model->load('Posts');
     $post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']);
     if (Jaws_Error::IsError($post)) {
         $this->SetActionMode('Attachment', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     $aModel = $this->gadget->model->load('Attachments');
     $attachment = $aModel->GetAttachmentInfo($rqst['attach']);
     if (Jaws_Error::IsError($attachment)) {
         $this->SetActionMode('Attachment', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     if (!empty($attachment)) {
         $filepath = JAWS_DATA . 'forums/' . $attachment['filename'];
         if (file_exists($filepath)) {
             // increase download hits
             $result = $aModel->HitAttachmentDownload($rqst['attach']);
             if (Jaws_Error::IsError($result)) {
                 // do nothing
             }
             if (Jaws_Utils::Download($filepath, $attachment['title'])) {
                 return;
             }
             $this->SetActionMode('Attachment', 'normal', 'standalone');
             return Jaws_HTTPError::Get(500);
         }
     }
     $this->SetActionMode('Attachment', 'normal', 'standalone');
     return Jaws_HTTPError::Get(404);
 }
예제 #2
0
 /**
  * Download message attachment
  *
  * @access  public
  * @return  string   Requested file content or HTML error page
  */
 function Attachment()
 {
     if (!$GLOBALS['app']->Session->Logged()) {
         return Jaws_HTTPError::Get(401);
     }
     $rqst = jaws()->request->fetch(array('uid', 'mid', 'aid'), 'get');
     $user = $GLOBALS['app']->Session->GetAttribute('user');
     $mModel = $this->gadget->model->load('Message');
     $aModel = $this->gadget->model->load('Attachment');
     $message = $mModel->GetMessage($rqst['mid'], false, false);
     if (Jaws_Error::IsError($message)) {
         return Jaws_HTTPError::Get(500);
     }
     // Check permissions
     if (!($message['from'] == $user && $message['to'] == 0) && $message['to'] != $user || $user != $rqst['uid']) {
         return Jaws_HTTPError::Get(403);
     }
     $attachment = $aModel->GetAttachment($rqst['aid'], $rqst['mid']);
     if (!empty($attachment)) {
         $filepath = JAWS_DATA . 'pm' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR . $attachment['filename'];
         if (file_exists($filepath)) {
             if (Jaws_Utils::Download($filepath, $attachment['title'], $attachment['filetype'])) {
                 return;
             }
             return Jaws_HTTPError::Get(500);
         }
     }
     $this->SetActionMode('Attachment', 'normal', 'standalone');
     return Jaws_HTTPError::Get(404);
 }
예제 #3
0
파일: Export.php 프로젝트: Dulciane/jaws
 /**
  * Export language
  *
  * @access  public
  * @return  void
  */
 function Export()
 {
     $lang = jaws()->request->fetch('lang', 'get');
     require_once PEAR_PATH . 'File/Archive.php';
     $tmpDir = sys_get_temp_dir();
     $tmpFileName = "{$lang}.tar";
     $tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName;
     $writerObj = File_Archive::toFiles();
     $src = File_Archive::read(JAWS_DATA . "languages/{$lang}", $lang);
     $dst = File_Archive::toArchive($tmpArchiveName, $writerObj);
     $res = File_Archive::extract($src, $dst);
     if (!PEAR::isError($res)) {
         return Jaws_Utils::Download($tmpArchiveName, $tmpFileName);
     }
     Jaws_Header::Referrer();
 }
예제 #4
0
파일: Logs.php 프로젝트: Dulciane/jaws
 /**
  * Export Logs
  *
  * @access  public
  * @return  void
  */
 function ExportLogs()
 {
     $this->gadget->CheckPermission('ExportLogs');
     $filters = jaws()->request->fetch(array('from_date', 'to_date', 'gname', 'user', 'priority', 'status'), 'get');
     $filters['gadget'] = $filters['gname'];
     unset($filters['gname']);
     $model = $this->gadget->model->load('Logs');
     $logs = $model->GetLogs($filters);
     if (Jaws_Error::IsError($logs) || count($logs) < 1) {
         return;
     }
     $tmpDir = sys_get_temp_dir();
     $tmpCSVFileName = uniqid(rand(), true) . '.csv';
     $fp = fopen($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName, 'w');
     $date = Jaws_Date::getInstance();
     foreach ($logs as $log) {
         $exportData = '';
         $exportData .= $log['id'] . ',';
         $exportData .= $log['username'] . ',';
         $exportData .= $log['gadget'] . ',';
         $exportData .= $log['action'] . ',';
         $exportData .= $log['priority'] . ',';
         $exportData .= $log['apptype'] . ',';
         $exportData .= $log['backend'] . ',';
         $exportData .= long2ip($log['ip']) . ',';
         $exportData .= $log['status'] . ',';
         $exportData .= $date->Format($log['insert_time'], 'Y-m-d H:i:s');
         $exportData .= PHP_EOL;
         fwrite($fp, $exportData);
     }
     fclose($fp);
     require_once PEAR_PATH . 'File/Archive.php';
     $tmpFileName = uniqid(rand(), true) . '.tar.gz';
     $tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName;
     $writerObj = File_Archive::toFiles();
     $src = File_Archive::read($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName);
     $dst = File_Archive::toArchive($tmpArchiveName, $writerObj);
     $res = File_Archive::extract($src, $dst);
     if (!PEAR::isError($res)) {
         return Jaws_Utils::Download($tmpArchiveName, $tmpFileName);
     }
     Jaws_Header::Referrer();
 }
예제 #5
0
파일: Themes.php 프로젝트: juniortux/jaws
 /**
  * Downloads the theme
  *
  * @access  public
  * @returns void
  */
 function DownloadTheme()
 {
     $theme = jaws()->request->fetch('theme', 'get');
     @(list($theme, $locality) = explode(',', $theme));
     $tInfo = Jaws_Utils::GetThemesInfo($locality, $theme);
     if (!empty($tInfo)) {
         if (!$tInfo['download']) {
             return Jaws_HTTPError::Get(403);
         }
         $tmpDir = sys_get_temp_dir();
         $tmsModel = $this->gadget->model->loadAdmin('Themes');
         $res = $tmsModel->packTheme($tInfo['name'], ($locality == 0 ? JAWS_DATA : JAWS_BASE_DATA) . 'themes', $tmpDir, false);
         if (!Jaws_Error::isError($res)) {
             Jaws_Utils::Download($res, "{$theme}.zip");
             return;
         }
     } else {
         return Jaws_HTTPError::Get(404);
     }
 }
예제 #6
0
파일: Files.php 프로젝트: Dulciane/jaws
 /**
  * Action for providing download file
  *
  * @access  public
  * @return  string   Requested file content or HTML error page
  */
 function Download()
 {
     $id = jaws()->request->fetch('id', 'get');
     $id = Jaws_XSS::defilter($id);
     $fModel = $this->gadget->model->load('Files');
     $iFile = $fModel->DBFileInfoByIndex($id);
     if (Jaws_Error::IsError($iFile)) {
         $this->SetActionMode('Download', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     if (!empty($iFile)) {
         $filepath = $fModel->GetFileBrowserRootDir() . $iFile['path'] . '/' . $iFile['filename'];
         if (file_exists($filepath)) {
             // increase download hits
             $fModel->HitFileDownload($iFile['id']);
             if (Jaws_Utils::Download($filepath, $iFile['filename'])) {
                 return;
             }
             $this->SetActionMode('Download', 'normal', 'standalone');
             return Jaws_HTTPError::Get(500);
         }
     }
     $this->SetActionMode('Download', 'normal', 'standalone');
     return Jaws_HTTPError::Get(404);
 }
예제 #7
0
파일: Directory.php 프로젝트: Dulciane/jaws
 /**
  * Downloads(streams) file
  *
  * @access  public
  * @return  mixed   File data or Jaws_Error
  */
 function Download()
 {
     $id = jaws()->request->fetch('id');
     if (is_null($id)) {
         return Jaws_HTTPError::Get(500);
     }
     $id = (int) $id;
     $model = $this->gadget->model->loadAdmin('Files');
     // Validate file
     $file = $model->GetFile($id);
     if (Jaws_Error::IsError($file)) {
         return Jaws_HTTPError::Get(500);
     }
     if (empty($file) || empty($file['user_filename'])) {
         return Jaws_HTTPError::Get(404);
     }
     // Check for file existence
     $filename = $GLOBALS['app']->getDataURL("directory/") . $file['host_filename'];
     if (!file_exists($filename)) {
         return Jaws_HTTPError::Get(404);
     }
     // Stream file
     if (!Jaws_Utils::Download($filename, $file['user_filename'], $file['filetype'])) {
         return Jaws_HTTPError::Get(500);
     }
     return true;
 }
예제 #8
0
파일: Files.php 프로젝트: juniortux/jaws
 /**
  * Downloads file (stream)
  *
  * @access  public
  * @return  mixed   File data or Jaws_Error
  */
 function Download($open = true)
 {
     $id = jaws()->request->fetch('id');
     if (is_null($id)) {
         return Jaws_HTTPError::Get(500);
     }
     $id = (int) $id;
     $model = $this->gadget->model->load('Files');
     // Validate file
     $file = $model->GetFile($id);
     if (Jaws_Error::IsError($file)) {
         return Jaws_HTTPError::Get(500);
     }
     if (empty($file) || empty($file['filename'])) {
         return Jaws_HTTPError::Get(404);
     }
     // Validate user
     if (!$file['public']) {
         $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
         $access = $model->CheckAccess($id, $user);
         if ($access !== true) {
             return Jaws_HTTPError::Get(403);
         }
     }
     // Check for file existance
     $uid = $file['id'] == $file['reference'] ? $file['user'] : $file['owner'];
     $filename = $GLOBALS['app']->getDataURL("directory/{$uid}/") . $file['filename'];
     if (!file_exists($filename)) {
         return Jaws_HTTPError::Get(404);
     }
     // Stream file
     if (!Jaws_Utils::Download($filename, $file['filename'], $file['filetype'], $open)) {
         return Jaws_HTTPError::Get(500);
     }
     return;
 }