| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // wcf imports |
|---|
| 4 | require_once(WCF_DIR.'lib/page/AbstractPage.class.php'); |
|---|
| 5 | require_once(WCF_DIR.'lib/data/downloadDB/DownloadDBDataEditor.class.php'); |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * Download Database Datei Download |
|---|
| 9 | * |
|---|
| 10 | * @author Robert "Tatzelwurm" Hempel |
|---|
| 11 | * @copyright 2007/2008 INSIDE das Hrspiel |
|---|
| 12 | * @license GNU LGPL http://www.gnu.org/licenses/lgpl.txt |
|---|
| 13 | * @package de.inside.wcf.DownloadDatabase |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | class DownloadDBFileDownloadPage extends AbstractPage { |
|---|
| 17 | |
|---|
| 18 | public $dataID; |
|---|
| 19 | public $katID; |
|---|
| 20 | private $fileName; |
|---|
| 21 | private $fileType; |
|---|
| 22 | private $linkType; |
|---|
| 23 | private $link; |
|---|
| 24 | |
|---|
| 25 | public function readParameters() { |
|---|
| 26 | parent :: readParameters(); |
|---|
| 27 | if (isset($_REQUEST['dataID'])) $this->dataID = intval($_REQUEST['dataID']); |
|---|
| 28 | if (!$this->dataID){ |
|---|
| 29 | require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php'); |
|---|
| 30 | throw new NamedUserException(WCF::getLanguage()->get('wcf.dldb.wrongid')); |
|---|
| 31 | exit; |
|---|
| 32 | } |
|---|
| 33 | if (!WCF::getUser()->getPermission('user.dldb.canUseDownloadDB')){ |
|---|
| 34 | require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php'); |
|---|
| 35 | throw new PermissionDeniedException(); |
|---|
| 36 | } |
|---|
| 37 | if (!WCF::getUser()->getPermission('user.dldb.canDownloadFile')){ |
|---|
| 38 | require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php'); |
|---|
| 39 | throw new PermissionDeniedException(); |
|---|
| 40 | } |
|---|
| 41 | WCF::getCache()->addResource('dldbData', |
|---|
| 42 | WCF_DIR.'cache/cache.dldbData.php', |
|---|
| 43 | WCF_DIR.'lib/system/cache/CacheBuilderDLDBData.class.php'); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public function show() { |
|---|
| 47 | $this->readDaten(); |
|---|
| 48 | |
|---|
| 49 | // Anzahl der Downloads erhöhen |
|---|
| 50 | $sql = "UPDATE wcf".WCF_N."_dldb_data |
|---|
| 51 | SET downloads = downloads + 1 |
|---|
| 52 | WHERE `dataID` = ".$this->dataID; |
|---|
| 53 | $row = WCF::getDB()->registerShutdownUpdate($sql); |
|---|
| 54 | |
|---|
| 55 | // Download-Log speichern |
|---|
| 56 | if (DOWNLOADDB_LOG) { |
|---|
| 57 | if (!WCF::getUser()->userID && DOWNLOADDB_LOG_GUESTS) $this->xferSave(); |
|---|
| 58 | if ( WCF::getUser()->userID && !DOWNLOADDB_LOG_ONLY_GUESTS) $this->xferSave(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | // reset cache |
|---|
| 62 | WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php'); |
|---|
| 63 | |
|---|
| 64 | // Link entschlÃŒsseln |
|---|
| 65 | if ($this->linkType == 0) { |
|---|
| 66 | // Es liegt ein Upload vor. |
|---|
| 67 | $dataset = new downloadDBDataEditor($this->dataID); |
|---|
| 68 | $link = FileUtil::getRealPath(RELATIVE_WCF_DIR.$dataset->getURL()); |
|---|
| 69 | $type = $this->fileType; |
|---|
| 70 | } |
|---|
| 71 | if ($this->linkType == 1) { |
|---|
| 72 | // Es liegt eine lokale Datei vor |
|---|
| 73 | $link = $_SERVER['DOCUMENT_ROOT'].$this->link; |
|---|
| 74 | $type = $this->fileType; |
|---|
| 75 | } |
|---|
| 76 | if ($this->linkType == 2) { |
|---|
| 77 | // Link ist eine URL |
|---|
| 78 | HeaderUtil::redirect($this->link,false); |
|---|
| 79 | exit; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | // Set Download Infos |
|---|
| 83 | @ header('Content-Description: File Transfer'); |
|---|
| 84 | @ header('Content-Type: '. $type); |
|---|
| 85 | @ header('Content-disposition: attachment; filename="' . $this->fileName . '"'); |
|---|
| 86 | @ header('Content-Length: ' . filesize($link)); |
|---|
| 87 | @ header('Pragma: no-cache'); |
|---|
| 88 | @ header('Expires: 0'); |
|---|
| 89 | // Start Download |
|---|
| 90 | @readfile($link); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | protected function readDaten() { |
|---|
| 94 | // Cache lesen |
|---|
| 95 | $data = WCF::getCache()->get('dldbData'); |
|---|
| 96 | foreach ($data as $daten) { |
|---|
| 97 | if ($daten['dataID'] == $this->dataID) { |
|---|
| 98 | $this->linkType = $daten['linkType']; |
|---|
| 99 | $this->fileType = $daten['mimeType']; |
|---|
| 100 | $this->fileName = $daten['fileName']; |
|---|
| 101 | $this->link = $daten['link']; |
|---|
| 102 | $this->katID = $daten['katID']; |
|---|
| 103 | // Kontrolle der Zugangsberechtigung; |
|---|
| 104 | $IDs = explode(',',$daten['groupcheck']); |
|---|
| 105 | $daten['canViewCat'] = false; |
|---|
| 106 | foreach ($IDs as $gruppe) { |
|---|
| 107 | if (in_array($gruppe, WCF::getUser()->getGroupIDs())) { |
|---|
| 108 | $daten['canViewCat'] = true; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | if ($daten['canViewCat'] != true){ |
|---|
| 112 | require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php'); |
|---|
| 113 | throw new PermissionDeniedException(); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | protected function xferSave() { |
|---|
| 120 | $sql = "INSERT INTO wcf".WCF_N."_dldb_xfer |
|---|
| 121 | (`dataID`, `katID`, `userID`, `ipadress`, `time`) |
|---|
| 122 | VALUES |
|---|
| 123 | ('".intval($this->dataID)."', |
|---|
| 124 | '".intval($this->katID)."', |
|---|
| 125 | '".WCF::getUser()->userID."', |
|---|
| 126 | '".escapeString(WCF::getSession()->ipAddress)."', |
|---|
| 127 | '".TIME_NOW."' |
|---|
| 128 | )"; |
|---|
| 129 | WCF::getDB()->sendQuery($sql); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | ?> |
|---|