| 1 |
jQuery(document).ready(function ($) { |
| 2 |
|
| 3 |
$('body').on('click','#waf_load_more', function (e) { |
| 4 |
e.preventDefault(); |
| 5 |
lazy_ajax('ajax_firewall',$(this)); |
| 6 |
}) |
| 7 |
.on('click','#av_load_more', function (e) { |
| 8 |
e.preventDefault(); |
| 9 |
lazy_ajax('ajax_antivirus',$(this)); |
| 10 |
}) |
| 11 |
.on('click','#reports_load_more', function (e) { |
| 12 |
e.preventDefault(); |
| 13 |
lazy_reports('ajax_reports', 'wtotem_data_box'); |
| 14 |
}) |
| 15 |
.on('click','#reports_load_more__mobile', function (e) { |
| 16 |
e.preventDefault(); |
| 17 |
lazy_reports('ajax_reports', 'wtotem_data_box_mobile', 'mobile'); |
| 18 |
}) |
| 19 |
.on('click', '.wtotem_reports-accordion__title', function () { |
| 20 |
$( this ).next('div').toggleClass( 'visually-hidden' ) |
| 21 |
}); |
| 22 |
|
| 23 |
$('#waf_period_filter').on('input', function (e) { |
| 24 |
var $period = $(this).val(); |
| 25 |
period_filter('ajax_firewall',$period) |
| 26 |
}); |
| 27 |
|
| 28 |
$('#av_period_filter').on('input', function (e) { |
| 29 |
var $period = $(this).val(); |
| 30 |
period_filter('ajax_antivirus',$period) |
| 31 |
}); |
| 32 |
|
| 33 |
|
| 34 |
$('#color_scheme_toggle input').on('click', function (e) { |
| 35 |
|
| 36 |
let $checked = $(this).prop("checked"); |
| 37 |
|
| 38 |
jQuery.post( |
| 39 |
ajaxurl, |
| 40 |
{ |
| 41 |
action: 'color_scheme_toggle', |
| 42 |
checked: Number($checked), |
| 43 |
}, |
| 44 |
function (response) { |
| 45 |
if(response == 'dark'){ |
| 46 |
$('body').addClass('wtotem_theme—dark'); |
| 47 |
} else{ |
| 48 |
$('body').removeClass('wtotem_theme—dark'); |
| 49 |
} |
| 50 |
}); |
| 51 |
}); |
| 52 |
|
| 53 |
$('body').on('click','.move_to_quarantine', function (e) { |
| 54 |
$('.wt-loader').removeClass('d-none'); |
| 55 |
let $path = $(this).attr('data-path'); |
| 56 |
jQuery.post( |
| 57 |
ajaxurl, |
| 58 |
{ |
| 59 |
action: 'move_to_quarantine', |
| 60 |
path: $path, |
| 61 |
}, |
| 62 |
function (response) { |
| 63 |
if(response != 'false'){ |
| 64 |
$('.wtotem_body') |
| 65 |
.html(response); |
| 66 |
} |
| 67 |
|
| 68 |
$('.wt-loader').addClass('d-none'); |
| 69 |
}); |
| 70 |
}); |
| 71 |
|
| 72 |
$('body').on('click','.move_from_quarantine', function (e) { |
| 73 |
$('.wt-loader').removeClass('d-none'); |
| 74 |
let $id = $(this).attr('data-id'); |
| 75 |
jQuery.post( |
| 76 |
ajaxurl, |
| 77 |
{ |
| 78 |
action: 'move_from_quarantine', |
| 79 |
id: $id, |
| 80 |
}, |
| 81 |
function (response) { |
| 82 |
if(response != 'false'){ |
| 83 |
$('.wtotem_body') |
| 84 |
.html(response); |
| 85 |
} |
| 86 |
$('.wt-loader').addClass('d-none'); |
| 87 |
}); |
| 88 |
}); |
| 89 |
|
| 90 |
|
| 91 |
$('.settings_toggle').on('click', function (e) { |
| 92 |
|
| 93 |
let $checked = $(this).prop("checked"); |
| 94 |
let $checkBox = $(this); |
| 95 |
e.preventDefault(); |
| 96 |
|
| 97 |
jQuery.post( |
| 98 |
ajaxurl, |
| 99 |
{ |
| 100 |
action: 'settings', |
| 101 |
checked: Number($checked), |
| 102 |
}, |
| 103 |
function (response) { |
| 104 |
if(response == 1){ |
| 105 |
$checkBox.prop('checked', true); |
| 106 |
} else{ |
| 107 |
$checkBox.prop('checked', false); |
| 108 |
} |
| 109 |
}); |
| 110 |
}); |
| 111 |
|
| 112 |
$('.report_link').on('click', function (e) { |
| 113 |
|
| 114 |
let $id = $(this).attr('data-id'); |
| 115 |
e.preventDefault(); |
| 116 |
|
| 117 |
jQuery.post( |
| 118 |
ajaxurl, |
| 119 |
{ |
| 120 |
action: 'report_link', |
| 121 |
id: $id, |
| 122 |
}, |
| 123 |
function (response) { |
| 124 |
let data = response; |
| 125 |
console.log(data); |
| 126 |
|
| 127 |
if(data){ |
| 128 |
window.open(data, '_blank'); |
| 129 |
} |
| 130 |
}); |
| 131 |
|
| 132 |
}); |
| 133 |
|
| 134 |
$('#report_form').on('submit', function (e) { |
| 135 |
$('.wt-spinner').removeClass('d-none'); |
| 136 |
let formdata = $('#report_form').serialize(); |
| 137 |
e.preventDefault(); |
| 138 |
|
| 139 |
jQuery.post( |
| 140 |
ajaxurl, |
| 141 |
formdata, |
| 142 |
function (response) { |
| 143 |
let data = response; |
| 144 |
|
| 145 |
if(data && data != 'false'){ |
| 146 |
$('.wt-spinner').addClass('d-none'); |
| 147 |
window.open(data); |
| 148 |
location.reload(); |
| 149 |
} |
| 150 |
}); |
| 151 |
}); |
| 152 |
|
| 153 |
$('.config_toggle').on('click', function (e) { |
| 154 |
let $id = $(this).val(); |
| 155 |
let $checkBox = $(this); |
| 156 |
e.preventDefault(); |
| 157 |
jQuery.post( |
| 158 |
ajaxurl, |
| 159 |
{ |
| 160 |
action: 'configs_toggle', |
| 161 |
service: $id, |
| 162 |
}, |
| 163 |
function (response) { |
| 164 |
let data = $.parseJSON(response); |
| 165 |
if(data){ |
| 166 |
|
| 167 |
if(data.isActive === true){ |
| 168 |
$checkBox.prop('checked', true); |
| 169 |
} |
| 170 |
else if(data.isActive === false) { |
| 171 |
$checkBox.prop('checked', false); |
| 172 |
} |
| 173 |
} |
| 174 |
}); |
| 175 |
}); |
| 176 |
|
| 177 |
$('#chart_btn div').click( function (e) { |
| 178 |
var $mainBox = $('#chart_wrap'); |
| 179 |
var $btn = $(this); |
| 180 |
var $days = $btn.data('days'); |
| 181 |
|
| 182 |
$mainBox.animate({opacity: 0.5}, 300); |
| 183 |
|
| 184 |
jQuery.post( |
| 185 |
ajaxurl, |
| 186 |
{ |
| 187 |
action: 'chart_filter', |
| 188 |
days: $days, |
| 189 |
}, |
| 190 |
function (response) { |
| 191 |
$('#chart_btn div').removeClass('wtotem_chart-first__btn_active'); |
| 192 |
$btn.addClass('wtotem_chart-first__btn_active'); |
| 193 |
|
| 194 |
$mainBox |
| 195 |
.html(response) |
| 196 |
.animate({opacity: 1}, 300); |
| 197 |
}); |
| 198 |
}); |
| 199 |
|
| 200 |
$('#map_btn div').click( function (e) { |
| 201 |
var $mainBox = $('#wtotem_map_box'); |
| 202 |
var $btn = $(this); |
| 203 |
var $days = $btn.data('days'); |
| 204 |
|
| 205 |
$mainBox.animate({opacity: 0.5}, 300); |
| 206 |
|
| 207 |
jQuery.post( |
| 208 |
ajaxurl, |
| 209 |
{ |
| 210 |
action: 'map_filter', |
| 211 |
days: $days, |
| 212 |
}, |
| 213 |
function (response) { |
| 214 |
$('#map_btn div').removeClass('wtotem_chart-first__btn_active'); |
| 215 |
$btn.addClass('wtotem_chart-first__btn_active'); |
| 216 |
|
| 217 |
$mainBox |
| 218 |
.html(response) |
| 219 |
.animate({opacity: 1}, 300); |
| 220 |
attacksMap(); |
| 221 |
}); |
| 222 |
}); |
| 223 |
|
| 224 |
$('body').on('click','#wtotem_av_state_filter', function (e) { |
| 225 |
var $period = $('#av_period_filter').val(); |
| 226 |
$period = $period.split(' to '); |
| 227 |
$period = ($period[0]) ? $period : null; |
| 228 |
|
| 229 |
var $mainBox = $('#wtotem_data_box'); |
| 230 |
$mainBox.animate({opacity: 0.5}, 300); |
| 231 |
|
| 232 |
jQuery.post( |
| 233 |
ajaxurl, |
| 234 |
{ |
| 235 |
action: 'ajax_antivirus', |
| 236 |
event: $(this).val(), |
| 237 |
period: $period, |
| 238 |
|
| 239 |
}, |
| 240 |
function (response) { |
| 241 |
$mainBox |
| 242 |
.html(response) |
| 243 |
.animate({opacity: 1}, 300); |
| 244 |
}); |
| 245 |
}); |
| 246 |
|
| 247 |
|
| 248 |
function lazy_ajax(actionName, btnMore ) { |
| 249 |
var $period = $('.flatpickr-input').val(); |
| 250 |
$period = $period.split(' to '); |
| 251 |
$period = ($period[0]) ? $period : null; |
| 252 |
|
| 253 |
var $mainBox = $('#wtotem_data_box'); |
| 254 |
$mainBox.animate({opacity: 0.5}, 300); |
| 255 |
|
| 256 |
jQuery.post( |
| 257 |
ajaxurl, |
| 258 |
{ |
| 259 |
action: actionName, |
| 260 |
period: $period, |
| 261 |
}, |
| 262 |
function (response) { |
| 263 |
$('#waf_load_more, #av_load_more').remove(); |
| 264 |
$mainBox |
| 265 |
.append(response) |
| 266 |
.animate({opacity: 1}, 300); |
| 267 |
}); |
| 268 |
} |
| 269 |
|
| 270 |
function lazy_reports(actionName, mainBox, type = '') { |
| 271 |
|
| 272 |
let $mainBox = $('#' + mainBox); |
| 273 |
$mainBox.animate({opacity: 0.5}, 300); |
| 274 |
|
| 275 |
jQuery.post( |
| 276 |
ajaxurl, |
| 277 |
{ |
| 278 |
action: actionName, |
| 279 |
type: type, |
| 280 |
}, |
| 281 |
function (response) { |
| 282 |
$('#reports_load_more, #reports_load_more__mobile').remove(); |
| 283 |
$mainBox |
| 284 |
.append(response) |
| 285 |
.animate({opacity: 1}, 300); |
| 286 |
}); |
| 287 |
} |
| 288 |
|
| 289 |
// period filter |
| 290 |
function period_filter(actionName, $period ) { |
| 291 |
$period = $period.split(' to '); |
| 292 |
$period = ($period[0]) ? $period : null; |
| 293 |
|
| 294 |
var $mainBox = $('#wtotem_data_box'); |
| 295 |
$mainBox.animate({opacity: 0.5}, 300); |
| 296 |
|
| 297 |
jQuery.post( |
| 298 |
ajaxurl, |
| 299 |
{ |
| 300 |
action: actionName, |
| 301 |
filter: 'period_filter', |
| 302 |
period: $period, |
| 303 |
|
| 304 |
}, |
| 305 |
function (response) { |
| 306 |
$mainBox |
| 307 |
.html(response) |
| 308 |
.animate({opacity: 1}, 300); |
| 309 |
}); |
| 310 |
} |
| 311 |
|
| 312 |
}); |