includes
2 months ago
server
2 months ago
tests
2 months ago
wordpress
2 months ago
class-rsssl-htaccess-file-manager.php
2 months ago
cron.php
2 months ago
deactivate-integration.php
2 months ago
firewall-manager.php
2 months ago
functions.php
2 months ago
index.php
2 months ago
integrations.php
2 months ago
notices.php
2 months ago
security.php
2 months ago
sync-settings.php
2 months ago
tests.php
2 months ago
notices.php
162 lines
| 1 | <?php defined( 'ABSPATH' ) or die(); |
| 2 | /** |
| 3 | * Convert htaccess rules to html friendly layout |
| 4 | * |
| 5 | * @param string $code |
| 6 | * |
| 7 | * @return string |
| 8 | */ |
| 9 | function rsssl_parse_htaccess_to_html( string $code): string { |
| 10 | if ( strpos($code, "\n")===0 ) { |
| 11 | $code = preg_replace('/\n/', '', $code, 1); |
| 12 | } |
| 13 | //split into linebreak separated array, so we can run esc_html on the result |
| 14 | $code = preg_replace('/\n/', '--br--', $code, 1); |
| 15 | $code = preg_replace('/<br>/', '--br--', $code, 1); |
| 16 | $code_arr = explode('--br--', $code); |
| 17 | $code_arr = array_map('esc_html', $code_arr); |
| 18 | $code = implode('<br>', $code_arr); |
| 19 | return '<br><code>' . $code . '</code><br>'; |
| 20 | } |
| 21 | |
| 22 | function rsssl_general_security_notices( $notices ) { |
| 23 | $code = rsssl_parse_htaccess_to_html( get_site_option( 'rsssl_htaccess_rules', '' ) ); |
| 24 | $uploads_code = rsssl_parse_htaccess_to_html( get_site_option( 'rsssl_uploads_htaccess_rules', '' ) ); |
| 25 | $open_hardening_count = rsssl_count_open_hardening_features(); |
| 26 | |
| 27 | $notices['htaccess_status'] = array( |
| 28 | 'callback' => 'rsssl_htaccess_status', |
| 29 | 'score' => 5, |
| 30 | 'output' => array( |
| 31 | 'not-writable' => array( |
| 32 | 'title' => __( ".htaccess not writable", "really-simple-ssl" ), |
| 33 | 'msg' => __( "An option that requires the .htaccess file is enabled, but the file is not writable.", "really-simple-ssl" ) . ' ' . __( "Please add the following lines to your .htaccess, or set it to writable:", "really-simple-ssl" ) . $code, |
| 34 | 'icon' => 'warning', |
| 35 | 'dismissible' => true, |
| 36 | 'plusone' => true, |
| 37 | 'url' => 'manual/editing-htaccess/', |
| 38 | ), |
| 39 | 'not-exists' => array( |
| 40 | 'title' => __( ".htaccess does not exist", "really-simple-ssl" ), |
| 41 | 'msg' => __( "An option that requires the .htaccess file is enabled, but the file does not exist.", "really-simple-ssl" ) . ' ' . __( "Please add the following lines to your .htaccess, or set it to writable:", "really-simple-ssl" ) . $code, |
| 42 | 'icon' => 'warning', |
| 43 | 'dismissible' => true, |
| 44 | 'plusone' => true, |
| 45 | 'url' => 'manual/editing-htaccess/', |
| 46 | ), |
| 47 | ), |
| 48 | 'show_with_options' => [ |
| 49 | 'disable_indexing', |
| 50 | 'redirect' |
| 51 | ] |
| 52 | ); |
| 53 | |
| 54 | $notices['htaccess_status_uploads'] = array( |
| 55 | 'callback' => 'rsssl_uploads_htaccess_status', |
| 56 | 'score' => 5, |
| 57 | 'output' => array( |
| 58 | 'not-writable' => array( |
| 59 | 'title' => __( ".htaccess in uploads not writable", "really-simple-ssl" ), |
| 60 | 'msg' => __( "An option that requires the .htaccess file in the uploads directory is enabled, but the file is not writable.", "really-simple-ssl" ) . ' ' . __( "Please add the following lines to your .htaccess, or set it to writable:", "really-simple-ssl" ) . $uploads_code, |
| 61 | 'icon' => 'warning', |
| 62 | 'dismissible' => true, |
| 63 | 'plusone' => true, |
| 64 | 'url' => 'manual/editing-htaccess/', |
| 65 | ), |
| 66 | ), |
| 67 | 'show_with_options' => [ |
| 68 | 'block_code_execution_uploads', |
| 69 | ] |
| 70 | ); |
| 71 | |
| 72 | $notices['display_name_is_login_exists'] = array( |
| 73 | 'condition' => [ 'rsssl_get_users_where_display_name_is_login' ], |
| 74 | 'callback' => '_true_', |
| 75 | 'score' => 5, |
| 76 | 'output' => array( |
| 77 | 'true' => array( |
| 78 | 'url' => 'manual/login-and-display-names-should-be-different-for-wordpress/', |
| 79 | 'msg' => __( "We have detected administrator roles where the login and display names are the same.", "really-simple-ssl" ) . " <b>" . rsssl_list_users_where_display_name_is_login_name() . "</b>", |
| 80 | 'icon' => 'open', |
| 81 | 'dismissible' => true, |
| 82 | ), |
| 83 | ), |
| 84 | ); |
| 85 | |
| 86 | $notices['new_username_empty'] = array( |
| 87 | 'condition' => [ 'rsssl_has_admin_user', 'option_rename_admin_user', 'NOT rsssl_new_username_valid' ], |
| 88 | 'callback' => '_true_', |
| 89 | 'score' => 5, |
| 90 | 'output' => array( |
| 91 | 'true' => array( |
| 92 | 'highlight_field_id' => 'rename_admin_user', |
| 93 | 'title' => __( "Username", "really-simple-ssl" ), |
| 94 | 'msg' => __( "Rename admin user enabled: Please choose a new username of at least 3 characters, which is not in use yet.", "really-simple-ssl" ), |
| 95 | 'icon' => 'warning', |
| 96 | 'dismissible' => true, |
| 97 | ), |
| 98 | ), |
| 99 | 'show_with_options' => [ |
| 100 | 'new_admin_user_login', |
| 101 | ], |
| 102 | ); |
| 103 | |
| 104 | $notices['enable_vulnerability_scanner'] = array( |
| 105 | 'callback' => 'option_enable_vulnerability_scanner', |
| 106 | 'score' => 5, |
| 107 | 'output' => array( |
| 108 | 'false' => array( |
| 109 | 'highlight_field_id' => 'enable_vulnerability_scanner', |
| 110 | 'msg' => __( "Enable the Vulnerability scan to detect possible vulnerabilities.", 'really-simple-ssl' ), |
| 111 | 'icon' => 'open', |
| 112 | 'admin_notice' => false, |
| 113 | 'dismissible' => true, |
| 114 | 'plusone' => false, |
| 115 | ), |
| 116 | 'true' => array( |
| 117 | 'msg' => __( "Vulnerability scanning is enabled.", 'really-simple-ssl' ), |
| 118 | 'icon' => 'success', |
| 119 | ), |
| 120 | ), |
| 121 | ); |
| 122 | |
| 123 | $notices['count_open_hardening_features'] = array( |
| 124 | 'callback' => 'rsssl_has_open_hardening_features', |
| 125 | 'score' => 5, |
| 126 | 'output' => array( |
| 127 | 'true' => array( |
| 128 | 'highlight_field_id' => 'disable_anyone_can_register', |
| 129 | 'msg' => sprintf( |
| 130 | _n( |
| 131 | "You have %s open hardening feature.", |
| 132 | "You have %s open hardening features.", |
| 133 | $open_hardening_count, |
| 134 | "really-simple-ssl" |
| 135 | ), |
| 136 | $open_hardening_count |
| 137 | ), |
| 138 | 'icon' => 'open', |
| 139 | 'dismissible' => true, |
| 140 | ), |
| 141 | 'false' => array( |
| 142 | 'msg' => __( "All recommended hardening features enabled.", "really-simple-ssl" ), |
| 143 | 'icon' => 'success', |
| 144 | ), |
| 145 | ), |
| 146 | ); |
| 147 | |
| 148 | $notices['lock_file_exists'] = array( |
| 149 | 'callback' => 'rsssl_lock_file_exists', |
| 150 | 'score' => 5, |
| 151 | 'output' => array( |
| 152 | 'true' => array( |
| 153 | 'msg' => __( 'The Firewall, LLA and 2FA are currently inactive, as you have activated Safe Mode with the rsssl-safe-mode.lock file. Remove the file from your /wp-content folder after you have finished debugging.', 'really-simple-ssl' ), |
| 154 | 'icon' => 'warning', |
| 155 | ), |
| 156 | ), |
| 157 | ); |
| 158 | |
| 159 | return $notices; |
| 160 | } |
| 161 | add_filter('rsssl_notices', 'rsssl_general_security_notices'); |
| 162 |