Project

General

Profile

Download (20 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_advanced_firewall.php
5
	part of pfSense
6
	Copyright (C) 2005-2007 Scott Ullrich
7
	Copyright (C) 2008 Shrew Soft Inc
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9

    
10
	originally part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_MODULE:	system
37
*/
38

    
39
##|+PRIV
40
##|*IDENT=page-system-advanced-firewall
41
##|*NAME=System: Advanced: Firewall and NAT page
42
##|*DESCR=Allow access to the 'System: Advanced: Firewall and NAT' page.
43
##|*MATCH=system_advanced_firewall.php*
44
##|-PRIV
45

    
46
require("guiconfig.inc");
47
require_once("functions.inc");
48
require_once("filter.inc");
49
require_once("shaper.inc");
50

    
51
$pconfig['disablefilter'] = $config['system']['disablefilter'];
52
$pconfig['scrubnodf'] = $config['system']['scrubnodf'];
53
$pconfig['scrubrnid'] = $config['system']['scrubrnid'];
54
$pconfig['optimization'] = $config['filter']['optimization'];
55
$pconfig['adaptivestart'] = $config['system']['adaptivestart'];
56
$pconfig['adaptiveend'] = $config['system']['adaptiveend'];
57
$pconfig['maximumstates'] = $config['system']['maximumstates'];
58
$pconfig['aliasesresolveinterval'] = $config['system']['aliasesresolveinterval'];
59
$old_aliasesresolveinterval = $config['system']['aliasesresolveinterval'];
60
$pconfig['checkaliasesurlcert'] = isset($config['system']['checkaliasesurlcert']);
61
$pconfig['maximumtableentries'] = $config['system']['maximumtableentries'];
62
$pconfig['disablereplyto'] = isset($config['system']['disablereplyto']);
63
$pconfig['disablenegate'] = isset($config['system']['disablenegate']);
64
$pconfig['bogonsinterval'] = $config['system']['bogons']['interval'];
65
$pconfig['disablenatreflection'] = $config['system']['disablenatreflection'];
66
$pconfig['enablebinatreflection'] = $config['system']['enablebinatreflection'];
67
$pconfig['reflectiontimeout'] = $config['system']['reflectiontimeout'];
68
$pconfig['bypassstaticroutes'] = isset($config['filter']['bypassstaticroutes']);
69
$pconfig['disablescrub'] = isset($config['system']['disablescrub']);
70
$pconfig['tftpinterface'] = explode(",", $config['system']['tftpinterface']);
71
$pconfig['disablevpnrules'] = isset($config['system']['disablevpnrules']);
72

    
73
if ($_POST) {
74

    
75
	unset($input_errors);
76
	$pconfig = $_POST;
77

    
78
	/* input validation */
79
	if ((empty($_POST['adaptive-start']) && !empty($_POST['adaptive-end'])) || (!empty($_POST['adaptive-start']) && empty($_POST['adaptive-end'])))
80
		$input_errors[] = gettext("The Firewall Adaptive values must be set together.");
81
	if (!empty($_POST['adaptive-start']) && !is_numericint($_POST['adaptive-start'])) {
82
		$input_errors[] = gettext("The Firewall Adaptive Start value must be an integer.");
83
	}
84
	if (!empty($_POST['adaptive-end']) && !is_numericint($_POST['adaptive-end'])) {
85
		$input_errors[] = gettext("The Firewall Adaptive End value must be an integer.");
86
	}
87
	if ($_POST['firewall-maximum-states'] && !is_numericint($_POST['firewall-maximum-states'])) {
88
		$input_errors[] = gettext("The Firewall Maximum States value must be an integer.");
89
	}
90
	if ($_POST['aliases-hostnames-resolve-interval'] && !is_numericint($_POST['aliases-hostnames-resolve-interval'])) {
91
		$input_errors[] = gettext("The Aliases Hostname Resolve Interval value must be an integer.");
92
	}
93
	if ($_POST['firewall-maximum-table-entries'] && !is_numericint($_POST['firewall-maximum-table-entries'])) {
94
		$input_errors[] = gettext("The Firewall Maximum Table Entries value must be an integer.");
95
	}
96
	if ($_POST['reflection-timeout'] && !is_numericint($_POST['reflection-timeout'])) {
97
		$input_errors[] = gettext("The Reflection timeout must be an integer.");
98
	}
99

    
100
	ob_flush();
101
	flush();
102

    
103
	if (!$input_errors) {
104

    
105
		if($_POST['disable-firewall'] == "yes")
106
			$config['system']['disablefilter'] = "enabled";
107
		else
108
			unset($config['system']['disablefilter']);
109

    
110
		if($_POST['disable-auto-added-vpn-rules'] == "yes")
111
			$config['system']['disablevpnrules'] = true;
112
		else
113
			unset($config['system']['disablevpnrules']);
114

    
115
		if($_POST['ip-do-not-fragment-compatibility'] == "yes")
116
			$config['system']['scrubnodf'] = "enabled";
117
		else
118
			unset($config['system']['scrubnodf']);
119

    
120
		if($_POST['ip-random-id-generation'] == "yes")
121
			$config['system']['scrubrnid'] = "enabled";
122
		else
123
			unset($config['system']['scrubrnid']);
124

    
125
		if (!empty($_POST['adaptive-end']))
126
			$config['system']['adaptiveend'] = $_POST['adaptive-end'];
127
		else
128
			unset($config['system']['adaptiveend']);
129
		if (!empty($_POST['adaptive-start']))
130
			$config['system']['adaptivestart'] = $_POST['adaptive-start'];
131
		else
132
			unset($config['system']['adaptive-start']);
133

    
134
		if ($_POST['check-certificate-of-aliases-urls'] == "yes")
135
			$config['system']['checkaliasesurlcert'] = true;
136
		else
137
			unset($config['system']['checkaliasesurlcert']);
138

    
139
		$config['system']['optimization'] = $_POST['firewall-optimization-options'];
140
		$config['system']['maximumstates'] = $_POST['firewall-maximum-states'];
141
		$config['system']['aliasesresolveinterval'] = $_POST['aliases-hostnames-resolve-interval'];
142
		$config['system']['maximumtableentries'] = $_POST['firewall-maximum-table-entries'];
143

    
144
		if($_POST['nat-reflection-mode-for-port-forwards'] == "proxy") {
145
			unset($config['system']['disablenatreflection']);
146
			unset($config['system']['enablenatreflectionpurenat']);
147
		} else if($_POST['nat-reflection-mode-for-port-forwards'] == "purenat") {
148
			unset($config['system']['disablenatreflection']);
149
			$config['system']['enablenatreflectionpurenat'] = "yes";
150
		} else {
151
			$config['system']['disablenatreflection'] = "yes";
152
			unset($config['system']['enablenatreflectionpurenat']);
153
		}
154

    
155
		if($_POST['enable-nat-reflection-for-1-1-nat'] == "yes")
156
			$config['system']['enablebinatreflection'] = "yes";
157
		else
158
			unset($config['system']['enablebinatreflection']);
159

    
160
		if($_POST['disable-reply-to'] == "yes")
161
			$config['system']['disablereplyto'] = $_POST['disable-reply-to'];
162
		else
163
			unset($config['system']['disablereplyto']);
164

    
165
		if($_POST['disable-negate-rules'] == "yes")
166
			$config['system']['disablenegate'] = $_POST['disable-negate-rules'];
167
		else
168
			unset($config['system']['disablenegate']);
169

    
170
		if($_POST['enable-automatic-outbound-nat-for-reflection'] == "yes")
171
			$config['system']['enablenatreflectionhelper'] = "yes";
172
		else
173
			unset($config['system']['enablenatreflectionhelper']);
174

    
175
		$config['system']['reflectiontimeout'] = $_POST['reflection-timeout'];
176

    
177
		if($_POST['static-route-filtering'] == "yes")
178
			$config['filter']['bypassstaticroutes'] = $_POST['static-route-filtering'];
179
		elseif(isset($config['filter']['bypassstaticroutes']))
180
			unset($config['filter']['bypassstaticroutes']);
181

    
182
		if($_POST['disable-firewall-scrub'] == "yes")
183
			$config['system']['disablescrub'] = $_POST['disable-firewall-scrub'];
184
		else
185
			unset($config['system']['disablescrub']);
186

    
187
		if ($_POST['tftp-proxy'])
188
			$config['system']['tftpinterface'] = implode(",", $_POST['tftp-proxy']);
189
		else
190
			unset($config['system']['tftpinterface']);
191

    
192
		if ($_POST['update-frequency'] != $config['system']['bogons']['interval']) {
193
			switch ($_POST['update-frequency']) {
194
				case 'daily':
195
					install_cron_job("/usr/bin/nice -n20 /etc/rc.update_bogons.sh", true, "1", "3", "*", "*", "*");
196
					break;
197
				case 'weekly':
198
					install_cron_job("/usr/bin/nice -n20 /etc/rc.update_bogons.sh", true, "1", "3", "*", "*", "0");
199
					break;
200
				case 'monthly':
201
					// fall through
202
				default:
203
					install_cron_job("/usr/bin/nice -n20 /etc/rc.update_bogons.sh", true, "1", "3", "1", "*", "*");
204
			}
205
			$config['system']['bogons']['interval'] = $_POST['update-frequency'];
206
		}
207

    
208
		write_config();
209

    
210
		// Kill filterdns when value changes, filter_configure() will restart it
211
		if (($old_aliasesresolveinterval != $config['system']['aliasesresolveinterval']) &&
212
			isvalidpid("{$g['varrun_path']}/filterdns.pid"))
213
			killbypid("{$g['varrun_path']}/filterdns.pid");
214

    
215
		$retval = 0;
216
		$retval = filter_configure();
217
		if(stristr($retval, "error") <> true)
218
			$savemsg = get_std_save_message($retval);
219
		else
220
			$savemsg = $retval;
221
	}
222
}
223

    
224
$pgtitle = array(gettext("System"),gettext("Advanced: Firewall and NAT"));
225
include("head.inc");
226

    
227
if ($input_errors)
228
	print_input_errors($input_errors);
229
if ($savemsg)
230
	print_info_box($savemsg);
231

    
232
$tab_array = array();
233
$tab_array[] = array(gettext("Admin Access"), false, "system_advanced_admin.php");
234
$tab_array[] = array(gettext("Firewall / NAT"), true, "system_advanced_firewall.php");
235
$tab_array[] = array(gettext("Networking"), false, "system_advanced_network.php");
236
$tab_array[] = array(gettext("Miscellaneous"), false, "system_advanced_misc.php");
237
$tab_array[] = array(gettext("System Tunables"), false, "system_advanced_sysctl.php");
238
$tab_array[] = array(gettext("Notifications"), false, "system_advanced_notifications.php");
239
display_top_tabs($tab_array);
240

    
241
?><div id="container"><?php
242

    
243
require('classes/Form.class.php');
244
$form = new Form;
245
$section = new Form_Section('Firewall Advanced');
246

    
247
$section->addInput(new Form_Checkbox(
248
	'ip-do-not-fragment-compatibility',
249
	'IP Do-Not-Fragment compatibility',
250
	'Clear invalid DF bits instead of dropping the packets',
251
	isset($config['system']['scrubnodf'])
252
))->setHelp('This allows for communications with hosts that generate fragmented '.
253
	'packets with the don"t fragment (DF) bit set. Linux NFS is known to do this. '.
254
	'This will cause the filter to not drop such packets but instead clear the don"t '.
255
	'fragment bit.');
256

    
257
$section->addInput(new Form_Checkbox(
258
	'ip-random-id-generation',
259
	'IP Random id generation',
260
	'Insert a stronger id into IP header of packets passing through the filter.',
261
	isset($config['system']['scrubrnid'])
262
))->setHelp('Replaces the IP identification field of packets with random values to '.
263
	'compensate for operating systems that use predictable values. This option only '.
264
	'applies to packets that are not fragmented after the optional packet '.
265
	'reassembly.');
266

    
267
$section->addInput($input = new Form_Select(
268
	'firewall-optimization-options',
269
	'Firewall Optimization Options',
270
	$config['system']['optimization'],
271
	array(
272
		'normal' => 'normal: the default optimization algorithm',
273
		'high-latency' => 'high-latency: used for eg. satellite links. Expires idle connections later than default',
274
		'aggressive' => 'aggressive: expires idle connections quicker. More efficient use of CPU and memory but can drop legitimate idle connections',
275
		'conservative' => 'conservative: tries to avoid dropping any legitimate idle connections at the expense of increased memory usage and CPU utilization.',
276
	)
277
))->setHelp('Select the type of state table optimization to use');
278

    
279
$section->addInput(new Form_Checkbox(
280
	'disable-firewall',
281
	'Disable Firewall',
282
	'Disable all packet filtering.',
283
	isset($config['system']['disablefilter'])
284
))->setHelp('Note: This converts %s into a routing only platform!<br/>'.
285
	'Note: This will also turn off NAT! If you only want to disable NAT, '.
286
	'and not firewall rules, visit the <a href="firewall_nat_out.php">Outbound '.
287
	'NAT</a>page.', [$g["product_name"]]);
288

    
289
$section->addInput(new Form_Checkbox(
290
	'disable-firewall-scrub',
291
	'Disable Firewall Scrub',
292
	'Disables the PF scrubbing option which can sometimes interfere with NFS and PPTP traffic.',
293
	isset($config['system']['disablescrub'])
294
));
295

    
296
$group = new Form_Group('Firewall Adaptive Timeouts');
297

    
298
$group->add(new Form_Input(
299
	'adaptive-start',
300
	'Adaptive start',
301
	'number',
302
	$pconfig['adaptivestart'],
303
	['min' => 1]
304
))->setHelp('When the number of state entries exceeds this value, adaptive '.
305
	'scaling begins.  All timeout values are scaled linearly with factor '.
306
	'(adaptive.end - number of states) / (adaptive.end - adaptive.start).');
307

    
308
$group->add(new Form_Input(
309
	'adaptive-end',
310
	'Adaptive end',
311
	'number',
312
	$pconfig['adaptiveend'],
313
	['min' => 1]
314
))->setHelp('When reaching this number of state entries, all timeout values '.
315
	'become zero, effectively purging all state entries immediately.  This '.
316
	'value is used to define the scale factor, it should not actually be '.
317
	'reached (set a lower state limit, see below).');
318

    
319
$group->setHelp('Timeouts for states can be scaled adaptively as the number of '.
320
	'state table entries grows. Leave blank for the default (0)');
321

    
322
$section->add($group);
323

    
324
$section->addInput(new Form_Input(
325
	'firewall-maximum-states',
326
	'Firewall Maximum States',
327
	'number',
328
	$pconfig['maximumstates'],
329
	['min' => 1, 'placeholder' => pfsense_default_state_size()]
330
))->setHelp('Maximum number of connections to hold in the firewall state table.. '.
331
	'<br/>Note: Leave this blank for the default. On your system the default '.
332
	'size is: %d', [pfsense_default_state_size()]);
333

    
334
$section->addInput(new Form_Input(
335
	'firewall-maximum-table-entries',
336
	'Firewall Maximum Table Entries',
337
	'text',
338
	$pconfig['maximumtableentries'],
339
	['placeholder' => pfsense_default_table_entries_size()]
340
))->setHelp('Maximum number of table entries for systems such as aliases, '.
341
	'sshlockout, snort, etc, combined..<br/>Note: Leave this blank for the '.
342
	'default. On your system the default size is: %d',
343
	[pfsense_default_table_entries_size()]);
344

    
345
$section->addInput(new Form_Checkbox(
346
	'static-route-filtering',
347
	'Static route filtering',
348
	'Bypass firewall rules for traffic on the same interface',
349
	$pconfig['bypassstaticroutes']
350
))->setHelp('This option only applies if you have defined one or more static '.
351
	'routes. If it is enabled, traffic that enters and leaves through the same '.
352
	'interface will not be checked by the firewall. This may be desirable in some '.
353
	'situations where multiple subnets are connected to the same interface.');
354

    
355
$section->addInput(new Form_Checkbox(
356
	'disable-auto-added-vpn-rules',
357
	'Disable Auto-added VPN rules',
358
	'Disable all auto-added VPN rules.',
359
	isset($config['system']['disablevpnrules'])
360
))->setHelp('<span>Note: This disables automatically added rules for IPsec, '.
361
	'PPTP.</span>');
362

    
363
$section->addInput(new Form_Checkbox(
364
	'disable-reply-to',
365
	'Disable reply-to',
366
	'Disable reply-to on WAN rules',
367
	$pconfig['disablereplyto']
368
))->setHelp('With Multi-WAN you generally want to ensure traffic leaves the same '.
369
	'interface it arrives on, hence reply-to is added automatically by default. When '.
370
	'using bridging, you must disable this behavior if the WAN gateway IP is '.
371
	'different from the gateway IP of the hosts behind the bridged interface.');
372

    
373
$section->addInput(new Form_Checkbox(
374
	'disable-negate-rules',
375
	'Disable Negate rules',
376
	'Disable Negate rule on policy routing rules',
377
	$pconfig['disablenegate']
378
))->setHelp('With Multi-WAN you generally want to ensure traffic reaches directly '.
379
	'connected networks and VPN networks when using policy routing. You can disable '.
380
	'this for special purposes but it requires manually creating rules for these '.
381
	'networks');
382

    
383
$section->addInput(new Form_Input(
384
	'aliases-hostnames-resolve-interval',
385
	'Aliases Hostnames Resolve Interval',
386
	'text',
387
	$pconfig['aliasesresolveinterval'],
388
	['placeholder' => '300']
389
))->setHelp('Interval, in seconds, that will be used to resolve hostnames '.
390
	'configured on aliases.. <br/>Note:  Leave this blank for the default '.
391
	'(300s).');
392

    
393
$section->addInput(new Form_Checkbox(
394
	'check-certificate-of-aliases-urls',
395
	'Check certificate of aliases URLs',
396
	'Verify HTTPS certificates when downloading alias URLs',
397
	$pconfig['checkaliasesurlcert']
398
))->setHelp('Make sure the certificate is valid for all HTTPS addresses on '.
399
	'aliases. If it\'s not valid or is revoked, do not download it.');
400

    
401
$form->add($section);
402
$section = new Form_Section('Bogon Networks');
403

    
404
$section->addInput(new Form_Select(
405
	'update-frequency',
406
	'Update Frequency',
407
	empty($pconfig['bogonsinterval']) ? 'monthly' : $pconfig['bogonsinterval'],
408
	array(
409
		'monthly' => 'Monthly',
410
		'weekly' => 'Weekly',
411
		'daily' => 'Daily',
412
	)
413
))->setHelp('The frequency of updating the lists of IP addresses that are '.
414
	'reserved (but not RFC 1918) or not yet assigned by IANA.');
415

    
416
$form->add($section);
417

    
418
if (count($config['interfaces']) > 1)
419
{
420
	$section = new Form_Section('Network Address Translation');
421

    
422
	if (isset($config['system']['disablenatreflection']))
423
		$value = 'disable';
424
	elseif (!isset($config['system']['enablenatreflectionpurenat']))
425
		$value = 'proxy';
426
	else
427
		$value = 'purenat';
428

    
429
	$section->addInput(new Form_Select(
430
		'nat-reflection-mode-for-port-forwards',
431
		'NAT Reflection mode for port forwards',
432
		$value,
433
		array(
434
			'disable' => 'disabled',
435
			'proxy' => 'NAT + proxy',
436
			'purenat' => 'Pure NAT',
437
		)
438
	))->setHelp('<ul><li>The pure NAT mode uses a set of NAT rules to direct '.
439
		'packets to the target of the port forward. It has better scalability, '.
440
		'but it must be possible to accurately determine the interface and '.
441
		'gateway IP used for communication with the target at the time the '.
442
		'rules are loaded. There are no inherent limits to the number of ports '.
443
		'other than the limits of the protocols.  All protocols available for '.
444
		'port forwards are supported.</li><li>The NAT + proxy mode uses a '.
445
		'helper program to send packets to the target of the port forward. '.
446
		'It is useful in setups where the interface and/or gateway IP used '.
447
		'for communication with the target cannot be accurately determined at '.
448
		'the time the rules are loaded. Reflection rules are not created for '.
449
		'ranges larger than 500 ports and will not be used for more than 1000 '.
450
		'ports total between all port forwards. Only TCP and UDP protocols are '.
451
		'supported.</li></ul>Individual rules may be configured to override '.
452
		'this system setting on a per-rule basis.');
453

    
454
	$section->addInput(new Form_Input(
455
		'reflection-timeout',
456
		'Reflection Timeout',
457
		'number',
458
		$config['system']['reflectiontimeout'],
459
		['min' => 1]
460
	))->setHelp('Enter value for Reflection timeout in seconds.<br/>Note: Only '.
461
		'applies to Reflection on port forwards in NAT + proxy mode.');
462

    
463
	$section->addInput(new Form_Checkbox(
464
		'enable-nat-reflection-for-1-1-nat',
465
		'Enable NAT Reflection for 1:1 NAT',
466
		'Automatic creation of additional NAT redirect rules from within your internal networks.',
467
		isset($config['system']['enablebinatreflection'])
468
	))->setHelp('Note: Reflection on 1:1 mappings is only for the inbound component of '.
469
		'the 1:1 mappings. This functions the same as the pure NAT mode for port '.
470
		'forwards. For more details, refer to the pure NAT mode description '.
471
		'above. Individual rules may be configured to override this system setting on a '.
472
		'per-rule basis.');
473

    
474
	$section->addInput(new Form_Checkbox(
475
		'enable-automatic-outbound-nat-for-reflection',
476
		'Enable automatic outbound NAT for Reflection',
477
		'Automatic create outbound NAT rules that direct traffic back out to the same subnet it originated from.',
478
		isset($config['system']['enablenatreflectionhelper'])
479
	))->setHelp('Required for full functionality of the pure NAT mode of NAT '.
480
		'Reflection for port forwards or NAT Reflection for 1:1 NAT.Note: This only works '.
481
		'for assigned interfaces.  Other interfaces require manually creating the '.
482
		'outbound NAT rules that direct the reply packets back through the router.');
483

    
484
	$section->addInput(new Form_Select(
485
		'tftp-proxy',
486
		'TFTP Proxy',
487
		$pconfig['tftpinterface'],
488
		get_configured_interface_with_descr(),
489
		true
490
	))->setHelp('Choose the interfaces where you want TFTP proxy helper to be enabled.');
491

    
492
	$form->add($section);
493
}
494

    
495
print $form;
496
include("foot.inc");
(203-203/252)