| @@ -45,20 +45,9 @@ | ||
| 45 | 45 | '7' => array( |
| 46 | 46 | 'id' => 'basic-auth-plugin-white-list', |
| 47 | 47 | 'title' => __('Ip White list', 'easy-basic-authentication'), |
| 48 | 48 | 'callback' => 'basic_auth_plugin_whitelist_cb', |
| 49 | - ), | |
| 50 | - '8' => array( | |
| 51 | - 'id' => 'basic-auth-plugin-url-white-list', | |
| 52 | - 'title' => __('Url White list', 'easy-basic-authentication'), | |
| 53 | - 'callback' => 'basic_auth_plugin_urlwhitelist_cb', | |
| 54 | - ), | |
| 55 | - '9' => array( | |
| 56 | - 'id' => 'basic-auth-plugin-remove-data-after-uninstall', | |
| 57 | - 'title' => __('Remove plugin data after uninstall', 'easy-basic-authentication'), | |
| 58 | - 'callback' => 'basic_auth_plugin_remove_data_after_uninstall_cb', | |
| 59 | - ), | |
| 60 | - | |
| 49 | + ) | |
| 61 | 50 | ); |
| 62 | 51 | } |
| 63 | 52 | |
| 64 | 53 | public function basic_auth_plugin_settings_init() { |
| @@ -138,23 +127,11 @@ | ||
| 138 | 127 | } |
| 139 | 128 | |
| 140 | 129 | public function basic_auth_plugin_whitelist_cb() { |
| 141 | 130 | $white_list = get_option( 'basic_auth_plugin_whitelist' ); |
| 142 | - $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma. Ex. 127.0.0.1, 1.1.1.1/20, 1.1.0.0 - 1.1.0.255', 'easy-basic-authentication')); | |
| 131 | + $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma', 'easy-basic-authentication')); | |
| 143 | 132 | } |
| 144 | - | |
| 145 | - public function basic_auth_plugin_urlwhitelist_cb() { | |
| 146 | - $white_list = get_option( 'basic_auth_plugin_urlwhitelist' ); | |
| 147 | - $this->printInputText("text","basic_auth_plugin_urlwhitelist",esc_attr( $white_list ),__('Url white list, separated by comma. Ex. /json/wp-, www.google.it,', 'easy-basic-authentication')); | |
| 148 | - } | |
| 149 | 133 | |
| 150 | - public function basic_auth_plugin_remove_data_after_uninstall_cb() { | |
| 151 | - $enable = get_option( 'basic_auth_plugin_remove_data_after_uninstall' ); | |
| 152 | - ?> | |
| 153 | - <input type="checkbox" name="basic_auth_plugin_remove_data_after_uninstall" value="1" <?php checked( $enable, 1 ); ?>> | |
| 154 | - <?php | |
| 155 | - } | |
| 156 | - | |
| 157 | 134 | public function printInputText($type, $name, $value='', $placeholder = '', $autocomplete = 'off') { |
| 158 | 135 | echo "<input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "' autocomplete='" . esc_attr($autocomplete) . "' >"; |
| 159 | 136 | } |
| 160 | 137 | |
| @@ -160,21 +137,16 @@ | ||
| 160 | 137 | |
| 161 | 138 | |
| 162 | 139 | public function basic_auth_plugin_save_settings($param) { |
| 163 | 140 | if ( isset( $param['eba_submit'] ) ) { |
| 164 | - if ( ! isset( $param['_wpnonce'] ) || ! wp_verify_nonce( $param['_wpnonce'], 'basic-auth-plugin-settings-options' ) ) { | |
| 165 | - return; | |
| 166 | - } | |
| 167 | 141 | $admin_enable = isset( $param['basic_auth_plugin_admin_enable'] ) ? 1 : 0; |
| 168 | 142 | $enable = isset( $param['basic_auth_plugin_enable'] ) ? 1 : 0; |
| 169 | 143 | $username = sanitize_text_field( $param['basic_auth_plugin_username'] ); |
| 170 | - $password = isset( $param['basic_auth_plugin_password'] ) ? wp_unslash( $param['basic_auth_plugin_password'] ) : ''; | |
| 144 | + $password = sanitize_text_field( $param['basic_auth_plugin_password'] ); | |
| 171 | 145 | $log_enable = isset( $param['basic_auth_plugin_admin_log_enable'] ) ? 1 : 0; |
| 172 | 146 | $alert_enable = isset( $param['basic_auth_plugin_alert_enable'] ) ? 1 : 0; |
| 173 | 147 | $alert_email = sanitize_text_field( $param['basic_auth_plugin_alertemail'] ); |
| 174 | 148 | $white_list = sanitize_text_field( $param['basic_auth_plugin_whitelist'] ); |
| 175 | - $remove_data = isset( $param['basic_auth_plugin_remove_data_after_uninstall'] ) ? 1 : 0; | |
| 176 | - $url_white_list = sanitize_text_field( $param['basic_auth_plugin_urlwhitelist'] ); | |
| 177 | 149 | |
| 178 | 150 | if ( empty( $username ) ) { |
| 179 | 151 | add_settings_error( |
| 180 | 152 | 'basic_auth_plugin_username', |
| @@ -206,10 +178,8 @@ | ||
| 206 | 178 | update_option( 'basic_auth_plugin_enable', $enable ); |
| 207 | 179 | update_option( 'basic_auth_plugin_username', $username ); |
| 208 | 180 | update_option( 'basic_auth_plugin_admin_log_enable', $log_enable ); |
| 209 | 181 | update_option( 'basic_auth_plugin_alert_enable', $alert_enable ); |
| 210 | - update_option( 'basic_auth_plugin_remove_data_after_uninstall', $remove_data ); | |
| 211 | - update_option( 'basic_auth_plugin_urlwhitelist', $url_white_list ); | |
| 212 | 182 | |
| 213 | 183 | if( $this->validateIpList( $white_list ) || strlen($white_list) == 0 ) { |
| 214 | 184 | update_option( 'basic_auth_plugin_whitelist', $white_list ); |
| 215 | 185 | } else { |
| @@ -222,8 +192,13 @@ | ||
| 222 | 192 | return; |
| 223 | 193 | |
| 224 | 194 | } |
| 225 | 195 | |
| 196 | + if ( ! empty( $password ) ) { | |
| 197 | + $hashed_password = wp_hash_password( $password ); | |
| 198 | + update_option( 'basic_auth_plugin_password', $hashed_password ); | |
| 199 | + } | |
| 200 | + | |
| 226 | 201 | $this->send_credentials_email($username, $password); |
| 227 | 202 | } |
| 228 | 203 | } |
| 229 | 204 | |
| @@ -234,37 +209,15 @@ | ||
| 234 | 209 | public function validateIpList($white_list) { |
| 235 | 210 | $ips = explode(',', $white_list); |
| 236 | 211 | foreach ($ips as $ip) { |
| 237 | 212 | $ip = trim($ip); |
| 238 | - | |
| 239 | - // ✅ Valida IP singoli | |
| 240 | - if (filter_var($ip, FILTER_VALIDATE_IP)) { | |
| 241 | - continue; | |
| 213 | + if (!filter_var($ip, FILTER_VALIDATE_IP)) { | |
| 214 | + return false; | |
| 242 | 215 | } |
| 243 | - | |
| 244 | - // ✅ Valida subnet CIDR (es. 1.1.1.1/20) | |
| 245 | - if (preg_match('/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/', $ip)) { | |
| 246 | - list($subnet, $mask) = explode('/', $ip); | |
| 247 | - if (filter_var($subnet, FILTER_VALIDATE_IP) && $mask >= 0 && $mask <= 32) { | |
| 248 | - continue; | |
| 249 | - } | |
| 250 | - } | |
| 251 | - | |
| 252 | - // ✅ Valida range IP (es. 1.1.0.0 - 1.1.0.255) | |
| 253 | - if (preg_match('/^(\d{1,3}\.){3}\d{1,3}\s*-\s*(\d{1,3}\.){3}\d{1,3}$/', $ip)) { | |
| 254 | - list($start_ip, $end_ip) = array_map('trim', explode('-', $ip)); | |
| 255 | - if (filter_var($start_ip, FILTER_VALIDATE_IP) && filter_var($end_ip, FILTER_VALIDATE_IP)) { | |
| 256 | - continue; | |
| 257 | - } | |
| 258 | - } | |
| 259 | - | |
| 260 | - // ❌ Se non passa nessuna validazione, ritorna false | |
| 261 | - return false; | |
| 262 | 216 | } |
| 263 | - | |
| 264 | 217 | return true; |
| 265 | 218 | } |
| 266 | - | |
| 219 | + | |
| 267 | 220 | public function send_credentials_email($username, $password) { |
| 268 | 221 | $admin_email = get_option('admin_email'); |
| 269 | 222 | $site_url = home_url(); |
| 270 | 223 | $plugin_url = 'https://wordpress.org/plugins/easy-basic-authentication/'; |
| @@ -276,12 +229,11 @@ | ||
| 276 | 229 | $message .= '<p>' . __('The basic authentication credentials for your site have been updated.', 'easy-basic-authentication') . '</p>'; |
| 277 | 230 | $message .= '<ul style="list-style-type: none; padding-left: 0;">' . |
| 278 | 231 | '<li>' . __('Site URL: ', 'easy-basic-authentication') . '<strong>' . esc_url($site_url) . '</strong></li>' . |
| 279 | 232 | '<li>' . __('Username: ', 'easy-basic-authentication') . '<strong>' . esc_html($username) . '</strong></li>' . |
| 280 | - '<li>' . __('Password: ', 'easy-basic-authentication') . '<strong>' . __('[updated — not shown for security]', 'easy-basic-authentication') . '</strong></li>' . | |
| 233 | + '<li>' . __('Password: ', 'easy-basic-authentication') . '<strong>' . esc_html($password) . '</strong></li>' . | |
| 281 | 234 | '</ul>'; |
| 282 | 235 | $message .= '<p>' . sprintf( |
| 283 | - /* translators: tag "a" and link */ | |
| 284 | 236 | __('For more information about this plugin, visit: %s', 'easy-basic-authentication'), |
| 285 | 237 | '<a href="' . esc_url($plugin_url) . '">' . esc_url($plugin_url) . '</a>' |
| 286 | 238 | ) . '</p>'; |
| 287 | 239 | $message .= '<p>' . __('Grazie and buona giornata,', 'easy-basic-authentication') . '</p>'; |