Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add an optional parameter to use a specific header value (e.g. X-Forw…
Browse files Browse the repository at this point in the history
…arder-For) instead of local detected IP in the logs. Fix #763
  • Loading branch information
cdujeu committed Dec 30, 2014
1 parent 456df5d commit 4242a32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/src/plugins/core.log/class.AJXP_Logger.php
Expand Up @@ -217,14 +217,19 @@ public static function logAction($action, $params=array())
*/
public static function getClientAdress()
{
if (isSet(self::$globalOptions["CUSTOM_HEADER_FOR_IP"])){
$hName = "HTTP_".strtoupper(str_replace("-", "_", self::$globalOptions["CUSTOM_HEADER_FOR_IP"]));
if(isSet($_SERVER[$hName])) {
return $_SERVER[$hName];
}
}
if (isSet($_SERVER['REMOTE_ADDR'])) {
$msg = $_SERVER['REMOTE_ADDR'];
} else if (php_sapi_name() == "cli") {
$msg = "PHP_CLI";
} else {
$msg = "Unknown Origin";
return $_SERVER['REMOTE_ADDR'];
}
if (php_sapi_name() == "cli") {
return "PHP_CLI";
}
return $msg;
return "Unknown Origin";
}

/**
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/core.log/manifest.xml
Expand Up @@ -5,6 +5,8 @@
<server_settings>
<global_param name="ERROR_TO_ERROR_LOG" type="boolean" label="CONF_MESSAGE[Send errors to system log]"
description="CONF_MESSAGE[Always send all Error-level messages to the system error log]" default="false" mandatory="true"/>
<global_param name="CUSTOM_HEADER_FOR_IP" type="string" label="CONF_MESSAGE[Custom Header for IP]"
description="CONF_MESSAGE[Can be used in a proxy situation to use e.g. X-Forwarded-For header value instead of proxy IP.]" mandatory="false"/>
<global_param description="CONF_MESSAGE[Plugin instance to handle log implementation]" label="CONF_MESSAGE[Logger plugin]"
name="UNIQUE_PLUGIN_INSTANCE" type="plugin_instance:log" default="log.text" mandatory="true"/>
</server_settings>
Expand Down

0 comments on commit 4242a32

Please sign in to comment.