From 70f589b3d97a17f8f2b0d2e38dc62f9a0b931eef Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Aug 2024 20:43:40 +0700 Subject: [PATCH 1/7] New. Settings. New option to change and delete the technical support link on the authorization page --- inc/spbc-auth.php | 13 ++++++++++- inc/spbc-settings.php | 53 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index f693d2c70..6b3b1b74a 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -418,13 +418,24 @@ 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 = 'tech support'; + if ( + $spbc->storage['settings']['edit_tech_support_url__enabled'] && + $spbc->storage['settings']['edit_tech_support_url__link'] + ) { + $tech_support_url = 'tech support'; + } + + if ($spbc->storage['settings']['edit_tech_support_url__remove'] ) { + $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 38acf4a60..842897e6e 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -361,13 +361,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', @@ -5506,6 +5533,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(); From 822bec5a4dc8f74e9d0bc1f4ee700a827eb9d953 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Aug 2024 20:41:07 +0700 Subject: [PATCH 2/7] Upd. Settings. Cleaning and sanitizing the link, added a default option --- inc/spbc-auth.php | 4 ++-- inc/spbc-settings.php | 6 ++++++ lib/CleantalkSP/SpbctWP/State.php | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index 6b3b1b74a..c75c73d07 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -418,12 +418,12 @@ 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 = 'tech support'; + $tech_support_url = 'tech support'; if ( $spbc->storage['settings']['edit_tech_support_url__enabled'] && $spbc->storage['settings']['edit_tech_support_url__link'] ) { - $tech_support_url = 'tech support'; + $tech_support_url = 'tech support'; } if ($spbc->storage['settings']['edit_tech_support_url__remove'] ) { diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index 842897e6e..6f27ab012 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -4541,6 +4541,12 @@ 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']) + ? $settings['edit_tech_support_url__link'] + : ''; + // Send email notification to admin if about changing login URL if ( empty($spbc->settings['login_page_rename__enabled']) && diff --git a/lib/CleantalkSP/SpbctWP/State.php b/lib/CleantalkSP/SpbctWP/State.php index 947e37253..c15066310 100644 --- a/lib/CleantalkSP/SpbctWP/State.php +++ b/lib/CleantalkSP/SpbctWP/State.php @@ -43,6 +43,9 @@ 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' => '', + 'edit_tech_support_url__remove' => 0, 'login_page_rename__enabled' => 0, 'login_page_rename__name' => 'custom-login-url', 'login_page_rename__redirect' => '', From 69812a1c77eeec813cf150a98b34d7c1ba4ead27 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Aug 2024 16:22:50 +0700 Subject: [PATCH 3/7] Fix. Settings. Passing the url before displaying the link --- inc/spbc-auth.php | 2 +- inc/spbc-settings.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index c75c73d07..1791fe6ca 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -423,7 +423,7 @@ function spbc_2fa__show_field() $spbc->storage['settings']['edit_tech_support_url__enabled'] && $spbc->storage['settings']['edit_tech_support_url__link'] ) { - $tech_support_url = 'tech support'; + $tech_support_url = 'tech support'; } if ($spbc->storage['settings']['edit_tech_support_url__remove'] ) { diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index 6f27ab012..c9f72f088 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -4544,7 +4544,7 @@ function spbc_sanitize_settings($settings) // 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']) - ? $settings['edit_tech_support_url__link'] + ? (string)$settings['edit_tech_support_url__link'] : ''; // Send email notification to admin if about changing login URL From 0b19fc9f41a2c85902b830b47fd18333fc84c3bd Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Aug 2024 16:26:31 +0700 Subject: [PATCH 4/7] Fix. Settings. Clearing the link if the remove flag is set --- inc/spbc-settings.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index c9f72f088..7920af418 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -4547,6 +4547,11 @@ function spbc_sanitize_settings($settings) ? (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']) && From c61e457a767743fe21bcd820e09aebbce00335eb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Aug 2024 17:33:45 +0700 Subject: [PATCH 5/7] Upd. Settings. Changing the composition of a link through a class --- inc/spbc-auth.php | 13 +++++++++---- lib/CleantalkSP/Common/LinkConstructor.php | 7 +++++++ lib/CleantalkSP/SpbctWP/LinkConstructor.php | 5 +++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index 1791fe6ca..ab1e4e5ac 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,12 +419,16 @@ 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 = 'tech support'; + $tech_support_url = $spbc->data["wl_support_url"]; if ( $spbc->storage['settings']['edit_tech_support_url__enabled'] && $spbc->storage['settings']['edit_tech_support_url__link'] ) { - $tech_support_url = 'tech support'; + $tech_support_url = + LinkConstructor::buildSimpleLink( + get_home_url(), + $spbc->storage['settings']['edit_tech_support_url__link'] + ); } if ($spbc->storage['settings']['edit_tech_support_url__remove'] ) { @@ -434,8 +439,8 @@ function spbc_2fa__show_field() . '

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

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

' + . '' + . $description . '

Contact tech support if you have questions.

' . '

' . '

' . '' 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 060226871..c47959a0a 100644 --- a/lib/CleantalkSP/SpbctWP/LinkConstructor.php +++ b/lib/CleantalkSP/SpbctWP/LinkConstructor.php @@ -116,4 +116,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); + } } From 43c4bac6831dda634dd925c761aff8e45e4e5f20 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Aug 2024 18:15:03 +0700 Subject: [PATCH 6/7] Fix. Settings. Editing the link rendering --- inc/spbc-auth.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index ab1e4e5ac..10f8cfd05 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -431,7 +431,16 @@ function spbc_2fa__show_field() ); } - if ($spbc->storage['settings']['edit_tech_support_url__remove'] ) { + 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 = @@ -440,7 +449,7 @@ function spbc_2fa__show_field() . '' . '' . '' - . $description . '

Contact tech support if you have questions.

' + . $description . '

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

' . '

' . '

' . '' From fe4aac94c3fbd10f8d6351bb301fe5ec257b9787 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Aug 2024 15:32:41 +0700 Subject: [PATCH 7/7] Fix. Settings. Add default tech support link --- inc/spbc-auth.php | 2 +- lib/CleantalkSP/SpbctWP/State.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/spbc-auth.php b/inc/spbc-auth.php index 10f8cfd05..7d1ce684e 100644 --- a/inc/spbc-auth.php +++ b/inc/spbc-auth.php @@ -419,7 +419,7 @@ 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->data["wl_support_url"]; + $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'] diff --git a/lib/CleantalkSP/SpbctWP/State.php b/lib/CleantalkSP/SpbctWP/State.php index c15066310..5585581b1 100644 --- a/lib/CleantalkSP/SpbctWP/State.php +++ b/lib/CleantalkSP/SpbctWP/State.php @@ -44,6 +44,7 @@ class State extends \CleantalkSP\Common\State '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,