Project

General

Profile

Download (26.1 KB) Statistics
| Branch: | Tag: | Revision:
1 d799787e Matthew Grooms
<?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 d84bd468 Ermal Lu?i
require_once("openvpn.inc");
39 d799787e Matthew Grooms
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 dc408939 Matthew Grooms
	openvpn_delete('client', $a_client[$id]);
63 d799787e Matthew Grooms
	unset($a_client[$id]);
64
	write_config();
65
	$savemsg = gettext("Client successfully deleted")."<br/>";
66
}
67
68 f432e364 Matthew Grooms
if($_GET['act']=="new"){
69 3c11bd3c Matthew Grooms
	$pconfig['autokey_enable'] = "yes";
70
	$pconfig['tlsauth_enable'] = "yes";
71
	$pconfig['autotls_enable'] = "yes";
72 f432e364 Matthew Grooms
	$pconfig['interface'] = "wan";
73
	$pconfig['server_port'] = 1194;
74
}
75
76 d799787e Matthew Grooms
if($_GET['act']=="edit"){
77
78
	if (isset($id) && $a_client[$id]) {
79
80
		$pconfig['disable'] = $a_client[$id]['disable'];
81 3c11bd3c Matthew Grooms
		$pconfig['mode'] = $a_client[$id]['mode'];
82 d799787e Matthew Grooms
		$pconfig['protocol'] = $a_client[$id]['protocol'];
83
		$pconfig['interface'] = $a_client[$id]['interface'];
84 67b0902f pierrepomes
		if (!empty($a_client[$id]['ipaddr'])) {
85
			$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$id]['ipaddr'];
86
		}
87 d799787e Matthew Grooms
		$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['description'] = $a_client[$id]['description'];
94 c7323d81 sullrich
		$pconfig['custom_options'] = $a_client[$id]['custom_options'];
95
		
96 3c11bd3c Matthew Grooms
		if ($pconfig['mode'] != "p2p_shared_key") {
97 d799787e Matthew Grooms
			$pconfig['caref'] = $a_client[$id]['caref'];
98
			$pconfig['certref'] = $a_client[$id]['certref'];
99 3c11bd3c Matthew Grooms
			if ($a_client[$id]['tls']) {
100
				$pconfig['tlsauth_enable'] = "yes";
101
				$pconfig['tls'] = base64_decode($a_client[$id]['tls']);
102
			}
103
		} else
104
			$pconfig['shared_key'] = base64_decode($a_client[$id]['shared_key']);
105 d799787e Matthew Grooms
		$pconfig['crypto'] = $a_client[$id]['crypto'];
106
107
		$pconfig['tunnel_network'] = $a_client[$id]['tunnel_network'];
108
		$pconfig['remote_network'] = $a_client[$id]['remote_network'];
109
		$pconfig['compression'] = $a_client[$id]['compression'];
110 1cb0b40a Matthew Grooms
		$pconfig['passtos'] = $a_client[$id]['passtos'];
111 3c11bd3c Matthew Grooms
112
		// just in case the modes switch
113
		$pconfig['autokey_enable'] = "yes";
114
		$pconfig['autotls_enable'] = "yes";
115 d799787e Matthew Grooms
	}
116
}
117
118
if ($_POST) {
119
120
	unset($input_errors);
121
	$pconfig = $_POST;
122
123 dc408939 Matthew Grooms
	if (isset($id) && $a_client[$id])
124
		$vpnid = $a_client[$id]['vpnid'];
125 f432e364 Matthew Grooms
	else
126
		$vpnid = 0;
127
128 98c0c87a jim-p
	if ($pconfig['mode'] != "p2p_shared_key")
129 3c11bd3c Matthew Grooms
		$tls_mode = true;
130
	else
131
		$tls_mode = false;
132
133 d799787e Matthew Grooms
	/* input validation */
134 f432e364 Matthew Grooms
	if ($pconfig['local_port']) {
135
136
		if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
137
			$input_errors[] = $result;
138
139 5accf130 jim-p
		$portused = openvpn_port_used($pconfig['protocol'], $pconfig['local_port']);
140
		if (($portused != $vpnid) && ($portused != 0))
141 f432e364 Matthew Grooms
			$input_errors[] = "The specified 'Local port' is in use. Please select another value";
142
	}
143
144 d799787e Matthew Grooms
	if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
145
		$input_errors[] = $result;
146
147
	if ($result = openvpn_validate_port($pconfig['server_port'], 'Server port'))
148
		$input_errors[] = $result;
149
150
	if ($pconfig['proxy_addr']) {
151
152
		if ($result = openvpn_validate_host($pconfig['proxy_addr'], 'Proxy host or address'))
153
			$input_errors[] = $result;
154
155
		if ($result = openvpn_validate_port($pconfig['proxy_port'], 'Proxy port'))
156
			$input_errors[] = $result;
157
	}
158
159 c13b87a0 sullrich
	if($pconfig['tunnel_network'])
160
		if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network'))
161
			$input_errors[] = $result;
162 d799787e Matthew Grooms
163
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network'))
164
		$input_errors[] = $result;
165
166 89e6e210 jim-p
    if ($pconfig['autokey_enable'])
167
        $pconfig['shared_key'] = openvpn_create_key();
168
169 3c11bd3c Matthew Grooms
	if (!$tls_mode && !$pconfig['autokey_enable'])
170 d799787e Matthew Grooms
		if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
171
			!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
172 3c11bd3c Matthew Grooms
			$input_errors[] = "The field 'Shared Key' does not appear to be valid";
173
174
	if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable'])
175
		if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") ||
176
			!strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----"))
177
			$input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid";
178 d799787e Matthew Grooms
179 89e6e210 jim-p
	if (!$tls_mode && !$pconfig['autokey_enable']) {
180 872d9195 Matthew Grooms
		$reqdfields = array('shared_key');
181
		$reqdfieldsn = array('Shared key');
182 d799787e Matthew Grooms
    } else {
183 872d9195 Matthew Grooms
		$reqdfields = explode(" ", "caref certref");
184
		$reqdfieldsn = explode(",", "Certificate Authority,Certificate");;
185 d799787e Matthew Grooms
	}
186
187
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
188
	
189
	if (!$input_errors) {
190
191
		$client = array();
192
193 f432e364 Matthew Grooms
		if ($vpnid)
194
			$client['vpnid'] = $vpnid;
195 d799787e Matthew Grooms
		else
196
			$client['vpnid'] = openvpn_vpnid_next();
197
198
		$client['disable'] = $pconfig['disable'];
199
		$client['protocol'] = $pconfig['protocol'];
200 67b0902f pierrepomes
		list($client['interface'], $client['ipaddr']) = explode ("|",$pconfig['interface']);
201 d799787e Matthew Grooms
		$client['local_port'] = $pconfig['local_port'];
202
		$client['server_addr'] = $pconfig['server_addr'];
203
		$client['server_port'] = $pconfig['server_port'];
204
		$client['resolve_retry'] = $pconfig['resolve_retry'];
205
		$client['proxy_addr'] = $pconfig['proxy_addr'];
206
		$client['proxy_port'] = $pconfig['proxy_port'];
207
		$client['description'] = $pconfig['description'];
208 50a9d5b9 jim-p
		$client['mode'] = $pconfig['mode'];
209 c7323d81 sullrich
		$client['custom_options'] = $pconfig['custom_options'];
210 d799787e Matthew Grooms
211 3c11bd3c Matthew Grooms
        if ($tls_mode) {
212
            $client['caref'] = $pconfig['caref'];
213
            $client['certref'] = $pconfig['certref'];
214
            if ($pconfig['tlsauth_enable']) {
215
                if ($pconfig['autotls_enable'])
216
                    $pconfig['tls'] = openvpn_create_key();
217
                $client['tls'] = base64_encode($pconfig['tls']);
218
            }
219
        } else {
220
            $client['shared_key'] = base64_encode($pconfig['shared_key']);
221
        }
222 d799787e Matthew Grooms
		$client['crypto'] = $pconfig['crypto'];
223
224
		$client['tunnel_network'] = $pconfig['tunnel_network'];
225
		$client['remote_network'] = $pconfig['remote_network'];
226
		$client['compression'] = $pconfig['compression'];
227
228
		if (isset($id) && $a_client[$id])
229
			$a_client[$id] = $client;
230
		else
231
			$a_client[] = $client;
232
233 dc408939 Matthew Grooms
		openvpn_resync('client', $client);
234 d799787e Matthew Grooms
		write_config();
235
		
236
		header("Location: vpn_openvpn_client.php");
237
		exit;
238
	}
239
}
240
241
include("head.inc");
242
243
?>
244
245
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
246
<?php include("fbegin.inc"); ?>
247
<script language="JavaScript">
248
<!--
249
250 3c11bd3c Matthew Grooms
function mode_change() {
251
	index = document.iform.mode.selectedIndex;
252
	value = document.iform.mode.options[index].value;
253 d799787e Matthew Grooms
	switch(value) {
254 3c11bd3c Matthew Grooms
		case "p2p_tls":
255
			document.getElementById("tls").style.display="";
256
			document.getElementById("tls_ca").style.display="";
257
			document.getElementById("tls_cert").style.display="";
258 d799787e Matthew Grooms
			document.getElementById("psk").style.display="none";
259
			break;
260 3c11bd3c Matthew Grooms
		case "p2p_shared_key":
261
			document.getElementById("tls").style.display="none";
262
			document.getElementById("tls_ca").style.display="none";
263
			document.getElementById("tls_cert").style.display="none";
264 d799787e Matthew Grooms
			document.getElementById("psk").style.display="";
265
			break;
266
	}
267
}
268
269 3c11bd3c Matthew Grooms
function autokey_change() {
270
	if (document.iform.autokey_enable.checked)
271
		document.getElementById("autokey_opts").style.display="none";
272
	else
273
		document.getElementById("autokey_opts").style.display="";
274
}
275
276
function tlsauth_change() {
277
278
<?php if (!$pconfig['tls']): ?>
279
	if (document.iform.tlsauth_enable.checked)
280
		document.getElementById("tlsauth_opts").style.display="";
281
	else
282
		document.getElementById("tlsauth_opts").style.display="none";
283
<?php endif; ?>
284
285
	autotls_change();
286
}
287
288
function autotls_change() {
289
290
<?php if (!$pconfig['tls']): ?>
291
	autocheck = document.iform.autotls_enable.checked;
292
<?php else: ?>
293
	autocheck = false;
294
<?php endif; ?>
295
296
	if (document.iform.tlsauth_enable.checked && !autocheck)
297
		document.getElementById("autotls_opts").style.display="";
298
	else
299
		document.getElementById("autotls_opts").style.display="none";
300
}
301
302 d799787e Matthew Grooms
//-->
303
</script>
304
<?php
305
	if ($input_errors)
306
		print_input_errors($input_errors);
307
	if ($savemsg)
308
		print_info_box($savemsg);
309
?>
310
<table width="100%" border="0" cellpadding="0" cellspacing="0">
311
 	<tr>
312
		<td class="tabnavtbl">
313
			<ul id="tabnav">
314
			<?php 
315
				$tab_array = array();
316
				$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
317
				$tab_array[] = array(gettext("Client"), true, "vpn_openvpn_client.php");
318
				$tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php");
319 b63f2e8b Matthew Grooms
				add_package_tabs("OpenVPN", $tab_array);
320 d799787e Matthew Grooms
				display_top_tabs($tab_array);
321
			?>
322
			</ul>
323
		</td>
324
	</tr>    
325
	<tr>
326
		<td class="tabcont">
327
328
			<?php if($act=="new" || $act=="edit"): ?>
329
330
			<form action="vpn_openvpn_client.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
331
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
332 47c00c09 Scott Ullrich
					<tr>
333
						<td colspan="2" valign="top" class="listtopic">General information</td>
334
					</tr>
335 d799787e Matthew Grooms
					<tr>
336
						<td width="22%" valign="top" class="vncellreq">Disabled</td>
337
						<td width="78%" class="vtable">
338
							<table border="0" cellpadding="0" cellspacing="0">
339
								<tr>
340
									<td>
341
										<?php set_checked($pconfig['disable'],$chk); ?>
342
										<input name="disable" type="checkbox" value="yes" <?=$chk;?>/>
343
									</td>
344
									<td>
345
										&nbsp;
346
										<span class="vexpl">
347
											<strong>Disable this client</strong><br>
348
										</span>
349
									</td>
350
								</tr>
351
							</table>
352
							Set this option to disable this client without removing it from the list.
353
						</td>
354
					</tr>
355 3c11bd3c Matthew Grooms
					<tr>
356
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server Mode");?></td>
357
						<td width="78%" class="vtable">
358
							<select name='mode' id='mode' class="formselect" onchange='mode_change()'>
359
							<?php
360
								foreach ($openvpn_client_modes as $name => $desc):
361
									$selected = "";
362
									if ($pconfig['mode'] == $name)
363
										$selected = "selected";
364
							?>
365
								<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
366
							<?php endforeach; ?>
367
							</select>
368
						</td>
369
					</tr>
370 d799787e Matthew Grooms
					<tr>
371
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
372
							<td width="78%" class="vtable">
373
							<select name='protocol' class="formselect">
374
							<?php
375
								foreach ($openvpn_prots as $prot):
376
									$selected = "";
377
									if ($pconfig['protocol'] == $prot)
378
										$selected = "selected";
379
							?>
380
								<option value="<?=$prot;?>" <?=$selected;?>><?=$prot;?></option>
381
							<?php endforeach; ?>
382
							</select>
383
							</td>
384
					</tr>
385
					<tr>
386
						<td width="22%" valign="top" class="vncellreq">Interface</td>
387
						<td width="78%" class="vtable">
388
							<select name="interface" class="formselect">
389
								<?php
390
									$interfaces = get_configured_interface_with_descr();
391 3d06e8f0 pierrepomes
									$carplist = get_configured_carp_interface_list();
392
									foreach ($carplist as $cif => $carpip)
393 67b0902f pierrepomes
										$interfaces[$cif.'|'.$carpip] = strtoupper($cif) . " ({$carpip})";
394
									$aliaslist = get_configured_ip_aliases_list();
395
									foreach ($aliaslist as $aliasip => $aliasif)
396
										$interfaces[$aliasif.'|'.$aliasip] = strtoupper($aliasif) . " ({$aliasip})";
397
									$interfaces['any'] = "any";
398 3d06e8f0 pierrepomes
									foreach ($interfaces as $iface => $ifacename):
399 1d3bcd2a Matthew Grooms
										$selected = "";
400
										if ($iface == $pconfig['interface'])
401
											$selected = "selected";
402 d799787e Matthew Grooms
								?>
403 1d3bcd2a Matthew Grooms
									<option value="<?=$iface;?>" <?=$selected;?>>
404
										<?=htmlspecialchars($ifacename);?>
405
									</option>
406 d799787e Matthew Grooms
								<?php endforeach; ?>
407
							</select> <br>
408
						</td>
409
					</tr>
410 1d3bcd2a Matthew Grooms
					<tr>
411
						<td width="22%" valign="top" class="vncell"><?=gettext("Local port");?></td>
412
						<td width="78%" class="vtable">
413
							<input name="local_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['local_port']);?>"/>
414 d799787e Matthew Grooms
							<br/>
415
							Set this option if you would like to bind to a specific port.
416 1d3bcd2a Matthew Grooms
						</td>
417
					</tr>
418 d799787e Matthew Grooms
					<tr>
419
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server host or address");?></td>
420
						<td width="78%" class="vtable">
421
							<input name="server_addr" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['server_addr']);?>"/>
422
						</td>
423
					</tr>
424
					<tr>
425
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Server port");?></td>
426
						<td width="78%" class="vtable">
427
							<input name="server_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['server_port']);?>"/>
428
						</td>
429
					</tr>
430
					<tr>
431
						<td width="22%" valign="top" class="vncell"><?=gettext("Proxy host or address");?></td>
432
						<td width="78%" class="vtable">
433
							<input name="proxy_addr" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['proxy_addr']);?>"/>
434
						</td>
435
					</tr>
436
					<tr>
437
						<td width="22%" valign="top" class="vncell"><?=gettext("Proxy port");?></td>
438
						<td width="78%" class="vtable">
439
							<input name="proxy_port" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['proxy_port']);?>"/>
440
						</td>
441
					</tr>
442
					<tr>
443
						<td width="22%" valign="top" class="vncell">Server host name resolution</td>
444
						<td width="78%" class="vtable">
445
							<table border="0" cellpadding="2" cellspacing="0">
446
								<tr>
447
									<td>
448
										<?php set_checked($pconfig['resolve_retry'],$chk); ?>
449 db2872a2 Ermal Lu?i
										<input name="resolve_retry" type="checkbox" value="yes" <?=$chk;?>>
450 d799787e Matthew Grooms
									</td>
451
									<td>
452
										<span class="vexpl">
453
											Infinitely resolve server
454
										</span>
455
									</td>
456
								</tr>
457
							</table>
458
							Continuously attempt to resolve the server host
459
							name. Useful when communicating with a server
460
							that is not permanently connected to the internet.
461
						</td>
462
					</tr>
463
					<tr> 
464
						<td width="22%" valign="top" class="vncell">Description</td>
465
						<td width="78%" class="vtable"> 
466
							<input name="description" type="text" class="formfld unknown" size="30" value="<?=htmlspecialchars($pconfig['description']);?>">
467
							<br>
468
							You may enter a description here for your reference (not parsed).
469
						</td>
470
					</tr>
471
					<tr>
472
						<td colspan="2" class="list" height="12"></td>
473
					</tr>
474
					<tr>
475
						<td colspan="2" valign="top" class="listtopic">Cryptographic Settings</td>
476
					</tr>
477 3c11bd3c Matthew Grooms
					<tr id="tls">
478
						<td width="22%" valign="top" class="vncellreq">TLS Authentication</td>
479
						<td width="78%" class="vtable">
480
							<table border="0" cellpadding="2" cellspacing="0">
481
								<tr>
482
									<td>
483
										<?php set_checked($pconfig['tlsauth_enable'],$chk); ?>
484
										<input name="tlsauth_enable" id="tlsauth_enable" type="checkbox" value="yes" <?=$chk;?> onClick="tlsauth_change()">
485
									</td>
486
									<td>
487
										<span class="vexpl">
488
											Enable authentication of TLS packets.
489
										</span>
490
									</td>
491
								</tr>
492
							</table>
493
							<?php if (!$pconfig['tls']): ?>
494
							<table border="0" cellpadding="2" cellspacing="0" id='tlsauth_opts'>
495
								<tr>
496
									<td>
497
										<?php set_checked($pconfig['autotls_enable'],$chk); ?>
498
										<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autotls_change()">
499
									</td>
500
									<td>
501
										<span class="vexpl">
502
											Automatically generate a shared TLS authentication key.
503
										</span>
504
									</td>
505
								</tr>
506
							</table>
507
							<?php endif; ?>
508
							<table border="0" cellpadding="2" cellspacing="0" id='autotls_opts'>
509
								<tr>
510
									<td>
511
										<textarea name="tls" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['tls']);?></textarea>
512
										<br/>
513
										Paste your shared key here.
514
									</td>
515
								</tr>
516
							</table>
517
						</td>
518 d799787e Matthew Grooms
					</tr>
519 3c11bd3c Matthew Grooms
					<tr id="tls_ca">
520
						<td width="22%" valign="top" class="vncellreq">Peer Certificate Authority</td>
521 d799787e Matthew Grooms
							<td width="78%" class="vtable">
522
							<select name='caref' class="formselect">
523
							<?php
524
								foreach ($config['system']['ca'] as $ca):
525
									$selected = "";
526
									if ($pconfig['caref'] == $ca['refid'])
527
										$selected = "selected";
528
							?>
529
								<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['name'];?></option>
530
							<?php endforeach; ?>
531
							</select>
532
							</td>
533
					</tr>
534 3c11bd3c Matthew Grooms
					<tr id="tls_cert">
535
						<td width="22%" valign="top" class="vncellreq">Client Certificate</td>
536 d799787e Matthew Grooms
							<td width="78%" class="vtable">
537
							<select name='certref' class="formselect">
538
							<?php
539
								foreach ($config['system']['cert'] as $cert):
540
									$selected = "";
541
									if ($pconfig['certref'] == $cert['refid'])
542
										$selected = "selected";
543
							?>
544
								<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['name'];?></option>
545
							<?php endforeach; ?>
546
							</select>
547
						</td>
548
					</tr>
549
					<tr id="psk">
550
						<td width="22%" valign="top" class="vncellreq">Shared Key</td>
551 3c11bd3c Matthew Grooms
						<td width="78%" class="vtable">
552
							<?php if (!$pconfig['shared_key']): ?>
553
							<table border="0" cellpadding="2" cellspacing="0">
554
								<tr>
555
									<td>
556
										<?php set_checked($pconfig['autokey_enable'],$chk); ?>
557
										<input name="autokey_enable" type="checkbox" value="yes" <?=$chk;?> onClick="autokey_change()">
558
									</td>
559
									<td>
560
										<span class="vexpl">
561
											Automatically generate a shared key.
562
										</span>
563
									</td>
564
								</tr>
565
							</table>
566
							<?php endif; ?>
567
							<table border="0" cellpadding="2" cellspacing="0" id='autokey_opts'>
568
								<tr>
569
									<td>
570
										<textarea name="shared_key" cols="65" rows="7" class="formpre"><?=htmlspecialchars($pconfig['shared_key']);?></textarea>
571
										<br/>
572
										Paste your shared key here.
573
									</td>
574
								</tr>
575
							</table>
576 d799787e Matthew Grooms
						</td>
577
					</tr>
578
					<tr>
579
						<td width="22%" valign="top" class="vncellreq">Encryption algorithm</td>
580
						<td width="78%" class="vtable">
581
							<select name="crypto" class="formselect">
582
								<?php
583
									$cipherlist = openvpn_get_cipherlist();
584
									foreach ($cipherlist as $name => $desc):
585
									$selected = '';
586
									if ($name == $pconfig['crypto'])
587
										$selected = ' selected';
588
								?>
589
								<option value="<?=$name;?>"<?=$selected?>>
590
									<?=htmlspecialchars($desc);?>
591
								</option>
592
								<?php endforeach; ?>
593
							</select>
594
						</td>
595
					</tr>
596
					<tr>
597
						<td colspan="2" class="list" height="12"></td>
598
					</tr>
599
					<tr>
600
						<td colspan="2" valign="top" class="listtopic">Tunnel Settings</td>
601
					</tr>
602
					<tr>
603 c13b87a0 sullrich
						<td width="22%" valign="top" class="vncell">Tunnel Network</td>
604 d799787e Matthew Grooms
						<td width="78%" class="vtable">
605
							<input name="tunnel_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['tunnel_network']);?>">
606
							<br>
607
							This is the virtual network used for private
608
							communications between this client and the
609
							server expressed using CIDR (eg. 10.0.8.0/24).
610
							The first network address is assumed to be the
611
							server address and the second network address
612
							will be assigned to the client virtual
613
							interface.
614
						</td>
615
					</tr>
616
					<tr>
617
						<td width="22%" valign="top" class="vncell">Remote Network</td>
618
						<td width="78%" class="vtable">
619
							<input name="remote_network" type="text" class="formfld unknown" size="20" value="<?=htmlspecialchars($pconfig['remote_network']);?>">
620
							<br>
621
							This is a network that will be routed through
622
							the tunnel, so that a site-to-site VPN can be
623
							established without manually changing the
624
							routing tables. Expressed as a CIDR range. If
625
							this is a site-to-site VPN, enter here the
626
							remote LAN here. You may leave this blank to
627
							only communicate with other clients.
628
						</td>
629
					</tr>
630
					<tr>
631
						<td width="22%" valign="top" class="vncell"><?=gettext("Limit outgoing bandwidth");?></td>
632
						<td width="78%" class="vtable">
633
							<input name="use_shaper" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['use_shaper']);?>"/>
634
							<br/>
635
							Maximum outgoing bandwidth for this tunnel.
636
							Leave empty for no limit. The input value has
637
							to be something between 100 bytes/sec and 100
638
							Mbytes/sec (entered as bytes per second).
639
						</td>
640
					</tr>
641
					<tr>
642
						<td width="22%" valign="top" class="vncell">Compression</td>
643
						<td width="78%" class="vtable">
644
							<table border="0" cellpadding="2" cellspacing="0">
645
								<tr>
646
									<td>
647
										<?php set_checked($pconfig['compression'],$chk); ?>
648
										<input name="compression" type="checkbox" value="yes" <?=$chk;?>>
649
									</td>
650
									<td>
651
										<span class="vexpl">
652
											Compress tunnel packets using the LZO algorithm.
653
										</span>
654
									</td>
655
								</tr>
656
							</table>
657
						</td>
658
					</tr>
659
					<tr>
660
						<td width="22%" valign="top" class="vncell">Type-of-Service</td>
661
						<td width="78%" class="vtable">
662
							<table border="0" cellpadding="2" cellspacing="0">
663
								<tr>
664
									<td>
665 1cb0b40a Matthew Grooms
										<?php set_checked($pconfig['passtos'],$chk); ?>
666
										<input name="passtos" type="checkbox" value="yes" <?=$chk;?>>
667 d799787e Matthew Grooms
									</td>
668
									<td>
669
										<span class="vexpl">
670
											Set the TOS IP header value of tunnel packets to match the encapsulated packet value.
671
										</span>
672
									</td>
673
								</tr>
674
							</table>
675
						</td>
676
					</tr>
677 c7323d81 sullrich
					<tr>
678
						<td colspan="2" class="list" height="12"></td>
679
					</tr>
680
					<tr>
681
						<td colspan="2" valign="top" class="listtopic">Advanced configuration</td>
682
					</tr>
683
					<tr>
684
						<td width="22%" valign="top" class="vncell">Advanced</td>
685
						<td width="78%" class="vtable">
686
							<table border="0" cellpadding="2" cellspacing="0">
687
								<tr>
688
									<td>
689
										<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=$pconfig['custom_options'];?></textarea><br/>
690
										Paste any additional options you would like to pass through to the OpenVPN server here seperated by a semicolon<br/>
691
										EXAMPLE: push "route 10.0.0.0 255.255.255.0";
692
									</td>
693
								</tr>
694
							</table>
695
						</td>
696
					</tr>					
697 d799787e Matthew Grooms
					<tr>
698
						<td width="22%" valign="top">&nbsp;</td>
699
						<td width="78%"> 
700
							<input name="save" type="submit" class="formbtn" value="Save"> 
701
							<input name="act" type="hidden" value="<?=$act;?>">
702
							<?php if (isset($id) && $a_client[$id]): ?>
703
							<input name="id" type="hidden" value="<?=$id;?>">
704
							<?php endif; ?>
705
						</td>
706
					</tr>
707
				</table>
708
			</form>
709
710
			<?php else: ?>
711
712
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
713
				<tr>
714
					<td width="10%" class="listhdrr">Disabled</td>
715
					<td width="10%" class="listhdrr">Protocol</td>
716
					<td width="30%" class="listhdrr">Server</td>
717
					<td width="40%" class="listhdrr">Description</td>
718
					<td width="10%" class="list"></td>
719
				</tr>
720
				<?php
721
					$i = 0;
722
					foreach($a_client as $client):
723
						$disabled = "NO";
724
						if ($client['disable'])
725
							$disabled = "YES";
726
						$server = "{$client['server_addr']}:{$client['server_port']}";
727
				?>
728
				<tr>
729
					<td class="listlr">
730
						<?=$disabled;?>
731
					</td>
732
					<td class="listr">
733
						<?=htmlspecialchars($client['protocol']);?>
734
					</td>
735
					<td class="listr">
736
						<?=htmlspecialchars($server);?>
737
					</td>
738 296a3cb6 Scott Ullrich
					<td class="listbg">
739 d799787e Matthew Grooms
						<?=htmlspecialchars($client['description']);?>
740
					</td>
741
					<td valign="middle" nowrap class="list">
742
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
743
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="edit client" width="17" height="17" border="0">
744
						</a>
745
						&nbsp;
746
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this client?')">
747
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="delete client" width="17" height="17" border="0">
748
						</a>
749
					</td>
750
				</tr>
751
				<?php
752
					$i++;
753
					endforeach;
754
				?>
755
				<tr>
756
					<td class="list" colspan="4"></td>
757
					<td class="list">
758
						<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">
759
						</a>
760
					</td>
761
				</tr>
762
				<tr>
763
					<td colspan="4">
764
						<p>
765
							<?=gettext("Additional OpenVPN clients can be added here.");?>
766
						</p>
767
					</td>
768
				</tr>
769
			</table>
770
771
			<? endif; ?>
772
773
		</td>
774
	</tr>
775
</table>
776
<script language="JavaScript">
777
<!--
778 3c11bd3c Matthew Grooms
mode_change();
779
autokey_change();
780
tlsauth_change();
781 d799787e Matthew Grooms
//-->
782
</script>
783
</body>
784
<?php include("fend.inc"); ?>
785
786
<?php
787
788
/* local utility functions */
789
790
function set_checked($var,& $chk) {
791
    if($var)
792
        $chk = 'checked';
793
    else
794
        $chk = '';
795
}
796
797
?>