forked from klinquist/iOS-VPN-Autoconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
344 lines (315 loc) · 16.9 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
<!doctype html>
<html lang="en">
<head>
<title>iOS VPN Profile Generator</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
body {
padding: 60px 60px 60px 60px;
}
.header{
margin-top: 20px;
margin-bottom: 40px;
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
</head>
<body>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>iOS VPN Profile Generator by Kris Linquist (@klinquist)</legend>
<div class='header'>
<p> This page will generate a .mobileprofile which, when placed on your iOS device, will auto-connect to a VPN. You can exclude SSIDs from the autoconnect VPN rules.</p>
<p>The file generated on this page is done so in your browser - none of this information is sent to this web page. You also have the option of downloading this file and running it locally.</p>
</div>
<div class='instructions'>
<h5>Instructions</h5>
<ul>
<li>Fill out the form below and press the Generate button</li>
<li>Airdrop or Email the file to your iOS device</li>
</ul>
</div>
<div class="form-group">
<div class="col-md-4">
<button id="pia" name="pia" class="btn btn-info btn-sm">Auto-fill with Private Internet Access server info</button>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name (that will be displayed on the VPN preferences page)</label>
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="" class="form-control input-md" value="Autoconnect VPN">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="identifier">Identifier (make this unique if you plan on importing >1 profile)</label>
<div class="col-md-4">
<input id="identifier" name="identifier" type="text" placeholder="" class="form-control input-md" value='com.vpn.vpn1'>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="autoconnect">Auto-connect</label>
<div class="col-md-4">
<select id="autoconnect" name="vpntype" class="form-control">
<option value="wifi">On wifi only</option>
<option value="cellular">On wifi & cellular</option>
<option value="none">Don't auto-connect</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="vpntype">VPN Type</label>
<div class="col-md-4">
<select id="vpntype" name="vpntype" class="form-control">
<option value="L2TP">L2TP</option>
<option value="IKEv2">IKEv2 (Not Yet Supported)</option>
<option value="IPSEC">IPSEC (Not Yet Supported)</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="hostname">Hostname</label>
<div class="col-md-4">
<input id="hostname" name="hostname" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="login">Login</label>
<div class="col-md-4">
<input id="login" name="login" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-4">
<input id="password" name="password" type="password" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="sharedsecret">Shared Secret</label>
<div class="col-md-4">
<input id="sharedsecret" name="sharedsecret" type="password" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group" id='ssidformgroup'>
<label class="col-md-4 control-label" for="ssids">Comma-separated list of SSIDs, which when connected to, you do NOT want the VPN to auto-connect</label>
<div class="col-md-4">
<input id="ssids" name="ssids" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Button -->
<div class="form-group">
<div class="col-md-4">
<button id="submit" name="submit" class="btn btn-primary">Generate</button>
</div>
</div>
</fieldset>
</form>
<script>
function generateUUID () { //Generates RUUID
var possible = 'ABCDEF0123456789';
let lengths = [8,4,4,4,12];
let chunks = [];
for (var j = 0; j < lengths.length; j++){
var text = '';
for (var i = 0; i < lengths[j]; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
chunks.push(text);
}
return chunks.join('-');
};
var xmlString = "";
xmlString += '<?xml version="1.0" encoding="UTF-8"?>\n';
xmlString += '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n';
xmlString += '<plist version="1.0">\n';
xmlString += '<dict>\n';
xmlString += ' <key>PayloadContent</key>\n';
xmlString += ' <array> ';
xmlString += ' <dict>\n';
xmlString += ' <key>UserDefinedName</key>\n';
xmlString += ' <string>{{name}}</string>\n';
xmlString += ' <key>PayloadDisplayName</key>\n';
xmlString += ' <string>{{name1}}</string>\n';
xmlString += ' <key>PayloadIdentifier</key>\n';
xmlString += ' <string>{{identifier}}</string>\n';
xmlString += ' <key>PayloadUUID</key>\n';
xmlString += ' <string>{{uuid1}}</string>\n';
xmlString += ' <key>VPNType</key>\n';
xmlString += ' <string>L2TP</string>\n';
xmlString += ' <key>IPSec</key>\n';
xmlString += ' <dict>\n';
xmlString += ' <key>AuthenticationMethod</key>\n';
xmlString += ' <string>SharedSecret</string>\n';
xmlString += ' <key>LocalIdentifierType</key>\n';
xmlString += ' <string>KeyID</string>\n';
xmlString += ' <key>SharedSecret</key>\n';
xmlString += ' <string>{{sharedsecret}}</string>\n';
xmlString += ' </dict>\n';
xmlString += ' <key>PPP</key>\n';
xmlString += ' <dict>\n';
xmlString += ' <key>AuthName</key>\n';
xmlString += ' <string>{{login}}</string>\n';
xmlString += ' <key>AuthPassword</key>\n';
xmlString += ' <string>{{password}}</string>\n';
xmlString += ' <key>CommRemoteAddress</key>\n';
xmlString += ' <string>{{hostname}}</string>\n';
xmlString += ' </dict>\n';
xmlString += ' {{onDemandRules}}';
xmlString += ' <key>OverridePrimary</key>\n';
xmlString += ' <true/>\n';
xmlString += ' <key>IPv4</key>\n';
xmlString += ' <dict>\n';
xmlString += ' <key>OverridePrimary</key>\n';
xmlString += ' <integer>1</integer>\n';
xmlString += ' </dict>\n';
xmlString += ' <key>PayloadType</key>\n';
xmlString += ' <string>com.apple.vpn.managed</string>\n';
xmlString += ' <key>PayloadVersion</key>\n';
xmlString += ' <integer>1</integer>\n';
xmlString += ' </dict>\n';
xmlString += '</array>\n';
xmlString += ' <key>PayloadDisplayName</key>\n';
xmlString += ' <string>VPN Configurations</string>\n';
xmlString += ' <key>PayloadIdentifier</key>\n';
xmlString += ' <string>{{uuid2}}</string>\n';
xmlString += ' <key>PayloadRemovalDisallowed</key>\n';
xmlString += ' <false/>\n';
xmlString += ' <key>PayloadType</key>\n';
xmlString += ' <string>Configuration</string>\n';
xmlString += ' <key>PayloadUUID</key>\n';
xmlString += ' <string>{{uuid3}}</string>\n';
xmlString += ' <key>PayloadVersion</key>\n';
xmlString += ' <integer>1</integer>\n';
xmlString += '</dict>\n';
xmlString += '</plist>';
onDemandRules = '';
onDemandRules += '<key>OnDemandEnabled</key>\n';
onDemandRules += ' <integer>{{onDemandEnabled}}</integer>\n';
onDemandRules += ' {{onDemandRulesDict}}'
onDemandRulesArr = [];
var wifiDict = ''
wifiDict += ' <dict>\n';
wifiDict += ' <key>InterfaceTypeMatch</key>\n';
wifiDict += ' <string>WiFi</string>\n';
wifiDict += ' <key>Action</key>\n';
wifiDict += ' <string>Connect</string>\n';
wifiDict += ' </dict>\n';
var wifiDefaultDict = '';
wifiDefaultDict += ' <dict>\n';
wifiDefaultDict += ' <!-- VPN Default state -->\n';
wifiDefaultDict += ' <key>Action</key>\n';
wifiDefaultDict += ' <string>Disconnect</string>\n'; //Default state tells it what to do by default. If wifi only is enabled, this should be disabled (so disable on cellular)
wifiDefaultDict += ' </dict>\n';
var cellularDefaultDict = '';
cellularDefaultDict += ' <dict>\n';
cellularDefaultDict += ' <!-- VPN Default state -->\n';
cellularDefaultDict += ' <key>Action</key>\n';
cellularDefaultDict += ' <string>Connect</string>\n'; //Default state tells it what to do by default. If wifi only is enabled, this should be disabled (so disable on cellular)
cellularDefaultDict += ' </dict>\n';
$(document).ready(function () {
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
$( "#autoconnect" ).change(function() {
if ($("#autoconnect").val() == "none") $("#ssidformgroup").hide()
if ($("#autoconnect").val() == "cellular") $("#ssidformgroup").show()
if ($("#autoconnect").val() == "wifi") $("#ssidformgroup").show()
});
$( "#pia" ).click(function(e) {
e.preventDefault();
$('#sharedsecret').val('mysafety')
$('#hostname').val('us-california.privateinternetaccess.com')
$('#login').attr("placeholder", "Your PIA 'x' username");
});
$('#submit').click(function(e) {
e.preventDefault();
var login = $("#login").val(),
password = $('#password').val(),
sharedsecret = $('#sharedsecret').val(),
ssids = $('#ssids').val(),
vpntype = $('#vpntype').val(),
name = $('#name').val() || 'Autoconnect VPN',
hostname = $('#hostname').val(),
identifier = $('#identifier').val() || 'com.vpn.vpn1',
autoconnect = $('#autoconnect').val();
if (!hostname) return alert('Hostname required')
xmlString = xmlString.replace('{{login}}', login);
xmlString = xmlString.replace('{{password}}', password);
xmlString = xmlString.replace('{{sharedsecret}}', sharedsecret);
xmlString = xmlString.replace('{{hostname}}', hostname);
xmlString = xmlString.replace('{{name}}', name);
xmlString = xmlString.replace('{{name1}}', name);
xmlString = xmlString.replace('{{uuid1}}', generateUUID());
xmlString = xmlString.replace('{{uuid2}}', generateUUID());
xmlString = xmlString.replace('{{uuid3}}', generateUUID());
xmlString = xmlString.replace('{{identifier}}', identifier);
if (ssids && autoconnect !== 'none'){
onDemandSSID = '';
onDemandSSID += ' <dict>\n';
onDemandSSID += ' <key>InterfaceTypeMatch</key>\n';
onDemandSSID += ' <string>WiFi</string>\n';
onDemandSSID += ' <key>SSIDMatch</key>\n';
onDemandSSID += ' {{ssidList}}';
onDemandSSID += ' <key>Action</key>\n';
onDemandSSID += ' <string>Disconnect</string>\n';
onDemandSSID += ' </dict>\n';
var onlySsids = '<array>\n';
ssids = ssids.split(',');
for (var i=0; i<ssids.length; i++){
onlySsids += ' <string>' + ssids[i].trim() + '</string>\n'
}
onlySsids += ' </array>\n'
onDemandSSID = onDemandSSID.replace('{{ssidList}}', onlySsids);
onDemandRulesArr.push(onDemandSSID);
}
if (autoconnect == 'wifi'){
onDemandRules = onDemandRules.replace('{{onDemandEnabled}}', '1');
onDemandRulesArr.push(wifiDict);
onDemandRulesArr.push(wifiDefaultDict);
console.log('Pushing wifi default dict');
}
if (autoconnect == 'cellular') {
onDemandRules = onDemandRules.replace('{{onDemandEnabled}}', '1');
onDemandRulesArr.push(cellularDefaultDict);
console.log('Pushing on cellular default dict');
}
if (autoconnect == 'none'){
onDemandRules = onDemandRules.replace('{{onDemandEnabled}}', '0');
console.log('Removing onDemandEnabled');
}
if (onDemandRulesArr.length > 0){
onDemandRules = onDemandRules.replace('{{onDemandRulesDict}}', '<key>OnDemandRules</key>\n <array>\n' + onDemandRulesArr.join('')+' </array>\n');
} else {
onDemandRules = onDemandRules.replace('{{onDemandRulesDict}}', '');
}
xmlString = xmlString.replace('{{onDemandRules}}', onDemandRules)
console.log(xmlString);
download('vpn.mobileconfig', xmlString);
location.reload(true)
})
});
</script>
</body>
</html>