Project

General

Profile

Download (39.2 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
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$id = $_POST['id'];
66

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

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

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

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

    
89
if($_GET['act']=="new"){
90
	$pconfig['autokey_enable'] = "yes";
91
	$pconfig['tlsauth_enable'] = "yes";
92
	$pconfig['autotls_enable'] = "yes";
93
	$pconfig['interface'] = "wan";
94
	$pconfig['server_port'] = 1194;
95
}
96

    
97
if($_GET['act']=="edit"){
98

    
99
	if (isset($id) && $a_client[$id]) {
100

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

    
134
		$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
135
		$pconfig['tunnel_networkv6'] = $a_client[$id]['tunnel_networkv6'];
136
		$pconfig['remote_network'] = $a_client[$id]['remote_network'];
137
		$pconfig['remote_networkv6'] = $a_client[$id]['remote_networkv6'];
138
		$pconfig['use_shaper'] = $a_client[$id]['use_shaper'];
139
		$pconfig['compression'] = $a_client[$id]['compression'];
140
		$pconfig['passtos'] = $a_client[$id]['passtos'];
141

    
142
		// just in case the modes switch
143
		$pconfig['autokey_enable'] = "yes";
144
		$pconfig['autotls_enable'] = "yes";
145
	}
146
}
147

    
148
if ($_POST) {
149

    
150
	unset($input_errors);
151
	$pconfig = $_POST;
152

    
153
	if (isset($id) && $a_client[$id])
154
		$vpnid = $a_client[$id]['vpnid'];
155
	else
156
		$vpnid = 0;
157

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

    
169
	if ($pconfig['mode'] != "p2p_shared_key")
170
		$tls_mode = true;
171
	else
172
		$tls_mode = false;
173

    
174
	/* input validation */
175
	if ($pconfig['local_port']) {
176

    
177
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
178
			$input_errors[] = $result;
179

    
180
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['interface'], $pconfig['local_port'], $vpnid);
181
		if (($portused != $vpnid) && ($portused != 0))
182
			$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
183
	}
184

    
185
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
186
		$input_errors[] = $result;
187

    
188
	if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
189
		$input_errors[] = $result;
190

    
191
	if ($pconfig['proxy_addr']) {
192

    
193
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
194
			$input_errors[] = $result;
195

    
196
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
197
			$input_errors[] = $result;
198

    
199
		if ($pconfig['proxy_authtype'] != "none") {
200
			if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
201
				$input_errors[] = gettext("User name and password are required for proxy with authentication.");
202
		}
203
	}
204

    
205
	if($pconfig['tunnel_network'])
206
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'IPv4 Tunnel Network', false, "ipv4"))
207
			$input_errors[] = $result;
208

    
209
	if($pconfig['tunnel_networkv6'])
210
		if ($result = openvpn_validate_cidr($pconfig['tunnel_networkv6'], 'IPv6 Tunnel Network', false, "ipv6"))
211
			$input_errors[] = $result;
212

    
213
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4"))
214
		$input_errors[] = $result;
215

    
216
	if ($result = openvpn_validate_cidr($pconfig['remote_networkv6'], 'IPv6 Remote Network', true, "ipv6"))
217
		$input_errors[] = $result;
218

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

    
222
    if ($pconfig['autokey_enable'])
223
        $pconfig['shared_key'] = openvpn_create_key();
224

    
225
	if (!$tls_mode && !$pconfig['autokey_enable'])
226
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
227
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
228
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
229

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

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

    
245
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
246
	
247
	if (!$input_errors) {
248

    
249
		$client = array();
250

    
251
		if ($vpnid)
252
			$client['vpnid'] = $vpnid;
253
		else
254
			$client['vpnid'] = openvpn_vpnid_next();
255

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

    
274
        if ($tls_mode) {
275
            $client['caref'] = $pconfig['caref'];
276
            $client['certref'] = $pconfig['certref'];
277
            if ($pconfig['tlsauth_enable']) {
278
                if ($pconfig['autotls_enable'])
279
                    $pconfig['tls'] = openvpn_create_key();
280
                $client['tls'] = base64_encode($pconfig['tls']);
281
            }
282
        } else {
283
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
284
        }
285
		$client['crypto'] = $pconfig['crypto'];
286
		$client['engine'] = $pconfig['engine'];
287

    
288
		$client['tunnel_network'] = $pconfig['tunnel_network'];
289
		$client['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
290
		$client['remote_network'] = $pconfig['remote_network'];
291
		$client['remote_networkv6'] = $pconfig['remote_networkv6'];
292
		$client['use_shaper'] = $pconfig['use_shaper'];
293
		$client['compression'] = $pconfig['compression'];
294
		$client['passtos'] = $pconfig['passtos'];
295

    
296
		if (isset($id) && $a_client[$id])
297
			$a_client[$id] = $client;
298
		else
299
			$a_client[] = $client;
300

    
301
		openvpn_resync('client', $client);
302
		write_config();
303
		
304
		header("Location: vpn_openvpn_client.php");
305
		exit;
306
	}
307
}
308

    
309
include("head.inc");
310

    
311
?>
312

    
313
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
314
<?php include("fbegin.inc"); ?>
315
<script language="JavaScript">
316
<!--
317

    
318
function mode_change() {
319
	index = document.iform.mode.selectedIndex;
320
	value = document.iform.mode.options[index].value;
321
	switch(value) {
322
		case "p2p_tls":
323
			document.getElementById("tls").style.display="";
324
			document.getElementById("tls_ca").style.display="";
325
			document.getElementById("tls_cert").style.display="";
326
			document.getElementById("psk").style.display="none";
327
			break;
328
		case "p2p_shared_key":
329
			document.getElementById("tls").style.display="none";
330
			document.getElementById("tls_ca").style.display="none";
331
			document.getElementById("tls_cert").style.display="none";
332
			document.getElementById("psk").style.display="";
333
			break;
334
	}
335
}
336

    
337
function autokey_change() {
338
	if (document.iform.autokey_enable.checked)
339
		document.getElementById("autokey_opts").style.display="none";
340
	else
341
		document.getElementById("autokey_opts").style.display="";
342
}
343

    
344
function useproxy_changed() {
345

    
346
	if (jQuery('#proxy_authtype').val() != 'none') {
347
                jQuery('#proxy_authtype_opts').show();
348
        } else {
349
                jQuery('#proxy_authtype_opts').hide();
350
        }
351
}
352

    
353
function tlsauth_change() {
354

    
355
<?php if (!$pconfig['tls']): ?>
356
	if (document.iform.tlsauth_enable.checked)
357
		document.getElementById("tlsauth_opts").style.display="";
358
	else
359
		document.getElementById("tlsauth_opts").style.display="none";
360
<?php endif; ?>
361

    
362
	autotls_change();
363
}
364

    
365
function autotls_change() {
366

    
367
<?php if (!$pconfig['tls']): ?>
368
	autocheck = document.iform.autotls_enable.checked;
369
<?php else: ?>
370
	autocheck = false;
371
<?php endif; ?>
372

    
373
	if (document.iform.tlsauth_enable.checked && !autocheck)
374
		document.getElementById("autotls_opts").style.display="";
375
	else
376
		document.getElementById("autotls_opts").style.display="none";
377
}
378

    
379
//-->
380
</script>
381
<?php
382
if (!$savemsg)
383
	$savemsg = "";
384

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

    
409
			<?php if($act=="new" || $act=="edit"): ?>
410

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

    
894
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
895
					<tr>
896
						<td colspan="2" class="list" height="12"></td>
897
					</tr>
898
					<tr>
899
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced configuration"); ?></td>
900
					</tr>
901
					<tr>
902
						<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
903
						<td width="78%" class="vtable">
904
							<table border="0" cellpadding="2" cellspacing="0">
905
								<tr>
906
									<td>
907
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
908
										<?=gettext("Enter any additional options you would like to add to the OpenVPN client configuration here, separated by a semicolon"); ?><br/>
909
										<?=gettext("EXAMPLE:"); ?> <strong>remote server.mysite.com 1194;</strong> or <strong>remote 1.2.3.4 1194;</strong>
910
									</td>
911
								</tr>
912
							</table>
913
						</td>
914
					</tr>
915
				</table>
916

    
917
				<br/>
918
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
919
					<tr>
920
						<td width="22%" valign="top">&nbsp;</td>
921
						<td width="78%"> 
922
							<input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> 
923
							<input name="act" type="hidden" value="<?=$act;?>">
924
							<?php if (isset($id) && $a_client[$id]): ?>
925
							<input name="id" type="hidden" value="<?=$id;?>">
926
							<?php endif; ?>
927
						</td>
928
					</tr>
929
				</table>
930
			</form>
931

    
932
			<?php else: ?>
933

    
934
			<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
935
				<thead>
936
				<tr>
937
					<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
938
					<td width="10%" class="listhdrr"><?=gettext("Protocol"); ?></td>
939
					<td width="30%" class="listhdrr"><?=gettext("Server"); ?></td>
940
					<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
941
					<td width="10%" class="list"></td>
942
				</tr>
943
				</thead>
944
				<tbody>
945
				<?php
946
					$i = 0;
947
					foreach($a_client as $client):
948
						$disabled = "NO";
949
						if (isset($client['disable']))
950
							$disabled = "YES";
951
						$server = "{$client['server_addr']}:{$client['server_port']}";
952
				?>
953
				<tr ondblclick="document.location='vpn_openvpn_client.php?act=edit&id=<?=$i;?>'">
954
					<td class="listlr">
955
						<?=$disabled;?>
956
					</td>
957
					<td class="listr">
958
						<?=htmlspecialchars($client['protocol']);?>
959
					</td>
960
					<td class="listr">
961
						<?=htmlspecialchars($server);?>
962
					</td>
963
					<td class="listbg">
964
						<?=htmlspecialchars($client['description']);?>
965
					</td>
966
					<td valign="middle" nowrap class="list">
967
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
968
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit client"); ?>" width="17" height="17" border="0">
969
						</a>
970
						&nbsp;
971
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this client?"); ?>')">
972
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete client"); ?>" width="17" height="17" border="0">
973
						</a>
974
					</td>
975
				</tr>
976
				<?php
977
					$i++;
978
					endforeach;
979
				?>
980
				</tbody>
981
				<tfoot>
982
				<tr>
983
					<td class="list" colspan="4"></td>
984
					<td class="list">
985
						<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">
986
						</a>
987
					</td>
988
				</tr>
989
				<tr>
990
					<td colspan="4">
991
						<p>
992
							<?=gettext("Additional OpenVPN clients can be added here.");?>
993
						</p>
994
					</td>
995
				</tr>
996
				</tfoot>
997
			</table>
998

    
999
			<?php endif; ?>
1000

    
1001
		</td>
1002
	</tr>
1003
</table>
1004
<script language="JavaScript">
1005
<!--
1006
mode_change();
1007
autokey_change();
1008
tlsauth_change();
1009
useproxy_changed();
1010
//-->
1011
</script>
1012
</body>
1013
<?php include("fend.inc"); ?>
1014

    
1015
<?php
1016

    
1017
/* local utility functions */
1018

    
1019
function set_checked($var,& $chk) {
1020
    if($var)
1021
        $chk = 'checked';
1022
    else
1023
        $chk = '';
1024
}
1025

    
1026
?>
(237-237/246)