1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
firewall_rules_edit.php
|
6
|
part of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
|
33
|
require("guiconfig.inc");
|
34
|
|
35
|
$specialsrcdst = explode(" ", "any lan pptp");
|
36
|
|
37
|
if (!is_array($config['filter']['rule'])) {
|
38
|
$config['filter']['rule'] = array();
|
39
|
}
|
40
|
filter_rules_sort();
|
41
|
$a_filter = &$config['filter']['rule'];
|
42
|
|
43
|
$id = $_GET['id'];
|
44
|
if (is_numeric($_POST['id']))
|
45
|
$id = $_POST['id'];
|
46
|
|
47
|
$after = $_GET['after'];
|
48
|
|
49
|
if (isset($_POST['after']))
|
50
|
$after = $_POST['after'];
|
51
|
|
52
|
if (isset($_GET['dup'])) {
|
53
|
$id = $_GET['dup'];
|
54
|
$after = $_GET['dup'];
|
55
|
}
|
56
|
|
57
|
if (isset($id) && $a_filter[$id]) {
|
58
|
$pconfig['interface'] = $a_filter[$id]['interface'];
|
59
|
|
60
|
if (!isset($a_filter[$id]['type']))
|
61
|
$pconfig['type'] = "pass";
|
62
|
else
|
63
|
$pconfig['type'] = $a_filter[$id]['type'];
|
64
|
|
65
|
if (isset($a_filter[$id]['protocol']))
|
66
|
$pconfig['proto'] = $a_filter[$id]['protocol'];
|
67
|
else
|
68
|
$pconfig['proto'] = "any";
|
69
|
|
70
|
if ($a_filter[$id]['protocol'] == "icmp")
|
71
|
$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
|
72
|
|
73
|
address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
|
74
|
$pconfig['srcmask'], $pconfig['srcnot'],
|
75
|
$pconfig['srcbeginport'], $pconfig['srcendport']);
|
76
|
|
77
|
if($a_filter[$id]['os'] <> "")
|
78
|
$pconfig['os'] = $a_filter[$id]['os'];
|
79
|
|
80
|
address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
|
81
|
$pconfig['dstmask'], $pconfig['dstnot'],
|
82
|
$pconfig['dstbeginport'], $pconfig['dstendport']);
|
83
|
|
84
|
$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
|
85
|
$pconfig['log'] = isset($a_filter[$id]['log']);
|
86
|
$pconfig['descr'] = $a_filter[$id]['descr'];
|
87
|
|
88
|
/* advanced */
|
89
|
$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
|
90
|
$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
|
91
|
$pconfig['statetype'] = $a_filter[$id]['statetype'];
|
92
|
$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
|
93
|
|
94
|
/* advanced - new connection per second banning*/
|
95
|
$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
|
96
|
$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
|
97
|
|
98
|
/* Multi-WAN next-hop support */
|
99
|
$pconfig['gateway'] = $a_filter[$id]['gateway'];
|
100
|
|
101
|
} else {
|
102
|
/* defaults */
|
103
|
if ($_GET['if'])
|
104
|
$pconfig['interface'] = $_GET['if'];
|
105
|
$pconfig['type'] = "pass";
|
106
|
$pconfig['src'] = "any";
|
107
|
$pconfig['dst'] = "any";
|
108
|
}
|
109
|
|
110
|
if (isset($_GET['dup']))
|
111
|
unset($id);
|
112
|
|
113
|
if ($_POST) {
|
114
|
|
115
|
if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
|
116
|
$_POST['srcbeginport'] = 0;
|
117
|
$_POST['srcendport'] = 0;
|
118
|
$_POST['dstbeginport'] = 0;
|
119
|
$_POST['dstendport'] = 0;
|
120
|
} else {
|
121
|
|
122
|
if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
|
123
|
$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
|
124
|
if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
|
125
|
$_POST['srcendport'] = $_POST['srcendport_cust'];
|
126
|
|
127
|
if ($_POST['srcbeginport'] == "any") {
|
128
|
$_POST['srcbeginport'] = 0;
|
129
|
$_POST['srcendport'] = 0;
|
130
|
} else {
|
131
|
if (!$_POST['srcendport'])
|
132
|
$_POST['srcendport'] = $_POST['srcbeginport'];
|
133
|
}
|
134
|
if ($_POST['srcendport'] == "any")
|
135
|
$_POST['srcendport'] = $_POST['srcbeginport'];
|
136
|
|
137
|
if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
|
138
|
$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
|
139
|
if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
|
140
|
$_POST['dstendport'] = $_POST['dstendport_cust'];
|
141
|
|
142
|
if ($_POST['dstbeginport'] == "any") {
|
143
|
$_POST['dstbeginport'] = 0;
|
144
|
$_POST['dstendport'] = 0;
|
145
|
} else {
|
146
|
if (!$_POST['dstendport'])
|
147
|
$_POST['dstendport'] = $_POST['dstbeginport'];
|
148
|
}
|
149
|
if ($_POST['dstendport'] == "any")
|
150
|
$_POST['dstendport'] = $_POST['dstbeginport'];
|
151
|
}
|
152
|
|
153
|
if (is_specialnet($_POST['srctype'])) {
|
154
|
$_POST['src'] = $_POST['srctype'];
|
155
|
$_POST['srcmask'] = 0;
|
156
|
} else if ($_POST['srctype'] == "single") {
|
157
|
$_POST['srcmask'] = 32;
|
158
|
}
|
159
|
if (is_specialnet($_POST['dsttype'])) {
|
160
|
$_POST['dst'] = $_POST['dsttype'];
|
161
|
$_POST['dstmask'] = 0;
|
162
|
} else if ($_POST['dsttype'] == "single") {
|
163
|
$_POST['dstmask'] = 32;
|
164
|
}
|
165
|
|
166
|
unset($input_errors);
|
167
|
$pconfig = $_POST;
|
168
|
|
169
|
/* input validation */
|
170
|
$reqdfields = explode(" ", "type interface proto src dst");
|
171
|
$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
|
172
|
|
173
|
|
174
|
if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state")
|
175
|
if( $_POST['proto'] != "tcp" )
|
176
|
$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
|
177
|
|
178
|
|
179
|
if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
|
180
|
$reqdfields[] = "srcmask";
|
181
|
$reqdfieldsn[] = "Source bit count";
|
182
|
}
|
183
|
if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
|
184
|
$reqdfields[] = "dstmask";
|
185
|
$reqdfieldsn[] = "Destination bit count";
|
186
|
}
|
187
|
|
188
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
189
|
|
190
|
if (!$_POST['srcbeginport']) {
|
191
|
$_POST['srcbeginport'] = 0;
|
192
|
$_POST['srcendport'] = 0;
|
193
|
}
|
194
|
if (!$_POST['dstbeginport']) {
|
195
|
$_POST['dstbeginport'] = 0;
|
196
|
$_POST['dstendport'] = 0;
|
197
|
}
|
198
|
|
199
|
if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
|
200
|
$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
|
201
|
}
|
202
|
if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
|
203
|
$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
|
204
|
}
|
205
|
if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
|
206
|
$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
|
207
|
}
|
208
|
if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
|
209
|
$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
|
210
|
}
|
211
|
|
212
|
if (!is_specialnet($_POST['srctype'])) {
|
213
|
if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
|
214
|
$input_errors[] = "A valid source IP address or alias must be specified.";
|
215
|
}
|
216
|
if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
|
217
|
$input_errors[] = "A valid source bit count must be specified.";
|
218
|
}
|
219
|
}
|
220
|
if (!is_specialnet($_POST['dsttype'])) {
|
221
|
if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
|
222
|
$input_errors[] = "A valid destination IP address or alias must be specified.";
|
223
|
}
|
224
|
if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
|
225
|
$input_errors[] = "A valid destination bit count must be specified.";
|
226
|
}
|
227
|
}
|
228
|
|
229
|
if ($_POST['srcbeginport'] > $_POST['srcendport']) {
|
230
|
/* swap */
|
231
|
$tmp = $_POST['srcendport'];
|
232
|
$_POST['srcendport'] = $_POST['srcbeginport'];
|
233
|
$_POST['srcbeginport'] = $tmp;
|
234
|
}
|
235
|
if ($_POST['dstbeginport'] > $_POST['dstendport']) {
|
236
|
/* swap */
|
237
|
$tmp = $_POST['dstendport'];
|
238
|
$_POST['dstendport'] = $_POST['dstbeginport'];
|
239
|
$_POST['dstbeginport'] = $tmp;
|
240
|
}
|
241
|
if ($_POST['os'])
|
242
|
if( $_POST['proto'] != "tcp" )
|
243
|
$input_errors[] = "OS detection is only valid with protocol tcp.";
|
244
|
|
245
|
if (!$input_errors) {
|
246
|
$filterent = array();
|
247
|
$filterent['type'] = $_POST['type'];
|
248
|
$filterent['interface'] = $_POST['interface'];
|
249
|
|
250
|
/* Advanced options */
|
251
|
$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
|
252
|
$filterent['max-src-states'] = $_POST['max-src-states'];
|
253
|
$filterent['statetimeout'] = $_POST['statetimeout'];
|
254
|
$filterent['statetype'] = $_POST['statetype'];
|
255
|
$filterent['os'] = $_POST['os'];
|
256
|
$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
|
257
|
$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
|
258
|
|
259
|
if ($_POST['proto'] != "any")
|
260
|
$filterent['protocol'] = $_POST['proto'];
|
261
|
else
|
262
|
unset($filterent['protocol']);
|
263
|
|
264
|
if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
|
265
|
$filterent['icmptype'] = $_POST['icmptype'];
|
266
|
else
|
267
|
unset($filterent['icmptype']);
|
268
|
|
269
|
pconfig_to_address($filterent['source'], $_POST['src'],
|
270
|
$_POST['srcmask'], $_POST['srcnot'],
|
271
|
$_POST['srcbeginport'], $_POST['srcendport']);
|
272
|
|
273
|
pconfig_to_address($filterent['destination'], $_POST['dst'],
|
274
|
$_POST['dstmask'], $_POST['dstnot'],
|
275
|
$_POST['dstbeginport'], $_POST['dstendport']);
|
276
|
|
277
|
if ($_POST['disabled'])
|
278
|
$filterent['disabled'] = true;
|
279
|
else
|
280
|
unset($filterent['disabled']);
|
281
|
if ($_POST['log'])
|
282
|
$filterent['log'] = true;
|
283
|
else
|
284
|
unset($filterent['log']);
|
285
|
strncpy($filterent['descr'], $_POST['descr'], 52);
|
286
|
|
287
|
if ($_POST['gateway'] != "") {
|
288
|
$filterent['gateway'] = $_POST['gateway'];
|
289
|
}
|
290
|
|
291
|
if (isset($id) && $a_filter[$id])
|
292
|
$a_filter[$id] = $filterent;
|
293
|
else {
|
294
|
if (is_numeric($after))
|
295
|
array_splice($a_filter, $after+1, 0, array($filterent));
|
296
|
else
|
297
|
$a_filter[] = $filterent;
|
298
|
}
|
299
|
|
300
|
write_config();
|
301
|
touch($d_filterconfdirty_path);
|
302
|
|
303
|
header("Location: firewall_rules.php?if=" . $_POST['interface']);
|
304
|
exit;
|
305
|
}
|
306
|
}
|
307
|
|
308
|
$pgtitle = "Firewall: Rules: Edit";
|
309
|
$closehead = false;
|
310
|
include("head.inc");
|
311
|
|
312
|
?>
|
313
|
|
314
|
<script language="JavaScript">
|
315
|
<!--
|
316
|
var portsenabled = 1;
|
317
|
|
318
|
function ext_change() {
|
319
|
if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
|
320
|
document.iform.srcbeginport_cust.disabled = 0;
|
321
|
} else {
|
322
|
document.iform.srcbeginport_cust.value = "";
|
323
|
document.iform.srcbeginport_cust.disabled = 1;
|
324
|
}
|
325
|
if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
|
326
|
document.iform.srcendport_cust.disabled = 0;
|
327
|
} else {
|
328
|
document.iform.srcendport_cust.value = "";
|
329
|
document.iform.srcendport_cust.disabled = 1;
|
330
|
}
|
331
|
if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
|
332
|
document.iform.dstbeginport_cust.disabled = 0;
|
333
|
} else {
|
334
|
document.iform.dstbeginport_cust.value = "";
|
335
|
document.iform.dstbeginport_cust.disabled = 1;
|
336
|
}
|
337
|
if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
|
338
|
document.iform.dstendport_cust.disabled = 0;
|
339
|
} else {
|
340
|
document.iform.dstendport_cust.value = "";
|
341
|
document.iform.dstendport_cust.disabled = 1;
|
342
|
}
|
343
|
|
344
|
if (!portsenabled) {
|
345
|
document.iform.srcbeginport.disabled = 1;
|
346
|
document.iform.srcendport.disabled = 1;
|
347
|
document.iform.dstbeginport.disabled = 1;
|
348
|
document.iform.dstendport.disabled = 1;
|
349
|
} else {
|
350
|
document.iform.srcbeginport.disabled = 0;
|
351
|
document.iform.srcendport.disabled = 0;
|
352
|
document.iform.dstbeginport.disabled = 0;
|
353
|
document.iform.dstendport.disabled = 0;
|
354
|
}
|
355
|
}
|
356
|
|
357
|
function typesel_change() {
|
358
|
switch (document.iform.srctype.selectedIndex) {
|
359
|
case 1: /* single */
|
360
|
document.iform.src.disabled = 0;
|
361
|
document.iform.srcmask.value = "";
|
362
|
document.iform.srcmask.disabled = 1;
|
363
|
break;
|
364
|
case 2: /* network */
|
365
|
document.iform.src.disabled = 0;
|
366
|
document.iform.srcmask.disabled = 0;
|
367
|
break;
|
368
|
default:
|
369
|
document.iform.src.value = "";
|
370
|
document.iform.src.disabled = 1;
|
371
|
document.iform.srcmask.value = "";
|
372
|
document.iform.srcmask.disabled = 1;
|
373
|
break;
|
374
|
}
|
375
|
switch (document.iform.dsttype.selectedIndex) {
|
376
|
case 1: /* single */
|
377
|
document.iform.dst.disabled = 0;
|
378
|
document.iform.dstmask.value = "";
|
379
|
document.iform.dstmask.disabled = 1;
|
380
|
break;
|
381
|
case 2: /* network */
|
382
|
document.iform.dst.disabled = 0;
|
383
|
document.iform.dstmask.disabled = 0;
|
384
|
break;
|
385
|
default:
|
386
|
document.iform.dst.value = "";
|
387
|
document.iform.dst.disabled = 1;
|
388
|
document.iform.dstmask.value = "";
|
389
|
document.iform.dstmask.disabled = 1;
|
390
|
break;
|
391
|
}
|
392
|
}
|
393
|
|
394
|
function proto_change() {
|
395
|
if (document.iform.proto.selectedIndex < 3) {
|
396
|
portsenabled = 1;
|
397
|
} else {
|
398
|
portsenabled = 0;
|
399
|
}
|
400
|
|
401
|
/* Disable OS knob if the proto is not TCP. */
|
402
|
if (document.iform.proto.selectedIndex < 1) {
|
403
|
document.forms[0].os.disabled = 0;
|
404
|
} else {
|
405
|
document.forms[0].os.disabled = 1;
|
406
|
}
|
407
|
|
408
|
if (document.iform.proto.selectedIndex == 3) {
|
409
|
document.iform.icmptype.disabled = 0;
|
410
|
} else {
|
411
|
document.iform.icmptype.disabled = 1;
|
412
|
}
|
413
|
|
414
|
ext_change();
|
415
|
}
|
416
|
|
417
|
function src_rep_change() {
|
418
|
document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
|
419
|
}
|
420
|
function dst_rep_change() {
|
421
|
document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
|
422
|
}
|
423
|
//-->
|
424
|
</script>
|
425
|
</head>
|
426
|
|
427
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
428
|
<?php include("fbegin.inc"); ?>
|
429
|
<p class="pgtitle"><?=$pgtitle?></p>
|
430
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
431
|
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
|
432
|
<?display_topbar()?>
|
433
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
434
|
<tr>
|
435
|
<td width="22%" valign="top" class="vncellreq">Action</td>
|
436
|
<td width="78%" class="vtable">
|
437
|
<select name="type" class="formfld">
|
438
|
<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
|
439
|
<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
|
440
|
<?=htmlspecialchars($type);?>
|
441
|
</option>
|
442
|
<?php endforeach; ?>
|
443
|
</select> <br>
|
444
|
<span class="vexpl">Choose what to do with packets that match
|
445
|
the criteria specified below.<br>
|
446
|
Hint: the difference between block and reject is that with reject, a packet (TCP RST or ICMP port unreachable for UDP) is returned to the sender, whereas with block the packet is dropped silently. In either case, the original packet is discarded. Reject only works when the protocol is set to either TCP or UDP (but not "TCP/UDP") below.</span></td>
|
447
|
</tr>
|
448
|
<tr>
|
449
|
<td width="22%" valign="top" class="vncellreq">Disabled</td>
|
450
|
<td width="78%" class="vtable">
|
451
|
<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
|
452
|
<strong>Disable this rule</strong><br>
|
453
|
<span class="vexpl">Set this option to disable this rule without
|
454
|
removing it from the list.</span></td>
|
455
|
</tr>
|
456
|
<tr>
|
457
|
<td width="22%" valign="top" class="vncellreq">Interface</td>
|
458
|
<td width="78%" class="vtable">
|
459
|
<select name="interface" class="formfld">
|
460
|
<?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN', 'pptp' => 'PPTP');
|
461
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
462
|
$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
|
463
|
}
|
464
|
foreach ($interfaces as $iface => $ifacename): ?>
|
465
|
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
|
466
|
<?=htmlspecialchars($ifacename);?>
|
467
|
</option>
|
468
|
<?php endforeach; ?>
|
469
|
</select> <br>
|
470
|
<span class="vexpl">Choose on which interface packets must
|
471
|
come in to match this rule.</span></td>
|
472
|
</tr>
|
473
|
<tr>
|
474
|
<td width="22%" valign="top" class="vncellreq">Protocol</td>
|
475
|
<td width="78%" class="vtable">
|
476
|
<select name="proto" class="formfld" onchange="proto_change()">
|
477
|
<?php $protocols = explode(" ", "TCP UDP TCP/UDP ICMP ICMP6 ESP AH GRE IPv6 IGMP any carp pfsync"); foreach ($protocols as $proto): ?>
|
478
|
<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
|
479
|
<?=htmlspecialchars($proto);?>
|
480
|
</option>
|
481
|
<?php endforeach; ?>
|
482
|
</select> <br>
|
483
|
<span class="vexpl">Choose which IP protocol this rule should
|
484
|
match.<br>
|
485
|
Hint: in most cases, you should specify <em>TCP</em> here.</span></td>
|
486
|
</tr>
|
487
|
<tr>
|
488
|
<td valign="top" class="vncell">ICMP type</td>
|
489
|
<td class="vtable">
|
490
|
<select name="icmptype" class="formfld">
|
491
|
<?php
|
492
|
|
493
|
$icmptypes = array(
|
494
|
"" => "any",
|
495
|
"echorep" => "Echo reply",
|
496
|
"unreach" => "Destination unreachable",
|
497
|
"squench" => "Source quench",
|
498
|
"redir" => "Redirect",
|
499
|
"althost" => "Alternate Host",
|
500
|
"echoreq" => "Echo",
|
501
|
"routeradv" => "Router advertisement",
|
502
|
"routersol" => "Router solicitation",
|
503
|
"timex" => "Time exceeded",
|
504
|
"paramprob" => "Invalid IP header",
|
505
|
"timereq" => "Timestamp",
|
506
|
"timerep" => "Timestamp reply",
|
507
|
"inforeq" => "Information request",
|
508
|
"inforep" => "Information reply",
|
509
|
"maskreq" => "Address mask request",
|
510
|
"maskrep" => "Address mask reply"
|
511
|
);
|
512
|
|
513
|
foreach ($icmptypes as $icmptype => $descr): ?>
|
514
|
<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>>
|
515
|
<?=htmlspecialchars($descr);?>
|
516
|
</option>
|
517
|
<?php endforeach; ?>
|
518
|
</select>
|
519
|
<br>
|
520
|
<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td>
|
521
|
</tr>
|
522
|
<tr>
|
523
|
<td width="22%" valign="top" class="vncellreq">Source</td>
|
524
|
<td width="78%" class="vtable">
|
525
|
<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
|
526
|
<strong>not</strong><br>
|
527
|
Use this option to invert the sense of the match.<br>
|
528
|
<br>
|
529
|
<table border="0" cellspacing="0" cellpadding="0">
|
530
|
<tr>
|
531
|
<td>Type: </td>
|
532
|
<td><select name="srctype" class="formfld" onChange="typesel_change()">
|
533
|
<?php $sel = is_specialnet($pconfig['src']); ?>
|
534
|
<option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
|
535
|
any</option>
|
536
|
<option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
|
537
|
Single host or alias</option>
|
538
|
<option value="network" <?php if (!$sel) echo "selected"; ?>>
|
539
|
Network</option>
|
540
|
<option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
|
541
|
LAN subnet</option>
|
542
|
<option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
|
543
|
PPTP clients</option>
|
544
|
<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
|
545
|
<option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
|
546
|
<?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
|
547
|
<?php endfor; ?>
|
548
|
</select></td>
|
549
|
</tr>
|
550
|
<tr>
|
551
|
<td>Address: </td>
|
552
|
<td><input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this)' onkeyup='actb_tocomplete(this,event,addressarray);' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>">
|
553
|
/
|
554
|
<select name="srcmask" class="formfld" id="srcmask">
|
555
|
<?php for ($i = 31; $i > 0; $i--): ?>
|
556
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
|
557
|
<?php endfor; ?>
|
558
|
</select>
|
559
|
</td>
|
560
|
</tr>
|
561
|
</table></td>
|
562
|
</tr>
|
563
|
<tr>
|
564
|
<td width="22%" valign="top" class="vncellreq">Source port range
|
565
|
</td>
|
566
|
<td width="78%" class="vtable">
|
567
|
<table border="0" cellspacing="0" cellpadding="0">
|
568
|
<tr>
|
569
|
<td>from: </td>
|
570
|
<td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
|
571
|
<option value="">(other)</option>
|
572
|
<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
|
573
|
<?php foreach ($wkports as $wkport => $wkportdesc): ?>
|
574
|
<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
|
575
|
echo "selected";
|
576
|
$bfound = 1;
|
577
|
}?>>
|
578
|
<?=htmlspecialchars($wkportdesc);?>
|
579
|
</option>
|
580
|
<?php endforeach; ?>
|
581
|
</select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>"></td>
|
582
|
</tr>
|
583
|
<tr>
|
584
|
<td>to:</td>
|
585
|
<td><select name="srcendport" class="formfld" onchange="ext_change()">
|
586
|
<option value="">(other)</option>
|
587
|
<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
|
588
|
<?php foreach ($wkports as $wkport => $wkportdesc): ?>
|
589
|
<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
|
590
|
echo "selected";
|
591
|
$bfound = 1;
|
592
|
}?>>
|
593
|
<?=htmlspecialchars($wkportdesc);?>
|
594
|
</option>
|
595
|
<?php endforeach; ?>
|
596
|
</select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>"></td>
|
597
|
</tr>
|
598
|
</table>
|
599
|
<br>
|
600
|
<span class="vexpl">Specify the port or port range for
|
601
|
the source of the packet for this rule. This is usually not equal to the destination port range (and is often "any"). <br>
|
602
|
Hint: you can leave the <em>'to'</em> field empty if you only
|
603
|
want to filter a single port</span></td>
|
604
|
|
605
|
<tr>
|
606
|
<td width="22%" valign="top" class="vncellreq">Source OS</td>
|
607
|
<td width="78%" class="vtable">OS Type:
|
608
|
<select name="os" id="os" class="formfld">
|
609
|
<?php
|
610
|
$ostypes = array(
|
611
|
"" => "any",
|
612
|
"AIX" => "AIX",
|
613
|
"Linux" => "Linux",
|
614
|
"FreeBSD" => "FreeBSD",
|
615
|
"NetBSD" => "NetBSD",
|
616
|
"OpenBSD" => "OpenBSD",
|
617
|
"Solaris" => "Solaris",
|
618
|
"MacOS" => "MacOS",
|
619
|
"Windows" => "Windows",
|
620
|
"Novell" => "Novell"
|
621
|
);
|
622
|
|
623
|
foreach ($ostypes as $ostype => $descr): ?>
|
624
|
<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>>
|
625
|
<?=htmlspecialchars($descr);?>
|
626
|
</option>
|
627
|
<?php endforeach; ?>
|
628
|
</select><br>
|
629
|
Note: this only works for TCP rules</td>
|
630
|
</tr>
|
631
|
<tr>
|
632
|
<td width="22%" valign="top" class="vncellreq">Destination</td>
|
633
|
<td width="78%" class="vtable">
|
634
|
<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
|
635
|
<strong>not</strong><br>
|
636
|
Use this option to invert the sense of the match.<br>
|
637
|
<br>
|
638
|
<table border="0" cellspacing="0" cellpadding="0">
|
639
|
<tr>
|
640
|
<td>Type: </td>
|
641
|
<td><select name="dsttype" class="formfld" onChange="typesel_change()">
|
642
|
<?php $sel = is_specialnet($pconfig['dst']); ?>
|
643
|
<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
|
644
|
any</option>
|
645
|
<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
|
646
|
Single host or alias</option>
|
647
|
<option value="network" <?php if (!$sel) echo "selected"; ?>>
|
648
|
Network</option>
|
649
|
<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
|
650
|
LAN subnet</option>
|
651
|
<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
|
652
|
PPTP clients</option>
|
653
|
<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
|
654
|
<option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
|
655
|
<?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
|
656
|
<?php endfor; ?>
|
657
|
</select></td>
|
658
|
</tr>
|
659
|
<tr>
|
660
|
<td>Address: </td>
|
661
|
<td><input name="dst" autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' onkeyup='actb_tocomplete(this,event,addressarray)' type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
|
662
|
/
|
663
|
<select name="dstmask" class="formfld" id="dstmask">
|
664
|
<?php for ($i = 31; $i > 0; $i--): ?>
|
665
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
|
666
|
<?php endfor; ?>
|
667
|
</select></td>
|
668
|
</tr>
|
669
|
</table></td>
|
670
|
</tr>
|
671
|
<tr>
|
672
|
<td width="22%" valign="top" class="vncellreq">Destination port
|
673
|
range </td>
|
674
|
<td width="78%" class="vtable">
|
675
|
<table border="0" cellspacing="0" cellpadding="0">
|
676
|
<tr>
|
677
|
<td>from: </td>
|
678
|
<td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
|
679
|
<option value="">(other)</option>
|
680
|
<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
|
681
|
<?php foreach ($wkports as $wkport => $wkportdesc): ?>
|
682
|
<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
|
683
|
echo "selected";
|
684
|
$bfound = 1;
|
685
|
}?>>
|
686
|
<?=htmlspecialchars($wkportdesc);?>
|
687
|
</option>
|
688
|
<?php endforeach; ?>
|
689
|
</select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td>
|
690
|
</tr>
|
691
|
<tr>
|
692
|
<td>to:</td>
|
693
|
<td><select name="dstendport" class="formfld" onchange="ext_change()">
|
694
|
<option value="">(other)</option>
|
695
|
<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
|
696
|
<?php foreach ($wkports as $wkport => $wkportdesc): ?>
|
697
|
<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
|
698
|
echo "selected";
|
699
|
$bfound = 1;
|
700
|
}?>>
|
701
|
<?=htmlspecialchars($wkportdesc);?>
|
702
|
</option>
|
703
|
<?php endforeach; ?>
|
704
|
</select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>"></td>
|
705
|
</tr>
|
706
|
</table>
|
707
|
<br> <span class="vexpl">Specify the port or port range for
|
708
|
the destination of the packet for this rule.<br>
|
709
|
Hint: you can leave the <em>'to'</em> field empty if you only
|
710
|
want to filter a single port</span></td>
|
711
|
</tr>
|
712
|
<tr>
|
713
|
<td width="22%" valign="top" class="vncellreq">Log</td>
|
714
|
<td width="78%" class="vtable">
|
715
|
<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
|
716
|
<strong>Log packets that are handled by this rule</strong><br>
|
717
|
<span class="vexpl">Hint: the firewall has limited local log
|
718
|
space. Don't turn on logging for everything. If you want to
|
719
|
do a lot of logging, consider using a remote syslog server
|
720
|
(see the <a href="diag_logs_settings.php">Diagnostics: System
|
721
|
logs: Settings</a> page).</span></td>
|
722
|
</tr>
|
723
|
<tr>
|
724
|
<td width="22%" valign="top" class="vncell">Description</td>
|
725
|
<td width="78%" class="vtable">
|
726
|
<input name="descr" type="text" class="formfld" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
727
|
<br> <span class="vexpl">You may enter a description here
|
728
|
for your reference (not parsed).</span></td>
|
729
|
</tr>
|
730
|
<tr>
|
731
|
<td width="22%" valign="top" class="vncell">Advanced Options</td>
|
732
|
<td width="78%" class="vtable">
|
733
|
<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
|
734
|
<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
|
735
|
<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
|
736
|
<select name="max-src-conn-rates" id="max-src-conn-rates">
|
737
|
<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
|
738
|
<?php
|
739
|
for($x=1; $x<255; $x++) {
|
740
|
if($x == $pconfig['max-src-conn-rates'])
|
741
|
$selected = " selected";
|
742
|
else
|
743
|
$selected = "";
|
744
|
echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
|
745
|
}
|
746
|
?>
|
747
|
</select>
|
748
|
<br>
|
749
|
Maximum new connections / per second
|
750
|
<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
|
751
|
</td>
|
752
|
</tr>
|
753
|
<tr>
|
754
|
<td width="22%" valign="top" class="vncell">State Type</td>
|
755
|
<td width="78%" class="vtable">
|
756
|
<select name="statetype">
|
757
|
<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
|
758
|
<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state") echo "selected"; ?>>modulate state</option>
|
759
|
<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state") echo "selected"; ?>>synproxy state</option>
|
760
|
<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
|
761
|
</select><br>HINT: Select which type of state tracking mechanism you would like to use. If in doubt, use keep state.
|
762
|
<p><strong>
|
763
|
<table>
|
764
|
<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
|
765
|
<tr><td width="25%"><li>modulate state</li></td><td>works only with TCP. pfSense will generate strong Initial Sequence Numbers (ISNs) for packets matching this rule.</li></td></tr>
|
766
|
<tr><td width="25%"><li>synproxy state</li></td><td>proxies incoming TCP connections to help protect servers from spoofed TCP SYN floods. This option includes the functionality of keep state and modulate state combined.</td></tr>
|
767
|
<tr><td width="25%"><li>none</li></td><td>do not use state mechanisms to keep track. this is only useful if your doing advanced queueing in certain situations. please check the faq.</td></tr>
|
768
|
</table>
|
769
|
</strong>
|
770
|
</td>
|
771
|
</tr>
|
772
|
|
773
|
<tr>
|
774
|
<td width="22%" valign="top" class="vncell">State Timeout</td>
|
775
|
<td width="78%" class="vtable">
|
776
|
<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
|
777
|
<p><strong>Leave blank for default. Amount is in seconds.
|
778
|
</strong>
|
779
|
</td>
|
780
|
</tr>
|
781
|
|
782
|
<?php
|
783
|
/* build a list of gateways */
|
784
|
$gateways = array();
|
785
|
$gateways[] = "default"; // default to don't use this feature :)
|
786
|
foreach($config['interfaces'] as $int) {
|
787
|
if($int['gateway'] <> "")
|
788
|
$gateways[]=$int['gateway'];
|
789
|
}
|
790
|
?>
|
791
|
<tr>
|
792
|
<td width="22%" valign="top" class="vncell">Gateway</td>
|
793
|
<td width="78%" class="vtable">
|
794
|
<select name='gateway'>
|
795
|
<?php
|
796
|
foreach($gateways as $gw) {
|
797
|
if($gw == $pconfig['gateway'])
|
798
|
$selected = " SELECTED";
|
799
|
else
|
800
|
$selected = "";
|
801
|
if ($gw == "default")
|
802
|
echo "<option value=\"\" {$selected}>{$gw}</option>\n";
|
803
|
else
|
804
|
echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
|
805
|
}
|
806
|
?>
|
807
|
</select>
|
808
|
<p><strong>Leave blank for default.
|
809
|
</strong>
|
810
|
</td>
|
811
|
</tr>
|
812
|
<tr>
|
813
|
<td width="22%" valign="top"> </td>
|
814
|
<td width="78%">
|
815
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
|
816
|
<?php if (isset($id) && $a_filter[$id]): ?>
|
817
|
<input name="id" type="hidden" value="<?=$id;?>">
|
818
|
<?php endif; ?>
|
819
|
<input name="after" type="hidden" value="<?=$after;?>">
|
820
|
</td>
|
821
|
</tr>
|
822
|
</table>
|
823
|
</form>
|
824
|
<script language="JavaScript">
|
825
|
<!--
|
826
|
ext_change();
|
827
|
typesel_change();
|
828
|
proto_change();
|
829
|
|
830
|
<?php
|
831
|
$isfirst = 0;
|
832
|
$aliases = "";
|
833
|
$addrisfirst = 0;
|
834
|
$aliasesaddr = "";
|
835
|
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
|
836
|
foreach($config['aliases']['alias'] as $alias_name) {
|
837
|
if(!stristr($alias_name['address'], ".")) {
|
838
|
if($isfirst == 1) $aliases .= ",";
|
839
|
$aliases .= "'" . $alias_name['name'] . "'";
|
840
|
$isfirst = 1;
|
841
|
} else {
|
842
|
if($addrisfirst == 1) $aliasesaddr .= ",";
|
843
|
$aliasesaddr .= "'" . $alias_name['name'] . "'";
|
844
|
$addrisfirst = 1;
|
845
|
}
|
846
|
}
|
847
|
?>
|
848
|
|
849
|
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
|
850
|
var customarray=new Array(<?php echo $aliases; ?>);
|
851
|
|
852
|
//-->
|
853
|
</script>
|
854
|
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
|
855
|
</script>
|
856
|
<?php include("fend.inc"); ?>
|
857
|
</body>
|
858
|
</html>
|
859
|
|