| 1 |
<?php |
| 2 |
/** |
| 3 |
* Manages the protection against information disclosure by configuring server settings. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component\Security_Tweaks |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component\Security_Tweaks; |
| 9 |
|
| 10 |
use WP_Error; |
| 11 |
use WP_Defender\Component\Security_Tweaks\Servers\Server; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class Protect_Information |
| 15 |
*/ |
| 16 |
class Protect_Information extends Abstract_Security_Tweaks { |
| 17 |
|
| 18 |
/** |
| 19 |
* Slug identifier for the component. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
public string $slug = 'protect-information'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Check whether the issue has been resolved or not. |
| 27 |
* |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public function check() { |
| 31 |
return Server::create( Server::get_current_server() )->from( $this->slug )->check(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error. |
| 36 |
* |
| 37 |
* @param string $current_server The current server software being used. |
| 38 |
* |
| 39 |
* @return bool|WP_Error |
| 40 |
*/ |
| 41 |
public function process( $current_server ) { |
| 42 |
if ( 'apache' === $current_server || 'litespeed' === $current_server ) { |
| 43 |
// Because the Prevent_PHP tweak uses the 'process' method too. |
| 44 |
return Server::create( $current_server )->from( $this->slug )->process( false ); |
| 45 |
} else { |
| 46 |
|
| 47 |
return Server::create( $current_server )->from( $this->slug )->process(); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* This is for un-do stuff that has been done in @process. |
| 53 |
* |
| 54 |
* @param string|null $current_server The current server software being used. |
| 55 |
* |
| 56 |
* @return bool|WP_Error |
| 57 |
*/ |
| 58 |
public function revert( $current_server = null ) { |
| 59 |
if ( is_null( $current_server ) ) { |
| 60 |
$current_server = Server::get_current_server(); |
| 61 |
} |
| 62 |
|
| 63 |
return Server::create( $current_server )->from( $this->slug )->revert(); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Shield up. |
| 68 |
* |
| 69 |
* @return bool |
| 70 |
*/ |
| 71 |
public function shield_up() { |
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Retrieve the tweak's label. |
| 77 |
* |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function get_label(): string { |
| 81 |
return wp_strip_all_tags( __( 'Prevent info disclosure', 'defender-security' ) ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Get the error reason. |
| 86 |
* |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
public function get_error_reason(): string { |
| 90 |
return ''; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Return a summary data of this tweak. |
| 95 |
* |
| 96 |
* @return array |
| 97 |
*/ |
| 98 |
public function to_array(): array { |
| 99 |
return array( |
| 100 |
'slug' => $this->slug, |
| 101 |
'title' => $this->get_label(), |
| 102 |
'errorReason' => $this->get_error_reason(), |
| 103 |
'successReason' => wp_strip_all_tags( __( 'Sensitive files are locked.', 'defender-security' ) ), |
| 104 |
'misc' => array( |
| 105 |
'active_server' => Server::get_current_server(), |
| 106 |
'apache_rules' => Server::create( 'apache' )->from( $this->slug )->get_rules_for_instruction(), |
| 107 |
'litespeed_rules' => Server::create( 'litespeed' )->from( $this->slug )->get_rules_for_instruction(), |
| 108 |
'nginx_rules' => Server::create( 'nginx' )->from( $this->slug )->get_rules(), |
| 109 |
'show_action_button' => true, |
| 110 |
), |
| 111 |
'bulk_description' => wp_strip_all_tags( |
| 112 |
__( 'Misconfigured servers can expose sensitive files, including config files, .htaccess files, and backups. Prevent info disclosure to protect private site details and reduce the risk of unauthorized access.', 'defender-security' ) |
| 113 |
), |
| 114 |
'bulk_title' => wp_strip_all_tags( __( 'Information Disclosure', 'defender-security' ) ), |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
|