|
@@ -12,12 +12,16 @@
|
12
|
12
|
require 'config.php'; //The config contains all site wide configuration information
|
13
|
13
|
|
14
|
14
|
// Check for common setup pitfalls
|
15
|
|
-if (!ini_get('short_open_tag')) { die('short_open_tag must be On in php.ini'); }
|
16
|
|
-if (!extension_loaded('apcu')) { die('APCu extension not loaded'); }
|
|
15
|
+if (!ini_get('short_open_tag')) {
|
|
16
|
+ die('short_open_tag must be On in php.ini');
|
|
17
|
+}
|
|
18
|
+if (!extension_loaded('apcu')) {
|
|
19
|
+ die('APCu extension not loaded');
|
|
20
|
+}
|
17
|
21
|
|
18
|
22
|
// Deal with dumbasses
|
19
|
23
|
if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) {
|
20
|
|
- die('d14:failure reason40:Invalid .torrent, try downloading again.e');
|
|
24
|
+ die('d14:failure reason40:Invalid .torrent, try downloading again.e');
|
21
|
25
|
}
|
22
|
26
|
|
23
|
27
|
require(SERVER_ROOT.'/classes/proxies.class.php');
|
|
@@ -25,30 +29,33 @@ require(SERVER_ROOT.'/classes/proxies.class.php');
|
25
|
29
|
// Get the user's actual IP address if they're proxied.
|
26
|
30
|
// Or if cloudflare is used
|
27
|
31
|
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
|
28
|
|
- $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
|
32
|
+ $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
29
|
33
|
}
|
30
|
34
|
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
|
31
|
35
|
&& proxyCheck($_SERVER['REMOTE_ADDR'])
|
32
|
|
- && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'],
|
|
36
|
+ && filter_var(
|
|
37
|
+ $_SERVER['HTTP_X_FORWARDED_FOR'],
|
33
|
38
|
FILTER_VALIDATE_IP,
|
34
|
|
- FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
35
|
|
- $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
39
|
+ FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
|
|
40
|
+ )) {
|
|
41
|
+ $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
36
|
42
|
}
|
37
|
43
|
|
38
|
44
|
if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) {
|
39
|
|
- // Skip this block if running from cli or if the browser is old and shitty
|
40
|
|
- // This should really be done in nginx config TODO: Remove
|
41
|
|
- if ($_SERVER['HTTP_HOST'] == 'www.'.SITE_DOMAIN) {
|
42
|
|
- header('Location: https://'.SITE_DOMAIN.$_SERVER['REQUEST_URI']); die();
|
43
|
|
- }
|
|
45
|
+ // Skip this block if running from cli or if the browser is old and shitty
|
|
46
|
+ // This should really be done in nginx config TODO: Remove
|
|
47
|
+ if ($_SERVER['HTTP_HOST'] == 'www.'.SITE_DOMAIN) {
|
|
48
|
+ header('Location: https://'.SITE_DOMAIN.$_SERVER['REQUEST_URI']);
|
|
49
|
+ die();
|
|
50
|
+ }
|
44
|
51
|
}
|
45
|
52
|
|
46
|
53
|
|
47
|
54
|
|
48
|
55
|
$ScriptStartTime = microtime(true); //To track how long a page takes to create
|
49
|
56
|
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
50
|
|
- $RUsage = getrusage();
|
51
|
|
- $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
|
|
57
|
+ $RUsage = getrusage();
|
|
58
|
+ $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
|
52
|
59
|
}
|
53
|
60
|
ob_start(); //Start a buffer, mainly in case there is a mysql error
|
54
|
61
|
|
|
@@ -97,19 +104,19 @@ list($Classes, $ClassLevels) = Users::get_classes();
|
97
|
104
|
// Permissions
|
98
|
105
|
|
99
|
106
|
if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
|
100
|
|
- $SessionID = $_COOKIE['session'];
|
101
|
|
- $LoggedUser['ID'] = (int)$_COOKIE['userid'];
|
|
107
|
+ $SessionID = $_COOKIE['session'];
|
|
108
|
+ $LoggedUser['ID'] = (int)$_COOKIE['userid'];
|
102
|
109
|
|
103
|
|
- $UserID = $LoggedUser['ID']; //TODO: UserID should not be LoggedUser
|
|
110
|
+ $UserID = $LoggedUser['ID']; //TODO: UserID should not be LoggedUser
|
104
|
111
|
|
105
|
|
- if (!$LoggedUser['ID'] || !$SessionID) {
|
106
|
|
- logout();
|
107
|
|
- }
|
|
112
|
+ if (!$LoggedUser['ID'] || !$SessionID) {
|
|
113
|
+ logout();
|
|
114
|
+ }
|
108
|
115
|
|
109
|
|
- $UserSessions = $Cache->get_value("users_sessions_$UserID");
|
110
|
|
- if (!is_array($UserSessions)) {
|
111
|
|
- $DB->query(
|
112
|
|
- "SELECT
|
|
116
|
+ $UserSessions = $Cache->get_value("users_sessions_$UserID");
|
|
117
|
+ if (!is_array($UserSessions)) {
|
|
118
|
+ $DB->query(
|
|
119
|
+ "SELECT
|
113
|
120
|
SessionID,
|
114
|
121
|
Browser,
|
115
|
122
|
OperatingSystem,
|
|
@@ -118,169 +125,167 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
|
118
|
125
|
FROM users_sessions
|
119
|
126
|
WHERE UserID = '$UserID'
|
120
|
127
|
AND Active = 1
|
121
|
|
- ORDER BY LastUpdate DESC");
|
122
|
|
- $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC);
|
123
|
|
- $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
|
124
|
|
- }
|
|
128
|
+ ORDER BY LastUpdate DESC"
|
|
129
|
+ );
|
|
130
|
+ $UserSessions = $DB->to_array('SessionID', MYSQLI_ASSOC);
|
|
131
|
+ $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
|
|
132
|
+ }
|
125
|
133
|
|
126
|
|
- if (!array_key_exists($SessionID, $UserSessions)) {
|
127
|
|
- logout();
|
128
|
|
- }
|
|
134
|
+ if (!array_key_exists($SessionID, $UserSessions)) {
|
|
135
|
+ logout();
|
|
136
|
+ }
|
129
|
137
|
|
130
|
|
- // Check if user is enabled
|
131
|
|
- $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
|
132
|
|
- if ($Enabled === false) {
|
133
|
|
- $DB->query("
|
|
138
|
+ // Check if user is enabled
|
|
139
|
+ $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
|
|
140
|
+ if ($Enabled === false) {
|
|
141
|
+ $DB->query("
|
134
|
142
|
SELECT Enabled
|
135
|
143
|
FROM users_main
|
136
|
144
|
WHERE ID = '$LoggedUser[ID]'");
|
137
|
|
- list($Enabled) = $DB->next_record();
|
138
|
|
- $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
|
139
|
|
- }
|
140
|
|
- if ($Enabled == 2) {
|
141
|
|
- logout();
|
142
|
|
- }
|
|
145
|
+ list($Enabled) = $DB->next_record();
|
|
146
|
+ $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
|
|
147
|
+ }
|
|
148
|
+ if ($Enabled == 2) {
|
|
149
|
+ logout();
|
|
150
|
+ }
|
143
|
151
|
|
144
|
|
- // Up/Down stats
|
145
|
|
- $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
|
146
|
|
- if (!is_array($UserStats)) {
|
147
|
|
- $DB->query("
|
|
152
|
+ // Up/Down stats
|
|
153
|
+ $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
|
|
154
|
+ if (!is_array($UserStats)) {
|
|
155
|
+ $DB->query("
|
148
|
156
|
SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio
|
149
|
157
|
FROM users_main
|
150
|
158
|
WHERE ID = '$LoggedUser[ID]'");
|
151
|
|
- $UserStats = $DB->next_record(MYSQLI_ASSOC);
|
152
|
|
- $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
|
153
|
|
- }
|
|
159
|
+ $UserStats = $DB->next_record(MYSQLI_ASSOC);
|
|
160
|
+ $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
|
|
161
|
+ }
|
154
|
162
|
|
155
|
|
- // Get info such as username
|
156
|
|
- $LightInfo = Users::user_info($LoggedUser['ID']);
|
157
|
|
- $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
|
|
163
|
+ // Get info such as username
|
|
164
|
+ $LightInfo = Users::user_info($LoggedUser['ID']);
|
|
165
|
+ $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
|
158
|
166
|
|
159
|
|
- // Create LoggedUser array
|
160
|
|
- $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
|
|
167
|
+ // Create LoggedUser array
|
|
168
|
+ $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
|
161
|
169
|
|
162
|
|
- $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
|
|
170
|
+ $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
|
163
|
171
|
|
164
|
|
- // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
|
165
|
|
- $LoggedUser['RatioWatch'] = (
|
166
|
|
- $LoggedUser['RatioWatchEnds']
|
|
172
|
+ // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
|
|
173
|
+ $LoggedUser['RatioWatch'] = (
|
|
174
|
+ $LoggedUser['RatioWatchEnds']
|
167
|
175
|
&& time() < strtotime($LoggedUser['RatioWatchEnds'])
|
168
|
176
|
&& ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
|
169
|
|
- );
|
|
177
|
+ );
|
170
|
178
|
|
171
|
|
- // Load in the permissions
|
172
|
|
- $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
|
173
|
|
- $LoggedUser['Permissions']['MaxCollages'] += Donations::get_personal_collages($LoggedUser['ID']);
|
|
179
|
+ // Load in the permissions
|
|
180
|
+ $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
|
|
181
|
+ $LoggedUser['Permissions']['MaxCollages'] += Donations::get_personal_collages($LoggedUser['ID']);
|
174
|
182
|
|
175
|
|
- // Change necessary triggers in external components
|
176
|
|
- $Cache->CanClear = check_perms('admin_clear_cache');
|
|
183
|
+ // Change necessary triggers in external components
|
|
184
|
+ $Cache->CanClear = check_perms('admin_clear_cache');
|
177
|
185
|
|
178
|
|
- // Because we <3 our staff
|
179
|
|
- if (check_perms('site_disable_ip_history')) {
|
180
|
|
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
181
|
|
- }
|
|
186
|
+ // Because we <3 our staff
|
|
187
|
+ if (check_perms('site_disable_ip_history')) {
|
|
188
|
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
|
189
|
+ }
|
182
|
190
|
|
183
|
|
- // Update LastUpdate every 10 minutes
|
184
|
|
- if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
|
185
|
|
- $DB->query("
|
|
191
|
+ // Update LastUpdate every 10 minutes
|
|
192
|
+ if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
|
|
193
|
+ $DB->query("
|
186
|
194
|
UPDATE users_main
|
187
|
195
|
SET LastAccess = NOW()
|
188
|
196
|
WHERE ID = '$LoggedUser[ID]'");
|
189
|
|
- $SessionQuery =
|
190
|
|
- "UPDATE users_sessions
|
|
197
|
+ $SessionQuery =
|
|
198
|
+ "UPDATE users_sessions
|
191
|
199
|
SET ";
|
192
|
|
- // Only update IP if we have an encryption key in memory
|
193
|
|
- if (apcu_exists('DBKEY')) {
|
194
|
|
- $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
|
195
|
|
- }
|
196
|
|
- $SessionQuery .=
|
197
|
|
- "Browser = '$Browser',
|
|
200
|
+ // Only update IP if we have an encryption key in memory
|
|
201
|
+ if (apcu_exists('DBKEY')) {
|
|
202
|
+ $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
|
|
203
|
+ }
|
|
204
|
+ $SessionQuery .=
|
|
205
|
+ "Browser = '$Browser',
|
198
|
206
|
OperatingSystem = '$OperatingSystem',
|
199
|
207
|
LastUpdate = NOW()
|
200
|
208
|
WHERE UserID = '$LoggedUser[ID]'
|
201
|
209
|
AND SessionID = '".db_string($SessionID)."'";
|
202
|
|
- $DB->query($SessionQuery);
|
203
|
|
- $Cache->begin_transaction("users_sessions_$UserID");
|
204
|
|
- $Cache->delete_row($SessionID);
|
205
|
|
- $UsersSessionCache = array(
|
|
210
|
+ $DB->query($SessionQuery);
|
|
211
|
+ $Cache->begin_transaction("users_sessions_$UserID");
|
|
212
|
+ $Cache->delete_row($SessionID);
|
|
213
|
+ $UsersSessionCache = array(
|
206
|
214
|
'SessionID' => $SessionID,
|
207
|
215
|
'Browser' => $Browser,
|
208
|
216
|
'OperatingSystem' => $OperatingSystem,
|
209
|
217
|
'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
|
210
|
218
|
'LastUpdate' => sqltime() );
|
211
|
|
- $Cache->insert_front($SessionID, $UsersSessionCache);
|
212
|
|
- $Cache->commit_transaction(0);
|
213
|
|
- }
|
214
|
|
-
|
215
|
|
- // Notifications
|
216
|
|
- if (isset($LoggedUser['Permissions']['site_torrents_notify'])) {
|
217
|
|
- $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
|
218
|
|
- if (!is_array($LoggedUser['Notify'])) {
|
219
|
|
- $DB->query("
|
|
219
|
+ $Cache->insert_front($SessionID, $UsersSessionCache);
|
|
220
|
+ $Cache->commit_transaction(0);
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ // Notifications
|
|
224
|
+ if (isset($LoggedUser['Permissions']['site_torrents_notify'])) {
|
|
225
|
+ $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
|
|
226
|
+ if (!is_array($LoggedUser['Notify'])) {
|
|
227
|
+ $DB->query("
|
220
|
228
|
SELECT ID, Label
|
221
|
229
|
FROM users_notify_filters
|
222
|
230
|
WHERE UserID = '$LoggedUser[ID]'");
|
223
|
|
- $LoggedUser['Notify'] = $DB->to_array('ID');
|
224
|
|
- $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
|
|
231
|
+ $LoggedUser['Notify'] = $DB->to_array('ID');
|
|
232
|
+ $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
|
|
233
|
+ }
|
225
|
234
|
}
|
226
|
|
- }
|
227
|
|
-
|
228
|
|
- // We've never had to disable the wiki privs of anyone.
|
229
|
|
- if ($LoggedUser['DisableWiki']) {
|
230
|
|
- unset($LoggedUser['Permissions']['site_edit_wiki']);
|
231
|
|
- }
|
232
|
235
|
|
233
|
|
- // IP changed
|
|
236
|
+ // We've never had to disable the wiki privs of anyone.
|
|
237
|
+ if ($LoggedUser['DisableWiki']) {
|
|
238
|
+ unset($LoggedUser['Permissions']['site_edit_wiki']);
|
|
239
|
+ }
|
234
|
240
|
|
235
|
|
- if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
|
|
241
|
+ // IP changed
|
236
|
242
|
|
237
|
|
- if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
|
238
|
|
- error('Your IP address has been banned.');
|
239
|
|
- }
|
|
243
|
+ if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
|
|
244
|
+ if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
|
|
245
|
+ error('Your IP address has been banned.');
|
|
246
|
+ }
|
240
|
247
|
|
241
|
|
- $CurIP = db_string($LoggedUser['IP']);
|
242
|
|
- $NewIP = db_string($_SERVER['REMOTE_ADDR']);
|
243
|
|
- $DB->query("
|
|
248
|
+ $CurIP = db_string($LoggedUser['IP']);
|
|
249
|
+ $NewIP = db_string($_SERVER['REMOTE_ADDR']);
|
|
250
|
+ $DB->query("
|
244
|
251
|
SELECT IP
|
245
|
252
|
FROM users_history_ips
|
246
|
253
|
WHERE EndTime IS NULL
|
247
|
254
|
AND UserID = '$LoggedUser[ID]'");
|
248
|
|
- while (list($EncIP) = $DB->next_record()) {
|
249
|
|
- if (Crypto::decrypt($EncIP) == $CurIP) {
|
250
|
|
- $CurIP = $EncIP;
|
251
|
|
- // CurIP is now the encrypted IP that was already in the database (for matching)
|
252
|
|
- break;
|
253
|
|
- }
|
254
|
|
- }
|
255
|
|
- $DB->query("
|
|
255
|
+ while (list($EncIP) = $DB->next_record()) {
|
|
256
|
+ if (Crypto::decrypt($EncIP) == $CurIP) {
|
|
257
|
+ $CurIP = $EncIP;
|
|
258
|
+ // CurIP is now the encrypted IP that was already in the database (for matching)
|
|
259
|
+ break;
|
|
260
|
+ }
|
|
261
|
+ }
|
|
262
|
+ $DB->query("
|
256
|
263
|
UPDATE users_history_ips
|
257
|
264
|
SET EndTime = NOW()
|
258
|
265
|
WHERE EndTime IS NULL
|
259
|
266
|
AND UserID = '$LoggedUser[ID]'
|
260
|
267
|
AND IP = '$CurIP'");
|
261
|
|
- $DB->query("
|
|
268
|
+ $DB->query("
|
262
|
269
|
INSERT IGNORE INTO users_history_ips
|
263
|
270
|
(UserID, IP, StartTime)
|
264
|
271
|
VALUES
|
265
|
272
|
('$LoggedUser[ID]', '".Crypto::encrypt($NewIP)."', NOW())");
|
266
|
273
|
|
267
|
|
- $ipcc = Tools::geoip($NewIP);
|
268
|
|
- $DB->query("
|
|
274
|
+ $ipcc = Tools::geoip($NewIP);
|
|
275
|
+ $DB->query("
|
269
|
276
|
UPDATE users_main
|
270
|
277
|
SET IP = '".Crypto::encrypt($NewIP)."', ipcc = '$ipcc'
|
271
|
278
|
WHERE ID = '$LoggedUser[ID]'");
|
272
|
|
- $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
|
273
|
|
- $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
|
274
|
|
- $Cache->commit_transaction(0);
|
275
|
|
-
|
276
|
|
-
|
277
|
|
- }
|
|
279
|
+ $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
|
|
280
|
+ $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
|
|
281
|
+ $Cache->commit_transaction(0);
|
|
282
|
+ }
|
278
|
283
|
|
279
|
284
|
|
280
|
|
- // Get stylesheets
|
281
|
|
- $Stylesheets = $Cache->get_value('stylesheets');
|
282
|
|
- if (!is_array($Stylesheets)) {
|
283
|
|
- $DB->query('
|
|
285
|
+ // Get stylesheets
|
|
286
|
+ $Stylesheets = $Cache->get_value('stylesheets');
|
|
287
|
+ if (!is_array($Stylesheets)) {
|
|
288
|
+ $DB->query('
|
284
|
289
|
SELECT
|
285
|
290
|
ID,
|
286
|
291
|
LOWER(REPLACE(Name, " ", "_")) AS Name,
|
|
@@ -288,16 +293,16 @@ if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
|
288
|
293
|
LOWER(REPLACE(Additions, " ", "_")) AS Additions,
|
289
|
294
|
Additions AS ProperAdditions
|
290
|
295
|
FROM stylesheets');
|
291
|
|
- $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
|
292
|
|
- $Cache->cache_value('stylesheets', $Stylesheets, 0);
|
293
|
|
- }
|
|
296
|
+ $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
|
|
297
|
+ $Cache->cache_value('stylesheets', $Stylesheets, 0);
|
|
298
|
+ }
|
294
|
299
|
|
295
|
|
- //A9 TODO: Clean up this messy solution
|
296
|
|
- $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
|
|
300
|
+ //A9 TODO: Clean up this messy solution
|
|
301
|
+ $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
|
297
|
302
|
|
298
|
|
- if (empty($LoggedUser['Username'])) {
|
299
|
|
- logout(); // Ghost
|
300
|
|
- }
|
|
303
|
+ if (empty($LoggedUser['Username'])) {
|
|
304
|
+ logout(); // Ghost
|
|
305
|
+ }
|
301
|
306
|
}
|
302
|
307
|
G::initialize();
|
303
|
308
|
$Debug->set_flag('end user handling');
|
|
@@ -307,48 +312,50 @@ $Debug->set_flag('start function definitions');
|
307
|
312
|
/**
|
308
|
313
|
* Log out the current session
|
309
|
314
|
*/
|
310
|
|
-function logout() {
|
311
|
|
- global $SessionID;
|
312
|
|
- setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
313
|
|
- setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
314
|
|
- setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
315
|
|
- if ($SessionID) {
|
316
|
|
-
|
317
|
|
- G::$DB->query("
|
|
315
|
+function logout()
|
|
316
|
+{
|
|
317
|
+ global $SessionID;
|
|
318
|
+ setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
|
319
|
+ setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
|
320
|
+ setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
|
|
321
|
+ if ($SessionID) {
|
|
322
|
+ G::$DB->query("
|
318
|
323
|
DELETE FROM users_sessions
|
319
|
324
|
WHERE UserID = '" . G::$LoggedUser['ID'] . "'
|
320
|
325
|
AND SessionID = '".db_string($SessionID)."'");
|
321
|
326
|
|
322
|
|
- G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
|
323
|
|
- G::$Cache->delete_row($SessionID);
|
324
|
|
- G::$Cache->commit_transaction(0);
|
325
|
|
- }
|
326
|
|
- G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
|
327
|
|
- G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
|
328
|
|
- G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
|
|
327
|
+ G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
|
|
328
|
+ G::$Cache->delete_row($SessionID);
|
|
329
|
+ G::$Cache->commit_transaction(0);
|
|
330
|
+ }
|
|
331
|
+ G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
|
|
332
|
+ G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
|
|
333
|
+ G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
|
329
|
334
|
|
330
|
|
- header('Location: login.php');
|
|
335
|
+ header('Location: login.php');
|
331
|
336
|
|
332
|
|
- die();
|
|
337
|
+ die();
|
333
|
338
|
}
|
334
|
339
|
|
335
|
|
-function logout_all_sessions() {
|
336
|
|
- $UserID = G::$LoggedUser['ID'];
|
|
340
|
+function logout_all_sessions()
|
|
341
|
+{
|
|
342
|
+ $UserID = G::$LoggedUser['ID'];
|
337
|
343
|
|
338
|
|
- G::$DB->query("
|
|
344
|
+ G::$DB->query("
|
339
|
345
|
DELETE FROM users_sessions
|
340
|
346
|
WHERE UserID = '$UserID'");
|
341
|
347
|
|
342
|
|
- G::$Cache->delete_value('users_sessions_' . $UserID);
|
343
|
|
- logout();
|
|
348
|
+ G::$Cache->delete_value('users_sessions_' . $UserID);
|
|
349
|
+ logout();
|
344
|
350
|
}
|
345
|
351
|
|
346
|
|
-function enforce_login() {
|
347
|
|
- global $SessionID;
|
348
|
|
- if (!$SessionID || !G::$LoggedUser) {
|
349
|
|
- setcookie('redirect', $_SERVER['REQUEST_URI'], time() + 60 * 30, '/', '', false);
|
350
|
|
- logout();
|
351
|
|
- }
|
|
352
|
+function enforce_login()
|
|
353
|
+{
|
|
354
|
+ global $SessionID;
|
|
355
|
+ if (!$SessionID || !G::$LoggedUser) {
|
|
356
|
+ setcookie('redirect', $_SERVER['REQUEST_URI'], time() + 60 * 30, '/', '', false);
|
|
357
|
+ logout();
|
|
358
|
+ }
|
352
|
359
|
}
|
353
|
360
|
|
354
|
361
|
/**
|
|
@@ -358,20 +365,21 @@ function enforce_login() {
|
358
|
365
|
* @param Are we using ajax?
|
359
|
366
|
* @return authorisation status. Prints an error message to LAB_CHAN on IRC on failure.
|
360
|
367
|
*/
|
361
|
|
-function authorize($Ajax = false) {
|
362
|
|
- if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != G::$LoggedUser['AuthKey']) {
|
363
|
|
- send_irc("PRIVMSG ".LAB_CHAN." :".G::$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER']) ? " coming from ".$_SERVER['HTTP_REFERER'] : ""));
|
364
|
|
- error('Invalid authorization key. Go back, refresh, and try again.', $Ajax);
|
365
|
|
- return false;
|
366
|
|
- }
|
367
|
|
- return true;
|
|
368
|
+function authorize($Ajax = false)
|
|
369
|
+{
|
|
370
|
+ if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != G::$LoggedUser['AuthKey']) {
|
|
371
|
+ send_irc("PRIVMSG ".LAB_CHAN." :".G::$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER']) ? " coming from ".$_SERVER['HTTP_REFERER'] : ""));
|
|
372
|
+ error('Invalid authorization key. Go back, refresh, and try again.', $Ajax);
|
|
373
|
+ return false;
|
|
374
|
+ }
|
|
375
|
+ return true;
|
368
|
376
|
}
|
369
|
377
|
|
370
|
378
|
$Debug->set_flag('ending function definitions');
|
371
|
379
|
//Include /sections/*/index.php
|
372
|
380
|
$Document = basename(parse_url($_SERVER['SCRIPT_FILENAME'], PHP_URL_PATH), '.php');
|
373
|
381
|
if (!preg_match('/^[a-z0-9]+$/i', $Document)) {
|
374
|
|
- error(404);
|
|
382
|
+ error(404);
|
375
|
383
|
}
|
376
|
384
|
|
377
|
385
|
$StripPostKeys = array_fill_keys(array('password', 'cur_pass', 'new_pass_1', 'new_pass_2', 'verifypassword', 'confirm_password', 'ChangePassword', 'Password'), true);
|
|
@@ -388,9 +396,9 @@ define('STAFF_LOCKED', 1);
|
388
|
396
|
$AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
|
389
|
397
|
|
390
|
398
|
if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
|
391
|
|
- require(SERVER_ROOT . '/sections/locked/index.php');
|
|
399
|
+ require(SERVER_ROOT . '/sections/locked/index.php');
|
392
|
400
|
} else {
|
393
|
|
- require(SERVER_ROOT . '/sections/' . $Document . '/index.php');
|
|
401
|
+ require(SERVER_ROOT . '/sections/' . $Document . '/index.php');
|
394
|
402
|
}
|
395
|
403
|
|
396
|
404
|
$Debug->set_flag('completed module execution');
|
|
@@ -401,8 +409,8 @@ upon hit rather than being browser cached for changing content.
|
401
|
409
|
Old versions of Internet Explorer choke when downloading binary files over HTTPS with disabled cache.
|
402
|
410
|
Define the following constant in files that handle file downloads */
|
403
|
411
|
if (!defined('SKIP_NO_CACHE_HEADERS')) {
|
404
|
|
- header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
|
405
|
|
- header('Pragma: no-cache');
|
|
412
|
+ header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
|
|
413
|
+ header('Pragma: no-cache');
|
406
|
414
|
}
|
407
|
415
|
|
408
|
416
|
//Flush to user
|