Project

General

Profile

Download (34.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/*
3
	vpn_openvpn_client.php
4

    
5
	Copyright (C) 2008 Shrew Soft Inc.
6
	All rights reserved. 
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
	
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
	
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
	
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
##|+PRIV
31
##|*IDENT=page-openvpn-client
32
##|*NAME=OpenVPN: Client page
33
##|*DESCR=Allow access to the 'OpenVPN: Client' page.
34
##|*MATCH=vpn_openvpn_client.php*
35
##|-PRIV
36

    
37
require("guiconfig.inc");
38
require_once("openvpn.inc");
39

    
40
$pgtitle = array(gettext("OpenVPN"), gettext("Client"));
41
$statusurl = "status_openvpn.php";
42
$logurl = "diag_logs_openvpn.php";
43

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
140
if ($_POST) {
141

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
220
		$client = array();
221

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

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

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

    
258
		$client['tunnel_network'] = $pconfig['tunnel_network'];
259
		$client['remote_network'] = $pconfig['remote_network'];
260
		$client['compression'] = $pconfig['compression'];
261
		$client['passtos'] = $pconfig['passtos'];
262

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

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

    
276
include("head.inc");
277

    
278
?>
279

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

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

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

    
311
function useproxy_changed() {
312

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

    
320
function tlsauth_change() {
321

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

    
329
	autotls_change();
330
}
331

    
332
function autotls_change() {
333

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

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

    
346
//-->
347
</script>
348
<?php
349
if (!$savemsg)
350
	$savemsg = "";
351
if (count($a_ca) == 0)
352
	$savemsg .= "You have no Certificate Authorities defined. You must visit the <a href=\"system_camanager.php\">Certificate Manager</a> to make one.";
353
if (count($a_cert) == 0)
354
	$savemsg .= "<br/>You have no Certificates defined. You must visit the <a href=\"system_camanager.php\">Certificate Manager</a> to make one.";
355

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

    
380
			<?php if($act=="new" || $act=="edit"): ?>
381

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

    
833
			<?php else: ?>
834

    
835
			<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
836
				<thead>
837
				<tr>
838
					<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
839
					<td width="10%" class="listhdrr"><?=gettext("Protocol"); ?></td>
840
					<td width="30%" class="listhdrr"><?=gettext("Server"); ?></td>
841
					<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
842
					<td width="10%" class="list"></td>
843
				</tr>
844
				</thead>
845
				<tbody>
846
				<?php
847
					$i = 0;
848
					foreach($a_client as $client):
849
						$disabled = "NO";
850
						if (isset($client['disable']))
851
							$disabled = "YES";
852
						$server = "{$client['server_addr']}:{$client['server_port']}";
853
				?>
854
				<tr ondblclick="document.location='vpn_openvpn_client.php?act=edit&id=<?=$i;?>'">
855
					<td class="listlr">
856
						<?=$disabled;?>
857
					</td>
858
					<td class="listr">
859
						<?=htmlspecialchars($client['protocol']);?>
860
					</td>
861
					<td class="listr">
862
						<?=htmlspecialchars($server);?>
863
					</td>
864
					<td class="listbg">
865
						<?=htmlspecialchars($client['description']);?>
866
					</td>
867
					<td valign="middle" nowrap class="list">
868
						<a href="vpn_openvpn_client.php?act=edit&id=<?=$i;?>">
869
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit client"); ?>" width="17" height="17" border="0">
870
						</a>
871
						&nbsp;
872
						<a href="vpn_openvpn_client.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this client?"); ?>')">
873
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete client"); ?>" width="17" height="17" border="0">
874
						</a>
875
					</td>
876
				</tr>
877
				<?php
878
					$i++;
879
					endforeach;
880
				?>
881
				</tbody>
882
				<tfoot>
883
				<tr>
884
					<td class="list" colspan="4"></td>
885
					<td class="list">
886
						<a href="vpn_openvpn_client.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add client"); ?>" width="17" height="17" border="0">
887
						</a>
888
					</td>
889
				</tr>
890
				<tr>
891
					<td colspan="4">
892
						<p>
893
							<?=gettext("Additional OpenVPN clients can be added here.");?>
894
						</p>
895
					</td>
896
				</tr>
897
				</tfoot>
898
			</table>
899

    
900
			<?php endif; ?>
901

    
902
		</td>
903
	</tr>
904
</table>
905
<script language="JavaScript">
906
<!--
907
mode_change();
908
autokey_change();
909
tlsauth_change();
910
useproxy_changed();
911
//-->
912
</script>
913
</body>
914
<?php include("fend.inc"); ?>
915

    
916
<?php
917

    
918
/* local utility functions */
919

    
920
function set_checked($var,& $chk) {
921
    if($var)
922
        $chk = 'checked';
923
    else
924
        $chk = '';
925
}
926

    
927
?>
928

    
(211-211/220)