-
Notifications
You must be signed in to change notification settings - Fork 0
/
configBuilder.html
160 lines (138 loc) · 7.18 KB
/
configBuilder.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
<html>
<body>
<form>
<input type="checkbox" id="chkBabeldClear" checked="true" /> Clear Babeld<br>
<input type="checkbox" id="chkBabeldBase" checked="true" />Base Babeld Config<br>
<hr>
<h1>Add Interface</h1>
Interface:<input type="textbox" id="txtInterface" value="eth0"><br>
<input type="checkbox" id="chkBabeldInterface" checked="true" />Look for BABELD nodes on this interface<br>
<input type="checkbox" id="chkBabeldRedistributeInterface" checked="true" />Redistribute IPS on this
interface<br>
<input type="checkbox" id="chkBabeldRedistributeInterfaceLocal" checked="true" />Limit to LOCAL ips on this
interface<br>
<input type="checkbox" id="chkConfigure" checked="true" />Set an IP for this interface<br>
OpenWRT Name<input type="textbox" id="txtOpenwrtName" value="lan"><br>
Protocol:
Dynamic <input type='radio' name='rdoProtocol' id='rdoProtocolDynamic' value='Dynamic'>
Static <input type='radio' name='rdoProtocol' id='rdoProtocolStatic' value='Static' checked="true"><br>
<input type="checkbox" id="chkSubnet" checked="true" />Extend Subnet to DHCP Clients on interface<br>
IPv4:<input type="textbox" id="txtIPv4" value="10.10.0.1"><input type="button" onclick="updateIPv6()"
value="GenerateIPv6" /><br>
IPv6:<input type="textbox" id="txtIPv6" value=""><br>
<input type="button" onclick="UpdateScript()" value="Build">
</form>
<div id="result1"
style='border:1px solid black; padding:10px; display:inline-block; width:45%; vertical-align:top;'>
</div>
<div id="result2" style='border:1px solid black; padding:10px;display:inline-block; width:45%; vertical-align:top;'>
</div>
<script>
function UpdateScript() {
var res = "<pre>";
var res2 = "<pre>";
if (document.getElementById("chkBabeldClear").checked) {
res += 'echo "package babeld" > /etc/config/babeld \n';
res2 += 'cat <<"EOF" > /etc/babeld.conf \n';
} else {
res2 += 'cat <<"EOF" >> /etc/babeld.conf \n';
}
var scriptInterface = "";
if (document.getElementById("chkBabeldBase").checked) {
res += 'uci delete babeld.general.general\n';
res += 'uci set babeld.general="general"\n';
res += 'uci set babeld.general.local_port="999"\n';
res += 'uci set babeld.general.log_file="/var/log/babeld.log"\n';
res2 += 'local_port 999\n';
res2 += 'log_file "/var/log/babeld.log"\n';
}
var Interface = document.getElementById("txtInterface").value;
if (document.getElementById("chkBabeldInterface").checked) {
res += 'uci delete babeld.' + Interface + '\n';
res += 'uci set babeld.' + Interface + '="interface"\n';
res += 'uci set babeld.' + Interface + '.ifname="' + Interface + '"\n';
res2 += 'interface ' + Interface + '\n';
}
var onlyLocal = document.getElementById("chkBabeldRedistributeInterfaceLocal").checked;
if (document.getElementById("chkBabeldRedistributeInterface").checked) {
res += 'uci delete babeld.redist_' + Interface + '\n';
res += 'uci set babeld.redist_' + Interface + '="filter"\n';
res += 'uci set babeld.redist_' + Interface + '.type="redistribute"\n';
res += 'uci set babeld.redist_' + Interface + '.if="' + Interface + '"\n';
res += 'uci set babeld.redist_' + Interface + '.action="metric 128"\n';
var localKeyword = '';
if (onlyLocal) {
res += 'uci set babeld.redist_' + Interface + '.local="true"\n';
localKeyword = ' local ';
}
res2 += 'redistribute ' + localKeyword + 'if ' + Interface + '\n';
}
var wrtName = document.getElementById("txtOpenwrtName").value;
var IPv4 = document.getElementById("txtIPv4").value;
var IPv6 = document.getElementById("txtIPv6").value;
var Proto = document.querySelector('input[name="rdoProtocol"]:checked').value;
var netMask = "255.255.255.255";
var netMaskV6 = "/128";
if (document.getElementById("chkSubnet").checked) {
netMask = "255.255.255.0";
netMaskV6 = "/64";
}
if (document.getElementById("chkConfigure").checked) {
res += 'uci delete network.interface.' + wrtName + '\n';
res += 'uci set network.' + wrtName + '="interface"\n';
res += 'uci set network.' + wrtName + '.ifname="' + Interface + '"\n';
if (Proto == "Dynamic") {
res += 'uci set network.' + wrtName + '.proto="dhcp"\n';
}
if (Proto == "Static") {
res += 'uci set network.' + wrtName + '.proto="static"\n';
res += 'uci set network.' + wrtName + '.ipaddr="' + IPv4 + '"\n';
res += 'uci set network.' + wrtName + '.netmask="' + netMask + '"\n';
res += 'uci set network.' + wrtName + '.ip6addr="' + IPv6 + '' + netMaskV6 + '"\n';
if (netMaskV6 == "/64') {
res += 'uci set network.' + wrtName + '.ip6gw="' + IPv6 + '"\n';
}
}
scriptInterface += "EOF\n";
scriptInterface += 'echo <<"EOF"> /etc/network/interfaces.d/' + Interface + "\n";
scriptInterface += "auto " + Interface + "\n";
if (Proto == "Dynamic") {
scriptInterface += "iface " + Interface + " inet dhcp\n";
}
if (Proto == "Static") {
scriptInterface += "iface " + Interface + " inet static\n";
scriptInterface += "address " + IPv4 + "\n";
scriptInterface += "netmask " + netMask + "\n";
}
scriptInterface += "iface " + Interface + " inet6 static\n"
scriptInterface += "address " + IPv6 + netMaskV6 + "\n";
}
/*
res += '';
res += '';
*/
res += "uci commit\n</pre>";
res2 += scriptInterface;
res2 += "EOF\n</pre>";
document.getElementById("result1").innerHTML = res;
document.getElementById("result2").innerHTML = res2;
}
function updateIPv6() {
var IPv4 = document.getElementById("txtIPv4").value;
var IPv6 = document.getElementById("txtIPv6").value;
var v = IPv4.split(".");
backhaul = 69;
if (v[0] == "100") {
backhaul = 68;
}
hex1 = Number(v[1]).toString(16);
if (hex1.length == 1) hex1 = '0' + hex1;
hex2 = Number(v[2]).toString(16);;
if (hex2.length == 1) hex2 = '0' + hex2;
var res = "FD74:6F6D:73" + backhaul + ":" + hex1 + hex2 + "::1";
res = res.toLowerCase();
document.getElementById("txtIPv6").value = res;
}
</script>
</body>
</html>