Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support proxy mode by checking the X-Forwarded-For header first #963

Merged
merged 2 commits into from Apr 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions classes/class-log.php
Expand Up @@ -107,19 +107,23 @@ function( $var ) {
$role = '';
}

// Support proxy mode by checking the `X-Forwarded-For` header first
$ip_address = wp_stream_filter_input( INPUT_SERVER, 'HTTP_X_FORWARDED_FOR', FILTER_VALIDATE_IP );
$ip_address = $ip_address ? $ip_address : wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fjarrett This is cool, thanks. The REMOTE_ADDR is also requested on line 154/158 So will need to be applied there.
Perhaps it might be better to have method to fetch the IP, or even a simpleIP param set in the constructor to prevent code duplication.


$recordarr = array(
'object_id' => (int) $object_id,
'site_id' => (int) is_multisite() ? get_current_site()->id : 1,
'blog_id' => (int) apply_filters( 'wp_stream_blog_id_logged', get_current_blog_id() ),
'user_id' => (int) $user_id,
'user_role' => (string) $role,
'created' => (string) $iso_8601_extended_date,
'summary' => (string) vsprintf( $message, $args ),
'connector' => (string) $connector,
'context' => (string) $context,
'action' => (string) $action,
'ip' => (string) wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP ),
'meta' => (array) $stream_meta,
'object_id' => (int) $object_id,
'site_id' => (int) is_multisite() ? get_current_site()->id : 1,
'blog_id' => (int) apply_filters( 'wp_stream_blog_id_logged', get_current_blog_id() ),
'user_id' => (int) $user_id,
'user_role' => (string) $role,
'created' => (string) $iso_8601_extended_date,
'summary' => (string) vsprintf( $message, $args ),
'connector' => (string) $connector,
'context' => (string) $context,
'action' => (string) $action,
'ip' => (string) $ip_address,
'meta' => (array) $stream_meta,
);

if ( 0 === $recordarr['object_id'] ) {
Expand Down