-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
196 lines (185 loc) · 7.78 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css">
<title>Mikrotik Wireguard Config Generator</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
</head>
<body>
<section class="section">
<div id="app" class="container">
<div class="columns">
<div class="column">
<h2 class="title">Mikrotik Wireguard Config Generator</h2>
<div class="buttons">
<button class="button is-primary" @click="updateclients">Generate</button>
<button class="button is-warning" v-if="!dlbuttonshidden" @click="downloadclients">Download Client Config</button>
<button class="button is-info" v-if="!dlbuttonshidden" @click="downloadqrcodes">Download Client QR Codes</button>
</div>
<article class="panel">
<table class="table">
<tr>
<td>Server:<br> <input v-model="server"></td>
<td>Port:<br> <input v-model="port"></td>
<td>Interface Name:<br> <input v-model="interfacename"></td>
</tr>
<tr>
<td>Net:<br> <input v-model="network" size="8"> </td>
<td>1stIP:<br> <input v-model="startip" size="1"></td>
<td>Clients:<br> <input v-model="clientcount" size="3"></td>
</tr>
<tr>
<td>Allowed Net(s):<br> <input v-model="allowednets" size="40"></td>
<td>DNS:<br> <input v-model="dns" size="20"></td>
</tr>
<tr>
<td colspan="3">ServerPrivateKey:<br> <input v-model="serverkeys.privateKey" size="50"></td>
</tr>
<tr>
<td colspan="3">ServerPublicKey:<br> <input v-model="serverkeys.publicKey" size="50"></td>
</tr>
</table>
</article>
<article class="panel">
<p class="panel-heading">Server config {{ server }}:{{ port }}</p>
<p class="panel-block" >
<code style="font-size:small;"><span @click="select">
/interface wireguard<br>
add listen-port={{ port }} mtu=1420 name={{interfacename}} private-key="{{ serverkeys.privateKey }}"<br><br>
/ip firewall filter<br>
add action=accept chain=input comment="Allow Wireguard from All" dst-port={{port}} protocol=udp<br>
add action=accept chain=input comment="Allow DNS from Wireguard Users" dst-port=53 in-interface={{interfacename}} protocol=udp<br><br>
/ip address <br>
add address={{ network }}.1/24 comment="Wireguard Interface" interface={{ interfacename }} network={{ network }}.0<br><br>
/interface wireguard peers<br>
<span v-for="line in oldconfig">{{ line }}<br></span>
<span v-for="(value, client) in clients"><br>
add allowed-address={{ network }}.{{ client }}/32 comment="{{ value.name }}" endpoint-address={{ network }}.{{ client }} interface={{interfacename}} public-key="{{ value.publicKey }}" preshared-key="{{ value.preSharedKey }}"<br>
</span>
</span>
</code>
</p>
</article>
</div>
<div class="column">
<article class="panel">
<p class="panel-heading">Client configs (first ip: {{network}}.{{startip}}, count: {{ clientcount }})</p>
<div class="panel-block" v-for="(value, client) in clients">
<canvas :id="'canvas'+client"></canvas>
<div>
<input v-model="value.name">
<code class="panel-block clients-code" style="font-size:small;" :id="'code'+client"><span @click="select">[Interface]<br>
## {{ value.name }}<br>
Address = {{ network }}.{{ client }}/32<br>
PrivateKey = {{ value.privateKey }}<br>
DNS = {{ dns }} <br>
[Peer]<br>
PublicKey = {{ serverkeys.publicKey }}<br>
PreSharedKey = {{ value.preSharedKey }}<br>
AllowedIPs = {{ network }}.1/32,{{allowednets}} <br>
Endpoint = {{ server }}:{{ port }}<br>
PersistentKeepalive = 10<br>
</span></code>
</div>
</div>
</article>
</div>
</div>
</div>
</section>
<script src="https://unpkg.com/vue@2.6.12/dist/vue.js"></script>
<script src="https://unpkg.com/qrcode@1.4.4/build/qrcode.min.js"></script>
<script src="https://unpkg.com/jszip@3.10.1/dist/jszip.min.js"></script>
<script src="https://unpkg.com/file-saver@2.0.5/dist/FileSaver.min.js"></script>
<script src="wireguard.js"></script>
<script>
new Vue({
el: "#app",
data() {
return {
server: "vpn.yournet.it",
port: 13231,
network: "172.22.0",
startip: 2,
clientcount: 3,
allowednets: "192.168.1.0/24,192.168.0.0/24",
dns:"172.22.0.1",
interfacename:"wg0",
oldconfig: [],
clients: {},
modalactive: null,
dlbuttonshidden:true,
serverkeys: wireguard.generateKeypair()
};
},
methods: {
select(event) {
r = document.createRange(); r.selectNode(event.target.closest("span"));
s = window.getSelection(); s.removeAllRanges(); s.addRange(r);
},
updateclients(event) {
this.clients = this.makeclients;
var clients = this.clients;
this.dlbuttonshidden=false;
setTimeout(function() {
for (client in clients) {
QRCode.toCanvas(document.getElementById('canvas' + client), document.getElementById('code' + client).innerText)
}
});
},
downloadclients(event) {
zip = new JSZip();
for (i=this.startip; i<parseInt(this.startip)+parseInt(this.clientcount); i++ ) {
var blob = new Blob(
[
"[Interface]\n",
"## "+this.clients[i].name+"\n",
"Address = "+this.network+"."+i+"/32\n",
"PrivateKey = "+this.clients[i].privateKey+"\n",
"DNS = "+this.dns+"\n\n",
"[Peer]\n",
"PublicKey = "+this.serverkeys.publicKey+"\n",
"PreSharedKey = "+this.clients[i].preSharedKey+"\n",
"AllowedIPs = "+this.network+".1/32,"+this.allowednets+"\n",
"Endpoint = "+this.server+":"+this.port+"\n",
"PersistentKeepalive = 10"
],
{
type: "text/plain;charset=utf-8;",
}
);
zip.file(this.clients[i].name+".conf", blob);
}
zip.generateAsync({ type: "blob" }).then(function(content) {
saveAs(content, "clients.zip");
});
},
downloadqrcodes(event) {
for (w=this.startip; w<this.startip+this.clientcount; w++ ) {
var canvas = document.getElementById("canvas"+w);
download(canvas,this.clients[w].name)
}
}
},
computed: {
makeclients() {
var c = {};
for (client in [...Array(Math.floor(this.clientcount)).keys()]) {
finaloctet = Math.floor(client) + Math.floor(this.startip);
c[finaloctet] = wireguard.generateKeypair();
c[finaloctet].name = "Client_" + finaloctet;
}
return c
}
}
});
function download(canvas,name,w) {
canvas.toBlob(function(blob,w) {
saveAs(blob,name+".png");
})
}
</script>
</body>
</html>