Project

General

Profile

Download (37.7 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 (!$a_client[$id]) {
79
		pfSenseHeader("vpn_openvpn_client.php");
80
		exit;
81
	}
82

    
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
	if ($pconfig['mode'] != "p2p_shared_key")
159
		$tls_mode = true;
160
	else
161
		$tls_mode = false;
162

    
163
	/* input validation */
164
	if ($pconfig['local_port']) {
165

    
166
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
167
			$input_errors[] = $result;
168

    
169
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
170
		if (($portused != $vpnid) && ($portused != 0))
171
			$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
172
	}
173

    
174
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
175
		$input_errors[] = $result;
176

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

    
180
	if ($pconfig['proxy_addr']) {
181

    
182
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
183
			$input_errors[] = $result;
184

    
185
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
186
			$input_errors[] = $result;
187

    
188
		if ($pconfig['proxy_authtype'] != "none") {
189
			if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
190
				$input_errors[] = gettext("User name and password are required for proxy with authentication.");
191
		}
192
	}
193

    
194
	if($pconfig['tunnel_network'])
195
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
196
			$input_errors[] = $result;
197

    
198
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
199
		$input_errors[] = $result;
200

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

    
204
    if ($pconfig['autokey_enable'])
205
        $pconfig['shared_key'] = openvpn_create_key();
206

    
207
	if (!$tls_mode && !$pconfig['autokey_enable'])
208
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
209
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
210
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
211

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

    
217
	/* If we are not in shared key mode, then we need the CA/Cert. */
218
	if ($pconfig['mode'] != "p2p_shared_key") {
219
		$reqdfields = explode(" ", "caref certref");
220
		$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
221
	} elseif (!$pconfig['autokey_enable']) {
222
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
223
		$reqdfields = array('shared_key');
224
		$reqdfieldsn = array(gettext('Shared key'));
225
	}
226

    
227
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
228
	
229
	if (!$input_errors) {
230

    
231
		$client = array();
232

    
233
		if ($vpnid)
234
			$client['vpnid'] = $vpnid;
235
		else
236
			$client['vpnid'] = openvpn_vpnid_next();
237

    
238
		if ($_POST['disable'] == "yes")
239
			$client['disable'] = true;
240
		$client['protocol'] = $pconfig['protocol'];
241
		$client['dev_mode'] = $pconfig['dev_mode'];
242
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
243
		$client['local_port'] = $pconfig['local_port'];
244
		$client['server_addr'] = $pconfig['server_addr'];
245
		$client['server_port'] = $pconfig['server_port'];
246
		$client['resolve_retry'] = $pconfig['resolve_retry'];
247
		$client['proxy_addr'] = $pconfig['proxy_addr'];
248
		$client['proxy_port'] = $pconfig['proxy_port'];
249
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
250
		$client['proxy_user'] = $pconfig['proxy_user'];
251
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
252
		$client['description'] = $pconfig['description'];
253
		$client['mode'] = $pconfig['mode'];
254
		$client['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
255

    
256
        if ($tls_mode) {
257
            $client['caref'] = $pconfig['caref'];
258
            $client['certref'] = $pconfig['certref'];
259
            if ($pconfig['tlsauth_enable']) {
260
                if ($pconfig['autotls_enable'])
261
                    $pconfig['tls'] = openvpn_create_key();
262
                $client['tls'] = base64_encode($pconfig['tls']);
263
            }
264
        } else {
265
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
266
        }
267
		$client['crypto'] = $pconfig['crypto'];
268
		$client['engine'] = $pconfig['engine'];
269

    
270
		$client['tunnel_network'] = $pconfig['tunnel_network'];
271
		$client['tunnel_networkv6'] = $pconfig['tunnel_networkv6'];
272
		$client['remote_network'] = $pconfig['remote_network'];
273
		$client['remote_networkv6'] = $pconfig['remote_networkv6'];
274
		$client['use_shaper'] = $pconfig['use_shaper'];
275
		$client['compression'] = $pconfig['compression'];
276
		$client['passtos'] = $pconfig['passtos'];
277

    
278
		if (isset($id) && $a_client[$id])
279
			$a_client[$id] = $client;
280
		else
281
			$a_client[] = $client;
282

    
283
		openvpn_resync('client', $client);
284
		write_config();
285
		
286
		header("Location: vpn_openvpn_client.php");
287
		exit;
288
	}
289
}
290

    
291
include("head.inc");
292

    
293
?>
294

    
295
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
296
<?php include("fbegin.inc"); ?>
297
<script language="JavaScript">
298
<!--
299

    
300
function mode_change() {
301
	index = document.iform.mode.selectedIndex;
302
	value = document.iform.mode.options[index].value;
303
	switch(value) {
304
		case "p2p_tls":
305
			document.getElementById("tls").style.display="";
306
			document.getElementById("tls_ca").style.display="";
307
			document.getElementById("tls_cert").style.display="";
308
			document.getElementById("psk").style.display="none";
309
			break;
310
		case "p2p_shared_key":
311
			document.getElementById("tls").style.display="none";
312
			document.getElementById("tls_ca").style.display="none";
313
			document.getElementById("tls_cert").style.display="none";
314
			document.getElementById("psk").style.display="";
315
			break;
316
	}
317
}
318

    
319
function autokey_change() {
320
	if (document.iform.autokey_enable.checked)
321
		document.getElementById("autokey_opts").style.display="none";
322
	else
323
		document.getElementById("autokey_opts").style.display="";
324
}
325

    
326
function useproxy_changed() {
327

    
328
	if (jQuery('#proxy_authtype').val() != 'none') {
329
                jQuery('#proxy_authtype_opts').show();
330
        } else {
331
                jQuery('#proxy_authtype_opts').hide();
332
        }
333
}
334

    
335
function tlsauth_change() {
336

    
337
<?php if (!$pconfig['tls']): ?>
338
	if (document.iform.tlsauth_enable.checked)
339
		document.getElementById("tlsauth_opts").style.display="";
340
	else
341
		document.getElementById("tlsauth_opts").style.display="none";
342
<?php endif; ?>
343

    
344
	autotls_change();
345
}
346

    
347
function autotls_change() {
348

    
349
<?php if (!$pconfig['tls']): ?>
350
	autocheck = document.iform.autotls_enable.checked;
351
<?php else: ?>
352
	autocheck = false;
353
<?php endif; ?>
354

    
355
	if (document.iform.tlsauth_enable.checked && !autocheck)
356
		document.getElementById("autotls_opts").style.display="";
357
	else
358
		document.getElementById("autotls_opts").style.display="none";
359
}
360

    
361
//-->
362
</script>
363
<?php
364
if (!$savemsg)
365
	$savemsg = "";
366

    
367
if ($input_errors)
368
	print_input_errors($input_errors);
369
if ($savemsg)
370
	print_info_box($savemsg);
371
?>
372
<table width="100%" border="0" cellpadding="0" cellspacing="0">
373
 	<tr>
374
		<td class="tabnavtbl">
375
			<ul id="tabnav">
376
			<?php 
377
				$tab_array = array();
378
				$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
379
				$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
380
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
381
				$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
382
				add_package_tabs("OpenVPN", $tab_array);
383
				display_top_tabs($tab_array);
384
			?>
385
			</ul>
386
		</td>
387
	</tr>    
388
	<tr>
389
		<td class="tabcont">
390

    
391
			<?php if($act=="new" || $act=="edit"): ?>
392

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

    
875
				<table width="100%" border="0" cellpadding="6" cellspacing="0" id="client_opts">
876
					<tr>
877
						<td colspan="2" class="list" height="12"></td>
878
					</tr>
879
					<tr>
880
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced configuration"); ?></td>
881
					</tr>
882
					<tr>
883
						<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
884
						<td width="78%" class="vtable">
885
							<table border="0" cellpadding="2" cellspacing="0">
886
								<tr>
887
									<td>
888
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
889
										<?=gettext("Enter any additional options you would like to add to the OpenVPN client configuration here, separated by a semicolon"); ?><br/>
890
										<?=gettext("EXAMPLE: route 10.0.0.0 255.255.255.0;"); ?>
891
									</td>
892
								</tr>
893
							</table>
894
						</td>
895
					</tr>
896
				</table>
897

    
898
				<br/>
899
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
900
					<tr>
901
						<td width="22%" valign="top">&nbsp;</td>
902
						<td width="78%"> 
903
							<input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> 
904
							<input name="act" type="hidden" value="<?=$act;?>">
905
							<?php if (isset($id) && $a_client[$id]): ?>
906
							<input name="id" type="hidden" value="<?=$id;?>">
907
							<?php endif; ?>
908
						</td>
909
					</tr>
910
				</table>
911
			</form>
912

    
913
			<?php else: ?>
914

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

    
980
			<?php endif; ?>
981

    
982
		</td>
983
	</tr>
984
</table>
985
<script language="JavaScript">
986
<!--
987
mode_change();
988
autokey_change();
989
tlsauth_change();
990
useproxy_changed();
991
//-->
992
</script>
993
</body>
994
<?php include("fend.inc"); ?>
995

    
996
<?php
997

    
998
/* local utility functions */
999

    
1000
function set_checked($var,& $chk) {
1001
    if($var)
1002
        $chk = 'checked';
1003
    else
1004
        $chk = '';
1005
}
1006

    
1007
?>
(241-241/250)