captcha.php
1 year ago
common.php
1 year ago
dashboard.php
1 year ago
disable-access-system-file.php
1 year ago
disable-author-query.php
1 year ago
disable-login.php
1 year ago
disable-restapi.php
1 year ago
disable-xmlrpc.php
1 year ago
login-log-table.php
2 years ago
login-log.php
1 year ago
login-notification.php
1 year ago
rename-login-page.php
1 year ago
restrict-admin-page.php
1 year ago
server-error-notification.php
1 year ago
server-error-table.php
1 year ago
two-factor-authentication-registration.php
2 years ago
two-factor-authentication.php
1 year ago
unify-messages.php
1 year ago
update-notice.php
1 year ago
waf-table.php
1 year ago
waf.php
1 year ago
two-factor-authentication.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class CloudSecureWP_Admin_Two_Factor_Authentication extends CloudSecureWP_Admin_Common { |
| 8 | private $two_factor_authentication; |
| 9 | |
| 10 | function __construct( array $info, CloudSecureWP_Two_Factor_Authentication $two_factor_authentication ) { |
| 11 | parent::__construct( $info ); |
| 12 | $this->two_factor_authentication = $two_factor_authentication; |
| 13 | $this->prepare_view_data(); |
| 14 | $this->render(); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * 画面表示用のデータを準備 |
| 19 | */ |
| 20 | public function prepare_view_data(): void { |
| 21 | $this->datas = $this->two_factor_authentication->get_settings(); |
| 22 | |
| 23 | if ( ! empty( $_POST ) && check_admin_referer( $this->two_factor_authentication->get_feature_key() . '_csrf' ) ) { |
| 24 | |
| 25 | foreach ( $this->datas as $key => $val ) { |
| 26 | |
| 27 | if ( 'two_factor_authentication' === $key ) { |
| 28 | $tmp = sanitize_text_field( $_POST[ $key ] ?? '' ); |
| 29 | if ( ! $this->is_selected( $tmp, self::TF_VALIES ) ) { |
| 30 | $this->errors[] = '有効・無効の値が不正です'; |
| 31 | } |
| 32 | |
| 33 | if ( ! $this->check_environment() ) { |
| 34 | $tmp = 'f'; |
| 35 | } |
| 36 | |
| 37 | $this->datas[ $key ] = $tmp; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if ( empty( $this->errors ) ) { |
| 42 | |
| 43 | $roles = array_map( 'sanitize_text_field', $_POST['roles'] ?? array() ); |
| 44 | update_option( 'cloudsecurewp_two_factor_authentication_roles', $roles ); |
| 45 | |
| 46 | if ( 't' === $this->datas['two_factor_authentication'] ) { |
| 47 | $this->messages[] = '2段階認証機能が有効になりました。'; |
| 48 | } else { |
| 49 | $this->messages[] = '2段階認証機能が無効になりました。'; |
| 50 | } |
| 51 | |
| 52 | $this->two_factor_authentication->save_settings( $this->datas ); |
| 53 | |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | $this->datas = $this->get_checked( $this->datas, array( 'two_factor_authentication' ) ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * ディスクリプション |
| 62 | */ |
| 63 | protected function admin_description(): void { |
| 64 | ?> |
| 65 | <nav> |
| 66 | <ul class="breadcrumb"> |
| 67 | <li class="breadcrumb__list"><a href="?page=cloudsecurewp">ダッシュボード</a></li> |
| 68 | <li class="breadcrumb__list">2段階認証</li> |
| 69 | </ul> |
| 70 | </nav> |
| 71 | <div class="title-block mb-12"> |
| 72 | <p class="title-block-small-text">この機能のマニュアルは<a class="title-block-link" target="_blank" href="https://wpplugin.cloudsecure.ne.jp/cloudsecure_wp_security/two_factor_authentication.php">こちら</a></p> |
| 73 | <h1 class="title-block-title">2段階認証</h1> |
| 74 | </div> |
| 75 | <div class="title-bottom-text"> |
| 76 | ユーザー名とパスワードの� |
| 77 | �力に加え、別のコードで追加認証を行います。<br /> |
| 78 | <b>※利用するには、<a class="title-block-link" href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank">Google Authenticator</a> アプリケーションでデバイスを登録する� |
| 79 | 要があります。</b> |
| 80 | </div> |
| 81 | <?php |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * ページコンテンツ |
| 86 | */ |
| 87 | protected function page(): void { |
| 88 | $all_roles = array_keys( wp_roles()->roles ); |
| 89 | $roles = get_option( 'cloudsecurewp_two_factor_authentication_roles', $all_roles ); |
| 90 | $lastkey = ''; |
| 91 | |
| 92 | if ( ! empty( $all_roles ) ) { |
| 93 | end( $all_roles ); |
| 94 | $lastkey = key( $all_roles ); |
| 95 | reset( $all_roles ); |
| 96 | } |
| 97 | |
| 98 | ?> |
| 99 | <form method="post"> |
| 100 | <div class="enabled-or-disabled"> |
| 101 | <input class="enabled-or-disabled__btn" id="enabled" type="radio" name="two_factor_authentication" |
| 102 | value="t" <?php echo esc_html( $this->datas['two_factor_authentication_t'] ?? '' ); ?> /><label for="enabled">有効</label> |
| 103 | <input class="enabled-or-disabled__btn" id="disabled" type="radio" name="two_factor_authentication" |
| 104 | value="f" <?php echo esc_html( $this->datas['two_factor_authentication_f'] ?? '' ); ?> /><label for="disabled">無効</label> |
| 105 | </div> |
| 106 | <div class="box"> |
| 107 | <div class="box-bottom"> |
| 108 | <div class="box-row flex-start"> |
| 109 | <div class="box-row-title not-label">2段階認証が有効な権限グループ</div> |
| 110 | <div class="box-row-content"> |
| 111 | <?php foreach ( $all_roles as $key => $role ) : ?> |
| 112 | <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $role ); ?>" name="roles[]" |
| 113 | value="<?php echo esc_attr( $role ); ?>"<?php checked( in_array( $role, $roles ) ); ?> /> |
| 114 | <label for="<?php echo esc_attr( $role ); ?>"><?php echo esc_html_x( ucfirst( $role ), 'User role' ); ?></label> |
| 115 | <?php if ( $key !== $lastkey ) : ?> |
| 116 | <br/> |
| 117 | <?php endif; ?> |
| 118 | <?php endforeach; ?> |
| 119 | </div> |
| 120 | </div> |
| 121 | </div> |
| 122 | </div> |
| 123 | <div id="submit-btn-area"> |
| 124 | <?php $this->nonce_wp( $this->two_factor_authentication->get_feature_key() ); ?> |
| 125 | <?php $this->submit_button_wp(); ?> |
| 126 | </div> |
| 127 | </form> |
| 128 | <?php |
| 129 | } |
| 130 | } |
| 131 |