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