forked from phpipam/phpipam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magic.js
executable file
·2910 lines (2613 loc) · 114 KB
/
magic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*
* Javascript / jQuery functions
*
*
*/
$(document).ready(function () {
/* @general functions */
/*loading spinner functions */
function showSpinner() { $('div.loading').show(); }
function hideSpinner() { $('div.loading').fadeOut('fast'); }
/* escape hide popups */
$(document).keydown(function(e) {
if(e.keyCode === 27) {
if($("#popupOverlay2").is(":visible")) {
hidePopup2 ();
}
else {
hidePopup1 ();
}
}
});
// no enter in sortfields
$(document).on("submit", ".searchFormClass", function() {
return false;
});
$('.show_popover').popover();
/* this functions opens popup */
/* -------------------------- */
function open_popup (popup_class, target_script, post_data, secondary) {
// class
secondary = typeof secondary !== 'undefined' ? secondary : false;
// show spinner
showSpinner();
// post
$.post(target_script, post_data, function(data) {
showPopup('popup_w'+popup_class, data, secondary);
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText+"<br>Status: "+textStatus+"<br>Error: "+errorThrown); });
// prevent reload
return false;
}
/* this functions saves popup result */
/* --------------------------------- */
function submit_popup_data (result_div, target_script, post_data, reload) {
// show spinner
showSpinner();
// set reload
reload = typeof reload !== 'undefined' ? reload : true;
// post
$.post(target_script, post_data, function(data) {
$('div'+result_div).html(data).slideDown('fast');
//reload after 2 seconds if succeeded!
if(reload) {
if(data.search("alert-danger")==-1 && data.search("error")==-1 && data.search("alert-warning")==-1 ) { setTimeout(function (){window.location.reload();}, 1500); }
else { hideSpinner(); }
}
else {
hideSpinner();
}
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
// prevent reload
return false;
}
/* reload window function for ajax error checking */
function reload_window (data) {
if( data.search("alert-danger")==-1 &&
data.search("error")==-1 &&
data.search("alert-warning") == -1 ) { setTimeout(function (){window.location.reload();}, 1500); }
else { hideSpinner(); }
}
/* tooltips */
if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); }
/* hide error div if jquery loads ok
*********************************************/
$('div.jqueryError').hide();
/* Show / hide JS error */
function showError(errorText) {
$('div.jqueryError').fadeIn('fast');
if(errorText.length>0) { $('.jqueryErrorText').html(errorText).show(); }
hideSpinner();
}
function hideError() {
$('.jqueryErrorText').html();
$('div.jqueryError').fadeOut('fast');
}
//hide error popup
$(document).on("click", "#hideError", function() {
hideError(); return false;
});
//disabled links
$('.disabled a').click(function() { return false;
});
/* tooltip hiding fix */
function hideTooltips() { $('.tooltip').hide(); }
/* popups */
function showPopup(pClass, data, secondary) {
showSpinner();
// secondary - load secondary popupoverlay
if (secondary === true) { var oclass = "#popupOverlay2";}
else { var oclass = "#popupOverlay"; }
// show overlay
$(oclass).fadeIn('fast');
// load data and show it
if (data!==false && typeof(data)!=="undefined") {
$(oclass+' .'+pClass).html(data);
}
// malaiam: Weird popup_max bug loads same content in both popupOverlay and popupOverlay2, duplicating forms and URL parameter, messing things up, so we delete it
if (secondary != true) { $('#popupOverlay2 > div').empty(); }
$(oclass+' .'+pClass).fadeIn('fast');
//disable page scrolling on bottom
$('body').addClass('stop-scrolling');
// resize
resize_pContent ()
}
function hidePopup(pClass, secondary) {
// secondary - load secondary popupoverlay
if (secondary === true) { var oclass = "#popupOverlay2";}
else { var oclass = "#popupOverlay"; }
// hide
$(oclass+' .'+pClass).fadeOut('fast');
// IMPORTANT: also empty loaded content to avoid issues on popup reopening
$(oclass+' > div').empty();
$('body').removeClass('stop-scrolling'); //enable scrolling back
}
function hidePopups() {
$('#popupOverlay').fadeOut('fast');
$('#popupOverlay2').fadeOut('fast');
// IMPORTANT: also empty loaded content to avoid issues on popup reopening
$('#popupOverlay > div').empty();
$('#popupOverlay2 > div').empty();
$('.popup').fadeOut('fast');
$('body').removeClass('stop-scrolling'); //enable scrolling back
hideSpinner();
}
function hidePopup1() {
$('#popupOverlay').fadeOut('fast');
$('#popupOverlay .popup').fadeOut('fast');
// IMPORTANT: also empty loaded content to avoid issues on popup reopening
$('#popupOverlay > div').empty();
hideSpinner();
$('body').removeClass('stop-scrolling'); //enable scrolling back
}
function hidePopup2() {
$('#popupOverlay2').fadeOut('fast');
$('#popupOverlay2 .popup').fadeOut('fast');
// IMPORTANT: also empty loaded content to avoid issues on popup reopening
$('#popupOverlay2 > div').empty();
hideSpinner();
$('body').removeClass('stop-scrolling'); //enable scrolling back
}
function hidePopupMasks() {
$('.popup_wmasks').fadeOut('fast');
hideSpinner();
}
$(document).on("click", ".hidePopups", function() {hidePopups(); });
$(document).on("click", ".hidePopup2", function() { hidePopup2(); });
$(document).on("click", ".hidePopupMasks", function() { hidePopupMasks(); });
$(document).on("click", ".hidePopupsReload", function() { window.location.reload(); });
//prevent loading for disabled buttons
$('a.disabled, button.disabled').click(function() { return false; });
//fix for menus on ipad
$('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); });
/* generate random password */
function randomPass() {
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
var pass = "";
var x;
var i;
for(x=0; x<10; x++) {
i = Math.floor(Math.random() * 62);
pass += chars.charAt(i);
}
return pass;
}
// on load
resize_pContent ()
// on resize
$(window).resize(function () {
resize_pContent ()
});
function resize_pContent () {
if($(".popup .pContent").is(":visible")) {
var myheight = $(window).height() - 250;
$(".popup .pContent").css('max-height', myheight);
}
}
/* remove self on click */
$(document).on("click", ".selfDestruct", function() {
$(this).parent('div').fadeOut('fast');
});
/* @cookies */
function createCookie(name,value,days) {
var date;
var expires;
if (typeof days !== 'undefined') {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
/* draggeable elements */
$(function() {
$(".popup").draggable({ handle: ".pHeader" });
});
// bootstrap-table
$('table.sorted-new')
.attr("data-toggle", "table")
.attr('data-pagination', 'true')
.attr('data-page-size', '250')
.attr('data-page-list', '[50,100,250,500,All]')
.attr('data-search','true')
.attr('data-classes','table-no-bordered')
.attr('data-icon-size','sm')
.attr('data-show-footer','false')
.attr('data-show-columns','true')
.attr('data-icons-prefix','fa')
.attr('data-icons','icons')
.attr('data-cookie','true')
.attr('data-sortable', 'false')
$('table.sorted')
.attr("data-toggle", "table")
.attr('data-pagination', 'true')
.attr('data-page-size', '250')
.attr('data-page-list', '[50,100,250,500,All]')
.attr('data-search','true')
.attr('data-classes','table-no-bordered')
.attr('data-icon-size','sm')
.attr('data-show-footer','false')
.attr('data-show-columns','true')
.attr('data-icons-prefix','fa')
.attr('data-icons','icons')
.attr('data-cookie', 'true')
.attr('data-sortable', 'false')
.attr('onlyInfoPagination', 'true')
.attr('smartDisplay', true)
.attr('showPaginationSwitch', true)
.attr('minimumCountColumns', true)
$('table.nosearch')
.attr('data-search','false')
.attr('data-show-columns','false')
$('table.nopagination')
.attr('data-pagination', 'false')
$('table.sortable')
.attr('data-sortable', 'true')
// tooltips, popovers
$('table.sorted').on('all.bs.table', function () {
if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); }
$('.show_popover').popover();
})
// icons - bootstrap table
window.icons = {
refresh : 'fa-refresh',
toggle : 'fa-toggle-on',
columns : 'fa-th-list'
};
$("li.disabled a").click(function () {
return false;
});
$('form.search-form').submit(function() {
return false;
});
/**
* Generic open popup scripts
*
* Generic function to open popup and provide data via POST attributes
*
* Attributes are:
* - data-script: script to load in popup
* - data-class: popup class/size (400, 700, ...)
* - data-secondary: open secondary popup
* - data-* : all data- parameters will be passed as POST params to requested script
*
* @return void
*/
$(document).on("click", ".open_popup", function () {
// defaults
var post_data = {};
var secondary = false;
var popup_class = "400";
var target_script = "";
// get all data- attributes
$.each(this.attributes, function() {
// script
if(this.name == "data-script") {
target_script = this.value;
}
// class
else if(this.name == "data-class") {
popup_class = this.value;
}
// secondary
else if(this.name == "data-secondary") {
secondary = true;
}
// parameters
else if(this.name.indexOf("data-") !== -1) {
post_data[this.name.replace("data-", "")] = this.value;
}
});
// checks
if(target_script == "") {
showError("Error: Missing target_script");
}
// load popup
else {
open_popup (popup_class, target_script, post_data, secondary);
}
// no reload
return false;
});
/**
* Generic submit popup script
*
* It will POST data from provided script and attributes to target
* script and display it in target div
*
*
*/
$(document).on("click", ".submit_popup", function () {
// defaults
var post_data = {};
var reload = true;
var result_div = "";
var target_script = "";
// get all data- attributes
$.each(this.attributes, function() {
// script
if(this.name == "data-script") {
target_script = this.value;
}
// class
else if(this.name == "data-result_div") {
result_div = "#"+this.value;
}
// secondary
else if(this.name == "data-noreload") {
reload = false;
}
// get form parameters
else if(this.name == "data-form") {
post_data = $('form#'+this.value).serialize ()
}
});
// checks
if(target_script == "") {
showError("Error: Missing target_script")
}
else if (result_div == "") {
showError("Error: Missing result div parameter")
}
// load popup
else {
submit_popup_data (result_div, target_script, post_data, reload)
}
// no reload
return false;
});
/* @dashboard widgets ---------- */
//if dashboard show widgets
if($('#dashboard').length>0) {
//get all boxes
$('div[id^="w-"]').each(function(){
var w = $(this).attr('id');
//remove w-
w = w.replace("w-", "");
$.post('app/dashboard/widgets/'+w+'.php', function(data) {
$("#w-"+w+' .hContent').html(data);
}).fail(function(xhr, textStatus, errorThrown) {
$.post('app/dashboard/widgets/custom/'+w+'.php', function(data) {
$("#w-"+w+' .hContent').html(data);
}).fail(function(xhr, textStatus, errorThrown) {
$("#w-"+w+' .hContent').html('<blockquote style="margin-top:20px;margin-left:20px;">File not found!</blockquote>');
})
});
});
}
//remove item
$(document).on('click', "i.remove-widget", function() {
$(this).parent().parent().fadeOut('fast').remove();
});
//add new widget form popup
$(document).on('click', '#sortablePopup li a.widget-add', function() {
var wid = $(this).attr('id');
var wsize = $(this).attr('data-size');
var wtitle= $(this).attr('data-htitle');
//create
var data = '<div class="row-fluid"><div class="span'+wsize+' widget-dash" id="'+wid+'"><div class="inner movable"><h4>'+wtitle+'</h4><div class="hContent"></div></div></div></div>';
$('#dashboard').append(data);
//load
w = wid.replace("w-", "");
$.post('app/dashboard/widgets/'+w+'.php', function(data) {
$("#"+wid+' .hContent').html(data);
}).fail(function(xhr, textStatus, errorThrown) {
$("#"+wid+' .hContent').html('<blockquote style="margin-top:20px;margin-left:20px;">File not found!</blockquote>');
});
//remove item
$(this).parent().fadeOut('fast'); return false;
});
/* @subnets list ---------- */
/* leftmenu toggle submenus */
// default hide
$('ul.submenu.submenu-close').hide();
// left menu folder delay tooltip
$('.icon-folder-close,.icon-folder-show, .icon-search').tooltip( {
delay: {show:2000, hide:0},
placement:"bottom"
});
// show submenus
$('ul#subnets').on("click", ".fa-folder-close-o", function() {
//change icon
$(this).removeClass('fa-folder-close-o').addClass('fa-folder-open-o');
//find next submenu and hide it
$(this).nextAll('.submenu').slideDown('fast');
//save cookie
update_subnet_structure_cookie ("add", $(this).attr("data-str_id"));
});
$('ul#subnets').on("click", ".fa-folder", function() {
//change icon
$(this).removeClass('fa-folder').addClass('fa-folder-open');
//find next submenu and hide it
$(this).nextAll('.submenu').slideDown('fast');
//save cookie
update_subnet_structure_cookie ("add", $(this).attr("data-str_id"));
});
// hide submenus
$('ul#subnets').on("click", ".fa-folder-open-o", function() {
//change icon
$(this).removeClass('fa-folder-open-o').addClass('fa-folder-close-o');
//find next submenu and hide it
$(this).nextAll('.submenu').slideUp('fast');
//save cookie
update_subnet_structure_cookie ("remove", $(this).attr("data-str_id"));
});
$('ul#subnets').on("click", ".fa-folder-open", function() {
//change icon
$(this).removeClass('fa-folder-open').addClass('fa-folder');
//find next submenu and hide it
$(this).nextAll('.submenu').slideUp('fast');
//save cookie
update_subnet_structure_cookie ("remove", $(this).attr("data-str_id"));
});
/* Function to save subnets structure left menu to cookie */
function update_subnet_structure_cookie (action, cid) {
// read old cookie
var s_cookie = readCookie("sstr");
// defualt - if empty
if(typeof s_cookie === 'undefined' || s_cookie==null || s_cookie.length===0) s_cookie = "|";
// add or replace
if (action == "add") {
// split to array and check if it already exists
var arr = s_cookie.split('|');
var exists = false;
for(var i=0;i < arr.length;i++) {
if(arr[i]==cid) {
exists = true;
} }
// new
if(exists==false) s_cookie += cid+"|";
}
else if (action == "remove") {
s_cookie = s_cookie.replace("|"+cid+"|", "|");
}
// save cookie
createCookie("sstr",s_cookie, 365);
}
//expand/contract all
$('#expandfolders').click(function() {
// get action
var action = $(this).attr('data-action');
//open
if(action == 'close') {
$('.subnets ul#subnets li.folder > i').removeClass('fa-folder-close-o').addClass('fa-folder-open-o');
$('.subnets ul#subnets li.folderF > i').removeClass('fa-folder').addClass('fa-folder-open');
$('.subnets ul#subnets ul.submenu').removeClass('submenu-close').addClass('submenu-open').slideDown('fast');
$(this).attr('data-action','open');
createCookie('expandfolders','1','365');
$(this).removeClass('fa-expand').addClass('fa-compress');
}
else {
$('.subnets ul#subnets li.folder > i').addClass('fa-folder-close-o').removeClass('fa-folder-open-o');
$('.subnets ul#subnets li.folderF > i').addClass('fa-folder').removeClass('fa-folder-open');
$('.subnets ul#subnets ul.submenu').addClass('submenu-close').removeClass('submenu-open').slideUp('fast');
$(this).attr('data-action','close');
createCookie('expandfolders','0','365');
$(this).removeClass('fa-compress').addClass('fa-expand');
}
});
/* @ipaddress list ---------- */
/* add / edit / delete IP address
****************************************/
//show form
$(document).on("click", ".modIPaddr", function() {
showSpinner();
var action = $(this).attr('data-action');
var id = $(this).attr('data-id');
var subnetId = $(this).attr('data-subnetId');
var stopIP = $(this).attr('data-stopIP');
//format posted values
var postdata = "action="+action+"&id="+id+"&subnetId="+subnetId+"&stopIP="+stopIP;
$.post('app/subnets/addresses/address-modify.php', postdata, function(data) {
$('#popupOverlay div.popup_w500').html(data);
showPopup('popup_w500');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//move orphaned IP address
$(document).on("click", "a.moveIPaddr", function() {
showSpinner();
var action = $(this).attr('data-action');
var id = $(this).attr('data-id');
var subnetId = $(this).attr('data-subnetId');
//format posted values
var postdata = "action="+action+"&id="+id+"&subnetId="+subnetId;
$.post('app/subnets/addresses/move-address.php', postdata, function(data) {
$('#popupOverlay div.popup_w400').html(data);
showPopup('popup_w400');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//resolve DNS name
$(document).on("click", "#refreshHostname", function() {
showSpinner();
var ipaddress = $('input.ip_addr').val();
var subnetId = $(this).attr('data-subnetId');;
$.post('app/subnets/addresses/address-resolve.php', {ipaddress:ipaddress, subnetId: subnetId}, function(data) {
if(data.length !== 0) {
$('input[name=hostname]').val(data);
}
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
});
//submit ip address change
$(document).on("click", "button#editIPAddressSubmit, .editIPSubmitDelete", function() {
//show spinner
showSpinner();
var postdata = $('form.editipaddress').serialize();
//append deleteconfirm
if($(this).attr('id') == "editIPSubmitDelete") { postdata += "&deleteconfirm=yes&action=delete"; }
//replace delete if from visual
if($(this).attr('data-action') == "all-delete" ) { postdata += '&action-visual=delete';}
$.post('app/subnets/addresses/address-modify-submit.php', postdata, function(data) {
$('div.addnew_check').html(data);
$('div.addnew_check').slideDown('fast');
//reload after 2 seconds if succeeded!
reload_window (data);
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//ping check
$(document).on("click", ".ping_ipaddress", function() {
showSpinner();
var id = $(this).attr('data-id');
var subnetId = $(this).attr('data-subnetId');
// new ip?
if ($(this).hasClass("ping_ipaddress_new")) { id = $("input[name=ip_addr]").val(); }
//check
$.post('app/subnets/addresses/ping-address.php', {id:id, subnetId:subnetId}, function(data) {
$('#popupOverlay2 div.popup_w400').html(data);
showPopup('popup_w400', false, true);
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); }); return false;
});
/* send notification mail
********************************/
//show form
$(document).on("click", "a.mail_ipaddress", function() {
//get IP address id
var IPid = $(this).attr('data-id');
$.post('app/subnets/addresses/mail-notify.php', { id:IPid }, function(data) {
$('#popupOverlay div.popup_w700').html(data);
showPopup('popup_w700');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//send mail with IP details!
$(document).on("click", "#mailIPAddressSubmit", function() {
showSpinner();
var mailData = $('form#mailNotify').serialize();
//post to check script
$.post('app/subnets/addresses/mail-notify-check.php', mailData, function(data) {
$('div.sendmail_check').html(data).slideDown('fast');
//reload after 2 seconds if succeeded!
reload_window (data);
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
/* send notification mail - subnet
********************************/
//show form
$(document).on("click", "a.mail_subnet", function() {
//get IP address id
var id = $(this).attr('data-id');
$.post('app/subnets/mail-notify-subnet.php', { id:id }, function(data) {
$('#popupOverlay div.popup_w700').html(data);
showPopup('popup_w700');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//send mail with IP details!
$(document).on("click", "#mailSubnetSubmit", function() {
showSpinner();
var mailData = $('form#mailNotifySubnet').serialize();
//post to check script
$.post('app/subnets/mail-notify-subnet-check.php', mailData, function(data) {
$('div.sendmail_check').html(data).slideDown('fast');
//reload after 2 seconds if succeeded!
reload_window (data);
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
/* scan subnet
*************************/
//open popup
$('a.scan_subnet').click(function() {
showSpinner();
var subnetId = $(this).attr('data-subnetId');
$.post('app/subnets/scan/subnet-scan.php', {subnetId:subnetId}, function(data) {
$('#popupOverlay div.popup_wmasks').html(data);
showPopup('popup_wmasks');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); }); return false;
});
//show telnet port
$(document).on('change', "table.table-scan select#type", function() {
var pingType = $('select[name=type]').find(":selected").val();
if(pingType=="scan-telnet") { $('tbody#telnetPorts').show(); }
else { $('tbody#telnetPorts').hide(); }
});
//save value to cookie
$(document).on('change', "table.table-scan select#type", function() {
var sel = ($(this).find(":selected").val());
createCookie("scantype",sel,32);
});
//start scanning
$(document).on('click','#subnetScanSubmit', function() {
showSpinner();
$('#subnetScanResult').slideUp('fast');
var subnetId = $(this).attr('data-subnetId');
var csrf = $(this).attr('data-csrf-cookie');
var type = $('select[name=type]').find(":selected").val();
if($('input[name=debug]').is(':checked')) { var debug = 1; }
else { var debug = 0; }
var port = $('input[name=telnetports]').val();
$('#alert-scan').slideUp('fast');
$.post('app/subnets/scan/subnet-scan-execute.php', {subnetId:subnetId, type:type, debug:debug, port:port, csrf_cookie:csrf}, function(data) {
$('#subnetScanResult').html(data).slideDown('fast');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); }); return false;
});
//remove result
$(document).on('click', '.resultRemove', function() {
// if MAC table show IP that is hidden
if ($(this).hasClass('resultRemoveMac')) {
// if this one is hidden dont show ip for next
if ($(this).parent().parent().find('span.ip-address').hasClass('hidden')) {
}
// else show
else {
$(this).parent().parent().next().find('span.ip-address').removeClass('hidden');
}
}
// get target
var target = $(this).attr('data-target');
$('tr.'+target).remove(); return false;
});
//submit scanning result
$(document).on('click', 'a#saveScanResults', function() {
showSpinner();
var script = $(this).attr('data-script');
var subnetId = $(this).attr('data-subnetId');
var postData = $('form.'+script+"-form").serialize();
var postData = postData+"&subnetId="+subnetId;
var postData = postData+"&type="+script;
$.post('app/subnets/scan/subnet-scan-result.php', postData, function(data) {
$('#subnetScanAddResult').html(data);
//hide if success!
//reload after 2 seconds if succeeded!
reload_window (data);
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); }); return false;
});
/* import IP addresses
*************************/
//load CSV import form
$('a.csvImport').click(function () {
showSpinner();
var subnetId = $(this).attr('data-subnetId');
$.post('app/subnets/import-subnet/index.php', {subnetId:subnetId}, function(data) {
$('div.popup_max').html(data);
showPopup('popup_max');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//display uploaded file
$(document).on("click", "input#csvimportcheck", function() {
showSpinner();
//get filetype
var filetype = $('span.fname').html();
var xlsSubnetId = $('a.csvImport').attr('data-subnetId');
$.post('app/subnets/import-subnet/print-file.php', { filetype:filetype, subnetId:xlsSubnetId }, function(data) {
$('div.csvimportverify').html(data).slideDown('fast');
hideSpinner();
// add reload class
$('.importFooter').removeClass("hidePopups").addClass("hidePopupsReload");
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
});
//import file script
$(document).on("click", "input#csvImportNo", function() {
$('div.csvimportverify').hide('fast');
});
$(document).on("click", "input#csvImportYes", function() {
showSpinner();
//get filetype
var filetype = $('span.fname').html();
//ignore errors
if($('input[name=ignoreErrors]').is(':checked')) { var ignoreError = "1"; }
else { var ignoreError = "0"; }
// get active subnet ID
var xlsSubnetId = $('a.csvImport').attr('data-subnetId');
// Get CSRF cookie
var csrf_cookie = $('input[name=csrf_cookie]').val();
var postData = "subnetId=" + xlsSubnetId + "&filetype=" + filetype + "&ignoreError=" + ignoreError + "&csrf_cookie=" + csrf_cookie;
$.post('app/subnets/import-subnet/import-file.php', postData, function(data) {
$('div.csvImportResult').html(data).slideDown('fast');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
});
//download template
$(document).on("click", "#csvtemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/subnets/import-subnet/import-template.php'></iframe></div>");
return false;
});
//download vrf template
$(document).on("click", "#vrftemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=vrf'></iframe></div>");
return false;
});
//download domain template
$(document).on("click", "#vlanstemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=vlans'></iframe></div>");
return false;
});
//download domain template
$(document).on("click", "#l2domtemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=l2dom'></iframe></div>");
return false;
});
//download vlan domain template
$(document).on("click", "#vlandomaintemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=vlandomain'></iframe></div>");
return false;
});
//download subnet template
$(document).on("click", "#subnetstemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=subnets'></iframe></div>");
return false;
});
//download ip address template
$(document).on("click", "#ipaddrtemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=ipaddr'></iframe></div>");
return false;
});
//download device template
$(document).on("click", "#devicestemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=devices'></iframe></div>"); return false;
});
//download device types template
$(document).on("click", "#devtypetemplate", function() {
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/admin/import-export/import-template.php?type=devtype'></iframe></div>");
return false;
});
/* export IP addresses
*************************/
//show fields
$('a.csvExport').click(function() {
showSpinner();
var subnetId = $(this).attr('data-subnetId');
//show select fields
$.post('app/subnets/addresses/export-field-select.php', {subnetId:subnetId}, function(data) {
$('#popupOverlay div.popup_w400').html(data);
showPopup('popup_w400');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//export
$(document).on("click", "button#exportSubnet", function() {
var subnetId = $('a.csvExport').attr('data-subnetId');
//get selected fields
var exportFields = $('form#selectExportFields').serialize();
$("div.dl").remove(); //remove old innerDiv
$('div.exportDIV').append("<div style='display:none' class='dl'><iframe src='app/subnets/addresses/export-subnet.php?subnetId=" + subnetId + "&" + exportFields + "'></iframe></div>");
return false;
});
/* add / remove favourite subnet
*********************************/
$(document).on('click', 'a.editFavourite', function() {
var subnetId = $(this).attr('data-subnetId');
var action = $(this).attr('data-action');
var from = $(this).attr('data-from');
var item = $(this);
//remove
$.post('app/tools/favourites/favourite-edit.php', {subnetId:subnetId, action:action, from:from}, function(data) {
//success - widget - remove item
if(data=='success' && from=='widget') {
$('tr.favSubnet-'+subnetId).addClass('error');
$('tr.favSubnet-'+subnetId).delay(200).fadeOut();
}
//success - subnet - toggle star-empty
else if (data=='success') {
$(this).toggleClass('btn-info');
$('a.favourite-'+subnetId+" i").toggleClass('fa-star-o');
$(item).toggleClass('btn-info');
//remove
if(action=="remove") {
$('a.favourite-'+subnetId).attr('data-original-title','Click to add to favourites');
$(item).attr('data-action','add');
}
//add
else {
$('a.favourite-'+subnetId).attr('data-original-title','Click to remove from favourites');
$(item).attr('data-action','remove');
}
}
//fail
else {
$('#popupOverlay div.popup_w500').html(data);
showPopup('popup_w500');
hideSpinner();
}
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); }); return false;
});
/* request IP address for non-admins if locked or viewer
*********************************************************/
//show request form
$('a.request_ipaddress').click(function () {
showSpinner();
var subnetId = $(this).attr('data-subnetId');
$.post('app/tools/request-ip/index.php', {subnetId:subnetId}, function(data) {
$('#popupOverlay div.popup_w500').html(data);
showPopup('popup_w500');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//show request form from widget
$(document).on("click", "button#requestIP_widget", function() {
showSpinner();
var subnetId = $('select#subnetId option:selected').attr('value');
var ip_addr = document.getElementById('ip_addr_widget').value;
$.post('app/tools/request-ip/index.php', {subnetId:subnetId, ip_addr:ip_addr}, function(data) {
$('div.popup_w500').html(data);
showPopup('popup_w500');
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
return false;
});
//auto-suggest first available IP in selected subnet
$(document).on("change", "select#subnetId", function() {
showSpinner();
var subnetId = $('select#subnetId option:selected').attr('value');
//post it via json to request_ip_first_free.php
$.post('app/login/request_ip_first_free.php', { subnetId:subnetId}, function(data) {
$('input.ip_addr').val(data);
hideSpinner();
}).fail(function(jqxhr, textStatus, errorThrown) { showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: "+errorThrown); });
});
//submit request
$(document).on("click", "button#requestIPAddressSubmit", function() {