Project

General

Profile

Download (35.1 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
$statusurl = "status_openvpn.php";
42
$logurl = "diag_logs_openvpn.php";
43

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

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

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

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

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

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

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

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

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

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

    
72
if ($_GET['act'] == "del") {
73

    
74
	if (!$a_client[$id]) {
75
		pfSenseHeader("vpn_openvpn_client.php");
76
		exit;
77
	}
78

    
79
	openvpn_delete('client', $a_client[$id]);
80
	unset($a_client[$id]);
81
	write_config();
82
	$savemsg = gettext("Client successfully deleted")."<br/>";
83
}
84

    
85
if($_GET['act']=="new"){
86
	$pconfig['autokey_enable'] = "yes";
87
	$pconfig['tlsauth_enable'] = "yes";
88
	$pconfig['autotls_enable'] = "yes";
89
	$pconfig['interface'] = "wan";
90
	$pconfig['server_port'] = 1194;
91
}
92

    
93
if($_GET['act']=="edit"){
94

    
95
	if (isset($id) && $a_client[$id]) {
96

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

    
130
		$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
131
		$pconfig['remote_network'] = $a_client[$id]['remote_network'];
132
		$pconfig['compression'] = $a_client[$id]['compression'];
133
		$pconfig['passtos'] = $a_client[$id]['passtos'];
134

    
135
		// just in case the modes switch
136
		$pconfig['autokey_enable'] = "yes";
137
		$pconfig['autotls_enable'] = "yes";
138
	}
139
}
140

    
141
if ($_POST) {
142

    
143
	unset($input_errors);
144
	$pconfig = $_POST;
145

    
146
	if (isset($id) && $a_client[$id])
147
		$vpnid = $a_client[$id]['vpnid'];
148
	else
149
		$vpnid = 0;
150

    
151
	if ($pconfig['mode'] != "p2p_shared_key")
152
		$tls_mode = true;
153
	else
154
		$tls_mode = false;
155

    
156
	/* input validation */
157
	if ($pconfig['local_port']) {
158

    
159
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
160
			$input_errors[] = $result;
161

    
162
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
163
		if (($portused != $vpnid) && ($portused != 0))
164
			$input_errors[] = gettext("The specified 'Local port' is in use. Please select another value");
165
	}
166

    
167
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
168
		$input_errors[] = $result;
169

    
170
	if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
171
		$input_errors[] = $result;
172

    
173
	if ($pconfig['proxy_addr']) {
174

    
175
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
176
			$input_errors[] = $result;
177

    
178
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
179
			$input_errors[] = $result;
180

    
181
		if ($pconfig['proxy_authtype'] != "none") {
182
			if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
183
				$input_errors[] = gettext("User name and password are required for proxy with authentication.");
184
		}
185
	}
186

    
187
	if($pconfig['tunnel_network'])
188
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
189
			$input_errors[] = $result;
190

    
191
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
192
		$input_errors[] = $result;
193

    
194
    if ($pconfig['autokey_enable'])
195
        $pconfig['shared_key'] = openvpn_create_key();
196

    
197
	if (!$tls_mode && !$pconfig['autokey_enable'])
198
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
199
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
200
			$input_errors[] = gettext("The field 'Shared Key' does not appear to be valid");
201

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

    
207
	/* If we are not in shared key mode, then we need the CA/Cert. */
208
	if ($pconfig['mode'] != "p2p_shared_key") {
209
		$reqdfields = explode(" ", "caref certref");
210
		$reqdfieldsn = array(gettext("Certificate Authority"),gettext("Certificate"));
211
	} elseif (!$pconfig['autokey_enable']) {
212
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
213
		$reqdfields = array('shared_key');
214
		$reqdfieldsn = array(gettext('Shared key'));
215
	}
216

    
217
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
218
	
219
	if (!$input_errors) {
220

    
221
		$client = array();
222

    
223
		if ($vpnid)
224
			$client['vpnid'] = $vpnid;
225
		else
226
			$client['vpnid'] = openvpn_vpnid_next();
227

    
228
		if ($_POST['disable'] == "yes")
229
			$client['disable'] = true;
230
		$client['protocol'] = $pconfig['protocol'];
231
		$client['dev_mode'] = $pconfig['dev_mode'];
232
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
233
		$client['local_port'] = $pconfig['local_port'];
234
		$client['server_addr'] = $pconfig['server_addr'];
235
		$client['server_port'] = $pconfig['server_port'];
236
		$client['resolve_retry'] = $pconfig['resolve_retry'];
237
		$client['proxy_addr'] = $pconfig['proxy_addr'];
238
		$client['proxy_port'] = $pconfig['proxy_port'];
239
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
240
		$client['proxy_user'] = $pconfig['proxy_user'];
241
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
242
		$client['description'] = $pconfig['description'];
243
		$client['mode'] = $pconfig['mode'];
244
		$client['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']);
245

    
246
        if ($tls_mode) {
247
            $client['caref'] = $pconfig['caref'];
248
            $client['certref'] = $pconfig['certref'];
249
            if ($pconfig['tlsauth_enable']) {
250
                if ($pconfig['autotls_enable'])
251
                    $pconfig['tls'] = openvpn_create_key();
252
                $client['tls'] = base64_encode($pconfig['tls']);
253
            }
254
        } else {
255
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
256
        }
257
		$client['crypto'] = $pconfig['crypto'];
258
		$client['engine'] = $pconfig['engine'];
259

    
260
		$client['tunnel_network'] = $pconfig['tunnel_network'];
261
		$client['remote_network'] = $pconfig['remote_network'];
262
		$client['compression'] = $pconfig['compression'];
263
		$client['passtos'] = $pconfig['passtos'];
264

    
265
		if (isset($id) && $a_client[$id])
266
			$a_client[$id] = $client;
267
		else
268
			$a_client[] = $client;
269

    
270
		openvpn_resync('client', $client);
271
		write_config();
272
		
273
		header("Location: vpn_openvpn_client.php");
274
		exit;
275
	}
276
}
277

    
278
include("head.inc");
279

    
280
?>
281

    
282
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
283
<?php include("fbegin.inc"); ?>
284
<script language="JavaScript">
285
<!--
286

    
287
function mode_change() {
288
	index = document.iform.mode.selectedIndex;
289
	value = document.iform.mode.options[index].value;
290
	switch(value) {
291
		case "p2p_tls":
292
			document.getElementById("tls").style.display="";
293
			document.getElementById("tls_ca").style.display="";
294
			document.getElementById("tls_cert").style.display="";
295
			document.getElementById("psk").style.display="none";
296
			break;
297
		case "p2p_shared_key":
298
			document.getElementById("tls").style.display="none";
299
			document.getElementById("tls_ca").style.display="none";
300
			document.getElementById("tls_cert").style.display="none";
301
			document.getElementById("psk").style.display="";
302
			break;
303
	}
304
}
305

    
306
function autokey_change() {
307
	if (document.iform.autokey_enable.checked)
308
		document.getElementById("autokey_opts").style.display="none";
309
	else
310
		document.getElementById("autokey_opts").style.display="";
311
}
312

    
313
function useproxy_changed() {
314

    
315
	if ($('proxy_authtype').value != 'none') {
316
                $('proxy_authtype_opts').show();
317
        } else {
318
                $('proxy_authtype_opts').hide();
319
        }
320
}
321

    
322
function tlsauth_change() {
323

    
324
<?php if (!$pconfig['tls']): ?>
325
	if (document.iform.tlsauth_enable.checked)
326
		document.getElementById("tlsauth_opts").style.display="";
327
	else
328
		document.getElementById("tlsauth_opts").style.display="none";
329
<?php endif; ?>
330

    
331
	autotls_change();
332
}
333

    
334
function autotls_change() {
335

    
336
<?php if (!$pconfig['tls']): ?>
337
	autocheck = document.iform.autotls_enable.checked;
338
<?php else: ?>
339
	autocheck = false;
340
<?php endif; ?>
341

    
342
	if (document.iform.tlsauth_enable.checked && !autocheck)
343
		document.getElementById("autotls_opts").style.display="";
344
	else
345
		document.getElementById("autotls_opts").style.display="none";
346
}
347

    
348
//-->
349
</script>
350
<?php
351
if (!$savemsg)
352
	$savemsg = "";
353

    
354
if ($input_errors)
355
	print_input_errors($input_errors);
356
if ($savemsg)
357
	print_info_box($savemsg);
358
?>
359
<table width="100%" border="0" cellpadding="0" cellspacing="0">
360
 	<tr>
361
		<td class="tabnavtbl">
362
			<ul id="tabnav">
363
			<?php 
364
				$tab_array = array();
365
				$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
366
				$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
367
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
368
				$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
369
				add_package_tabs("OpenVPN", $tab_array);
370
				display_top_tabs($tab_array);
371
			?>
372
			</ul>
373
		</td>
374
	</tr>    
375
	<tr>
376
		<td class="tabcont">
377

    
378
			<?php if($act=="new" || $act=="edit"): ?>
379

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

    
855
			<?php else: ?>
856

    
857
			<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
858
				<thead>
859
				<tr>
860
					<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
861
					<td width="10%" class="listhdrr"><?=gettext("Protocol"); ?></td>
862
					<td width="30%" class="listhdrr"><?=gettext("Server"); ?></td>
863
					<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
864
					<td width="10%" class="list"></td>
865
				</tr>
866
				</thead>
867
				<tbody>
868
				<?php
869
					$i = 0;
870
					foreach($a_client as $client):
871
						$disabled = "NO";
872
						if (isset($client['disable']))
873
							$disabled = "YES";
874
						$server = "{$client['server_addr']}:{$client['server_port']}";
875
				?>
876
				<tr ondblclick="document.location='vpn_openvpn_client.php?act=edit&id=<?=$i;?>'">
877
					<td class="listlr">
878
						<?=$disabled;?>
879
					</td>
880
					<td class="listr">
881
						<?=htmlspecialchars($client['protocol']);?>
882
					</td>
883
					<td class="listr">
884
						<?=htmlspecialchars($server);?>
885
					</td>
886
					<td class="listbg">
887
						<?=htmlspecialchars($client['description']);?>
888
					</td>
889
					<td valign="middle" nowrap class="list">
890
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
891
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit client"); ?>" width="17" height="17" border="0">
892
						</a>
893
						&nbsp;
894
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this client?"); ?>')">
895
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete client"); ?>" width="17" height="17" border="0">
896
						</a>
897
					</td>
898
				</tr>
899
				<?php
900
					$i++;
901
					endforeach;
902
				?>
903
				</tbody>
904
				<tfoot>
905
				<tr>
906
					<td class="list" colspan="4"></td>
907
					<td class="list">
908
						<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">
909
						</a>
910
					</td>
911
				</tr>
912
				<tr>
913
					<td colspan="4">
914
						<p>
915
							<?=gettext("Additional OpenVPN clients can be added here.");?>
916
						</p>
917
					</td>
918
				</tr>
919
				</tfoot>
920
			</table>
921

    
922
			<?php endif; ?>
923

    
924
		</td>
925
	</tr>
926
</table>
927
<script language="JavaScript">
928
<!--
929
mode_change();
930
autokey_change();
931
tlsauth_change();
932
useproxy_changed();
933
//-->
934
</script>
935
</body>
936
<?php include("fend.inc"); ?>
937

    
938
<?php
939

    
940
/* local utility functions */
941

    
942
function set_checked($var,& $chk) {
943
    if($var)
944
        $chk = 'checked';
945
    else
946
        $chk = '';
947
}
948

    
949
?>
950

    
(223-223/232)