PluginProbe
Stream – Activity Log & Audit Trail / 3.7.0
Stream – Activity Log & Audit Trail v3.7.0
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-log.php +29 -21 trunk3.7.0 View file →
@@ -19,8 +19,16 @@
19 19 */
20 20 public $plugin;
21 21
22 22 /**
23 + * Hold Current visitors IP Address.
24 + *
25 + * @var string
26 + */
27 + private $ip_address;
28 +
29 +
30 + /**
23 31 * Previous Stream record ID, used for chaining same-session records
24 32 *
25 33 * @var int
26 34 */
@@ -33,8 +41,14 @@
33 41 */
34 42 public function __construct( $plugin ) {
35 43 $this->plugin = $plugin;
36 44
45 + // Support proxy mode by checking the `X-Forwarded-For` header first.
46 + $ip_address = wp_stream_filter_input( INPUT_SERVER, 'HTTP_X_FORWARDED_FOR', FILTER_VALIDATE_IP );
47 + $ip_address = $ip_address ? $ip_address : wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
48 +
49 + $this->ip_address = $ip_address;
50 +
37 51 // Ensure function used in various methods is pre-loaded.
38 52 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
39 53 require_once ABSPATH . '/wp-admin/includes/plugin.php';
40 54 }
@@ -72,13 +86,11 @@
72 86 if ( ! $wp_cron_tracking && 'wp_cron' === $agent ) {
73 87 return false;
74 88 }
75 89
76 - $ip_address = $this->plugin->get_client_ip_address();
77 -
78 90 $user = new \WP_User( $user_id );
79 91
80 - if ( $this->is_record_excluded( $connector, $context, $action, $user, $ip_address ) ) {
92 + if ( $this->is_record_excluded( $connector, $context, $action, $user ) ) {
81 93 return false;
82 94 }
83 95
84 96 $user_meta = array(
@@ -92,22 +104,17 @@
92 104 if ( 'wp_cli' === $agent && function_exists( 'posix_getuid' ) ) {
93 105 $uid = posix_getuid();
94 106 $user_info = posix_getpwuid( $uid );
95 107
96 - // Normalize the user info to an array if it's not already.
97 - if ( ! is_array( $user_info ) ) {
98 - $user_info = array( 'name' => 'unknown' );
99 - }
100 -
101 108 $user_meta['system_user_id'] = (int) $uid;
102 - $user_meta['system_user_name'] = (string) ( $user_info['name'] ?? 'unknown' );
109 + $user_meta['system_user_name'] = (string) $user_info['name'];
103 110 }
104 111
105 112 // Prevent any meta with null values from being logged.
106 113 $stream_meta = array_filter(
107 114 $args,
108 - function ( $value ) {
109 - return ! is_null( $value );
115 + function ( $var ) {
116 + return ! is_null( $var );
110 117 }
111 118 );
112 119
113 120 // Add user meta to Stream meta.
@@ -132,9 +139,9 @@
132 139 'summary' => (string) vsprintf( $message, $args ),
133 140 'connector' => (string) $connector,
134 141 'context' => (string) $context,
135 142 'action' => (string) $action,
136 - 'ip' => (string) $ip_address,
143 + 'ip' => (string) $this->ip_address,
137 144 'meta' => (array) $stream_meta,
138 145 );
139 146
140 147 if ( 0 === $recordarr['object_id'] ) {
@@ -166,8 +173,14 @@
166 173 if ( is_null( $user ) ) {
167 174 $user = wp_get_current_user();
168 175 }
169 176
177 + if ( is_null( $ip ) ) {
178 + $ip = $this->ip_address;
179 + } else {
180 + $ip = wp_stream_filter_var( $ip, FILTER_VALIDATE_IP );
181 + }
182 +
170 183 if ( ! empty( $user->roles ) ) {
171 184 $roles = array_values( $user->roles );
172 185 $role = $roles[0];
173 186 } else {
@@ -198,14 +211,9 @@
198 211 'author' => is_numeric( $exclude_rule['author_or_role'] ) ? absint( $exclude_rule['author_or_role'] ) : null,
199 212 'role' => ( ! empty( $exclude_rule['author_or_role'] ) && ! is_numeric( $exclude_rule['author_or_role'] ) ) ? $exclude_rule['author_or_role'] : null,
200 213 );
201 214
202 - $exclude_rules = array_filter(
203 - $exclude,
204 - function ( $value ) {
205 - return ! is_null( $value );
206 - }
207 - );
215 + $exclude_rules = array_filter( $exclude, 'strlen' );
208 216
209 217 if ( $this->record_matches_rules( $record, $exclude_rules ) ) {
210 218 $exclude_record = true;
211 219 break;
@@ -244,12 +252,12 @@
244 252 if ( 'ip_address' === $exclude_key ) {
245 253 $ip_addresses = explode( ',', $exclude_value );
246 254
247 255 if ( in_array( $record['ip_address'], $ip_addresses, true ) ) {
248 - ++$matches_found;
256 + $matches_found++;
249 257 }
250 258 } elseif ( $record[ $exclude_key ] === $exclude_value ) {
251 - ++$matches_found;
259 + $matches_found++;
252 260 }
253 261 }
254 262
255 263 return $matches_found === $matches_needed;
@@ -302,9 +310,9 @@
302 310 * @return string
303 311 */
304 312 public function debug_backtrace( $recordarr ) {
305 313 if ( version_compare( PHP_VERSION, '5.3.6', '<' ) ) {
306 - return __( 'Debug backtrace requires at least PHP 5.3.6', 'stream' );
314 + return __( 'Debug backtrace requires at least PHP 5.3.6', 'wp_stream' );
307 315 }
308 316
309 317 // Record details.
310 318 $summary = isset( $recordarr['summary'] ) ? $recordarr['summary'] : null;