Project

General

Profile

Download (32.3 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
$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
$id = $_GET['id'];
50
if (isset($_POST['id']))
51
	$id = $_POST['id'];
52

    
53
$act = $_GET['act'];
54
if (isset($_POST['act']))
55
	$act = $_POST['act'];
56

    
57
if ($_GET['act'] == "del") {
58

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

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

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

    
78
if($_GET['act']=="edit"){
79

    
80
	if (isset($id) && $a_client[$id]) {
81

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

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

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

    
125
if ($_POST) {
126

    
127
	unset($input_errors);
128
	$pconfig = $_POST;
129

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

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

    
140
	/* input validation */
141
	if ($pconfig['local_port']) {
142

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

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

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

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

    
157
	if ($pconfig['proxy_addr']) {
158

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

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

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

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

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

    
178
    if ($pconfig['autokey_enable'])
179
        $pconfig['shared_key'] = openvpn_create_key();
180

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

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

    
191
	/* If we are not in shared key mode, then we need the CA/Cert. */
192
	if ($pconfig['mode'] != "p2p_shared_key") {
193
		$reqdfields = explode(" ", "caref certref");
194
		$reqdfieldsn = explode(",", "Certificate Authority,Certificate");;
195
	} elseif (!$pconfig['autokey_enable']) {
196
		/* We only need the shared key filled in if we are in shared key mode and autokey is not selected. */
197
		$reqdfields = array('shared_key');
198
		$reqdfieldsn = array('Shared key');
199
	}
200

    
201
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
202
	
203
	if (!$input_errors) {
204

    
205
		$client = array();
206

    
207
		if ($vpnid)
208
			$client['vpnid'] = $vpnid;
209
		else
210
			$client['vpnid'] = openvpn_vpnid_next();
211

    
212
		if ($_POST['disable'] == "yes")
213
			$client['disable'] = true;
214
		$client['protocol'] = $pconfig['protocol'];
215
		$client['dev_mode'] = $pconfig['dev_mode'];
216
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
217
		$client['local_port'] = $pconfig['local_port'];
218
		$client['server_addr'] = $pconfig['server_addr'];
219
		$client['server_port'] = $pconfig['server_port'];
220
		$client['resolve_retry'] = $pconfig['resolve_retry'];
221
		$client['proxy_addr'] = $pconfig['proxy_addr'];
222
		$client['proxy_port'] = $pconfig['proxy_port'];
223
		$client['proxy_authtype'] = $pconfig['proxy_authtype'];
224
		$client['proxy_user'] = $pconfig['proxy_user'];
225
		$client['proxy_passwd'] = $pconfig['proxy_passwd'];
226
		$client['description'] = $pconfig['description'];
227
		$client['mode'] = $pconfig['mode'];
228
		$client['custom_options'] = $pconfig['custom_options'];
229

    
230
        if ($tls_mode) {
231
            $client['caref'] = $pconfig['caref'];
232
            $client['certref'] = $pconfig['certref'];
233
            if ($pconfig['tlsauth_enable']) {
234
                if ($pconfig['autotls_enable'])
235
                    $pconfig['tls'] = openvpn_create_key();
236
                $client['tls'] = base64_encode($pconfig['tls']);
237
            }
238
        } else {
239
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
240
        }
241
		$client['crypto'] = $pconfig['crypto'];
242

    
243
		$client['tunnel_network'] = $pconfig['tunnel_network'];
244
		$client['remote_network'] = $pconfig['remote_network'];
245
		$client['compression'] = $pconfig['compression'];
246
		$client['passtos'] = $pconfig['passtos'];
247

    
248
		if (isset($id) && $a_client[$id])
249
			$a_client[$id] = $client;
250
		else
251
			$a_client[] = $client;
252

    
253
		openvpn_resync('client', $client);
254
		write_config();
255
		
256
		header("Location: vpn_openvpn_client.php");
257
		exit;
258
	}
259
}
260

    
261
include("head.inc");
262

    
263
?>
264

    
265
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
266
<?php include("fbegin.inc"); ?>
267
<script language="JavaScript">
268
<!--
269

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

    
289
function autokey_change() {
290
	if (document.iform.autokey_enable.checked)
291
		document.getElementById("autokey_opts").style.display="none";
292
	else
293
		document.getElementById("autokey_opts").style.display="";
294
}
295

    
296
function useproxy_changed() {
297

    
298
	if ($('proxy_authtype').value != 'none') {
299
                $('proxy_authtype_opts').show();
300
        } else {
301
                $('proxy_authtype_opts').hide();
302
        }
303
}
304

    
305
function tlsauth_change() {
306

    
307
<?php if (!$pconfig['tls']): ?>
308
	if (document.iform.tlsauth_enable.checked)
309
		document.getElementById("tlsauth_opts").style.display="";
310
	else
311
		document.getElementById("tlsauth_opts").style.display="none";
312
<?php endif; ?>
313

    
314
	autotls_change();
315
}
316

    
317
function autotls_change() {
318

    
319
<?php if (!$pconfig['tls']): ?>
320
	autocheck = document.iform.autotls_enable.checked;
321
<?php else: ?>
322
	autocheck = false;
323
<?php endif; ?>
324

    
325
	if (document.iform.tlsauth_enable.checked && !autocheck)
326
		document.getElementById("autotls_opts").style.display="";
327
	else
328
		document.getElementById("autotls_opts").style.display="none";
329
}
330

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

    
359
			<?php if($act=="new" || $act=="edit"): ?>
360

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

    
800
			<?php else: ?>
801

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

    
861
			<? endif; ?>
862

    
863
		</td>
864
	</tr>
865
</table>
866
<script language="JavaScript">
867
<!--
868
mode_change();
869
autokey_change();
870
tlsauth_change();
871
useproxy_changed();
872
//-->
873
</script>
874
</body>
875
<?php include("fend.inc"); ?>
876

    
877
<?php
878

    
879
/* local utility functions */
880

    
881
function set_checked($var,& $chk) {
882
    if($var)
883
        $chk = 'checked';
884
    else
885
        $chk = '';
886
}
887

    
888
?>
889

    
(208-208/218)