| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_Defender\Component\Security_Tweaks; |
| 4 |
|
| 5 |
use Calotes\Base\Component; |
| 6 |
use WP_Defender\Component\Security_Tweaks\Servers\Server; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class Protect_Information |
| 10 |
* @package WP_Defender\Component\Security_Tweaks |
| 11 |
*/ |
| 12 |
class Protect_Information extends Component { |
| 13 |
public $slug = 'protect-information'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Check whether the issue has been resolved or not. |
| 17 |
* |
| 18 |
* @return bool |
| 19 |
*/ |
| 20 |
public function check() { |
| 21 |
return Server::create( Server::get_current_server() )->from( $this->slug )->check(); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error. |
| 26 |
* @param string $current_server |
| 27 |
* |
| 28 |
* @return bool|\WP_Error |
| 29 |
*/ |
| 30 |
public function process( $current_server) { |
| 31 |
if ( 'apache' === $current_server || 'litespeed' === $current_server ) { |
| 32 |
// because the Prevent_PHP tweak uses the 'process' method too |
| 33 |
return Server::create( $current_server )->from( $this->slug )->process( false ); |
| 34 |
} else { |
| 35 |
|
| 36 |
return Server::create( $current_server )->from( $this->slug )->process(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* This is for un-do stuff that has be done in @process. |
| 42 |
* @param string|null $current_server |
| 43 |
* |
| 44 |
* @return bool|\WP_Error |
| 45 |
*/ |
| 46 |
public function revert( $current_server = null ) { |
| 47 |
if ( is_null( $current_server ) ) { |
| 48 |
$current_server = Server::get_current_server(); |
| 49 |
} |
| 50 |
return Server::create( $current_server )->from( $this->slug )->revert(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Shield up. |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public function shield_up() { |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Return a summary data of this tweak. |
| 64 |
* |
| 65 |
* @return array |
| 66 |
*/ |
| 67 |
public function to_array() { |
| 68 |
return [ |
| 69 |
'slug' => $this->slug, |
| 70 |
'title' => __( 'Prevent Information Disclosure', 'wpdef' ), |
| 71 |
'errorReason' => __( 'You don\'t have information disclosure protection active.', 'wpdef' ), |
| 72 |
'successReason' => __( 'You\'ve automatically enabled information disclosure protection.', 'wpdef' ), |
| 73 |
'misc' => [ |
| 74 |
'active_server' => Server::get_current_server(), |
| 75 |
'apache_rules' => Server::create( 'apache' )->from( $this->slug )->get_rules_for_instruction(), |
| 76 |
'nginx_rules' => Server::create( 'nginx' )->from( $this->slug )->get_rules(), |
| 77 |
], |
| 78 |
'blk_description' => __( 'Often servers are incorrectly configured, and can allow an attacker to get access to sensitive files like your config, .htaccess and backup files. We will automatically add an .htaccess file to your root folder to action this fix.', 'wpdef' ), |
| 79 |
'bulk_title' => __( 'Information Disclosure', 'wpdef' ) |
| 80 |
]; |
| 81 |
} |
| 82 |
} |
| 83 |
|