2015-10-15 22:52:37 +10:00
|
|
|
<?php
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* MainWP Security
|
|
|
|
*
|
|
|
|
* @package MainWP/Child
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
|
2020-05-05 20:13:38 +07:00
|
|
|
namespace MainWP\Child;
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Class MainWP_Security
|
|
|
|
*
|
|
|
|
* Detect security issues
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
class MainWP_Security {
|
2020-05-05 13:19:34 +00:00
|
|
|
|
2020-05-05 20:13:38 +07:00
|
|
|
/**
|
|
|
|
* Method get_class_name()
|
|
|
|
*
|
2020-05-27 19:22:54 +02:00
|
|
|
* Get class name.
|
2020-05-05 20:13:38 +07:00
|
|
|
*
|
2020-05-27 19:22:54 +02:00
|
|
|
* @return string __CLASS__ Class name.
|
2020-05-05 20:13:38 +07:00
|
|
|
*/
|
|
|
|
public static function get_class_name() {
|
|
|
|
return __CLASS__;
|
|
|
|
}
|
2020-05-05 13:19:34 +00:00
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method fix_all()
|
|
|
|
*
|
|
|
|
* Fire off functions to fix detected security issues.
|
|
|
|
*
|
|
|
|
* @uses MainWP_Security::remove_wp_version() Remove the WordPress version.
|
|
|
|
* @uses MainWP_Security::remove_rsd() Remove the Really Simple Discovery meta tag.
|
|
|
|
* @uses MainWP_Security::remove_wlw() Remove the Windows Live Writer meta tag.
|
|
|
|
* @uses MainWP_Security::remove_php_reporting() Disable the PHP error reporting.
|
|
|
|
* @uses MainWP_Security::remove_registered_versions() Remove the registered scripts versions.
|
|
|
|
* @uses MainWP_Security::remove_generator_version() Remove the WordPress Generator meta tag.
|
|
|
|
* @uses MainWP_Security::remove_readme() Remove the readme.html file.
|
|
|
|
* @uses MainWP_Security::remove_script_versions() Remove scripts and stylesheets versions.
|
|
|
|
* @uses MainWP_Security::remove_theme_versions() Remove themes scripts and stylesheets version.
|
|
|
|
*/
|
2020-05-06 20:22:11 +07:00
|
|
|
public static function fix_all() {
|
2020-03-26 14:05:04 +00:00
|
|
|
self::remove_wp_version();
|
|
|
|
self::remove_rsd();
|
|
|
|
self::remove_wlw();
|
|
|
|
self::remove_php_reporting();
|
|
|
|
self::remove_registered_versions();
|
|
|
|
self::remove_generator_version();
|
|
|
|
self::remove_readme();
|
2015-10-15 22:52:37 +10:00
|
|
|
|
2020-05-05 20:13:38 +07:00
|
|
|
add_filter( 'style_loader_src', array( self::get_class_name(), 'remove_script_versions' ), PHP_INT_MAX );
|
|
|
|
add_filter( 'style_loader_src', array( self::get_class_name(), 'remove_theme_versions' ), PHP_INT_MAX );
|
|
|
|
add_filter( 'script_loader_src', array( self::get_class_name(), 'remove_script_versions' ), PHP_INT_MAX );
|
|
|
|
add_filter( 'script_loader_src', array( self::get_class_name(), 'remove_theme_versions' ), PHP_INT_MAX );
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Private static variable to hold the directory listing information.
|
|
|
|
*
|
|
|
|
* @var mixed Default null
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
private static $listingDirectories = null;
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method init_listing_directories()
|
|
|
|
*
|
|
|
|
* Get directories array to prevent listing.
|
|
|
|
*/
|
2020-05-06 20:22:11 +07:00
|
|
|
private static function init_listing_directories() {
|
2020-03-26 14:05:04 +00:00
|
|
|
if ( null === self::$listingDirectories ) {
|
2020-03-26 19:45:07 +00:00
|
|
|
$wp_upload_dir = wp_upload_dir();
|
2020-03-26 14:05:04 +00:00
|
|
|
self::$listingDirectories = array(
|
2015-10-15 22:52:37 +10:00
|
|
|
WP_CONTENT_DIR,
|
|
|
|
WP_PLUGIN_DIR,
|
|
|
|
get_theme_root(),
|
|
|
|
$wp_upload_dir['basedir'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method prevent_listing()
|
|
|
|
*
|
|
|
|
* Prevent directory listing by creating the index.php file.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function prevent_listing() {
|
2020-05-06 20:22:11 +07:00
|
|
|
self::init_listing_directories();
|
2020-05-13 18:48:37 +07:00
|
|
|
global $wp_filesystem;
|
|
|
|
MainWP_Helper::get_wp_filesystem();
|
2020-05-13 11:49:16 +00:00
|
|
|
|
2020-03-26 14:05:04 +00:00
|
|
|
foreach ( self::$listingDirectories as $directory ) {
|
2015-10-15 22:52:37 +10:00
|
|
|
$file = $directory . DIRECTORY_SEPARATOR . 'index.php';
|
2020-05-13 18:48:37 +07:00
|
|
|
if ( ! $wp_filesystem->exists( $file ) ) {
|
|
|
|
$wp_filesystem->put_contents( $file, "<?php \n" );
|
|
|
|
$wp_filesystem->put_contents( $file, "header(\$_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden' );\n" );
|
2020-05-13 11:49:16 +00:00
|
|
|
$wp_filesystem->put_contents( $file, "die( '403 Forbidden' );\n" );
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_wp_version()
|
|
|
|
*
|
|
|
|
* Remove the WordPress version (WordPress Generator).
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_wp_version( $force = false ) {
|
|
|
|
if ( $force || self::get_security_option( 'wp_version' ) ) {
|
|
|
|
remove_action( 'wp_head', 'wp_generator' );
|
|
|
|
remove_filter( 'wp_head', 'wp_generator' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_rsd()
|
|
|
|
*
|
|
|
|
* Remove the Really Simple Discovery meta tag.
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_rsd( $force = false ) {
|
|
|
|
if ( $force || self::get_security_option( 'rsd' ) ) {
|
|
|
|
remove_action( 'wp_head', 'rsd_link' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_wlw()
|
|
|
|
*
|
|
|
|
* Remove the Windows Live Writer meta tag.
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_wlw( $force = false ) {
|
|
|
|
if ( $force || self::get_security_option( 'wlw' ) ) {
|
|
|
|
remove_action( 'wp_head', 'wlwmanifest_link' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_php_reporting()
|
|
|
|
*
|
|
|
|
* Disable the PHP error reporting.
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
|
|
|
public static function remove_php_reporting( $force = false ) {
|
|
|
|
if ( $force || self::get_security_option( 'php_reporting' ) ) {
|
|
|
|
error_reporting( 0 ); //phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
|
|
|
ini_set( 'display_errors', 'off' ); //phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
|
|
|
ini_set( 'display_startup_errors', 0 ); //phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
|
|
|
}
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_database_reporting()
|
|
|
|
*
|
|
|
|
* Disable the database error reporting.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_database_reporting() {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$wpdb->hide_errors();
|
|
|
|
$wpdb->suppress_errors();
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_registered_versions()
|
|
|
|
*
|
|
|
|
* Remove the scripts and stylesheets registered versions.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2018-09-27 19:52:32 +02:00
|
|
|
public static function remove_registered_versions() {
|
2020-03-27 15:13:11 +00:00
|
|
|
if ( self::get_security_option( 'registered_versions' ) ) {
|
2018-09-27 19:52:32 +02:00
|
|
|
global $wp_styles;
|
2020-03-26 17:03:00 +00:00
|
|
|
if ( $wp_styles instanceof WP_Styles ) {
|
2018-09-27 19:52:32 +02:00
|
|
|
foreach ( $wp_styles->registered as $handle => $style ) {
|
2020-03-27 15:13:11 +00:00
|
|
|
$wp_styles->registered[ $handle ]->ver = null;
|
|
|
|
}
|
2018-09-27 19:52:32 +02:00
|
|
|
}
|
2020-03-27 15:13:11 +00:00
|
|
|
global $wp_scripts;
|
2018-09-27 19:52:32 +02:00
|
|
|
if ( $wp_scripts instanceof WP_Scripts ) {
|
|
|
|
foreach ( $wp_scripts->registered as $handle => $script ) {
|
2020-03-27 15:13:11 +00:00
|
|
|
$wp_scripts->registered[ $handle ]->ver = null;
|
|
|
|
}
|
2018-09-27 19:52:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 22:08:39 +01:00
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_script_versions()
|
|
|
|
*
|
|
|
|
* Remove scripts versions.
|
|
|
|
*
|
|
|
|
* @param string $src Script or stylesheet location path.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*
|
|
|
|
* @return string $src Script or stylesheet striped location path.
|
|
|
|
*/
|
|
|
|
public static function remove_script_versions( $src ) {
|
|
|
|
if ( self::get_security_option( 'scripts_version' ) ) {
|
|
|
|
if ( strpos( $src, '?ver=' ) ) {
|
|
|
|
$src = remove_query_arg( 'ver', $src );
|
|
|
|
}
|
|
|
|
return $src;
|
|
|
|
}
|
|
|
|
return $src;
|
2016-02-15 22:08:39 +01:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_generator_version()
|
|
|
|
*
|
|
|
|
* Remove the WordPress Generator version.
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @uses MainWP_Security::custom_the_generator() Set custom generator.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*/
|
2016-02-15 22:08:39 +01:00
|
|
|
public static function remove_generator_version( $force = false ) {
|
|
|
|
if ( $force || self::get_security_option( 'generator_version' ) ) {
|
|
|
|
$types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' );
|
|
|
|
foreach ( $types as $type ) {
|
2016-02-17 20:38:44 +01:00
|
|
|
add_filter( 'get_the_generator_' . $type, array( 'MainWP_Security', 'custom_the_generator' ), 10, 2 );
|
2016-02-15 22:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method custom_the_generator()
|
|
|
|
*
|
|
|
|
* Set custom generator.
|
|
|
|
*
|
|
|
|
* @param string $generator Generator to process.
|
|
|
|
* @param array $type Array containing the generator types.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::remove_generator_version() Remove the WordPress Generator version.
|
|
|
|
*
|
|
|
|
* @return string Return empty string.
|
|
|
|
*/
|
2016-02-17 20:38:44 +01:00
|
|
|
public static function custom_the_generator( $generator, $type = '' ) {
|
2016-02-15 22:08:39 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_theme_versions()
|
|
|
|
*
|
|
|
|
* Remove themes versions.
|
|
|
|
*
|
|
|
|
* @param string $src Theme stylesheet location path.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*
|
|
|
|
* @return string $src Theme stylesheet striped location path.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_theme_versions( $src ) {
|
2017-01-14 13:16:52 +01:00
|
|
|
if ( self::get_security_option( 'styles_version' ) ) {
|
2015-10-15 22:52:37 +10:00
|
|
|
if ( strpos( $src, '?ver=' ) ) {
|
2016-03-15 20:54:21 +01:00
|
|
|
$src = remove_query_arg( 'ver', $src );
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
return $src;
|
|
|
|
}
|
|
|
|
return $src;
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_readme()
|
|
|
|
*
|
|
|
|
* Remove the readme.html file.
|
|
|
|
*
|
|
|
|
* @param bool $force Force action if true, don't force if false.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::fix_all() Fire off functions to fix detected security issues.
|
|
|
|
*
|
|
|
|
* @return bool true Return true to skip the process if child site is on WP Engine host.
|
|
|
|
*/
|
2020-03-27 15:13:11 +00:00
|
|
|
public static function remove_readme( $force = false ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
// to prevent remove readme.html file on WP Engine hosting.
|
2020-03-27 15:13:11 +00:00
|
|
|
if ( MainWP_Helper::is_wp_engine() ) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-13 18:48:37 +07:00
|
|
|
MainWP_Helper::get_wp_filesystem();
|
2020-05-13 11:49:16 +00:00
|
|
|
global $wp_filesystem;
|
2015-10-15 22:52:37 +10:00
|
|
|
if ( $force || self::get_security_option( 'readme' ) ) {
|
2020-05-13 18:48:37 +07:00
|
|
|
if ( $wp_filesystem->exists( ABSPATH . 'readme.html' ) ) {
|
2020-05-13 11:49:16 +00:00
|
|
|
if ( ! unlink( ABSPATH . 'readme.html' ) ) {
|
2020-05-13 18:48:37 +07:00
|
|
|
$wp_filesystem->delete( ABSPATH . 'readme.html' );
|
|
|
|
if ( $wp_filesystem->exists( ABSPATH . 'readme.html' ) ) {
|
|
|
|
// prevent repeat delete.
|
|
|
|
self::update_security_option( 'readme', false );
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method prevent_listing_ok()
|
|
|
|
*
|
|
|
|
* Check if the directory listing is prevented.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If directory listing prevented, return true, if not, return false.
|
|
|
|
*/
|
|
|
|
public static function prevent_listing_ok() {
|
|
|
|
global $wp_filesystem;
|
|
|
|
MainWP_Helper::get_wp_filesystem();
|
|
|
|
|
|
|
|
self::init_listing_directories();
|
|
|
|
foreach ( self::$listingDirectories as $directory ) {
|
|
|
|
$file = $directory . DIRECTORY_SEPARATOR . 'index.php';
|
|
|
|
if ( ! $wp_filesystem->exists( $file ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_wp_version_ok()
|
|
|
|
*
|
|
|
|
* Check if the WordPress version has been removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If WordPress version removed, return true, if not return false.
|
|
|
|
*/
|
|
|
|
public static function remove_wp_version_ok() {
|
|
|
|
return ! ( has_action( 'wp_head', 'wp_generator' ) || has_filter( 'wp_head', 'wp_generator' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_rsd_ok()
|
|
|
|
*
|
|
|
|
* Check if the Really Simple Discovery meta tag has been removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If the Really Simple Discovery meta tag has been removed, return true, if not return false.
|
|
|
|
*/
|
|
|
|
public static function remove_rsd_ok() {
|
|
|
|
return ( ! has_action( 'wp_head', 'rsd_link' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_wlw_ok()
|
|
|
|
*
|
|
|
|
* Check if the Windows Live Writer meta tag has been removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If the Windows Live Writer meta tag has been removed, return true, if not return false.
|
|
|
|
*/
|
|
|
|
public static function remove_wlw_ok() {
|
|
|
|
return ( ! has_action( 'wp_head', 'wlwmanifest_link' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_database_reporting_ok()
|
|
|
|
*
|
|
|
|
* Check if the database error reporting has been disabled.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If the database error reporting has been disabled, return true, if not, return false.
|
|
|
|
*/
|
|
|
|
public static function remove_database_reporting_ok() {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
return ( false === $wpdb->show_errors );
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_php_reporting_ok()
|
|
|
|
*
|
|
|
|
* Check if the PHP error reporting has been disabled.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false If the PHP error reporting has been disabled, return true, if not, return false.
|
|
|
|
*/
|
|
|
|
public static function remove_php_reporting_ok() {
|
|
|
|
return ! ( ( ( 0 != ini_get( 'display_errors' ) ) && ( 'off' != ini_get( 'display_errors' ) ) ) || ( ( 0 != ini_get( 'display_startup_errors' ) ) && ( 'off' != ini_get( 'display_startup_errors' ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_scripts_version_ok()
|
|
|
|
*
|
|
|
|
* Check if scripts versions are removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false Return true if versions have been removed, false if not.
|
|
|
|
*/
|
|
|
|
public static function remove_scripts_version_ok() {
|
|
|
|
return self::get_security_option( 'scripts_version' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_styles_version_ok()
|
|
|
|
*
|
|
|
|
* Check if stylesheets versions are removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false Return true if versions have been removed, false if not.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function remove_styles_version_ok() {
|
|
|
|
return self::get_security_option( 'styles_version' );
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_generator_version_ok()
|
|
|
|
*
|
|
|
|
* Check if the WordPress Generator version has been removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false Return true if registered versions have been removed, false if not.
|
|
|
|
*/
|
|
|
|
public static function remove_generator_version_ok() {
|
|
|
|
return self::get_security_option( 'generator_version' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method remove_registered_versions_ok()
|
|
|
|
*
|
|
|
|
* Check if the scripts and stylesheets registered versions are removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false Return true if registered versions have been removed, false if not.
|
|
|
|
*/
|
|
|
|
public static function remove_registered_versions_ok() {
|
|
|
|
return self::get_security_option( 'registered_versions' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method admin_user_ok()
|
|
|
|
*
|
|
|
|
* Check if any of administrator accounts has 'admin' as username.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true Return true no 'admin' username detected, fale if not.
|
|
|
|
*/
|
2015-10-15 22:52:37 +10:00
|
|
|
public static function admin_user_ok() {
|
|
|
|
$user = get_user_by( 'login', 'admin' );
|
2020-03-26 17:03:00 +00:00
|
|
|
if ( ! $user ) {
|
2020-03-26 19:51:58 +00:00
|
|
|
return true;
|
2020-03-27 15:13:11 +00:00
|
|
|
}
|
2016-12-29 22:19:20 +01:00
|
|
|
if ( 10 !== $user->wp_user_level && ( ! isset( $user->user_level ) || 10 !== $user->user_level ) && ! user_can( $user, 'level_10' ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|
2016-02-15 22:08:39 +01:00
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method remove_readme_ok()
|
|
|
|
*
|
|
|
|
* Check if the readme.html file has been removed.
|
|
|
|
*
|
|
|
|
* @used-by MainWP_Security::get_stats_security() Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @return bool true|false Return true if the readme.html file has been removed, false if not.
|
|
|
|
*/
|
|
|
|
public static function remove_readme_ok() {
|
|
|
|
return ! file_exists( ABSPATH . 'readme.html' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method get_stats_security()
|
|
|
|
*
|
|
|
|
* Calculate total number of detected secutiry issues.
|
|
|
|
*
|
|
|
|
* @uses MainWP_Security::prevent_listing_ok() Check if the directory listing is prevented.
|
|
|
|
* @uses MainWP_Security::remove_wp_version_ok() Check if the WordPress version has been removed.
|
|
|
|
* @uses MainWP_Security::remove_rsd_ok() Check if the Really Simple Discovery meta tag has been removed.
|
|
|
|
* @uses MainWP_Security::remove_wlw_ok() Check if the Windows Live Writer meta tag has been removed.
|
|
|
|
* @uses MainWP_Security::remove_database_reporting_ok() Check if the database error reporting has been disabled.
|
|
|
|
* @uses MainWP_Security::remove_php_reporting_ok() Check if the PHP error reporting has been disabled.
|
|
|
|
* @uses MainWP_Security::remove_scripts_version_ok() Check if scripts versions are removed.
|
|
|
|
* @uses MainWP_Security::remove_styles_version_ok() Check if stylesheets versions are removed.
|
|
|
|
* @uses MainWP_Security::remove_generator_version_ok() Check if the WordPress Generator version has been removed.
|
|
|
|
* @uses MainWP_Security::remove_registered_versions_ok() Check if the scripts and stylesheets registered versions are removed.
|
|
|
|
* @uses MainWP_Security::admin_user_ok() Check if any of administrator accounts has 'admin' as username.
|
|
|
|
* @uses MainWP_Security::remove_readme_ok() Check if the readme.html file has been removed.
|
|
|
|
*
|
|
|
|
* @return int $total_issues Total number of detected security issues.
|
|
|
|
*/
|
2020-05-11 20:30:56 +07:00
|
|
|
public static function get_stats_security() {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues = 0;
|
2020-05-11 20:30:56 +07:00
|
|
|
if ( ! self::prevent_listing_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_wp_version_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_rsd_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_wlw_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_database_reporting_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_php_reporting_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_scripts_version_ok() || ! self::remove_styles_version_ok() || ! self::remove_generator_version_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_registered_versions_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::admin_user_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
|
|
|
if ( ! self::remove_readme_ok() ) {
|
2020-05-27 19:22:54 +02:00
|
|
|
$total_issues ++;
|
2020-05-11 13:33:45 +00:00
|
|
|
}
|
2020-05-27 19:22:54 +02:00
|
|
|
return $total_issues;
|
2020-05-11 20:30:56 +07:00
|
|
|
}
|
2020-05-11 13:33:45 +00:00
|
|
|
|
2020-05-27 19:22:54 +02:00
|
|
|
/**
|
|
|
|
* Method get_security_option()
|
|
|
|
*
|
|
|
|
* Get security check settings.
|
|
|
|
*
|
2020-05-27 19:24:41 +02:00
|
|
|
* @param string $option Security check option.
|
2020-05-27 19:22:54 +02:00
|
|
|
*
|
|
|
|
* @return array Security settings.
|
|
|
|
*/
|
|
|
|
public static function get_security_option( $option ) {
|
|
|
|
$security = get_option( 'mainwp_security' );
|
|
|
|
|
|
|
|
return ! empty( $security ) && isset( $security[ $option ] ) && ( true === $security[ $option ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method update_security_option()
|
|
|
|
*
|
|
|
|
* Update the security issues feature settings.
|
|
|
|
*
|
2020-05-27 19:24:41 +02:00
|
|
|
* @param string $key Security option key.
|
|
|
|
* @param string $value Security option value.
|
2020-05-27 19:22:54 +02:00
|
|
|
*/
|
2016-02-15 22:08:39 +01:00
|
|
|
public static function update_security_option( $key, $value ) {
|
|
|
|
$security = get_option( 'mainwp_security' );
|
2020-04-21 20:09:08 +02:00
|
|
|
if ( ! empty( $key ) ) {
|
2020-03-26 15:29:54 +00:00
|
|
|
$security[ $key ] = $value;
|
2020-03-27 15:13:11 +00:00
|
|
|
}
|
2016-02-15 22:08:39 +01:00
|
|
|
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
|
|
|
|
}
|
2015-10-15 22:52:37 +10:00
|
|
|
}
|