Skip to content

Commit

Permalink
Replaced $_SERVER['REMOTE_ADDR'] with \Geeklog\IP::getIPAddress()
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Jun 5, 2021
1 parent 0a0cf41 commit 9dbcd6f
Show file tree
Hide file tree
Showing 38 changed files with 98 additions and 98 deletions.
6 changes: 3 additions & 3 deletions plugins/polls/functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function plugin_deletecomment_polls($cid, $id, $returnBoolean)
COM_redirect($_CONF['site_url'] . "/polls/index.php?pid=$id&aid=-1");
}
} else {
COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) "
COM_errorLog("User {$_USER['username']} (IP: " . \Geeklog\IP::getIPAddress() . ") "
. "tried to illegally delete comment $cid from poll $id");

if ($returnBoolean) {
Expand Down Expand Up @@ -803,7 +803,7 @@ function POLLS_pollsave($pid, $aid)
// This always does an insert so no need to provide key_field and key_value args
DB_query(
"INSERT INTO {$_TABLES['pollvoters']} (ipaddress, date, pid) "
. "VALUES ('" . DB_escapeString($_SERVER['REMOTE_ADDR']) . "', " . time() . ", '" . DB_escapeString($pid) . "')");
. "VALUES ('" . DB_escapeString(\Geeklog\IP::getIPAddress()) . "', " . time() . ", '" . DB_escapeString($pid) . "')");
$retval .= COM_showMessageText(
$LANG_POLLS['savedvotemsg'] . ' "'
. DB_getItem($_TABLES['polltopics'], 'topic', "pid = '" . DB_escapeString($pid) . "'") . '"',
Expand Down Expand Up @@ -1027,7 +1027,7 @@ function POLLS_ipAlreadyVoted($pid, $ip = '')
$retval = false;

if (empty($ip)) {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = \Geeklog\IP::getIPAddress();
}

if (DB_count($_TABLES['pollvoters'],
Expand Down
4 changes: 2 additions & 2 deletions plugins/recaptcha/functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ function RECAPTCHA_getIP()
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = \Geeklog\IP::getIPAddress();
}

return $ip;
Expand Down Expand Up @@ -703,7 +703,7 @@ function RECAPTCHA_verify($type, $token)
$entry = sprintf(
RECAPTCHA_str('entry_error', true),
$type,
$_SERVER['REMOTE_ADDR'],
\Geeklog\IP::getIPAddress(),
$msg
);
$entry = RECAPTCHA_esc($entry);
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/Akismet.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
if (($answer == PLG_SPAM_FOUND) || ($answer == PLG_SPAM_UNSURE)) {
SPAMX_log(
$LANG_SX00['foundspam'] . 'Akismet' . $LANG_SX00['foundspam2'] . $this->getUid()
. $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']
. $LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress()
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/BannedUsers.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
$answer = PLG_SPAM_FOUND; // quit on first positive match
SPAMX_log($LANG_SX00['foundspam'] . $val . ' (' . $LANG28[42] . ')' .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']
$LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress()
);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/BlackList.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
$this->updateStat('Personal', $val);
SPAMX_log($LANG_SX00['foundspam'] . $val .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
$LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/Header.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
SPAMX_log($LANG_SX00['foundspam'] . $entry .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] .
$_SERVER['REMOTE_ADDR']
\Geeklog\IP::getIPAddress()
);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/IP.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IP extends BaseCommand
public function execute($comment, $permanentLink = null, $commentType = Geeklog\Akismet::COMMENT_TYPE_COMMENT,
$commentAuthor = null, $commentAuthorEmail = null, $commentAuthorURL = null)
{
return $this->_process($_SERVER['REMOTE_ADDR']);
return $this->_process(\Geeklog\IP::getIPAddress());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/IPofUrl.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
$this->updateStat('IPofUrl', $val);
SPAMX_log($LANG_SX00['foundspam'] . $urls[2][$i] .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']
$LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress()
);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/MailAdmin.Action.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
{
global $_CONF, $LANG_SX00, $_SPX_CONF;

$uid = $this->getUid() . '@' . $_SERVER['REMOTE_ADDR'];
$uid = $this->getUid() . '@' . \Geeklog\IP::getIPAddress();
$msg = sprintf($LANG_SX00['emailmsg'],
$_CONF['site_name'], $uid, $comment);

Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/SFS.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
$answer = PLG_SPAM_FOUND;
SPAMX_log($LANG_SX00['foundspam'] . 'Stop Forum Spam (SFS)' .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']
$LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress()
);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/SFS.Misc.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SFS extends BaseCommand
public function execute($comment, $permanentLink = null, $commentType = Geeklog\Akismet::COMMENT_TYPE_COMMENT,
$commentAuthor = null, $commentAuthorEmail = null, $commentAuthorURL = null)
{
$this->result = $this->_process($commentAuthorEmail, $_SERVER['REMOTE_ADDR']);
$this->result = $this->_process($commentAuthorEmail, \Geeklog\IP::getIPAddress());

return $this->result;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/SFSbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CheckForSpam($post)
}


$ip = $_SERVER['REMOTE_ADDR'];
$ip = \Geeklog\IP::getIPAddress();
$query = "http://api.stopforumspam.org/api?f=serial&ip=$ip";

$req = new HTTP_Request2(
Expand Down
2 changes: 1 addition & 1 deletion plugins/spamx/SNL.Examine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function execute($comment, $permanentLink = null, $commentType = Geeklog\
$answer = PLG_SPAM_FOUND;
SPAMX_log($LANG_SX00['foundspam'] . 'Spam Number of Links (SNL)' .
$LANG_SX00['foundspam2'] . $uid .
$LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']
$LANG_SX00['foundspam3'] . \Geeklog\IP::getIPAddress()
);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/staticpages/functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function plugin_deletecomment_staticpages($cid, $id, $returnBoolean)
COM_redirect($url);
}
} else {
COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) "
COM_errorLog("User {$_USER['username']} (IP: " . \Geeklog\IP::getIPAddress() . ") "
. "tried to illegally delete comment $cid from staticpage $id");

if ($returnBoolean) {
Expand Down
2 changes: 1 addition & 1 deletion public_html/admin/plugins/recaptcha/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// Only let admin users access this page
if (!SEC_hasRights('recaptcha.edit')) {
// Someone is trying to illegally access this page
COM_errorLog("Someone has tried to illegally access the recaptcha Admin page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$_SERVER['REMOTE_ADDR']}", 1);
COM_errorLog("Someone has tried to illegally access the recaptcha Admin page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: " . \Geeklog\IP::getIPAddress(), 1);

$content = COM_startBlock(RECAPTCHA_esc($LANG_ACCESS['accessdenied']))
. RECAPTCHA_esc($LANG_ACCESS['plugin_access_denied_msg'])
Expand Down
2 changes: 1 addition & 1 deletion public_html/admin/plugins/spamx/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
// Someone is trying to illegally access this page
$display .= COM_showMessageText($MESSAGE[29], $MESSAGE[30]);
$display = COM_createHTMLDocument($display, array('pagetitle' => $MESSAGE[30]));
COM_accessLog("Someone has tried to illegally access the Spam-X Admin page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$_SERVER['REMOTE_ADDR']}", 1);
COM_accessLog("Someone has tried to illegally access the Spam-X Admin page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: " . \Geeklog\IP::getIPAddress(), 1);
COM_output($display);
exit;
}
Expand Down
10 changes: 5 additions & 5 deletions public_html/lib-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ function COM_errorLog($logEntry, $actionId = '')
if (!empty($logEntry)) {
$logEntry = str_replace(array('<?', '?>'), array('(@', '@)'), $logEntry);
$timestamp = @strftime('%c');
$remoteAddress = $_SERVER['REMOTE_ADDR'];
$remoteAddress = \Geeklog\IP::getIPAddress();

if (!isset($_CONF['path_layout']) && (($actionId == 2) || empty($actionId))) {
$actionId = 1;
Expand Down Expand Up @@ -6133,7 +6133,7 @@ function COM_checkSpeedlimit($type = 'submit', $max = 1, $property = '')
}

if (empty($property)) {
$property = $_SERVER['REMOTE_ADDR'];
$property = \Geeklog\IP::getIPAddress();
}
$property = DB_escapeString($property);

Expand Down Expand Up @@ -6594,7 +6594,7 @@ function COM_applyBasicFilter($parameter, $isNumeric = false)

if ($log_manipulation) {
if (strcmp($p, $parameter) != 0) {
COM_errorLog("Filter applied: >> {$parameter} << filtered to {$p} [IP {$_SERVER['REMOTE_ADDR']}]", 1);
COM_errorLog("Filter applied: >> {$parameter} << filtered to {$p} [IP " . \Geeklog\IP::getIPAddress() . "]", 1);
}
}

Expand Down Expand Up @@ -8067,9 +8067,9 @@ function COM_handle404($alternate_url = '')
// Add file log stuff
if (isset($_CONF['404_log']) && $_CONF['404_log']) {
if (empty($_USER['uid'])) {
$byUser = 'anon@' . $_SERVER['REMOTE_ADDR'];
$byUser = 'anon@' . \Geeklog\IP::getIPAddress();
} else {
$byUser = $_USER['uid'] . '@' . $_SERVER['REMOTE_ADDR'];
$byUser = $_USER['uid'] . '@' . \Geeklog\IP::getIPAddress();
}

$logEntry = "404 Error generated by {$byUser} for URL: {$url}";
Expand Down
2 changes: 1 addition & 1 deletion public_html/links/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ function prepare_link_item($A, &$template)
$msg = $LANG_LINKS[119] . LB . LB . "{$title}, {$url}" . LB . LB
. $LANG_LINKS[120] . LB . $editurl . LB . LB
. $LANG_LINKS[121] . $_USER['username'] . ', IP: '
. $_SERVER['REMOTE_ADDR'];
. \Geeklog\IP::getIPAddress();
COM_mail($_CONF['site_mail'], $LANG_LINKS[118], $msg);
$message = array($LANG_LINKS[123], $LANG_LINKS[122]);
}
Expand Down
6 changes: 3 additions & 3 deletions public_html/pingback.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function PNB_handlePingback($id, $type, $url, $oururl)

// handle pingbacks to articles on our own site
$skip_speedlimit = false;
if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) {
if (\Geeklog\IP::getIPAddress() === $_SERVER['SERVER_ADDR']) {
if (!isset($_CONF['pingback_self'])) {
$_CONF['pingback_self'] = 0; // default: skip self-pingbacks
}
Expand All @@ -95,7 +95,7 @@ function PNB_handlePingback($id, $type, $url, $oururl)
// update speed limit in any case
COM_updateSpeedlimit('pingback');

if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
if (\Geeklog\IP::getIPAddress() !== $_SERVER['SERVER_ADDR']) {
if ($_CONF['check_trackback_link'] & 4) {
$parts = parse_url($url);
if (empty($parts['host'])) {
Expand All @@ -104,7 +104,7 @@ function PNB_handlePingback($id, $type, $url, $oururl)
return new XML_RPC_Response(0, 33, $PNB_ERROR['uri_invalid']);
} else {
$ip = gethostbyname($parts['host']);
if ($ip != $_SERVER['REMOTE_ADDR']) {
if ($ip !== \Geeklog\IP::getIPAddress()) {
TRB_logRejected('Pingback: IP address mismatch', $url);

return new XML_RPC_Response(0, 49, $PNB_ERROR['spam']);
Expand Down
2 changes: 1 addition & 1 deletion system/classes/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function init($ipAddressTable = 'gl_ip_addresses', $anonymizationP
self::$anonymizationPolicy = $anonymizationPolicy;

self::$ipAddress = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.01';
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
// $_SERVER['REMOTE_ADDR'] = '0.0.0.0'; // some time in the future
self::$isInitialized = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions system/classes/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ public static function send($to, $subject, $body, $from = '', $html = false, $pr
$headers = $message->getHeaders();
$headers->addTextHeader('X-Mailer', 'Geeklog ' . VERSION);

if (!empty($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['SERVER_ADDR']) &&
($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'])
if (!empty(IP::getIPAddress()) && !empty($_SERVER['SERVER_ADDR']) &&
(IP::getIPAddress() !== $_SERVER['SERVER_ADDR'])
) {
$url = COM_getCurrentURL();

if (substr($url, 0, strlen($_CONF['site_admin_url']))
!= $_CONF['site_admin_url']
) {
$headers->addTextHeader('X-Originating-IP', $_SERVER['REMOTE_ADDR']);
$headers->addTextHeader('X-Originating-IP', \Geeklog\IP::getIPAddress());
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/classes/downloader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ public function downloadFile($fileName)
// IP address and, if so, verify the user is originating from one of
// those places
if ($this->_limitByIP) {
if (!in_array($_SERVER['REMOTE_ADDR'], $this->_allowedIPS)) {
$this->_addError('The IP, ' . $_SERVER['REMOTE_ADDR'] . ' is not in the list of accepted IP addresses. Refusing to allow file download(s)');
if (!in_array(\Geeklog\IP::getIPAddress(), $this->_allowedIPS)) {
$this->_addError('The IP, ' . \Geeklog\IP::getIPAddress() . ' is not in the list of accepted IP addresses. Refusing to allow file download(s)');

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion system/classes/sanitize.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private function _applyFilter($parameter, $isnumeric = false)

if ($this->_logmode) {
if (strcmp($p, $parameter) != 0) {
COM_errorLog("Filter applied: >> $parameter << filtered to $p [IP {$_SERVER['REMOTE_ADDR']}]", 1);
COM_errorLog("Filter applied: >> $parameter << filtered to $p [IP " . \Geeklog\IP::getIPAddress() . "]", 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/classes/upload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1211,8 +1211,8 @@ public function uploadFiles()
// IP address and, if so, verify the poster is originating from one of
// those places
if ($this->_limitByIP) {
if (!in_array($_SERVER['REMOTE_ADDR'], $this->_allowedIPS)) {
$this->_addError('The IP, ' . $_SERVER['REMOTE_ADDR'] . ' is not in the list of '
if (!in_array(\Geeklog\IP::getIPAddress(), $this->_allowedIPS)) {
$this->_addError('The IP, ' . \Geeklog\IP::getIPAddress() . ' is not in the list of '
. 'accepted IP addresses. Refusing to allow file upload(s)');

return false;
Expand Down
2 changes: 1 addition & 1 deletion system/lib-article.php
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ function plugin_deletecomment_article($cid, $id, $returnBoolean)
COM_redirect(COM_buildUrl($_CONF['site_url'] . "/article.php?story=$id") . '#comments');
}
} else {
COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) "
COM_errorLog("User {$_USER['username']} (IP: " . \Geeklog\IP::getIPAddress() . ") "
. "tried to illegally delete comment $cid from $id");

if ($returnBoolean) {
Expand Down

0 comments on commit 9dbcd6f

Please sign in to comment.