Project

General

Profile

Download (40 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
	// OpenVPN Defaults to SHA1
96
	$pconfig['digest'] = "SHA1";
97
}
98

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

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

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

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

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

    
152
if ($_POST) {
153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
253
		$client = array();
254

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

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

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

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

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

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

    
314
include("head.inc");
315

    
316
?>
317

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

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

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

    
349
function useproxy_changed() {
350

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

    
358
function tlsauth_change() {
359

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

    
367
	autotls_change();
368
}
369

    
370
function autotls_change() {
371

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

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

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

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

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

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