Project

General

Profile

Download (20.3 KB) Statistics
| Branch: | Tag: | Revision:
1 b83e61e4 sbeaver
<?php
2 d799787e Matthew Grooms
/*
3
	vpn_openvpn_csc.php
4
5
	Copyright (C) 2008 Shrew Soft Inc.
6 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 b83e61e4 sbeaver
	All rights reserved.
8 d799787e Matthew Grooms
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 b83e61e4 sbeaver
12 d799787e Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 b83e61e4 sbeaver
15 d799787e Matthew Grooms
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18 b83e61e4 sbeaver
19 d799787e Matthew Grooms
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31
##|+PRIV
32
##|*IDENT=page-openvpn-csc
33
##|*NAME=OpenVPN: Client Specific Override page
34
##|*DESCR=Allow access to the 'OpenVPN: Client Specific Override' page.
35
##|*MATCH=vpn_openvpn_csc.php*
36
##|-PRIV
37
38
require("guiconfig.inc");
39 d84bd468 Ermal Lu?i
require_once("openvpn.inc");
40 fdae0912 Renato Botelho
require_once("pkg-utils.inc");
41 d799787e Matthew Grooms
42 deeda874 Carlos Eduardo Ramos
$pgtitle = array(gettext("OpenVPN"), gettext("Client Specific Override"));
43 b32dd0a6 jim-p
$shortcut_section = "openvpn";
44 d799787e Matthew Grooms
45 e38c75a8 Phil Davis
if (!is_array($config['openvpn']['openvpn-csc'])) {
46 d799787e Matthew Grooms
	$config['openvpn']['openvpn-csc'] = array();
47 e38c75a8 Phil Davis
}
48 d799787e Matthew Grooms
49
$a_csc = &$config['openvpn']['openvpn-csc'];
50
51 e38c75a8 Phil Davis
if (is_numericint($_GET['id'])) {
52 e41ec584 Renato Botelho
	$id = $_GET['id'];
53 e38c75a8 Phil Davis
}
54
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
55 d799787e Matthew Grooms
	$id = $_POST['id'];
56 e38c75a8 Phil Davis
}
57 d799787e Matthew Grooms
58
$act = $_GET['act'];
59 e38c75a8 Phil Davis
if (isset($_POST['act'])) {
60 d799787e Matthew Grooms
	$act = $_POST['act'];
61 e38c75a8 Phil Davis
}
62 d799787e Matthew Grooms
63
if ($_GET['act'] == "del") {
64
	if (!$a_csc[$id]) {
65
		pfSenseHeader("vpn_openvpn_csc.php");
66
		exit;
67
	}
68
69 e6af6518 jim-p
	openvpn_delete_csc($a_csc[$id]);
70 d799787e Matthew Grooms
	unset($a_csc[$id]);
71
	write_config();
72 8cd558b6 ayvis
	$savemsg = gettext("Client Specific Override successfully deleted")."<br />";
73 d799787e Matthew Grooms
}
74
75 e38c75a8 Phil Davis
if ($_GET['act'] == "edit") {
76 d799787e Matthew Grooms
77
	if (isset($id) && $a_csc[$id]) {
78 72d51890 Scott Ullrich
		$pconfig['custom_options'] = $a_csc[$id]['custom_options'];
79 0c88fc1e jim-p
		$pconfig['disable'] = isset($a_csc[$id]['disable']);
80 d799787e Matthew Grooms
		$pconfig['common_name'] = $a_csc[$id]['common_name'];
81
		$pconfig['block'] = $a_csc[$id]['block'];
82
		$pconfig['description'] = $a_csc[$id]['description'];
83
84
		$pconfig['tunnel_network'] = $a_csc[$id]['tunnel_network'];
85 5c427ce7 jim-p
		$pconfig['local_network'] = $a_csc[$id]['local_network'];
86
		$pconfig['local_networkv6'] = $a_csc[$id]['local_networkv6'];
87
		$pconfig['remote_network'] = $a_csc[$id]['remote_network'];
88
		$pconfig['remote_networkv6'] = $a_csc[$id]['remote_networkv6'];
89 d799787e Matthew Grooms
		$pconfig['gwredir'] = $a_csc[$id]['gwredir'];
90
91
		$pconfig['push_reset'] = $a_csc[$id]['push_reset'];
92
93
		$pconfig['dns_domain'] = $a_csc[$id]['dns_domain'];
94 e38c75a8 Phil Davis
		if ($pconfig['dns_domain']) {
95 d799787e Matthew Grooms
			$pconfig['dns_domain_enable'] = true;
96 e38c75a8 Phil Davis
		}
97 d799787e Matthew Grooms
98
		$pconfig['dns_server1'] = $a_csc[$id]['dns_server1'];
99
		$pconfig['dns_server2'] = $a_csc[$id]['dns_server2'];
100
		$pconfig['dns_server3'] = $a_csc[$id]['dns_server3'];
101
		$pconfig['dns_server4'] = $a_csc[$id]['dns_server4'];
102 b83e61e4 sbeaver
103 d799787e Matthew Grooms
		if ($pconfig['dns_server1'] ||
104 e38c75a8 Phil Davis
		    $pconfig['dns_server2'] ||
105
		    $pconfig['dns_server3'] ||
106
		    $pconfig['dns_server4']) {
107 d799787e Matthew Grooms
			$pconfig['dns_server_enable'] = true;
108 e38c75a8 Phil Davis
		}
109 d799787e Matthew Grooms
110
		$pconfig['ntp_server1'] = $a_csc[$id]['ntp_server1'];
111
		$pconfig['ntp_server2'] = $a_csc[$id]['ntp_server2'];
112 b83e61e4 sbeaver
113 d799787e Matthew Grooms
		if ($pconfig['ntp_server1'] ||
114 e38c75a8 Phil Davis
		    $pconfig['ntp_server2']) {
115 d799787e Matthew Grooms
			$pconfig['ntp_server_enable'] = true;
116 e38c75a8 Phil Davis
		}
117 d799787e Matthew Grooms
118
		$pconfig['netbios_enable'] = $a_csc[$id]['netbios_enable'];
119
		$pconfig['netbios_ntype'] = $a_csc[$id]['netbios_ntype'];
120
		$pconfig['netbios_scope'] = $a_csc[$id]['netbios_scope'];
121
122
		$pconfig['wins_server1'] = $a_csc[$id]['wins_server1'];
123
		$pconfig['wins_server2'] = $a_csc[$id]['wins_server2'];
124 b83e61e4 sbeaver
125 d799787e Matthew Grooms
		if ($pconfig['wins_server1'] ||
126 e38c75a8 Phil Davis
		    $pconfig['wins_server2']) {
127 d799787e Matthew Grooms
			$pconfig['wins_server_enable'] = true;
128 e38c75a8 Phil Davis
		}
129 d799787e Matthew Grooms
130
		$pconfig['nbdd_server1'] = $a_csc[$id]['nbdd_server1'];
131 e38c75a8 Phil Davis
		if ($pconfig['nbdd_server1']) {
132 d799787e Matthew Grooms
			$pconfig['nbdd_server_enable'] = true;
133 e38c75a8 Phil Davis
		}
134 d799787e Matthew Grooms
	}
135
}
136
137
if ($_POST) {
138
139
	unset($input_errors);
140
	$pconfig = $_POST;
141
142
	/* input validation */
143 e38c75a8 Phil Davis
	if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) {
144 d799787e Matthew Grooms
		$input_errors[] = $result;
145 e38c75a8 Phil Davis
	}
146 d799787e Matthew Grooms
147 e38c75a8 Phil Davis
	if ($result = openvpn_validate_cidr($pconfig['local_network'], 'IPv4 Local Network', true, "ipv4")) {
148 5c427ce7 jim-p
		$input_errors[] = $result;
149 e38c75a8 Phil Davis
	}
150 5c427ce7 jim-p
151 e38c75a8 Phil Davis
	if ($result = openvpn_validate_cidr($pconfig['local_networkv6'], 'IPv6 Local Network', true, "ipv6")) {
152 5c427ce7 jim-p
		$input_errors[] = $result;
153 e38c75a8 Phil Davis
	}
154 5c427ce7 jim-p
155 e38c75a8 Phil Davis
	if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4")) {
156 5c427ce7 jim-p
		$input_errors[] = $result;
157 e38c75a8 Phil Davis
	}
158 5c427ce7 jim-p
159 e38c75a8 Phil Davis
	if ($result = openvpn_validate_cidr($pconfig['remote_networkv6'], 'IPv6 Remote Network', true, "ipv6")) {
160 5c427ce7 jim-p
		$input_errors[] = $result;
161 e38c75a8 Phil Davis
	}
162 5c427ce7 jim-p
163 d799787e Matthew Grooms
	if ($pconfig['dns_server_enable']) {
164 e38c75a8 Phil Davis
		if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1']))) {
165 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'DNS Server #1' must contain a valid IP address");
166 e38c75a8 Phil Davis
		}
167
		if (!empty($pconfig['dns_server2']) && !is_ipaddr(trim($pconfig['dns_server2']))) {
168 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'DNS Server #2' must contain a valid IP address");
169 e38c75a8 Phil Davis
		}
170
		if (!empty($pconfig['dns_server3']) && !is_ipaddr(trim($pconfig['dns_server3']))) {
171 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'DNS Server #3' must contain a valid IP address");
172 e38c75a8 Phil Davis
		}
173
		if (!empty($pconfig['dns_server4']) && !is_ipaddr(trim($pconfig['dns_server4']))) {
174 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'DNS Server #4' must contain a valid IP address");
175 e38c75a8 Phil Davis
		}
176 d799787e Matthew Grooms
	}
177
178
	if ($pconfig['ntp_server_enable']) {
179 e38c75a8 Phil Davis
		if (!empty($pconfig['ntp_server1']) && !is_ipaddr(trim($pconfig['ntp_server1']))) {
180 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'NTP Server #1' must contain a valid IP address");
181 e38c75a8 Phil Davis
		}
182
		if (!empty($pconfig['ntp_server2']) && !is_ipaddr(trim($pconfig['ntp_server2']))) {
183 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'NTP Server #2' must contain a valid IP address");
184 e38c75a8 Phil Davis
		}
185
		if (!empty($pconfig['ntp_server3']) && !is_ipaddr(trim($pconfig['ntp_server3']))) {
186 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'NTP Server #3' must contain a valid IP address");
187 e38c75a8 Phil Davis
		}
188
		if (!empty($pconfig['ntp_server4']) && !is_ipaddr(trim($pconfig['ntp_server4']))) {
189 deeda874 Carlos Eduardo Ramos
			$input_errors[] = gettext("The field 'NTP Server #4' must contain a valid IP address");
190 e38c75a8 Phil Davis
		}
191 d799787e Matthew Grooms
	}
192
193
	if ($pconfig['netbios_enable']) {
194
		if ($pconfig['wins_server_enable']) {
195 e38c75a8 Phil Davis
			if (!empty($pconfig['wins_server1']) && !is_ipaddr(trim($pconfig['wins_server1']))) {
196 deeda874 Carlos Eduardo Ramos
				$input_errors[] = gettext("The field 'WINS Server #1' must contain a valid IP address");
197 e38c75a8 Phil Davis
			}
198
			if (!empty($pconfig['wins_server2']) && !is_ipaddr(trim($pconfig['wins_server2']))) {
199 deeda874 Carlos Eduardo Ramos
				$input_errors[] = gettext("The field 'WINS Server #2' must contain a valid IP address");
200 e38c75a8 Phil Davis
			}
201 d799787e Matthew Grooms
		}
202 b83e61e4 sbeaver
		if ($pconfig['nbdd_server_enable']) {
203 e38c75a8 Phil Davis
			if (!empty($pconfig['nbdd_server1']) && !is_ipaddr(trim($pconfig['nbdd_server1']))) {
204 deeda874 Carlos Eduardo Ramos
				$input_errors[] = gettext("The field 'NetBIOS Data Distribution Server #1' must contain a valid IP address");
205 e38c75a8 Phil Davis
			}
206 b83e61e4 sbeaver
		}
207 d799787e Matthew Grooms
	}
208
209 872d9195 Matthew Grooms
	$reqdfields[] = 'common_name';
210
	$reqdfieldsn[] = 'Common name';
211 d799787e Matthew Grooms
212 b83e61e4 sbeaver
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
213 d799787e Matthew Grooms
214
	if (!$input_errors) {
215
		$csc = array();
216
217 72d51890 Scott Ullrich
		$csc['custom_options'] = $pconfig['custom_options'];
218 e38c75a8 Phil Davis
		if ($_POST['disable'] == "yes") {
219 0c88fc1e jim-p
			$csc['disable'] = true;
220 e38c75a8 Phil Davis
		}
221 d799787e Matthew Grooms
		$csc['common_name'] = $pconfig['common_name'];
222
		$csc['block'] = $pconfig['block'];
223
		$csc['description'] = $pconfig['description'];
224
		$csc['tunnel_network'] = $pconfig['tunnel_network'];
225 5c427ce7 jim-p
		$csc['local_network'] = $pconfig['local_network'];
226
		$csc['local_networkv6'] = $pconfig['local_networkv6'];
227
		$csc['remote_network'] = $pconfig['remote_network'];
228
		$csc['remote_networkv6'] = $pconfig['remote_networkv6'];
229 d799787e Matthew Grooms
		$csc['gwredir'] = $pconfig['gwredir'];
230
		$csc['push_reset'] = $pconfig['push_reset'];
231
232 e38c75a8 Phil Davis
		if ($pconfig['dns_domain_enable']) {
233 d799787e Matthew Grooms
			$csc['dns_domain'] = $pconfig['dns_domain'];
234 e38c75a8 Phil Davis
		}
235 d799787e Matthew Grooms
236
		if ($pconfig['dns_server_enable']) {
237
			$csc['dns_server1'] = $pconfig['dns_server1'];
238
			$csc['dns_server2'] = $pconfig['dns_server2'];
239
			$csc['dns_server3'] = $pconfig['dns_server3'];
240
			$csc['dns_server4'] = $pconfig['dns_server4'];
241
		}
242
243
		if ($pconfig['ntp_server_enable']) {
244
			$csc['ntp_server1'] = $pconfig['ntp_server1'];
245
			$csc['ntp_server2'] = $pconfig['ntp_server2'];
246
		}
247
248
		$csc['netbios_enable'] = $pconfig['netbios_enable'];
249
		$csc['netbios_ntype'] = $pconfig['netbios_ntype'];
250
		$csc['netbios_scope'] = $pconfig['netbios_scope'];
251
252
		if ($pconfig['netbios_enable']) {
253
			if ($pconfig['wins_server_enable']) {
254
				$csc['wins_server1'] = $pconfig['wins_server1'];
255
				$csc['wins_server2'] = $pconfig['wins_server2'];
256
			}
257
258 e38c75a8 Phil Davis
			if ($pconfig['dns_server_enable']) {
259 d799787e Matthew Grooms
				$csc['nbdd_server1'] = $pconfig['nbdd_server1'];
260 e38c75a8 Phil Davis
			}
261 d799787e Matthew Grooms
		}
262 b83e61e4 sbeaver
263 de85521a jim-p
		if (isset($id) && $a_csc[$id]) {
264
			$old_csc_cn = $a_csc[$id]['common_name'];
265 d799787e Matthew Grooms
			$a_csc[$id] = $csc;
266 e38c75a8 Phil Davis
		} else {
267 d799787e Matthew Grooms
			$a_csc[] = $csc;
268 e38c75a8 Phil Davis
		}
269 d799787e Matthew Grooms
270 e38c75a8 Phil Davis
		if (!empty($old_csc_cn)) {
271 de85521a jim-p
			openvpn_cleanup_csc($old_csc_cn);
272 e38c75a8 Phil Davis
		}
273 dc408939 Matthew Grooms
		openvpn_resync_csc($csc);
274 d799787e Matthew Grooms
		write_config();
275 b83e61e4 sbeaver
276 d799787e Matthew Grooms
		header("Location: vpn_openvpn_csc.php");
277
		exit;
278
	}
279
}
280
281
include("head.inc");
282
283 b83e61e4 sbeaver
if ($input_errors)
284
	print_input_errors($input_errors);
285
286
if ($savemsg)
287
	print_info_box($savemsg, 'success');
288
289
$tab_array = array();
290
$tab_array[] = array(gettext("Server"), false, "vpn_openvpn_server.php");
291
$tab_array[] = array(gettext("Client"), false, "vpn_openvpn_client.php");
292
$tab_array[] = array(gettext("Client Specific Overrides"), true, "vpn_openvpn_csc.php");
293
$tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml");
294
add_package_tabs("OpenVPN", $tab_array);
295
display_top_tabs($tab_array);
296
297
if($act=="new" || $act=="edit"):
298
	require('classes/Form.class.php');
299
300
	$form = new Form();
301
302
	$section = new Form_Section('General Information');
303
304
	$section->addInput(new Form_Checkbox(
305
		'disable',
306
		'Disable',
307
		'Disable this override',
308
		$pconfig['disable']
309
	))->setHelp('Set this option to disable this client-specific override without removing it from the list.');
310
311
	$section->addInput(new Form_Input(
312
		'common_name',
313
		'Common name',
314
		'text',
315
		$pconfig['common_name']
316
	))->setHelp('Enter the client\'s X.509 common name.');
317
318
	$section->addInput(new Form_Input(
319
		'description',
320
		'Description',
321
		'text',
322
		$pconfig['description']
323
	))->setHelp('You may enter a description here for your reference (not parsed). ');
324
325
	$section->addInput(new Form_Checkbox(
326
		'block',
327
		'Connection blocking',
328
		'Block this client connection based on its common name. ',
329
		$pconfig['block']
330
	))->setHelp('Don\'t use this option to permanently disable a client due to a compromised key or password. Use a CRL (certificate revocation list) instead. ');
331
332
	$form->add($section);
333
334
	$section = new Form_Section('Tunnel settings');
335
336
	$section->addInput(new Form_Input(
337
		'tunnel_network',
338
		'Tunnel Network',
339
		'text',
340
		$pconfig['tunnel_network']
341
	))->setHelp('This is the virtual network used for private communications between this client and the server expressed using CIDR (eg. 10.0.8.0/24). ' .
342
				'The first network address is assumed to be the server address and the second network address will be assigned to the client virtual interface. ');
343
344
	$section->addInput(new Form_Input(
345
		'local_network',
346
		'IPv4 Local Network/s',
347
		'text',
348
		$pconfig['local_network']
349
	))->setHelp('These are the IPv4 networks that will be accessible from this particular client. Expressed as a comma-separated list of one or more CIDR ranges. ' . '<br />' .
350
				'NOTE: You do not need to specify networks here if they have already been defined on the main server configuration.');
351
352
	$section->addInput(new Form_Input(
353
		'local_networkv6',
354
		'IPv6 Local Network/s',
355
		'text',
356
		$pconfig['local_networkv6']
357
	))->setHelp('These are the IPv4 networks that will be accessible from this particular client. Expressed as a comma-separated list of one or more IP/PREFIX networks.' . '<br />' .
358
				'NOTE: You do not need to specify networks here if they have already been defined on the main server configuration.');
359
360
	$section->addInput(new Form_Input(
361
		'remote_network',
362
		'IPv4 Remote Network/s',
363
		'text',
364
		$pconfig['remote_network']
365
	))->setHelp('These are the IPv4 networks that will be routed to this client specifically using iroute, so that a site-to-site VPN can be established. ' .
366
				'Expressed as a comma-separated list of one or more CIDR ranges. You may leave this blank if there are no client-side networks to be routed.' . '<br />' .
367
				'NOTE: Remember to add these subnets to the IPv4 Remote Networks list on the corresponding OpenVPN server settings.');
368
369
	$section->addInput(new Form_Input(
370
		'remote_networkv6',
371
		'IPv6 Remote Network/s',
372
		'text',
373
		$pconfig['remote_networkv6']
374
	))->setHelp('These are the IPv4 networks that will be routed to this client specifically using iroute, so that a site-to-site VPN can be established. ' .
375
				'Expressed as a comma-separated list of one or more IP/PREFIX networks. You may leave this blank if there are no client-side networks to be routed.' . '<br />' .
376
				'NOTE: Remember to add these subnets to the IPv6 Remote Networks list on the corresponding OpenVPN server settings.');
377
378
	$section->addInput(new Form_Checkbox(
379
		'gwredir',
380
		'Redirect Gateway',
381
		'Force all client generated traffic through the tunnel.',
382
		$pconfig['gwredir']
383
	));
384
385
	$form->add($section);
386
387
	$section = new Form_Section('Client settings');
388
389
	// Default domain name
390
	$section->addInput(new Form_Checkbox(
391
		'push_reset',
392
		'Server Definitions',
393
		'Prevent this client from receiving any server-defined client settings. ',
394
		$pconfig['push_reset']
395
	));
396
397
	$section->addInput(new Form_Checkbox(
398
		'dns_domain_enable',
399
		'DNS Default Domain',
400
		'Provide a default domain name to clients',
401
		$pconfig['dns_domain_enable']
402
	))->toggles('.dnsdomain');
403
404
	$group = new Form_Group('DNS Domain');
405
	$group->addClass('dnsdomain');
406
407
	$group->add(new Form_Input(
408
		'dns_domain',
409
		'DNS Domain',
410
		'text',
411
		$pconfig['dns_domain']
412
	));
413
414
	$section->add($group);
415
416
	// DNS servers
417
	$section->addInput(new Form_Checkbox(
418
		'dns_server_enable',
419
		'DNS Servers',
420
		'Provide a DNS server list to clients',
421
		$pconfig['dns_server_enable']
422
	))->toggles('.dnsservers');
423
424
	$group = new Form_Group(null);
425
	$group->addClass('dnsservers');
426
427
	$group->add(new Form_Input(
428
		'dns_server1',
429
		null,
430
		'text',
431
		$pconfig['dns_server1']
432
	))->setHelp('Server 1');
433
434
	$group->add(new Form_Input(
435
		'dns_server2',
436
		null,
437
		'text',
438
		$pconfig['dns_server2']
439
	))->setHelp('Server 2');
440
441
	$group->add(new Form_Input(
442
		'dns_server3',
443
		null,
444
		'text',
445
		$pconfig['dns_server3']
446
	))->setHelp('Server 3');
447
448
	$group->add(new Form_Input(
449
		'dns_server4',
450
		null,
451
		'text',
452
		$pconfig['dns_server4']
453
	))->setHelp('Server 4');
454
455
	$section->add($group);
456
457
	// NTP servers
458
	$section->addInput(new Form_Checkbox(
459
		'ntp_server_enable',
460
		'NTP Servers',
461
		'Provide an NTP server list to clients',
462
		$pconfig['ntp_server_enable']
463
	))->toggles('.ntpservers');
464
465
	$group = new Form_Group(null);
466
	$group->addClass('ntpservers');
467
468
	$group->add(new Form_Input(
469
		'ntp_server1',
470
		null,
471
		'text',
472
		$pconfig['ntp_server1']
473
	))->setHelp('Server 1');
474
475
	$group->add(new Form_Input(
476
		'ntp_server2',
477
		null,
478
		'text',
479
		$pconfig['ntp_server2']
480
	))->setHelp('Server 2');
481
482
	$section->add($group);
483
484
	// NTP servers - For this section we need to use Javascript hiding since there
485
	// are nested toggles
486
	$section->addInput(new Form_Checkbox(
487
		'netbios_enable',
488
		'Netbios Option',
489
		'Enable Netbios over TCP/IP',
490
		$pconfig['netbios_enable']
491
	))->setHelp('If this option is not set, all NetBIOS-over-TCP/IP options (including WINS) will be disabled. ');
492
493
	$section->addInput(new Form_Select(
494
		'netbios_ntype',
495
		'Node Type',
496
		$pconfig['netbios_ntype'],
497
		$netbios_nodetypes
498
	))->setHelp('Possible options: b-node (broadcasts), p-node (point-to-point name queries to a WINS server), m-node (broadcast then query name server), ' .
499
				'and h-node (query name server, then broadcast). ');
500
501
	$section->addInput(new Form_Input(
502
		'netbios_scope',
503
		null,
504
		'text',
505
		$pconfig['netbios_scope']
506
	))->setHelp('A NetBIOS Scope ID provides an extended naming service for NetBIOS over TCP/IP. ' .
507
				'The NetBIOS scope ID isolates NetBIOS traffic on a single network to only those nodes with the same NetBIOS scope ID. ');
508
509
	$section->addInput(new Form_Checkbox(
510
		'wins_server_enable',
511
		'WINS servers',
512
		'Provide a WINS server list to clients',
513
		$pconfig['wins_server_enable']
514
	));
515
516
	$group = new Form_Group(null);
517
518
	$group->add(new Form_Input(
519
		'wins_server1',
520
		null,
521
		'text',
522
		$pconfig['wins_server1']
523
	))->setHelp('Server 1');
524
525
	$group->add(new Form_Input(
526
		'wins_server2',
527
		null,
528
		'text',
529
		$pconfig['wins_server2']
530
	))->setHelp('Server 2');
531
532
	$group->addClass('winsservers');
533
534
	$section->add($group);
535
536
	$section->addInput(new Form_TextArea(
537
		'custom_options',
538
		'Advanced',
539
		$pconfig['custom_options']
540
	))->setHelp('Enter any additional options you would like to add for this client specific override, separated by a semicolon. ' . '<br />' .
541
				'EXAMPLE: push "route 10.0.0.0 255.255.255.0"; ');
542
543
	// The hidden fields
544
	$section->addInput(new Form_Input(
545
		'act',
546
		null,
547
		'hidden',
548
		$act
549
	));
550 d799787e Matthew Grooms
551 b83e61e4 sbeaver
	if (isset($id) && $a_csc[$id]) {
552
		$section->addInput(new Form_Input(
553
			'id',
554
			null,
555
			'hidden',
556
			$id
557
		));
558
	}
559 d799787e Matthew Grooms
560 b83e61e4 sbeaver
	$form->add($section);
561
	print($form);
562 d799787e Matthew Grooms
563 b83e61e4 sbeaver
?>
564 d799787e Matthew Grooms
565 b83e61e4 sbeaver
<script>
566
//<![CDATA[
567
events.push(function(){
568
	var visible = false;
569
570
	// Hides the <div> in which the specified input element lives so that the input, its label and help text are hidden
571
	function hideInput(id, hide) {
572
		if(hide)
573
			$('#' + id).parent().parent('div').addClass('hidden');
574
		else
575
			$('#' + id).parent().parent('div').removeClass('hidden');
576
	}
577 d799787e Matthew Grooms
578 b83e61e4 sbeaver
	// Hides the <div> in which the specified checkbox lives so that the checkbox, its label and help text are hidden
579
	function hideCheckbox(id, hide) {
580
		if(hide)
581
			$('#' + id).parent().parent().parent('div').addClass('hidden');
582
		else
583
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
584
	}
585 d799787e Matthew Grooms
586 b83e61e4 sbeaver
	// Hides all elements of the specified class. This will usually be a section or group
587
	function hideClass(s_class, hide) {
588
		if(hide)
589
			$('.' + s_class).hide();
590
		else
591
			$('.' + s_class).show();
592
	}
593 d799787e Matthew Grooms
594 b83e61e4 sbeaver
	// Hide/show that section, but have to also respect the wins_server_enable checkbox
595
	function setNetbios() {
596
		if($('#netbios_enable').prop('checked')) {
597
			hideInput('netbios_ntype', false);
598
			hideInput('netbios_scope', false);
599
			hideCheckbox('wins_server_enable', false);
600
			setWins();
601
		} else {
602
			hideInput('netbios_ntype', true);
603
			hideInput('netbios_scope', true);
604
			hideCheckbox('wins_server_enable', true);
605
			hideClass('winsservers', true);
606
		}
607
	}
608 d799787e Matthew Grooms
609 b83e61e4 sbeaver
	function setWins() {
610
		hideClass('winsservers', ! $('#wins_server_enable').prop('checked'));
611
	}
612 d799787e Matthew Grooms
613 b83e61e4 sbeaver
	// On clicking the netbios_enable checkbox
614
	$('#netbios_enable').click(function () {
615
		setNetbios();
616
	});
617 d799787e Matthew Grooms
618 b83e61e4 sbeaver
	// On clicking the wins_server_enable checkbox
619
	$('#wins_server_enable').click(function () {
620
		setWins();
621
	});
622 d799787e Matthew Grooms
623 b83e61e4 sbeaver
	// On initial page load
624
	setNetbios();
625
});
626 1b244d38 Colin Fleming
//]]>
627 d799787e Matthew Grooms
</script>
628 b83e61e4 sbeaver
629 d799787e Matthew Grooms
<?php
630 b83e61e4 sbeaver
else :  // Not an 'add' or an 'edit'. Just the table of Override CSCs
631 d799787e Matthew Grooms
?>
632 b83e61e4 sbeaver
633
<div class="panel panel-default">
634 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('CSC Overrides')?></h2></div>
635 b83e61e4 sbeaver
	<div class="panel-body table-responsive">
636
		<table class="table table-striped table-hover table-condensed">
637
			<thead>
638 d799787e Matthew Grooms
				<tr>
639 b83e61e4 sbeaver
					<th><?=gettext("Disabled")?></th>
640
					<th><?=gettext("Common Name")?></th>
641
					<th><?=gettext("Description")?></th>
642
					<th> <!-- Buttons --></th>
643 d799787e Matthew Grooms
				</tr>
644 b83e61e4 sbeaver
			</thead>
645
			<tbody>
646
<?php
647
	$i = 0;
648
	foreach($a_csc as $csc):
649
		$disabled = isset($csc['disable']) ? "Yes":"No";
650
?>
651
				<tr>
652 d799787e Matthew Grooms
					<td class="listlr">
653 b83e61e4 sbeaver
						<?=$disabled?>
654 d799787e Matthew Grooms
					</td>
655
					<td class="listr">
656 b83e61e4 sbeaver
						<?=htmlspecialchars($csc['common_name'])?>
657 d799787e Matthew Grooms
					</td>
658 296a3cb6 Scott Ullrich
					<td class="listbg">
659 b83e61e4 sbeaver
						<?=htmlspecialchars($csc['description'])?>
660 d799787e Matthew Grooms
					</td>
661 b83e61e4 sbeaver
					<td>
662
						<a href="vpn_openvpn_csc.php?act=edit&amp;id=<?=$i?>" class="btn btn-info btn-xs"><?=gettext('Edit')?></a>
663
						<a href="vpn_openvpn_csc.php?act=del&amp;id=<?=$i?>" class="btn btn-danger btn-xs"><?=gettext('Delete')?></a>
664 d799787e Matthew Grooms
					</td>
665
				</tr>
666
<?php
667 b83e61e4 sbeaver
	   $i++;
668
	endforeach;
669
?>
670
			</tbody>
671
		</table>
672 d799787e Matthew Grooms
673 b83e61e4 sbeaver
		<nav class="action-buttons">
674
			<a href="vpn_openvpn_csc.php?act=new" class="btn btn-success btn-sm"><?=gettext('Add CSC')?></a>
675
		</nav>
676 d799787e Matthew Grooms
677 b83e61e4 sbeaver
	</div>
678
</div>
679 d799787e Matthew Grooms
680 b83e61e4 sbeaver
<?php
681
endif;
682
include("foot.inc");