PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.9
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.9
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / static / ninjafirewall.js
ninjafirewall / static Last commit date
chart.min.js 7 months ago index.html 7 years ago jquery.tipTip.js 4 years ago ninjafirewall.css 11 months ago ninjafirewall.js 1 month ago
ninjafirewall.js
987 lines
1 /*
2 +---------------------------------------------------------------------+
3 | NinjaFirewall (WP Edition) |
4 | |
5 | (c) NinTechNet - https://nintechnet.com/ |
6 +---------------------------------------------------------------------+
7 | This program is free software: you can redistribute it and/or |
8 | modify it under the terms of the GNU General Public License as |
9 | published by the Free Software Foundation, either version 3 of |
10 | the License, or (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 +---------------------------------------------------------------------+
17 */
18
19 // =====================================================================
20 // Generic.
21
22 // TipTip tooltip
23 jQuery( document ).ready(function( $ ) {
24 $( '.ninjafirewall-tip' ).tipTip( {
25 'attribute': 'data-tip',
26 'fadeIn': 50,
27 'fadeOut': 50,
28 'delay': 100,
29 'maxWidth' : '300px'
30 });
31 });
32
33
34 function nfwjs_switch_tabs( what, list ) {
35 // Active tab:
36 jQuery('#'+ what +'-options').show();
37 jQuery('#tab-'+ what).addClass('nav-tab-active');
38 jQuery('#tab-selected').val( what );
39 // Inactive tabs:
40 var tabs = list.split( ':' );
41 var list_length = tabs.length;
42 for ( var i = 0; i < list_length; i++ ) {
43 if ( tabs[i] != what ) {
44 jQuery('#'+ tabs[i] +'-options').hide();
45 jQuery('#tab-'+ tabs[i]).removeClass('nav-tab-active');
46 }
47 }
48 }
49
50 function nfwjs_up_down( id ) {
51 if ( jQuery('#'+ id).css('display') == 'none' ) {
52 jQuery('#'+ id).slideDown();
53 } else {
54 jQuery('#'+ id).slideUp();
55 }
56 }
57
58 function nfwjs_restore_default() {
59 if ( confirm( nfwi18n.restore_default ) ) {
60 return true;
61 }
62 return false;
63 }
64
65 // =====================================================================
66 // Overview page.
67
68 jQuery( document ).ready( function() {
69 // Full WAF activation thickbox
70 jQuery( '#nfw-activate-thickbox' ).click( function() {
71 var h = jQuery(window).height() - 100;
72 var w = jQuery(window).width() - 100;
73 tb_show( '', '#TB_inline?width='+ (w - 20) +
74 '&amp;height='+ (h - 20) +
75 '&amp;inlineId=nfw-activate-thickbox-content', null );
76 return false;
77 } );
78 // Full WAF configuration thickbox
79 jQuery( '#nfw-configure-thickbox' ).click( function() {
80 var h = jQuery(window).height() - 100;
81 var w = jQuery(window).width() - 100;
82 tb_show( '', '#TB_inline?width='+ (w - 20) +
83 '&amp;height='+ (h - 20) +
84 '&amp;inlineId=nfw-configure-thickbox-content', null );
85 return false;
86 } );
87 // Error log thickbox
88 jQuery( '#nfw-errorlog-thickbox' ).click( function() {
89 var h = jQuery(window).height() - 100;
90 var w = jQuery(window).width() - 100;
91 tb_show( '', '#TB_inline?width='+ (w - 20) +
92 '&amp;height='+ (h - 20) +
93 '&amp;inlineId=nfw-errorlog-thickbox-content', null );
94 return false;
95 } );
96 });
97
98 function nfwjs_httpserver( what ) {
99
100 if ( what == 6 ) {
101 // Openlitespeed only
102 jQuery('#diy-div').hide();
103
104 } else {
105 jQuery('#diy-div').show();
106 }
107
108 if ( what == 1 || what == 5 || what == 6 || what == 8 ) {
109 // No INI file
110 jQuery('#tr-ini-userini').hide();
111 jQuery('#tr-ini-phpini').hide();
112 jQuery('#tr-select-ini').hide();
113 jQuery('#tr-htaccess-suphp').hide();
114
115 if ( what == 1 ) {
116 // mod_php
117 jQuery('#tr-htaccess-litespeed').hide();
118 jQuery('#tr-htaccess-openlitespeed').hide();
119 jQuery('#tr-htaccess-apachelsapi').hide();
120 jQuery('#tr-htaccess-modphp').show();
121 } else if ( what == 5 ) {
122 // Litespeed
123 jQuery('#tr-htaccess-modphp').hide();
124 jQuery('#tr-htaccess-openlitespeed').hide();
125 jQuery('#tr-htaccess-apachelsapi').hide();
126 jQuery('#tr-htaccess-litespeed').show();
127 } else if ( what == 6 ) {
128 // Openlitespeed
129 jQuery('#tr-htaccess-modphp').hide();
130 jQuery('#tr-htaccess-litespeed').hide();
131 jQuery('#tr-htaccess-apachelsapi').hide();
132 jQuery('#tr-htaccess-openlitespeed').show();
133 jQuery('#nfwaf-step2').slideDown();
134 } else { // 8
135 // Apache + LSAPI
136 jQuery('#tr-htaccess-modphp').hide();
137 jQuery('#tr-htaccess-litespeed').hide();
138 jQuery('#tr-htaccess-apachelsapi').show();
139 jQuery('#tr-htaccess-openlitespeed').hide();
140 }
141
142 } else {
143 jQuery( '#tr-select-ini' ).show();
144
145 if ( what == 2 || what == 4 || what == 7 ) {
146 // No .htaccess file
147 jQuery('#tr-htaccess-modphp').hide();
148 jQuery('#tr-htaccess-litespeed').hide();
149 jQuery('#tr-htaccess-apachelsapi').hide();
150 jQuery('#tr-htaccess-suphp').hide();
151 jQuery('#tr-htaccess-openlitespeed').hide();
152
153 } else if ( what == 3 ) {
154 // ini + suPHP
155 jQuery('#tr-htaccess-litespeed').hide();
156 jQuery('#tr-htaccess-apachelsapi').hide();
157 jQuery('#tr-htaccess-modphp').hide();
158 jQuery('#tr-htaccess-openlitespeed').hide();
159 jQuery('#tr-htaccess-suphp').show();
160 }
161
162 // Which INI?
163 if ( jQuery('#ini-type-user').prop('checked') == true ) {
164 jQuery('#tr-ini-userini').show();
165 jQuery('#tr-ini-phpini').hide();
166 } else {
167 jQuery('#tr-ini-userini').hide();
168 jQuery('#tr-ini-phpini').show();
169 }
170 }
171
172 if ( jQuery('#diynfw').prop('checked') == true && what != 6 ) {
173 nfwjs_diy_chg( 'nfw' );
174
175 } else {
176 nfwjs_diy_chg( 'usr' );
177 }
178 }
179
180 function nfwjs_radio_ini( what ) {
181
182 if ( what == 1 ) { // .user.ini
183 jQuery('#tr-ini-userini').show();
184 jQuery('#tr-ini-phpini').hide();
185
186 } else { // php.ini
187 jQuery('#tr-ini-userini').hide();
188 jQuery('#tr-ini-phpini').show();
189 }
190 }
191
192 function nfwjs_fullwafconfig( what) {
193
194 // Security nonce
195 var nonce = jQuery('input[name=nfwnonce_fullwaf]').val();
196 if ( typeof nonce === 'undefined' || nonce == '' ) {
197 alert( nfwi18n.missing_nonce );
198 return false;
199 }
200
201 var data = {
202 'action': 'nfw_fullwafconfig',
203 'nonce': nonce
204 };
205
206 // Full WAF mode configuration
207 if ( what == 1 ) {
208 var exclude_waf_list = jQuery("input:checkbox[name='nfw_exclude_waf_list[]']:not(:checked)").map(function() {
209 return jQuery(this).val()
210 }).get();
211 data['list'] = JSON.stringify( exclude_waf_list );
212 data['what'] = 1;
213
214 // Downgrade to WP WAF mode
215 } else if ( what == 2 ) {
216 data['what'] = 2;
217
218 } else {
219 return false;
220 }
221
222 jQuery.ajax( {
223 type: "POST",
224 url: ajaxurl,
225 headers: {
226 'Accept-Language':'en-US,en;q=0.5'
227 },
228 data: data,
229 dataType: "text",
230 success: function( response ) {
231 if ( response == '200' ) {
232 window.location.href = window.location.href + '&nfwafconfig=1';
233 } else {
234 alert( response );
235 }
236 },
237 // Display non-200 HTTP response
238 error: function( xhr, status, err ) {
239 alert( nfwi18n.http_error +' "'+ xhr.status +' '+ err +'".' );
240 }
241 });
242 return false;
243 }
244
245 function nfwjs_fullwafsubmit() {
246
247 // Security nonce
248 var nonce = jQuery('input[name=nfwnonce_fullwaf]').val();
249 if ( typeof nonce === 'undefined' || nonce == '' ) {
250 alert( nfwi18n.missing_nonce );
251 return false;
252 }
253
254 var httpserver = jQuery('select[name=http_server]').val();
255 if ( httpserver == '' ) {
256 alert( nfwi18n.missing_httpserver );
257 return false;
258 }
259 var initype = jQuery('input[name=ini_type]:checked').val();
260 var diy = jQuery('input[name=diy-choice]:checked').val();
261 var sandbox = jQuery('input[name=enable_sandbox]:checked').val();
262 // Exclusion folders, if any
263 var exclude_waf_list = jQuery("input:checkbox[name='nfw_exclude_waf_list[]']:not(:checked)").map(function() {
264 return jQuery(this).val()
265 }).get();
266 exclude_waf_list_json = JSON.stringify( exclude_waf_list );
267
268 // Ajax
269 var data = {
270 'action': 'nfw_fullwafsetup',
271 'nonce': nonce,
272 'httpserver': httpserver,
273 'initype': initype,
274 'exclude_waf_list': exclude_waf_list_json,
275 'diy': diy,
276 'sandbox': sandbox
277 };
278 jQuery.ajax( {
279 type: "POST",
280 url: ajaxurl,
281 headers: {
282 'Accept-Language':'en-US,en;q=0.5'
283 },
284 data: data,
285 dataType: "text",
286 success: function( response ) {
287 if ( response == '200' ) {
288 window.location.href = window.location.href + '&fullwaf=1';
289 } else {
290 alert( response );
291 }
292 },
293 // Display non-200 HTTP response
294 error: function( xhr, status, err ) {
295 alert( nfwi18n.http_error +' "'+ xhr.status +' '+ err +'".' );
296 }
297 });
298 return false;
299 }
300
301 function nfwjs_diy_chg( what ) {
302 if ( what == 'nfw' ) {
303 jQuery('#diy-msg').slideUp();
304 jQuery('#nfwaf-step2').slideUp();
305 jQuery('#enable-sandbox').slideDown();
306 } else {
307 jQuery('#diy-msg').slideDown();
308 jQuery('#nfwaf-step2').slideDown();
309 jQuery('#enable-sandbox').slideUp();
310 }
311 }
312
313 var fullwaf_count;
314 var fullwaf;
315 function nfwjs_fullwaf_countdown() {
316
317 if ( fullwaf_count > 1 ) {
318 fullwaf_count--;
319 jQuery('#nfw-waf-count').html( fullwaf_count );
320
321 } else {
322 clearInterval( fullwaf );
323 location.reload();
324 }
325 }
326
327 function nfwjs_del_errorlog() {
328 if ( confirm( nfwi18n.del_errorlog ) ) {
329 return true;
330 }
331 return false;
332 }
333 // =====================================================================
334 // Statistics page.
335
336 function nfwjs_stat_redir(where) {
337 if (where == '') { return false;}
338 document.location.href='?page=NinjaFirewall&tab=statistics&statx='+ where;
339 }
340
341 // =====================================================================
342 // Firewall Options.
343
344 function nfwjs_default_msg() {
345 var msg = jQuery('#default-msg').val();
346 jQuery('#blocked-msg').val( msg );
347
348 }
349
350 var restoreconf = 0;
351
352 function nfwjs_select_backup( what ) {
353 if ( what == 0 ) {
354 restoreconf = 0;
355 } else {
356 restoreconf = 1;
357 }
358 }
359
360 function nfwjs_save_options() {
361 if ( restoreconf > 0 ) {
362 if ( confirm( nfwi18n.restore_warning ) ) {
363 return true;
364 }
365 return false;
366 }
367 return true;
368 }
369
370 // =====================================================================
371 // Firewall Policies.
372
373 function nfwjs_upload_onoff( id ) {
374 if ( id.value == 1 ) {
375 jQuery('#san').prop('disabled', false);
376 jQuery('#subs').prop('disabled', false);
377 } else {
378 jQuery('#san').prop('disabled', true);
379 jQuery('#subs').prop('disabled', true);
380 }
381 }
382
383 function nfwjs_sanitise( cbox ) {
384 if ( cbox.checked ) {
385 if ( confirm( nfwi18n.warn_sanitise) ) {
386 return true;
387 }
388 return false;
389 }
390 }
391
392 function nfwjs_no_xmlrpc( cbox ) {
393
394 if ( cbox.checked == true ) {
395 document.fwrules.elements['nfw_options[no_xmlrpc_multi]'].disabled = true;
396 document.fwrules.elements['nfw_options[no_xmlrpc_pingback]'].disabled = true;
397 } else {
398 document.fwrules.elements['nfw_options[no_xmlrpc_multi]'].disabled = false;
399 document.fwrules.elements['nfw_options[no_xmlrpc_pingback]'].disabled = false;
400 }
401 }
402
403 function nfwjs_no_restapi( cbox ) {
404 if ( cbox.checked == true ) {
405 document.fwrules.elements['nfw_options[restapi_loggedin]'].disabled = false;
406 } else {
407 document.fwrules.elements['nfw_options[restapi_loggedin]'].disabled = true;
408 }
409 }
410
411 function nfwjs_ssl_warn( item, is_ssl ) {
412 if ( is_ssl == true || item.checked == false ) {
413 return true;
414 }
415 if ( confirm( nfwi18n.ssl_warning ) ) {
416 return true;
417 }
418 return false;
419 }
420
421 function nfwjs_woowarning( cbox ) {
422 if ( cbox.checked ) {
423 if ( confirm( nfwi18n.woo_warning) ) {
424 return true;
425 }
426 return false;
427 }
428 }
429 function nfwjs_reguserwarning( cbox ) {
430 if ( cbox.checked ) {
431 if ( confirm( nfwi18n.reguser_warning) ) {
432 return true;
433 }
434 return false;
435 }
436 }
437 function nfwjs_regsitewarning( cbox ) {
438 if ( cbox.checked ) {
439 if ( confirm( nfwi18n.regsite_warning) ) {
440 return true;
441 }
442 return false;
443 }
444 }
445
446 function nfwjs_csp_onoff( id1, id2 ) {
447 if ( jQuery('#'+ id1).prop('checked') == true ) {
448 jQuery('#'+ id2).prop('readonly', false);
449 jQuery('#'+ id2).focus();
450 } else {
451 jQuery('#'+ id2).prop('readonly', true);
452 }
453 }
454
455 function nfwjs_referrer_onoff() {
456 if ( jQuery('#referrer_switch').prop('checked') == true ) {
457 jQuery('#rp_select').prop('disabled', false);
458 jQuery('#rp_select').focus();
459 } else {
460 jQuery('#rp_select').prop('disabled', true);
461 }
462 }
463
464 function nfwjs_test_headers( homepage ) {
465 // Bypass caching
466 homepage = homepage +'?'+ Date.now();
467
468 jQuery('#progress-gif').show();
469 jQuery.ajax( {
470 url: homepage,
471 method: 'HEAD'
472 } ).then( function( data, status, xhr ) {
473 jQuery('#progress-gif').hide();
474 alert( xhr.getAllResponseHeaders() );
475 });
476 }
477
478 // =====================================================================
479 // File Check.
480
481 function nfwjs_file_info(what, where) {
482 if ( what == '' ) { return false; }
483
484 // Because we use a "multiple" select for aesthetic purposes
485 // but don't want the user to select multiple files, we focus
486 // only on the currently selected one:
487 var current_item = jQuery('#select-'+ where ).prop('selectedIndex');
488 jQuery('#select-'+ where ).prop('selectedIndex',current_item);
489
490 // New file
491 if (where == 1) {
492 var nfo = what.split(':');
493 jQuery('#new_size').html( nfo[3] );
494 jQuery('#new_chmod').html( nfo[0] );
495 jQuery('#new_uidgid').html( nfo[1] + ' / ' + nfo[2] );
496 jQuery('#new_mtime').html( nfo[4].replace(/~/g, ':') );
497 jQuery('#new_ctime').html( nfo[5].replace(/~/g, ':') );
498 jQuery('#table_new').show();
499
500 // Modified file
501 } else if (where == 2) {
502 var all = what.split('::');
503 var nfo = all[0].split(':');
504 var nfo2 = all[1].split(':');
505 jQuery('#mod_size').html( nfo[3] );
506 if (nfo[3] != nfo2[3]) {
507 jQuery('#mod_size2').html( '<font color="red">'+ nfo2[3] +'</font>' );
508 } else {
509 jQuery('#mod_size2').html( nfo2[3] );
510 }
511 jQuery('#mod_chmod').html( nfo[0] );
512 if (nfo[0] != nfo2[0]) {
513 jQuery('#mod_chmod2').html( '<font color="red">'+ nfo2[0] +'</font>' );
514 } else {
515 jQuery('#mod_chmod2').html( nfo2[0] );
516 }
517 jQuery('#mod_uidgid').html( nfo[1] + ' / ' + nfo[2] );
518 if ( (nfo[1] != nfo2[1]) || (nfo[2] != nfo2[2]) ) {
519 jQuery('#mod_uidgid2').html( '<font color="red">'+ nfo2[1] + '/' + nfo2[2] +'</font>' );
520 } else {
521 jQuery('#mod_uidgid2').html( nfo2[1] + ' / ' + nfo2[2] );
522 }
523 jQuery('#mod_mtime').html( nfo[4].replace(/~/g, ':') );
524 if (nfo[4] != nfo2[4]) {
525 jQuery('#mod_mtime2').html( '<font color="red">'+ nfo2[4].replace(/~/g, ':') +'</font>' );
526 } else {
527 jQuery('#mod_mtime2').html( nfo2[4].replace(/~/g, ':') );
528 }
529 jQuery('#mod_ctime').html( nfo[5].replace(/~/g, ':') );
530 if (nfo[5] != nfo2[5]) {
531 jQuery('#mod_ctime2').html( '<font color="red">'+ nfo2[5].replace(/~/g, ':') +'</font>' );
532 } else {
533 jQuery('#mod_ctime2').html( nfo2[5].replace(/~/g, ':') );
534 }
535 jQuery('#table_mod').show();
536 }
537 }
538
539 function nfwjs_del_snapshot() {
540 if ( confirm( nfwi18n.del_snapshot ) ) {
541 return true;
542 }
543 return false;
544 }
545
546 function nfwjs_show_changes() {
547 jQuery('#changes_table').slideDown();
548 jQuery('#vcbtn').prop('disabled', true);
549 }
550
551 // =====================================================================
552 // Event Notifications.
553
554 function ac_radio_toogle( on_off, rbutton ) {
555 var what = "nfw_options["+rbutton+"]";
556 if ( on_off ) {
557 document.nfwalerts.elements[what].disabled = false;
558 document.nfwalerts.elements[what].focus();
559 } else {
560 document.nfwalerts.elements[what].disabled = true;
561 }
562 }
563
564
565 function nfwjs_upgrade_plugin( plugin, version, nonce ) {
566
567 if ( typeof plugin === 'undefined' || typeof version === 'undefined' ||
568 typeof nonce === 'undefined') {
569
570 alert( nfwi18n.missing_parameters );
571 return false;
572 }
573 nfwjs_upgrade_plugin_progress( 0 );
574
575 var data = {
576 'action': 'nfw_pluginupgrade',
577 'plugin': plugin,
578 'version': version,
579 'nonce': nonce
580 }
581
582 jQuery.ajax( {
583 type: 'POST',
584 url: ajaxurl,
585 data: data,
586 dataType: 'json',
587 success: function( response ) {
588
589 if (typeof response === 'undefined') {
590 alert( nfwi18n.unknown_error );
591 nfwjs_upgrade_plugin_progress( 1 );
592 return false;
593 }
594
595 if ( response.status == 'error') {
596 alert( response.message );
597 nfwjs_upgrade_plugin_progress( 1 );
598
599 } else if ( response.status == 'success') {
600 alert( response.message );
601 location.reload();
602
603 } else {
604 alert( nfwi18n.unknown_error );
605 nfwjs_upgrade_plugin_progress( 1 );
606 }
607 return false;
608 },
609
610 error: function(xhr, status, error) {
611 alert('Error: ' + error );
612 nfwjs_upgrade_plugin_progress( 1 );
613 return false;
614 },
615 } );
616
617 return false;
618 }
619
620 function nfwjs_upgrade_plugin_progress( show ) {
621
622 if ( show == 1 ) {
623 jQuery('#nf-progress-id').show();
624 jQuery('#nf-progress-gif').hide();
625 } else {
626 jQuery('#nf-progress-id').hide();
627 jQuery('#nf-progress-gif').show();
628 }
629
630 }
631
632
633 // =====================================================================
634 // Login Protection.
635
636 function nfwjs_auth_user_valid() {
637 var e = document.bp_form.elements['nfw_options[auth_name]'];
638 if ( e.value.match(/[^-\/\\_.a-zA-Z0-9 ]/) ) {
639 alert( nfwi18n.invalid_char );
640 e.value = e.value.replace(/[^-\/\\_.a-zA-Z0-9 ]/g,'');
641 return false;
642 }
643 if (e.value == 'admin') {
644 alert( nfwi18n.no_admin );
645 e.value = '';
646 return false;
647 }
648 }
649
650 function nfwjs_realm_valid() {
651 var e = document.getElementById('realm').value;
652 if ( e.length >= 1024 ) {
653 alert( nfwi18n.max_char );
654 return false;
655 }
656 }
657
658 function nfwjs_getpost(request){
659 if ( request == 'GETPOST' ) {
660 request = 'GET/POST';
661 }
662 document.getElementById('get_post').innerHTML = request;
663 }
664
665 function nfwjs_toggle_submenu( enable ) {
666 if ( enable == 0 ) {
667 // Disable protection
668 bf_enable = 0;
669 jQuery('#submenu_table').slideUp();
670 jQuery('#bf_table').slideUp();
671 jQuery('#bf_table_extra').slideUp();
672 jQuery('#bf_table_password').slideUp();
673 jQuery('#bf_table_captcha').slideUp();
674 } else {
675 bf_enable = enable;
676 jQuery('#submenu_table').slideDown();
677 // Display the right table (captcha or password protection)
678 nfwjs_toggle_table( enable, bf_type );
679 jQuery('#bf_table_extra').slideDown();
680 }
681 // Enable/disable write to auth log
682 if ( bf_enable == 1 ) {
683 jQuery('#nfw-authlog').prop('disabled', false);
684 } else {
685 jQuery('#nfw-authlog').prop('disabled', true);
686 }
687 }
688
689 function nfwjs_toggle_table( enable, type ) {
690 if ( type == 1 ) {
691 // Captcha
692 bf_type = 1;
693 if ( enable == 1 ) {
694 // Yes, if under attack
695 jQuery('#bf_table').slideDown();
696 } else {
697 // Always ON
698 jQuery('#bf_table').slideUp();
699 }
700 jQuery('#bf_table_password').slideUp();
701 jQuery('#bf_table_captcha').slideDown();
702 } else { // type == 2
703 // Password
704 bf_type = 0;
705 if ( enable == 1 ) {
706 // Yes, if under attack
707 jQuery('#bf_table').slideDown();
708 } else {
709 // Always ON
710 jQuery('#bf_table').slideUp();
711 }
712 jQuery('#bf_table_password').slideDown();
713 jQuery('#bf_table_captcha').slideUp();
714 }
715 }
716
717 function check_login_fields() {
718
719 if ( jQuery('#ui-enabled').prop('checked') == false ) {
720 return true;
721 }
722
723 if ( bf_enable < 1 ) {
724 alert( nfwi18n.select_when );
725 return false;
726 }
727
728 if ( document.bp_form.elements['nfw_options[bf_type]'].value == 0 ) {
729 if ( document.bp_form.elements['nfw_options[auth_name]'].value == '' && document.bp_form.elements['nfw_options[auth_pass]'].value == '' ) {
730 alert( nfwi18n.missing_auth );
731 return false;
732 }
733 }
734 return true;
735 }
736
737 // =====================================================================
738 // Firewall Log.
739
740 function nfwjs_check_key() {
741
742 var pubkey = jQuery('#clogs-pubkey').val();
743 if ( pubkey == '' ) {
744 return false;
745 }
746 if (! pubkey.match( /^[a-f0-9]{40}:(?:[a-f0-9:.]{3,39}|\*)$/) ) {
747 jQuery('#clogs-pubkey').focus();
748 alert( nfwi18n.invalid_key );
749 return false;
750 }
751 }
752
753 // =====================================================================
754 // Live Log.
755
756 var livelog = 0;
757 var livecls = 0;
758 var lines = 0;
759 var livecount = 1;
760 var counter = 0;
761
762 function nfwjs_livelog() {
763
764 if ( jQuery('#livelog-switch').prop('checked') == false ) {
765 nfwjs_livelog_stop();
766 return true;
767 }
768 if ( jQuery('#idtxtlog').val() == nfwi18n.live_log_desc || jQuery('#idtxtlog').val() == '' ) {
769 jQuery('#idtxtlog').val( nfwi18n.no_traffic +' '+ liveinterval/1000 + nfwi18n.seconds +"\n" );
770 }
771 if ( scroll == 1 ) {
772 document.getElementById('idtxtlog').scrollTop = document.getElementById('idtxtlog').scrollHeight;
773 }
774 if ( lwrap == 1 ) {
775 jQuery('#idtxtlog').attr('wrap', 'soft');
776 } else {
777 jQuery('#idtxtlog').attr('wrap', 'off');
778 }
779
780 jQuery('#nfw-progress').show();
781
782 counter = setInterval( nfwjs_countdown, 1000 );
783 livelog = setInterval( nfwjs_start_livelog, liveinterval );
784 }
785
786 function nfwjs_countdown() {
787 if ( livecount <= ( liveinterval/1000 ) ) {
788 jQuery('#nfw-progress').val( livecount++ );
789 }
790 jQuery('#nfw-progress').attr( 'max', liveinterval/1000 );
791 }
792
793 function nfwjs_start_livelog() {
794
795 // Send HTTP request
796 var data = {
797 'livecls': livecls,
798 'lines': lines
799 };
800 jQuery.ajax( {
801 type: "POST",
802 url: site_url,
803 data: data,
804 dataType: "text",
805 success: function( response ) {
806 if ( response == '' ) {
807 jQuery('#idtxtlog').val( nfwi18n.no_traffic +' '+ liveinterval/1000 + nfwi18n.seconds +"\n" );
808 } else if ( response != '*' ) {
809 if ( response.charAt(0) != '^' ) {
810 jQuery('#idtxtlog').val( nfwi18n.err_unexpected + "\n\n" + response );
811 // Stop
812 nfwjs_livelog_stop( 'force' );
813 return;
814 } else {
815 var line = response.substr(1);
816 line = line.replace( '<?php exit; ?>', '' );
817 if ( line != '' ) {
818 // Get number of lines
819 var res = line.split(/\n/).length - 1;
820 // Work around for old IE bug
821 if (! res ) { res = 1; }
822 if ( lines == 0 ) {
823 document.liveform.txtlog.value = line;
824 } else {
825 document.liveform.txtlog.value += line;
826 }
827 lines += res;
828 if ( scroll ) {
829 document.getElementById('idtxtlog').scrollTop = document.getElementById('idtxtlog').scrollHeight;
830 }
831 if ( lwrap == 1 ) {
832 jQuery('#idtxtlog').attr('wrap', 'soft');
833 } else {
834 jQuery('#idtxtlog').attr('wrap', 'off');
835 }
836 }
837 }
838 }
839 },
840 // Display non-200 HTTP response
841 error: function( xhr, status, err ) {
842 if ( xhr.status == 404 ) {
843 document.liveform.txtlog.value += nfwi18n.error_404 +' '+ site_url + "\n";
844 } else if ( xhr.status == 503 ) {
845 document.liveform.txtlog.value += nfwi18n.log_not_found + "\n";
846 } else {
847 document.liveform.txtlog.value += nfwi18n.http_error +' '+ xhr.status + "\n";
848 }
849 // Stop
850 nfwjs_livelog_stop( 'force' );
851 return;
852 }
853 });
854 livecls = 0;
855 livecount = 1;
856
857 if ( jQuery('#idtxtlog').val() == nfwi18n.live_log_desc ) {
858 jQuery('#idtxtlog').val( nfwi18n.no_traffic +' '+ liveinterval/1000 + nfwi18n.seconds +"\n" );
859 }
860 return false;
861 }
862
863 function nfwjs_livelog_stop( force ) {
864 // Clear timer
865 if ( livelog != 0 ) {
866 clearInterval( livelog );
867 livelog = 0;
868
869 clearInterval( counter );
870 livecount = 1;
871 }
872
873 jQuery('#nfw-progress').hide();
874 jQuery('#nfw-progress').val( 0 );
875
876 var textarea = jQuery('#idtxtlog').val();
877 if ( textarea.includes( nfwi18n.no_traffic ) ) {
878 jQuery('#idtxtlog').val( nfwi18n.live_log_desc );
879 }
880
881 lines = 0;
882
883 if ( force == 'force' ) {
884 jQuery('#livelog-switch').prop('checked', false);
885 }
886 }
887
888 function nfwjs_cls() {
889 if ( jQuery('#livelog-switch').prop('checked') == true ) {
890 jQuery('#idtxtlog').val( nfwi18n.no_traffic +' '+ liveinterval/1000 + nfwi18n.seconds +"\n" );
891 } else {
892 jQuery('#idtxtlog').val( '' );
893 }
894 livecls = 1;
895 lines = 0;
896 }
897
898 function nfwjs_change_int( intv ) {
899 liveinterval = intv;
900 nfwjs_create_cookie( 'nfwintval', intv );
901 // We must restart
902 if ( livelog != 0 ) {
903 clearInterval( livelog );
904 livelog = 0;
905 var textarea = jQuery('#idtxtlog').val();
906 if ( textarea.includes( nfwi18n.no_traffic ) ) {
907 jQuery('#idtxtlog').val( nfwi18n.no_traffic +' '+ liveinterval/1000 + nfwi18n.seconds +"\n" );
908 }
909 livelog = setInterval( nfwjs_start_livelog, liveinterval );
910
911 clearInterval( counter );
912 livecount = 1;
913 counter = setInterval( nfwjs_countdown, 1000 );
914 }
915 }
916
917 function nfwjs_is_scroll() {
918 if ( jQuery('#livescroll').prop('checked') == true ) {
919 scroll = 1;
920 if ( livelog != 0 ) {
921 document.getElementById('idtxtlog').scrollTop = document.getElementById('idtxtlog').scrollHeight;
922 }
923 nfwjs_create_cookie( 'nfwscroll', scroll );
924 } else {
925 scroll = 0;
926 nfwjs_delete_cookie( 'nfwscroll' )
927 }
928 }
929
930 function nfwjs_linewrapping() {
931 if ( jQuery('#idtxtlog').attr('wrap') == 'off') {
932 jQuery('#idtxtlog').attr('wrap', 'soft');
933 lwrap = 1;
934 nfwjs_create_cookie('nfwlwrap', lwrap );
935 } else {
936 jQuery('#idtxtlog').attr('wrap', 'off');
937 lwrap = 0;
938 nfwjs_delete_cookie('nfwlwrap');
939 }
940 }
941
942 function nfwjs_create_cookie( name, value ) {
943 var d = new Date();
944 d.setTime(d.getTime() + ( 365 * 24 * 60 * 60 * 1000) );
945 var expires = "expires=" + d.toUTCString();
946 document.cookie = name +'=' + value + "; " + expires;
947 }
948
949 function nfwjs_delete_cookie( name ) {
950 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
951 }
952
953 function nfwjs_lv_select( value ) {
954 if ( value > 0 ) {
955 jQuery('#lr-disabled').prop('disabled', false);
956 jQuery('#lr-disabled').focus();
957 } else {
958 jQuery('#lr-disabled').prop('disabled', true);
959 }
960 }
961
962 // =====================================================================
963 // About.
964
965 function nfwjs_about_table(table_id) {
966 var av_table = [11, 12, 13, 14, 15];
967 for (var i = 0; i < av_table.length; ++i) {
968 if ( table_id == av_table[i] ) {
969 jQuery("#" + table_id).slideDown();
970 } else {
971 jQuery("#" + av_table[i]).slideUp();
972 }
973 };
974 }
975 var dgs=0;
976 function nfw_eg() {
977 setTimeout('nfw_eg()',5);if(dgs<180){++dgs;
978 document.body.style.webkitTransform = 'rotate('+dgs+'deg)';
979 document.body.style.msTransform = 'rotate('+dgs+'deg)';
980 document.body.style.transform = 'rotate('+dgs+'deg)';
981 }
982 document.body.style.overflow='hidden';
983 }
984
985 // =====================================================================
986 // EOF
987