diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index f693d2c70..7d1ce684e 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -6,6 +6,7 @@ use CleantalkSP\SpbctWP\Helpers\IP; use CleantalkSP\Variables\Get; use CleantalkSP\Variables\Server; +use CleantalkSP\SpbctWP\LinkConstructor; add_filter('authenticate', 'spbc_authenticate', 20, 3); // Hooks for authentificate add_action('login_errors', 'spbc_fix_error_messages', 99999); // Filters error message @@ -418,13 +419,37 @@ function spbc_2fa__show_field() if ( spbc_is_user_role_in($spbc->settings['2fa__roles'], $user_name) && ( isset($spbc->data['2fa_keys'][ $user_name ]) || $type2fa === 'google_authenticator' ) ) { + $tech_support_url = $spbc->default_settings['edit_tech_support_url__link_default']; + if ( + $spbc->storage['settings']['edit_tech_support_url__enabled'] && + $spbc->storage['settings']['edit_tech_support_url__link'] + ) { + $tech_support_url = + LinkConstructor::buildSimpleLink( + get_home_url(), + $spbc->storage['settings']['edit_tech_support_url__link'] + ); + } + + if ( + $spbc->storage['settings']['edit_tech_support_url__enabled'] && + $spbc->storage['settings']['edit_tech_support_url__remove'] + ) { + $tech_support_url = ''; + } + + if ( $tech_support_url ) { + $tech_support_url = 'tech support'; + } else { + $tech_support_url = 'tech support'; + } $replacement = '

' . $spbc->data["wl_brandname"] . '

' . '

' . '' . '' - . '' - . $description . '

Contact tech support if you have questions.

' + . '' + . $description . '

Contact ' . $tech_support_url . ' if you have questions.

' . '

' . '

' . '' diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index a8352a520..c0e8b1375 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -362,13 +362,40 @@ function spbc_settings__register() ), 'title' => __('Two-factor authentication (2FA)', 'security-malware-firewall'), 'description' => 'spbc_settings_2fa_description_callback', - 'children' => array('2fa__roles]['), + 'children' => array('2fa__roles', 'edit_tech_support_url__enabled', 'edit_tech_support_url__link'), 'long_description' => true, ), '2fa__roles' => array( 'type' => 'field', 'callback' => 'spbc_field_2fa__roles', ), + 'edit_tech_support_url__enabled' => array( + 'display' => version_compare($wp_version, '4.0-RC1-src', '>='), + 'type' => 'field', + 'title' => __('Change the technical support link on the authorization page', 'security-malware-firewall'), + 'description' => spbc_settings_field__edit_tech_support_url_description(), + 'parent' => '2fa__enable', + 'children' => array('edit_tech_support_url__link', 'edit_tech_support_url__remove'), + ), + 'edit_tech_support_url__link' => array( + 'display' => version_compare($wp_version, '4.0-RC1-src', '>='), + 'input_type' => 'text', + 'type' => 'field', + 'title_first' => true, + 'title' => __('Technical support URL: ', 'security-malware-firewall') + . get_home_url() + . '/' + . (get_option('permalink_structure', false) ? '' : '?'), + 'class' => 'spbc_middle_text_field', + 'parent' => 'edit_tech_support_url__enabled', + ), + 'edit_tech_support_url__remove' => array( + 'display' => version_compare($wp_version, '4.0-RC1-src', '>='), + 'type' => 'field', + 'title' => __('Remove the technical support link from the authorization page', 'security-malware-firewall'), + 'description' => '', + 'parent' => 'edit_tech_support_url__enabled', + ), 'login_page_rename__enabled' => array( 'display' => version_compare($wp_version, '4.0-RC1-src', '>='), 'type' => 'field', @@ -4515,6 +4542,17 @@ function spbc_sanitize_settings($settings) || $settings['login_page_rename__redirect'] === '' ? $settings['login_page_rename__redirect'] : ''; + + // Sanitize URLs for technical support link + $settings['edit_tech_support_url__link'] = preg_match('@^[a-zA-Z0-9-/]+$@', (string)$settings['edit_tech_support_url__link']) + ? (string)$settings['edit_tech_support_url__link'] + : ''; + + // Clearing the link if the edit_tech_support_url__remove flag is set + if ($settings['edit_tech_support_url__remove']) { + $settings['edit_tech_support_url__link'] = ''; + } + // Send email notification to admin if about changing login URL if ( empty($spbc->settings['login_page_rename__enabled']) && @@ -5507,6 +5545,30 @@ function spbc_settings_field__action_adjust() echo AdjustToEnvironmentSettings::render(); } +/** + * Description for optoin edit_tech_support_url + * @return string + */ +function spbc_settings_field__edit_tech_support_url_description() +{ + + global $spbc; + + $login_url = wp_login_url(); + + if ( + $spbc->storage['settings']['login_page_rename__enabled'] && + $spbc->storage['settings']['login_page_rename__name'] + ) { + $login_url = get_site_url() . '/' . $spbc->storage['settings']['login_page_rename__name']; + } + + return sprintf( + __('The link will change on the authorization page %s', 'security-malware-firewall'), + '' . $login_url . '' + ); +} + function spbc_settings_field__secfw__get_ip__get_description() { $ip = IP::get(); diff --git a/lib/CleantalkSP/Common/LinkConstructor.php b/lib/CleantalkSP/Common/LinkConstructor.php index 5cee48740..9d54d669a 100644 --- a/lib/CleantalkSP/Common/LinkConstructor.php +++ b/lib/CleantalkSP/Common/LinkConstructor.php @@ -87,4 +87,11 @@ public static function buildRenewalLinkATag($user_token, $link_inner_html, $prod //prepare link return '' . $link_inner_html . ''; } + + public static function buildSimpleLink($domain, $uri = '') + { + $domain = rtrim($domain, '/'); + $link = $domain . '/' . $uri; + return $link; + } } diff --git a/lib/CleantalkSP/SpbctWP/LinkConstructor.php b/lib/CleantalkSP/SpbctWP/LinkConstructor.php index 3f26876a6..f28624572 100644 --- a/lib/CleantalkSP/SpbctWP/LinkConstructor.php +++ b/lib/CleantalkSP/SpbctWP/LinkConstructor.php @@ -123,4 +123,9 @@ public static function buildRenewalLinkATag($user_token, $link_inner_html, $prod { return parent::buildRenewalLinkATag($user_token, $link_inner_html, $product_id, $utm_preset); } + + public static function buildSimpleLink($domain, $uri = '') + { + return parent::buildSimpleLink($domain, $uri); + } } diff --git a/lib/CleantalkSP/SpbctWP/State.php b/lib/CleantalkSP/SpbctWP/State.php index 947e37253..5585581b1 100644 --- a/lib/CleantalkSP/SpbctWP/State.php +++ b/lib/CleantalkSP/SpbctWP/State.php @@ -43,6 +43,10 @@ class State extends \CleantalkSP\Common\State 'bfp__delay__5_fails' => 10, // Delay to sleep after 5 wrong auths 'bfp__block_period__5_fails' => 3600, // By default ban IP for brute force for one hour 'bfp__count_interval' => 900, // Counting login attempts in this interval + 'edit_tech_support_url__enabled' => 0, + 'edit_tech_support_url__link_default' => 'https://wordpress.org/support/plugin/security-malware-firewall', + 'edit_tech_support_url__link' => '', + 'edit_tech_support_url__remove' => 0, 'login_page_rename__enabled' => 0, 'login_page_rename__name' => 'custom-login-url', 'login_page_rename__redirect' => '',