Index: branches/5.2.x/core/kernel/utility/logger.php
===================================================================
diff -u -r15553 -r15569
--- branches/5.2.x/core/kernel/utility/logger.php (.../logger.php) (revision 15553)
+++ branches/5.2.x/core/kernel/utility/logger.php (.../logger.php) (revision 15569)
@@ -1,6 +1,6 @@
Application->InitDone ) {
$this->_logRecord['LogUserId'] = $this->Application->RecallVar('user_id');
$this->_logRecord['LogSessionKey'] = $this->Application->GetSID();
+ $this->_logRecord['IpAddress'] = $this->Application->getClientIp();
}
return $this;
Index: branches/5.2.x/core/kernel/session/session_storage.php
===================================================================
diff -u -r15012 -r15569
--- branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 15012)
+++ branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 15569)
@@ -1,7 +1,7 @@
Application->ConfigValue('SessionIPAddressCheck') && ($result['IpAddress'] != $_SERVER['REMOTE_ADDR'])) {
+ if ($this->Application->ConfigValue('SessionIPAddressCheck') && ($result['IpAddress'] != $this->Application->getClientIp())) {
// most secure, except for cases where NAT (Network Address Translation)
// is used and two or more computers can have same IP address
return false;
Index: branches/5.2.x/core/units/helpers/rating_helper.php
===================================================================
diff -u -r15137 -r15569
--- branches/5.2.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 15137)
+++ branches/5.2.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 15569)
@@ -1,6 +1,6 @@
$object->GetID(),
'RatingValue' => $rating,
- 'IPAddress' => $_SERVER['REMOTE_ADDR'],
+ 'IPAddress' => $this->Application->getClientIp(),
'CreatedOn' => adodb_mktime(),
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'CatalogRatings');
Index: branches/5.2.x/core/kernel/utility/http_query.php
===================================================================
diff -u -r15345 -r15569
--- branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 15345)
+++ branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 15569)
@@ -1,6 +1,6 @@
_trustProxy = isset($vars['TrustProxy']) ? (bool)$vars['TrustProxy'] : false;
}
/**
@@ -717,7 +728,7 @@
$user_id = $session->GetField('PortalUserId');
$admin_mark = $this->Application->isAdmin ? 'ADMIN' : 'FRONT';
- $data = '[' . date('D M d H:i:s Y') . '] ' . $admin_mark . '; ip: ' . $_SERVER['REMOTE_ADDR'] . '; user_id: ' . $user_id . '; sid: ' . $this->Application->GetSID() . '; request: ' . "\n";
+ $data = '[' . date('D M d H:i:s Y') . '] ' . $admin_mark . '; ip: ' . $this->getClientIp() . '; user_id: ' . $user_id . '; sid: ' . $this->Application->GetSID() . '; request: ' . "\n";
if ( $this->Get ) {
$data .= "_GET:\n" . print_r($this->Get, true);
}
@@ -758,4 +769,34 @@
return !count($this->Get);
}
+ /**
+ * Returns the client IP address.
+ *
+ * @return string The client IP address
+ * @access public
+ */
+ public function getClientIp()
+ {
+ if ( $this->_trustProxy ) {
+ if ( array_key_exists('HTTP_CLIENT_IP', $_SERVER) ) {
+ return $_SERVER['HTTP_CLIENT_IP'];
+ }
+
+ if ( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ) {
+ $client_ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
+
+ foreach ($client_ip as $ip_address) {
+ $clean_ip_address = trim($ip_address);
+
+ if ( false !== filter_var($clean_ip_address, FILTER_VALIDATE_IP) ) {
+ return $clean_ip_address;
+ }
+ }
+
+ return '';
+ }
+ }
+
+ return $_SERVER['REMOTE_ADDR'];
+ }
}
\ No newline at end of file
Index: branches/5.2.x/core/install/steps_db.xml
===================================================================
diff -u -r15552 -r15569
--- branches/5.2.x/core/install/steps_db.xml (.../steps_db.xml) (revision 15552)
+++ branches/5.2.x/core/install/steps_db.xml (.../steps_db.xml) (revision 15569)
@@ -152,6 +152,9 @@
Errors and Warnings, and User defined messages that happened on your website. It has 3 modes - Enabled (logs everything, including user
defined messages), User-only (user defined messages only), and Disabled (don't log anything at all - default setting).
+ Trust Proxy - whatever to trust information provided by provided by proxy server (if any) located between web server
+ and client browser.
+
]]>
Index: branches/5.2.x/core/units/users/users_event_handler.php
===================================================================
diff -u -r15545 -r15569
--- branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 15545)
+++ branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 15569)
@@ -1,6 +1,6 @@
SetError('Username', 'banned');
}
- $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('IPAddress', $this->Application->getClientIp());
if ( !$this->Application->isAdmin ) {
$object->SetDBField('FrontLanguage', $this->Application->GetVar('m_lang'));
Index: branches/5.2.x/core/units/helpers/language_import_helper.php
===================================================================
diff -u -r15445 -r15569
--- branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15445)
+++ branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15569)
@@ -1,6 +1,6 @@
_updateEventsCache();
}
- $this->ip_address = getenv('HTTP_X_FORWARDED_FOR') ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR');
+ $this->ip_address = $this->Application->getClientIp();
// $this->_debugMode = $this->Application->isDebugMode();
}
Index: branches/5.2.x/core/units/phrases/phrases_event_handler.php
===================================================================
diff -u -r15465 -r15569
--- branches/5.2.x/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 15465)
+++ branches/5.2.x/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 15569)
@@ -1,6 +1,6 @@
translationChanged($object) ) {
$object->SetDBField('LastChanged_date', adodb_mktime() );
$object->SetDBField('LastChanged_time', adodb_mktime() );
- $object->SetDBField('LastChangeIP', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('LastChangeIP', $this->Application->getClientIp());
}
$this->Application->Session->SetCookie('last_module', $object->GetDBField('Module'));
Index: branches/5.2.x/core/units/reviews/reviews_event_handler.php
===================================================================
diff -u -r15145 -r15569
--- branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 15145)
+++ branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 15569)
@@ -1,6 +1,6 @@
getEventParam('type') == 'current_user' ) {
$object->addFilter('current_user', '%1$s.CreatedById = ' . $this->Application->RecallVar('user_id'));
- $object->addFilter('current_ip', '%1$s.IPAddress = "' . $_SERVER['REMOTE_ADDR'] . '"');
+ $object->addFilter('current_ip', '%1$s.IPAddress = "' . $this->Application->getClientIp() . '"');
}
}
@@ -275,7 +275,7 @@
$parent_info = $object->getLinkedInfo();
$item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType');
- $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('IPAddress', $this->Application->getClientIp());
$object->SetDBField('ItemType', $item_type);
$object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name'));
Index: branches/5.2.x/core/kernel/session/inp_session_storage.php
===================================================================
diff -u -r15012 -r15569
--- branches/5.2.x/core/kernel/session/inp_session_storage.php (.../inp_session_storage.php) (revision 15012)
+++ branches/5.2.x/core/kernel/session/inp_session_storage.php (.../inp_session_storage.php) (revision 15569)
@@ -1,7 +1,7 @@
$this->Application->GetDefaultThemeId(),
'GroupId' => $this->Application->ConfigValue('User_GuestGroup'),
'GroupList' => $this->Application->ConfigValue('User_GuestGroup'),
+ 'IpAddress' => $this->Application->getClientIp(),
);
if ( !$this->Application->isAdmin ) {
// Guest users on Front-End belongs to Everyone group too
$fields_hash['GroupList'] .= ',' . $this->Application->ConfigValue('User_LoggedInGroup');
}
- if( isset($_SERVER['REMOTE_ADDR']) ) {
- $fields_hash['IpAddress'] = $_SERVER['REMOTE_ADDR']; // getenv('REMOTE_ADDR') won't work on IIS, so use $_SERVER instead
- }
-
return array_merge($fields_hash, parent::GetSessionDefaults());
}
Index: branches/5.2.x/core/units/forms/form_submissions/form_submissions_eh.php
===================================================================
diff -u -r15314 -r15569
--- branches/5.2.x/core/units/forms/form_submissions/form_submissions_eh.php (.../form_submissions_eh.php) (revision 15314)
+++ branches/5.2.x/core/units/forms/form_submissions/form_submissions_eh.php (.../form_submissions_eh.php) (revision 15569)
@@ -1,6 +1,6 @@
getObject();
/* @var $object kDBItem */
- $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('IPAddress', $this->Application->getClientIp());
if ( !$object->GetDBField('ReferrerURL') ) {
$referrer = $this->Application->GetVar('original_referrer');
Index: branches/5.2.x/core/units/visits/visits_event_handler.php
===================================================================
diff -u -r15145 -r15569
--- branches/5.2.x/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 15145)
+++ branches/5.2.x/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 15569)
@@ -1,6 +1,6 @@
SetDBField('VisitDate_date', adodb_mktime());
$object->SetDBField('VisitDate_time', adodb_mktime());
$object->SetDBField('Referer', getArrayValue($_SERVER, 'HTTP_REFERER'));
- $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('IPAddress', $this->Application->getClientIp());
if ( $object->Create() ) {
$this->Application->StoreVar('visit_id', $object->GetID());
Index: branches/5.2.x/core/kernel/utility/debugger.php
===================================================================
diff -u -r15552 -r15569
--- branches/5.2.x/core/kernel/utility/debugger.php (.../debugger.php) (revision 15552)
+++ branches/5.2.x/core/kernel/utility/debugger.php (.../debugger.php) (revision 15569)
@@ -1,6 +1,6 @@
never match
+ if ( php_sapi_name() == 'cli' ) {
return false;
}
$ip_match = false;
$ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
+ $client_ip = self::getClientIp();
+
foreach ($ip_addresses as $ip_address) {
- if (self::netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
+ if ( self::netMatch($ip_address, $client_ip) ) {
$ip_match = true;
break;
}
@@ -105,6 +113,37 @@
}
/**
+ * Returns the client IP address.
+ *
+ * @return string The client IP address
+ * @access public
+ */
+ public static function getClientIp()
+ {
+ if ( self::$trustProxy ) {
+ if ( array_key_exists('HTTP_CLIENT_IP', $_SERVER) ) {
+ return $_SERVER['HTTP_CLIENT_IP'];
+ }
+
+ if ( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ) {
+ $client_ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
+
+ foreach ($client_ip as $ip_address) {
+ $clean_ip_address = trim($ip_address);
+
+ if ( false !== filter_var($clean_ip_address, FILTER_VALIDATE_IP) ) {
+ return $clean_ip_address;
+ }
+ }
+
+ return '';
+ }
+ }
+
+ return $_SERVER['REMOTE_ADDR'];
+ }
+
+ /**
* Checks, that given ip belongs to given subnet
*
* @param string $network
@@ -352,6 +391,11 @@
die('error: constant DEBUG_MODE defined directly, please use $dbg_options array instead');
}
+ if ( class_exists('kUtil') ) {
+ $vars = kUtil::getConfigVars();
+ DebuggerUtil::$trustProxy = isset($vars['TrustProxy']) ? (bool)$vars['TrustProxy'] : false;
+ }
+
// check IP before enabling debug mode
$ip_match = DebuggerUtil::ipMatch(isset($dbg_options['DBG_IP']) ? $dbg_options['DBG_IP'] : '');
Index: branches/5.2.x/core/kernel/managers/cache_manager.php
===================================================================
diff -u -r15226 -r15569
--- branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 15226)
+++ branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 15569)
@@ -1,6 +1,6 @@
getToCache()
);
- $cache_rebuild_by = SERVER_NAME . ' (' . getenv('REMOTE_ADDR') . ') - ' . adodb_date('d/m/Y H:i:s');
+ $cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . adodb_date('d/m/Y H:i:s');
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
$this->Application->setCache('master:configs_parsed', serialize($cache));
Index: branches/5.2.x/core/units/helpers/spam_helper.php
===================================================================
diff -u -r14777 -r15569
--- branches/5.2.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 14777)
+++ branches/5.2.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 15569)
@@ -1,6 +1,6 @@
$_SERVER['REMOTE_ADDR'],
+ 'IPaddress' => $this->Application->getClientIp(),
'PortalUserId' => $user_id,
'DataType' => $this->DataType,
);
Index: branches/5.2.x/core/kernel/application.php
===================================================================
diff -u -r15552 -r15569
--- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 15552)
+++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 15569)
@@ -1,6 +1,6 @@
_logger->delete($unique_id, $storage_medium);
}
+
+ /**
+ * Returns the client IP address.
+ *
+ * @return string The client IP address
+ * @access public
+ */
+ public function getClientIp()
+ {
+ return $this->HttpQuery->getClientIp();
+ }
}
\ No newline at end of file
Index: branches/5.2.x/core/kernel/globals.php
===================================================================
diff -u -r15517 -r15569
--- branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 15517)
+++ branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 15569)
@@ -1,6 +1,6 @@
never match
+ if ( php_sapi_name() == 'cli' ) {
return false;
}
$ip_match = false;
$ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
+ $application =& kApplication::Instance();
+ $client_ip = $application->getClientIp();
+
foreach ($ip_addresses as $ip_address) {
- if (self::netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
+ if ( self::netMatch($ip_address, $client_ip) ) {
$ip_match = true;
break;
}
Index: branches/5.2.x/core/units/logs/session_logs/session_log_eh.php
===================================================================
diff -u -r15145 -r15569
--- branches/5.2.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 15145)
+++ branches/5.2.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 15569)
@@ -1,6 +1,6 @@
adodb_mktime(),
- 'IP' => $_SERVER['REMOTE_ADDR'],
+ 'IP' => $this->Application->getClientIp(),
'PortalUserId' => $this->Application->RecallVar('user_id'),
'SessionId' => $this->Application->GetSID(),
'Status' => SESSION_LOG_ACTIVE,
Index: branches/5.2.x/core/units/helpers/deployment_helper.php
===================================================================
diff -u -r15332 -r15569
--- branches/5.2.x/core/units/helpers/deployment_helper.php (.../deployment_helper.php) (revision 15332)
+++ branches/5.2.x/core/units/helpers/deployment_helper.php (.../deployment_helper.php) (revision 15569)
@@ -1,6 +1,6 @@
isCommandLine = isset($GLOBALS['argv']) && count($GLOBALS['argv']);
if ( !$this->isCommandLine ) {
- $this->ip = $_SERVER['REMOTE_ADDR'];
+ $this->ip = $this->Application->getClientIp();
}
elseif ( isset($GLOBALS['argv'][3]) ) {
$this->ip = $GLOBALS['argv'][3];
Index: branches/5.2.x/core/install/step_templates/sys_config.tpl
===================================================================
diff -u -r15552 -r15569
--- branches/5.2.x/core/install/step_templates/sys_config.tpl (.../sys_config.tpl) (revision 15552)
+++ branches/5.2.x/core/install/step_templates/sys_config.tpl (.../sys_config.tpl) (revision 15569)
@@ -13,6 +13,7 @@
'WebsiteCharset' => Array ('type' => 'text', 'title' => 'Website Charset', 'section' => 'Misc', 'required' => 1, 'default' => 'utf-8'),
'EnableSystemLog' => Array ('type' => 'radio', 'title' => 'Enable "System Log"', 'section' => 'Misc', 'required' => 1, 'default' => '0'),
'SystemLogMaxLevel' => Array ('type' => 'select', 'title' => 'Highest "Log Level", that will be saved in "System Log"', 'section' => 'Misc', 'required' => 1, 'default' => '5'),
+ 'TrustProxy' => Array ('type' => 'radio', 'title' => 'Trust Proxy', 'section' => 'Misc', 'required' => 1, 'default' => '0'),
);
$settings['CacheHandler']['options'] = $this->toolkit->getWorkingCacheHandlers();
@@ -22,6 +23,7 @@
0 => 'emergency', 1 => 'alert', 2 => 'critical', 3 => 'error',
4 => 'warning', 5 => 'notice', 6 => 'info', 7 => 'debug'
);
+ $settings['TrustProxy']['options'] = Array (1 => 'Yes', 0 => 'No');
$row_class = 'table-color2';