| 1 |
/* global pagenow, ajaxurl, xoSecurityAdminOptions */ |
| 2 |
(function ($) { |
| 3 |
var xoSecuritySettings = function () { |
| 4 |
var |
| 5 |
field_login_interval = $("#field_interval"), |
| 6 |
field_login_page = $("#field_login_page"), |
| 7 |
field_login_page_name = $("#field_login_page_name"), |
| 8 |
field_login_two_factor = $("#field_two_factor"), |
| 9 |
field_login_two_factor_roles = $("[id^='field_two_factor_roles_']"), |
| 10 |
field_login_alert = $("#field_login_alert"), |
| 11 |
field_login_alert_subject = $("#field_login_alert_subject"), |
| 12 |
field_login_alert_body = $("#field_login_alert_body"), |
| 13 |
field_login_alert_admin_only = $("#field_login_alert_admin_only"), |
| 14 |
field_rest = $("#field_rest"), |
| 15 |
field_rest_namespace = $("#xo_security_rest_disable input.namespace"); |
| 16 |
field_comment_spam = $("#field_comment_spam"), |
| 17 |
field_comment_spam_message = $("#field_comment_spam_message"), |
| 18 |
|
| 19 |
login_interval_change = function () { |
| 20 |
if ("0" === field_login_interval.val()) { |
| 21 |
$("#field_limit_count").attr("disabled", "disabled"); |
| 22 |
} else { |
| 23 |
$("#field_limit_count").prop("disabled", false); |
| 24 |
} |
| 25 |
}, |
| 26 |
|
| 27 |
login_page_change = function () { |
| 28 |
if (field_login_page.prop("checked")) { |
| 29 |
field_login_page_name.prop("disabled", false); |
| 30 |
} else { |
| 31 |
field_login_page_name.attr("disabled", "disabled"); |
| 32 |
} |
| 33 |
login_url_update(); |
| 34 |
}, |
| 35 |
|
| 36 |
login_url_update = function () { |
| 37 |
if (field_login_page.prop("checked")) { |
| 38 |
var login_url = field_login_page_name.val(); |
| 39 |
if (login_url !== '') { |
| 40 |
login_url = login_url.toLowerCase().replace(/[^\w-]/g, ""); |
| 41 |
field_login_page_name.val(login_url); |
| 42 |
$("#login_url").text(xoSecurityAdminOptions.site_url + login_url + ".php"); |
| 43 |
} else { |
| 44 |
$("#login_url").text(""); |
| 45 |
} |
| 46 |
} else { |
| 47 |
$("#login_url").text(xoSecurityAdminOptions.site_url + "wp-login.php"); |
| 48 |
} |
| 49 |
}, |
| 50 |
|
| 51 |
login_two_factor_change = function () { |
| 52 |
if (field_login_two_factor.prop("checked")) { |
| 53 |
field_login_two_factor_roles.prop("readonly", false); |
| 54 |
} else { |
| 55 |
field_login_two_factor_roles.attr("readonly", "disabled"); |
| 56 |
} |
| 57 |
}, |
| 58 |
|
| 59 |
login_alert_change = function () { |
| 60 |
if (field_login_alert.prop("checked")) { |
| 61 |
field_login_alert_subject.prop("readonly", false); |
| 62 |
field_login_alert_body.prop("readonly", false); |
| 63 |
field_login_alert_admin_only.prop("readonly", false); |
| 64 |
} else { |
| 65 |
field_login_alert_subject.attr("readonly", "disabled"); |
| 66 |
field_login_alert_body.attr("readonly", "disabled"); |
| 67 |
field_login_alert_admin_only.attr("readonly", "disabled"); |
| 68 |
} |
| 69 |
}, |
| 70 |
|
| 71 |
rest_change = function () { |
| 72 |
if (field_rest.prop("checked")) { |
| 73 |
$("#xo_security_rest_disable input").prop("disabled", false); |
| 74 |
} else { |
| 75 |
$("#xo_security_rest_disable input").prop("disabled", true); |
| 76 |
} |
| 77 |
}, |
| 78 |
|
| 79 |
rest_namespace_change = function () { |
| 80 |
console.log(this); |
| 81 |
var namespace = $(this).val(); |
| 82 |
console.log(namespace); |
| 83 |
if ($(this).prop("checked")) { |
| 84 |
$("input[data-namespace='" + namespace + "']").prop('checked', true); |
| 85 |
} else { |
| 86 |
$("input[data-namespace='" + namespace + "']").prop('checked', false); |
| 87 |
} |
| 88 |
}, |
| 89 |
|
| 90 |
comment_spam_change = function () { |
| 91 |
if (field_comment_spam.prop("checked")) { |
| 92 |
field_comment_spam_message.prop("readonly", false); |
| 93 |
} else { |
| 94 |
field_comment_spam_message.attr("readonly", "disabled"); |
| 95 |
} |
| 96 |
}; |
| 97 |
|
| 98 |
field_login_interval.on('change', login_interval_change); |
| 99 |
field_login_page.on('change', login_page_change); |
| 100 |
field_login_page_name.on('change', login_url_update); |
| 101 |
field_login_two_factor.on('change', login_two_factor_change); |
| 102 |
field_login_alert.on('change', login_alert_change); |
| 103 |
field_rest.on('change', rest_change); |
| 104 |
field_rest_namespace.on('change', rest_namespace_change); |
| 105 |
field_comment_spam.on('change', comment_spam_change); |
| 106 |
|
| 107 |
login_interval_change(); |
| 108 |
login_page_change(); |
| 109 |
login_two_factor_change(); |
| 110 |
login_alert_change(); |
| 111 |
rest_change(); |
| 112 |
comment_spam_change(); |
| 113 |
}; |
| 114 |
|
| 115 |
var xoSecurityCaptchaTypeSettings = function () { |
| 116 |
var $captchatypepicker = $('#captcha-type-picker'); |
| 117 |
|
| 118 |
$captchatypepicker.on( 'click.captchatypepicker', '.captcha-type-option', function() { |
| 119 |
var $this = $(this); |
| 120 |
if ( $this.hasClass( 'selected' ) ) { |
| 121 |
return; |
| 122 |
} |
| 123 |
$this.siblings( '.selected' ).removeClass( 'selected' ); |
| 124 |
$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true ); |
| 125 |
}); |
| 126 |
}; |
| 127 |
|
| 128 |
var xoSecurityDashboard = function () { |
| 129 |
var target = $('#xo_security_dashboard_login_widget .inside'); |
| 130 |
if ( target.length ) { |
| 131 |
$.ajax({ |
| 132 |
type: 'POST', |
| 133 |
url: ajaxurl, |
| 134 |
data: { action: 'xo_security_dashboard', nonce: xoSecurityAdminOptions.nonce }, |
| 135 |
}) |
| 136 |
.done(function (response) { |
| 137 |
if ( response.success ) { |
| 138 |
target.html(response.data); |
| 139 |
} else { |
| 140 |
target.html(''); |
| 141 |
} |
| 142 |
}); |
| 143 |
} |
| 144 |
}; |
| 145 |
|
| 146 |
$(document).ready(function () { |
| 147 |
if ('settings_page_xo-security-settings' === pagenow) { |
| 148 |
xoSecuritySettings(); |
| 149 |
xoSecurityCaptchaTypeSettings(); |
| 150 |
} else if ('dashboard' === pagenow) { |
| 151 |
xoSecurityDashboard(); |
| 152 |
} |
| 153 |
}); |
| 154 |
}(jQuery)); |
| 155 |
|