Project

General

Profile

Download (31.8 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("OpenVPN", "Client");
41

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

    
45
$a_client = &$config['openvpn']['openvpn-client'];
46

    
47
$id = $_GET['id'];
48
if (isset($_POST['id']))
49
	$id = $_POST['id'];
50

    
51
$act = $_GET['act'];
52
if (isset($_POST['act']))
53
	$act = $_POST['act'];
54

    
55
if ($_GET['act'] == "del") {
56

    
57
	if (!$a_client[$id]) {
58
		pfSenseHeader("vpn_openvpn_client.php");
59
		exit;
60
	}
61

    
62
	openvpn_delete('client', $a_client[$id]);
63
	unset($a_client[$id]);
64
	write_config();
65
	$savemsg = gettext("Client successfully deleted")."<br/>";
66
}
67

    
68
if($_GET['act']=="new"){
69
	$pconfig['autokey_enable'] = "yes";
70
	$pconfig['tlsauth_enable'] = "yes";
71
	$pconfig['autotls_enable'] = "yes";
72
	$pconfig['interface'] = "wan";
73
	$pconfig['server_port'] = 1194;
74
}
75

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

    
78
	if (isset($id) && $a_client[$id]) {
79

    
80
		$pconfig['disable'] = $a_client[$id]['disable'];
81
		$pconfig['mode'] = $a_client[$id]['mode'];
82
		$pconfig['protocol'] = $a_client[$id]['protocol'];
83
		$pconfig['interface'] = $a_client[$id]['interface'];
84
		if (!empty($a_client[$id]['ipaddr'])) {
85
			$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$id]['ipaddr'];
86
		}
87
		$pconfig['local_port'] = $a_client[$id]['local_port'];
88
		$pconfig['server_addr'] = $a_client[$id]['server_addr'];
89
		$pconfig['server_port'] = $a_client[$id]['server_port'];
90
		$pconfig['resolve_retry'] = $a_client[$id]['resolve_retry'];
91
		$pconfig['proxy_addr'] = $a_client[$id]['proxy_addr'];
92
		$pconfig['proxy_port'] = $a_client[$id]['proxy_port'];
93
		$pconfig['proxy_user'] = $a_client[$id]['proxy_user'];
94
		$pconfig['proxy_passwd'] = $a_client[$id]['proxy_passwd'];
95
		$pconfig['proxy_authtype'] = $a_client[$id]['proxy_authtype'];
96
		$pconfig['description'] = $a_client[$id]['description'];
97
		$pconfig['custom_options'] = $a_client[$id]['custom_options'];
98
		$pconfig['ns_cert_type'] = $a_client[$id]['ns_cert_type'];
99
		$pconfig['dev_mode'] = $a_client[$id]['dev_mode'];
100
	
101
		if ($pconfig['mode'] != "p2p_shared_key") {
102
			$pconfig['caref'] = $a_client[$id]['caref'];
103
			$pconfig['certref'] = $a_client[$id]['certref'];
104
			if ($a_client[$id]['tls']) {
105
				$pconfig['tlsauth_enable'] = "yes";
106
				$pconfig['tls'] = base64_decode($a_client[$id]['tls']);
107
			}
108
		} else
109
			$pconfig['shared_key'] = base64_decode($a_client[$id]['shared_key']);
110
		$pconfig['crypto'] = $a_client[$id]['crypto'];
111

    
112
		$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
113
		$pconfig['remote_network'] = $a_client[$id]['remote_network'];
114
		$pconfig['compression'] = $a_client[$id]['compression'];
115
		$pconfig['passtos'] = $a_client[$id]['passtos'];
116

    
117
		// just in case the modes switch
118
		$pconfig['autokey_enable'] = "yes";
119
		$pconfig['autotls_enable'] = "yes";
120
	}
121
}
122

    
123
if ($_POST) {
124

    
125
	unset($input_errors);
126
	$pconfig = $_POST;
127

    
128
	if (isset($id) && $a_client[$id])
129
		$vpnid = $a_client[$id]['vpnid'];
130
	else
131
		$vpnid = 0;
132

    
133
	if ($pconfig['mode'] != "p2p_shared_key")
134
		$tls_mode = true;
135
	else
136
		$tls_mode = false;
137

    
138
	/* input validation */
139
	if ($pconfig['local_port']) {
140

    
141
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
142
			$input_errors[] = $result;
143

    
144
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
145
		if (($portused != $vpnid) && ($portused != 0))
146
			$input_errors[] = "The specified 'Local port' is in use. Please select another value";
147
	}
148

    
149
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
150
		$input_errors[] = $result;
151

    
152
	if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
153
		$input_errors[] = $result;
154

    
155
	if ($pconfig['proxy_addr']) {
156

    
157
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
158
			$input_errors[] = $result;
159

    
160
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
161
			$input_errors[] = $result;
162

    
163
		if ($pconfig['proxy_authtype'] != "none") {
164
			if (empty($pconfig['proxy_user']) || empty($pconfig['proxy_passwd']))
165
				$input_errors[] = "User name and password are required for proxy with authentication.";
166
		}
167
	}
168

    
169
	if($pconfig['tunnel_network'])
170
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
171
			$input_errors[] = $result;
172

    
173
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
174
		$input_errors[] = $result;
175

    
176
    if ($pconfig['autokey_enable'])
177
        $pconfig['shared_key'] = openvpn_create_key();
178

    
179
	if (!$tls_mode && !$pconfig['autokey_enable'])
180
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
181
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
182
			$input_errors[] = "The field 'Shared Key' does not appear to be valid";
183

    
184
	if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
185
		if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
186
			!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
187
			$input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
188

    
189
	if (!$tls_mode && !$pconfig['autokey_enable']) {
190
		$reqdfields = array('shared_key');
191
		$reqdfieldsn = array('Shared key');
192
    } else {
193
		$reqdfields = explode(" ", "caref certref");
194
		$reqdfieldsn = explode(",", "Certificate Authority,Certificate");;
195
	}
196

    
197
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
198
	
199
	if (!$input_errors) {
200

    
201
		$client = array();
202

    
203
		if ($vpnid)
204
			$client['vpnid'] = $vpnid;
205
		else
206
			$client['vpnid'] = openvpn_vpnid_next();
207

    
208
		$client['disable'] = $pconfig['disable'];
209
		$client['protocol'] = $pconfig['protocol'];
210
		$client['dev_mode'] = $pconfig['dev_mode'];
211
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
212
		$client['local_port'] = $pconfig['local_port'];
213
		$client['server_addr'] = $pconfig['server_addr'];
214
		$client['server_port'] = $pconfig['server_port'];
215
		$client['resolve_retry'] = $pconfig['resolve_retry'];
216
		$client['proxy_addr'] = $pconfig['proxy_addr'];
217
		$client['proxy_port'] = $pconfig['proxy_port'];
218
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
219
		$client['proxy_user'] = $pconfig['proxy_user'];
220
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
221
		$client['description'] = $pconfig['description'];
222
		$client['mode'] = $pconfig['mode'];
223
		$client['custom_options'] = $pconfig['custom_options'];
224

    
225
        if ($tls_mode) {
226
            $client['caref'] = $pconfig['caref'];
227
            $client['certref'] = $pconfig['certref'];
228
            if ($pconfig['tlsauth_enable']) {
229
                if ($pconfig['autotls_enable'])
230
                    $pconfig['tls'] = openvpn_create_key();
231
                $client['tls'] = base64_encode($pconfig['tls']);
232
            }
233
        } else {
234
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
235
        }
236
		$client['crypto'] = $pconfig['crypto'];
237

    
238
		$client['tunnel_network'] = $pconfig['tunnel_network'];
239
		$client['remote_network'] = $pconfig['remote_network'];
240
		$client['compression'] = $pconfig['compression'];
241
		$client['passtos'] = $pconfig['passtos'];
242

    
243
		if (isset($id) && $a_client[$id])
244
			$a_client[$id] = $client;
245
		else
246
			$a_client[] = $client;
247

    
248
		openvpn_resync('client', $client);
249
		write_config();
250
		
251
		header("Location: vpn_openvpn_client.php");
252
		exit;
253
	}
254
}
255

    
256
include("head.inc");
257

    
258
?>
259

    
260
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
261
<?php include("fbegin.inc"); ?>
262
<script language="JavaScript">
263
<!--
264

    
265
function mode_change() {
266
	index = document.iform.mode.selectedIndex;
267
	value = document.iform.mode.options[index].value;
268
	switch(value) {
269
		case "p2p_tls":
270
			document.getElementById("tls").style.display="";
271
			document.getElementById("tls_ca").style.display="";
272
			document.getElementById("tls_cert").style.display="";
273
			document.getElementById("psk").style.display="none";
274
			break;
275
		case "p2p_shared_key":
276
			document.getElementById("tls").style.display="none";
277
			document.getElementById("tls_ca").style.display="none";
278
			document.getElementById("tls_cert").style.display="none";
279
			document.getElementById("psk").style.display="";
280
			break;
281
	}
282
}
283

    
284
function autokey_change() {
285
	if (document.iform.autokey_enable.checked)
286
		document.getElementById("autokey_opts").style.display="none";
287
	else
288
		document.getElementById("autokey_opts").style.display="";
289
}
290

    
291
function useproxy_changed() {
292

    
293
	if ($('proxy_authtype').value != 'none') {
294
                $('proxy_authtype_opts').show();
295
        } else {
296
                $('proxy_authtype_opts').hide();
297
        }
298
}
299

    
300
function tlsauth_change() {
301

    
302
<?php if (!$pconfig['tls']): ?>
303
	if (document.iform.tlsauth_enable.checked)
304
		document.getElementById("tlsauth_opts").style.display="";
305
	else
306
		document.getElementById("tlsauth_opts").style.display="none";
307
<?php endif; ?>
308

    
309
	autotls_change();
310
}
311

    
312
function autotls_change() {
313

    
314
<?php if (!$pconfig['tls']): ?>
315
	autocheck = document.iform.autotls_enable.checked;
316
<?php else: ?>
317
	autocheck = false;
318
<?php endif; ?>
319

    
320
	if (document.iform.tlsauth_enable.checked && !autocheck)
321
		document.getElementById("autotls_opts").style.display="";
322
	else
323
		document.getElementById("autotls_opts").style.display="none";
324
}
325

    
326
//-->
327
</script>
328
<?php
329
	if ($input_errors)
330
		print_input_errors($input_errors);
331
	if ($savemsg)
332
		print_info_box($savemsg);
333
?>
334
<table width="100%" border="0" cellpadding="0" cellspacing="0">
335
 	<tr>
336
		<td class="tabnavtbl">
337
			<ul id="tabnav">
338
			<?php 
339
				$tab_array = array();
340
				$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
341
				$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
342
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
343
				add_package_tabs("OpenVPN", $tab_array);
344
				display_top_tabs($tab_array);
345
			?>
346
			</ul>
347
		</td>
348
	</tr>    
349
	<tr>
350
		<td class="tabcont">
351

    
352
			<?php if($act=="new" || $act=="edit"): ?>
353

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

    
793
			<?php else: ?>
794

    
795
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
796
				<tr>
797
					<td width="10%" class="listhdrr">Disabled</td>
798
					<td width="10%" class="listhdrr">Protocol</td>
799
					<td width="30%" class="listhdrr">Server</td>
800
					<td width="40%" class="listhdrr">Description</td>
801
					<td width="10%" class="list"></td>
802
				</tr>
803
				<?php
804
					$i = 0;
805
					foreach($a_client as $client):
806
						$disabled = "NO";
807
						if ($client['disable'])
808
							$disabled = "YES";
809
						$server = "{$client['server_addr']}:{$client['server_port']}";
810
				?>
811
				<tr>
812
					<td class="listlr">
813
						<?=$disabled;?>
814
					</td>
815
					<td class="listr">
816
						<?=htmlspecialchars($client['protocol']);?>
817
					</td>
818
					<td class="listr">
819
						<?=htmlspecialchars($server);?>
820
					</td>
821
					<td class="listbg">
822
						<?=htmlspecialchars($client['description']);?>
823
					</td>
824
					<td valign="middle" nowrap class="list">
825
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
826
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="edit client" width="17" height="17" border="0">
827
						</a>
828
						&nbsp;
829
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this client?')">
830
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="delete client" width="17" height="17" border="0">
831
						</a>
832
					</td>
833
				</tr>
834
				<?php
835
					$i++;
836
					endforeach;
837
				?>
838
				<tr>
839
					<td class="list" colspan="4"></td>
840
					<td class="list">
841
						<a href="vpn_openvpn_client.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="add client" width="17" height="17" border="0">
842
						</a>
843
					</td>
844
				</tr>
845
				<tr>
846
					<td colspan="4">
847
						<p>
848
							<?=gettext("Additional OpenVPN clients can be added here.");?>
849
						</p>
850
					</td>
851
				</tr>
852
			</table>
853

    
854
			<? endif; ?>
855

    
856
		</td>
857
	</tr>
858
</table>
859
<script language="JavaScript">
860
<!--
861
mode_change();
862
autokey_change();
863
tlsauth_change();
864
useproxy_changed();
865
//-->
866
</script>
867
</body>
868
<?php include("fend.inc"); ?>
869

    
870
<?php
871

    
872
/* local utility functions */
873

    
874
function set_checked($var,& $chk) {
875
    if($var)
876
        $chk = 'checked';
877
    else
878
        $chk = '';
879
}
880

    
881
?>
882

    
(208-208/218)