forked from jackyaz/YazDHCP
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdvanced_DHCP_Content.asp
More file actions
2819 lines (2554 loc) · 96.3 KB
/
Advanced_DHCP_Content.asp
File metadata and controls
2819 lines (2554 loc) · 96.3 KB
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">
<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>LAN - DHCP Server - Enhanced by YazDHCP</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="device-map/device-map.css">
<style>
thead.collapsible-jquery {
color: white;
padding: 0px;
width: 100%;
border: none;
text-align: left;
outline: none;
cursor: pointer;
}
.sort_border {
position: relative;
cursor: pointer;
}
.sort_border:before {
content: "";
position: absolute;
width: 100%;
left: 0;
border-top: 1px solid #FC0;
top: 0;
}
.sort_border.decrease:before {
bottom: 0;
top: initial;
}
.SettingsTable .invalid {
background-color: darkred !important;
}
</style>
<script language="JavaScript" type="text/javascript" src="/js/jquery.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/httpApi.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/d3.js"></script>
<script language="JavaScript" type="text/javascript" src="/state.js"></script>
<script language="JavaScript" type="text/javascript" src="/general.js"></script>
<script language="JavaScript" type="text/javascript" src="/popup.js"></script>
<script language="JavaScript" type="text/javascript" src="/help.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/detect.js"></script>
<script language="JavaScript" type="text/javascript" src="/client_function.js"></script>
<script language="JavaScript" type="text/javascript" src="/validator.js"></script>
<script language="JavaScript" type="text/javascript" src="/base64.js"></script>
<script>
/**----------------------------------------**/
/** Modified by Martinski W. [2025-Nov-01] **/
/**----------------------------------------**/
const actionScriptPrefix = "start_YazDHCP";
/**----------------------------------------------**/
/** Added/Modified by Martinski W. [2023-Jan-28] **/
/**----------------------------------------------**/
/** The DHCP Lease Time values can be given in: **/
/** seconds, minutes, hours, days, or weeks. **/
/** Single '0' or 'I' indicates "infinite" value.**/
/** For NVRAM the "infinite" value (in secs.) is **/
/** 1092 days (i.e. 156 weeks, or ~=3 years). **/
/**----------------------------------------------**/
const theDHCPLeaseTime=
{
uiLabel: 'Lease time',
yazCustomTag: 'DHCP_LEASE',
minVal: 120, minStr: '2 minutes',
maxVal: 7776000, maxStr: '90 days',
infiniteTag: 'I', infiniteSecs: 94348800,
errorMsg: function(formField)
{
return (`DHCP Lease Time value "${formField.value}" is not between ${this.minVal} and ${this.maxVal} seconds (${this.minStr} to ${this.maxStr}).`);
},
hintMsg: function()
{
return (`DHCP Lease Time in seconds: ${this.minVal} (${this.minStr}) to ${this.maxVal} (${this.maxStr}). A single '0' or 'I' indicates an "infinite" lease time.`);
},
ConvertToSeconds: function(theValue)
{
let timeUnits, timeFactor, timeNumber;
const valueFormat0 = /^0+/;
const valueFormat1 = /^[0-9]{1,7}$/;
const valueFormat2 = /^[0-9]{1,6}[smhdw]{1}$/;
if (theValue == '0' || theValue == this.infiniteTag)
{ return this.infiniteSecs; }
if (valueFormat0.test(theValue))
{ return -1; }
if (valueFormat1.test(theValue))
{
timeUnits = 's';
timeNumber = theValue;
}
else if (valueFormat2.test(theValue))
{
let valLen = theValue.length;
timeUnits = theValue.substring ((valLen - 1), valLen);
timeNumber = theValue.substring (0, (valLen - 1));
}
else { return -1; }
switch (timeUnits)
{
case 's': timeFactor=1; break;
case 'm': timeFactor=60; break;
case 'h': timeFactor=3600; break;
case 'd': timeFactor=86400; break;
case 'w': timeFactor=604800; break;
}
if (!valueFormat1.test(timeNumber)) { return -1; }
return (timeNumber * timeFactor);
},
ValidateLeaseValue: function(theValue)
{
let LeaseTime = this.ConvertToSeconds (theValue);
if (LeaseTime == this.infiniteSecs) { return true; }
if (LeaseTime == -1 ||
LeaseTime < this.minVal || LeaseTime > this.maxVal)
{ return false; }
else
{ return true; }
},
ValidateLeaseInput: function(formField, event)
{
const theValue = formField.value;
const valueFormat = /^[0-9]{1,6}$/;
const keyPressed = (event.keyCode ? event.keyCode : event.which);
if (validator.isFunctionButton(event)) { return true; }
if (theValue == this.infiniteTag) { return false; }
if (keyPressed == 73 && theValue.length == 0) { return true; }
if (keyPressed > 47 && keyPressed < 58 &&
(theValue.length == 0 || theValue.charAt(0) != '0' || keyPressed != 48))
{ return true; }
if (theValue.length > 0 && theValue.charAt(0) != '0' && valueFormat.test(theValue) &&
(keyPressed == 115 || keyPressed == 109 || keyPressed == 104 || keyPressed == 100 || keyPressed == 119))
{ return true; }
if (event.metaKey &&
(keyPressed == 65 || keyPressed == 67 || keyPressed == 86 || keyPressed == 88 ||
keyPressed == 97 || keyPressed == 99 || keyPressed == 118 || keyPressed == 120))
{ return true; }
else
{ return false; }
},
showHint: function()
{
let tag_name = document.getElementsByTagName('a');
for (var i=0; i<tag_name.length; i++)
{ tag_name[i].onmouseout=nd; }
return overlib(this.hintMsg(),0,0);
}
};
/**-------------------------------------**/
/** Added by Martinski W. [2023-Apr-22] **/
/**-------------------------------------**/
const WaitMsgPopupBox=
{
waitCounter: 0, waitMaxSecs: 0,
waitTimerOn: false,
waitTimerID: null,
waitMsgBox: null,
waitMsgTemp: '',
waitMsgBoxID: 'myWaitMsgPopupBoxID',
waitToCloseMsg: false,
CloseMsg: function()
{
if (this.waitToCloseMsg) { return 0; }
this.waitTimerOn = false;
this.waitCounter = 0;
this.waitMaxSecs = 0;
this.waitMsgTemp = '';
if (this.waitTimerID != null)
{
clearTimeout (this.waitTimerID);
this.waitTimerID = null;
}
if (this.waitMsgBox != null)
{ this.waitMsgBox.close(); }
},
StartMsg: function (waitMsg, msSecsWaitMax, showCounter)
{
if (this.waitTimerOn) { return; }
this.waitTimerOn = true;
this.waitCounter = 0;
this.waitMsgTemp = '';
this.waitMaxSecs = Math.round(msSecsWaitMax / 1000);
this.ShowTimedMsg (waitMsg, showCounter);
},
ShowTimedMsg: function (waitMsg, showCounter)
{
if (this.waitCounter > this.waitMaxSecs)
{
this.waitToCloseMsg = false;
this.CloseMsg();
return;
}
else if (! this.waitTimerOn) { return; }
this.waitMsgBox = document.getElementById(this.waitMsgBoxID);
if (this.waitMsgBox == null)
{
this.waitMsgBox = document.body.appendChild (document.createElement("dialog"));
this.waitMsgBox.setAttribute("id", this.waitMsgBoxID);
}
let msSecsWaitInterval = 1000;
let theWaitCounter = (this.waitCounter + 1);
if (this.waitCounter == 0) { this.waitMsgBox.close(); }
if (! showCounter)
{
if (this.waitCounter == 0)
{ this.waitMsgTemp = waitMsg + "\n >"; }
else
{ this.waitMsgTemp = this.waitMsgTemp + ">"; }
this.waitMsgBox.innerText = this.waitMsgTemp;
}
else if (showCounter)
{
this.waitMsgBox.innerText = waitMsg + ` [${theWaitCounter}]`;
}
if (this.waitCounter == 0) { this.waitMsgBox.showModal(); }
this.waitCounter = theWaitCounter;
this.waitTimerID = setTimeout (function ()
{ WaitMsgPopupBox.ShowTimedMsg (waitMsg, showCounter); }, msSecsWaitInterval);
},
ShowMsg: function (waitMsg, msSecsWait)
{
this.waitMsgBox = document.getElementById(this.waitMsgBoxID);
if (this.waitMsgBox == null)
{
this.waitMsgBox = document.body.appendChild (document.createElement("dialog"));
this.waitMsgBox.setAttribute("id", this.waitMsgBoxID);
}
this.waitMsgBox.close();
this.waitMsgBox.innerText = waitMsg;
this.waitMsgBox.showModal();
setTimeout (function () { WaitMsgPopupBox.waitMsgBox.close(); }, msSecsWait);
}
};
/**-------------------------------------**/
/** Added by Martinski W. [2023-Apr-23] **/
/**-------------------------------------**/
const AlertMsgBox=
{
alertMsgBox: null,
alertMsgBoxID: 'myAlertMsgPopupBoxID',
BuildAlertBox: function (theAlertMsg)
{
let htmlCode;
const alertMsgList = theAlertMsg.split('\n');
htmlCode = '<div name="alertMsgBox" id="myAlertMsgBox">'
+ '<div class = "message">';
for (var indx = 0; indx < alertMsgList.length; indx++)
{ htmlCode += '<p>' + alertMsgList[indx] + '</p>'; }
htmlCode += '</div>'
+ '<div style="text-align:center">'
+ '<button class="button_gen" id="myAlertBoxButton"'
+ ' style="margin-top:15px;"'
+ ' onclick="AlertMsgBox.CloseAlert();">Close</button>'
+ '</div></div>';
return (htmlCode);
},
CloseAlert: function()
{
if (this.alertMsgBox != null) { this.alertMsgBox.close(); }
},
ShowAlert: function (theAlertMsg)
{
this.alertMsgBox = document.getElementById(this.alertMsgBoxID);
if (this.alertMsgBox == null)
{
this.alertMsgBox = document.body.appendChild (document.createElement("dialog"));
this.alertMsgBox.setAttribute("id", this.alertMsgBoxID);
}
this.alertMsgBox.close();
this.alertMsgBox.innerHTML = this.BuildAlertBox (theAlertMsg);
this.alertMsgBox.showModal();
}
};
/**----------------------------------------**/
/** Modified by Martinski W. [2023-Apr-24] **/
/**----------------------------------------**/
const customUserIcons=
{
backupOp: false,
restoreOp: false,
varPrefix: 'Icons_',
theUserIconsOrigDir: '/jffs/usericon',
theUserIconsSavedDir: 'INIT',
theUserIconsSavedPath: 'NONE',
theUserIconsSavedFile: 'NONE',
theBackupFilePathList: [],
theBackupFilePathIndex: 0,
theBackupFileSelectFormID: 'myBackupFileSelectForm',
theBackupFileSelectDialogID: 'myBackupFileSelectDialog',
maxTries: 4, numTries: 0, initState: true,
enableBackupButton: false,
enableRestoreButton: false,
backupOKMsg: 'Custom user icon files were successfully saved to',
restoreOKMsg: 'Custom user icon files were successfully restored from',
configWaitMsg: 'Getting data, please wait...',
backupWaitMsg: 'Saving icon files, please wait...',
getListWaitMsg: 'Getting list of backup files, please wait...',
restoreWaitMsg: 'Restoring icon files, please wait...',
backupErrorMsg: 'ERROR: Custom user icon files were not saved.',
backupEnabledMsg: function()
{ return (`Back up user icons found in the directory:\n"${this.theUserIconsOrigDir}"\n`); },
backupDisabledMsg: function()
{ return (`No user icons found in the directory:\n"${this.theUserIconsOrigDir}"\n`); },
restoreErrorMsg1: 'ERROR: Custom user icon backup list was not found.',
restoreErrorMsg2: 'ERROR: Custom user icon files were not restored.',
restoreEnabledMsg: function()
{ return (`Restore user icons from a backup file found in the directory:\n"${this.theUserIconsSavedDir}"\n`); },
restoreDisabledMsg: function()
{ return (`No backup files found in the directory:\n"${this.theUserIconsSavedDir}"\n`); }
};
/**-------------------------------------**/
/** Added by Martinski W. [2023-Jan-28] **/
/**-------------------------------------**/
function Validate_DHCP_LeaseTime (formField)
{
if (!theDHCPLeaseTime.ValidateLeaseValue (formField.value))
{
formField.focus();
$(formField).addClass('invalid');
$(formField).on('mouseover',function(){return overlib(theDHCPLeaseTime.errorMsg(formField),0,0);});
$(formField)[0].onmouseout = nd;
return false;
}
else
{
$(formField).removeClass('invalid');
$(formField).off('mouseover');
return true;
}
}
/**----------------------------------------**/
/** Modified by Martinski W. [2025-Sep-05] **/
/**----------------------------------------**/
var custom_settings;
function LoadCustomSettings()
{
custom_settings = <% get_custom_settings(); %>;
for (var prop in custom_settings)
{
if (Object.prototype.hasOwnProperty.call(custom_settings, prop))
{
if (prop.indexOf("yazdhcp_") === -1)
{
eval("delete custom_settings."+prop)
}
}
}
let dataLength = JSON.stringify(custom_settings).length;
let diffLength = (totalMaxLength - (dataLength + padCushnLength));
if (diffLength > formxMaxLength)
{ apiMaxLength = formxMaxLength; }
else
{ apiMaxLength = diffLength; }
}
$(function(){
if(amesh_support && (isSwMode("rt") || isSwMode("ap")) && ameshRouter_support){
addNewScript('/require/modules/amesh.js');
}
});
/**----------------------------------------**/
/** Modified by Martinski W. [2024-Jun-27] **/
/**----------------------------------------**/
let theProductID = '<% nvram_get("productid"); %>';
theProductID = theProductID.toUpperCase();
let firmVerStr = '<% nvram_get("firmver"); %>';
let firmVerNum = parseFloat(firmVerStr.replace(/\./g,""));
let fwBuildStr = '<% nvram_get("buildno"); %>';
let fwBuildNum = parseFloat(fwBuildStr);
var foundActiveGuestNetworks = false;
var allowGuestNet_IP_Reservation = false;
var guestNetwork_SubnetInfoArray = [];
let gnColorArray =
[ {Backgrnd: '#FFE4B5', Foregrnd: 'black'},
{Backgrnd: '#90EE90', Foregrnd: 'black'},
{Backgrnd: '#87CEFA', Foregrnd: 'black'},
{Backgrnd: '#FFB6C1', Foregrnd: 'black'},
{Backgrnd: '#FFA07A', Foregrnd: 'black'},
{Backgrnd: '#FFE4E1', Foregrnd: 'black'},
{Backgrnd: '#F0E68C', Foregrnd: 'black'},
{Backgrnd: '#7FFFD4', Foregrnd: 'black'},
{Backgrnd: '#EE82EE', Foregrnd: 'black'},
{Backgrnd: '#ADFF2F', Foregrnd: 'black'},
{Backgrnd: '#F5DEB3', Foregrnd: 'black'},
{Backgrnd: '#F4A460', Foregrnd: 'black'},
{Backgrnd: '#DB7093', Foregrnd: 'black'},
{Backgrnd: '#8FBC8F', Foregrnd: 'black'},
{Backgrnd: '#20B2AA', Foregrnd: 'black'},
{Backgrnd: '#D8BFD8', Foregrnd: 'black'}
];
let gnBackgrndColor = '';
let gnForegrndColor = '';
/**----------------------------------------**/
/** ORIGINAL: ~6.346KB = 6498 [+ 1694]
/**----------------------------------------**/
const totalMaxLength = 8192;
const formxMaxLength = 7680;
const initlMaxLength = 7092;
const padCushnLength = 200;
const defAvrgInputLen = 55;
var apiMaxLength = initlMaxLength;
var maxNumRows = 128;
let isInitialLoading = false;
var vpnc_dev_policy_list_array = [];
var vpnc_dev_policy_list_array_ori = [];
var dhcp_staticlist_array = [];
var manually_dhcp_list_array = [];
var manually_dhcp_list_array_ori = [];
var dhcp_hostnames_array = [];
var manually_dhcp_hosts_array = [];
if(pptpd_support){
var pptpd_clients = '<% nvram_get("pptpd_clients"); %>';
var pptpd_clients_subnet = pptpd_clients.split(".")[0]+"."
+pptpd_clients.split(".")[1]+"."
+pptpd_clients.split(".")[2]+".";
var pptpd_clients_start_ip = parseInt(pptpd_clients.split(".")[3].split("-")[0]);
var pptpd_clients_end_ip = parseInt(pptpd_clients.split("-")[1]);
}
var dhcp_enable = '<% nvram_get("dhcp_enable_x"); %>';
var pool_start = '<% nvram_get("dhcp_start"); %>';
var pool_end = '<% nvram_get("dhcp_end"); %>';
var pool_subnet = pool_start.split(".")[0]+"."+pool_start.split(".")[1]+"."+pool_start.split(".")[2]+".";
var pool_start_end = parseInt(pool_start.split(".")[3]);
var pool_end_end = parseInt(pool_end.split(".")[3]);
var lan_domain_ori = '<% nvram_get("lan_domain"); %>';
var dhcp_gateway_ori = '<% nvram_get("dhcp_gateway_x"); %>';
var dhcp_dns1_ori = '<% nvram_get("dhcp_dns1_x"); %>';
var dhcp_dns2_ori = '<% nvram_get("dhcp_dns2_x"); %>';
var dhcp_wins_ori = '<% nvram_get("dhcp_wins_x"); %>';
var static_enable = '<% nvram_get("dhcp_static_x"); %>';
if(yadns_support){
var yadns_enable = '<% nvram_get("yadns_enable_x"); %>';
var yadns_mode = '<% nvram_get("yadns_mode"); %>';
}
var backup_mac = "";
var backup_ip = "";
var backup_dns = "";
var backup_name = "";
var sortfield, sortdir;
var sorted_array = [];
/**---------------------------------------**/
/** Ported by Martinski W. [2023-Jun-13] **/
/** For IPv6 DNS support (from 388.X ASP) **/
/**---------------------------------------**/
var ipv6_proto_orig = httpApi.nvramGet(["ipv6_service"]).ipv6_service;
function SelectedFile(){
var fileList = event.target.files;
var filename = fileList[0].name.split('.')[0];
var fileext = fileList[0].name.substring(fileList[0].name.indexOf('.')+1);
if(filename != "DHCP_clients" && fileext != "csv"){
alert("Filename must be DHCP_clients.csv");
$("#fileImportDHCPClients").val('');
}
else{
var fileReader = new FileReader();
fileReader.addEventListener('load',LoadedFile,false);
fileReader.readAsText(fileList[0]);
}
}
function LoadedFile()
{
var dataResult = [];
var fileResult = event.target.result.split('\n');
fileResult.shift();
for(var i=0; i < fileResult.length; i++){
var obj = {};
if(fileResult[i] == ""){
continue;
}
var splitstring = fileResult[i].split(',');
obj["MAC"] = splitstring[0].replace(/[\x00-\x1F\x7F-\x9F]/g, "");
obj["IP"] = splitstring[1].replace(/[\x00-\x1F\x7F-\x9F]/g, "");
obj["HOSTNAME"] = splitstring[2].replace(/[\x00-\x1F\x7F-\x9F]/g, "");
obj["DNS"] = splitstring[3].replace(/[\x00-\x1F\x7F-\x9F]/g, "");
dataResult.push(obj);
}
ParseCSVData(dataResult);
PageSetup();
alert("CSV import complete.\nPlease check the Manual Assignment table.\nTo save the imported data, click Apply at the bottom of the page.");
$("#fileImportDHCPClients").val('');
}
function ErrorCSVExport(){
document.getElementById("aExport").href="javascript:alert(\"Error exporting CSV, please refresh the page and try again\")";
}
/**-------------------------------------**/
/** Added by Martinski W. [2025-Sep-05] **/
/**-------------------------------------**/
function SetMaxNumberOfClients(averageLength)
{
maxNumRows = Math.round(apiMaxLength / averageLength);
if (maxNumRows > 253) { maxNumRows = 253; }
document.getElementById("GWStatic").innerHTML = "Manually Assigned IP addresses in the DHCP scope (Max Limit: " + maxNumRows + ")";
}
/**----------------------------------------**/
/** Modified by Martinski W. [2025-Sep-05] **/
/**----------------------------------------**/
function ParseCSVData(data)
{
dhcp_staticlist_array = [];
manually_dhcp_list_array = [];
manually_dhcp_list_array_ori = [];
dhcp_hostnames_array = [];
manually_dhcp_hosts_array = [];
var lanIPaddr4, lanIPaddr3, theIPaddr3;
lanIPaddr4 = document.form.lan_ipaddr.value;
lanIPaddr3 = lanIPaddr4.split(".", 3).join(".");
var csvContent = "MAC,IP,HOSTNAME,DNS\n";
var settingslength = 0;
for (var i = 0; i < data.length; i++)
{
var theIPvalue = data[i].IP;
theIPaddr3 = theIPvalue.split(".", 3).join(".");
/** Get the last octet ONLY if IP address is in the main LAN subnet range, otherwise take the full IP address **/
if (theIPaddr3 === lanIPaddr3 && document.form.lan_netmask.value === "255.255.255.0")
{ theIPvalue = data[i].IP.split(".")[3]; }
if (data[i].DNS.length > 0 && data[i].HOSTNAME.length >= 0){
settingslength+=(data[i].MAC+">"+theIPvalue+">"+data[i].HOSTNAME+">"+data[i].DNS+">").length;
}
else if (data[i].DNS.length == 0 && data[i].HOSTNAME.length > 0){
settingslength+=(data[i].MAC+">"+theIPvalue+">"+data[i].HOSTNAME+">").length;
}
else{
settingslength+=(data[i].MAC+">"+theIPvalue+">").length;
}
var dataString = data[i].MAC+","+data[i].IP+","+data[i].HOSTNAME+","+data[i].DNS;
csvContent += i < data.length-1 ? dataString + '\n' : dataString;
}
document.getElementById("aExport").href="data:text/csv;charset=utf-8," + encodeURIComponent(csvContent);
let averageSettingLength = Math.round(settingslength / data.length);
SetMaxNumberOfClients (averageSettingLength);
dhcp_hostnames_array = data.map(function(obj) {
return {
MAC: obj.MAC,
HOSTNAME: obj.HOSTNAME
}
});
for (var i = 0; i < dhcp_hostnames_array.length; i++){
var item_para = {"hostname" : dhcp_hostnames_array[i].HOSTNAME};
manually_dhcp_hosts_array[dhcp_hostnames_array[i].MAC] = item_para;
}
dhcp_staticlist_array = data.map(function(obj) {
return {
MAC: obj.MAC,
IP: obj.IP,
DNS: obj.DNS
}
});
for (var i = 0; i < dhcp_staticlist_array.length; i++)
{
var item_para = {
"mac" : dhcp_staticlist_array[i].MAC.toUpperCase(),
"dns" : dhcp_staticlist_array[i].DNS,
"hostname" : (manually_dhcp_hosts_array[dhcp_staticlist_array[i].MAC] == undefined) ? "" : manually_dhcp_hosts_array[dhcp_staticlist_array[i].MAC].hostname,
"ip" : dhcp_staticlist_array[i].IP
};
manually_dhcp_list_array[dhcp_staticlist_array[i].IP] = item_para;
manually_dhcp_list_array_ori[dhcp_staticlist_array[i].IP] = item_para;
}
}
function PageSetup()
{
showtext(document.getElementById("LANIP"), '<% nvram_get("lan_ipaddr"); %>');
if((inet_network(document.form.lan_ipaddr.value) >= inet_network(document.form.dhcp_start.value)) && (inet_network(document.form.lan_ipaddr.value) <= inet_network(document.form.dhcp_end.value))){
document.getElementById('router_in_pool').style.display="";
}
else if(dhcp_staticlist_array.length > 0){
for(var i = 0; i < dhcp_staticlist_array.length; i++){
var static_ip = dhcp_staticlist_array[i].IP;
if(static_ip == document.form.lan_ipaddr.value){
document.getElementById('router_in_pool').style.display="";
}
}
}
if(((sortfield = cookie.get('dhcp_sortcol')) != null) && ((sortdir = cookie.get('dhcp_sortmet')) != null)){
sortfield = parseInt(sortfield);
sortdir = parseInt(sortdir) * -1;
}
else{
sortfield = 1;
sortdir = -1;
}
sortlist(sortfield);
setTimeout(showdhcp_staticlist, 100);
setTimeout("showDropdownClientList('setClientIP', 'mac>ip', 'all', 'ClientList_Block_PC', 'pull_arrow', 'all');", 1000);
if(pptpd_support){
var chk_vpn = check_vpn();
if(chk_vpn == true){
document.getElementById("VPN_conflict").style.display = "";
document.getElementById("VPN_conflict_span").innerHTML = "* In conflict with the VPN server settings:" + pptpd_clients;
}
}
}
/**-------------------------------------**/
/** Added by Martinski W. [2023-Apr-22] **/
/**-------------------------------------**/
var theButtonBackStyle = null;
function SetButtonGenState (buttonID, enableState, titleStr)
{
if (enableState)
{
document.getElementById(buttonID).disabled = false;
document.getElementById(buttonID).title = titleStr;
if (theButtonBackStyle != null)
{ document.getElementById(buttonID).style.background = theButtonBackStyle; }
}
else
{
if (document.getElementById(buttonID).disabled == false)
{ theButtonBackStyle = document.getElementById(buttonID).style.background; }
document.getElementById(buttonID).disabled = true;
document.getElementById(buttonID).title = titleStr;
document.getElementById(buttonID).style.background = "grey";
}
}
function SetBackUpIconsButtonState (enableState)
{
let titleStr;
if (enableState)
{ titleStr = customUserIcons.backupEnabledMsg(); }
else if (customUserIcons.backupOp)
{ titleStr = customUserIcons.backupWaitMsg; }
else
{ titleStr = customUserIcons.backupDisabledMsg(); }
SetButtonGenState ('BackupIconsBtn', enableState, titleStr);
}
function SetRestoreIconsButtonState (enableState)
{
let titleStr;
if (enableState)
{ titleStr = customUserIcons.restoreEnabledMsg(); }
else if (customUserIcons.restoreOp)
{ titleStr = customUserIcons.restoreWaitMsg; }
else
{ titleStr = customUserIcons.restoreDisabledMsg(); }
SetButtonGenState ('RestoreIconsBtn', enableState, titleStr);
}
/**-------------------------------------**/
/** Added by Martinski W. [2023-Apr-22] **/
/**-------------------------------------**/
function FileSelectionHandler (fileSelDialog)
{
if (fileSelDialog.returnValue == "FileSelSubmitButton")
{
fileSelDialog.returnValue = "SUBMIT";
let fileSelForm = document.getElementById(customUserIcons.theBackupFileSelectFormID);
let selectIndex = fileSelForm.backupFilePath.selectedIndex;
const theFileIndex = customUserIcons.theBackupFilePathIndex;
if (theFileIndex > 0)
{
customUserIcons.numTries = 0;
customUserIcons.restoreOp = true;
WaitMsgPopupBox.StartMsg (customUserIcons.restoreWaitMsg, 10000, false);
let actionScriptVal = actionScriptPrefix + 'restoreIcons_reqNum_' + theFileIndex;
document.formScriptActions.action_script.value = actionScriptVal;
document.formScriptActions.submit();
setTimeout(GetCustomUserIconsStatus, 5000);
}
else
{
alert ("INVALID selection.");
ShowBackupFileSelectorDialog();
}
}
else if (fileSelDialog.returnValue == "SUBMIT")
{
customUserIcons.numTries = 0;
customUserIcons.restoreOp = true;
customUserIcons.enableRestoreButton = false;
}
else
{
customUserIcons.numTries = 0;
customUserIcons.enableRestoreButton = true;
SetRestoreIconsButtonState (customUserIcons.enableRestoreButton);
setTimeout(GetCustomUserIconsConfig, 500);
}
}
function GetFileSelectionIndex (formInput)
{
let selectIndex = formInput.selectedIndex;
let selectValue = formInput[selectIndex].value;
let selectTextS = formInput[selectIndex].text;
customUserIcons.theBackupFilePathIndex = formInput.selectedIndex;
}
function BuildBackupFileSelectorDialog()
{
let htmlCode;
htmlCode = '<form method="dialog" name="myFileSelectForm" '
+ 'id="' + customUserIcons.theBackupFileSelectFormID + '">'
+ '<h3>Select one of the backup files listed below:</h3>'
+ '<p> <label>'
+ '<select name="backupFilePath" id="myBackupFilePath" onchange="GetFileSelectionIndex(this);" required>';
for (var indx = 0; indx < customUserIcons.theBackupFilePathList.length; indx++)
{
htmlCode += '<option value="' + indx + '">'
+ customUserIcons.theBackupFilePathList[indx][0] + '</option>';
}
htmlCode += '</select> </label> </p>'
+ '<menu>'
+ '<button type="cancel" class="button_gen" id="myFileSelCancelBtn"'
+ ' style="margin-left:-10px; margin-top:10px" value="FileSelCancelButton">Cancel</button>'
+ '<button type="submit" class="button_gen" id="myFileSelSubmitBtn"'
+ ' style="margin-left:20px; margin-top:10px" value="FileSelSubmitButton">OK</button>'
+ '</menu> </form>';
return (htmlCode);
}
function ShowBackupFileSelectorDialog()
{
let fileSelDialog = document.getElementById(customUserIcons.theBackupFileSelectDialogID);
if (fileSelDialog == null)
{
fileSelDialog = document.body.appendChild (document.createElement("dialog"));
fileSelDialog.setAttribute("id", customUserIcons.theBackupFileSelectDialogID);
fileSelDialog.addEventListener("close", () =>
{ FileSelectionHandler (fileSelDialog); });
}
customUserIcons.theBackupFilePathIndex = 0;
fileSelDialog.returnValue = "NONE";
fileSelDialog.innerHTML = BuildBackupFileSelectorDialog();
fileSelDialog.showModal();
}
function GetCustomUserIconsBackupList()
{
$.ajax({
url: '/ext/YazDHCP/CustomUserIconsBackupList.htm',
dataType: 'text',
error: function(xhr)
{
if (customUserIcons.numTries < customUserIcons.maxTries)
{
customUserIcons.numTries += 1;
setTimeout(GetCustomUserIconsBackupList, 2000);
return false;
}
WaitMsgPopupBox.CloseMsg();
AlertMsgBox.ShowAlert (customUserIcons.restoreErrorMsg1);
customUserIcons.numTries = 0;
customUserIcons.restoreOp = false;
customUserIcons.enableRestoreButton = true;
SetBackUpIconsButtonState (customUserIcons.enableBackupButton);
SetRestoreIconsButtonState (customUserIcons.enableRestoreButton);
setTimeout(GetCustomUserIconsConfig, 1000);
},
success: function(data)
{
var fileList = data.split('\n');
fileList = fileList.filter(Boolean);
let fileCount = fileList.length;
let commentStart;
customUserIcons.theBackupFilePathList = [];
for (var indx = 0; indx < fileCount; indx++)
{
commentStart = fileList[indx].indexOf('#');
if (commentStart != -1) {continue;}
customUserIcons.theBackupFilePathList.push ([`${fileList[indx]}`]);
}
WaitMsgPopupBox.CloseMsg();
customUserIcons.numTries=0;
if (customUserIcons.theBackupFilePathList.length == 0)
{
AlertMsgBox.ShowAlert (customUserIcons.restoreErrorMsg1);
setTimeout(GetCustomUserIconsConfig, 1000);
}
else
{
setTimeout(ShowBackupFileSelectorDialog, 100);
}
}
});
}
function GetCustomUserIconsStatus()
{
$.ajax({
url: '/ext/YazDHCP/CustomUserIconsStatus.htm',
dataType: 'text',
error: function(xhr)
{
if (customUserIcons.numTries < customUserIcons.maxTries)
{
customUserIcons.numTries += 1;
setTimeout(GetCustomUserIconsStatus, 2000);
return false;
}
WaitMsgPopupBox.CloseMsg();
if (customUserIcons.restoreOp)
{ AlertMsgBox.ShowAlert (customUserIcons.restoreErrorMsg2); }
else if (customUserIcons.backupOp)
{ AlertMsgBox.ShowAlert (customUserIcons.backupErrorMsg); }
customUserIcons.numTries = 0;
customUserIcons.backupOp = false;
customUserIcons.restoreOp = false
SetBackUpIconsButtonState (customUserIcons.enableBackupButton);
SetRestoreIconsButtonState (customUserIcons.enableRestoreButton);
setTimeout(GetCustomUserIconsConfig, 1000);
},
success: function(data)
{
var settings = data.split('\n');
settings = settings.filter(Boolean);
let linesCount = settings.length;
let theVarName, commentStart, theMsge="";
let theSetting, settingName, settingValue="";
customUserIcons.theUserIconsSavedPath = 'NONE';
customUserIcons.theUserIconsSavedFile = 'NONE';
for (var i = 0; i < linesCount; i++)
{
theVarName = settings[i].match(`^${customUserIcons.varPrefix}`);
commentStart = settings[i].indexOf('#');
if (commentStart != -1 || theVarName == null) { continue; }
theSetting = settings[i].split('=');
settingName = theSetting[0];
settingValue = theSetting[1];
switch (settingName)
{
case `${customUserIcons.varPrefix}DIRP`:
if (settingValue != "")
{ customUserIcons.theUserIconsSavedPath = settingValue; }
break;
case `${customUserIcons.varPrefix}FILE`:
if (settingValue != "")
{ customUserIcons.theUserIconsSavedFile = settingValue; }
break;
case `${customUserIcons.varPrefix}RESTD`:
if (! customUserIcons.restoreOp) { break; }
if (settingValue == "NONE")
{
customUserIcons.theUserIconsSavedPath = 'NONE';
customUserIcons.theUserIconsSavedFile = 'NONE';
customUserIcons.enableRestoreButton = false;
}
else
{
customUserIcons.enableBackupButton = true;
customUserIcons.enableRestoreButton = true;
}
break;
case `${customUserIcons.varPrefix}SAVED`:
if (! customUserIcons.backupOp) { break; }
if (settingValue == "NONE")
{
customUserIcons.theUserIconsSavedPath = 'NONE';
customUserIcons.theUserIconsSavedFile = 'NONE';
customUserIcons.enableRestoreButton = false;
}
else
{
customUserIcons.enableBackupButton = true;
customUserIcons.enableRestoreButton = true;
}
break;
}
}
if (customUserIcons.restoreOp)
{
if (customUserIcons.theUserIconsSavedFile == 'NONE')
{ theMsge = customUserIcons.restoreErrorMsg2; }
else
{
theMsge = `${customUserIcons.restoreOKMsg}` +
`\nFolder:\n<b>${customUserIcons.theUserIconsSavedPath}</b>` +
`\nFilename:\n<b>${customUserIcons.theUserIconsSavedFile}</b>\n`;
}
}
else if (customUserIcons.backupOp)
{
if (customUserIcons.theUserIconsSavedFile == 'NONE')
{ theMsge = customUserIcons.backupErrorMsg; }
else
{
theMsge = `${customUserIcons.backupOKMsg}` +
`\nFolder:\n<b>${customUserIcons.theUserIconsSavedPath}</b>` +
`\nFilename:\n<b>${customUserIcons.theUserIconsSavedFile}</b>\n`;
}
}
WaitMsgPopupBox.CloseMsg();
if (theMsge != "") { AlertMsgBox.ShowAlert (theMsge); }
customUserIcons.numTries = 0;
customUserIcons.backupOp = false;
customUserIcons.restoreOp = false;
SetBackUpIconsButtonState (customUserIcons.enableBackupButton);
SetRestoreIconsButtonState (customUserIcons.enableRestoreButton);
setTimeout(GetCustomUserIconsConfig, 1000);
}
});
}
/**----------------------------------------**/
/** Modified by Martinski W. [2025-Nov-01] **/
/**----------------------------------------**/
function GetCustomUserIconsConfig()
{
$.ajax({
url: '/ext/YazDHCP/CustomUserIconsConfig.htm',
dataType: 'text',
error: function(xhr)
{
if (customUserIcons.numTries < customUserIcons.maxTries)
{
customUserIcons.numTries += 1;
WaitMsgPopupBox.StartMsg (customUserIcons.configWaitMsg, 9000, false);
setTimeout(GetCustomUserIconsConfig, 2000);
return false;
}
WaitMsgPopupBox.CloseMsg();