Project

General

Profile

Download (38.6 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)) {
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)) {
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['local_port']);
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'], 'Tunnel network'))
207
			$input_errors[] = $result;
208

    
209
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
210
		$input_errors[] = $result;
211

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

    
215
    if ($pconfig['autokey_enable'])
216
        $pconfig['shared_key'] = openvpn_create_key();
217

    
218
	if (!$tls_mode && !$pconfig['autokey_enable'])
219
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
220
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
221
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
222

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

    
228
	/* If we are not in shared key mode, then we need the CA/Cert. */
229
	if ($pconfig['mode'] != "p2p_shared_key") {
230
		$reqdfields = explode(" ", "caref certref");
231
		$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
232
	} elseif (!$pconfig['autokey_enable']) {
233
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
234
		$reqdfields = array('shared_key');
235
		$reqdfieldsn = array(gettext('Shared key'));
236
	}
237

    
238
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
239
	
240
	if (!$input_errors) {
241

    
242
		$client = array();
243

    
244
		if ($vpnid)
245
			$client['vpnid'] = $vpnid;
246
		else
247
			$client['vpnid'] = openvpn_vpnid_next();
248

    
249
		if ($_POST['disable'] == "yes")
250
			$client['disable'] = true;
251
		$client['protocol'] = $pconfig['protocol'];
252
		$client['dev_mode'] = $pconfig['dev_mode'];
253
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
254
		$client['local_port'] = $pconfig['local_port'];
255
		$client['server_addr'] = $pconfig['server_addr'];
256
		$client['server_port'] = $pconfig['server_port'];
257
		$client['resolve_retry'] = $pconfig['resolve_retry'];
258
		$client['proxy_addr'] = $pconfig['proxy_addr'];
259
		$client['proxy_port'] = $pconfig['proxy_port'];
260
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
261
		$client['proxy_user'] = $pconfig['proxy_user'];
262
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
263
		$client['description'] = $pconfig['description'];
264
		$client['mode'] = $pconfig['mode'];
265
		$client['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
266

    
267
        if ($tls_mode) {
268
            $client['caref'] = $pconfig['caref'];
269
            $client['certref'] = $pconfig['certref'];
270
            if ($pconfig['tlsauth_enable']) {
271
                if ($pconfig['autotls_enable'])
272
                    $pconfig['tls'] = openvpn_create_key();
273
                $client['tls'] = base64_encode($pconfig['tls']);
274
            }
275
        } else {
276
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
277
        }
278
		$client['crypto'] = $pconfig['crypto'];
279
		$client['engine'] = $pconfig['engine'];
280

    
281
		$client['tunnel_network'] = $pconfig['tunnel_network'];
282
		$client['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
283
		$client['remote_network'] = $pconfig['remote_network'];
284
		$client['remote_networkv6'] = $pconfig['remote_networkv6'];
285
		$client['use_shaper'] = $pconfig['use_shaper'];
286
		$client['compression'] = $pconfig['compression'];
287
		$client['passtos'] = $pconfig['passtos'];
288

    
289
		if (isset($id) && $a_client[$id])
290
			$a_client[$id] = $client;
291
		else
292
			$a_client[] = $client;
293

    
294
		openvpn_resync('client', $client);
295
		write_config();
296
		
297
		header("Location: vpn_openvpn_client.php");
298
		exit;
299
	}
300
}
301

    
302
include("head.inc");
303

    
304
?>
305

    
306
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
307
<?php include("fbegin.inc"); ?>
308
<script language="JavaScript">
309
<!--
310

    
311
function mode_change() {
312
	index = document.iform.mode.selectedIndex;
313
	value = document.iform.mode.options[index].value;
314
	switch(value) {
315
		case "p2p_tls":
316
			document.getElementById("tls").style.display="";
317
			document.getElementById("tls_ca").style.display="";
318
			document.getElementById("tls_cert").style.display="";
319
			document.getElementById("psk").style.display="none";
320
			break;
321
		case "p2p_shared_key":
322
			document.getElementById("tls").style.display="none";
323
			document.getElementById("tls_ca").style.display="none";
324
			document.getElementById("tls_cert").style.display="none";
325
			document.getElementById("psk").style.display="";
326
			break;
327
	}
328
}
329

    
330
function autokey_change() {
331
	if (document.iform.autokey_enable.checked)
332
		document.getElementById("autokey_opts").style.display="none";
333
	else
334
		document.getElementById("autokey_opts").style.display="";
335
}
336

    
337
function useproxy_changed() {
338

    
339
	if (jQuery('#proxy_authtype').val() != 'none') {
340
                jQuery('#proxy_authtype_opts').show();
341
        } else {
342
                jQuery('#proxy_authtype_opts').hide();
343
        }
344
}
345

    
346
function tlsauth_change() {
347

    
348
<?php if (!$pconfig['tls']): ?>
349
	if (document.iform.tlsauth_enable.checked)
350
		document.getElementById("tlsauth_opts").style.display="";
351
	else
352
		document.getElementById("tlsauth_opts").style.display="none";
353
<?php endif; ?>
354

    
355
	autotls_change();
356
}
357

    
358
function autotls_change() {
359

    
360
<?php if (!$pconfig['tls']): ?>
361
	autocheck = document.iform.autotls_enable.checked;
362
<?php else: ?>
363
	autocheck = false;
364
<?php endif; ?>
365

    
366
	if (document.iform.tlsauth_enable.checked && !autocheck)
367
		document.getElementById("autotls_opts").style.display="";
368
	else
369
		document.getElementById("autotls_opts").style.display="none";
370
}
371

    
372
//-->
373
</script>
374
<?php
375
if (!$savemsg)
376
	$savemsg = "";
377

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

    
402
			<?php if($act=="new" || $act=="edit"): ?>
403

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

    
886
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
887
					<tr>
888
						<td colspan="2" class="list" height="12"></td>
889
					</tr>
890
					<tr>
891
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced configuration"); ?></td>
892
					</tr>
893
					<tr>
894
						<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
895
						<td width="78%" class="vtable">
896
							<table border="0" cellpadding="2" cellspacing="0">
897
								<tr>
898
									<td>
899
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
900
										<?=gettext("Enter any additional options you would like to add to the OpenVPN client configuration here, separated by a semicolon"); ?><br/>
901
										<?=gettext("EXAMPLE: route 10.0.0.0 255.255.255.0;"); ?>
902
									</td>
903
								</tr>
904
							</table>
905
						</td>
906
					</tr>
907
				</table>
908

    
909
				<br/>
910
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
911
					<tr>
912
						<td width="22%" valign="top">&nbsp;</td>
913
						<td width="78%"> 
914
							<input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> 
915
							<input name="act" type="hidden" value="<?=$act;?>">
916
							<?php if (isset($id) && $a_client[$id]): ?>
917
							<input name="id" type="hidden" value="<?=$id;?>">
918
							<?php endif; ?>
919
						</td>
920
					</tr>
921
				</table>
922
			</form>
923

    
924
			<?php else: ?>
925

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

    
991
			<?php endif; ?>
992

    
993
		</td>
994
	</tr>
995
</table>
996
<script language="JavaScript">
997
<!--
998
mode_change();
999
autokey_change();
1000
tlsauth_change();
1001
useproxy_changed();
1002
//-->
1003
</script>
1004
</body>
1005
<?php include("fend.inc"); ?>
1006

    
1007
<?php
1008

    
1009
/* local utility functions */
1010

    
1011
function set_checked($var,& $chk) {
1012
    if($var)
1013
        $chk = 'checked';
1014
    else
1015
        $chk = '';
1016
}
1017

    
1018
?>
(240-240/249)