Skip to content

Commit

Permalink
Merge pull request #410 from CleanTalk/edit_support_link_av
Browse files Browse the repository at this point in the history
New. Settings. New option to change and delete the technical support …
  • Loading branch information
AntonV1211 authored Sep 2, 2024
2 parents 8484e25 + fe4aac9 commit 3fc6b1f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
29 changes: 27 additions & 2 deletions inc/spbc-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<a href="' . esc_url($tech_support_url) . '">tech support</a>';
} else {
$tech_support_url = 'tech support';
}
$replacement =
'<h3 style="text-align: center;margin: 0 0 10px 0;">' . $spbc->data["wl_brandname"] . '</h3>'
. '<p id="spbc_2fa_wrapper" style="display: inline !important;">'
. '<label for="spbc_2fa">' . $label . '</label>'
. '<input type="text" name="spbc_2fa" id="spbc_2fa" class="input" value="" size="20" />'
. '<input type="hidden" name="log" class="input" value="' . $user_name . '" />'
. $description . '<br><br>Contact <a href="' . $spbc->data["wl_support_url"] . '">tech support</a> if you have questions.<br><br>'
. '<input type="hidden" name="log" class="input" value="' . $user_name . '" />'
. $description . '<br><br>Contact ' . $tech_support_url . ' if you have questions.<br><br>'
. '</p>'
. '<p class="submit" style="display: inline !important;">'
. '<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In">'
Expand Down
64 changes: 63 additions & 1 deletion inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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']) &&
Expand Down Expand Up @@ -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'),
'<a href="' . $login_url . '" target="_blank">' . $login_url . '</a>'
);
}

function spbc_settings_field__secfw__get_ip__get_description()
{
$ip = IP::get();
Expand Down
7 changes: 7 additions & 0 deletions lib/CleantalkSP/Common/LinkConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ public static function buildRenewalLinkATag($user_token, $link_inner_html, $prod
//prepare link
return '<a href="' . $link . '" target="_blank">' . $link_inner_html . '</a>';
}

public static function buildSimpleLink($domain, $uri = '')
{
$domain = rtrim($domain, '/');
$link = $domain . '/' . $uri;
return $link;
}
}
5 changes: 5 additions & 0 deletions lib/CleantalkSP/SpbctWP/LinkConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions lib/CleantalkSP/SpbctWP/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down

0 comments on commit 3fc6b1f

Please sign in to comment.