class-first-time-wizard-steps.php
3 years ago
class-settings-page-render.php
3 years ago
class-wizard-steps.php
3 years ago
class-first-time-wizard-steps.php
660 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Settings page render class. |
| 4 | * |
| 5 | * @package wp2fa |
| 6 | * @subpackage views |
| 7 | * @copyright 2023 WP White Security |
| 8 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 9 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 10 | */ |
| 11 | |
| 12 | namespace WP2FA\Admin\Views; |
| 13 | |
| 14 | use WP2FA\WP2FA; |
| 15 | use WP2FA\Admin\Helpers\WP_Helper; |
| 16 | use WP2FA\Admin\Controllers\Settings; |
| 17 | use WP2FA\Extensions\RoleSettings\Role_Settings_Controller; |
| 18 | |
| 19 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 20 | |
| 21 | /** |
| 22 | * WP2FA First Wizard Settings view controller |
| 23 | * |
| 24 | * @since 1.7 |
| 25 | */ |
| 26 | class First_Time_Wizard_Steps { |
| 27 | |
| 28 | /** |
| 29 | * Select method step |
| 30 | * |
| 31 | * @since 1.7.0 |
| 32 | * |
| 33 | * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public static function select_method( $setup_wizard = false ) { |
| 38 | |
| 39 | ob_start(); |
| 40 | ?> |
| 41 | <h3><?php esc_html_e( 'Which 2FA methods can your users use?', 'wp-2fa' ); ?></h3> |
| 42 | <p class="description"> |
| 43 | <?php esc_html_e( 'When you uncheck any of the below 2FA methods it won\'t be available for your users to use. You can always change this later on from the plugin\'s settings.', 'wp-2fa' ); ?> |
| 44 | </p> |
| 45 | <?php |
| 46 | $data_role = 'data-role="global"'; |
| 47 | if ( ! $setup_wizard ) { |
| 48 | ?> |
| 49 | <table class="form-table"> |
| 50 | <tbody> |
| 51 | <tr> |
| 52 | <th colspan="2"><?php esc_html_e( 'Which of the below 2FA methods can users use?', 'wp-2fa' ); ?></th> |
| 53 | </tr> |
| 54 | <tr> |
| 55 | <th><label for="2fa-method"><?php esc_html_e( 'Select the methods', 'wp-2fa' ); ?></label></th> |
| 56 | <td> |
| 57 | <?php } ?> |
| 58 | <fieldset id="2fa-method-select" class="2fa-method-select"> |
| 59 | <div class="method-title"><em><?php esc_html_e( 'Primary 2FA methods:', 'wp-2fa' ); ?></em></div> |
| 60 | <br> |
| 61 | <label for="totp"> |
| 62 | <input type="checkbox" id="totp" name="wp_2fa_policy[enable_totp]" value="enable_totp" |
| 63 | <?php echo $data_role; // phpcs:ignore ?> |
| 64 | <?php checked( 'enable_totp', WP2FA::get_wp2fa_setting( 'enable_totp' ), true ); ?> |
| 65 | > |
| 66 | <?php esc_html_e( 'One-time code via 2FA App (TOTP)', 'wp-2fa' ); ?> |
| 67 | </label> |
| 68 | |
| 69 | <?php |
| 70 | if ( $setup_wizard ) { |
| 71 | echo '<p class="description">'; |
| 72 | printf( |
| 73 | /* translators: link to the knowledge base website */ |
| 74 | esc_html__( 'When using this method, users will need to configure a 2FA app to get the one-time login code. The plugin supports all standard 2FA apps. Refer to the %s for more information. Allowing users to set up a secondary 2FA method is highly recommended. You can do this in the next step of the wizard. This will allow users to log in using an alternative method should they, for example lose access to their phone.', 'wp-2fa' ), |
| 75 | '<a href="https://wp2fa.io/support/kb/configuring-2fa-apps/?utm_source=plugin&utm_medium=referral&utm_campaign=WP2FA&utm_content=settings+pages" target="_blank">' . esc_html__( 'guide on how to set up 2FA apps', 'wp-2fa' ) . '</a>' |
| 76 | ); |
| 77 | echo '</p>'; |
| 78 | } |
| 79 | ?> |
| 80 | <?php |
| 81 | /** |
| 82 | * Fired right after the TOTP method HTML rendering. |
| 83 | * |
| 84 | * @param bool $wizard - Is that a wizard call or settings call. |
| 85 | * @param string $data_role - String with the JS data to add to form element. |
| 86 | * @param string $name - The name of the role. |
| 87 | * |
| 88 | * @since 2.0.0 |
| 89 | */ |
| 90 | \do_action( WP_2FA_PREFIX . 'after_totp_setup', $setup_wizard, $data_role, null ); |
| 91 | ?> |
| 92 | <br/> |
| 93 | <label for="hotp"> |
| 94 | <input type="checkbox" id="hotp" name="wp_2fa_policy[enable_email]" value="enable_email" |
| 95 | <?php echo $data_role; // phpcs:ignore ?> |
| 96 | <?php checked( WP2FA::get_wp2fa_setting( 'enable_email' ), 'enable_email' ); ?> |
| 97 | > |
| 98 | <?php esc_html_e( 'One-time code via email (HOTP)', 'wp-2fa' ); |
| 99 | esc_html_e( ' - ensure email deliverability with the free plugin ', 'wp-2fa' ); |
| 100 | echo '<a href="https://wordpress.org/plugins/wp-mail-smtp/" target="_blank" rel="nofollow">WP Mail SMTP</a>.'; |
| 101 | ?> |
| 102 | <?php |
| 103 | ?> |
| 104 | </label> |
| 105 | <?php |
| 106 | if ( $setup_wizard ) { |
| 107 | echo '<p class="description">' . esc_html__( 'When using this method, users will receive the one-time login code over email. Therefore, email deliverability is very important. Users using this method should whitelist the address from which the codes are sent. By default, this is the email address configured in your WordPress. You can run an email test from the plugin\'s settings to confirm email deliverability. If you have had email deliverability / reliability issues, we highly recommend you to install the free plugin ', 'wp-2fa' ) . '<a href="https://wordpress.org/plugins/wp-mail-smtp/" target="_blank" rel="nofollow">WP Mail SMTP</a><br><br>' . esc_html__( 'Allowing users to set up a secondary 2FA method is highly recommended. You can do this in the next step of the wizard. This will allow users to log in using an alternative method should they, for example lose access to their phone.', 'wp-2fa' ) . '</p>'; |
| 108 | } |
| 109 | ?> |
| 110 | <?php if ( ! $setup_wizard ) { ?> |
| 111 | <div class="use-different-hotp-mail<?php echo \esc_attr( ( false === WP2FA::get_wp2fa_setting( 'enable_email' ) ? ' disabled' : '' ) ); ?>"> |
| 112 | <p class="description" style="margin-bottom: 5px; font-style: normal;"> |
| 113 | <?php esc_html_e( 'Allow user to specify the email address of choice', 'wp-2fa' ); ?> |
| 114 | </p> |
| 115 | <fieldset class="email-hotp-options"> |
| 116 | <?php |
| 117 | $options = array( |
| 118 | 'yes' => array( |
| 119 | 'label' => esc_html__( 'Yes', 'wp-2fa' ), |
| 120 | 'value' => 'specify-email_hotp', |
| 121 | ), |
| 122 | 'no' => array( |
| 123 | 'label' => esc_html__( 'No', 'wp-2fa' ), |
| 124 | 'value' => '', |
| 125 | ), |
| 126 | ); |
| 127 | |
| 128 | foreach ( $options as $option_key => $option_settings ) { |
| 129 | ?> |
| 130 | <label for="specify-email_hotp-<?php echo \esc_attr( $option_key ); ?>"> |
| 131 | <input type="radio" name="wp_2fa_policy[specify-email_hotp]" id="specify-email_hotp-<?php echo \esc_attr( $option_key ); ?>" value="<?php echo \esc_attr( $option_settings['value'] ); ?>" class="js-nested" |
| 132 | <?php checked( Settings::get_role_or_default_setting( 'specify-email_hotp', null ), $option_settings['value'] ); ?> |
| 133 | > |
| 134 | <span><?php echo $option_settings['label']; // phpcs:ignore ?></span> |
| 135 | </label> |
| 136 | <?php |
| 137 | } |
| 138 | ?> |
| 139 | </fieldset> |
| 140 | </div> |
| 141 | <?php } ?> |
| 142 | <br /> |
| 143 | <?php |
| 144 | if ( ! $setup_wizard ) { |
| 145 | $class = ''; |
| 146 | |
| 147 | if ( '' === trim( Settings::get_role_or_default_setting( 'enable_totp', null, null, true ) ) && '' === trim( Settings::get_role_or_default_setting( 'enable_email', null, null, true ) ) && '' === trim( Settings::get_role_or_default_setting( 'enable_oob_email', null, null, true ) ) ) { |
| 148 | $class = 'disabled'; |
| 149 | } |
| 150 | ?> |
| 151 | <div class="method-title"><em><?php esc_html_e( 'Secondary 2FA methods:', 'wp-2fa' ); ?></em></div> |
| 152 | <br> |
| 153 | <label for="backup-codes" class="wp-2fa-settings-wrapper <?php echo $class; // phpcs:ignore ?>"> |
| 154 | <input type="checkbox" class="<?php echo \esc_attr( $class ); ?>" id="backup-codes" name="wp_2fa_policy[backup_codes_enabled]" |
| 155 | <?php echo $data_role; // phpcs:ignore ?> |
| 156 | value="yes" |
| 157 | <?php checked( WP2FA::get_wp2fa_setting( 'backup_codes_enabled' ), 'yes' ); ?> |
| 158 | > |
| 159 | <?php |
| 160 | esc_html_e( 'Backup codes', 'wp-2fa' ); |
| 161 | if ( $setup_wizard ) { |
| 162 | echo '<p class="description">Note: '; |
| 163 | } else { |
| 164 | echo ' - '; |
| 165 | } |
| 166 | esc_html_e( 'Backup codes are a secondary method which you can use to log in to the website in case the primary 2FA method is unavailable. Therefore they can\'t be enabled and used as a primary method.', 'wp-2fa' ); |
| 167 | if ( $setup_wizard ) { |
| 168 | echo '</p>'; |
| 169 | } |
| 170 | ?> |
| 171 | </label> |
| 172 | <?php |
| 173 | /** |
| 174 | * Fires after the backup methods HTML rendering is finished. |
| 175 | * |
| 176 | * @param bool $wizard - Is that wizard ot standard setting. |
| 177 | * @param string $data_role - The JS data attribute for the form inputs. |
| 178 | * @param string $role - The name of the user role. |
| 179 | * |
| 180 | * @since 2.0.0 |
| 181 | */ |
| 182 | \do_action( WP_2FA_PREFIX . 'after_backup_methods_setup', $setup_wizard, $data_role, null ); |
| 183 | } |
| 184 | ?> |
| 185 | </fieldset> |
| 186 | <?php |
| 187 | if ( ! $setup_wizard ) { |
| 188 | ?> |
| 189 | </td> |
| 190 | </tr> |
| 191 | </tbody> |
| 192 | </table> |
| 193 | <?php } ?> |
| 194 | <?php |
| 195 | $output = ob_get_clean(); |
| 196 | |
| 197 | /** |
| 198 | * At this point, none of the default providers is set / activated. This filter allows additional providers to change the behaviour. Checking the input array for specific values (methods), and based on that we can raise error that none of the allowed methods has bees selected by the user, or dismiss the error otherwise. |
| 199 | * |
| 200 | * @param string $output - Parsed HTML with the methods. |
| 201 | * @param bool $setup_wizard - The type of the wizard (first time wizard / settings). |
| 202 | * |
| 203 | * @since 2.0.0 |
| 204 | */ |
| 205 | $output = apply_filters( WP_2FA_PREFIX . 'select_methods', $output, $setup_wizard ); |
| 206 | |
| 207 | echo $output; // phpcs:ignore |
| 208 | } |
| 209 | |
| 210 | public static function backup_method( $setup_wizard = false ) { |
| 211 | |
| 212 | ob_start(); |
| 213 | ?> |
| 214 | <h3><?php esc_html_e( 'Which alternative 2FA methods can users use?', 'wp-2fa' ); ?></h3> |
| 215 | <p class="description"> |
| 216 | <?php esc_html_e( 'An alternative 2FA method allows users to configure another 2FA method that can be used as a backup should the primary 2FA method fail. This can happen if, for example, a user forgets their smartphone, the smartphone runs out of battery, or there are email deliverability problems.', 'wp-2fa' ); ?> |
| 217 | </p> |
| 218 | <p class="description"> |
| 219 | <?php esc_html_e( 'It is highly recommended to have an alternative 2FA method configured at all times. Below is a list of alternative 2FA methods available through this plugin:', 'wp-2fa' ); ?> |
| 220 | </p> |
| 221 | |
| 222 | <br> |
| 223 | |
| 224 | <fieldset> |
| 225 | <label for="backup-codes"> |
| 226 | <input type="checkbox" id="backup-codes-global" name="wp_2fa_policy[backup_codes_enabled]" value="yes" |
| 227 | <?php checked( WP2FA::get_wp2fa_setting( 'backup_codes_enabled' ), 'yes' ); ?> |
| 228 | > |
| 229 | <?php esc_html_e( 'Backup codes', 'wp-2fa' ); ?> |
| 230 | </label> |
| 231 | |
| 232 | <?php |
| 233 | echo '<p class="description">'; |
| 234 | echo sprintf( '%1$1s <a href="https://wp2fa.io/support/kb/what-are-2fa-backup-codes/?utm_source=plugin&utm_medium=referral&utm_campaign=WP2FA&utm_content=settings+pages" target="_blank">%2$1s</a> <br><br>', |
| 235 | esc_html__( 'Backup codes allow users to log in to WordPress should they find themselves unable to log in via the primary 2FA method. Backup codes are enabled by default and are generated during the 2FA configuration process. Each backup code can be used only once. Once the initial list is exhausted, more backup codes can be generated through the user’s WordPress profile page - ', 'wp-2fa' ), |
| 236 | esc_html__( 'More information', 'wp-2fa' ) ); |
| 237 | echo '</p>'; |
| 238 | ?> |
| 239 | |
| 240 | <?php |
| 241 | echo '<label>'; |
| 242 | echo sprintf( '%1$1s <a href="https://wp2fa.io/features/alternative-2fa-backup-method-options/?utm_source=plugin&utm_medium=referral&utm_campaign=WP2FA&utm_content=settings+pages" target="_blank">%2$1s</a> %3$1s', |
| 243 | esc_html__( 'Upgrade to WP 2FA Premium for', 'wp-2fa' ), |
| 244 | esc_html__( 'more alternative 2FA methods', 'wp-2fa' ), |
| 245 | esc_html__( 'to give your users more options.', 'wp-2fa' ) ); |
| 246 | echo '<label>'; |
| 247 | ?> |
| 248 | </fieldset> |
| 249 | <?php |
| 250 | ?> |
| 251 | <?php |
| 252 | $output = ob_get_clean(); |
| 253 | $output = apply_filters( WP_2FA_PREFIX . 'backup_methods', $output, $setup_wizard ); |
| 254 | |
| 255 | echo $output; // phpcs:ignore |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Enforcement policy step |
| 260 | * |
| 261 | * @since 1.7.0 |
| 262 | * |
| 263 | * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call. |
| 264 | * |
| 265 | * @return void |
| 266 | */ |
| 267 | public static function enforcement_policy( $setup_wizard = false ) { |
| 268 | ?> |
| 269 | <h3 id="enforcement_settings"><?php esc_html_e( 'Do you want to enforce 2FA for some, or all the users? ', 'wp-2fa' ); ?></h3> |
| 270 | <p class="description"> |
| 271 | <?php esc_html_e( 'When you enforce 2FA the users will be prompted to configure 2FA the next time they login. Users have a grace period for configuring 2FA. You can configure the grace period and also exclude user(s) or role(s) in this settings page. ', 'wp-2fa' ); ?> <a href="https://wp2fa.io/support/kb/configure-2fa-policies-enforce/?utm_source=plugin&utm_medium=referral&utm_campaign=WP2FA&utm_content=settings+pages" target="_blank" rel=noopener><?php esc_html_e( 'Learn more.', 'wp-2fa' ); ?></a> |
| 272 | </p> |
| 273 | <?php |
| 274 | if ( ! $setup_wizard ) { |
| 275 | ?> |
| 276 | <table class="form-table js-enforcement-policy-section"> |
| 277 | <tbody> |
| 278 | <tr> |
| 279 | <th><label for="enforcement-policy"><?php esc_html_e( 'Enforce 2FA on', 'wp-2fa' ); ?></label></th> |
| 280 | <td> |
| 281 | <?php } ?> |
| 282 | <fieldset class="contains-hidden-inputs"> |
| 283 | <label for="all-users" style="margin:.35em 0 .5em !important; display: block;"> |
| 284 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="all-users" value="all-users" |
| 285 | <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'all-users' ); ?> |
| 286 | > |
| 287 | <span><?php esc_html_e( 'All users', 'wp-2fa' ); ?></span> |
| 288 | </label> |
| 289 | |
| 290 | <?php if ( WP_Helper::is_multisite() ) : ?> |
| 291 | <label for="superadmins-only" style="margin:.35em 0 .5em !important; display: block;"> |
| 292 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-only" value="superadmins-only" |
| 293 | <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-only' ); ?> /> |
| 294 | <span><?php esc_html_e( 'Only super admins', 'wp-2fa' ); ?></span> |
| 295 | </label> |
| 296 | <label for="superadmins-siteadmins-only" style="margin:.35em 0 .5em !important; display: block;"> |
| 297 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-siteadmins-only" value="superadmins-siteadmins-only" |
| 298 | <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-siteadmins-only' ); ?> /> |
| 299 | <span><?php esc_html_e( 'Only super admins and site admins', 'wp-2fa' ); ?></span> |
| 300 | </label> |
| 301 | <?php endif; ?> |
| 302 | |
| 303 | <label for="certain-roles-only" style="margin:.35em 0 .5em !important; display: block;"> |
| 304 | <?php $checked = in_array( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), array( 'certain-roles-only', 'certain-users-only' ), true ); ?> |
| 305 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="certain-roles-only" value="certain-roles-only" |
| 306 | <?php ( $setup_wizard ) ? checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'certain-roles-only' ) : checked( $checked ); ?> |
| 307 | data-unhide-when-checked=".certain-roles-only-inputs, .certain-users-only-inputs"> |
| 308 | <span><?php esc_html_e( 'Only for specific users and roles', 'wp-2fa' ); ?></span> |
| 309 | </label> |
| 310 | <fieldset class="hidden certain-users-only-inputs"> |
| 311 | <div> |
| 312 | <p> |
| 313 | <label for="enforced_users-multi-select"><?php esc_html_e( 'Users :', 'wp-2fa' ); ?></label> <select multiple="multiple" id="enforced_users-multi-select" name="wp_2fa_policy[enforced_users][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 314 | <?php |
| 315 | $excluded_users = WP2FA::get_wp2fa_setting( 'enforced_users' ); |
| 316 | foreach ( $excluded_users as $user ) { |
| 317 | ?> |
| 318 | <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_attr( $user ); ?></option> |
| 319 | <?php |
| 320 | } |
| 321 | ?> |
| 322 | </select> |
| 323 | </p> |
| 324 | </div> |
| 325 | </fieldset> |
| 326 | <fieldset class="hidden certain-roles-only-inputs"> |
| 327 | <div> |
| 328 | <p style="margin-top: 0;"> |
| 329 | <label for="enforced-roles-multi-select"><?php esc_html_e( 'Roles :', 'wp-2fa' ); ?></label> |
| 330 | <select multiple="multiple" id="enforced-roles-multi-select" name="wp_2fa_policy[enforced_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 331 | <?php |
| 332 | $all_roles = \WP2FA\WP2FA::wp_2fa_get_roles(); |
| 333 | $enforced_roles = WP2FA::get_wp2fa_setting( 'enforced_roles' ); |
| 334 | foreach ( $all_roles as $role => $role_name ) { |
| 335 | $selected = ''; |
| 336 | if ( in_array( $role, $enforced_roles, true ) ) { |
| 337 | $selected = 'selected="selected"'; |
| 338 | } |
| 339 | ?> |
| 340 | <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option> |
| 341 | <?php |
| 342 | } |
| 343 | ?> |
| 344 | </select> |
| 345 | </p> |
| 346 | </div> |
| 347 | <?php if ( WP_Helper::is_multisite() ) { ?> |
| 348 | <p class="description"> |
| 349 | <input type="checkbox" name="wp_2fa_policy[superadmins-role-add]" id="superadmins-role-add" value="yes" style="position: relative; top: -3px;" |
| 350 | <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-add' ), 'yes' ); ?> /> |
| 351 | <label for="superadmins-role-add"><?php esc_html_e( 'Also enforce 2FA on network users with super admin privileges', 'wp-2fa' ); ?></label> |
| 352 | </p> |
| 353 | <?php } ?> |
| 354 | </fieldset> |
| 355 | <?php if ( WP_Helper::is_multisite() ) { ?> |
| 356 | <div> |
| 357 | <label for="enforce-on-multisite" style="margin:.35em 0 .5em !important; display: block;"> |
| 358 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="enforce-on-multisite" value="enforce-on-multisite" |
| 359 | <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'enforce-on-multisite' ); ?> |
| 360 | data-unhide-when-checked=".all-sites"> |
| 361 | <span><?php esc_html_e( 'These sub-sites', 'wp-2fa' ); ?></span> |
| 362 | </label> |
| 363 | <fieldset class="hidden all-sites"> |
| 364 | <p> |
| 365 | <label for="slim-multi-select"><?php esc_html_e( 'Sites :', 'wp-2fa' ); ?></label> <select multiple="multiple" id="slim-multi-select" name="wp_2fa_policy[included_sites][]" style="display:none; width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 366 | <?php |
| 367 | $selected_sites = WP2FA::get_wp2fa_setting( 'included_sites' ); |
| 368 | foreach ( WP_Helper::get_multi_sites() as $site ) { |
| 369 | $args = array( |
| 370 | 'blog_id' => $site->blog_id, |
| 371 | ); |
| 372 | |
| 373 | $current_blog_details = get_blog_details( $args ); |
| 374 | $selected = ''; |
| 375 | if ( in_array( $site->blog_id, $selected_sites, true ) ) { |
| 376 | $selected = 'selected="selected"'; |
| 377 | } |
| 378 | ?> |
| 379 | <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( $site->blog_id ); ?>"><?php echo \esc_html( $current_blog_details->blogname ); ?></option> |
| 380 | <?php |
| 381 | } |
| 382 | ?> |
| 383 | </select> |
| 384 | </p> |
| 385 | </fieldset> |
| 386 | </div> |
| 387 | <?php } ?> |
| 388 | <div> |
| 389 | <label for="do-not-enforce" style="margin:.35em 0 .5em !important; display: block;"> |
| 390 | <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="do-not-enforce" value="do-not-enforce" |
| 391 | <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'do-not-enforce' ); ?> |
| 392 | > |
| 393 | <span><?php esc_html_e( 'Do not enforce on any users', 'wp-2fa' ); ?></span> |
| 394 | </label> |
| 395 | </div> |
| 396 | <br/> |
| 397 | </fieldset> |
| 398 | <?php |
| 399 | if ( ! $setup_wizard ) { |
| 400 | ?> |
| 401 | </td> |
| 402 | </tr> |
| 403 | </tbody> |
| 404 | </table> |
| 405 | <?php |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Exclude users and groups |
| 411 | * |
| 412 | * @since 1.7.0 |
| 413 | * |
| 414 | * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call. |
| 415 | * |
| 416 | * @return void |
| 417 | */ |
| 418 | public static function exclude_users( $setup_wizard = false ) { |
| 419 | ?> |
| 420 | <h3><?php esc_html_e( 'Do you want to exclude any users or roles from 2FA? ', 'wp-2fa' ); ?></h3> |
| 421 | <p class="description"> |
| 422 | <?php esc_html_e( 'If you are enforcing 2FA on all users but for some reason you would like to exclude individual user(s) or users with a specific role, you can exclude them below', 'wp-2fa' ); ?> |
| 423 | </p> |
| 424 | <?php |
| 425 | if ( ! $setup_wizard ) { |
| 426 | ?> |
| 427 | <table class="form-table js-enforcement-policy-section"> |
| 428 | <tbody> |
| 429 | <tr> |
| 430 | <th><label id="exclude-users" for="excluded-users-multi-select"><?php esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?></label></th> |
| 431 | <td> |
| 432 | <?php } else { ?> |
| 433 | <label for="excluded-users-multi-select"><?php esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?> |
| 434 | <?php } ?> |
| 435 | <fieldset> |
| 436 | <div> |
| 437 | <select multiple="multiple" id="excluded-users-multi-select" name="wp_2fa_policy[excluded_users][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 438 | <?php |
| 439 | $excluded_users = WP2FA::get_wp2fa_setting( 'excluded_users' ); |
| 440 | foreach ( $excluded_users as $user ) { |
| 441 | ?> |
| 442 | <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_html( $user ); ?></option> |
| 443 | <?php |
| 444 | } |
| 445 | ?> |
| 446 | </select> |
| 447 | </div> |
| 448 | <?php |
| 449 | if ( ! $setup_wizard ) { |
| 450 | ?> |
| 451 | |
| 452 | </td> |
| 453 | </tr> |
| 454 | <tr> |
| 455 | <th><label for="excluded-roles-multi-select"><?php esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label></th> |
| 456 | <td> |
| 457 | <p> |
| 458 | <?php } else { ?> |
| 459 | <br> |
| 460 | <label for="excluded-roles-multi-select"><?php esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label> |
| 461 | <?php } ?> |
| 462 | <select multiple="multiple" id="excluded-roles-multi-select" name="wp_2fa_policy[excluded_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 463 | <?php |
| 464 | $all_roles = \WP2FA\WP2FA::wp_2fa_get_roles(); |
| 465 | $excluded_roles = WP2FA::get_wp2fa_setting( 'excluded_roles' ); |
| 466 | foreach ( $all_roles as $role => $role_name ) { |
| 467 | $selected = ''; |
| 468 | if ( in_array( strtolower( $role ), $excluded_roles, true ) ) { |
| 469 | $selected = 'selected="selected"'; |
| 470 | } |
| 471 | ?> |
| 472 | <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option> |
| 473 | <?php |
| 474 | } |
| 475 | ?> |
| 476 | </select> |
| 477 | <br> |
| 478 | <?php if ( WP_Helper::is_multisite() ) { ?> |
| 479 | <div style="margin-top:10px;"> |
| 480 | <input type="checkbox" name="wp_2fa_policy[superadmins-role-exclude]" id="superadmins-role-exclude" value="yes" |
| 481 | <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-exclude' ), 'yes' ); ?> /> |
| 482 | <label for="superadmins-role-exclude"><?php esc_html_e( 'Also exclude users with super admin privilege', 'wp-2fa' ); ?></label> |
| 483 | </div> |
| 484 | <?php } ?> |
| 485 | </fieldset> |
| 486 | <?php |
| 487 | if ( ! $setup_wizard ) { |
| 488 | ?> |
| 489 | </td> |
| 490 | </tr> |
| 491 | </tbody> |
| 492 | </table> |
| 493 | <?php } ?> |
| 494 | <?php |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Which network sites to exclude (for multisite instal) |
| 499 | * |
| 500 | * @since 1.7.0 |
| 501 | * |
| 502 | * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call. |
| 503 | * |
| 504 | * @return void |
| 505 | */ |
| 506 | public static function excluded_network_sites( $setup_wizard = false ) { |
| 507 | ?> |
| 508 | <h3><?php esc_html_e( 'Do you want to exclude all the users of a site from 2FA? ', 'wp-2fa' ); ?></h3> |
| 509 | <p class="description"> |
| 510 | <?php esc_html_e( 'If you are enforcing 2FA on all users but for some reason you do not want to enforce it on a specific sub site, specify the sub site name below:', 'wp-2fa' ); ?> |
| 511 | </p> |
| 512 | <?php |
| 513 | if ( ! $setup_wizard ) { |
| 514 | ?> |
| 515 | <table class="form-table js-enforcement-policy-section"> |
| 516 | <tbody> |
| 517 | <tr> |
| 518 | <th><label for="excluded-sites-multi-select"><?php esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?></label></th> |
| 519 | <td> |
| 520 | <?php } ?> |
| 521 | <fieldset> |
| 522 | <?php |
| 523 | if ( $setup_wizard ) { |
| 524 | ?> |
| 525 | |
| 526 | <div class="option-pill"> |
| 527 | <label for="excluded_sites_search"><?php esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?> |
| 528 | <?php } ?> |
| 529 | <select multiple="multiple" id="excluded-sites-multi-select" name="wp_2fa_policy[excluded_sites][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%"> |
| 530 | <?php |
| 531 | $excluded_sites = WP2FA::get_wp2fa_setting( 'excluded_sites' ); |
| 532 | if ( ! empty( $excluded_sites ) ) { |
| 533 | foreach ( $excluded_sites as $site_id ) { |
| 534 | $site = get_blog_details( $site_id )->blogname; |
| 535 | ?> |
| 536 | <option selected="selected" value="<?php echo \esc_attr( $site_id ); ?>"><?php echo \esc_html( $site ); ?></option> |
| 537 | <?php |
| 538 | } |
| 539 | } |
| 540 | ?> |
| 541 | </select> |
| 542 | <?php |
| 543 | if ( $setup_wizard ) { |
| 544 | ?> |
| 545 | </label> |
| 546 | </div> |
| 547 | <?php } ?> |
| 548 | </fieldset> |
| 549 | <?php |
| 550 | if ( ! $setup_wizard ) { |
| 551 | ?> |
| 552 | </td> |
| 553 | </tr> |
| 554 | </tbody> |
| 555 | </table> |
| 556 | <?php } ?> |
| 557 | <?php |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Set the grace period |
| 562 | * |
| 563 | * @since 1.7.0 |
| 564 | * |
| 565 | * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call. |
| 566 | * |
| 567 | * @return void |
| 568 | */ |
| 569 | public static function grace_period( $setup_wizard = false ) { |
| 570 | $grace_period = (int) WP2FA::get_wp2fa_setting( 'grace-period', true ); |
| 571 | /** |
| 572 | * Via that, you can change the grace period TTL. |
| 573 | * |
| 574 | * @param bool - Default at this point is true - no method is selected. |
| 575 | */ |
| 576 | $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false ); |
| 577 | if ( $testing ) { |
| 578 | $grace_max = 600; |
| 579 | } else { |
| 580 | $grace_max = 10; |
| 581 | } |
| 582 | ?> |
| 583 | <fieldset class="contains-hidden-inputs"> |
| 584 | <label for="no-grace-period" style="margin-bottom: 10px; display: block;"> |
| 585 | <input type="radio" name="wp_2fa_policy[grace-policy]" id="no-grace-period" value="no-grace-period" |
| 586 | <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'no-grace-period' ); ?> |
| 587 | > |
| 588 | <span><?php esc_html_e( 'Users have to configure 2FA straight away.', 'wp-2fa' ); ?></span> |
| 589 | </label> |
| 590 | |
| 591 | <label for="use-grace-period"> |
| 592 | <input type="radio" name="wp_2fa_policy[grace-policy]" id="use-grace-period" value="use-grace-period" |
| 593 | <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'use-grace-period' ); ?> |
| 594 | data-unhide-when-checked=".grace-period-inputs"> |
| 595 | <span><?php esc_html_e( 'Give users a grace period to configure 2FA', 'wp-2fa' ); ?></span> |
| 596 | </label> |
| 597 | <fieldset class="hidden grace-period-inputs"> |
| 598 | <br/> |
| 599 | <input type="number" id="grace-period" name="wp_2fa_policy[grace-period]" value="<?php echo esc_attr( $grace_period ); ?>" min="1" max="<?php echo esc_attr( $grace_max ); ?>"> |
| 600 | <label class="radio-inline"> |
| 601 | <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="hours" |
| 602 | <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'hours' ); ?> |
| 603 | > |
| 604 | <?php esc_html_e( 'hours', 'wp-2fa' ); ?> |
| 605 | </label> |
| 606 | <label class="radio-inline"> |
| 607 | <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="days" |
| 608 | <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'days' ); ?> |
| 609 | > |
| 610 | <?php esc_html_e( 'days', 'wp-2fa' ); ?> |
| 611 | </label> |
| 612 | <?php |
| 613 | /** |
| 614 | * Fires after the grace period. Gives the ability to change the parsed code. |
| 615 | * |
| 616 | * @param string $content - HTML content. |
| 617 | * @param string $role - The name of the role. |
| 618 | * @param string $name_prefix - Name prefix for the input name, includes the role name if provided. |
| 619 | * @param string $data_role - Data attribute - used by the JS. |
| 620 | * @param string $role_id - The role name, used to identify the inputs. |
| 621 | * |
| 622 | * @since 2.0.0 |
| 623 | */ |
| 624 | $after_grace_content = \apply_filters( WP_2FA_PREFIX . 'after_grace_period', '', '', 'wp_2fa_policy' ); |
| 625 | echo $after_grace_content; // phpcs:ignore |
| 626 | ?> |
| 627 | <?php |
| 628 | /** |
| 629 | * Via that, you can change the grace period TTL. |
| 630 | * |
| 631 | * @param bool - Default at this point is true - no method is selected. |
| 632 | */ |
| 633 | $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false ); |
| 634 | if ( $testing ) { |
| 635 | ?> |
| 636 | <label class="radio-inline"> |
| 637 | <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="seconds" |
| 638 | <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'seconds' ); ?> |
| 639 | > |
| 640 | <?php esc_html_e( 'Seconds', 'wp-2fa' ); ?> |
| 641 | </label> |
| 642 | <?php |
| 643 | } |
| 644 | |
| 645 | if ( $setup_wizard ) { |
| 646 | $user = wp_get_current_user(); |
| 647 | $last_user_to_update_settings = $user->ID; |
| 648 | |
| 649 | ?> |
| 650 | <input type="hidden" id="2fa_main_user" name="wp_2fa_policy[2fa_settings_last_updated_by]" value="<?php echo esc_attr( $last_user_to_update_settings ); ?>"> |
| 651 | <?php } else { ?> |
| 652 | <p><?php esc_html_e( 'Note: If users do not configure it within the configured stipulated time, their account will be locked and have to be unlocked manually.', 'wp-2fa' ); ?></p> |
| 653 | <?php } ?> |
| 654 | </fieldset> |
| 655 | <br/> |
| 656 | </fieldset> |
| 657 | <?php |
| 658 | } |
| 659 | } |
| 660 |