Project

General

Profile

Download (40.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/*
3
	vpn_openvpn_client.php
4

    
5
	Copyright (C) 2008 Shrew Soft Inc.
6
	All rights reserved. 
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
	
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
	
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
	
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
##|+PRIV
31
##|*IDENT=page-openvpn-client
32
##|*NAME=OpenVPN: Client page
33
##|*DESCR=Allow access to the 'OpenVPN: Client' page.
34
##|*MATCH=vpn_openvpn_client.php*
35
##|-PRIV
36

    
37
require("guiconfig.inc");
38
require_once("openvpn.inc");
39

    
40
$pgtitle = array(gettext("OpenVPN"), gettext("Client"));
41
$shortcut_section = "openvpn";
42

    
43
if (!is_array($config['openvpn']['openvpn-client']))
44
	$config['openvpn']['openvpn-client'] = array();
45

    
46
$a_client = &$config['openvpn']['openvpn-client'];
47

    
48
if (!is_array($config['ca']))
49
	$config['ca'] = array();
50

    
51
$a_ca =& $config['ca'];
52

    
53
if (!is_array($config['cert']))
54
	$config['cert'] = array();
55

    
56
$a_cert =& $config['cert'];
57

    
58
if (!is_array($config['crl']))
59
	$config['crl'] = array();
60

    
61
$a_crl =& $config['crl'];
62

    
63
if (is_numericint($_GET['id']))
64
	$id = $_GET['id'];
65
if (isset($_POST['id']) && is_numericint($_POST['id']))
66
	$id = $_POST['id'];
67

    
68
$act = $_GET['act'];
69
if (isset($_POST['act']))
70
	$act = $_POST['act'];
71

    
72
if (isset($id) && $a_client[$id])
73
	$vpnid = $a_client[$id]['vpnid'];
74
else
75
	$vpnid = 0;
76

    
77
if ($_GET['act'] == "del") {
78

    
79
	if (!isset($a_client[$id])) {
80
		pfSenseHeader("vpn_openvpn_client.php");
81
		exit;
82
	}
83
	if (!empty($a_client[$id]))
84
		openvpn_delete('client', $a_client[$id]);
85
	unset($a_client[$id]);
86
	write_config();
87
	$savemsg = gettext("Client successfully deleted")."<br />";
88
}
89

    
90
if($_GET['act']=="new"){
91
	$pconfig['autokey_enable'] = "yes";
92
	$pconfig['tlsauth_enable'] = "yes";
93
	$pconfig['autotls_enable'] = "yes";
94
	$pconfig['interface'] = "wan";
95
	$pconfig['server_port'] = 1194;
96
	// OpenVPN Defaults to SHA1
97
	$pconfig['digest'] = "SHA1";
98
}
99

    
100
if($_GET['act']=="edit"){
101

    
102
	if (isset($id) && $a_client[$id]) {
103

    
104
		$pconfig['disable'] = isset($a_client[$id]['disable']);
105
		$pconfig['mode'] = $a_client[$id]['mode'];
106
		$pconfig['protocol'] = $a_client[$id]['protocol'];
107
		$pconfig['interface'] = $a_client[$id]['interface'];
108
		if (!empty($a_client[$id]['ipaddr'])) {
109
			$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$id]['ipaddr'];
110
		}
111
		$pconfig['local_port'] = $a_client[$id]['local_port'];
112
		$pconfig['server_addr'] = $a_client[$id]['server_addr'];
113
		$pconfig['server_port'] = $a_client[$id]['server_port'];
114
		$pconfig['resolve_retry'] = $a_client[$id]['resolve_retry'];
115
		$pconfig['proxy_addr'] = $a_client[$id]['proxy_addr'];
116
		$pconfig['proxy_port'] = $a_client[$id]['proxy_port'];
117
		$pconfig['proxy_user'] = $a_client[$id]['proxy_user'];
118
		$pconfig['proxy_passwd'] = $a_client[$id]['proxy_passwd'];
119
		$pconfig['proxy_authtype'] = $a_client[$id]['proxy_authtype'];
120
		$pconfig['description'] = $a_client[$id]['description'];
121
		$pconfig['custom_options'] = $a_client[$id]['custom_options'];
122
		$pconfig['ns_cert_type'] = $a_client[$id]['ns_cert_type'];
123
		$pconfig['dev_mode'] = $a_client[$id]['dev_mode'];
124
	
125
		if ($pconfig['mode'] != "p2p_shared_key") {
126
			$pconfig['caref'] = $a_client[$id]['caref'];
127
			$pconfig['certref'] = $a_client[$id]['certref'];
128
			if ($a_client[$id]['tls']) {
129
				$pconfig['tlsauth_enable'] = "yes";
130
				$pconfig['tls'] = base64_decode($a_client[$id]['tls']);
131
			}
132
		} else
133
			$pconfig['shared_key'] = base64_decode($a_client[$id]['shared_key']);
134
		$pconfig['crypto'] = $a_client[$id]['crypto'];
135
		// OpenVPN Defaults to SHA1 if unset
136
		$pconfig['digest'] = !empty($a_client[$id]['digest']) ? $a_client[$id]['digest'] : "SHA1";
137
		$pconfig['engine'] = $a_client[$id]['engine'];
138

    
139
		$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
140
		$pconfig['tunnel_networkv6'] = $a_client[$id]['tunnel_networkv6'];
141
		$pconfig['remote_network'] = $a_client[$id]['remote_network'];
142
		$pconfig['remote_networkv6'] = $a_client[$id]['remote_networkv6'];
143
		$pconfig['use_shaper'] = $a_client[$id]['use_shaper'];
144
		$pconfig['compression'] = $a_client[$id]['compression'];
145
		$pconfig['passtos'] = $a_client[$id]['passtos'];
146

    
147
		// just in case the modes switch
148
		$pconfig['autokey_enable'] = "yes";
149
		$pconfig['autotls_enable'] = "yes";
150
	}
151
}
152

    
153
if ($_POST) {
154

    
155
	unset($input_errors);
156
	$pconfig = $_POST;
157

    
158
	if (isset($id) && $a_client[$id])
159
		$vpnid = $a_client[$id]['vpnid'];
160
	else
161
		$vpnid = 0;
162

    
163
	list($iv_iface, $iv_ip) = explode ("|",$pconfig['interface']);
164
	if (is_ipaddrv4($iv_ip) && (stristr($pconfig['protocol'], "6") !== false)) {
165
		$input_errors[] = gettext("Protocol and IP address families do not match. You cannot select an IPv6 protocol and an IPv4 IP address.");
166
	} elseif (is_ipaddrv6($iv_ip) && (stristr($pconfig['protocol'], "6") === false)) {
167
		$input_errors[] = gettext("Protocol and IP address families do not match. You cannot select an IPv4 protocol and an IPv6 IP address.");
168
	} elseif ((stristr($pconfig['protocol'], "6") === false) && !get_interface_ip($iv_iface) && ($pconfig['interface'] != "any")) {
169
		$input_errors[] = gettext("An IPv4 protocol was selected, but the selected interface has no IPv4 address.");
170
	} elseif ((stristr($pconfig['protocol'], "6") !== false) && !get_interface_ipv6($iv_iface) && ($pconfig['interface'] != "any")) {
171
		$input_errors[] = gettext("An IPv6 protocol was selected, but the selected interface has no IPv6 address.");
172
	}
173

    
174
	if ($pconfig['mode'] != "p2p_shared_key")
175
		$tls_mode = true;
176
	else
177
		$tls_mode = false;
178

    
179
	/* input validation */
180
	if ($pconfig['local_port']) {
181

    
182
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
183
			$input_errors[] = $result;
184

    
185
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['interface'], $pconfig['local_port'], $vpnid);
186
		if (($portused != $vpnid) && ($portused != 0))
187
			$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
188
	}
189

    
190
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
191
		$input_errors[] = $result;
192

    
193
	if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
194
		$input_errors[] = $result;
195

    
196
	if ($pconfig['proxy_addr']) {
197

    
198
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
199
			$input_errors[] = $result;
200

    
201
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
202
			$input_errors[] = $result;
203

    
204
		if ($pconfig['proxy_authtype'] != "none") {
205
			if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
206
				$input_errors[] = gettext("User name and password are required for proxy with authentication.");
207
		}
208
	}
209

    
210
	if($pconfig['tunnel_network'])
211
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'IPv4 Tunnel Network', false, "ipv4"))
212
			$input_errors[] = $result;
213

    
214
	if($pconfig['tunnel_networkv6'])
215
		if ($result = openvpn_validate_cidr($pconfig['tunnel_networkv6'], 'IPv6 Tunnel Network', false, "ipv6"))
216
			$input_errors[] = $result;
217

    
218
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4"))
219
		$input_errors[] = $result;
220

    
221
	if ($result = openvpn_validate_cidr($pconfig['remote_networkv6'], 'IPv6 Remote Network', true, "ipv6"))
222
		$input_errors[] = $result;
223

    
224
	if (!empty($pconfig['use_shaper']) && (!is_numeric($pconfig['use_shaper']) || ($pconfig['use_shaper'] <= 0)))
225
		$input_errors[] = gettext("The bandwidth limit must be a positive numeric value.");
226

    
227
    if ($pconfig['autokey_enable'])
228
        $pconfig['shared_key'] = openvpn_create_key();
229

    
230
	if (!$tls_mode && !$pconfig['autokey_enable'])
231
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
232
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
233
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
234

    
235
	if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
236
		if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
237
			!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
238
			$input_errors[] = gettext("The field 'TLS Authentication Key' does not appear to be valid");
239

    
240
	/* If we are not in shared key mode, then we need the CA/Cert. */
241
	if ($pconfig['mode'] != "p2p_shared_key") {
242
		$reqdfields = explode(" ", "caref certref");
243
		$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
244
	} elseif (!$pconfig['autokey_enable']) {
245
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
246
		$reqdfields = array('shared_key');
247
		$reqdfieldsn = array(gettext('Shared key'));
248
	}
249

    
250
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
251
	
252
	if (!$input_errors) {
253

    
254
		$client = array();
255

    
256
		if ($vpnid)
257
			$client['vpnid'] = $vpnid;
258
		else
259
			$client['vpnid'] = openvpn_vpnid_next();
260

    
261
		if ($_POST['disable'] == "yes")
262
			$client['disable'] = true;
263
		$client['protocol'] = $pconfig['protocol'];
264
		$client['dev_mode'] = $pconfig['dev_mode'];
265
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
266
		$client['local_port'] = $pconfig['local_port'];
267
		$client['server_addr'] = $pconfig['server_addr'];
268
		$client['server_port'] = $pconfig['server_port'];
269
		$client['resolve_retry'] = $pconfig['resolve_retry'];
270
		$client['proxy_addr'] = $pconfig['proxy_addr'];
271
		$client['proxy_port'] = $pconfig['proxy_port'];
272
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
273
		$client['proxy_user'] = $pconfig['proxy_user'];
274
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
275
		$client['description'] = $pconfig['description'];
276
		$client['mode'] = $pconfig['mode'];
277
		$client['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
278

    
279
        if ($tls_mode) {
280
            $client['caref'] = $pconfig['caref'];
281
            $client['certref'] = $pconfig['certref'];
282
            if ($pconfig['tlsauth_enable']) {
283
                if ($pconfig['autotls_enable'])
284
                    $pconfig['tls'] = openvpn_create_key();
285
                $client['tls'] = base64_encode($pconfig['tls']);
286
            }
287
        } else {
288
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
289
        }
290
		$client['crypto'] = $pconfig['crypto'];
291
		$client['digest'] = $pconfig['digest'];
292
		$client['engine'] = $pconfig['engine'];
293

    
294
		$client['tunnel_network'] = $pconfig['tunnel_network'];
295
		$client['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
296
		$client['remote_network'] = $pconfig['remote_network'];
297
		$client['remote_networkv6'] = $pconfig['remote_networkv6'];
298
		$client['use_shaper'] = $pconfig['use_shaper'];
299
		$client['compression'] = $pconfig['compression'];
300
		$client['passtos'] = $pconfig['passtos'];
301

    
302
		if (isset($id) && $a_client[$id])
303
			$a_client[$id] = $client;
304
		else
305
			$a_client[] = $client;
306

    
307
		openvpn_resync('client', $client);
308
		write_config();
309
		
310
		header("Location: vpn_openvpn_client.php");
311
		exit;
312
	}
313
}
314

    
315
include("head.inc");
316

    
317
?>
318

    
319
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
320
<?php include("fbegin.inc"); ?>
321
<script language="JavaScript">
322
<!--
323

    
324
function mode_change() {
325
	index = document.iform.mode.selectedIndex;
326
	value = document.iform.mode.options[index].value;
327
	switch(value) {
328
		case "p2p_tls":
329
			document.getElementById("tls").style.display="";
330
			document.getElementById("tls_ca").style.display="";
331
			document.getElementById("tls_cert").style.display="";
332
			document.getElementById("psk").style.display="none";
333
			break;
334
		case "p2p_shared_key":
335
			document.getElementById("tls").style.display="none";
336
			document.getElementById("tls_ca").style.display="none";
337
			document.getElementById("tls_cert").style.display="none";
338
			document.getElementById("psk").style.display="";
339
			break;
340
	}
341
}
342

    
343
function autokey_change() {
344
	if (document.iform.autokey_enable.checked)
345
		document.getElementById("autokey_opts").style.display="none";
346
	else
347
		document.getElementById("autokey_opts").style.display="";
348
}
349

    
350
function useproxy_changed() {
351

    
352
	if (jQuery('#proxy_authtype').val() != 'none') {
353
                jQuery('#proxy_authtype_opts').show();
354
        } else {
355
                jQuery('#proxy_authtype_opts').hide();
356
        }
357
}
358

    
359
function tlsauth_change() {
360

    
361
<?php if (!$pconfig['tls']): ?>
362
	if (document.iform.tlsauth_enable.checked)
363
		document.getElementById("tlsauth_opts").style.display="";
364
	else
365
		document.getElementById("tlsauth_opts").style.display="none";
366
<?php endif; ?>
367

    
368
	autotls_change();
369
}
370

    
371
function autotls_change() {
372

    
373
<?php if (!$pconfig['tls']): ?>
374
	autocheck = document.iform.autotls_enable.checked;
375
<?php else: ?>
376
	autocheck = false;
377
<?php endif; ?>
378

    
379
	if (document.iform.tlsauth_enable.checked && !autocheck)
380
		document.getElementById("autotls_opts").style.display="";
381
	else
382
		document.getElementById("autotls_opts").style.display="none";
383
}
384

    
385
//-->
386
</script>
387
<?php
388
if (!$savemsg)
389
	$savemsg = "";
390

    
391
if ($input_errors)
392
	print_input_errors($input_errors);
393
if ($savemsg)
394
	print_info_box($savemsg);
395
?>
396
<table width="100%" border="0" cellpadding="0" cellspacing="0">
397
 	<tr>
398
		<td class="tabnavtbl">
399
			<ul id="tabnav">
400
			<?php 
401
				$tab_array = array();
402
				$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
403
				$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
404
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
405
				$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
406
				add_package_tabs("OpenVPN", $tab_array);
407
				display_top_tabs($tab_array);
408
			?>
409
			</ul>
410
		</td>
411
	</tr>    
412
	<tr>
413
		<td class="tabcont">
414

    
415
			<?php if($act=="new" || $act=="edit"): ?>
416

    
417
			<form action="vpn_openvpn_client.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
418
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
419
					<tr>
420
						<td colspan="2" valign="top" class="listtopic"><?=gettext("General information"); ?></td>
421
					</tr>
422
					<tr>
423
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
424
						<td width="78%" class="vtable">
425
							<table border="0" cellpadding="0" cellspacing="0">
426
								<tr>
427
									<td>
428
										<?php set_checked($pconfig['disable'],$chk); ?>
429
										<input name="disable" type="checkbox" value="yes" <?=$chk;?>/>
430
									</td>
431
									<td>
432
										&nbsp;
433
										<span class="vexpl">
434
											<strong><?=gettext("Disable this client"); ?></strong><br />
435
										</span>
436
									</td>
437
								</tr>
438
							</table>
439
							<?=gettext("Set this option to disable this client without removing it from the list"); ?>.
440
						</td>
441
					</tr>
442
					<tr>
443
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server Mode");?></td>
444
						<td width="78%" class="vtable">
445
							<select name='mode' id='mode' class="formselect" onchange='mode_change()'>
446
							<?php
447
								foreach ($openvpn_client_modes as $name => $desc):
448
									$selected = "";
449
									if ($pconfig['mode'] == $name)
450
										$selected = "selected";
451
							?>
452
								<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
453
							<?php endforeach; ?>
454
							</select>
455
						</td>
456
					</tr>
457
					<tr>
458
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
459
							<td width="78%" class="vtable">
460
							<select name='protocol' class="formselect">
461
							<?php
462
								foreach ($openvpn_prots as $prot):
463
									$selected = "";
464
									if ($pconfig['protocol'] == $prot)
465
										$selected = "selected";
466
							?>
467
								<option value="<?=$prot;?>" <?=$selected;?>><?=$prot;?></option>
468
							<?php endforeach; ?>
469
							</select>
470
							</td>
471
					</tr>
472
                                        <tr>
473
                                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Device mode");?></td>
474
                                                        <td width="78%" class="vtable">
475
                                                        <select name='dev_mode' class="formselect">
476
                                                        <?php
477
                                                                foreach ($openvpn_dev_mode as $mode):
478
                                                                        $selected = "";
479
                                                                        if ($pconfig['dev_mode'] == $mode)
480
                                                                                $selected = "selected";
481
                                                        ?>
482
                                                                <option value="<?=$mode;?>" <?=$selected;?>><?=$mode;?></option>
483
                                                        <?php endforeach; ?>
484
                                                        </select>
485
                                                        </td>
486
                                        </tr>
487
					<tr>
488
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
489
						<td width="78%" class="vtable">
490
							<select name="interface" class="formselect">
491
								<?php
492
									$interfaces = get_configured_interface_with_descr();
493
									$carplist = get_configured_carp_interface_list();
494
									foreach ($carplist as $cif => $carpip)
495
										$interfaces[$cif.'|'.$carpip] = $carpip." (".get_vip_descr($carpip).")";
496
									$aliaslist = get_configured_ip_aliases_list();
497
									foreach ($aliaslist as $aliasip => $aliasif)
498
										$interfaces[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
499
									$grouplist = return_gateway_groups_array();
500
									foreach ($grouplist as $name => $group) {
501
										if($group['ipprotocol'] != inet)
502
											continue;
503
										if($group[0]['vip'] <> "")
504
											$vipif = $group[0]['vip'];
505
										else
506
											$vipif = $group[0]['int'];
507
										$interfaces[$name] = "GW Group {$name}";
508
									}
509
									$interfaces['lo0'] = "Localhost";
510
									$interfaces['any'] = "any";
511
									foreach ($interfaces as $iface => $ifacename):
512
										$selected = "";
513
										if ($iface == $pconfig['interface'])
514
											$selected = "selected";
515
								?>
516
									<option value="<?=$iface;?>" <?=$selected;?>>
517
										<?=htmlspecialchars($ifacename);?>
518
									</option>
519
								<?php endforeach; ?>
520
							</select> <br />
521
						</td>
522
					</tr>
523
					<tr>
524
						<td width="22%" valign="top" class="vncell"><?=gettext("Local port");?></td>
525
						<td width="78%" class="vtable">
526
							<input name="local_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['local_port']);?>"/>
527
							<br />
528
							<?=gettext("Set this option if you would like to bind to a specific port. Leave this blank or enter 0 for a random dynamic port."); ?>
529
						</td>
530
					</tr>
531
					<tr>
532
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server host or address");?></td>
533
						<td width="78%" class="vtable">
534
							<input name="server_addr" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['server_addr']);?>"/>
535
						</td>
536
					</tr>
537
					<tr>
538
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server port");?></td>
539
						<td width="78%" class="vtable">
540
							<input name="server_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['server_port']);?>"/>
541
						</td>
542
					</tr>
543
					<tr>
544
						<td width="22%" valign="top" class="vncell"><?=gettext("Proxy host or address");?></td>
545
						<td width="78%" class="vtable">
546
							<input name="proxy_addr" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['proxy_addr']);?>"/>
547
						</td>
548
					</tr>
549
					<tr>
550
						<td width="22%" valign="top" class="vncell"><?=gettext("Proxy port");?></td>
551
						<td width="78%" class="vtable">
552
							<input name="proxy_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['proxy_port']);?>"/>
553
						</td>
554
					</tr>
555
					<tr>
556
						<td width="22%" valign="top" class="vncell"><?=gettext("Proxy authentication extra options");?></td>
557
						<td width="78%" class="vtable">
558
							<table border="0" cellpadding="2" cellspacing="0">
559
								<tr>
560
                                                                        <td align="right" width="25%">
561
                                                                                <span class="vexpl">
562
                                                                                         &nbsp;<?=gettext("Authentication method"); ?> :&nbsp;
563
                                                                                </span>
564
                                                                        </td>
565
                                                                        <td>
566
										<select name="proxy_authtype" id="proxy_authtype" class="formfld select" onChange="useproxy_changed()">
567
											<option value="none" <?php if ($pconfig['proxy_authtype'] == "none") echo "selected"; ?>><?=gettext("none"); ?></option>
568
											<option value="basic" <?php if ($pconfig['proxy_authtype'] == "basic") echo "selected"; ?>><?=gettext("basic"); ?></option>
569
											<option value="ntlm" <?php if ($pconfig['proxy_authtype'] == "ntlm") echo "selected"; ?>><?=gettext("ntlm"); ?></option>
570
										</select>
571
									</td>
572
								</tr>
573
							</table>
574
							<br />
575
							 <table border="0" cellpadding="2" cellspacing="0" id="proxy_authtype_opts" style="display:none">
576
                                                                <tr>
577
                                                                        <td align="right" width="25%">
578
                                                                                <span class="vexpl">
579
                                                                                         &nbsp;<?=gettext("Username"); ?> :&nbsp;
580
                                                                                </span>
581
                                                                        </td>
582
                                                                        <td>
583
                                                                                <input name="proxy_user" id="proxy_user" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['proxy_user']);?>" />
584
                                                                        </td>
585
                                                                </tr>
586
                                                                <tr>
587
                                                                        <td align="right" width="25%">
588
                                                                                <span class="vexpl">
589
                                                                                         &nbsp;<?=gettext("Password"); ?> :&nbsp;
590
                                                                                </span>
591
                                                                        </td>
592
                                                                        <td>
593
                                                                                <input name="proxy_passwd" id="proxy_passwd" type="password" class="formfld pwd" size="20" value="<?=htmlspecialchars($pconfig['proxy_passwd']);?>" />
594
                                                                        </td>
595
                                                                </tr>
596
                                                        </table>
597
						</td>
598
					</tr>
599
					<tr>
600
						<td width="22%" valign="top" class="vncell"><?=gettext("Server host name resolution"); ?></td>
601
						<td width="78%" class="vtable">
602
							<table border="0" cellpadding="2" cellspacing="0">
603
								<tr>
604
									<td>
605
										<?php set_checked($pconfig['resolve_retry'],$chk); ?>
606
										<input name="resolve_retry" type="checkbox" value="yes" <?=$chk;?>>
607
									</td>
608
									<td>
609
										<span class="vexpl">
610
											<?=gettext("Infinitely resolve server"); ?>
611
										</span>
612
									</td>
613
								</tr>
614
							</table>
615
							<?=gettext("Continuously attempt to resolve the server host " .
616
							"name. Useful when communicating with a server " .
617
							"that is not permanently connected to the Internet"); ?>.
618
						</td>
619
					</tr>
620
					<tr> 
621
						<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
622
						<td width="78%" class="vtable"> 
623
							<input name="description" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['description']);?>">
624
							<br />
625
							<?=gettext("You may enter a description here for your reference (not parsed)"); ?>.
626
						</td>
627
					</tr>
628
					<tr>
629
						<td colspan="2" class="list" height="12"></td>
630
					</tr>
631
					<tr>
632
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Cryptographic Settings"); ?></td>
633
					</tr>
634
					<tr id="tls">
635
						<td width="22%" valign="top" class="vncellreq"><?=gettext("TLS Authentication"); ?></td>
636
						<td width="78%" class="vtable">
637
							<table border="0" cellpadding="2" cellspacing="0">
638
								<tr>
639
									<td>
640
										<?php set_checked($pconfig['tlsauth_enable'],$chk); ?>
641
										<input name="tlsauth_enable" id="tlsauth_enable" type="checkbox" value="yes" <?=$chk;?> onClick="tlsauth_change()">
642
									</td>
643
									<td>
644
										<span class="vexpl">
645
											<?=gettext("Enable authentication of TLS packets"); ?>.
646
										</span>
647
									</td>
648
								</tr>
649
							</table>
650
							<?php if (!$pconfig['tls']): ?>
651
							<table border="0" cellpadding="2" cellspacing="0" id='tlsauth_opts'>
652
								<tr>
653
									<td>
654
										<?php set_checked($pconfig['autotls_enable'],$chk); ?>
655
										<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autotls_change()">
656
									</td>
657
									<td>
658
										<span class="vexpl">
659
											<?=gettext("Automatically generate a shared TLS authentication key"); ?>.
660
										</span>
661
									</td>
662
								</tr>
663
							</table>
664
							<?php endif; ?>
665
							<table border="0" cellpadding="2" cellspacing="0" id='autotls_opts'>
666
								<tr>
667
									<td>
668
										<textarea name="tls" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['tls']);?></textarea>
669
										<br />
670
										<?=gettext("Paste your shared key here"); ?>.
671
									</td>
672
								</tr>
673
							</table>
674
						</td>
675
					</tr>
676
					<tr id="tls_ca">
677
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Peer Certificate Authority"); ?></td>
678
							<td width="78%" class="vtable">
679
							<?php if (count($a_ca)): ?>
680
							<select name='caref' class="formselect">
681
							<?php
682
								foreach ($a_ca as $ca):
683
									$selected = "";
684
									if ($pconfig['caref'] == $ca['refid'])
685
										$selected = "selected";
686
							?>
687
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
688
							<?php endforeach; ?>
689
							</select>
690
							<?php else: ?>
691
								<b>No Certificate Authorities defined.</b> <br />Create one under <a href="system_camanager.php">System &gt; Cert Manager</a>.
692
							<?php endif; ?>
693
							</td>
694
					</tr>
695
					<tr id="tls_cert">
696
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Client Certificate"); ?></td>
697
							<td width="78%" class="vtable">
698
							<?php if (count($a_cert)): ?>
699
							<select name='certref' class="formselect">
700
							<?php
701
							foreach ($a_cert as $cert):
702
								$selected = "";
703
								$caname = "";
704
								$inuse = "";
705
								$revoked = "";
706
								$ca = lookup_ca($cert['caref']);
707
								if ($ca)
708
									$caname = " (CA: {$ca['descr']})";
709
								if ($pconfig['certref'] == $cert['refid'])
710
									$selected = "selected";
711
								if (cert_in_use($cert['refid']))
712
									$inuse = " *In Use";
713
								if (is_cert_revoked($cert))
714
									$revoked = " *Revoked";
715
							?>
716
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
717
							<?php endforeach; ?>
718
							</select>
719
							<?php else: ?>
720
								<b>No Certificates defined.</b> <br />Create one under <a href="system_certmanager.php">System &gt; Cert Manager</a>.
721
							<?php endif; ?>
722
						</td>
723
					</tr>
724
					<tr id="psk">
725
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Shared Key"); ?></td>
726
						<td width="78%" class="vtable">
727
							<?php if (!$pconfig['shared_key']): ?>
728
							<table border="0" cellpadding="2" cellspacing="0">
729
								<tr>
730
									<td>
731
										<?php set_checked($pconfig['autokey_enable'],$chk); ?>
732
										<input name="autokey_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autokey_change()">
733
									</td>
734
									<td>
735
										<span class="vexpl">
736
											<?=gettext("Automatically generate a shared key"); ?>.
737
										</span>
738
									</td>
739
								</tr>
740
							</table>
741
							<?php endif; ?>
742
							<table border="0" cellpadding="2" cellspacing="0" id='autokey_opts'>
743
								<tr>
744
									<td>
745
										<textarea name="shared_key" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['shared_key']);?></textarea>
746
										<br />
747
										<?=gettext("Paste your shared key here"); ?>.
748
									</td>
749
								</tr>
750
							</table>
751
						</td>
752
					</tr>
753
					<tr>
754
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Encryption algorithm"); ?></td>
755
						<td width="78%" class="vtable">
756
							<select name="crypto" class="formselect">
757
								<?php
758
									$cipherlist = openvpn_get_cipherlist();
759
									foreach ($cipherlist as $name => $desc):
760
									$selected = '';
761
									if ($name == $pconfig['crypto'])
762
										$selected = ' selected';
763
								?>
764
								<option value="<?=$name;?>"<?=$selected?>>
765
									<?=htmlspecialchars($desc);?>
766
								</option>
767
								<?php endforeach; ?>
768
							</select>
769
						</td>
770
					</tr>
771
					<tr>
772
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Auth Digest Algorithm"); ?></td>
773
						<td width="78%" class="vtable">
774
							<select name="digest" class="formselect">
775
								<?php
776
									$digestlist = openvpn_get_digestlist();
777
									foreach ($digestlist as $name => $desc):
778
									$selected = '';
779
									if ($name == $pconfig['digest'])
780
										$selected = ' selected';
781
								?>
782
								<option value="<?=$name;?>"<?=$selected?>>
783
									<?=htmlspecialchars($desc);?>
784
								</option>
785
								<?php endforeach; ?>
786
							</select>
787
						</td>
788
					</tr>
789
					<tr id="engine">
790
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Hardware Crypto"); ?></td>
791
						<td width="78%" class="vtable">
792
							<select name="engine" class="formselect">
793
								<?php
794
									$engines = openvpn_get_engines();
795
									foreach ($engines as $name => $desc):
796
									$selected = '';
797
									if ($name == $pconfig['engine'])
798
										$selected = ' selected';
799
								?>
800
								<option value="<?=$name;?>"<?=$selected?>>
801
									<?=htmlspecialchars($desc);?>
802
								</option>
803
								<?php endforeach; ?>
804
							</select>
805
						</td>
806
					</tr>
807
					<tr>
808
						<td colspan="2" class="list" height="12"></td>
809
					</tr>
810
					<tr>
811
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Tunnel Settings"); ?></td>
812
					</tr>
813
					<tr>
814
						<td width="22%" valign="top" class="vncell"><?=gettext("IPv4 Tunnel Network"); ?></td>
815
						<td width="78%" class="vtable">
816
							<input name="tunnel_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['tunnel_network']);?>">
817
							<br />
818
							<?=gettext("This is the virtual network used for private " .
819
							"communications between this client and the " .
820
							"server expressed using CIDR (eg. 10.0.8.0/24). " .
821
							"The first network address is assumed to be the " .
822
							"server address and the second network address " .
823
							"will be assigned to the client virtual " .
824
							"interface"); ?>.
825
						</td>
826
					</tr>
827
					<tr>
828
						<td width="22%" valign="top" class="vncell"><?=gettext("IPv6 Tunnel Network"); ?></td>
829
						<td width="78%" class="vtable">
830
							<input name="tunnel_networkv6" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['tunnel_networkv6']);?>">
831
							<br />
832
							<?=gettext("This is the IPv6 virtual network used for private " .
833
							"communications between this client and the " .
834
							"server expressed using CIDR (eg. fe80::/64). " .
835
							"The first network address is assumed to be the " .
836
							"server address and the second network address " .
837
							"will be assigned to the client virtual " .
838
							"interface"); ?>.
839
						</td>
840
					</tr>
841
					<tr>
842
						<td width="22%" valign="top" class="vncell"><?=gettext("IPv4 Remote Network/s"); ?></td>
843
						<td width="78%" class="vtable">
844
							<input name="remote_network" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['remote_network']);?>">
845
							<br />
846
							<?=gettext("These are the IPv4 networks that will be routed through " .
847
							"the tunnel, so that a site-to-site VPN can be " .
848
							"established without manually changing the routing tables. " .
849
							"Expressed as a comma-separated list of one or more CIDR ranges. " .
850
							"If this is a site-to-site VPN, enter the " .
851
							"remote LAN/s here. You may leave this blank to " .
852
							"only communicate with other clients"); ?>.
853
						</td>
854
					</tr>
855
					<tr>
856
						<td width="22%" valign="top" class="vncell"><?=gettext("IPv6 Remote Network/s"); ?></td>
857
						<td width="78%" class="vtable">
858
							<input name="remote_networkv6" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['remote_networkv6']);?>">
859
							<br />
860
							<?=gettext("These are the IPv6 networks that will be routed through " .
861
							"the tunnel, so that a site-to-site VPN can be " .
862
							"established without manually changing the routing tables. " .
863
							"Expressed as a comma-separated list of one or more IP/PREFIX. " .
864
							"If this is a site-to-site VPN, enter the " .
865
							"remote LAN/s here. You may leave this blank to " .
866
							"only communicate with other clients"); ?>.
867
						</td>
868
					</tr>
869
					<tr>
870
						<td width="22%" valign="top" class="vncell"><?=gettext("Limit outgoing bandwidth");?></td>
871
						<td width="78%" class="vtable">
872
							<input name="use_shaper" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['use_shaper']);?>"/>
873
							<br />
874
							<?=gettext("Maximum outgoing bandwidth for this tunnel. " .
875
							"Leave empty for no limit. The input value has " .
876
							"to be something between 100 bytes/sec and 100 " .
877
							"Mbytes/sec (entered as bytes per second)"); ?>.
878
						</td>
879
					</tr>
880
					<tr>
881
						<td width="22%" valign="top" class="vncell"><?=gettext("Compression"); ?></td>
882
						<td width="78%" class="vtable">
883
							<select name="compression" class="formselect">
884
								<?php
885
									foreach ($openvpn_compression_modes as $cmode => $cmodedesc):
886
									$selected = '';
887
									if ($cmode == $pconfig['compression'])
888
										$selected = ' selected';
889
								?>
890
								<option value="<?= $cmode ?>" <?= $selected ?>><?= $cmodedesc ?></option>
891
								<?php endforeach; ?>
892
							</select>
893
							<br />
894
							<?=gettext("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."); ?>.
895
						</td>
896
					</tr>
897
					<tr>
898
						<td width="22%" valign="top" class="vncell"><?=gettext("Type-of-Service"); ?></td>
899
						<td width="78%" class="vtable">
900
							<table border="0" cellpadding="2" cellspacing="0">
901
								<tr>
902
									<td>
903
										<?php set_checked($pconfig['passtos'],$chk); ?>
904
										<input name="passtos" type="checkbox" value="yes" <?=$chk;?>>
905
									</td>
906
									<td>
907
										<span class="vexpl">
908
											<?=gettext("Set the TOS IP header value of tunnel packets to match the encapsulated packet value"); ?>.
909
										</span>
910
									</td>
911
								</tr>
912
							</table>
913
						</td>
914
					</tr>
915
				</table>
916

    
917
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
918
					<tr>
919
						<td colspan="2" class="list" height="12"></td>
920
					</tr>
921
					<tr>
922
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced configuration"); ?></td>
923
					</tr>
924
					<tr>
925
						<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
926
						<td width="78%" class="vtable">
927
							<table border="0" cellpadding="2" cellspacing="0">
928
								<tr>
929
									<td>
930
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br />
931
										<?=gettext("Enter any additional options you would like to add to the OpenVPN client configuration here, separated by a semicolon"); ?><br />
932
										<?=gettext("EXAMPLE:"); ?> <strong>remote server.mysite.com 1194;</strong> or <strong>remote 1.2.3.4 1194;</strong>
933
									</td>
934
								</tr>
935
							</table>
936
						</td>
937
					</tr>
938
				</table>
939

    
940
				<br />
941
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
942
					<tr>
943
						<td width="22%" valign="top">&nbsp;</td>
944
						<td width="78%"> 
945
							<input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> 
946
							<input name="act" type="hidden" value="<?=$act;?>">
947
							<?php if (isset($id) && $a_client[$id]): ?>
948
							<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
949
							<?php endif; ?>
950
						</td>
951
					</tr>
952
				</table>
953
			</form>
954

    
955
			<?php else: ?>
956

    
957
			<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
958
				<thead>
959
				<tr>
960
					<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
961
					<td width="10%" class="listhdrr"><?=gettext("Protocol"); ?></td>
962
					<td width="30%" class="listhdrr"><?=gettext("Server"); ?></td>
963
					<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
964
					<td width="10%" class="list"></td>
965
				</tr>
966
				</thead>
967
				<tbody>
968
				<?php
969
					$i = 0;
970
					foreach($a_client as $client):
971
						$disabled = "NO";
972
						if (isset($client['disable']))
973
							$disabled = "YES";
974
						$server = "{$client['server_addr']}:{$client['server_port']}";
975
				?>
976
				<tr ondblclick="document.location='vpn_openvpn_client.php?act=edit&id=<?=$i;?>'">
977
					<td class="listlr">
978
						<?=$disabled;?>
979
					</td>
980
					<td class="listr">
981
						<?=htmlspecialchars($client['protocol']);?>
982
					</td>
983
					<td class="listr">
984
						<?=htmlspecialchars($server);?>
985
					</td>
986
					<td class="listbg">
987
						<?=htmlspecialchars($client['description']);?>
988
					</td>
989
					<td valign="middle" nowrap class="list">
990
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
991
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit client"); ?>" width="17" height="17" border="0">
992
						</a>
993
						&nbsp;
994
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this client?"); ?>')">
995
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete client"); ?>" width="17" height="17" border="0">
996
						</a>
997
					</td>
998
				</tr>
999
				<?php
1000
					$i++;
1001
					endforeach;
1002
				?>
1003
				</tbody>
1004
				<tfoot>
1005
				<tr>
1006
					<td class="list" colspan="4"></td>
1007
					<td class="list">
1008
						<a href="vpn_openvpn_client.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add client"); ?>" width="17" height="17" border="0">
1009
						</a>
1010
					</td>
1011
				</tr>
1012
				<tr>
1013
					<td colspan="4">
1014
						<p>
1015
							<?=gettext("Additional OpenVPN clients can be added here.");?>
1016
						</p>
1017
					</td>
1018
				</tr>
1019
				</tfoot>
1020
			</table>
1021

    
1022
			<?php endif; ?>
1023

    
1024
		</td>
1025
	</tr>
1026
</table>
1027
<script language="JavaScript">
1028
<!--
1029
mode_change();
1030
autokey_change();
1031
tlsauth_change();
1032
useproxy_changed();
1033
//-->
1034
</script>
1035
</body>
1036
<?php include("fend.inc"); ?>
1037

    
1038
<?php
1039

    
1040
/* local utility functions */
1041

    
1042
function set_checked($var,& $chk) {
1043
    if($var)
1044
        $chk = 'checked';
1045
    else
1046
        $chk = '';
1047
}
1048

    
1049
?>
(242-242/251)