Skip to content

Commit 65a222c

Browse files
cheeseeatercheeseeater
authored andcommitted
Revert to using 'REMOTE_ADDR' used before CF change
1 parent e47e96b commit 65a222c

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

public_html/assets/includes/database.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ function setAccountType($user, $type){
7171
$stmt = NULL;
7272
if(is_int($user)) $stmt = $forum_dbh->prepare("UPDATE `$forum_member_table` SET `account`=? WHERE `memberId`=?");
7373
else $stmt = $forum_dbh->prepare("UPDATE `$forum_member_table` SET `account`=? WHERE `username`=?");
74-
74+
7575
$stmt->execute(array($type, $user));
7676
}
7777

7878
function setProfileSettings($userid, $settings){
7979
global $forum_dbh;
80-
80+
8181
$res = forumQuery("SELECT * FROM `os_profile_settings` WHERE `userid`=?", array($userid));
8282
if(sizeof($res) == 0){
8383
$stmt = $forum_dbh->prepare("INSERT INTO `os_profile_settings` (`userid`, `bgcolor`) VALUES (:userid, :bgcolor)");
@@ -90,10 +90,10 @@ function setProfileSettings($userid, $settings){
9090

9191
function getProfileSettings($userid){
9292
global $forum_dbh;
93-
93+
9494
$res = forumQuery("SELECT * FROM `os_profile_settings` WHERE `userid`=?", array($userid));
9595
if(sizeof($res) == 0) return array("bgcolor" => "avatar");
96-
96+
9797
return $res[0];
9898
}
9999

@@ -104,7 +104,7 @@ function getUserInfo($userid){
104104
global $forum_profile_data_table;
105105
$res = forumQuery("SELECT * FROM `$forum_member_table` WHERE `memberId`=?", array($userid));
106106
if(sizeof($res) == 0) return FALSE;
107-
107+
108108
// the order by here is so we can avoid having to look through the entire array and access by groupId - 1
109109
$groupRes = forumQuery("SELECT * FROM `$forum_group_table` ORDER BY `groupId`", array());
110110
$memberGroupRes = forumQuery("SELECT * FROM `$forum_group_member_table` WHERE `memberId`=?", array($userid));
@@ -114,7 +114,7 @@ function getUserInfo($userid){
114114
$groupName = $groupRes[intval($groupId) - 1]['name'];
115115
array_push($groups, $groupName);
116116
}
117-
117+
118118
// look up profile fields
119119
$about = "No about section given";
120120
$location = "No location set";
@@ -127,7 +127,7 @@ function getUserInfo($userid){
127127
$location = $profileRes[$j]['data'];
128128
}
129129
}
130-
130+
131131
$userInfo = array(
132132
"userid" => $userid,
133133
"username" => $res[0]['username'],
@@ -251,28 +251,28 @@ function checkFailedLogin($userid){
251251
if(sizeof($res) == 0){
252252
$stmt2 = $forum_dbh->prepare("INSERT INTO `os_login_attempts` (`ipAddr`,`userAgent`, `lastLoginTime`, `loginAttempts`, `userid`)"
253253
. " VALUES(:ip, :ua, NOW(), 1, :userid)");
254-
$stmt2->execute(array(":userid"=>$userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
254+
$stmt2->execute(array(":userid"=>$userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
255255
return TRUE;
256256
} else {
257257
$lastDate = $res[0]['lastLoginTime'];
258258
$numAttempts = $res[0]['loginAttempts'] + 1;
259-
259+
260260
$stmt4 = $forum_dbh->prepare("SELECT UNIX_TIMESTAMP(?) as timestamp");
261261
$stmt4->execute(array($lastDate));
262262
$res4 = $stmt4->fetchAll(PDO::FETCH_ASSOC);
263263
$lastDate = $res4[0]['timestamp'];
264-
264+
265265
if($numAttempts < 5){
266266
$stmt3 = $forum_dbh->prepare("UPDATE `os_login_attempts` SET `ipAddr`=:ip, `userAgent`=:ua, `lastLoginTime`=NOW(), `loginAttempts`=`loginAttempts`+1 WHERE `userid`=:userid");
267-
$stmt3->execute(array(":userid"=>$userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
267+
$stmt3->execute(array(":userid"=>$userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
268268
return TRUE;
269269
} else {
270270
$val1 = time() - $lastDate;
271271
if($val1 < 120){
272272
return 120 - $val1;
273273
}
274274
$stmt3 = $forum_dbh->prepare("UPDATE `os_login_attempts` SET `ipAddr`=:ip, `userAgent`=:ua, `lastLoginTime`=NOW(), `loginAttempts`=0 WHERE `userid`=:userid");
275-
$stmt3->execute(array(":userid"=>$userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
275+
$stmt3->execute(array(":userid"=>$userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
276276
return TRUE;
277277
}
278278
}
@@ -287,22 +287,22 @@ function isUserAbleToReport($userid){
287287
if(sizeof($res) == 0){
288288
$stmt2 = $dbh->prepare("INSERT INTO `$user_report_table_name` (`userid`,`lastReportTime`, `ipAddr`, `userAgent`)"
289289
. " VALUES(:userid, NOW(), :ip, :ua)");
290-
$stmt2->execute(array(":userid"=>$userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
290+
$stmt2->execute(array(":userid"=>$userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
291291
return TRUE;
292292
} else {
293293
$lastDate = $res[0]['lastReportTime'];
294-
294+
295295
$stmt2 = $dbh->prepare("SELECT UNIX_TIMESTAMP(?) as timestamp");
296296
$stmt2->execute(array($lastDate));
297297
$res2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
298298
$lastDate = $res2[0]['timestamp'];
299-
299+
300300
$reports_per_sec = 1 / 60; // 1 report per minute
301301
$val1 = time() - $lastDate;
302302
$val2 = 1 / $reports_per_sec;
303303
if($val1 > $val2){
304304
$stmt3 = $dbh->prepare("UPDATE `$user_report_table_name` SET `lastReportTime`=NOW(), `ipAddr`=:ip, `userAgent`=:ua WHERE `userid`=:userid");
305-
$stmt3->execute(array(":userid" => $userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
305+
$stmt3->execute(array(":userid" => $userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
306306
return TRUE;
307307
} else {
308308
return $val2 - $val1; // no spam pls
@@ -319,24 +319,24 @@ function isUserAbleToUpload($userid, $post_size){
319319
if(sizeof($res) == 0){
320320
$stmt2 = $dbh->prepare("INSERT INTO `$user_upload_table_name` (`userid`,`bytesUploaded`,`lastUploadTime`, `ipAddr`, `userAgent`)"
321321
. " VALUES(:userid, :postSize, NOW(), :ip, :ua)");
322-
$stmt2->execute(array(":userid"=>$userid, ":postSize" => $post_size, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
322+
$stmt2->execute(array(":userid"=>$userid, ":postSize" => $post_size, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
323323
return TRUE;
324324
} else {
325325
$lastDate = $res[0]['lastUploadTime'];
326-
326+
327327
$stmt2 = $dbh->prepare("SELECT UNIX_TIMESTAMP(?) as timestamp");
328328
$stmt2->execute(array($lastDate));
329329
$res2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
330330
$lastDate = $res2[0]['timestamp'];
331-
331+
332332
$uploadSize = $res[0]['bytesUploaded'];
333-
333+
334334
$bytes_per_sec = 1024 * 1024 * 10 / 60; // 10MB / min
335335
$val1 = time() - $lastDate;
336336
$val2 = $uploadSize / $bytes_per_sec;
337337
if($val1 > $val2){
338338
$stmt3 = $dbh->prepare("UPDATE `$user_upload_table_name` SET `lastUploadTime`=NOW(), `bytesUploaded`=:bytes, `ipAddr`=:ip, `userAgent`=:ua WHERE `userid`=:userid");
339-
$stmt3->execute(array(":bytes" => $post_size, ":userid" => $userid, ":ip" => $_SERVER['X_FORWARDED_FOR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
339+
$stmt3->execute(array(":bytes" => $post_size, ":userid" => $userid, ":ip" => $_SERVER['REMOTE_ADDR'], ":ua" => $_SERVER['HTTP_USER_AGENT']));
340340
return TRUE;
341341
} else {
342342
return $val2 - $val1; // no spam pls

0 commit comments

Comments
 (0)