1
|
<?php
|
2
|
/*
|
3
|
vpn_openvpn_client.php
|
4
|
|
5
|
Copyright (C) 2008 Shrew Soft Inc.
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
##|+PRIV
|
32
|
##|*IDENT=page-openvpn-client
|
33
|
##|*NAME=OpenVPN: Client page
|
34
|
##|*DESCR=Allow access to the 'OpenVPN: Client' page.
|
35
|
##|*MATCH=vpn_openvpn_client.php*
|
36
|
##|-PRIV
|
37
|
|
38
|
require("guiconfig.inc");
|
39
|
require_once("openvpn.inc");
|
40
|
|
41
|
$pgtitle = array(gettext("OpenVPN"), gettext("Client"));
|
42
|
$shortcut_section = "openvpn";
|
43
|
|
44
|
if (!is_array($config['openvpn']['openvpn-client']))
|
45
|
$config['openvpn']['openvpn-client'] = array();
|
46
|
|
47
|
$a_client = &$config['openvpn']['openvpn-client'];
|
48
|
|
49
|
if (!is_array($config['ca']))
|
50
|
$config['ca'] = array();
|
51
|
|
52
|
$a_ca =& $config['ca'];
|
53
|
|
54
|
if (!is_array($config['cert']))
|
55
|
$config['cert'] = array();
|
56
|
|
57
|
$a_cert =& $config['cert'];
|
58
|
|
59
|
if (!is_array($config['crl']))
|
60
|
$config['crl'] = array();
|
61
|
|
62
|
$a_crl =& $config['crl'];
|
63
|
|
64
|
if (is_numericint($_GET['id']))
|
65
|
$id = $_GET['id'];
|
66
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
67
|
$id = $_POST['id'];
|
68
|
|
69
|
$act = $_GET['act'];
|
70
|
if (isset($_POST['act']))
|
71
|
$act = $_POST['act'];
|
72
|
|
73
|
if (isset($id) && $a_client[$id])
|
74
|
$vpnid = $a_client[$id]['vpnid'];
|
75
|
else
|
76
|
$vpnid = 0;
|
77
|
|
78
|
if ($_GET['act'] == "del") {
|
79
|
|
80
|
if (!isset($a_client[$id])) {
|
81
|
pfSenseHeader("vpn_openvpn_client.php");
|
82
|
exit;
|
83
|
}
|
84
|
if (!empty($a_client[$id]))
|
85
|
openvpn_delete('client', $a_client[$id]);
|
86
|
unset($a_client[$id]);
|
87
|
write_config();
|
88
|
$savemsg = gettext("Client successfully deleted")."<br />";
|
89
|
}
|
90
|
|
91
|
if($_GET['act']=="new"){
|
92
|
$pconfig['autokey_enable'] = "yes";
|
93
|
$pconfig['tlsauth_enable'] = "yes";
|
94
|
$pconfig['autotls_enable'] = "yes";
|
95
|
$pconfig['interface'] = "wan";
|
96
|
$pconfig['server_port'] = 1194;
|
97
|
$pconfig['verbosity_level'] = 1; // Default verbosity is 1
|
98
|
// OpenVPN Defaults to SHA1
|
99
|
$pconfig['digest'] = "SHA1";
|
100
|
}
|
101
|
|
102
|
global $simplefields;
|
103
|
$simplefields = array('auth_user','auth_pass');
|
104
|
|
105
|
if($_GET['act']=="edit"){
|
106
|
|
107
|
if (isset($id) && $a_client[$id]) {
|
108
|
foreach($simplefields as $stat)
|
109
|
$pconfig[$stat] = $a_client[$id][$stat];
|
110
|
|
111
|
$pconfig['disable'] = isset($a_client[$id]['disable']);
|
112
|
$pconfig['mode'] = $a_client[$id]['mode'];
|
113
|
$pconfig['protocol'] = $a_client[$id]['protocol'];
|
114
|
$pconfig['interface'] = $a_client[$id]['interface'];
|
115
|
if (!empty($a_client[$id]['ipaddr'])) {
|
116
|
$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$id]['ipaddr'];
|
117
|
}
|
118
|
$pconfig['local_port'] = $a_client[$id]['local_port'];
|
119
|
$pconfig['server_addr'] = $a_client[$id]['server_addr'];
|
120
|
$pconfig['server_port'] = $a_client[$id]['server_port'];
|
121
|
$pconfig['resolve_retry'] = $a_client[$id]['resolve_retry'];
|
122
|
$pconfig['proxy_addr'] = $a_client[$id]['proxy_addr'];
|
123
|
$pconfig['proxy_port'] = $a_client[$id]['proxy_port'];
|
124
|
$pconfig['proxy_user'] = $a_client[$id]['proxy_user'];
|
125
|
$pconfig['proxy_passwd'] = $a_client[$id]['proxy_passwd'];
|
126
|
$pconfig['proxy_authtype'] = $a_client[$id]['proxy_authtype'];
|
127
|
$pconfig['description'] = $a_client[$id]['description'];
|
128
|
$pconfig['custom_options'] = $a_client[$id]['custom_options'];
|
129
|
$pconfig['ns_cert_type'] = $a_client[$id]['ns_cert_type'];
|
130
|
$pconfig['dev_mode'] = $a_client[$id]['dev_mode'];
|
131
|
|
132
|
if ($pconfig['mode'] != "p2p_shared_key") {
|
133
|
$pconfig['caref'] = $a_client[$id]['caref'];
|
134
|
$pconfig['certref'] = $a_client[$id]['certref'];
|
135
|
if ($a_client[$id]['tls']) {
|
136
|
$pconfig['tlsauth_enable'] = "yes";
|
137
|
$pconfig['tls'] = base64_decode($a_client[$id]['tls']);
|
138
|
}
|
139
|
} else
|
140
|
$pconfig['shared_key'] = base64_decode($a_client[$id]['shared_key']);
|
141
|
$pconfig['crypto'] = $a_client[$id]['crypto'];
|
142
|
// OpenVPN Defaults to SHA1 if unset
|
143
|
$pconfig['digest'] = !empty($a_client[$id]['digest']) ? $a_client[$id]['digest'] : "SHA1";
|
144
|
$pconfig['engine'] = $a_client[$id]['engine'];
|
145
|
|
146
|
$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
|
147
|
$pconfig['tunnel_networkv6'] = $a_client[$id]['tunnel_networkv6'];
|
148
|
$pconfig['remote_network'] = $a_client[$id]['remote_network'];
|
149
|
$pconfig['remote_networkv6'] = $a_client[$id]['remote_networkv6'];
|
150
|
$pconfig['use_shaper'] = $a_client[$id]['use_shaper'];
|
151
|
$pconfig['compression'] = $a_client[$id]['compression'];
|
152
|
$pconfig['passtos'] = $a_client[$id]['passtos'];
|
153
|
|
154
|
// just in case the modes switch
|
155
|
$pconfig['autokey_enable'] = "yes";
|
156
|
$pconfig['autotls_enable'] = "yes";
|
157
|
|
158
|
$pconfig['no_tun_ipv6'] = $a_client[$id]['no_tun_ipv6'];
|
159
|
$pconfig['route_no_pull'] = $a_client[$id]['route_no_pull'];
|
160
|
$pconfig['route_no_exec'] = $a_client[$id]['route_no_exec'];
|
161
|
if (isset($a_client[$id]['verbosity_level']))
|
162
|
$pconfig['verbosity_level'] = $a_client[$id]['verbosity_level'];
|
163
|
else
|
164
|
$pconfig['verbosity_level'] = 1; // Default verbosity is 1
|
165
|
}
|
166
|
}
|
167
|
|
168
|
if ($_POST) {
|
169
|
|
170
|
unset($input_errors);
|
171
|
$pconfig = $_POST;
|
172
|
|
173
|
if (isset($id) && $a_client[$id])
|
174
|
$vpnid = $a_client[$id]['vpnid'];
|
175
|
else
|
176
|
$vpnid = 0;
|
177
|
|
178
|
list($iv_iface, $iv_ip) = explode ("|",$pconfig['interface']);
|
179
|
if (is_ipaddrv4($iv_ip) && (stristr($pconfig['protocol'], "6") !== false)) {
|
180
|
$input_errors[] = gettext("Protocol and IP address families do not match. You cannot select an IPv6 protocol and an IPv4 IP address.");
|
181
|
} elseif (is_ipaddrv6($iv_ip) && (stristr($pconfig['protocol'], "6") === false)) {
|
182
|
$input_errors[] = gettext("Protocol and IP address families do not match. You cannot select an IPv4 protocol and an IPv6 IP address.");
|
183
|
} elseif ((stristr($pconfig['protocol'], "6") === false) && !get_interface_ip($iv_iface) && ($pconfig['interface'] != "any")) {
|
184
|
$input_errors[] = gettext("An IPv4 protocol was selected, but the selected interface has no IPv4 address.");
|
185
|
} elseif ((stristr($pconfig['protocol'], "6") !== false) && !get_interface_ipv6($iv_iface) && ($pconfig['interface'] != "any")) {
|
186
|
$input_errors[] = gettext("An IPv6 protocol was selected, but the selected interface has no IPv6 address.");
|
187
|
}
|
188
|
|
189
|
if ($pconfig['mode'] != "p2p_shared_key")
|
190
|
$tls_mode = true;
|
191
|
else
|
192
|
$tls_mode = false;
|
193
|
|
194
|
/* input validation */
|
195
|
if ($pconfig['local_port']) {
|
196
|
|
197
|
if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
|
198
|
$input_errors[] = $result;
|
199
|
|
200
|
$portused = openvpn_port_used($pconfig['protocol'], $pconfig['interface'], $pconfig['local_port'], $vpnid);
|
201
|
if (($portused != $vpnid) && ($portused != 0))
|
202
|
$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
|
203
|
}
|
204
|
|
205
|
if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
|
206
|
$input_errors[] = $result;
|
207
|
|
208
|
if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
|
209
|
$input_errors[] = $result;
|
210
|
|
211
|
if ($pconfig['proxy_addr']) {
|
212
|
|
213
|
if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
|
214
|
$input_errors[] = $result;
|
215
|
|
216
|
if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
|
217
|
$input_errors[] = $result;
|
218
|
|
219
|
if ($pconfig['proxy_authtype'] != "none") {
|
220
|
if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
|
221
|
$input_errors[] = gettext("User name and password are required for proxy with authentication.");
|
222
|
}
|
223
|
}
|
224
|
|
225
|
if($pconfig['tunnel_network'])
|
226
|
if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'IPv4 Tunnel Network', false, "ipv4"))
|
227
|
$input_errors[] = $result;
|
228
|
|
229
|
if($pconfig['tunnel_networkv6'])
|
230
|
if ($result = openvpn_validate_cidr($pconfig['tunnel_networkv6'], 'IPv6 Tunnel Network', false, "ipv6"))
|
231
|
$input_errors[] = $result;
|
232
|
|
233
|
if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4"))
|
234
|
$input_errors[] = $result;
|
235
|
|
236
|
if ($result = openvpn_validate_cidr($pconfig['remote_networkv6'], 'IPv6 Remote Network', true, "ipv6"))
|
237
|
$input_errors[] = $result;
|
238
|
|
239
|
if (!empty($pconfig['use_shaper']) && (!is_numeric($pconfig['use_shaper']) || ($pconfig['use_shaper'] <= 0)))
|
240
|
$input_errors[] = gettext("The bandwidth limit must be a positive numeric value.");
|
241
|
|
242
|
if ($pconfig['autokey_enable'])
|
243
|
$pconfig['shared_key'] = openvpn_create_key();
|
244
|
|
245
|
if (!$tls_mode && !$pconfig['autokey_enable'])
|
246
|
if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
|
247
|
!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
|
248
|
$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
|
249
|
|
250
|
if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
|
251
|
if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
|
252
|
!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
|
253
|
$input_errors[] = gettext("The field 'TLS Authentication Key' does not appear to be valid");
|
254
|
|
255
|
/* If we are not in shared key mode, then we need the CA/Cert. */
|
256
|
if ($pconfig['mode'] != "p2p_shared_key") {
|
257
|
$reqdfields = explode(" ", "caref");
|
258
|
$reqdfieldsn = array(gettext("Certificate Authority"));
|
259
|
} elseif (!$pconfig['autokey_enable']) {
|
260
|
/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
|
261
|
$reqdfields = array('shared_key');
|
262
|
$reqdfieldsn = array(gettext('Shared key'));
|
263
|
}
|
264
|
|
265
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
266
|
|
267
|
if (($pconfig['mode'] != "p2p_shared_key") && empty($pconfig['certref']) && empty($pconfig['auth_user']) && empty($pconfig['auth_pass'])) {
|
268
|
$input_errors[] = gettext("If no Client Certificate is selected, a username and password must be entered.");
|
269
|
}
|
270
|
|
271
|
if (!$input_errors) {
|
272
|
|
273
|
$client = array();
|
274
|
|
275
|
foreach($simplefields as $stat)
|
276
|
update_if_changed($stat, $client[$stat], $_POST[$stat]);
|
277
|
|
278
|
if ($vpnid)
|
279
|
$client['vpnid'] = $vpnid;
|
280
|
else
|
281
|
$client['vpnid'] = openvpn_vpnid_next();
|
282
|
|
283
|
if ($_POST['disable'] == "yes")
|
284
|
$client['disable'] = true;
|
285
|
$client['protocol'] = $pconfig['protocol'];
|
286
|
$client['dev_mode'] = $pconfig['dev_mode'];
|
287
|
list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
|
288
|
$client['local_port'] = $pconfig['local_port'];
|
289
|
$client['server_addr'] = $pconfig['server_addr'];
|
290
|
$client['server_port'] = $pconfig['server_port'];
|
291
|
$client['resolve_retry'] = $pconfig['resolve_retry'];
|
292
|
$client['proxy_addr'] = $pconfig['proxy_addr'];
|
293
|
$client['proxy_port'] = $pconfig['proxy_port'];
|
294
|
$client['proxy_authtype'] = $pconfig['proxy_authtype'];
|
295
|
$client['proxy_user'] = $pconfig['proxy_user'];
|
296
|
$client['proxy_passwd'] = $pconfig['proxy_passwd'];
|
297
|
$client['description'] = $pconfig['description'];
|
298
|
$client['mode'] = $pconfig['mode'];
|
299
|
$client['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
|
300
|
|
301
|
if ($tls_mode) {
|
302
|
$client['caref'] = $pconfig['caref'];
|
303
|
$client['certref'] = $pconfig['certref'];
|
304
|
if ($pconfig['tlsauth_enable']) {
|
305
|
if ($pconfig['autotls_enable'])
|
306
|
$pconfig['tls'] = openvpn_create_key();
|
307
|
$client['tls'] = base64_encode($pconfig['tls']);
|
308
|
}
|
309
|
} else {
|
310
|
$client['shared_key'] = base64_encode($pconfig['shared_key']);
|
311
|
}
|
312
|
$client['crypto'] = $pconfig['crypto'];
|
313
|
$client['digest'] = $pconfig['digest'];
|
314
|
$client['engine'] = $pconfig['engine'];
|
315
|
|
316
|
$client['tunnel_network'] = $pconfig['tunnel_network'];
|
317
|
$client['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
|
318
|
$client['remote_network'] = $pconfig['remote_network'];
|
319
|
$client['remote_networkv6'] = $pconfig['remote_networkv6'];
|
320
|
$client['use_shaper'] = $pconfig['use_shaper'];
|
321
|
$client['compression'] = $pconfig['compression'];
|
322
|
$client['passtos'] = $pconfig['passtos'];
|
323
|
|
324
|
$client['no_tun_ipv6'] = $pconfig['no_tun_ipv6'];
|
325
|
$client['route_no_pull'] = $pconfig['route_no_pull'];
|
326
|
$client['route_no_exec'] = $pconfig['route_no_exec'];
|
327
|
$client['verbosity_level'] = $pconfig['verbosity_level'];
|
328
|
|
329
|
if (isset($id) && $a_client[$id])
|
330
|
$a_client[$id] = $client;
|
331
|
else
|
332
|
$a_client[] = $client;
|
333
|
|
334
|
openvpn_resync('client', $client);
|
335
|
write_config();
|
336
|
|
337
|
header("Location: vpn_openvpn_client.php");
|
338
|
exit;
|
339
|
}
|
340
|
}
|
341
|
|
342
|
include("head.inc");
|
343
|
|
344
|
function build_if_list() {
|
345
|
$list = array();
|
346
|
|
347
|
$interfaces = get_configured_interface_with_descr();
|
348
|
$carplist = get_configured_carp_interface_list();
|
349
|
|
350
|
foreach ($carplist as $cif => $carpip)
|
351
|
$interfaces[$cif.'|'.$carpip] = $carpip." (".get_vip_descr($carpip).")";
|
352
|
|
353
|
$aliaslist = get_configured_ip_aliases_list();
|
354
|
|
355
|
foreach ($aliaslist as $aliasip => $aliasif)
|
356
|
$interfaces[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
|
357
|
|
358
|
$grouplist = return_gateway_groups_array();
|
359
|
|
360
|
foreach ($grouplist as $name => $group) {
|
361
|
if($group['ipprotocol'] != inet)
|
362
|
continue;
|
363
|
|
364
|
if($group[0]['vip'] != "")
|
365
|
$vipif = $group[0]['vip'];
|
366
|
else
|
367
|
$vipif = $group[0]['int'];
|
368
|
|
369
|
$interfaces[$name] = "GW Group {$name}";
|
370
|
}
|
371
|
|
372
|
$interfaces['lo0'] = "Localhost";
|
373
|
$interfaces['any'] = "any";
|
374
|
|
375
|
foreach ($interfaces as $iface => $ifacename)
|
376
|
$list[$iface] = $ifacename;
|
377
|
|
378
|
return($list);
|
379
|
}
|
380
|
|
381
|
function build_cert_list() {
|
382
|
global $a_cert;
|
383
|
|
384
|
$list = array();
|
385
|
|
386
|
foreach ($a_cert as $cert) {
|
387
|
$caname = "";
|
388
|
$inuse = "";
|
389
|
$revoked = "";
|
390
|
$ca = lookup_ca($cert['caref']);
|
391
|
|
392
|
if ($ca)
|
393
|
$caname = " (CA: {$ca['descr']})";
|
394
|
|
395
|
if ($pconfig['certref'] == $cert['refid'])
|
396
|
$selected = "selected=\"selected\"";
|
397
|
|
398
|
if (cert_in_use($cert['refid']))
|
399
|
$inuse = " *In Use";
|
400
|
|
401
|
if (is_cert_revoked($cert))
|
402
|
$revoked = " *Revoked";
|
403
|
|
404
|
$list[$cert['refid']] = $cert['descr'] . $caname . $inuse . $revoked;
|
405
|
}
|
406
|
|
407
|
return($list);
|
408
|
}
|
409
|
|
410
|
if (!$savemsg)
|
411
|
$savemsg = "";
|
412
|
|
413
|
if ($input_errors)
|
414
|
print_input_errors($input_errors);
|
415
|
|
416
|
if ($savemsg)
|
417
|
print_info_box($savemsg, 'success');
|
418
|
|
419
|
$tab_array = array();
|
420
|
$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
|
421
|
$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
|
422
|
$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
|
423
|
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
|
424
|
add_package_tabs("OpenVPN", $tab_array);
|
425
|
display_top_tabs($tab_array);
|
426
|
|
427
|
if($act=="new" || $act=="edit") :
|
428
|
require('classes/Form.class.php');
|
429
|
|
430
|
$form = new Form();
|
431
|
|
432
|
$section = new Form_Section('General Information');
|
433
|
|
434
|
$section->addInput(new Form_checkbox(
|
435
|
'disable',
|
436
|
'Disabled',
|
437
|
'Disable this server',
|
438
|
$pconfig['disable']
|
439
|
))->setHelp('Set this option to disable this client without removing it from the list');
|
440
|
|
441
|
$section->addInput(new Form_Select(
|
442
|
'mode',
|
443
|
'Server mode',
|
444
|
$pconfig['mode'],
|
445
|
$openvpn_client_modes
|
446
|
));
|
447
|
|
448
|
$section->addInput(new Form_Select(
|
449
|
'protocol',
|
450
|
'Protocol',
|
451
|
$pconfig['protocol'],
|
452
|
$openvpn_prots
|
453
|
));
|
454
|
|
455
|
$section->addInput(new Form_Select(
|
456
|
'dev_mode',
|
457
|
'Device mode',
|
458
|
empty($pconfig['dev_mode']) ? 'tun':$pconfig['dev_mode'],
|
459
|
array_combine($openvpn_dev_mode, $openvpn_dev_mode)
|
460
|
));
|
461
|
|
462
|
$section->addInput(new Form_Select(
|
463
|
'interface',
|
464
|
'Interface',
|
465
|
$pconfig['interface'],
|
466
|
build_if_list()
|
467
|
));
|
468
|
|
469
|
$section->addInput(new Form_Input(
|
470
|
'local_port',
|
471
|
'Local port',
|
472
|
'number',
|
473
|
$pconfig['local_port']
|
474
|
))->setHelp('Set this option if you would like to bind to a specific port. Leave this blank or enter 0 for a random dynamic port.');
|
475
|
|
476
|
$section->addInput(new Form_Input(
|
477
|
'sever_addr',
|
478
|
'Server host or address',
|
479
|
'text',
|
480
|
$pconfig['sever_addr']
|
481
|
));
|
482
|
|
483
|
$section->addInput(new Form_Input(
|
484
|
'server_port',
|
485
|
'Server port',
|
486
|
'number',
|
487
|
$pconfig['server_port']
|
488
|
));
|
489
|
|
490
|
$section->addInput(new Form_Input(
|
491
|
'proxy_addr',
|
492
|
'Proxy host or address',
|
493
|
'text',
|
494
|
$pconfig['proxy_addr']
|
495
|
));
|
496
|
|
497
|
$section->addInput(new Form_Select(
|
498
|
'proxy_authtype',
|
499
|
'Proxy Auth. - Extra options',
|
500
|
$pconfig['proxy_authtype'],
|
501
|
array('none' => 'none', 'basic' => 'basic', 'ntlm' => 'ntlm')
|
502
|
));
|
503
|
|
504
|
$section->addInput(new Form_Input(
|
505
|
'proxy_user',
|
506
|
'Username',
|
507
|
'text',
|
508
|
$pconfig['proxy_user']
|
509
|
));
|
510
|
|
511
|
$section->addInput(new Form_Input(
|
512
|
'proxy_passwd',
|
513
|
'Password',
|
514
|
'password',
|
515
|
$pconfig['proxy_passwd']
|
516
|
));
|
517
|
|
518
|
$section->addInput(new Form_checkbox(
|
519
|
'resolve_retry',
|
520
|
'Server hostname resolution',
|
521
|
'Infinitely resolve server ',
|
522
|
$pconfig['resolve_retry']
|
523
|
))->setHelp('Continuously attempt to resolve the server host name. ' .
|
524
|
'Useful when communicating with a server that is not permanently connected to the Internet.');
|
525
|
|
526
|
$section->addInput(new Form_Input(
|
527
|
'description',
|
528
|
'Description',
|
529
|
'text',
|
530
|
$pconfig['description']
|
531
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
532
|
|
533
|
$form->add($section);
|
534
|
$section = new Form_Section('User Authentication settings');
|
535
|
$section->addClass('authentication');
|
536
|
|
537
|
$section->addInput(new Form_Input(
|
538
|
'auth_user',
|
539
|
'Username',
|
540
|
'text',
|
541
|
$pconfig['auth_user']
|
542
|
))->setHelp('Leave empty when no user name is needed');
|
543
|
|
544
|
$section->addInput(new Form_Input(
|
545
|
'auth_passwd',
|
546
|
'Password',
|
547
|
'password',
|
548
|
$pconfig['auth_passwd']
|
549
|
))->setHelp('Leave empty when no password is needed');
|
550
|
|
551
|
$form->add($section);
|
552
|
|
553
|
$section = new Form_Section('Cryptographic settings');
|
554
|
|
555
|
$section->addInput(new Form_checkbox(
|
556
|
'tlsauth_enable',
|
557
|
'TLS authentication',
|
558
|
'Enable authentication of TLS packets.',
|
559
|
$pconfig['tlsauth_enable']
|
560
|
));
|
561
|
|
562
|
if (!$pconfig['tls']) {
|
563
|
$section->addInput(new Form_checkbox(
|
564
|
'autotls_enable',
|
565
|
null,
|
566
|
'Automatically generate a shared TLS authentication key.',
|
567
|
$pconfig['autotls_enable']
|
568
|
));
|
569
|
}
|
570
|
|
571
|
$section->addInput(new Form_TextArea(
|
572
|
'tls',
|
573
|
'Key',
|
574
|
$pconfig['tls']
|
575
|
))->setHelp('Paste your shared key here');
|
576
|
|
577
|
$section->addInput(new Form_Select(
|
578
|
'caref',
|
579
|
'Peer Certifiacte Authority',
|
580
|
$pconfig['caref'],
|
581
|
count($a_ca) ? array_combine($a_ca, $a_ca) : ['' => 'None']
|
582
|
))->setHelp(count($a_ca) ? '':sprintf('No Certificate Authorities defined. You may create one here: %s', '<a href="system_camanager.php">System > Cert Manager</a>'));
|
583
|
|
584
|
$section->addInput(new Form_Select(
|
585
|
'certref',
|
586
|
'Peer Certifiacte Authority',
|
587
|
$pconfig['certref'],
|
588
|
build_cert_list()
|
589
|
))->setHelp(count($a_cert) ? '':sprintf('No Certificates defined. You may create one here: %s', '<a href="system_camanager.php">System > Cert Manager</a>'));
|
590
|
|
591
|
if (!$pconfig['shared_key']) {
|
592
|
$section->addInput(new Form_checkbox(
|
593
|
'autokey_enable',
|
594
|
'Auto generate',
|
595
|
'Automatically generate a shared key',
|
596
|
$pconfig['autokey_enable']
|
597
|
));
|
598
|
}
|
599
|
|
600
|
$section->addInput(new Form_TextArea(
|
601
|
'shared_key',
|
602
|
'Shared Key',
|
603
|
$pconfig['shared_key']
|
604
|
))->setHelp('Paste your shared key here');
|
605
|
|
606
|
$section->addInput(new Form_Select(
|
607
|
'crypto',
|
608
|
'Encryption Algorithm',
|
609
|
$pconfig['crypto'],
|
610
|
openvpn_get_cipherlist()
|
611
|
));
|
612
|
|
613
|
$section->addInput(new Form_Select(
|
614
|
'digest',
|
615
|
'Auth digest algorithm',
|
616
|
$pconfig['digest'],
|
617
|
openvpn_get_digestlist()
|
618
|
))->setHelp('Leave this set to SHA1 unless all clients are set to match. SHA1 is the default for OpenVPN. ');
|
619
|
|
620
|
$section->addInput(new Form_Select(
|
621
|
'engine',
|
622
|
'Hardware Crypto',
|
623
|
$pconfig['engine'],
|
624
|
openvpn_get_engines()
|
625
|
));
|
626
|
|
627
|
$form->add($section);
|
628
|
|
629
|
$section = new Form_Section('Tunnel settings');
|
630
|
|
631
|
$section->addInput(new Form_Input(
|
632
|
'tunnel_network',
|
633
|
'IPv4 Tunnel Network',
|
634
|
'text',
|
635
|
$pconfig['tunnel_network']
|
636
|
))->setHelp('This is the IPv4 virtual network used for private communications between this client and the sercer ' .
|
637
|
'expressed using CIDR (eg. 10.0.8.0/24). The first network address will be assigned to ' .
|
638
|
'the client virtual interface.');
|
639
|
|
640
|
$section->addInput(new Form_Input(
|
641
|
'tunnel_networkv6',
|
642
|
'IPv6 Tunnel Network',
|
643
|
'text',
|
644
|
$pconfig['tunnel_networkv6']
|
645
|
))->setHelp('This is the IPv6 virtual network used for private ' .
|
646
|
'communications between this client and the server expressed using CIDR (eg. fe80::/64). ' .
|
647
|
'The first network address will be assigned to the server virtual interface.');
|
648
|
|
649
|
$section->addInput(new Form_Input(
|
650
|
'remote_network',
|
651
|
'IPv4 Remote network(s)',
|
652
|
'text',
|
653
|
$pconfig['remote_network']
|
654
|
))->setHelp('IPv4 networks that will be routed through the tunnel, so that a site-to-site VPN can be established without manually ' .
|
655
|
'changing the routing tables. Expressed as a comma-separated list of one or more CIDR ranges. ' .
|
656
|
'If this is a site-to-site VPN, enter the remote LAN/s here. You may leave this blank if you don\'t want a site-to-site VPN.');
|
657
|
|
658
|
$section->addInput(new Form_Input(
|
659
|
'remote_networkv6',
|
660
|
'IPv6 Remote network(s)',
|
661
|
'text',
|
662
|
$pconfig['remote_networkv6']
|
663
|
))->setHelp('These are the IPv6 networks that will be routed through the tunnel, so that a site-to-site VPN can be established without manually ' .
|
664
|
'changing the routing tables. Expressed as a comma-separated list of one or more IP/PREFIX. ' .
|
665
|
'If this is a site-to-site VPN, enter the remote LAN/s here. You may leave this blank if you don\'t want a site-to-site VPN.');
|
666
|
|
667
|
$section->addInput(new Form_Input(
|
668
|
'use_shaper',
|
669
|
'Limit outgoing bandwidth',
|
670
|
'number',
|
671
|
$pconfig['use_shaper'],
|
672
|
['min' => 100, 'max' => 100000000, 'placeholder' => 'Between 100 and 100,000,000 bytes/sec']
|
673
|
))->setHelp('Maximum outgoing bandwidth for this tunnel. Leave empty for no limit. The input value has to be something between 100 bytes/sec and 100 Mbytes/sec (entered as bytes per second).');
|
674
|
|
675
|
$section->addInput(new Form_Select(
|
676
|
'compression',
|
677
|
'Compression',
|
678
|
$pconfig['compression'],
|
679
|
$openvpn_compression_modes
|
680
|
))->setHelp('Compress tunnel packets using the LZO algorithm. Adaptive compression will dynamically disable compression for a period of time if OpenVPN detects that the data in the packets is not being compressed efficiently.');
|
681
|
|
682
|
$section->addInput(new Form_checkbox(
|
683
|
'passtos',
|
684
|
'Type-of-Service',
|
685
|
'Set the TOS IP header value of tunnel packets to match the encapsulated packet value.',
|
686
|
$pconfig['passtos']
|
687
|
));
|
688
|
|
689
|
$section->addInput(new Form_checkbox(
|
690
|
'no_tun_ipv6',
|
691
|
'Disable IPv6',
|
692
|
'Don\'t forward IPv6 traffic. ',
|
693
|
$pconfig['no_tun_ipv6']
|
694
|
));
|
695
|
|
696
|
$section->addInput(new Form_checkbox(
|
697
|
'route_no_pull',
|
698
|
'Don\'t pull routes',
|
699
|
'Bars the server from adding routes to the client\'s routing table',
|
700
|
$pconfig['route_no_pull']
|
701
|
))->setHelp('This option still allows the server to set the TCP/IP properties of the client\'s TUN/TAP interface. ');
|
702
|
|
703
|
$section->addInput(new Form_checkbox(
|
704
|
'route_no_exec',
|
705
|
'Don\'t add/remove routes',
|
706
|
'Don\'t add or remove routes automatically',
|
707
|
$pconfig['route_no_exec']
|
708
|
))->setHelp('Pass routes to --route-upscript using environmental variables');
|
709
|
|
710
|
$form->add($section);
|
711
|
|
712
|
$section = new Form_Section('Advanced Configuration');
|
713
|
$section->addClass('advanced');
|
714
|
|
715
|
$section->addInput(new Form_TextArea(
|
716
|
'custom_options',
|
717
|
'Custom options',
|
718
|
$pconfig['custom_options']
|
719
|
))->setHelp('Enter any additional options you would like to add to the OpenVPN server configuration here, separated by semicolon' . '<br />' .
|
720
|
'EXAMPLE: push "route 10.0.0.0 255.255.255.0"');
|
721
|
|
722
|
$section->addInput(new Form_Select(
|
723
|
'verbosity_level',
|
724
|
'Verbosity level',
|
725
|
$pconfig['verbosity_level'],
|
726
|
$openvpn_verbosity_level
|
727
|
))->setHelp('Each level shows all info from the previous levels. Level 3 is recommended if you want a good summary of what\'s happening without being swamped by output' . '<br /><br />' .
|
728
|
'None: Only fatal errors' . '<br />' .
|
729
|
'Default: Normal usage range' . '<br />' .
|
730
|
'5: Output R and W characters to the console for each packet read and write, uppercase is used for TCP/UDP packets and lowercase is used for TUN/TAP packets' .'<br />' .
|
731
|
'6: Debug info range');
|
732
|
|
733
|
$section->addInput(new Form_Input(
|
734
|
'act',
|
735
|
null,
|
736
|
'hidden',
|
737
|
$act
|
738
|
));
|
739
|
|
740
|
if (isset($id) && $a_server[$id]) {
|
741
|
$section->addInput(new Form_Input(
|
742
|
'id',
|
743
|
null,
|
744
|
'hidden',
|
745
|
$id
|
746
|
));
|
747
|
}
|
748
|
|
749
|
$form->add($section);
|
750
|
print($form);
|
751
|
else:
|
752
|
?>
|
753
|
<div class="panel panel-default">
|
754
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('OpenVPN Servers')?></h2></div>
|
755
|
<div class="panel-body table-responsive">
|
756
|
<table class="table table-striped table-hover table-condensed">
|
757
|
<thead>
|
758
|
<tr>
|
759
|
<th><?=gettext("Protocol")?></th>
|
760
|
<th><?=gettext("Server")?></th>
|
761
|
<th><?=gettext("Description")?></th>
|
762
|
<th><!-- Buttons --></th>
|
763
|
</tr>
|
764
|
</thead>
|
765
|
|
766
|
<tbody>
|
767
|
<?php
|
768
|
$i = 0;
|
769
|
foreach($a_client as $client):
|
770
|
$server = "{$client['server_addr']}:{$client['server_port']}";
|
771
|
?>
|
772
|
<tr <?=isset($server['disable']) ? 'class="disabled"':''?>>
|
773
|
<td>
|
774
|
<?=htmlspecialchars($client['protocol'])?>
|
775
|
</td>
|
776
|
<td>
|
777
|
<?=htmlspecialchars($server)?>
|
778
|
</td>
|
779
|
<td>
|
780
|
<?=htmlspecialchars($client['description'])?>
|
781
|
</td>
|
782
|
<td>
|
783
|
<a href="vpn_openvpn_client.php?act=edit&id=<?=$i?>" class="btn btn-xs btn-info"><?=gettext("Edit")?></a>
|
784
|
<a href="vpn_openvpn_client.php?act=del&id=<?=$i?>" class="btn btn-xs btn-danger"><?=gettext("Delete")?></a>
|
785
|
</td>
|
786
|
</tr>
|
787
|
<?php
|
788
|
$i++;
|
789
|
endforeach;
|
790
|
?>
|
791
|
</tbody>
|
792
|
</table>
|
793
|
</div>
|
794
|
</div>
|
795
|
|
796
|
<nav class="action-buttons">
|
797
|
<a href="vpn_openvpn_client.php?act=new" class="btn btn-sm btn-success">
|
798
|
<?=gettext("Add server")?>
|
799
|
</a>
|
800
|
</nav>
|
801
|
|
802
|
<?php
|
803
|
endif;
|
804
|
|
805
|
// Note:
|
806
|
// The following *_change() functions were converted from Javascript/DOM to JQuery but otherwise
|
807
|
// mostly left unchanged. The logic on this form is complex andthis works!
|
808
|
?>
|
809
|
|
810
|
<script type="text/javascript">
|
811
|
//<![CDATA[
|
812
|
events.push(function(){
|
813
|
|
814
|
function mode_change() {
|
815
|
value = $('#mode').val();
|
816
|
|
817
|
switch(value) {
|
818
|
case "p2p_tls":
|
819
|
hideInput('tls', false);
|
820
|
hideCheckbox('tlsauth_enable', false);
|
821
|
hideCheckbox('autotls_enable', false);
|
822
|
hideInput('caref', false);
|
823
|
hideInput('certreft', false);
|
824
|
hideClass('authentication', false);
|
825
|
hideCheckbox('autokey_enable', true);
|
826
|
hideInput('shared_key', true);
|
827
|
break;
|
828
|
case "p2p_shared_key":
|
829
|
hideInput('tls', true);
|
830
|
hideCheckbox('tlsauth_enable', true);
|
831
|
hideCheckbox('autotls_enable', true);
|
832
|
hideInput('caref', true);
|
833
|
hideInput('certreft', true);
|
834
|
hideClass('authentication', true);
|
835
|
hideCheckbox('autokey_enable', false);
|
836
|
hideInput('shared_key', false);
|
837
|
break;
|
838
|
}
|
839
|
}
|
840
|
|
841
|
function dev_mode_change() {
|
842
|
hideCheckbox('no_tun_ipv6', ($('#dev_mode').val() == 'tap'));
|
843
|
}
|
844
|
|
845
|
function autokey_change() {
|
846
|
hideInput('shared_key', $('#autokey_enable').prop('checked'));
|
847
|
}
|
848
|
|
849
|
function useproxy_changed() {
|
850
|
hideInput('proxy_user', ($('#proxy_authtype').val() == 'none'));
|
851
|
hideInput('proxy_passwd', ($('#proxy_authtype').val() == 'none'));
|
852
|
}
|
853
|
|
854
|
function tlsauth_change() {
|
855
|
var hide = ! $('#tlsauth_enable').prop('checked')
|
856
|
|
857
|
<?php if (!$pconfig['tls']): ?>
|
858
|
hideCheckbox('autotls_enable', hide);
|
859
|
<?php endif; ?>
|
860
|
|
861
|
autotls_change();
|
862
|
}
|
863
|
|
864
|
function autotls_change() {
|
865
|
|
866
|
<?php if (!$pconfig['tls']): ?>
|
867
|
autocheck = $('#autotls_enable').prop('checked');
|
868
|
<?php else: ?>
|
869
|
autocheck = false;
|
870
|
<?php endif; ?>
|
871
|
|
872
|
if ($('#tlsauth_enable').prop('checked') && !autocheck)
|
873
|
hideInput('tls', false);
|
874
|
else
|
875
|
hideInput('tls', true);
|
876
|
}
|
877
|
|
878
|
// ---------- Library of show/hide functions ----------------------------------------------------------------------
|
879
|
|
880
|
// Hides the <div> in which the specified input element lives so that the input,
|
881
|
// its label and help text are hidden
|
882
|
function hideInput(id, hide) {
|
883
|
if(hide)
|
884
|
$('#' + id).parent().parent('div').addClass('hidden');
|
885
|
else
|
886
|
$('#' + id).parent().parent('div').removeClass('hidden');
|
887
|
}
|
888
|
|
889
|
// Hides the <div> in which the specified checkbox lives so that the checkbox,
|
890
|
// its label and help text are hidden
|
891
|
function hideCheckbox(id, hide) {
|
892
|
if(hide)
|
893
|
$('#' + id).parent().parent().parent('div').addClass('hidden');
|
894
|
else
|
895
|
$('#' + id).parent().parent().parent('div').removeClass('hidden');
|
896
|
}
|
897
|
|
898
|
// Disables the specified input element
|
899
|
function disableInput(id, disable) {
|
900
|
$('#' + id).prop("disabled", disable);
|
901
|
}
|
902
|
|
903
|
// Hides all elements of the specified class. This will usually be a section or group
|
904
|
function hideClass(s_class, hide) {
|
905
|
if(hide)
|
906
|
$('.' + s_class).hide();
|
907
|
else
|
908
|
$('.' + s_class).show();
|
909
|
}
|
910
|
|
911
|
// ---------- Monitor elements for change and call the appropriate display functions ------------------------------
|
912
|
|
913
|
// TLS Authorization
|
914
|
$('#tlsauth_enable').click(function () {
|
915
|
tlsauth_change();
|
916
|
});
|
917
|
|
918
|
// Auto key
|
919
|
$('#autokey_enable').click(function () {
|
920
|
autokey_change();
|
921
|
});
|
922
|
|
923
|
// Mode
|
924
|
$('#mode').click(function () {
|
925
|
mode_change();
|
926
|
});
|
927
|
|
928
|
// Use proxy
|
929
|
$('#proxy_authtype').click(function () {
|
930
|
useproxy_changed();
|
931
|
});
|
932
|
|
933
|
// Tun/tap
|
934
|
$('#dev_mode').click(function () {
|
935
|
dev_mode_change();
|
936
|
});
|
937
|
|
938
|
// ---------- Set initial page display state ----------------------------------------------------------------------
|
939
|
mode_change();
|
940
|
autokey_change();
|
941
|
tlsauth_change();
|
942
|
useproxy_changed();
|
943
|
dev_mode_change();
|
944
|
});
|
945
|
//]]>
|
946
|
</script>
|
947
|
|
948
|
<?php include("foot.inc");
|