This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
forked from FreshJR07/FreshJR_QOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FreshJR_QoS_Stats.asp
1998 lines (1828 loc) · 96.3 KB
/
FreshJR_QoS_Stats.asp
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
##FreshJR_QOS_v8.9 released 06/03/2020
Modification on-top of RMerlins QoS_Stats page taken from 384.9
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns:v>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="icon" href="images/favicon.png">
<title>QoS - Classification</title>
<link rel="stylesheet" type="text/css" href="index_style.css">
<link rel="stylesheet" type="text/css" href="form_style.css">
<link rel="stylesheet" type="text/css" href="usp_style.css">
<link rel="stylesheet" type="text/css" href="/js/table/table.css">
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/chart.min.js"></script>
<script type="text/javascript" src="/state.js"></script>
<script type="text/javascript" src="/help.js"></script>
<script type="text/javascript" src="/general.js"></script>
<script type="text/javascript" src="/popup.js"></script>
<script type="text/javascript" src="/js/table/table.js"></script>
<script type="text/javascript" src="js/httpApi.js"></script>
<style>
.tableApi_table th {
height: 22px;
text-align: left;
}
.tableApi_table td {
text-align: left;
}
.data_tr {
height: 32px;
}
span.cat0{
background-color:#B3645B;
}
span.cat1{
background-color:#B98F53;
}
span.cat2{
background-color:#C6B36A;
}
span.cat3{
background-color:#849E75;
}
span.cat4{
background-color:#4C8FC0;
}
span.cat5{
background-color:#7C637A;
}
span.cat6{
background-color:#2B6692;
}
span.cat7{
background-color:#6C604F;
}
span.catrow{
padding: 4px 8px 4px 8px; color: white !important;
border-radius: 5px; border: 1px #2f3a3e solid;
white-space: nowrap;
}
div.t_item{
cursor:default;
}
span.t_mark{
display:none;
}
div.t_item:active span.t_label{
display:none;
}
div.t_item:active span.t_mark{
display:inline;
}
div.localdeviceip{
display:inline-block;
width:50%;
}
span.devicename{
display:inline-block;
font-size:75%;
width:50%;
vertical-align: middle;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.input_15_table{
margin-left:-5px;
height:23px;
width:117px;
line-height:23px \9; /*IE*/
font-size:12px;
font-family: Lucida Console;
background: #596E74;
border: 1px solid #929EA1;
color:#FFFFFF;
}
.input_12_table{
margin-left:-5px;
height:23px;
width:90px;
line-height:23px \9; /*IE*/
font-size:12px;
font-family: Lucida Console;
background: #596E74;
border: 1px solid #929EA1;
color:#FFFFFF;
}
.input_6_table{
margin-left:-5px;
height:23px;
width:50px;
line-height:23px \9; /*IE*/
font-size:12px;
font-family: Lucida Console;
background: #596E74;
border: 1px solid #929EA1;
color:#FFFFFF;
}
</style>
<script>
var device = {}; // devices database --> device["IP"] = { mac: "AA:BB:CC:DD:EE:FF" , name:"name" }
var clientlist = <% get_clientlist_from_json_database(); %>; // data from /jffs/nmp_cl_json.js (used to correlate mac addresses to corresponding device names )
</script>
<script>
var tablesize = 500; //max size of tracked connections table
var tabledata; //tabled of tracked connections after device-filtered
var sortmode=6; //current sort mode of tracked connections table (default =6)
var dhcp_start = "<% nvram_get("dhcp_start"); %>"
var dhcp_start = dhcp_start.substr(0, dhcp_start.lastIndexOf("."));
var rulename1="Rule1";
var rulename2="Rule2";
var rulename3="Rule3";
var rulename4="Rule4";
var appdb1; // AppDB rules
var appdb2;
var appdb3;
var appdb4;
var rule1; // IPv4 rules
var rule2;
var rule3;
var rule4;
var gamerule;
var gameCIDR; // CIDR/IP of game devices
var ruleFLAG; // Unused - reserved for toggling ON/OFF hardcoded rules in future release
//Syntax Hints
var ipsyntaxL = '<b>Syntax:</b> <p>  192.168.X.XXX</p> <p> !192.168.X.XXX</p> <p> </p> <p>  192.168.X.XXX/CIDR</p> <p> !192.168.X.XXX/CIDR</p>';
var ipsyntaxR = '<b>Syntax:</b> <p>  75.75.75.75</p> <p> !75.75.75.75</p> <p> </p> <p>  75.75.75.75/CIDR</p> <p> !75.75.75.75/CIDR</p>';
var protosyntax = '<b>Protocol</b> <p> TCP OR UDP</p> <p> </p> <b>Note:</b> <p>Conditional Evaluation</p> <p>(only with port rules)</p>' ;
var portsyntax = '<b>Syntax:</b> <p>  XXX</p> <p> !XXX</p> <p> </p> <p>  XXXX:YYYY</p> <p> !XXXX:YYYY</p> <p> </p> <p>  XXX,YYY,ZZZ</p> <p> !XXX,YYY,ZZZ</p>';
var marksyntax = '<b>Syntax:</b> <p> XXYYYY</p> <p> </p> <p><b>Note:</b></p> <p>XX - Cat (hex)</p> <p>YYYY - ID (hex or ****)</p> ';
var classsyntax = '<b>Class:</b> <p> Traffic Destination</p>';
var qos_type = "<% nvram_get("qos_type"); %>";
if ("<% nvram_get("qos_enable"); %>" == 0) { // QoS disabled
var qos_mode = 0;
} else if (bwdpi_support && (qos_type == "1")) { // aQoS
var qos_mode = 2;
} else if (qos_type == "0") { // tQoS
var qos_mode = 1;
} else if (qos_type == "2") { // BW limiter
var qos_mode = 3;
} else { // invalid mode
var qos_mode = 0;
}
if (qos_mode == 2) {
var bwdpi_app_rulelist = "<% nvram_get("bwdpi_app_rulelist"); %>".replace(/</g, "<");
var bwdpi_app_rulelist_row = bwdpi_app_rulelist.split("<");
if (bwdpi_app_rulelist == "" || bwdpi_app_rulelist_row.length != 9) {
bwdpi_app_rulelist = "9,20<8<4<0,5,6,15,17<13,24<1,3,14<7,10,11,21,23<<";
bwdpi_app_rulelist_row = bwdpi_app_rulelist.split("<");
}
var category_title = ["Net Control Packets", "Gaming", "Video and Audio Streaming", "VoIP and Instant Messaging", "Web Surfing", "File Transferring", "Others", "Game Transferring"];
var cat_id_array = [
[9, 20],
[8],
[4],
[0, 5, 6, 15, 17],
[13, 24],
[1, 3, 14],
[7, 10, 11, 21, 23],
[]
];
var c_net=bwdpi_app_rulelist_row.indexOf(cat_id_array[0].toString())
var c_gaming=bwdpi_app_rulelist_row.indexOf(cat_id_array[1].toString())
var c_streaming=bwdpi_app_rulelist_row.indexOf(cat_id_array[2].toString())
var c_voip=bwdpi_app_rulelist_row.indexOf(cat_id_array[3].toString())
var c_web=bwdpi_app_rulelist_row.indexOf(cat_id_array[4].toString())
var c_downloads=bwdpi_app_rulelist_row.indexOf(cat_id_array[5].toString())
var c_others=bwdpi_app_rulelist_row.indexOf(cat_id_array[6].toString())
var c_default=bwdpi_app_rulelist_row.indexOf(cat_id_array[7].toString())
} else {
var category_title = ["", "Highest", "High", "Medium", "Low", "Lowest"];
}
var pie_obj_ul, pie_obj_dl;
var refreshRate;
var timedEvent = 0;
var color = ["#B3645B", "#B98F53", "#C6B36A", "#849E75", "#4C8FC0", "#7C637A", "#2B6692", "#6C604F"];
var bwdpi_conntrack = []; //this variable is later updated via ajax call
<% get_tcclass_array(); %>;
var pieOptions = {
segmentShowStroke: false,
segmentStrokeColor: "#000",
animationEasing: "easeOutQuart",
animationSteps: 100,
animateScale: true,
legend: {
display: false
},
tooltips: {
callbacks: {
title: function(tooltipItem, data) {
return data.labels[tooltipItem[0].index];
},
label: function(tooltipItem, data) {
var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
var orivalue = value;
var total = eval(data.datasets[tooltipItem.datasetIndex].data.join("+"));
var unit = " bytes";
if (value > 1024) {
value = value / 1024;
unit = " KB";
}
if (value > 1024) {
value = value / 1024;
unit = " MB";
}
if (value > 1024) {
value = value / 1024;
unit = " GB";
}
return value.toFixed(2) + unit + ' ( ' + parseFloat(orivalue * 100 / total).toFixed(2) + '% )';
},
}
},
}
function ip2dec(addr) {
if( /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b$/.test(addr) ) //regex that accepts ipv4 addresses ###.###.###.### (no cidr flag allowed)
{
var parts = addr.split('.').map(Number);
return (parts[0] << 24) + (parts[1] << 16) + (parts[2] << 8) + (parts[3]) >>> 0;
}
else return 0
};
function cidr_start(addr) {
addr=addr.split('/');
var parts = addr[0].split('.').map(Number);
var dec_ip = (parts[0] << 24) + (parts[1] << 16) + (parts[2] << 8) + (parts[3]) >>> 0;
var dec_mask= (4294967295 << 32-addr[1]) >>> 0;
return (dec_ip&dec_mask)>>>0;
};
function cidr_end(addr) {
addr=addr.split('/');
var parts = addr[0].split('.').map(Number);
var dec_ip = (parts[0] << 24) + (parts[1] << 16) + (parts[2] << 8) + (parts[3]) >>> 0;
var dec_mask= ~(4294967295 << 32-addr[1]) >>> 0;
return (dec_ip|dec_mask)>>>0;
};
function draw_conntrack_table() {
//bwdpi_conntrack[i][0] = protocol
//bwdpi_conntrack[i][1] = Source IP
//bwdpi_conntrack[i][2] = Source Port
//bwdpi_conntrack[i][3] = Destination IP
//bwdpi_conntrack[i][4] = Destination Port
//bwdpi_conntrack[i][5] = Pre-formatted Title
//bwdpi_conntrack[i][6] = Traffic ID
//bwdpi_conntrack[i][7] = Traffic Category
tabledata = new Array(tablesize);
var j = 0;
for (var i = 0; i < bwdpi_conntrack.length; i++)
{
if (( deviceFilter == "*" || deviceFilter == bwdpi_conntrack[i][1] ) && ( j < tablesize ))
{
//format app name label into html
var label = bwdpi_conntrack[i][5]; (label.length > 27) ? size='style="font-size: 75%;"' : size = "" ;
var qos_class = get_qos_class(bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]);
var mark = (parseInt(bwdpi_conntrack[i][7]).toString(16).padStart(2,'0') + parseInt(bwdpi_conntrack[i][6]).toString(16).padStart(4,'0')).toUpperCase();
//bwdpi_conntrack[i][5] = '<span title="' + label + '" class="catrow cat' + qos_class + '"' + size + '>' + label + '</span>'; //sort by AppID name
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + qos_class + '"' + size + '>' + label + '</span>' + //sort by Container Destination
'<span class="t_mark catrow cat' + qos_class + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
//shorten IPV6
var isIPv6 = false;
if (bwdpi_conntrack[i][1].indexOf(":") >= 0) {
bwdpi_conntrack[i][1] = compIPV6(bwdpi_conntrack[i][1]);
isIPv6 = true;
}
if (bwdpi_conntrack[i][3].indexOf(":") >= 0) {
bwdpi_conntrack[i][3] = compIPV6(bwdpi_conntrack[i][3]);
isIPv6 = true;
}
//OVERRIDE LABEL - TC RULES
if (bwdpi_conntrack[i][7] == 0 && bwdpi_conntrack[i][6] == 0 ) //unidentified
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_others + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_others + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][7] == 13 && (bwdpi_conntrack[i][6] == 7 || bwdpi_conntrack[i][6] == 134 || bwdpi_conntrack[i][6] == 160) ) //speedtest + playstore + appstore
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_downloads + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_downloads + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][7] == 0 && bwdpi_conntrack[i][6] == 107) //snapchat
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_others + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_others + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][7] == 26) //advertisement
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_downloads + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_downloads + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][7] == 19 || bwdpi_conntrack[i][7] == 20 || ( bwdpi_conntrack[i][7] == 18 && bwdpi_conntrack[i][6]==63) ) //https + TSL/SSL + http
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_web + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_web + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(appdb1, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + appdb1[18] + '"' + size + '>' + label + ' ~</span>' +
'<span class="t_mark catrow cat' + appdb1[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(appdb2, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + appdb2[18] + '"' + size + '>' + label + ' ~</span>' +
'<span class="t_mark catrow cat' + appdb2[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(appdb3, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + appdb3[18] + '"' + size + '>' + label + ' ~</span>' +
'<span class="t_mark catrow cat' + appdb3[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(appdb4, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + appdb4[18] + '"' + size + '>' + label + ' ~</span>' +
'<span class="t_mark catrow cat' + appdb4[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (!isIPv6)
{
//SHOW LOCAL DEVICES AT LEFT SIDE OF TABLE (FLIP POSITION IF REQUIRED)
if (bwdpi_conntrack[i][3].startsWith(dhcp_start))
{
var temp = bwdpi_conntrack[i][3];
bwdpi_conntrack[i][3] = bwdpi_conntrack[i][1];
bwdpi_conntrack[i][1] = temp;
temp = bwdpi_conntrack[i][4];
bwdpi_conntrack[i][4] = bwdpi_conntrack[i][2];
bwdpi_conntrack[i][2] = temp;
}
//OVERRIDE LABEL - IPTABLE RULES
if (bwdpi_conntrack[i][4] == 500 || bwdpi_conntrack[i][4] == 4500) //wifi caling
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_voip + '"' + size + '>Wi-Fi Calling</span>' +
'<span class="t_mark catrow cat' + c_voip + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][2] >= 16384 && bwdpi_conntrack[i][2] <= 16415) //facetime
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_voip + '"' + size + '>Facetime</span>' +
'<span class="t_mark catrow cat' + c_voip + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (bwdpi_conntrack[i][7] == 8 && (bwdpi_conntrack[i][4] == 80 || bwdpi_conntrack[i][4] == 443) && bwdpi_conntrack[i][0] == "tcp" ) { //game downloads
label = "Game Transfering: " + label;
if (label.length > 27) size='style="font-size: 75%;"';
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + c_default + '"' + size + '>' + label + '</span>' +
'<span class="t_mark catrow cat' + c_default + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
}
if (eval_rule(gamerule, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + gamerule[18] + '"' + size + '>Game Rule: Untracked</span>' +
'<span class="t_mark catrow cat' + gamerule[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(rule1, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + rule1[18] + '"' + size + '>'+rulename1+'</span>' +
'<span class="t_mark catrow cat' + rule1[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(rule2, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + rule2[18] + '"' + size + '>'+rulename2+'</span>' +
'<span class="t_mark catrow cat' + rule2[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(rule3, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + rule3[18] + '"' + size + '>'+rulename3+'</span>' +
'<span class="t_mark catrow cat' + rule3[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
if (eval_rule(rule4, bwdpi_conntrack[i][0], bwdpi_conntrack[i][2], bwdpi_conntrack[i][4], bwdpi_conntrack[i][1], bwdpi_conntrack[i][3], bwdpi_conntrack[i][7], bwdpi_conntrack[i][6]))
bwdpi_conntrack[i][5] = '<div class="t_item">' +
'<span class="t_label catrow cat' + rule4[18] + '"' + size + '>'+rulename4+'</span>' +
'<span class="t_mark catrow cat' + rule4[18] + '"' + size + '>MARK:' + mark + '</span>' +
'<div>';
//PRETTY PRINT LOCAL DEVICE NAME NEXT TO IPv4 address
//(be placed after evaluation of custom rules due to injecting HTML into LocalIP field and breaking LocalIP data used for rule)
if (typeof device[bwdpi_conntrack[i][1]] != "undefined")
{
bwdpi_conntrack[i][1] =
'<div title="' + bwdpi_conntrack[i][1].split('.')[3].padStart(3, '#') + '" class="localdeviceip">' + bwdpi_conntrack[i][1] + '</div>' +
'<span class="devicename">' + device[bwdpi_conntrack[i][1]].name + '</span>'
}
}
tabledata[j] = bwdpi_conntrack[i];
j++;
}
}
j <= 30 ? tabledata.length = 30 : tabledata.length = j ; //table will always contain at least 30 blank entries to maintain some scroll distance
//draw table
updateTable()
}
function updateTable()
{
//table header
var header = new Array(6);
header[0]='<th width="5%" style="cursor: pointer;" onclick="sortmode=1; updateTable()" >Proto</th>';
header[1]='<th width="28%" style="cursor: pointer;" onclick="sortmode=2; updateTable()" >Local IP</th>';
header[2]='<th width="6%" style="cursor: pointer;" onclick="sortmode=3; updateTable()" >Port</th>';
header[3]='<th width="28%" style="cursor: pointer;" onclick="sortmode=4; updateTable()" >Remote IP</th>';
header[4]='<th width="6%" style="cursor: pointer;" onclick="sortmode=5; updateTable()" >Port</th>';
header[5]='<th width="27%" style="cursor: pointer;" onclick="sortmode=6; updateTable()" >Application</th>';
//sort table data
switch(sortmode) {
case 1:
// sort by protocol
header[0]='<th width="5%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=7; updateTable()" >Proto</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return a[0].localeCompare(b[0])} );
break;
case 2:
// sort by local IP
header[1]='<th width="28%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=8; updateTable()" >Local IP</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return a[1].localeCompare(b[1])} );
break;
case 3:
// sort by local port
header[2]='<th width="6%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=9; updateTable()" >Port</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return a[2]-b[2]} );
break;
case 4:
// sort by remote IP
header[3]='<th width="28%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=10; updateTable()" >Remote IP</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return full_IPv6(a[3]).localeCompare(full_IPv6(b[3]))} );
break;
case 5:
// sort by remote port
header[4]='<th width="6%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=11; updateTable()" >Port</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return a[4]-b[4]} );
break;
case 6:
// sort by label
header[5]='<th width="27%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px -1px 0px 0px inset;" onclick="sortmode=12; updateTable()" >Application</th>';
tabledata.sort(function(a,b) {return a[1].localeCompare(b[1])} );
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
break;
case 7:
// sort by protocol
header[0]='<th width="5%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=1; updateTable()" >Proto</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return b[0].localeCompare(a[0])} );
break;
case 8:
// sort by local IP
header[1]='<th width="28%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=2; updateTable()" >Local IP</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return b[1].localeCompare(a[1])} );
break;
case 9:
// sort by local port
header[2]='<th width="6%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=3; updateTable()" >Port</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return b[2]-a[2]} );
break;
case 10:
// sort by remote IP
header[3]='<th width="28%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=4; updateTable()" >Remote IP</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return full_IPv6(b[3]).localeCompare(full_IPv6(a[3]))} );
break;
case 11:
// sort by remote port
header[4]='<th width="6%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=5; updateTable()" >Port</th>';
tabledata.sort(function(a,b) {return a[5].localeCompare(b[5])} );
tabledata.sort(function(a,b) {return b[4]-a[4]} );
break;
case 12:
// sort by label
header[5]='<th width="27%" style="cursor: pointer; box-shadow: rgb(255, 204, 0) 0px 1px 0px 0px inset;" onclick="sortmode=6; updateTable()" >Application</th>';
tabledata.sort(function(a,b) {return a[1].localeCompare(b[1])} );
tabledata.sort(function(a,b) { return b[5].localeCompare(a[5])} );
break;
}
//generate table
var tbl = document.getElementById('tableContainer');
var code = '<tr class="row_title">'+header[0]+header[1]+header[2]+header[3]+header[4]+header[5]+'</tr>';
for(var i = 0; i < tabledata.length; i++){
if(tabledata[i])
{
code += '<tr class="row_tr data_tr" row_tr_idx="' + i +' ">';
code += '<td>' + tabledata[i][0] +'</td>';
code += '<td>' + tabledata[i][1] +'</td>';
code += '<td>' + tabledata[i][2] +'</td>';
code += '<td>' + tabledata[i][3] +'</td>';
code += '<td>' + tabledata[i][4] +'</td>';
code += '<td>' + tabledata[i][5] +'</td></tr>';
}else
{
code += '<tr class="row_tr data_tr" row_tr_idx="' + i +' "></tr>';
}
}
if (tabledata[tablesize - 1] )
{
code += '<tr class="row_tr data_tr" row_tr_idx="' + tablesize +' "><td style="text-align:center; font-weight:bold;" colspan="7">Reached table limit. Please use device filter.</td>'
}
tbl.innerHTML = code;
}
function comma(n) {
n = '' + n;
var p = n;
while ((n = n.replace(/(\d+)(\d{3})/g, '$1,$2')) != p) p = n;
return n;
}
function get_devicenames()
{
// populate device["IP"].mac from nvram variable "dhcp_staticlist"
decodeURIComponent('<% nvram_char_to_ascii("", "dhcp_staticlist"); %>').split("<").forEach( element => {
if ( element.split(">")[1] ){
//device[element.split(">")[1]] = { mac:element.split(">")[0].toUpperCase() , name:"DEBUG: NVRAM" };
device[element.split(">")[1]] = { mac:element.split(">")[0].toUpperCase() , name:"*" };
}
});
// populate device["IP"].mac from arp table
[<% get_arp_table(); %>].forEach( element => {
if ( element[3] ){
//device[element[0]] = { mac:element[3].toUpperCase() , name:"DEBUG: ARP" };
device[element[0]] = { mac:element[3].toUpperCase() , name:element[4] };
}
});
//populate device["IP"].mac from the dhcp table
// disabled due to <get_leases_array()> taking 1 second to load. This code is ran elsewhere asynchronously
// <'%' get_leases_array(); '%'> //returns variable named leasearray[]
// leasearray.forEach( element => {
// if ( element[1] ){
// device[element[2]] = { mac:element[1].toUpperCase() , name:"DEBUG: DHCP" };
// device[element[2]] = { mac:element[1].toUpperCase() , name::element[3] };
// }
// });
//instead temporarily populate device["IP"].name from dhcp table
// used as stopgap source of partial information on page load until complete information is later available from asynchronous code
// is NOT ideal since the names using this method do not reflect nicknames and sometimes return "*" instead of a device name
dhcpnamelist = <% IP_dhcpLeaseInfo(); %>
dhcpnamelist.forEach( element => {
if ( element[0] ){
if( device[element[0]] )
device[element[0]].name = element[1];
else
device[element[0]] = { mac:undefined , name:element[1]};
}
});
// populate device["IP"].name from device["IP"].mac saved in /jffs/nmp_cl_json.js
// clientlist = is data set from /jffs/nmp_cl_json.js
for (var i in device) {
if (typeof clientlist[device[i].mac] != "undefined")
{
if(clientlist[device[i].mac].nickName != "")
{
device[i].name = clientlist[device[i].mac].nickName;
}
else if(clientlist[device[i].mac].name != "")
{
device[i].name = clientlist[device[i].mac].name;
}
}
}
}
function update_devicenames(leasearray)
{
// this code is after ajax call
leasearray.forEach( element => {
if ( element[1] ){
mac = element[1].toUpperCase();
ip = element[2];
name = element[3];
//update device["IP"].mac from DHCP table
//device[ip] = { mac:mac , name:"DEBUG: DHCP" };
device[ip] = { mac:mac , name:name };
//update device{"IP"].name from /jffs/nmp_cl_json.js
if (typeof clientlist[mac] != "undefined")
{
if(clientlist[mac].nickName != "")
{
device[ip].name = clientlist[mac].nickName;
}
else if(clientlist[mac].name != "")
{
device[ip].name = clientlist[mac].name;
}
}
//update device filter drop down formated values
document.getElementById(ip).innerHTML = ip.padEnd(18,' ') + device[ip].name;
}
});
}
function populate_devicefilter(){
var code = '<option value="*" > </option>';
//Presort clients before adding clients into devicefilter to make it easier to read
keysSorted = Object.keys(device).sort(function(a,b){ return ip2dec(a)-ip2dec(b) }) // sort by IP
//keysSorted = Object.keys(device).sort(function(a,b){ return device[a].name.localeCompare(device[b].name) }) // sort by device name
for (i = 0; i < keysSorted.length; i++) {
key = keysSorted[i];
code += '<option id="' + key + '" value="' + key + '">' + key.padEnd(18,' ') + device[key].name + "</option>\n";
}
document.getElementById('devicefilter').innerHTML=code;
}
function initial() {
set_FreshJR_mod_vars();
get_devicenames(); //used for printing name next to IP
populate_devicefilter(); //used to populate drop down filter
show_menu();
refreshRate = document.getElementById('refreshrate').value;
deviceFilter = document.getElementById('devicefilter').value;
get_data();
//draw_conntrack_table(); get_data() already draws table
if (qos_mode == 0){ //if QoS is invalid
document.getElementById('filter_device').style.display = "none";
document.getElementById('tracked_connections').style.display = "none";
document.getElementById('refresh_data').style.display = "none";
}
$.ajax({
url: "Main_DHCPStatus_Content.asp",
success: function(result){
result = result.match(/leasearray=([\s\S]*?);/);
if (result[1]){
update_devicenames(eval(result[1])); //regex data string into actual array
}
}
});
}
function get_qos_class(category, appid) {
var i, j, catlist, rules;
if ((category == 0 && appid == 0) || (qos_mode != 2))
return 7;
for (i = 0; i < bwdpi_app_rulelist_row.length - 2; i++) {
rules = bwdpi_app_rulelist_row[i];
if (i == 0)
rules += ",18,19";
else if (i == 4)
rules += ",28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43";
else if (i == 5)
rules += ",12";
catlist = rules.split(",");
for (j = 0; j < catlist.length; j++) {
if (catlist[j] == category) {
return i;
}
}
}
return 7;
}
function compIPV6(input) {
input = input.replace(/\b(?:0+:){2,}/, ':');
return input.replace(/(^|:)0{1,4}/g, ':');
}
function create_rule(Proto, Lport, Rport, Lip, Rip, Mark, Dst){
var rule =[]; //user rule in specific format later used for quick evaluation
//rule[0]=enabled filters flag (8bit)
//rule[1]=protocol
//rule[2]=Local port inverse match (!) bool
//rule[3]=Local port start
//rule[4]=Local port end
//rule[5]=Local port multimatch array
//rule[6]=Remote port inverse match (!) bool
//rule[7]=Remote port start
//rule[8]=Remote port end
//rule[9]=Remote port multimatch array
//rule[10]=Local IP inverse match (!) bool
//rule[11]=Local IP start
//rule[12]=Local IP end
//rule[13]=Remote IP inverse match (!) bool
//rule[14]=Remote IP start
//rule[15]=Remote IP end
//rule[16]=Mark (General Category Match)
//rule[17]=Mark (Specific Traffic Match)
//rule[18]=QoS Destination
rule[0]=0;
if (Dst) rule[18]=bwdpi_app_rulelist_row.indexOf(cat_id_array[Dst].toString());
Proto = Proto.toLowerCase();
if ( Proto )
{
rule[1]=Proto;
if( Lport )
{
if(Lport.startsWith("!")) {
rule[2]=1;
Lport=Lport.replace("!", "");
}
if(Lport.includes(",")) {
rule[0]+=4;
rule[5]=Lport.split(",").map(Number);;
}
else if (Lport.includes(":")) {
rule[0]+=1;
rule[3]=parseInt(Lport.split(':')[0]);
rule[4]=parseInt(Lport.split(':')[1]);
}
else{
rule[0]+=1;
rule[3]=parseInt(Lport);
rule[4]=rule[3];
}
}
if( Rport )
{
if(Rport.startsWith("!")) {
rule[6]=1;
Rport=Rport.replace("!", "");
}
if(Rport.includes(",")) {
rule[0]+=8;
rule[9]=Rport.split(",").map(Number);;
}
else if (Rport.includes(":")) {
rule[0]+=2;
rule[7]=parseInt(Rport.split(':')[0]);
rule[8]=parseInt(Rport.split(':')[1]);
}
else{
rule[0]+=2;
rule[7]=parseInt(Rport);
rule[8]=rule[7];
}
}
}
if ( Lip )
{
rule[0]+=16;
if(Lip.startsWith("!")) {
rule[10]=1;
Lip=Lip.replace("!", "");
}
if(Lip.includes("/")) {
rule[11]=cidr_start(Lip);
rule[12]=cidr_end(Lip);
}
else{
rule[11]=ip2dec(Lip);
rule[12]=rule[11];
}
}
if ( Rip )
{
rule[0]+=32;
if(Rip.startsWith("!")) {
rule[13]=1;
Rip=Rip.replace("!", "");
}
if(Rip.includes("/")) {
rule[14]=cidr_start(Rip);
rule[15]=cidr_end(Rip);
}
else{
rule[14]=ip2dec(Rip);
rule[15]=rule[14];
}
}
if ( Mark.length == 6 )
{
rule[0]+=64;
rule[16]=parseInt(Mark.substr(0,2),16);
if (Mark.substr(-4) != "****")
{
rule[0]+=128;
rule[17]=parseInt(Mark.substr(-4),16);
}
}
// console.log(rule);
return rule;
};
function eval_rule(rule, CProto, CLport, CRport, CLip, CRip, CCat, CId){
//eval false if rule has no filters or destination specified
if (!rule || !rule[0] || (rule[18]==undefined) )
{
// console.log("rule is not configured");
return 0;
}
if ( rule[1] && CProto != rule[1] && rule[1] != "both" )
{
// console.log("protocol mismatch");
return 0;
}
//if rule has local/remote ports specified
if (rule[0] & 15)
{
if ((rule[0] & 15) <= 3 ) //if port rule is NOT a multiport match
{
if ( (rule[0] & 1) && !((CLport >= rule[3] && CLport <= rule[4])^(rule[2])) )
{
// console.log("local port mismatch");
return 0;
}
if ( (rule[0] & 2) && !((CRport >= rule[7] && CRport <= rule[8])^(rule[6])) )
{
// console.log("remote port mismatch");
return 0;
}
}
else if (( rule[0] & 15) == 4 ) //if port rule is ONLY a local multiport match
{
var match=false;
for (var i = 0; i < rule[5].length; i++) {
if(rule[5][i] == CLport) match=true;
}
if (rule[2]) match=!(match);
if (match == false)
{
// console.log("local multiport mismatch");
return 0;
}
}
else if (( rule[0] & 15) == 8 ) //if port rule is ONLY a remote multiport match
{
var match=false;
for (var i = 0; i < rule[9].length; i++) {
if(rule[9][i] == CRport) match=true;
}
if (rule[6]) match=!(match);
if (match == false)
{
// console.log("remote multiport mismatch");
return 0;
}
}
else
{
//console.log("improper configuration of port rule");
return 0; //false since multiport match cannot be simultanously used with other port match
}
}
// if rule has local IP specified
if ((rule[0] & 16) )
{
CLip=ip2dec(CLip);
if ( !((CLip >= rule[11] && CLip <= rule[12])^(rule[10])) )
{
// console.log("local ip mismatch");
return 0;
}
}
// if rule has remote IP specified
if (rule[0] & 32)
{
CRip=ip2dec(CRip);
if ( !((CRip >= rule[14] && CRip <= rule[15])^(rule[13])) )
{
//console.log("remote ip mismatch");
return 0;
}
}
// if rule has mark cat specified
if ( (rule[0] & 64) && (rule[16] != CCat) )
{
// console.log("category mismatch");
return 0;
}
// if rule has mark id specified
if ( (rule[0] & 128) && (rule[17] != CId) )
{
// console.log("traffic ID mismatch");
return 0;
}
// console.log("rule matches current connection");
return 1;
}
function redraw() {
var code;
switch (qos_mode) {
case 0: // Disabled
document.getElementById('dl_tr').style.display = "none";
document.getElementById('ul_tr').style.display = "none";
document.getElementById('no_qos_notice').style.display = "";
return;
case 3: // Bandwith Limiter
document.getElementById('dl_tr').style.display = "none";
document.getElementById('ul_tr').style.display = "none";
document.getElementById('limiter_notice').style.display = "";
return;
case 1: // Traditional
document.getElementById('dl_tr').style.display = "none";
document.getElementById('tqos_notice').style.display = "";
break;
case 2: // Adaptive
if (pie_obj_dl != undefined) pie_obj_dl.destroy();
var ctx_dl = document.getElementById("pie_chart_dl").getContext("2d");
tcdata_lan_array.sort(function(a, b) {
return a[0] - b[0]
});
code = draw_chart(tcdata_lan_array, ctx_dl, "dl");