| @@ -921,8 +921,54 @@ | ||
| 921 | 921 | return $this->database->get_activity_logs_count( $args ); |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | /** |
| 925 | + * The address a logged event was recorded for, when the event carries one | |
| 926 | + * | |
| 927 | + * Every blocking module stores the request it turned away under | |
| 928 | + * 'request_uri' in the entry's extra data, but nothing ever showed it. The | |
| 929 | + * address is what tells a firewall hit on a legitimate page apart from a | |
| 930 | + * scanner probe, and a remote manager being refused apart from an intruder, | |
| 931 | + * so an owner looking at a surprising entry had no way to tell which one | |
| 932 | + * they were reading. | |
| 933 | + * | |
| 934 | + * That first sentence was not true of the firewall, which is the module | |
| 935 | + * that logs the most: it stored the address under 'uri', so the column | |
| 936 | + * this method feeds was empty for every one of its blocks, and diagnosing | |
| 937 | + * one meant reading the table by hand. Fixed in the firewall in 2.11.1; | |
| 938 | + * 'uri' is read here as well so the entries already on disk show it too. | |
| 939 | + * | |
| 940 | + * @since 2.10.2 | |
| 941 | + * | |
| 942 | + * @param string|array|null $extra_data The entry's extra data, as stored. | |
| 943 | + * @return string The recorded address, or '' when the entry carries none. | |
| 944 | + */ | |
| 945 | + public static function extract_request_uri( $extra_data ) { | |
| 946 | + if ( is_string( $extra_data ) ) { | |
| 947 | + $extra_data = json_decode( $extra_data, true ); | |
| 948 | + } | |
| 949 | + | |
| 950 | + if ( ! is_array( $extra_data ) ) { | |
| 951 | + return ''; | |
| 952 | + } | |
| 953 | + | |
| 954 | + $key = isset( $extra_data['request_uri'] ) ? 'request_uri' : 'uri'; | |
| 955 | + | |
| 956 | + if ( ! isset( $extra_data[ $key ] ) ) { | |
| 957 | + return ''; | |
| 958 | + } | |
| 959 | + | |
| 960 | + // Nothing writes anything but a string here, but the value comes back | |
| 961 | + // from a longtext column that any past version could have filled, and | |
| 962 | + // casting an array would emit a notice and print the word "Array". | |
| 963 | + if ( ! is_scalar( $extra_data[ $key ] ) ) { | |
| 964 | + return ''; | |
| 965 | + } | |
| 966 | + | |
| 967 | + return (string) $extra_data[ $key ]; | |
| 968 | + } | |
| 969 | + | |
| 970 | + /** | |
| 925 | 971 | * Cleanup old logs based on retention settings (uses fresh options) |
| 926 | 972 | */ |
| 927 | 973 | public function cleanup_old_logs() { |
| 928 | 974 | $options = $this->get_current_options(); |