forked from ttgapers/cakeqos-merlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cake-qos.asp
1362 lines (1291 loc) · 47.8 KB
/
cake-qos.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">
<!--
CakeQoS v2.1.0 released 2021-08-18
-->
<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>ASUS Wireless Router - CakeQOS-Merlin</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="device-map/device-map.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="/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="/validator.js"></script>
<script type="text/javascript" src="/js/table/table.js"></script>
<script language="JavaScript" type="text/javascript" src="/base64.js"></script>
<style>
thead.collapsible-jquery {
color: white;
padding: 0px;
width: 100%;
border: none;
text-align: left;
outline: none;
cursor: pointer;
}
</style>
<script>
<% login_state_hook(); %>
var custom_settings = <% get_custom_settings(); %>;
const iptables_default_rules = "";
const iptables_default_rulenames = "";
var iptables_rulelist_array="";
var iptables_rulename_array="";
var iptables_temp_array=[];
var iptables_names_temp_array=[];
var qos_obw=<% nvram_get("qos_obw"); %>;
var qos_ibw=<% nvram_get("qos_ibw"); %>;
var qos_type = '<% nvram_get("qos_type"); %>';
if ('<% nvram_get("qos_enable"); %>' == 0) { // QoS disabled
var qos_mode = 0;
} else if (qos_type == "9") { // Cake
var qos_mode = 9;
} 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;
}
var stat_retries = 0;
/* ATM, overhead, pmu, label */
var overhead_presets = [["1", "48", "0", "Conservative default"],
["0", "42", "84", "Ethernet with VLAN"],
["0", "18", "64", "Cable (DOCSIS)"],
["0", "27", "0", "PPPoE VDSL"],
["1", "32", "0", "RFC2684/RFC1483 Bridged LLC/Snap"],
["1", "32", "0", "ADSL PPPoE VC/Mux"],
["1", "40", "0", "ADSL PPPoE LLC/Snap"],
["0", "19", "0", "VDSL Bridged/IPoE"],
["2", "30", "0", "VDSL2 PPPoE PTM"],
["2", "22", "0", "VDSL2 Bridged PTM"]
];
var cake_stats_labels = {
"threshold_rate": "Threshold Rate",
"target_us": "Target",
"interval_us": "Interval",
"peak_delay_us": "Peak Delay",
"avg_delay_us": "Average Delay",
"base_delay_us": "Sparse Delay",
"backlog_bytes": "Backlog",
"sent_packets": "Packets Sent",
"sent_bytes": "Sent",
"way_indirect_hits": "Hash Indirect Hits",
"way_misses": "Hash Misses",
"way_collisions": "Hash Collisions",
"drops": "Drops",
"ecn_mark": "ECN Marked Packets",
"ack_drops": "Dropped ACK Packets",
"sparse_flows": "Sparse Flows",
"bulk_flows": "Bulk Flows",
"unresponsive_flows": "Unresponsive Flows",
"max_pkt_len": "Max Packet Length",
"flow_quantum": "Flow Quantum"
};
/* prototype function to respect user locale number formatting for fixed decimal point numbers */
Number.prototype.toLocaleFixed = function(min, max) {
return this.toLocaleString(undefined, {
minimumFractionDigits: min,
maximumFractionDigits: max
});
};
function YazHint(hintid) {
var tag_name = document.getElementsByTagName('a');
for (var i = 0; i < tag_name.length; i++) {
tag_name[i].onmouseout = nd;
}
switch (hintid) {
case 1:
hinttext = "Select whether to shape traffic on the WAN or LAN interface. LAN interface allows for easier iptables manipulation.";
break;
case 2:
hinttext = "CAKE can divide traffic into tins based on the Diffserv field.";
break;
case 3:
hinttext = "Specify whether fairness is based on source address, destination address, individual flows, or any combination.";
break;
case 4:
hinttext = "CAKE will use the conntrack NAT table to better determine real local addresses for fairness decisions.";
break;
case 5:
hinttext = "Apply the wash option to clear all extra diffserv (but not ECN bits), after priority queuing has taken place.";
break;
case 6:
hinttext = "Remove duplicate TCP ACKs from the flow queue since only the last ACK is needed.";
break;
case 7:
hinttext = "Add any custom parameters separated by spaces. These will be appended to the end of the CAKE options and take priority over the options above. There is no validation done on these options. Use carefully!";
break;
default:
hinttext = "Help text not yet defined";
}
return overlib(hinttext, HAUTO, VAUTO);
}
function build_overhead_presets(){
var code = "";
for(var i = 0; i < overhead_presets.length; i++) {
code += '<a><div onclick="set_overhead(' + i +');">' + overhead_presets[i][3] + '</div></a>';
}
document.getElementById("overhead_presets_list").innerHTML += code;
$(".ovh_pull_arrow").show();
}
function pullOverheadList(_this) {
event.stopPropagation();
var $element = $("#overhead_presets_list");
var isMenuopen = $element[0].offsetWidth > 0 || $element[0].offsetHeight > 0;
if(isMenuopen == 0) {
$(_this).attr("src","/images/arrow-top.gif");
$element.show();
}
else {
$(_this).attr("src","/images/arrow-down.gif");
$element.hide();
}
}
function set_overhead(entry) {
var framing = overhead_presets[entry][0];
document.getElementById('qos_mpu').value = overhead_presets[entry][2];
document.getElementById('qos_overhead').value = overhead_presets[entry][1];
document.getElementById('qos_atm').value = framing;
document.getElementById("ovh_pull_arrow").src = "/images/arrow-down.gif";
document.getElementById('overhead_presets_list').style.display='none';
}
function initial() {
SetCurrentPage();
show_menu();
get_config();
build_overhead_presets();
showhide('well_known_rules_tr',(custom_settings.cakeqos_ulrules == 1 ? 1 : 0));
showhide('iptables_rules_block',(custom_settings.cakeqos_ulrules == 1 ? 1 : 0));
if (qos_mode != 9){ //if Cake is not enabled
document.getElementById('no_aqos_notice').style.display = "";
return;
}
show_iptables_rules();
well_known_rules();
submit_refresh_status();
}
tableValidator.qosPortRange = {
keyPress : function($obj,event) {
var objValue = $obj.val();
var keyPressed = event.keyCode ? event.keyCode : event.which;
if (tableValid_isFunctionButton(event)) {
return true;
}
if ((keyPressed > 47 && keyPressed < 58)) { //0~9
return true;
}
else if (keyPressed == 58 && objValue.length > 0) { // colon :
for(var i = 0; i < objValue.length; i++) {
var c = objValue.charAt(i);
if (c == ':' || c == ',')
return false;
}
return true;
}
else if (keyPressed == 33) { // exclamation !
if(objValue.length > 0 && objValue.length < $obj[0].attributes.maxlength.value && objValue.charAt(0) != '!') { // field already has value; only allow ! as first char
$obj.val('!' + objValue);
}
else if (objValue.length == 0)
return true;
return false;
}
else if (keyPressed == 44 && objValue.length > 0){ // comma ,
for(var i = 0; i < objValue.length; i++) {
var c = objValue.charAt(i);
if (c == ':')
return false;
}
return true;
}
return false;
},
blur : function(_$obj) {
var eachPort = function(num, min, max) {
if(num < min || num > max) {
return false;
}
return true;
};
var hintMsg = "";
var _value = _$obj.val();
_value = $.trim(_value);
_$obj.val(_value);
if(_value == "") {
if(_$obj.hasClass("valueMust"))
hintMsg = "Fields cannot be blank.";
else
hintMsg = HINTPASS;
}
else {
var mini = 1;
var maxi = 65535;
var PortRange = _value.replace(/^\!/g, "");
var singlerangere = new RegExp("^([0-9]{1,5})\:([0-9]{1,5})$", "gi");
var multiportre = new RegExp("^([0-9]{1,5})(\,[0-9]{1,5})+$", "gi");
if(singlerangere.test(PortRange)) { // single port range
if(parseInt(RegExp.$1) >= parseInt(RegExp.$2)) {
hintMsg = _value + " is not a valid port range!";
}
else{
if(!eachPort(RegExp.$1, mini, maxi) || !eachPort(RegExp.$2, mini, maxi)) {
hintMsg = "Please enter a value between " + mini + " to " + maxi;
}
else
hintMsg = HINTPASS;
}
}
else if (multiportre.test(PortRange)) {
var split = PortRange.split(",");
for (var i = 0; i < split.length; i++) {
if(!eachPort(split[i], mini, maxi)){
hintMsg = "Please enter a value between " + mini + " to " + maxi;
}
else
hintMsg = HINTPASS;
}
}
else {
if(!tableValid_range(PortRange, mini, maxi)) {
hintMsg = "Please enter a value between " + mini + " to " + maxi;
}
else
hintMsg = HINTPASS;
}
}
if(_$obj.next().closest(".hint").length) {
_$obj.next().closest(".hint").remove();
}
if(hintMsg != HINTPASS) {
var $hintHtml = $('<div>');
$hintHtml.addClass("hint");
$hintHtml.html(hintMsg);
_$obj.after($hintHtml);
_$obj.focus();
return false;
}
return true;
}
};
tableValidator.qosIPCIDR = { // only IP or IP plus netmask
keyPress : function($obj,event) {
var objValue = $obj.val();
var keyPressed = event.keyCode ? event.keyCode : event.which;
if (tableValid_isFunctionButton(event)) {
return true;
}
var i,j;
if((keyPressed > 47 && keyPressed < 58)){
j = 0;
for(i = 0; i < objValue.length; i++){
if(objValue.charAt(i) == '.'){
j++;
}
}
if(j < 3 && i >= 3){
if(objValue.charAt(i-3) != '!' && objValue.charAt(i-3) != '.' && objValue.charAt(i-2) != '.' && objValue.charAt(i-1) != '.'){
$obj.val(objValue + '.');
}
}
return true;
}
else if(keyPressed == 46){
j = 0;
for(i = 0; i < objValue.length; i++){
if(objValue.charAt(i) == '.'){
j++;
}
}
if(objValue.charAt(i-1) == '.' || j == 3){
return false;
}
return true;
}
else if(keyPressed == 47){
j = 0;
for(i = 0; i < objValue.length; i++){
if(objValue.charAt(i) == '.'){
j++;
}
}
if( j < 3){
return false;
}
return true;
}
else if (keyPressed == 33) { // exclamation !
if(objValue.length > 0 && objValue.length < $obj[0].attributes.maxlength.value && objValue.charAt(0) != '!') { // field already has value; only allow ! as first char
$obj.val('!' + objValue);
}
else if (objValue.length == 0)
return true;
return false;
}
return false;
},
blur : function(_$obj) {
var hintMsg = "";
var _value = _$obj.val();
_value = $.trim(_value);
_value = _value.toLowerCase();
_$obj.val(_value);
var _firstChar = _value.charAt(0);
_value = _value.replace(/^\!/g, "");
if(_value == "") {
if(_$obj.hasClass("valueMust"))
hintMsg = "Fields cannot be blank.";
else
hintMsg = HINTPASS;
}
else {
var startIPAddr = tableValid_ipAddrToIPDecimal("0.0.0.0");
var endIPAddr = tableValid_ipAddrToIPDecimal("255.255.255.255");
var ipNum = 0;
if(_value.search("/") == -1) { // only IP
ipNum = tableValid_ipAddrToIPDecimal(_value);
if(ipNum > startIPAddr && ipNum < endIPAddr) {
hintMsg = HINTPASS;
//convert number to ip address
if(_firstChar=="!")
_$obj.val(_firstChar + tableValid_decimalToIPAddr(ipNum));
else
_$obj.val(tableValid_decimalToIPAddr(ipNum));
}
else {
hintMsg = _value + " is not a valid IP address!";
}
}
else{ // IP plus netmask
if(_value.split("/").length > 2) {
hintMsg = _value + " is not a valid IP address!";
}
else {
var ip_tmp = _value.split("/")[0];
var mask_tmp = parseInt(_value.split("/")[1]);
ipNum = tableValid_ipAddrToIPDecimal(ip_tmp);
if(ipNum > startIPAddr && ipNum < endIPAddr) {
if(mask_tmp == "" || isNaN(mask_tmp))
hintMsg = _value + " is not a valid IP address!";
else if(mask_tmp == 0 || mask_tmp > 32)
hintMsg = _value + " is not a valid IP address!";
else {
hintMsg = HINTPASS;
//convert number to ip address
if(_firstChar=="!")
_$obj.val(_firstChar + tableValid_decimalToIPAddr(ipNum) + "/" + mask_tmp);
else
_$obj.val(tableValid_decimalToIPAddr(ipNum) + "/" + mask_tmp);
}
}
else {
hintMsg = _value + " is not a valid IP address!";
}
}
}
}
if(_$obj.next().closest(".hint").length) {
_$obj.next().closest(".hint").remove();
}
if(hintMsg != HINTPASS) {
var $hintHtml = $('<div>');
$hintHtml.addClass("hint");
$hintHtml.html(hintMsg);
_$obj.after($hintHtml);
_$obj.focus();
return false;
}
return true;
}
};
tableRuleDuplicateValidation = {
iptables_rule : function(_newRuleArray, _currentRuleArray) {
// Check that no 2 rules with the same values exist, ignoring the Description and Class
if(_currentRuleArray.length == 0)
return true;
else {
var newRuleArrayTemp = _newRuleArray.slice();
newRuleArrayTemp.splice(0, 1); // Remove Description
newRuleArrayTemp.splice(-1, 1); // Remove Class
for(var i = 0; i < _currentRuleArray.length; i += 1) {
var currentRuleArrayTemp = _currentRuleArray[i].slice();
currentRuleArrayTemp.splice(0, 1); // Remove Description
currentRuleArrayTemp.splice(-1, 1); // Remove Class
if(newRuleArrayTemp.toString() == currentRuleArrayTemp.toString())
return false;
}
}
return true;
}
} // tableRuleDuplicateValidation
tableRuleValidation = {
iptables_rule : function(_newRuleArray) {
if(_newRuleArray.length == 7) {
if(_newRuleArray[1] == "" && _newRuleArray[2] == "" && _newRuleArray[4] == "" && _newRuleArray[5] == "" && _newRuleArray[6] == "") {
return "Define at least one criterion for this rule!";
}
return HINTPASS;
}
}
} // tableRuleValidation
function show_iptables_rules(){
var tableStruct = {
data: iptables_temp_array,
container: "iptables_rules_block",
title: "iptables Rules",
titieHint: "Edit existing rules by clicking in the table below.<small style='float:right; font-weight:normal; color:white; margin-right:10px; cursor:pointer;' onclick='CakeQoS_reset_iptables()'>Reset</small>",
capability: {
add: true,
del: true,
clickEdit: true
},
header: [
{
"title" : "Name",
"width" : "15%"
},
{
"title" : "Local IP",
"width" : "15%"
},
{
"title" : "Remote IP",
"width" : "15%"
},
{
"title" : "Proto",
"width" : "10%"
},
{
"title" : "Local Port",
"width" : "15%"
},
{
"title" : "Remote Port",
"width" : "15%"
},
{
"title" : "Category",
"width" : "15%"
}
],
createPanel: {
inputs : [
{
"editMode" : "text",
"title" : "Rule Description",
"maxlength" : "27",
"placeholder": "Rule Description",
"validator" : "description"
},
{
"editMode" : "text",
"title" : "Local IP/CIDR",
"maxlength" : "19",
"valueMust" : false,
"placeholder": "192.168.1.100 !192.168.1.100 192.168.1.100/31 !192.168.1.100/31",
"validator" : "qosIPCIDR"
},
{
"editMode" : "text",
"title" : "Remote IP/CIDR",
"maxlength" : "19",
"valueMust" : false,
"placeholder": "9.9.9.9 !9.9.9.9 9.9.9.0/24 !9.9.9.0/24",
"validator" : "qosIPCIDR"
},
{
"editMode" : "select",
"title" : "Protocol",
"option" : {"BOTH" : "both", "TCP" : "tcp", "UDP" : "udp"}
},
{
"editMode" : "text",
"title" : "Local Port",
"maxlength" : "36",
"valueMust" : false,
"placeholder": "443 !443 1234:5678 !1234:5678 53,123,853 !53,123,853",
"validator" : "qosPortRange"
},
{
"editMode" : "text",
"title" : "Remote Port",
"maxlength" : "36",
"valueMust" : false,
"placeholder": "443 !443 1234:5678 !1234:5678 53,123,853 !53,123,853",
"validator" : "qosPortRange"
},
{
"editMode" : "select",
"title" : "Category",
"option" : { "Bulk" : "0", "Streaming" : "1", "Voice" : "2", "Conferencing" : "3", "Gaming" : "4" }
}
],
maximum: 24
},
clickRawEditPanel: {
inputs : [
{
"editMode" : "text",
"maxlength" : "27",
"styleList" : {"word-wrap":"break-word","overflow-wrap":"break-word"},
"validator" : "description"
},
{
"editMode" : "text",
"maxlength" : "19",
"valueMust" : false,
"validator" : "qosIPCIDR"
},
{
"editMode" : "text",
"maxlength" : "19",
"valueMust" : false,
"validator" : "qosIPCIDR"
},
{
"editMode" : "select",
"option" : {"BOTH" : "both", "TCP" : "tcp", "UDP" : "udp"}
},
{
"editMode" : "text",
"maxlength" : "36",
"valueMust" : false,
"validator" : "qosPortRange"
},
{
"editMode" : "text",
"maxlength" : "36",
"valueMust" : false,
"validator" : "qosPortRange"
},
{
"editMode" : "select",
"option" : { "Bulk" : "0", "Streaming" : "1", "Voice" : "2", "Conferencing" : "3", "Gaming" : "4" }
}
]
},
ruleDuplicateValidation : "iptables_rule",
ruleValidation : "iptables_rule"
}
tableApi.genTableAPI(tableStruct);
}
function get_config()
{
if ( qos_ibw == 0 && qos_obw == 0 ) {
document.getElementById('cakeqos_ibw').innerText = "Auto";
document.getElementById('cakeqos_obw').innerText = "Auto";
} else {
document.getElementById('cakeqos_ibw').innerText = (qos_ibw/1024).toFixed(2) + ' Mb/s';
document.getElementById('cakeqos_obw').innerText = (qos_obw/1024).toFixed(2) + ' Mb/s';
}
if ( custom_settings.cakeqos_ver != undefined )
document.getElementById("cakeqos_version").innerText = "v" + custom_settings.cakeqos_ver;
else
document.getElementById("cakeqos_version").innerHTML = "<span>N/A</span>";
if ( custom_settings.cakeqos_branch != undefined )
document.getElementById("cakeqos_version").innerText += " Dev";
if ( custom_settings.cakeqos_iptables == undefined ) // rules not yet converted to API format
{
iptables_rulelist_array = iptables_default_rules;
iptables_rulename_array = decodeURIComponent(iptables_default_rulenames);
}
else { // rules are migrated to new API variables
iptables_rulelist_array = custom_settings.cakeqos_iptables;
if ( custom_settings.cakeqos_iptables_names == undefined ) {
iptables_rulename_array = "";
var iptables_rulecount = iptables_rulelist_array.split("<").length;
for (var i=0;i<iptables_rulecount;i++) {
iptables_rulename_array += "<Rule " + eval(" i + 1 ");
}
}
else
iptables_rulename_array = decodeURIComponent(custom_settings.cakeqos_iptables_names);
}
if ( custom_settings.cakeqos_dlprio == undefined )
document.getElementById('cakeqos_dlprio').value = 3;
else
document.getElementById('cakeqos_dlprio').value = custom_settings.cakeqos_dlprio;
if ( custom_settings.cakeqos_ulprio == undefined )
document.getElementById('cakeqos_ulprio').value = 0;
else
document.getElementById('cakeqos_ulprio').value = custom_settings.cakeqos_ulprio;
if ( custom_settings.cakeqos_dlflowiso == undefined )
document.getElementById('cakeqos_dlflowiso').value = 6;
else
document.getElementById('cakeqos_dlflowiso').value = custom_settings.cakeqos_dlflowiso;
if ( custom_settings.cakeqos_ulflowiso == undefined )
document.getElementById('cakeqos_ulflowiso').value = 5;
else
document.getElementById('cakeqos_ulflowiso').value = custom_settings.cakeqos_ulflowiso;
if ( custom_settings.cakeqos_dlnat == undefined )
document.form.cakeqos_dlnat.value = <% nvram_match( "wan0_nat_x", "1", "1"); %>;
else
document.form.cakeqos_dlnat.value = custom_settings.cakeqos_dlnat;
if ( custom_settings.cakeqos_ulnat == undefined )
document.form.cakeqos_ulnat.value = <% nvram_match( "wan0_nat_x", "1", "1"); %>;
else
document.form.cakeqos_ulnat.value = custom_settings.cakeqos_ulnat;
if ( custom_settings.cakeqos_dlwash == undefined )
document.form.cakeqos_dlwash.value = 1;
else
document.form.cakeqos_dlwash.value = custom_settings.cakeqos_dlwash;
if ( custom_settings.cakeqos_ulwash == undefined )
document.form.cakeqos_ulwash.value = 0;
else
document.form.cakeqos_ulwash.value = custom_settings.cakeqos_ulwash;
if ( custom_settings.cakeqos_dlack == undefined )
document.form.cakeqos_dlack.value = 0;
else
document.form.cakeqos_dlack.value = custom_settings.cakeqos_dlack;
if ( custom_settings.cakeqos_ulack == undefined )
document.form.cakeqos_ulack.value = 0;
else
document.form.cakeqos_ulack.value = custom_settings.cakeqos_ulack;
if ( custom_settings.cakeqos_dlcust == undefined )
document.getElementById('cakeqos_dlcust').value = "";
else
document.getElementById('cakeqos_dlcust').value = Base64.decode(custom_settings.cakeqos_dlcust);
if ( custom_settings.cakeqos_ulcust == undefined )
document.getElementById('cakeqos_ulcust').value = "";
else
document.getElementById('cakeqos_ulcust').value = Base64.decode(custom_settings.cakeqos_ulcust);
if ( custom_settings.cakeqos_ulrules == undefined )
document.form.cakeqos_ulrules.value = 0;
else
document.form.cakeqos_ulrules.value = custom_settings.cakeqos_ulrules;
var r=0;
iptables_temp_array = iptables_rulelist_array.split("<");
var iptables_names_temp_array = iptables_rulename_array.split("<");
iptables_temp_array.shift();
iptables_names_temp_array.shift();
for (r=0;r<iptables_temp_array.length;r++){
if (iptables_temp_array[r] != "") {
iptables_temp_array[r]=iptables_temp_array[r].split(">");
if (iptables_names_temp_array[r])
iptables_temp_array[r].unshift(iptables_names_temp_array[r]);
}
}
}
function CakeQoS_reset_iptables() {
iptables_rulelist_array = iptables_default_rules;
iptables_rulename_array = decodeURIComponent(iptables_default_rulenames);
iptables_temp_array = [];
iptables_temp_array = iptables_rulelist_array.split("<");
iptables_temp_array.shift();
iptables_names_temp_array = [];
iptables_names_temp_array = iptables_rulename_array.split("<");
iptables_names_temp_array.shift();
for (r=0;r<iptables_temp_array.length;r++){
if (iptables_temp_array[r] != "") {
iptables_temp_array[r]=iptables_temp_array[r].split(">");
if (iptables_names_temp_array[r])
iptables_temp_array[r].unshift(iptables_names_temp_array[r]);
}
}
show_iptables_rules();
} // CakeQoS_reset_iptables()
function save_config_apply() {
iptables_rulelist_array = "";
iptables_rulename_array = "";
for(var i = 0; i < iptables_temp_array.length; i++) {
if(iptables_temp_array[i].length != 0) {
iptables_rulelist_array += "<";
iptables_rulename_array += "<";
for(var j = 0; j < iptables_temp_array[i].length; j++) {
if ( j == 0 )
iptables_rulename_array += encodeURIComponent(iptables_temp_array[i][j]);
else {
iptables_rulelist_array += iptables_temp_array[i][j];
if( (j + 1) != iptables_temp_array[i].length)
iptables_rulelist_array += ">";
}
}
}
}
if (iptables_rulelist_array.length > 2999) {
alert("Total iptables rules exceeds 2999 bytes! Please delete or consolidate!");
return
}
if (iptables_rulename_array.length > 2999) {
alert("Total iptables rule names exceed 2999 bytes! Please shorten or consolidate rules!");
return
}
if (iptables_rulelist_array == iptables_default_rules && iptables_rulename_array == iptables_default_rulenames) {
delete custom_settings.cakeqos_iptables;
delete custom_settings.cakeqos_iptables_names;
} else {
custom_settings.cakeqos_iptables = iptables_rulelist_array;
custom_settings.cakeqos_iptables_names = iptables_rulename_array;
}
if ( document.getElementById('cakeqos_dlprio').value == 3 )
delete custom_settings.cakeqos_dlprio;
else
custom_settings.cakeqos_dlprio = document.getElementById('cakeqos_dlprio').value;
if ( document.getElementById('cakeqos_ulprio').value == 0 )
delete custom_settings.cakeqos_ulprio;
else
custom_settings.cakeqos_ulprio = document.getElementById('cakeqos_ulprio').value;
if ( document.getElementById('cakeqos_dlflowiso').value == 6 )
delete custom_settings.cakeqos_dlflowiso;
else
custom_settings.cakeqos_dlflowiso = document.getElementById('cakeqos_dlflowiso').value;
if ( document.getElementById('cakeqos_ulflowiso').value == 5 )
delete custom_settings.cakeqos_ulflowiso;
else
custom_settings.cakeqos_ulflowiso = document.getElementById('cakeqos_ulflowiso').value;
if ( document.form.cakeqos_dlnat.value == <% nvram_match( "wan0_nat_x", "1", "1"); %> )
delete custom_settings.cakeqos_dlnat;
else
custom_settings.cakeqos_dlnat = document.form.cakeqos_dlnat.value;
if ( document.form.cakeqos_ulnat.value == <% nvram_match( "wan0_nat_x", "1", "1"); %> )
delete custom_settings.cakeqos_ulnat;
else
custom_settings.cakeqos_ulnat = document.form.cakeqos_ulnat.value;
if ( document.form.cakeqos_dlwash.value == 1 )
delete custom_settings.cakeqos_dlwash;
else
custom_settings.cakeqos_dlwash = document.form.cakeqos_dlwash.value;
if ( document.form.cakeqos_ulwash.value == 0 )
delete custom_settings.cakeqos_ulwash;
else
custom_settings.cakeqos_ulwash = document.form.cakeqos_ulwash.value;
if ( document.form.cakeqos_dlack.value == 0 )
delete custom_settings.cakeqos_dlack;
else
custom_settings.cakeqos_dlack = document.form.cakeqos_dlack.value;
if ( document.form.cakeqos_ulack.value == 0 )
delete custom_settings.cakeqos_ulack;
else
custom_settings.cakeqos_ulack = document.form.cakeqos_ulack.value;
if ( document.getElementById('cakeqos_dlcust').value == "" )
delete custom_settings.cakeqos_dlcust;
else
custom_settings.cakeqos_dlcust = Base64.encode(document.getElementById('cakeqos_dlcust').value);
if ( document.getElementById('cakeqos_ulcust').value == "" )
delete custom_settings.cakeqos_ulcust;
else
custom_settings.cakeqos_ulcust = Base64.encode(document.getElementById('cakeqos_ulcust').value);
if ( custom_settings.cakeqos_ulrules == 0 )
delete custom_settings.cakeqos_ulrules;
else
custom_settings.cakeqos_ulrules = document.form.cakeqos_ulrules.value;
/* Store object as a string in the amng_custom hidden input field */
if (JSON.stringify(custom_settings).length < 8192) {
document.getElementById('amng_custom').value = JSON.stringify(custom_settings);
document.form.action_script.value = "restart_qos;restart_firewall";
//document.form.action_script.value = "";
document.form.submit();
}
else
alert("Settings for all addons exceeds 8K limit! Cannot save!");
}
function SetCurrentPage() {
var model = '<% nvram_get("odmpid"); %>';
if ( model == "" ) model = '<% nvram_get("productid"); %>';
document.title = "ASUS Wireless Router " + model + " - CakeQOS-Merlin";
document.form.next_page.value = window.location.pathname.substring(1);
document.form.current_page.value = window.location.pathname.substring(1);
}
function GetCookie(cookiename,returntype){
var s;
if((s = cookie.get("cakeqos_"+cookiename)) != null){
return cookie.get("cakeqos_"+cookiename);
}
else{
if(returntype == "string"){
return "";
}
else if(returntype == "number"){
return 0;
}
}
}
function SetCookie(cookiename,cookievalue){
cookie.set("cakeqos_"+cookiename, cookievalue, 10 * 365);
}
function AddEventHandlers(){
$(".collapsible-jquery").off('click').on('click', function(){
$(this).siblings().toggle("fast",function(){
if($(this).css("display") == "none"){
SetCookie($(this).siblings()[0].id,"collapsed");
}
else{
SetCookie($(this).siblings()[0].id,"expanded");
}
})
});
$(".collapsible-jquery").each(function(index,element){
if(GetCookie($(this)[0].id,"string") == "collapsed"){
$(this).siblings().toggle(false);
}
else{
$(this).siblings().toggle(true);
}
});
}
function format_Cake_Stat(statname, statval) {
var usec = new RegExp("^.*_us$", "gi");
var bytes = new RegExp("^.*_bytes$", "gi");
var unit = ' B';
if (statname.match(usec)) {
if (statval >= 1000)
return ( statval / 1000 ).toLocaleFixed(0,2) + ' ms';
else
return statval.toLocaleString() + ' μs';
}
if (statname.match(bytes)) {
if (statval > 1024) {
statval = statval / 1024;
unit = " KB";
}
if (statval > 1024) {
statval = statval / 1024;
unit = " MB";
}
if (statval > 1024) {
statval = statval / 1024;
unit = " GB";
}
return statval.toLocaleFixed(0,2) + unit;
}
if (statname == 'threshold_rate')
return ( statval * 8 / 1000 ).toLocaleString() + ' Kbit';
return statval.toLocaleString();
}
function generate_Cake_StatsTable(cake_stats_object, dir){
var code = '';
var lastUpdated = new Date(cake_statstime*1000);
code +='<table width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#6b8fa3" class="FormTable_table">';
code += '<thead class="collapsible-jquery" id="dl_status"><tr><td colspan="' + ( cake_stats_object.tins.length + 1 ) + '">Cake ' + dir + ' Statistics (click to expand/collapse)<small style="float:right;font-weight:normal;">Last Updated: ' + lastUpdated.toLocaleDateString() + ' ' + lastUpdated.toLocaleTimeString() + '</small></td></tr></thead>';
code += '<tr><th></th>';
switch (cake_stats_object.tins.length) {
case 3:
code += '<th width="26%">Bulk</th><th width="27%">Best Effort</th><th width="27%">Voice</th>';
break;
case 4:
code += '<th width="20%">Bulk</th><th width="20%">Best Effort</th><th width="20%">Video</th><th width="20%">Voice</th>';
break;
default:
for (var i=0;i<cake_stats_object.tins.length;i++)
code += '<th width="' + ( 80 / cake_stats_object.tins.length ) +'%">Tin ' + i + '</th>';
break;
}
code += '</tr>';
for (const key in cake_stats_labels) {
code += '<tr><th title="' + key + '">' + cake_stats_labels[key] + '</th>';
for (var i=0;i<cake_stats_object.tins.length;i++) {
code += '<td title="' + cake_stats_object.tins[i][key] + '">' + format_Cake_Stat(key, cake_stats_object.tins[i][key]) + '</td>';
}
code += '</tr>';
}
code += '</table>';
return code;
}
function refresh_Cake_StatsInfo(){
var lastUpdated = new Date(cake_statstime*1000);
var code='<table width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#6b8fa3" class="FormTable_table">';
code += '<thead class="collapsible-jquery" id="qdisc_status"><tr><td colspan="3">Cake Current Status (click to expand/collapse)<small style="float:right;font-weight:normal;">Last Updated: ' + lastUpdated.toLocaleDateString() + ' ' + lastUpdated.toLocaleTimeString() + '</small></td></tr></thead>';
code += '<tr><th width="34%"></th>';
code += '<th width="33%">Download</th>';
code += '<th width="33%">Upload</th></tr>';
code += '<tr><th>Bandwidth (Mb/s)</th><td>' + ( cake_download_stats.options.bandwidth * 8 / 1024000 ).toLocaleFixed(2,2) + '</td><td>' + ( cake_upload_stats.options.bandwidth * 8 / 1024000 ).toLocaleFixed(2,2) + '</td></tr>';
code += '<tr><th>Priority Queue</th><td>' + cake_download_stats.options.diffserv + '</td><td>' + cake_upload_stats.options.diffserv + '</td></tr>';
code += '<tr><th>Flow Isolation</th><td>' + cake_download_stats.options.flowmode + '</td><td>' + cake_upload_stats.options.flowmode + '</td></tr>';
code += '<tr><th>NAT</th><td>' + ( cake_download_stats.options.nat ? 'Yes' : 'No' ) + '</td><td>' + ( cake_upload_stats.options.nat ? 'Yes' : 'No' ) + '</td></tr>';
code += '<tr><th>Wash</th><td>' + ( cake_download_stats.options.wash ? 'Yes' : 'No' ) + '</td><td>' + ( cake_upload_stats.options.wash ? 'Yes' : 'No' ) + '</td></tr>';
code += '<tr><th>Ingress</th><td>' + ( cake_download_stats.options.ingress ? 'ingress' : 'egress' ) + '</td><td>' + ( cake_upload_stats.options.ingress ? 'ingress' : 'egress' ) + '</td></tr>';
code += '<tr><th>ACK Filter</th><td>' + cake_download_stats.options["ack-filter"] + '</td><td>' + cake_upload_stats.options["ack-filter"] + '</td></tr>';
code += '<tr><th>Split GSO</th><td>' + ( cake_download_stats.options["split_gso"] ? 'Yes' : 'No' ) + '</td><td>' + ( cake_upload_stats.options["split_gso"] ? 'Yes' : 'No' ) + '</td></tr>';
code += '<tr><th>Rount Trip Time (ms)</th><td>' + ( cake_download_stats.options.rtt / 1000 ) + '</td><td>' + ( cake_upload_stats.options.rtt / 1000 ) + '</td></tr>';
code += '<tr><th>Overhead</th><td>' + cake_download_stats.options.overhead + '</td><td>' + cake_upload_stats.options.overhead + '</td></tr>';
code += '<tr><th>ATM</th><td>' + cake_download_stats.options.atm + '</td><td>' + cake_upload_stats.options.atm + '</td></tr>';
code += '<tr><th>MPU</th><td>' + cake_download_stats.options.mpu + '</td><td>' + cake_upload_stats.options.mpu + '</td></tr>';
code += '</table>';
code += generate_Cake_StatsTable(cake_download_stats, "Download");
code += generate_Cake_StatsTable(cake_upload_stats, "Upload");
return code;
}
function update_cake_status(){
$.ajax({
url: '/ext/cake-qos/cake_status.js',
dataType: 'script',
timeout: 3000,
error: function(xhr){
if ( stat_retries < 5 ) {
setTimeout('update_cake_status();', 3000);
stat_retries++;
} else {
stat_retries = 0;
document.getElementById("cake_status_check").disabled = false;
document.getElementById('cakeqos_status').innerHTML='<div style="font-size: 125%; color: rgb(255, 204, 0);">Timeout retrieving Cake stats. Try again later.</div>';
}
},
success: function(){
stat_retries = 0;
document.getElementById("cake_status_check").disabled = false;