| 1 |
<?php |
| 2 |
/** |
| 3 |
* Responsible for gathering analytics data for the firewall feature. |
| 4 |
* |
| 5 |
* @package WP_Defender\Helper\Analytics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Helper\Analytics; |
| 9 |
|
| 10 |
use WP_Defender\Event; |
| 11 |
|
| 12 |
/** |
| 13 |
* Gather analytics data required for firewall feature. |
| 14 |
*/ |
| 15 |
class Firewall extends Event { |
| 16 |
|
| 17 |
public const EVENT_IP_DETECTION = 'def_ip_detection'; |
| 18 |
public const PROP_IP_DETECTION = 'Detection Method'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Provides data for the frontend. |
| 22 |
* |
| 23 |
* @return array An array of data for the frontend. |
| 24 |
*/ |
| 25 |
public function data_frontend(): array { |
| 26 |
return array(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Converts the current state of the object to an array. |
| 31 |
* |
| 32 |
* @return array Returns an associative array of object properties. |
| 33 |
*/ |
| 34 |
public function to_array(): array { |
| 35 |
return array(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Imports data into the model. |
| 40 |
* |
| 41 |
* @param array $data Data to be imported into the model. |
| 42 |
*/ |
| 43 |
public function import_data( array $data ) { |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Removes settings for all submodules. |
| 48 |
*/ |
| 49 |
public function remove_settings() { |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Delete all the data & the cache. |
| 54 |
*/ |
| 55 |
public function remove_data() { |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Exports strings. |
| 60 |
*/ |
| 61 |
public function export_strings() { |
| 62 |
} |
| 63 |
// End. |
| 64 |
|
| 65 |
/** |
| 66 |
* Get a label of the detection method. |
| 67 |
* |
| 68 |
* @param string $ip_detection_type IP detection type. |
| 69 |
* @param string $http_ip_header HTTP IP header. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
public static function get_detection_method_label( string $ip_detection_type, string $http_ip_header ): string { |
| 74 |
if ( 'automatic' === $ip_detection_type ) { |
| 75 |
$detection_method = 'Automatic'; |
| 76 |
} else { |
| 77 |
// Manual options. |
| 78 |
$detection_method = 'Manual - '; |
| 79 |
switch ( $http_ip_header ) { |
| 80 |
case 'HTTP_X_FORWARDED_FOR': |
| 81 |
$detection_method .= 'X-Forward-For'; |
| 82 |
break; |
| 83 |
case 'HTTP_X_REAL_IP': |
| 84 |
$detection_method .= 'X-Real-IP'; |
| 85 |
break; |
| 86 |
case 'HTTP_CF_CONNECTING_IP': |
| 87 |
$detection_method .= 'CF-Connecting-IP'; |
| 88 |
break; |
| 89 |
case 'REMOTE_ADDR': |
| 90 |
default: |
| 91 |
$detection_method .= 'Remote-Addr'; |
| 92 |
break; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
return $detection_method; |
| 97 |
} |
| 98 |
} |
| 99 |
|