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