-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopt43.html
277 lines (259 loc) · 9.78 KB
/
opt43.html
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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/tom-select.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/tom-select.complete.min.js"></script>
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="icon" type="image/x-icon" href="images/favicon.ico" />
<link rel="icon" type="image/png" href="images/favicon-32x32.png" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>
DHCP Option 43 Generator for Wireless LAN Controllers
</title>
</head>
<body>
<fieldset>
<legend>DHCP Option 43 Generator for Wireless LAN Controllers</legend>
<div class="container">
<form>
<!-- select a wireless controller -->
<div id="wlcItems" class="row">
<div class="col-25">
<label for="wlcList">Wireless Controller:</label>
</div>
<div class="col-75">
<select id="wlcList" onchange="updateForm();">
<option value="vsz">Ruckus SmartZone/Virtual SmartZone</option>
<option value="zd">Ruckus ZoneDirector</option>
<option value="cisco">Cisco WLC</option>
<option value="unifi">Unifi Controller/Cloud Key</option>
<option value="fortiold">Fortinet (Old)</option>
<option value="fortinew">Fortinet (New/CAPWAP)</option>
<option value="cambium">Cambium cnMaestro</option>
<option value="aruba">Aruba</option>
</select>
</div>
</div>
<br>
<!-- select a firewall -->
<div id="fwItems" class="row">
<div class="col-25">
<label for="fwList">DHCP Server:</label>
</div>
<div class="col-75">
<select id="fwList" onchange="updateForm();">
<option value="sonicwall">SonicWall</option>
<option value="asa">Cisco ASA</option>
<option value="ndx">Nomadix</option>
<option value="win">Windows</option>
<option value="juniper">Juniper SRX</option>
<option value="pfsense">pfSense/opnSense (enter as "String")</option>
</select>
</div>
</div>
<div id="ip" class="row">
<br>
<!-- enter list of ip addresses -->
<div class="col-25">
<label for="ipAddr">IP Address(es) (separate multiple IPs by comma):</label>
</div>
<div class="col-75">
<input type="text" id="ipAddr" placeholder="10.0.0.1,10.0.0.2,..." onKeyUp="updateForm();" />
</div>
</div>
</form>
</div>
</fieldset>
<hr>
<!-- This will eventually be split apart, using info parsed from the form -->
<div class="container">
<div class="row">
IP Address(es):
<b id='ipAddressString'></b>
</div>
<div class="row">
Option 43:
<b id='Opt43String'></b>
</div>
<div class="row" id="cliString"></div>
</div>
<hr>
<div class="container">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png" /></a>
<br />
<p style="font-family:courier";"font-size:6px">
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title" style="font-family:courier";"font-size:6px">DHCP Option 43 Calculator</span> by <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName" style="font-family:courier";"font-size:6px">William Hill</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/" style="font-family:courier";"font-size:6px">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
<br />
Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://r2d2.mu-world.net/opt43.html" rel="dct:source" style="font-family:courier";"font-size:6px">http://r2d2.mu-world.net/opt43.html</a>.
</p>
</div>
<script>
function updateForm() {
var wlcSelect = document.getElementById("wlcList");
var wlcValue = wlcSelect.value;
var wlcType = wlcSelect.options[wlcSelect.selectedIndex].text;
var fwSelect = document.getElementById("fwList");
var fwValue = fwSelect.value;
var fwType = fwSelect.options[fwSelect.selectedIndex].text;
var ipValue = document.getElementById('ipAddr').value;
ipValue = ipValue.replace(/\s+/g, '');
var ipTruncValue = removeTrailingComma(ipValue);
var newIp;
var ipLen = ipTruncValue.length;
var ipQuantity = ipValue.split(",").length;
var ipQuanValue = (decimalToHex((ipQuantity * 4),2));
// Determine vendor ID of WLC
switch (wlcValue) {
case "zd":
var vendorId = "03";
break;
case "vsz":
var vendorId = "06";
break;
case "cisco":
var vendorId = "f1";
break;
case "unifi":
var vendorId = "01";
break;
default:
var vendorId = "No data found";
}
// Convert IP from ASCII to hex (not for Cisco WLCs)
const convertToHex = (ip = '') => {
const res = [];
const { length: len } = ip;
for (let n = 0, l = len; n < l; n ++) {
const hex = Number(ip.charCodeAt(n)).toString(16);
res.push(hex);
};
return res.join('');
}
// IP Validation functions
function ipValidation(ip) {
const validateIp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
return validateIp.test(ip);
}
function allIpsValid(ipAddrs) {
var validIpArray = ipAddrs.split(',');
validIpFilter = validIpArray.filter(function(e) { return e});
return validIpFilter.every(element => ipValidation(element));
}
function ipValidList(ipAddrList) {
var validIpList = ipAddrList.split(',');
const returnValidIp = [];
for (let valIpNum = 0; valIpNum < validIpList.length; valIpNum++) {
const validIpRes = validIpList[valIpNum];
if (ipValidation(validIpRes)) {
returnValidIp.push(validIpRes);
} else if (!validIpRes) {
} else {
returnValidIp.push("<font color='red'>" + validIpRes + " (INVALID)</font>");
}
}
return returnValidIp.join(', ');
}
// Convert decimal to hex, pad each byte to 2 characters
function decimalToHex(d, padding) {
var hex = Number(d).toString(16);
padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
while (hex.length < padding) {
hex = "0" + hex;
}
return hex;
}
// Cisco devices expect the IP's decimal value converted to hex
// This function will individually convert each IP entered, and then combine the results into a single string
function ciscoIpArray(ipElem) {
ipArray = ipElem.split(',');
const ciscoIpRes = [];
for (let ipNum = 0; ipNum < ipArray.length; ipNum++) {
const ciscoIpResult = ciscoIpASA(ipArray[ipNum]);
ciscoIpRes.push(ciscoIpResult);
}
return ciscoIpRes.join('');
}
// Calculate hex value of the IP address for Cisco WLCs
function ciscoIpASA(ciscoIp) {
var [ciscoOctet1,ciscoOctet2,ciscoOctet3,ciscoOctet4] = ciscoIp.split('.');
return decimalToHex(ciscoOctet1,2) + decimalToHex(ciscoOctet2,2) + decimalToHex(ciscoOctet3,2) + decimalToHex(ciscoOctet4,2);
}
// Take the string and parse it to a Sonicwall-usable format (i.e. 0x<hex> and separated by semicolon)
function parseForSonicwall(string) {
var parseString = string.split(/(..)/g).filter(s => s);
const sonicwallHex = [];
for (let i = 0; i < parseString.length; i++) {
const sonicwallRes = parseString[i];
sonicwallHex.push("0x" + sonicwallRes);
}
return sonicwallHex.join(';');
}
// Take the string and parse it to a Windows-usable format (space-separated)
function parseForWindows(string) {
var parseString = string.split(/(..)/g).filter(s => s);
const windowsHex = [];
for (let i = 0; i < parseString.length; i++) {
const windowsRes = parseString[i];
windowsHex.push(windowsRes);
}
return windowsHex.join(' ');
}
// Take the string and parse it to a pfSense/opnSense-usable format (colon-separated)
function parseForpfSense(string) {
var parseString = string.split(/(..)/g).filter(s => s);
const pfsenseHex = [];
for (let i = 0; i < parseString.length; i++) {
const pfsenseRes = parseString[i];
pfsenseHex.push(pfsenseRes);
}
return pfsenseHex.join(':');
}
function removeTrailingComma(value) {
if (value.endsWith(',')) {
return value.slice(0, -1);
}
return value;
}
// Generate the complete option 43 hex string based on the WLC type
if (allIpsValid(ipValue)) {
switch (wlcValue) {
case "cisco":
case "unifi":
var opt43Result = vendorId + ipQuanValue + ciscoIpArray(removeTrailingComma(ipValue));
break;
case "vsz":
case "zd":
var opt43Result = vendorId + decimalToHex(ipLen) + convertToHex(removeTrailingComma(ipValue));
break;
default:
var opt43Result = "No data found.";
}
// Determine the firewall type to know if the hex values need the escape characters for each byte (i.e. Sonicwall)
switch (fwValue) {
case "sonicwall":
document.getElementById('Opt43String').innerHTML = parseForSonicwall(opt43Result);
break;
case "asa":
document.getElementById('Opt43String').innerHTML = opt43Result;
document.getElementById('cliString').innerHTML = 'CLI Command: <b>option 43 hex ' + opt43Result + '</b>';
break;
case "ndx":
document.getElementById('Opt43String').innerHTML = "0x" + opt43Result;
break;
case "pfsense":
document.getElementById('Opt43String').innerHTML = parseForpfSense(opt43Result);
break;
case "win":
document.getElementById('Opt43String').innerHTML = parseForWindows(opt43Result);
break;
default:
document.getElementById('Opt43String').innerHTML = "No data found.";
}
} else {
document.getElementById('Opt43String').innerHTML = "You entered an invalid IP address. Please check your entries and submit again."
}
document.getElementById('ipAddressString').innerHTML = ipValidList(ipValue);
}
</script>
</body>
</html>