class-abstract-migration.php
1 year ago
class-date-time-utils.php
1 year ago
class-debugging.php
1 year ago
class-generate-modal.php
1 year ago
class-migration.php
1 year ago
class-request-utils.php
1 year ago
class-settings-utils.php
1 year ago
class-user-utils.php
1 year ago
class-white-label.php
1 year ago
index.php
1 year ago
class-white-label.php
173 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsible for white labeling functionality. |
| 4 | * |
| 5 | * @package wp2fa |
| 6 | * @subpackage white-label |
| 7 | * |
| 8 | * @copyright 2024 Melapress |
| 9 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 10 | * |
| 11 | * @see https://wordpress.org/plugins/wp-2fa/ |
| 12 | */ |
| 13 | |
| 14 | declare(strict_types=1); |
| 15 | |
| 16 | namespace WP2FA\Utils; |
| 17 | |
| 18 | if ( ! class_exists( '\WP2FA\Utils\White_Label' ) ) { |
| 19 | /** |
| 20 | * Utility class for white labeling. |
| 21 | * |
| 22 | * @package WP2FA\Utils |
| 23 | * |
| 24 | * @since 2.8.0 |
| 25 | */ |
| 26 | class White_Label { |
| 27 | |
| 28 | /** |
| 29 | * Local static cache for plugins settings. |
| 30 | * |
| 31 | * @var array |
| 32 | * |
| 33 | * @since 2.8.0 |
| 34 | */ |
| 35 | private static $plugin_settings = array(); |
| 36 | |
| 37 | /** |
| 38 | * Inits the plugin related classes and settings |
| 39 | * |
| 40 | * @return void |
| 41 | * |
| 42 | * @since 2.8.0 |
| 43 | */ |
| 44 | public static function init() { |
| 45 | |
| 46 | self::$plugin_settings[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] = Settings_Utils::get_option( WP_2FA_WHITE_LABEL_SETTINGS_NAME, array() ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Util function to grab white label settings or apply defaults if no settings are saved into the db. |
| 51 | * |
| 52 | * @param string $setting_name Settings to grab value of. |
| 53 | * @param boolean $get_default_on_empty return default setting value if current one is empty. |
| 54 | * |
| 55 | * @return string|array Settings value or default value. |
| 56 | * |
| 57 | * @since 2.8.0 |
| 58 | */ |
| 59 | public static function get_setting( $setting_name = '', $get_default_on_empty = false ) { |
| 60 | $default_settings = self::get_default_settings(); |
| 61 | |
| 62 | $white_label_setting = self::$plugin_settings[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ]; |
| 63 | |
| 64 | // If we have no setting name, return them all. |
| 65 | if ( empty( $setting_name ) ) { |
| 66 | return $white_label_setting; |
| 67 | } |
| 68 | |
| 69 | // First lets check if any options have been saved. |
| 70 | if ( empty( $white_label_setting ) || ! isset( $white_label_setting ) ) { |
| 71 | $apply_defaults = true; |
| 72 | } |
| 73 | |
| 74 | if ( $apply_defaults ) { |
| 75 | return isset( $default_settings[ $setting_name ] ) ? $default_settings[ $setting_name ] : ''; |
| 76 | } elseif ( ! isset( $white_label_setting[ $setting_name ] ) ) { |
| 77 | if ( true === $get_default_on_empty ) { |
| 78 | if ( isset( $default_settings[ $setting_name ] ) ) { |
| 79 | return $default_settings[ $setting_name ]; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return ''; |
| 84 | } else { |
| 85 | return $white_label_setting[ $setting_name ]; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Array with all the plugin default settings. |
| 91 | * |
| 92 | * @return array |
| 93 | * |
| 94 | * @since 2.8.0 |
| 95 | */ |
| 96 | public static function get_default_settings() { |
| 97 | $default_settings = array( |
| 98 | 'default-text-code-page' => '<p>' . __( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . __( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>', |
| 99 | 'default-text-pw-reset-code-page' => '<p>' . __( 'You have been sent a one-time code via email. Please enter the code below and then click Get New Password to proceed with the password reset.', 'wp-2fa' ) . '</p><br><p><strong>' . __( 'Note: If you have not received the code please click the button Resend Code. If you still do not get the code after pressing the button, please contact the website\'s administrator.', 'wp-2fa' ) . '</strong></p>', |
| 100 | 'default-2fa-required-notice' => '<p>' . __( 'This website\'s administrator requires you to enable two-factor authentication (2FA) {grace_period_remaining}.', 'wp-2fa' ) . '</p><br><p>' . __( 'Failing to configure 2FA within this time period will result in a locked account. For more information, please contact your website administrator.', 'wp-2fa' ) . '</p>', |
| 101 | 'default-2fa-resetup-required-notice' => '<p>' . __( 'This website\'s administrator requires you to enable two-factor authentication (2FA) {grace_period_remaining}.', 'wp-2fa' ) . '</p><br><p>' . __( 'Failing to configure 2FA within this time period will result in a locked account. For more information, please contact your website administrator.', 'wp-2fa' ) . '</p>', |
| 102 | 'custom-text-authy-code-page-intro' => __( 'If you are using the Authy app approve the OneTouch request to log in.', 'wp-2fa' ), |
| 103 | 'custom-text-authy-code-page-awaiting' => __( 'Waiting for approval from application...', 'wp-2fa' ), |
| 104 | 'custom-text-authy-code-page' => __( 'Manually enter the code from the mobile app.', 'wp-2fa' ), |
| 105 | 'custom-text-twilio-code-page' => __( 'Enter the 2FA code you have received over SMS.', 'wp-2fa' ), |
| 106 | 'custom-text-clickatell-code-page' => __( 'Enter the 2FA code you have received over SMS.', 'wp-2fa' ), |
| 107 | 'custom-text-yubico-code-page' => __( 'Please insert the YubiKey in a USB port and touch / click the button on the YubiKey to generate the OTP required to log in.', 'wp-2fa' ), |
| 108 | 'custom-text-app-code-page' => '<p>' . __( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . __( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>', |
| 109 | 'custom-text-email-code-page' => '<p>' . __( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . __( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>', |
| 110 | |
| 111 | 'default-backup-code-page' => __( 'Enter a backup verification code.', 'wp-2fa' ), |
| 112 | 'method_invalid_setting' => 'login_block', |
| 113 | 'enable_wizard_styling' => 'enable_wizard_styling', |
| 114 | 'show_help_text' => 'show_help_text', |
| 115 | 'enable_wizard_logo' => '', |
| 116 | 'enable_welcome' => '', |
| 117 | 'welcome' => '', |
| 118 | 'method_selection' => '<h3>' . __( 'Choose the 2FA method', 'wp-2fa' ) . '</h3>' . esc_html__( |
| 119 | 'There are {available_methods_count} methods available to choose from for 2FA:', |
| 120 | 'wp-2fa' |
| 121 | ), |
| 122 | 'method_selection_single' => '<h3>' . __( 'Choose the 2FA method', 'wp-2fa' ) . '</h3><p>' . __( 'Only the below 2FA method is allowed on this website:', 'wp-2fa' ) . '</p>', |
| 123 | 'method_help_authy_intro' => '<h3>' . __( 'Setting up Push notifications', 'wp-2fa' ) . '</h3><p>' . __( 'To enable push notifications enter the country and cellphone number in order to use it with this account.', 'wp-2fa' ) . '</p>', |
| 124 | 'method_help_twilio_intro' => '<h3>' . __( 'Setting up 2FA over SMS', 'wp-2fa' ) . '</h3><p>' . __( 'When you use 2FA over SMS to log in to this website you will receive your one-time code via an SMS on your cellphone. Therefore please enter the cellphone number of where you would like to receive the SMS below.', 'wp-2fa' ) . '</p>', |
| 125 | 'method_help_clickatell_intro' => '<h3>' . __( 'Setting up 2FA over SMS', 'wp-2fa' ) . '</h3><p>' . __( 'When you use 2FA over SMS to log in to this website you will receive your one-time code via an SMS on your cellphone. Therefore please enter the cellphone number of where you would like to receive the SMS below.', 'wp-2fa' ) . '</p>', |
| 126 | 'method_help_oob_intro' => '<h3>' . __( 'Setting up Link over email 2FA', 'wp-2fa' ) . '</h3><p>' . __( 'Please select the email address to where the out-of-band link should be sent:', 'wp-2fa' ) . '</p>', |
| 127 | 'method_help_yubico_intro' => '<h3>' . __( 'Setting up 2FA with YubiKey', 'wp-2fa' ) . '</h3><p>' . __( '1 - Insert your YubiKey into the computer\'s / mobile\'s USB port', 'wp-2fa' ) . '</p><p>' . __( '2 - Touch / press the button on your YubiKey to generate the OTP code, which is automatically populated below', 'wp-2fa' ) . '</p>', |
| 128 | 'method_verification_oob_pre' => '<h3>' . __( 'Almost there…', 'wp-2fa' ) . '</h3><p>' . __( 'Please type in the one-time code sent to your email address to finalize the setup. Once the code is confirmed and 2FA is set up, you only have to verify a login by clicking on a link sent to you via email.', 'wp-2fa' ) . '</p>', |
| 129 | 'method_verification_authy_pre' => '<h3>' . __( 'Almost there…', 'wp-2fa' ) . '</h3><p>' . __( 'Please type in the code from your Authy application with name {authy_name}', 'wp-2fa' ) . '</p>', |
| 130 | 'method_verification_twilio_pre' => '<h3>' . __( 'Almost there…', 'wp-2fa' ) . '</h3><p>' . __( 'Please type in the one-time code sent via SMS to your phone to confirm your phone number.', 'wp-2fa' ) . '</p>', |
| 131 | 'method_verification_clickatell_pre' => '<h3>' . __( 'Almost there…', 'wp-2fa' ) . '</h3><p>' . __( 'Please type in the one-time code sent via SMS to your phone to confirm your phone number.', 'wp-2fa' ) . '</p>', |
| 132 | 'method_verification_yubico_pre' => '<h3>' . __( 'Almost there…', 'wp-2fa' ) . '</h3><p>' . __( 'Touch the YubiKey again to generate the OTP code to confirm the setup. Once the code is populated below, it should be automatically saved and verified. If that does not happen by any reason, once the secret key was pasted, click "Validate & save" button below to manually save and complete the configuration.', 'wp-2fa' ) . '</p>', |
| 133 | 'backup_codes_intro_multi' => '<h3>' . __( 'Your login just got more secure', 'wp-2fa' ) . '</h3><p>' . __( 'It is recommended to configure a backup 2FA method in case you do not have access to the primary 2FA method to generate a code to log in. You can configure any of the below. You can always configure any or both from your user profile page later.', 'wp-2fa' ) . '</p>', |
| 134 | 'backup_codes_intro' => '<h3>' . __( 'Your login just got more secure', 'wp-2fa' ) . '</h3><p>' . __( 'Congratulations! You have enabled two-factor authentication for your user. You’ve just helped towards making this website more secure!', 'wp-2fa' ) . '</p>', |
| 135 | 'backup_codes_intro_continue' => '<h3>' . __( 'Your login just got more secure', 'wp-2fa' ) . '</h3><p>' . __( 'Congratulations! You have enabled two-factor authentication for your user. You’ve just helped towards making this website more secure!', 'wp-2fa' ) . '</p><p>' . __( 'You should now generate the list of backup method. Although this is optional, it is highly recommended to have a secondary 2FA method. This can be used as a backup should the primary 2FA method fail. This can happen if, for example, you forget your smartphone, the smartphone runs out of battery, or there are email deliverability problems.', 'wp-2fa' ) . '</p>', |
| 136 | 'backup_codes_generate_intro' => '<h3>' . __( 'Generate list of backup codes', 'wp-2fa' ) . '</h3><p>' . __( 'It is recommended to generate and print some backup codes in case you lose access to your primary 2FA method.', 'wp-2fa' ) . '</p>', |
| 137 | 'backup_codes_generated' => '<h3>' . __( 'Backup codes generated', 'wp-2fa' ) . '</h3><p>' . __( 'Here are your backup codes:', 'wp-2fa' ) . '</p>', |
| 138 | 'no_further_action' => '<h3>' . __( 'Congratulations! You are all set.', 'wp-2fa' ), |
| 139 | '2fa_required_intro' => '<h3>' . __( 'You are required to configure 2FA.', 'wp-2fa' ) . '</h3><p>' . __( 'In order to keep this site - and your details secure, this website’s administrator requires you to enable 2FA authentication to continue.', 'wp-2fa' ) . '</p><p>' . __( 'Two factor authentication ensures only you have access to your account by creating an added layer of security when logging in -', 'wp-2fa' ) . ' <a href="https://melapress.com/wordpress-2fa/?&utm_source=plugin&utm_medium=link&utm_campaign=wp2fa" target="_blank" rel="noopener">' . __( 'Learn more', 'wp-2fa' ) . '</a></p>', |
| 140 | 'authy_reconfigure_intro' => '<h3>' . __( '{reconfigure_or_configure_capitalized} push notification method', 'wp-2fa' ) . '</h3><p>' . __( 'Click the below button to {reconfigure_or_configure} the push notifications configuration.', 'wp-2fa' ) . '</p>', |
| 141 | 'authy_reconfigure_intro_unavailable' => '<h3>' . __( '{reconfigure_or_configure_capitalized} push notification method', 'wp-2fa' ) . '</h3><p>' . __( 'The 2FA service you want to use is currently unavailable. Please try again later or restart the wizard to choose another method.', 'wp-2fa' ) . '</p>', |
| 142 | 'twilio_reconfigure_intro' => '<h3>' . __( '{reconfigure_or_configure_capitalized} SMS method (Twilio)', 'wp-2fa' ) . '</h3><p>' . __( 'Click the below button to {reconfigure_or_configure} the mobile phone number where the one-time code should be sent.', 'wp-2fa' ) . '</p>', |
| 143 | 'clickatell_reconfigure_intro' => '<h3>' . __( '{reconfigure_or_configure_capitalized} SMS method (Clickatell)', 'wp-2fa' ) . '</h3><p>' . __( 'Please select the phone where code should be send:', 'wp-2fa' ) . '</p>', |
| 144 | 'yubico_reconfigure_intro' => '<h3>' . __( '{reconfigure_or_configure_capitalized} 2FA over YubiKey', 'wp-2fa' ) . '</h3><p>' . __( 'Click the below button to {reconfigure_or_configure} the YubiKey associated with your user.', 'wp-2fa' ) . '</p>', |
| 145 | 'twilio_reconfigure_intro_unavailable' => '<h3>' . __( '{reconfigure_or_configure_capitalized} SMS method', 'wp-2fa' ) . '</h3><p>' . __( 'The 2FA over SMS service you want to use is currently unavailable. Please try again later or restart the wizard to choose another method.', 'wp-2fa' ) . '</p>', |
| 146 | 'clickatell_reconfigure_intro_unavailable' => '<h3>' . __( '{reconfigure_or_configure_capitalized} SMS method', 'wp-2fa' ) . '</h3><p>' . __( 'The 2FA over SMS service you want to use is currently unavailable. Please try again later or restart the wizard to choose another method.', 'wp-2fa' ) . '</p>', |
| 147 | 'yubico_reconfigure_intro_unavailable' => '<h3>' . __( ' {reconfigure_or_configure_capitalized} 2FA over YubiKey', 'wp-2fa' ) . '</h3><p>' . __( 'The Yubico service you want to use is currently unavailable. Please try again later or restart the wizard to choose another method.', 'wp-2fa' ) . '</p>', |
| 148 | 'oob_reconfigure_intro' => '<h3>' . __( '{reconfigure_or_configure_capitalized} link over email method', 'wp-2fa' ) . '</h3><p>' . __( 'Click the below button to {reconfigure_or_configure} the email address where the link should be sent.', 'wp-2fa' ) . '</p>', |
| 149 | 'custom_css' => '', |
| 150 | 'login_custom_css' => '', |
| 151 | 'logo-code-page' => '', |
| 152 | 'disable_login_css' => '', |
| 153 | 'login-to-view-area' => '<p>' . __( 'You must be logged in to view this page. {login_url}', 'wp-2fa' ) . '</p>', |
| 154 | 'backup_email_intro' => '<h3>' . __( 'Your login just got more secure', 'wp-2fa' ) . '</h3><p>' . __( 'Well done on configuring 2FA, your login has just got more secure. To make sure you never get locked out you are required to confirm your email address and use email as an alternative and backup 2FA method in case your primary method is unavailable. Please confirm your email address below', 'wp-2fa' ) . '</p>', |
| 155 | 'user-profile-form-preamble-title' => __( 'Two-factor authentication settings', 'wp-2fa' ), |
| 156 | 'user-profile-form-preamble-desc' => __( 'Add two-factor authentication to strengthen the security of your user account.', 'wp-2fa' ), |
| 157 | 'use_custom_2fa_message' => 'use-defaults', |
| 158 | ); |
| 159 | |
| 160 | /** |
| 161 | * Gives the ability to filter the default settings array of the plugin |
| 162 | * |
| 163 | * @param array $settings - The array with all the default settings. |
| 164 | * |
| 165 | * @since 2.0.0 |
| 166 | */ |
| 167 | $default_settings = \apply_filters( WP_2FA_PREFIX . 'white_label_default_settings', $default_settings ); |
| 168 | |
| 169 | return $default_settings; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 |