forked from ozonni/do-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
424 lines (391 loc) · 19.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<!-- Bootstrap CSS -->
<link type="text/css" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/bootstrap-vue.css" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://unpkg.com/[email protected]/nprogress.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-117946998-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-117946998-1');
</script>
<style>
.c-pointer {
cursor: pointer;
}
.nostyle,
.nostyle:hover {
color: inherit;
text-decoration: none;
}
.material-icons.md-18 {
font-size: 18px;
}
.material-icons.md-48 {
font-size: 48px;
}
[v-cloak] {
display: none;
}
</style>
<title>Do VPN</title>
</head>
<body class="bg-light">
<nav class="navbar navbar-light bg-light d-flex flex-row-reverse">
<a class="navbar-text" href="https://github.com/ozonni/do-vpn">View on GitHub</a>
</nav>
<main role="main" class="container" v-cloak id="app">
<div class="py-4 text-center">
<i class="material-icons md-48">vpn_lock</i>
<h2>{{ $t("message.doVPN") }}</h2>
<p class="mt-4" v-if="!authorized" v-html="$t('message.welcome')"></p>
</div>
<div>
<div class="row justify-content-md-center">
<div class="col-md-8" v-if="!authorized">
<a class="btn btn-primary btn-lg btn-block" href="https://cloud.digitalocean.com/v1/oauth/authorize?response_type=token&client_id=a74eb85bd3567014726fbf26a6f713cbf64c28224d5b838b8abbc9706fcec178&redirect_uri=https://ozonni.github.io/do-vpn/&scope=read write"
role="button">{{ $t("message.authorize") }}</a>
</div>
<div class="col-md-10" v-if="authorized">
<p v-html="$t('message.intro')"></p>
<div class="alert alert-danger" role="alert" v-if="errorMsg">
{{ errorMsg }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close" v-on:click="closeErrorMsg">
<span aria-hidden="true">×</span>
</button>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">IP Address</th>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">PSK</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr v-for="inst in instances">
<td>
<b-btn variant="outline-info" size="sm" v-b-tooltip.hover.top :title="$t('message.takes55Sec')" v-if="inst.status != 'active'"
v-on:click="loadInstList">
{{ $t("message.refresh") }}
</b-btn>
<span v-if="inst.status == 'active'">{{ inst.ip }}</span>
</td>
<td>{{ inst.username }}</td>
<td>{{ inst.password }}</td>
<td>{{ inst.psk }}</td>
<td class="d-flex justify-content-between">
<a class="nostyle" download="dovpn.mobileconfig" :href="getMobileConfigData(inst)" v-if="inst.status == 'active'">
<i class="material-icons" title="ios/macos setup">phonelink_setup</i>
</a>
<i class="material-icons c-pointer ml-auto" title="Delete" v-on:click="deleteInst(inst)">delete_forever</i>
</td>
</tr>
</tbody>
</table>
<div class="input-group">
<select class="custom-select w-25" v-model="selectedRegion">
<option disabled value="">{{ $t("message.selectRegion") }}</option>
<option v-for="region in regions" v-bind:value="region.slug">{{ region.name }}</option>
</select>
<div class="input-group-append w-75">
<button type="button" class="btn btn-primary btn-block" v-on:click="createInst">{{ $t("message.createVPN") }}</button>
</div>
</div>
<div class="text-center mt-5">
<b>{{ $t("message.howTo") }}</b>
<ul class="list-inline">
<li class="list-inline-item">
<a id="ios-link" href="https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/docs/clients.md#ios" target="_blank">iOS (iPhone/iPad)</a>
<b-tooltip placement="bottom" target="ios-link">
{{ $t("message.useAutoSetup") }}
<i class="material-icons md-18 align-middle" title="ios/macos setup">phonelink_setup</i>
</b-tooltip>
</li>
<li class="list-inline-item">
<a href="https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/docs/clients.md#android" target="_blank">Android</a>
</li>
<li class="list-inline-item">
<a id="macos-link" href="https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/docs/clients.md#os-x" target="_blank">OS X (macOS)</a>
<b-tooltip placement="bottom" target="macos-link">
{{ $t("message.useAutoSetup") }}
<i class="material-icons md-18 align-middle" title="ios/macos setup">phonelink_setup</i>
</b-tooltip>
</li>
<li class="list-inline-item">
<a href="https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/docs/clients.md#windows" target="_blank">Windows</a>
</li>
</ul>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://unpkg.com/[email protected]/nprogress.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue-i18n.js"></script>
<script src="https://unpkg.com/[email protected]/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-vue.js"></script>
<script>
var params = new URLSearchParams(window.location.hash.substr(1))
var token = params.get('access_token');
Vue.http.interceptors.push((request, next) => {
NProgress.start();
next((response) => {
NProgress.done();
});
});
if (token) {
Vue.http.headers.common['Authorization'] = 'Bearer ' + token;
Vue.http.headers.common['Content-Type'] = 'application/json';
}
var generateRandomString = function () {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 8; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
};
const messages = {
'en': {
message: {
doVPN: 'Do your own VPN',
authorize: 'Authorize with DigitalOcean',
howTo: 'How to configure VPN on your device',
createVPN: 'Create VPN',
selectRegion: 'Please select region',
refresh: 'refresh',
takes55Sec: 'It takes ~55s. to create IP address',
useAutoSetup: 'Use auto-setup. Look for',
intro: `Below is a list of VPN servers you have created. You can delete one or create a new one. By creating a new VPN server a new
DigitalOcean droplet will be created in your account with 1TB internet traffic available. Each VPN
server will cost you <a href="https://www.digitalocean.com/pricing" target="_blank">$5/mo</a>.`,
welcome: `Using <a href="https://www.digitalocean.com" target="_blank">DigitalOcean</a> you can have your private VPN server just for $5/mo. We do
<b>NOT</b> charge anything, you only pay to DigitalOcean for droplets and we do
<b>NOT</b> store any of your data, as well as we do
<b>NOT</b> analyze your traffic. We just make it simple to set up your own VPN. If you already have DigitalOcean
account you can proceed by clicking on
<b>Authorize</b> otherwise follow this referral
<a href="https://m.do.co/c/0e1ce5621123" target="_blank">link</a> to create a new account (you will get $10 in credit, will be enough for 2 month).`
}
},
'ru': {
message: {
doVPN: 'Cоздай собственный VPN',
authorize: 'Зайти через DigitalOcean',
howTo: 'Как настроить VPN на устройстве',
createVPN: 'Создать VPN',
selectRegion: 'Выберите регион',
refresh: 'обновить',
takes55Sec: 'Занимает ~55сек. чтобы создать IP адрес',
useAutoSetup: 'Автонастройка, нажмите на',
intro: `Ниже вы можете видеть список созданных VPN серверов. Вы можете удалять их, а также создавать новые. При создании VPN сервера, в вашем аккаунте DigitalOcean создается новый сервер с 1 Tерабайтом доступного трафика.
Каждый VPN сервер стоит <a href="https://www.digitalocean.com/pricing" target="_blank">$5 в месяц</a>. VPN аккаунт может быть использован с разных устройств.`,
welcome: `Используя <a href="https://www.digitalocean.com" target="_blank">DigitalOcean</a> вы можете создать свой собственный приватный VPN за 5$ в месяц.
Вы платите <b>только за сервера</b> DigitalOcean. Мы <b>НЕ</b> анализируем ваш трафик и <b>НЕ</b> храним ваши данные.
Мы просто делаем настройку VPN доступной для каждого. Нажмите на кнопку <b>Авторизации</b> если у вас уже есть аккаунт в DigitalOcean.
Иначе используйте <a href="https://m.do.co/c/0e1ce5621123" target="_blank">реферальную ссылку</a> что бы создать новый аккаунт (вы получите $10 в подарок, этого хватит на 2 месяца использования).`
}
}
};
const i18n = new VueI18n({
locale: navigator.language.substr(0, 2),
fallbackLocale: 'en',
messages,
})
var app = new Vue({
i18n,
el: '#app',
data: {
authorized: !!token,
instances: [],
regions: [],
selectedRegion: '',
errorMsg: null
},
methods: {
getMobileConfigData: function (inst) {
var xml = mobileConfig
.replace("{psk}", btoa(inst.psk))
.replace("{username}", inst.username)
.replace("{password}", inst.password)
.replace("{ip}", inst.ip);
return "data:application/x-apple-aspen-config;base64," + btoa(xml);
},
createInst: function () {
if (!this.selectedRegion) {
return;
}
var psk = generateRandomString();
var username = generateRandomString();
var password = generateRandomString();
var userData = `#!/bin/bash
modprobe af_key
docker run --name ipsec-vpn-server -e VPN_IPSEC_PSK=${psk} -e VPN_USER=${username} -e VPN_PASSWORD=${password} --restart=always -p 500:500/udp -p 4500:4500/udp -v /lib/modules:/lib/modules:ro -d --privileged hwdsl2/ipsec-vpn-server`;
const name = "do-vpn";
var newDroplet =
{
name: name,
region: this.selectedRegion,
size: "s-1vcpu-1gb",
image: "23219707",
tags: [name, "psk:" + psk, "username:" + username, "password:" + password],
user_data: userData
};
this.$http.post('https://api.digitalocean.com/v2/droplets', newDroplet).then(response => {
if (response.status === 202) {
console.log("created");
this.loadInstList();
}
}, response => {
console.log(response);
this.errorMsg = response.body.message;
});
},
deleteInst: function (inst) {
this.$http.delete('https://api.digitalocean.com/v2/droplets/' + inst.id).then(response => {
if (response.status === 204) {
this.instances = this.instances.filter(x => x.id !== inst.id);
}
}, response => {
console.log(response);
this.errorMsg = response.body.message;
});
},
loadInstList: function () {
this.$http.get('https://api.digitalocean.com/v2/droplets?tag_name=do-vpn').then(response => {
if (response.status === 200) {
this.instances = response.body.droplets.map(x => {
var inst = {
id: x.id,
status: x.status,
username: x.tags.find(x => x.startsWith("username:")).substr(9),
password: x.tags.find(x => x.startsWith("password:")).substr(9),
psk: x.tags.find(x => x.startsWith("psk:")).substr(4),
};
if (x.networks.v4[0]) {
inst.ip = x.networks.v4[0].ip_address
}
return inst;
});
}
}, response => {
console.log(response);
this.errorMsg = response.body.message;
});
},
loadRegions: function () {
this.$http.get('https://api.digitalocean.com/v2/regions').then(response => {
if (response.status === 200) {
this.regions = response.body.regions
.filter(x => x.available)
.map(x => {
return {
name: x.name,
slug: x.slug
};
})
.sort((a, b) => a.name > b.name);
}
}, response => {
console.log(response);
this.errorMsg = response.body.message;
});
},
closeErrorMsg: function () {
this.errorMsg = null;
}
},
mounted: function () {
if (this.authorized) {
this.loadInstList();
this.loadRegions();
}
}
})
var mobileConfig = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>IPSec</key>
<dict>
<key>AuthenticationMethod</key>
<string>SharedSecret</string>
<key>LocalIdentifierType</key>
<string>KeyID</string>
<key>SharedSecret</key>
<data>{psk}</data>
</dict>
<key>IPv4</key>
<dict>
<key>OverridePrimary</key>
<integer>1</integer>
</dict>
<key>PPP</key>
<dict>
<key>AuthName</key>
<string>{username}</string>
<key>AuthPassword</key>
<string>{password}</string>
<key>CommRemoteAddress</key>
<string>{ip}</string>
</dict>
<key>PayloadDescription</key>
<string>Configures VPN settings</string>
<key>PayloadDisplayName</key>
<string>VPN</string>
<key>PayloadIdentifier</key>
<string>com.apple.vpn.managed.F905E46A-60F6-4ABD-91D1-061C4EB8F838</string>
<key>PayloadType</key>
<string>com.apple.vpn.managed</string>
<key>PayloadUUID</key>
<string>F905E46A-60F6-4ABD-91D1-061C4EB8F838</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>Proxies</key>
<dict>
<key>HTTPEnable</key>
<integer>0</integer>
<key>HTTPSEnable</key>
<integer>0</integer>
</dict>
<key>UserDefinedName</key>
<string>DO VPN</string>
<key>VPNType</key>
<string>L2TP</string>
</dict>
</array>
<key>PayloadDescription</key>
<string>Profile to quickly configure VPN</string>
<key>PayloadDisplayName</key>
<string>DO VPN</string>
<key>PayloadIdentifier</key>
<string>5D042124-0DD9-4AD1-803B-F900B3CA85CB</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>BB8694E4-8DF2-45F7-BC9B-E497F3F7D6A6</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
`;
</script>
</body>
</html>