siteguard-login-history-table.php
1 month ago
siteguard-menu-admin-filter.php
4 weeks ago
siteguard-menu-author-query.php
2 weeks ago
siteguard-menu-captcha.php
4 weeks ago
siteguard-menu-dashboard.php
4 weeks ago
siteguard-menu-fail-once.php
4 weeks ago
siteguard-menu-init.php
1 month ago
siteguard-menu-login-alert.php
4 weeks ago
siteguard-menu-login-history.php
4 weeks ago
siteguard-menu-login-lock.php
4 weeks ago
siteguard-menu-protect-xmlrpc.php
4 weeks ago
siteguard-menu-rename-login.php
2 weeks ago
siteguard-menu-same-error.php
4 weeks ago
siteguard-menu-updates-notify.php
4 weeks ago
siteguard-menu-waf-tuning-support.php
4 weeks ago
siteguard-waf-exclude-rule-table.php
1 month ago
siteguard-menu-admin-filter.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | class SiteGuard_Menu_Admin_Filter extends SiteGuard_Base { |
| 4 | const OPT_NAME_FEATURE = 'admin_filter_enable'; |
| 5 | const OPT_NAME_EXCLUDE = 'admin_filter_exclude_path'; |
| 6 | |
| 7 | function __construct() { |
| 8 | $this->render_page(); |
| 9 | } |
| 10 | |
| 11 | function render_page() { |
| 12 | global $siteguard_admin_filter, $siteguard_config; |
| 13 | |
| 14 | $opt_val_feature = $siteguard_config->get( self::OPT_NAME_FEATURE ); |
| 15 | $opt_val_exclude = $this->cvt_camma2ret( $siteguard_config->get( self::OPT_NAME_EXCLUDE ) ); |
| 16 | if ( isset( $_POST['update'] ) && check_admin_referer( 'siteguard-menu-admin-filter-submit' ) ) { |
| 17 | $error = false; |
| 18 | $errors = siteguard_check_multisite(); |
| 19 | if ( is_wp_error( $errors ) ) { |
| 20 | echo '<div class="error settings-error"><p><strong>'; |
| 21 | echo esc_html( $errors->get_error_message() ); |
| 22 | echo '</strong></p></div>'; |
| 23 | $error = true; |
| 24 | } |
| 25 | if ( false === $error && false === $this->is_switch_value( $_POST[ self::OPT_NAME_FEATURE ] ) ) { |
| 26 | echo '<div class="error settings-error"><p><strong>'; |
| 27 | esc_html_e( 'ERROR: Invalid input value.', 'siteguard' ); |
| 28 | echo '</strong></p></div>'; |
| 29 | $error = true; |
| 30 | } |
| 31 | if ( false === $error ) { |
| 32 | $old_opt_val_feature = $opt_val_feature; |
| 33 | $old_opt_val_exclude = $opt_val_exclude; |
| 34 | $opt_val_feature = sanitize_text_field( $_POST[ self::OPT_NAME_FEATURE ] ); |
| 35 | $opt_val_exclude = stripslashes( sanitize_textarea_field( $_POST[ self::OPT_NAME_EXCLUDE ] ) ); |
| 36 | $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature ); |
| 37 | $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) ); |
| 38 | $siteguard_config->update(); |
| 39 | $result = true; |
| 40 | if ( '0' === $opt_val_feature ) { |
| 41 | $result = $siteguard_admin_filter->feature_off(); |
| 42 | } else { |
| 43 | $result = $siteguard_admin_filter->feature_on( $this->get_ip() ); |
| 44 | } |
| 45 | if ( true === $result ) { |
| 46 | $opt_val_exclude = $this->cvt_camma2ret( $opt_val_exclude ); |
| 47 | ?> |
| 48 | <div class="updated"><p><strong><?php esc_html_e( 'Options saved.', 'siteguard' ); ?></strong></p></div> |
| 49 | <?php |
| 50 | } else { |
| 51 | $opt_val_feature = $old_opt_val_feature; |
| 52 | $opt_val_exclude = $old_opt_val_exclude; |
| 53 | $siteguard_config->set( self::OPT_NAME_FEATURE, $opt_val_feature ); |
| 54 | $siteguard_config->set( self::OPT_NAME_EXCLUDE, $this->cvt_ret2camma( $opt_val_exclude ) ); |
| 55 | $siteguard_config->update(); |
| 56 | echo '<div class="error settings-error"><p><strong>'; |
| 57 | esc_html_e( 'ERROR: Failed to update settings. Please try again.', 'siteguard' ); |
| 58 | echo '</strong></p></div>'; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | echo '<div class="wrap">'; |
| 64 | echo '<img src="' . SITEGUARD_URL_PATH . 'images/sg_wp_plugin_logo_40.png" alt="SiteGuard Logo" />'; |
| 65 | echo '<h2>' . esc_html__( 'Admin Page IP Filter', 'siteguard' ) . '</h2>'; |
| 66 | $documentation_link = '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/howto/admin_filter/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'online documentation', 'siteguard' ) . '</a>'; |
| 67 | echo '<div class="siteguard-description">' |
| 68 | . sprintf( |
| 69 | /* translators: %1$s: Link to the online documentation. */ |
| 70 | esc_html__( 'See the %1$s.', 'siteguard' ), |
| 71 | $documentation_link |
| 72 | ) |
| 73 | . '</div>'; |
| 74 | ?> |
| 75 | <form name="form1" method="post" action=""> |
| 76 | <table class="form-table"> |
| 77 | <tr> |
| 78 | <th scope="row" colspan="2"> |
| 79 | <ul class="siteguard-radios"> |
| 80 | <li> |
| 81 | <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" value="1" <?php checked( $opt_val_feature, '1' ); ?> > |
| 82 | <label for="<?php echo self::OPT_NAME_FEATURE . '_on'; ?>" ><?php echo esc_html_e( 'ON', 'siteguard' ); ?></label> |
| 83 | </li> |
| 84 | <li> |
| 85 | <input type="radio" name="<?php echo self::OPT_NAME_FEATURE; ?>" id="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" value="0" <?php checked( $opt_val_feature, '0' ); ?> > |
| 86 | <label for="<?php echo self::OPT_NAME_FEATURE . '_off'; ?>" ><?php echo esc_html_e( 'OFF', 'siteguard' ); ?></label> |
| 87 | </li> |
| 88 | </ul> |
| 89 | <?php |
| 90 | $error = siteguard_check_multisite(); |
| 91 | if ( is_wp_error( $error ) ) { |
| 92 | echo '<p class="description">'; |
| 93 | echo esc_html( $error->get_error_message() ); |
| 94 | echo '</p>'; |
| 95 | } |
| 96 | ?> |
| 97 | </th> |
| 98 | </tr><tr> |
| 99 | <th scope="row"><label for="<?php echo self::OPT_NAME_EXCLUDE; ?>"><?php echo esc_html_e( 'Exclude Path', 'siteguard' ); ?></label></th> |
| 100 | <td><textarea name="<?php echo self::OPT_NAME_EXCLUDE; ?>" id="<?php echo self::OPT_NAME_EXCLUDE; ?>" cols=40 rows=5 ><?php echo esc_textarea( $opt_val_exclude ); ?></textarea> |
| 101 | <p class="description"><?php esc_html_e( 'Enter the path after /wp-admin/ to exclude. One path per line.', 'siteguard' ); ?></p></td> |
| 102 | </tr> |
| 103 | </table> |
| 104 | <input type="hidden" name="update" value="Y"> |
| 105 | <div class="siteguard-description"> |
| 106 | <?php |
| 107 | esc_html_e( |
| 108 | 'Blocks unauthorized access to the admin area. Only computers that have previously logged in are allowed through. Access is automatically removed after 24 hours. Note: This protection covers WordPress pages only, not static files such as images or stylesheets. You can specify paths to exclude from this protection.', |
| 109 | 'siteguard' |
| 110 | ); |
| 111 | ?> |
| 112 | </div> |
| 113 | <hr /> |
| 114 | <?php |
| 115 | wp_nonce_field( 'siteguard-menu-admin-filter-submit' ); |
| 116 | submit_button(); |
| 117 | ?> |
| 118 | </form> |
| 119 | </div> |
| 120 | |
| 121 | <?php |
| 122 | } |
| 123 | } |
| 124 |