XoopsModules25x /
wfdownloads
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | /* |
||
| 3 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Wfdownloads module |
||
| 14 | * |
||
| 15 | * @copyright XOOPS Project (https://xoops.org) |
||
| 16 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 17 | * @package wfdownload |
||
| 18 | * @since 3.23 |
||
| 19 | * @author Xoops Development Team |
||
| 20 | */ |
||
| 21 | |||
| 22 | use Xmf\Request; |
||
| 23 | use XoopsModules\Wfdownloads\{ |
||
| 24 | Common, |
||
| 25 | Helper, |
||
| 26 | Utility |
||
| 27 | }; |
||
| 28 | |||
| 29 | /** @var Helper $helper */ |
||
| 30 | /** @var Utility $utility */ |
||
| 31 | |||
| 32 | $currentFile = basename(__FILE__); |
||
| 33 | require_once __DIR__ . '/header.php'; |
||
| 34 | |||
| 35 | // Check permissions |
||
| 36 | if (is_object($GLOBALS['xoopsUser'])) { |
||
| 37 | if ($GLOBALS['xoopsUser']->getVar('posts') < $helper->getConfig('download_minposts') && !$GLOBALS['xoopsUser']->isAdmin()) { |
||
| 38 | redirect_header('index.php', 5, _MD_WFDOWNLOADS_DOWNLOADMINPOSTS); |
||
| 39 | } |
||
| 40 | } elseif (!is_object($GLOBALS['xoopsUser']) && ($helper->getConfig('download_minposts') > 0)) { |
||
| 41 | redirect_header(XOOPS_URL . '/user.php', 1, _MD_WFDOWNLOADS_MUSTREGFIRST); |
||
| 42 | } |
||
| 43 | |||
| 44 | $lid = Request::getInt('lid', 0); |
||
| 45 | $downloadObj = $helper->getHandler('Download')->get($lid); |
||
| 46 | // Check if download exists |
||
| 47 | if ($downloadObj->isNew()) { |
||
| 48 | redirect_header('index.php', 1, _MD_WFDOWNLOADS_NODOWNLOAD); |
||
| 49 | } |
||
| 50 | $cid = Request::getInt('cid', $downloadObj->getVar('cid')); |
||
| 51 | $agreed = Request::getBool('agreed', false, 'POST'); |
||
| 52 | |||
| 53 | // Download not published, expired or taken offline - redirect |
||
| 54 | if (0 == $downloadObj->getVar('published') || $downloadObj->getVar('published') > time() || true === $downloadObj->getVar('offline') |
||
| 55 | || (0 != $downloadObj->getVar('expired') |
||
| 56 | && $downloadObj->getVar('expired') < time()) |
||
| 57 | || _WFDOWNLOADS_STATUS_WAITING == $downloadObj->getVar('status')) { |
||
| 58 | redirect_header('index.php', 3, _MD_WFDOWNLOADS_NODOWNLOAD); |
||
| 59 | } |
||
| 60 | |||
| 61 | // Check permissions |
||
| 62 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 63 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 64 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS]; |
||
| 65 | if (!$grouppermHandler->checkRight('WFDownCatPerm', $cid, $groups, $helper->getModule()->mid())) { |
||
| 66 | redirect_header('index.php', 3, _NOPERM); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (false === $agreed) { |
||
| 70 | if ($helper->getConfig('check_host')) { |
||
| 71 | $isAGoodHost = false; |
||
| 72 | $referer = parse_url(xoops_getenv('HTTP_REFERER')); |
||
| 73 | $refererHost = $referer['host']; |
||
| 74 | foreach ($helper->getConfig('referers') as $ref) { |
||
| 75 | if (!empty($ref) && preg_match("/{$ref}/i", $refererHost)) { |
||
| 76 | $isAGoodHost = true; |
||
| 77 | break; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | if (!$isAGoodHost) { |
||
| 81 | redirect_header(WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}", 20, _MD_WFDOWNLOADS_NOPERMISETOLINK); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($helper->getConfig('showDowndisclaimer') && false === $agreed) { |
||
| 87 | $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_disclaimer.tpl"; |
||
| 88 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 89 | |||
| 90 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 91 | $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js'); |
||
| 92 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css'); |
||
| 93 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css'); |
||
| 94 | |||
| 95 | $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/'); |
||
| 96 | |||
| 97 | $catarray['imageheader'] = Utility::headerImage(); |
||
| 98 | $xoopsTpl->assign('catarray', $catarray); |
||
| 99 | |||
| 100 | // Breadcrumb |
||
| 101 | $breadcrumb = new Common\Breadcrumb(); |
||
| 102 | $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL); |
||
| 103 | $breadcrumb->addLink(_MD_WFDOWNLOADS_DOWNLOADNOW, ''); |
||
| 104 | $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render()); |
||
| 105 | |||
| 106 | $xoopsTpl->assign('lid', $lid); |
||
| 107 | $xoopsTpl->assign('cid', $cid); |
||
| 108 | |||
| 109 | $xoopsTpl->assign('image_header', Utility::headerImage()); |
||
| 110 | |||
| 111 | $xoopsTpl->assign('submission_disclaimer', false); |
||
| 112 | $xoopsTpl->assign('download_disclaimer', true); |
||
| 113 | $xoopsTpl->assign('download_disclaimer_content', $myts->displayTarea($helper->getConfig('downdisclaimer'), true, true, true, true, true)); |
||
| 114 | |||
| 115 | $xoopsTpl->assign('down_disclaimer', true); // this definition is not removed for backward compatibility issues |
||
| 116 | $xoopsTpl->assign('downdisclaimer', $myts->displayTarea($helper->getConfig('downdisclaimer'), true, true, true, true, true)); // this definition is not removed for backward compatibility issues |
||
| 117 | $xoopsTpl->assign('cancel_location', WFDOWNLOADS_URL . '/index.php'); // this definition is not removed for backward compatibility issues |
||
| 118 | $xoopsTpl->assign('agree_location', WFDOWNLOADS_URL . "/{$currentFile}?agree=1&lid={$lid}&cid={$cid}"); |
||
| 119 | require_once __DIR__ . '/footer.php'; |
||
| 120 | } else { |
||
| 121 | if (!Utility::userIsAdmin()) { |
||
| 122 | $helper->getHandler('Download')->incrementHits($lid); |
||
| 123 | } |
||
| 124 | // Create ip log |
||
| 125 | $ip_logObj = $helper->getHandler('Iplog')->create(); |
||
| 126 | $ip_logObj->setVar('lid', $lid); |
||
| 127 | $ip_logObj->setVar('date', time()); |
||
| 128 | $ip_logObj->setVar('ip_address', getenv('REMOTE_ADDR')); |
||
| 129 | $ip_logObj->setVar('uid', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
||
| 130 | $helper->getHandler('Iplog')->insert($ip_logObj, true); |
||
| 131 | |||
| 132 | // Download file |
||
| 133 | $fileFilename = trim($downloadObj->getVar('filename')); // IN PROGRESS: why 'trim'? |
||
| 134 | if (('' == !$downloadObj->getVar('url') && 'http://' === !$downloadObj->getVar('url')) || '' == $fileFilename) { |
||
|
0 ignored issues
–
show
|
|||
| 135 | // download is a remote file: download from remote url |
||
| 136 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 137 | |||
| 138 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 139 | $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js'); |
||
| 140 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css'); |
||
| 141 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css'); |
||
| 142 | |||
| 143 | $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/'); |
||
| 144 | |||
| 145 | echo "<div align='center'>" . Utility::headerImage() . '</div>'; |
||
| 146 | $url = htmlspecialchars(preg_replace('/javascript:/si', 'javascript:', $downloadObj->getVar('url')), ENT_QUOTES); |
||
| 147 | echo "<h4>\n"; |
||
| 148 | echo "<img src='" . WFDOWNLOADS_URL . "/assets/images/icon/downloads.gif' align='middle' alt='' title='" . _MD_WFDOWNLOADS_DOWNINPROGRESS . "'> " . _MD_WFDOWNLOADS_DOWNINPROGRESS . "\n"; |
||
| 149 | echo "</h4>\n"; |
||
| 150 | echo '<div>' . _MD_WFDOWNLOADS_DOWNSTARTINSEC . "</div><br>\n"; |
||
| 151 | echo '<div>' . _MD_WFDOWNLOADS_DOWNNOTSTART . "\n"; |
||
| 152 | echo "<a href='{$url}' target='_blank'>" . _MD_WFDOWNLOADS_CLICKHERE . "</a>.\n"; |
||
| 153 | echo "</div>\n"; |
||
| 154 | |||
| 155 | header('Cache-Control: no-store, no-cache, must-revalidate'); |
||
| 156 | header('Cache-Control: post-check=0, pre-check=0', false); |
||
| 157 | header('Pragma: no-cache'); // HTTP/1.0 |
||
| 158 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past |
||
| 159 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // Always modified |
||
| 160 | header("Refresh: 3; url={$url}"); |
||
| 161 | } elseif (!empty($fileFilename)) { |
||
| 162 | // download is a local file: download from filesystem |
||
| 163 | if (ini_get('zlib.output_compression')) { |
||
| 164 | ini_set('zlib.output_compression', 'Off'); |
||
| 165 | } |
||
| 166 | // get file informations from filesystem |
||
| 167 | $fileFilename = trim($downloadObj->getVar('filename')); // IN PROGRESS: why 'trim'? |
||
| 168 | $fileMimetype = ('' != $downloadObj->getVar('filetype')) ? $downloadObj->getVar('filetype') : 'application/octet-stream'; |
||
| 169 | $filePath = $helper->getConfig('uploaddir') . '/' . stripslashes(trim($fileFilename)); |
||
| 170 | $fileFilesize = filesize($filePath); |
||
| 171 | $fileInfo = pathinfo($filePath); |
||
| 172 | $fileName = $fileInfo['basename']; |
||
| 173 | $fileExtension = $fileInfo['extension']; |
||
| 174 | |||
| 175 | $headerFilename = mb_strtolower(strrev(mb_substr(strrev($fileFilename), 0, mb_strpos(strrev($fileFilename), '--')))); |
||
| 176 | $headerFilename = ('' == $headerFilename) ? $fileFilename : $headerFilename; |
||
| 177 | // MSIE Bug fix |
||
| 178 | if (false !== mb_strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { |
||
| 179 | $headerFilename = preg_replace('/\./', '%2e', $headerFilename, mb_substr_count($headerFilename, '.') - 1); |
||
| 180 | } |
||
| 181 | |||
| 182 | header('Pragma: public'); |
||
| 183 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
||
| 184 | header('Cache-Control: private', false); |
||
| 185 | header('Content-Length: ' . $fileFilesize); |
||
| 186 | header('Content-Transfer-Encoding: binary'); |
||
| 187 | header("Content-Type: {$fileMimetype}"); |
||
| 188 | header("Content-Disposition: attachment; filename={$headerFilename}"); |
||
| 189 | if (false !== mb_strpos($fileMimetype, 'text/')) { |
||
| 190 | // downladed file is not binary |
||
| 191 | Utility::download($filePath, false, true); |
||
| 192 | } else { |
||
| 193 | // downladed file is binary |
||
| 194 | Utility::download($filePath, true, true); |
||
| 195 | } |
||
| 196 | exit(); |
||
| 197 | } else { |
||
| 198 | // download is a broken file: report broken |
||
| 199 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 200 | echo '<br>'; |
||
| 201 | echo "<div align='center'>" . Utility::headerImage() . '</div>'; |
||
| 202 | echo '<h4>' . _MD_WFDOWNLOADS_BROKENFILE . "</h4>\n"; |
||
| 203 | echo '<div>' . _MD_WFDOWNLOADS_PLEASEREPORT . "\n"; |
||
| 204 | echo "<a href='" . WFDOWNLOADS_URL . "/brokenfile.php?lid={$lid}'>" . _MD_WFDOWNLOADS_CLICKHERE . "</a>\n"; |
||
| 205 | echo "</div>\n"; |
||
| 206 | } |
||
| 207 | require_once __DIR__ . '/footer.php'; |
||
| 208 | } |
||
| 209 |