PluginProbe
WebTotem Security / 3.0.1
WebTotem Security v3.0.1
3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 2.2.4 All 109 releases
wt-security / includes / js / main.js

main.js in WebTotem Security 3.0.1, at includes/js/main.js

322 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 jQuery(document).ready(function ($) {
3
4 $('#wtotem-dos').on('change', function () {
5 let checked = $(this).prop('checked');
6 toggleLimits($('#wtotem-dos-limit'), $('#wtotem-dos-limit input'), checked);
7 });
8
9 $('#wtotem-login-attempts').on('change', function () {
10 let checked = $(this).prop('checked');
11 toggleLimits($('#wtotem-login-attempts-limit'), $('#wtotem-login-attempts-limit input'), checked);
12 });
13
14 function toggleLimits(limitWrap, limitInput, checked) {
15 (checked) ? limitWrap.removeClass('visually-hidden') : limitWrap.addClass('visually-hidden');
16 (checked) ? limitInput.removeAttr('disabled') : limitInput.attr('disabled', 'disabled');
17 }
18
19 $('body').on('click', 'ul.wtotem-tabs__caption li:not(.active)', function () {
20 $(this)
21 .addClass('active').siblings().removeClass('active')
22 .closest('div.wtotem-tabs').find('div.wtotem-tabs__content').removeClass('active').eq($(this).index()).addClass('active');
23 });
24
25 $('body').on('click', '#wtotem_ps_settings, .port-scanner-ports .port__result-list-item', function () {
26 $('.popup-overlay').removeClass('d-none');
27 $('body').addClass('lock');
28 }).on('click', '.port-scanner-list__header--close, .antivirus-log__close', function (e) {
29 $('.popup-overlay').addClass('d-none');
30 $('body').removeClass('lock');
31 }).on('click', '.popup-overlay', function (e) {
32 if (e.target.className.includes('popup-overlay')) {
33 $('.popup-overlay').addClass('d-none');
34 $('body').removeClass('lock');
35 }
36 }).on('click', '.firewall-configuration__multi-adding', function () {
37 let list = $(this).attr('data-list');
38 $('#wtotem-ip-list-type').val(list);
39 $('.firewall-multi-adding__close').attr('data-list', list);
40 if(list === 'white'){
41 AmplitudeAnalytics.addWhiteIpList();
42 } else {
43 AmplitudeAnalytics.addBlackIpList();
44 }
45 }).on('click', '.firewall-multi-adding__close', function () {
46 if($(this).attr('data-list') === "white"){
47 AmplitudeAnalytics.closeWhiteIp();
48 } else{
49 AmplitudeAnalytics.closeBlackIp();
50 }
51 }).on('click', '.wtotem_reports-accordion__title', function () {
52 $(this).next('div').toggleClass('visually-hidden')
53 }).on('click', '.wtotem_alert__close', function () {
54 $(this).parent('.wtotem_alert').remove();
55 }).on('hover', '.wtotem_title-info__info', function () {
56 let service = $(this).attr('data-service');
57 if(service) {
58 AmplitudeAnalytics.showTooltip(service);
59 }
60 }).on('click', '.wtotem_calendar_from', function () {
61 AmplitudeAnalytics.selectGraphStartDay($(this).attr('data-service'));
62 }).on('click', '.wtotem_calendar_to', function () {
63 AmplitudeAnalytics.selectGraphEndDay($(this).attr('data-service'));
64 }).on('click', '.open_support_dialog', function () {
65 AmplitudeAnalytics.openSupportDialog($(this).attr('data-service'));
66 });
67
68
69 // Pop-up notification options.
70 toastr.options = {
71 "closeButton": true,
72 "debug": false,
73 "newestOnTop": false,
74 "progressBar": true,
75 "positionClass": "toast-top-right",
76 "preventDuplicates": false,
77 "onclick": null,
78 "showDuration": "300",
79 "hideDuration": "5000",
80 "timeOut": "5000",
81 "extendedTimeOut": "1000",
82 "showEasing": "swing",
83 "hideEasing": "linear",
84 "showMethod": "fadeIn",
85 "hideMethod": "fadeOut"
86 }
87
88 });
89
90 function treatAsUTC(date) {
91 const month = {
92 Jan: "Янв",
93 Feb: "Фев",
94 Mar: "Мар",
95 Apr: "Апр",
96 May: "Май",
97 Jun: "Июн",
98 Jul: "Июл",
99 Aug: "Авг",
100 Sep: "Сен",
101 Oct: "Окт",
102 Nov: "Ноя",
103 Dec: "Дек",
104 };
105
106 for (var key in month) {
107 var value = month[key];
108 if(date.includes(value)){
109 date = date.replace(value, key)
110 }
111 }
112
113 var result = new Date(date);
114
115 result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
116 return result;
117 }
118
119 function daysBetween(startDate, endDate) {
120 var millisecondsPerDay = 24 * 60 * 60 * 1000;
121 return (treatAsUTC(endDate) - treatAsUTC(startDate)) / millisecondsPerDay;
122 }
123
124 // Hamburger menu.
125 const burgerEl = document.querySelector(".wtotem_burger");
126 const menuEl = document.querySelector(".wtotem_nav");
127 const bodyEl = document.getElementsByTagName("body")[0];
128
129 if (burgerEl) {
130 burgerEl.addEventListener("click", () => {
131 burgerEl.classList.toggle("active");
132 menuEl.classList.toggle("active");
133 // Adds body overflow hidden when the menu is open.
134 bodyEl.classList.toggle("lock");
135 });
136 }
137
138 // Report generate Modal.
139 const reportsBtn = document.querySelectorAll(".add_report");
140 const reportsModal = document.querySelector(".wtotem_reports-modal");
141 const reportsModalClose = document.querySelector(".wtotem_reports-modal__close");
142 const reportsModalMessage = document.querySelector("#wtotem_reports_form-messages");
143
144 if (reportsBtn) {
145 for (let elem of reportsBtn) {
146 elem.addEventListener("click", () => {
147 reportsModal.classList.add("wtotem_reports-modal--active");
148 bodyEl.classList.add("lock");
149 });
150 }
151 }
152
153 if (reportsModalClose) {
154 reportsModalClose.addEventListener("click", () => {
155 reportsModal.classList.remove("wtotem_reports-modal--active");
156 bodyEl.classList.remove("lock");
157 reportsModalMessage.innerHTML = '';
158 });
159 }
160
161
162 const addSideModal = (modal, openButton, closeButton, form) => {
163
164 const overlay = document.querySelector(".side-modal__overlay");
165 const message = document.querySelector(".wtotem_input__messages");
166 const bodyEl = document.getElementsByTagName("body")[0];
167 const toggleClassName = "side-modal--opened";
168 const toggleBody = "lock";
169
170 const showModal = () => {
171 modal.classList.add(toggleClassName);
172 bodyEl.classList.add(toggleBody);
173 };
174
175 const closeModal = () => {
176 modal.classList.remove(toggleClassName);
177 bodyEl.classList.remove(toggleBody);
178 if (form) {
179 form.reset();
180 message.innerHTML = '';
181 }
182 };
183
184 openButton.addEventListener("click", showModal);
185 closeButton.addEventListener("click", closeModal);
186 overlay.addEventListener("click", closeModal);
187 };
188
189 (function () {
190 const modal = document.querySelector(".firewall-multi-adding");
191 const openButton = document.querySelector(".firewall-configuration__multi-adding");
192 const openButton2 = document.querySelector(".multi-adding-deny_list");
193 const closeButton = document.querySelector(".firewall-multi-adding__close");
194 const form = document.querySelector("#wtotem-allow-deny-multi-add-form");
195
196 if (modal) {
197 addSideModal(modal, openButton, closeButton, form);
198 addSideModal(modal, openButton2, closeButton, form);
199 }
200 })();
201
202 (function () {
203 const modal = document.querySelector(".country-blocking-modal");
204 const openButton = document.querySelector("#block_countries_btn");
205 const closeButton = document.querySelector(".country-blocking-modal__closeBtn");
206
207 if (modal) {
208 addSideModal(modal, openButton, closeButton, false);
209 }
210 })();
211
212 window.addEventListener('DOMContentLoaded', function () {
213
214 function tlite(t) {
215 document.addEventListener("mouseover", function (e) {
216 var i = e.target, n = t(i);
217 n || (n = (i = i.parentElement) && t(i)), n && tlite.show(i, n, !0)
218 })
219 }
220
221 tlite.show = function (t, e, i) {
222 var n = "data-tlite";
223 e = e || {}, (t.tooltip || function (t, e) {
224 function o() {
225 tlite.hide(t, !0)
226 }
227
228 function l() {
229 r || (r = function (t, e, i) {
230 function n() {
231 o.className = "tlite tlite-" + r + s;
232 var e = t.offsetTop, i = t.offsetLeft;
233 o.offsetParent === t && (e = i = 0);
234 var n = t.offsetWidth, l = t.offsetHeight, d = o.offsetHeight, f = o.offsetWidth, a = i + n / 2;
235 o.style.top = ("s" === r ? e - d - 10 : "n" === r ? e + l + 10 : e + l / 2 - d / 2) + "px", o.style.left = ("w" === s ? i : "e" === s ? i + n - f : "w" === r ? i + n + 10 : "e" === r ? i - f - 10 : a - f / 2) + "px"
236 }
237
238 var o = document.createElement("span"), l = i.grav || t.getAttribute("data-tlite") || "n";
239 o.innerHTML = e, t.appendChild(o);
240 var r = l[0] || "", s = l[1] || "";
241 n();
242 var d = o.getBoundingClientRect();
243 return "s" === r && d.top < 0 ? (r = "n", n()) : "n" === r && d.bottom > window.innerHeight ? (r = "s", n()) : "e" === r && d.left < 0 ? (r = "w", n()) : "w" === r && d.right > window.innerWidth && (r = "e", n()), o.className += " tlite-visible", o
244 }(t, d, e))
245 }
246
247 var r, s, d;
248 return t.addEventListener("mousedown", o), t.addEventListener("mouseleave", o), t.tooltip = {
249 show: function () {
250 d = t.title || t.getAttribute(n) || d, t.title = "", t.setAttribute(n, ""), d && !s && (s = setTimeout(l, i ? 150 : 1))
251 }, hide: function (t) {
252 if (i === t) {
253 s = clearTimeout(s);
254 var e = r && r.parentNode;
255 e && e.removeChild(r), r = void 0
256 }
257 }
258 }
259 }(t, e)).show()
260 }, tlite.hide = function (t, e) {
261 t.tooltip && t.tooltip.hide(e)
262 }, "undefined" != typeof module && module.exports && (module.exports = tlite);
263
264 // init tooltip with class js--tooltip
265 tlite(el => {
266 return {
267 el: el.classList.contains('js--tooltip'), grav: 'sw',
268 }
269 });
270
271 });
272
273 /**
274 * Calendar init
275 *
276 * @param element
277 * Input selector element with the start date of the period.
278 * @param dateFromSelector
279 * Input selector with the start date of the period.
280 * @param dateToSelector
281 * Input selector with the end date of the period.
282 * @param toggler
283 * Selector element of the wrapper of the elements that open the calendar when clicked.
284 * @param site_created_at
285 * @param period
286 * @returns {*}
287 * @private
288 */
289 const setFlatpickr_ = (element, dateFromSelector, dateToSelector, toggler, period = null) => {
290 let site_created_at = document.getElementById('wtotem_site_created_at');
291 let date_site_created_at = site_created_at.getAttribute('data-value');
292
293 const calendar = flatpickr(element,
294 {
295 mode: "range",
296 minDate: date_site_created_at ?? "today",
297 maxDate: "today",
298 onChange: function (selectedDates) {
299 // debugger;
300 const dates = selectedDates.map(date => this.formatDate(date, "j M, Y"));
301 document.querySelector(dateFromSelector).value = dates[0];
302 if (dates[1]) {
303 document.querySelector(dateToSelector).value = dates[1];
304 }
305 }
306 });
307
308 toggler.addEventListener("click", calendar.open);
309
310 if(period){
311 calendar.setDate(period, true);
312 }
313
314 return calendar;
315 };
316
317 /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
318 var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,i=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/constructor/i.test(e.HTMLElement),f=/CriOS\/[\d]+/.test(navigator.userAgent),u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},d="application/octet-stream",s=1e3*40,c=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,s)},l=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(i){u(i)}}}},p=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob([String.fromCharCode(65279),e],{type:e.type})}return e},v=function(t,u,s){if(!s){t=p(t)}var v=this,w=t.type,m=w===d,y,h=function(){l(v,"writestart progress write writeend".split(" "))},S=function(){if((f||m&&a)&&e.FileReader){var r=new FileReader;r.onloadend=function(){var t=f?r.result:r.result.replace(/^data:[^;]*;/,"data:attachment/file;");var n=e.open(t,"_blank");if(!n)e.location.href=t;t=undefined;v.readyState=v.DONE;h()};r.readAsDataURL(t);v.readyState=v.INIT;return}if(!y){y=n().createObjectURL(t)}if(m){e.location.href=y}else{var o=e.open(y,"_blank");if(!o){e.location.href=y}}v.readyState=v.DONE;h();c(y)};v.readyState=v.INIT;if(o){y=n().createObjectURL(t);setTimeout(function(){r.href=y;r.download=u;i(r);h();c(y);v.readyState=v.DONE});return}S()},w=v.prototype,m=function(e,t,n){return new v(e,t||e.name||"download",n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){t=t||e.name||"download";if(!n){e=p(e)}return navigator.msSaveOrOpenBlob(e,t)}}w.abort=function(){};w.readyState=w.INIT=0;w.WRITING=1;w.DONE=2;w.error=w.onwritestart=w.onprogress=w.onwrite=w.onabort=w.onerror=w.onwriteend=null;return m}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!==null){define([],function(){return saveAs})}
319
320 !function(t){"use strict";if(t.URL=t.URL||t.webkitURL,t.Blob&&t.URL)try{return void new Blob}catch(e){}var n=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||function(t){var e=function(t){return Object.prototype.toString.call(t).match(/^\[object\s(.*)\]$/)[1]},n=function(){this.data=[]},o=function(t,e,n){this.data=t,this.size=t.length,this.type=e,this.encoding=n},i=n.prototype,a=o.prototype,r=t.FileReaderSync,c=function(t){this.code=this[this.name=t]},l="NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR".split(" "),s=l.length,u=t.URL||t.webkitURL||t,d=u.createObjectURL,f=u.revokeObjectURL,R=u,p=t.btoa,h=t.atob,b=t.ArrayBuffer,g=t.Uint8Array,w=/^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/;for(o.fake=a.fake=!0;s--;)c.prototype[l[s]]=s+1;return u.createObjectURL||(R=t.URL=function(t){var e,n=document.createElementNS("http://www.w3.org/1999/xhtml","a");return n.href=t,"origin"in n||("data:"===n.protocol.toLowerCase()?n.origin=null:(e=t.match(w),n.origin=e&&e[1])),n}),R.createObjectURL=function(t){var e,n=t.type;return null===n&&(n="application/octet-stream"),t instanceof o?(e="data:"+n,"base64"===t.encoding?e+";base64,"+t.data:"URI"===t.encoding?e+","+decodeURIComponent(t.data):p?e+";base64,"+p(t.data):e+","+encodeURIComponent(t.data)):d?d.call(u,t):void 0},R.revokeObjectURL=function(t){"data:"!==t.substring(0,5)&&f&&f.call(u,t)},i.append=function(t){var n=this.data;if(g&&(t instanceof b||t instanceof g)){for(var i="",a=new g(t),l=0,s=a.length;s>l;l++)i+=String.fromCharCode(a[l]);n.push(i)}else if("Blob"===e(t)||"File"===e(t)){if(!r)throw new c("NOT_READABLE_ERR");var u=new r;n.push(u.readAsBinaryString(t))}else t instanceof o?"base64"===t.encoding&&h?n.push(h(t.data)):"URI"===t.encoding?n.push(decodeURIComponent(t.data)):"raw"===t.encoding&&n.push(t.data):("string"!=typeof t&&(t+=""),n.push(unescape(encodeURIComponent(t))))},i.getBlob=function(t){return arguments.length||(t=null),new o(this.data.join(""),t,"raw")},i.toString=function(){return"[object BlobBuilder]"},a.slice=function(t,e,n){var i=arguments.length;return 3>i&&(n=null),new o(this.data.slice(t,i>1?e:this.data.length),n,this.encoding)},a.toString=function(){return"[object Blob]"},a.close=function(){this.size=0,delete this.data},n}(t);t.Blob=function(t,e){var o=e?e.type||"":"",i=new n;if(t)for(var a=0,r=t.length;r>a;a++)Uint8Array&&t[a]instanceof Uint8Array?i.append(t[a].buffer):i.append(t[a]);var c=i.getBlob(o);return!c.slice&&c.webkitSlice&&(c.slice=c.webkitSlice),c};var o=Object.getPrototypeOf||function(t){return t.__proto__};t.Blob.prototype=o(new t.Blob)}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this);
321
322