-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.html
475 lines (402 loc) · 18.7 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DigitalOcean VPN Setup</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/pure/0.6.0/pure-min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:200,400">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<style type="text/css">
body {
font-family: "Raleway", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #777;
}
.header {
font-family: "Raleway", "Helvetica Neue", Helvetica, Arial, sans-serif;
max-width: 768px;
margin: 0 auto;
padding: 1em;
text-align: center;
border-bottom: 1px solid #eee;
letter-spacing: 0.05em;
}
.footer {
font-family: "Raleway", "Helvetica Neue", Helvetica, Arial, sans-serif;
max-width: 768px;
margin: 0 auto;
padding: 1em;
text-align: center;
border-top: 1px solid #eee;
font-size: 80%;
font-weight: 200;
}
h1 {
font-size: 320%;
font-weight: 200;
color: rgb(75, 75, 75);
}
h2 {
font-size: 128%;
font-weight: 200;
color: #666;
}
.content {
max-width: 420px;
margin: 48px auto;
}
p {
text-align: center;
margin: 1.4em auto;
}
input[type=text], input[type=password], select {
width: 220px;
}
.spinner {
width: 40px;
height: 40px;
margin: 60px auto 48px;
background-color: #333;
border-radius: 100%;
-webkit-animation: sk-scaleout 1.0s infinite ease-in-out;
animation: sk-scaleout 1.0s infinite ease-in-out;
}
@-webkit-keyframes sk-scaleout {
0% { -webkit-transform: scale(0) }
100% {
-webkit-transform: scale(1.0);
opacity: 0;
}
}
@keyframes sk-scaleout {
0% {
-webkit-transform: scale(0);
transform: scale(0);
} 100% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
opacity: 0;
}
}
.ion-ios-checkmark-outline {
font-size: 320%;
}
pre {
border-radius: 0.4em;
border: 1px solid #eee;
padding: 0.5em
}
.active-0, .active-1, .active-2, .active-3 {
display: none;
}
.state-0 .active-0,.state-1 .active-1,.state-2 .active-2,.state-3 .active-3 {
display: block;
}
@media only screen and (max-width: 480px) {
form {
width: 220px;
margin: 0 auto;
}
pre {
margin-left: 1em;
margin-right: 1em;
}
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55331118-5', 'auto');
ga('send', 'pageview');
</script>
</head>
<body class="state-0">
<div class="header">
<h1>DigitalOcean VPN</h1>
<h2>Automatically setup a private VPN server on a DigitalOcean Droplet.</h2>
</div>
<div class="content">
<p class="active-0">Log in with DigitalOcean to get started:</p>
<p class="active-0">
<a class="pure-button pure-button-primary" href="https://cloud.digitalocean.com/v1/oauth/authorize?client_id=b7050abbbd4b73c243292736073bb9638d75e63c1ef1429abb60b51698d31f62&redirect_uri=http://dovpn.carlfriess.com/&response_type=token&scope=read%20write
">
Log in with DigitalOcean
</a>
</p>
<p class="active-1">Just need a few more details about the server:</p>
<form class="pure-form pure-form-aligned active-1">
<fieldset>
<div class="pure-control-group">
<label for="region">Region</label>
<select id="region"></select>
</div>
<div class="pure-controls">
<label for="random" class="pure-checkbox">
<input id="random" type="checkbox" checked> Generate login details:
</label>
</div>
<div class="pure-control-group">
<label for="username">Username</label>
<input id="username" type="text" placeholder="Username">
</div>
<div class="pure-control-group">
<label for="password">Password</label>
<input id="password" type="password" placeholder="Password">
</div>
<div class="pure-control-group">
<label for="psk">IPsec PSK</label>
<input id="psk" type="password" placeholder="Pre-Shared Key">
</div>
<p><a id="create-vpn" class="pure-button pure-button-primary" href="#">Create VPN Server</a></p>
</fieldset>
</form>
<div class="spinner active-2"></div>
<p id="progressMsg" class="active-2">Creating droplet...</p>
<p class="active-3"><i class="ion-ios-checkmark-outline"></i></p>
<p class="active-3">All done! Your VPN server is ready to go!</p>
<pre class="active-3">
L2TP over IPsec VPN Server:
===========================
IP-Address: <span id="setup-ip"></span>
Username: <span id="setup-username"></span>
Password: <span id="setup-password"></span>
IPsec PSK: <span id="setup-psk"></span></pre>
<p class="active-3">
<button id="show-logs" class="pure-button">Show Logs</button>
<a id="config-link" class="pure-button pure-button-primary" href="#" download="config.networkConnect">
<i class="ion-android-download"></i>
Download configuration (Mac)
</a>
</p>
<pre id="log" class="active-2 hidden"></pre>
</div>
<div class="footer">
<p>This tool will create a Basic 1 GB / 1 CPU Droplet in your DigitalOcean account and install a VPN server using this <a href="https://github.com/hwdsl2/setup-ipsec-vpn" target="_blank">script</a>. It may take several minutes until the installation is complete, so be patient. ;)</p>
<a href="https://www.digitalocean.com/?refcode=85a8c72ff6ef&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge"><img src="https://web-platforms.sfo2.digitaloceanspaces.com/WWW/Badge%202.svg" alt="DigitalOcean Referral Badge" /></a>
</div>
<!--
Github Corner by Tim Holman
https://tholman.com/github-corners/
-->
<a href="https://github.com/carlfriess/DigitalOceanVPNSetup" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<script type="text/javascript">
let token;
if (location.protocol === "https:") {
location.href = "http://dovpn.carlfriess.com";
}
function randomString(length) {
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const randoms = crypto.getRandomValues(new Uint8Array(length));
return [].slice.call(randoms).map(v => possible.charAt(v % possible.length)).join("");
}
function encryptNetworkConnect(cleartext) {
while (cleartext.length % 12 != 0) {
cleartext += String.fromCharCode(0);
}
var decryption_key = [0x7d, 0x89, 0x52, 0x23, 0xd2, 0xbc, 0xdd, 0xea, 0xa3, 0xb9, 0x1f];
var i = 0;
var cryptotext = "";
for (var j = 0, len = cleartext.length; j < len; j++) {
cryptotext += String.fromCharCode(cleartext.charCodeAt(j) ^ decryption_key[i]);
i++;
i %= decryption_key.length;
}
return btoa(cryptotext);
}
function setState(nextState) {
document.body.className = document.body.className.replace(/state-\d/, "state-" + nextState);
}
function setLoginValues() {
if (document.getElementById("random").checked) {
document.getElementById("username").value = "vpnuser";
document.getElementById("password").value = randomString(24);
document.getElementById("psk").value = randomString(24);
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("psk").disabled = true;
}
else {
document.getElementById("username").value = "";
document.getElementById("password").value = "";
document.getElementById("psk").value = "";
document.getElementById("username").disabled = false;
document.getElementById("password").disabled = false;
document.getElementById("psk").disabled = false;
}
}
document.getElementById("random").onchange = setLoginValues;
function xhrStandardCallback(xhr) {
if (xhr.readyState === 4 && xhr.status === 401) {
token = null;
setState(0);
}
else if (xhr.readyState === 4) {
try {
const res = JSON.parse(xhr.responseText);
alert(`An error occurred! Please refresh the page!\n\n${ res.message }\n(${ res.id })`);
} catch (e) {
alert("An error occurred! Please refresh the page!");
}
}
}
function waitForBoot(config) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const res = JSON.parse(xhr.responseText);
if (res.droplet.status !== "active") {
setTimeout(() => waitForBoot(config), 5000);
}
else {
document.getElementById("progressMsg").innerHTML = "Waiting for droplet...";
config.ip = res.droplet.networks.v4[0].ip_address;
waitForInstall(config);
}
}
else xhrStandardCallback(xhr);
};
xhr.open("GET", "https://api.digitalocean.com/v2/droplets/" + config.id, true);
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send()
}
function waitForInstall(config) {
let connected = false;
let done = false;
const ws = new WebSocket(`ws://${config.ip}/`);
ws.onopen = () => {
connected = true;
document.getElementById("progressMsg").innerHTML = "Installing VPN server...";
document.getElementById("log").classList.remove("hidden");
};
ws.onclose = () => {
if (!connected) {
setTimeout(() => waitForInstall(config), 5000);
} else if (!done) {
alert("An error occurred configuring the VPN server! Please check the log.");
}
};
ws.onmessage = (e) => {
if (e.data === "<DONE>") {
done = true;
setState(3);
document.getElementById("setup-ip").innerHTML = config.ip;
document.getElementById("setup-username").innerHTML = config.username;
document.getElementById("setup-password").innerHTML = config.password;
document.getElementById("setup-psk").innerHTML = config.psk;
const xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-\/\/Apple\/\/DTD " +
"PLIST 1.0\/\/EN\" \"http:\/\/www.apple.com\/DTDs\/PropertyList-1.0.dtd\">\r\n<plist version=\"1.0\">" +
"\r\n<dict>\r\n\t<key>L2TP<\/key>\r\n\t<dict>\r\n\t\t<key>UserConfigs<\/key>\r\n\t\t<array>\r\n\t\t\t" +
"<dict>\r\n\t\t\t\t<key>EAP<\/key>\r\n\t\t\t\t<dict\/>\r\n\t\t\t\t<key>IPSec<\/key>\r\n\t\t\t\t<dict>" +
"\r\n\t\t\t\t\t<key>AuthenticationMethod<\/key>\r\n\t\t\t\t\t<string>SharedSecret<\/string>" +
"\r\n\t\t\t\t<\/dict>\r\n\t\t\t\t<key>PPP<\/key>\r\n\t\t\t\t<dict>\r\n\t\t\t\t" +
"\t<key>AuthName<\/key>\r\n\t\t\t\t\t<string>" + config.username + "<\/string>\r\n\t\t\t\t\t<key>" +
"AuthPasswordEncryption<\/key>\r\n\t\t\t\t\t<string>Keychain<\/string>\r\n\t\t\t\t\t<key>" +
"CommRemoteAddress<\/key>\r\n\t\t\t\t\t<string>" + config.ip + "<\/string>\r\n" +
"\t\t\t\t\t<key>UserDefinedName<\/key>\r\n\t\t\t\t\t<string>DigitalOcean VPN (" +
config.region + ")<\/string>\r\n\t\t\t\t<\/dict>\r\n\t\t\t<\/dict>\r\n\t\t<\/array>\r\n\t<\/dict>" +
"\r\n<\/dict>\r\n<\/plist>\r\n";
document.getElementById("config-link").href = "data:application/octet-stream;base64," + btoa(xml);
ga('send', 'event', 'Setup', 'completed', config.region);
} else {
document.getElementById('log').textContent += `${ e.data }\n`;
}
};
}
token = window.location.href.match(/#.*access_token=([0-9|a-z|_]+)/i);
if (token && token.length >= 2) {
token = token[1];
setState(1);
setLoginValues();
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const res = JSON.parse(xhr.responseText);
const select = document.getElementById("region");
res.regions.sort(function (a,b) {
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
});
res.regions.forEach(function (region) {
if (region.available &&
region.features.indexOf("metadata") !== -1 &&
region.sizes.indexOf("s-1vcpu-1gb") !== -1) {
select.options.add(new Option(region.name, region.slug));
}
});
}
else xhrStandardCallback(xhr);
};
xhr.open("GET", "https://api.digitalocean.com/v2/regions", true);
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send()
}
document.getElementById("create-vpn").onclick = (e) => {
e.preventDefault();
const config = {
"region": document.getElementById("region").value,
"username": document.getElementById("username").value,
"password": document.getElementById("password").value,
"psk": document.getElementById("psk").value
};
if (!config.region || !config.username || !config.password || !config.psk) {
alert("Please complete all the fields!");
return;
}
ga('send', 'event', 'Setup', 'started', config.region);
setState(2);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 202) {
const res = JSON.parse(xhr.responseText);
config.id = res.droplet.id;
setTimeout(function(){ waitForBoot(config); }, 10000);
}
else xhrStandardCallback(xhr);
};
xhr.open("POST", "https://api.digitalocean.com/v2/droplets", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send(JSON.stringify({
"name": "vpn-server-" + config.region,
"region": config.region,
"size": "s-1vcpu-1gb",
"image": "ubuntu-20-04-x64",
"ssh_keys": null,
"backups": false,
"ipv6": false,
"user_data": "#!/bin/bash\n\n" +
"wget https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip\n" +
"apt install unzip\n" +
"unzip websocketd-0.4.1-linux_amd64.zip\n" +
"cat > ./install.sh << EOF\n" +
"#!/bin/bash\n\n" +
"wget https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/vpnsetup.sh -qO vpn.sh && " +
"VPN_IPSEC_PSK='" + config.psk + "' " +
"VPN_USER='" + config.username + "' " +
"VPN_PASSWORD='" + config.password + "' " +
"sh vpn.sh 2>&1 " +
"| sed -u 's/" + config.psk + "/*****/' " +
"| sed -u 's/" + config.password + "/*****/' && " +
"echo '<DONE>'\n" +
"killall websocketd\n" +
"EOF\n" +
"chmod +x install.sh\n" +
"./websocketd --port=80 ./install.sh\n" +
"rm install.sh\n",
"private_networking": null,
"volumes": null
}));
}
document.getElementById("show-logs").onclick = (e) => {
e.preventDefault();
document.getElementById("log").classList.add("active-3");
document.getElementById("show-logs").classList.add("hidden");
}
</script>
</body>
</html>