. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require("guiconfig.inc"); $specialsrcdst = explode(" ", "any wanip lanip lan pptp pppoe"); if (!is_array($config['filter']['rule'])) { $config['filter']['rule'] = array(); } filter_rules_sort(); $a_filter = &$config['filter']['rule']; $id = $_GET['id']; if (is_numeric($_POST['id'])) $id = $_POST['id']; $after = $_GET['after']; if (isset($_POST['after'])) $after = $_POST['after']; if (isset($_GET['dup'])) { $id = $_GET['dup']; $after = $_GET['dup']; } if (isset($id) && $a_filter[$id]) { $pconfig['interface'] = $a_filter[$id]['interface']; if (!isset($a_filter[$id]['type'])) $pconfig['type'] = "pass"; else $pconfig['type'] = $a_filter[$id]['type']; if (isset($a_filter[$id]['protocol'])) $pconfig['proto'] = $a_filter[$id]['protocol']; else $pconfig['proto'] = "any"; if ($a_filter[$id]['protocol'] == "icmp") $pconfig['icmptype'] = $a_filter[$id]['icmptype']; address_to_pconfig($a_filter[$id]['source'], $pconfig['src'], $pconfig['srcmask'], $pconfig['srcnot'], $pconfig['srcbeginport'], $pconfig['srcendport']); if($a_filter[$id]['os'] <> "") $pconfig['os'] = $a_filter[$id]['os']; address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'], $pconfig['dstmask'], $pconfig['dstnot'], $pconfig['dstbeginport'], $pconfig['dstendport']); $pconfig['disabled'] = isset($a_filter[$id]['disabled']); $pconfig['log'] = isset($a_filter[$id]['log']); $pconfig['descr'] = $a_filter[$id]['descr']; /* advanced */ $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes']; $pconfig['max-src-states'] = $a_filter[$id]['max-src-states']; $pconfig['statetype'] = $a_filter[$id]['statetype']; $pconfig['statetimeout'] = $a_filter[$id]['statetimeout']; $pconfig['nosync'] = isset($a_filter[$id]['nosync']); /* advanced - new connection per second banning*/ $pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate']; $pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates']; /* Multi-WAN next-hop support */ $pconfig['gateway'] = $a_filter[$id]['gateway']; //schedule support $pconfig['sched'] = $a_filter[$id]['sched']; } else { /* defaults */ if ($_GET['if']) $pconfig['interface'] = $_GET['if']; $pconfig['type'] = "pass"; $pconfig['src'] = "any"; $pconfig['dst'] = "any"; } if (isset($_GET['dup'])) unset($id); if ($_POST) { if ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp") $input_errors[] = "Reject type rules only works when the protocol is set to TCP."; if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) { $_POST['srcbeginport'] = 0; $_POST['srcendport'] = 0; $_POST['dstbeginport'] = 0; $_POST['dstendport'] = 0; } else { if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport']) $_POST['srcbeginport'] = $_POST['srcbeginport_cust']; if ($_POST['srcendport_cust'] && !$_POST['srcendport']) $_POST['srcendport'] = $_POST['srcendport_cust']; if ($_POST['srcbeginport'] == "any") { $_POST['srcbeginport'] = 0; $_POST['srcendport'] = 0; } else { if (!$_POST['srcendport']) $_POST['srcendport'] = $_POST['srcbeginport']; } if ($_POST['srcendport'] == "any") $_POST['srcendport'] = $_POST['srcbeginport']; if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport']) $_POST['dstbeginport'] = $_POST['dstbeginport_cust']; if ($_POST['dstendport_cust'] && !$_POST['dstendport']) $_POST['dstendport'] = $_POST['dstendport_cust']; if ($_POST['dstbeginport'] == "any") { $_POST['dstbeginport'] = 0; $_POST['dstendport'] = 0; } else { if (!$_POST['dstendport']) $_POST['dstendport'] = $_POST['dstbeginport']; } if ($_POST['dstendport'] == "any") $_POST['dstendport'] = $_POST['dstbeginport']; } if (is_specialnet($_POST['srctype'])) { $_POST['src'] = $_POST['srctype']; $_POST['srcmask'] = 0; } else if ($_POST['srctype'] == "single") { $_POST['srcmask'] = 32; } if (is_specialnet($_POST['dsttype'])) { $_POST['dst'] = $_POST['dsttype']; $_POST['dstmask'] = 0; } else if ($_POST['dsttype'] == "single") { $_POST['dstmask'] = 32; } unset($input_errors); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "type interface proto src dst"); $reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination"); if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") { if( $_POST['proto'] != "tcp" ) $input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp."; if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != "")) $input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'."; } if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) { $reqdfields[] = "srcmask"; $reqdfieldsn[] = "Source bit count"; } if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) { $reqdfields[] = "dstmask"; $reqdfieldsn[] = "Destination bit count"; } do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (!$_POST['srcbeginport']) { $_POST['srcbeginport'] = 0; $_POST['srcendport'] = 0; } if (!$_POST['dstbeginport']) { $_POST['dstbeginport'] = 0; $_POST['dstendport'] = 0; } if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) { $input_errors[] = "The start source port must be an alias or integer between 1 and 65535."; } if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) { $input_errors[] = "The end source port must be an alias or integer between 1 and 65535."; } if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) { $input_errors[] = "The start destination port must be an alias or integer between 1 and 65535."; } if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) { $input_errors[] = "The end destination port must be an alias or integer between 1 and 65535."; } /* if user enters an alias and selects "network" then disallow. */ if($_POST['srctype'] == "network") { if(is_alias($_POST['src'])) $input_errors[] = "You must specify single host or alias for alias entries."; } if($_POST['sched'] && $_POST['gateway']) $input_errors[] = "You cannot specify a gateway with time based rules."; if($_POST['dsttype'] == "network") { if(is_alias($_POST['dst'])) $input_errors[] = "You must specify single host or alias for alias entries."; } if (!is_specialnet($_POST['srctype'])) { if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) { $input_errors[] = "A valid source IP address or alias must be specified."; } if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) { $input_errors[] = "A valid source bit count must be specified."; } } if (!is_specialnet($_POST['dsttype'])) { if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) { $input_errors[] = "A valid destination IP address or alias must be specified."; } if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) { $input_errors[] = "A valid destination bit count must be specified."; } } if ($_POST['srcbeginport'] > $_POST['srcendport']) { /* swap */ $tmp = $_POST['srcendport']; $_POST['srcendport'] = $_POST['srcbeginport']; $_POST['srcbeginport'] = $tmp; } if ($_POST['dstbeginport'] > $_POST['dstendport']) { /* swap */ $tmp = $_POST['dstendport']; $_POST['dstendport'] = $_POST['dstbeginport']; $_POST['dstbeginport'] = $tmp; } if ($_POST['os']) if( $_POST['proto'] != "tcp" ) $input_errors[] = "OS detection is only valid with protocol tcp."; if (!$input_errors) { $filterent = array(); $filterent['type'] = $_POST['type']; $filterent['interface'] = $_POST['interface']; /* Advanced options */ $filterent['max-src-nodes'] = $_POST['max-src-nodes']; $filterent['max-src-states'] = $_POST['max-src-states']; $filterent['statetimeout'] = $_POST['statetimeout']; $filterent['statetype'] = $_POST['statetype']; $filterent['os'] = $_POST['os']; /* Nosync directive - do not xmlrpc sync this item */ if($_POST['nosync'] <> "") $filterent['nosync'] = true; else unset($filterent['nosync']); /* unless both values are provided, unset the values - ticket #650 */ if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") { $filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate']; $filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates']; } else { unset($filterent['max-src-conn-rate']); unset($filterent['max-src-conn-rates']); } if ($_POST['proto'] != "any") $filterent['protocol'] = $_POST['proto']; else unset($filterent['protocol']); if ($_POST['proto'] == "icmp" && $_POST['icmptype']) $filterent['icmptype'] = $_POST['icmptype']; else unset($filterent['icmptype']); pconfig_to_address($filterent['source'], $_POST['src'], $_POST['srcmask'], $_POST['srcnot'], $_POST['srcbeginport'], $_POST['srcendport']); pconfig_to_address($filterent['destination'], $_POST['dst'], $_POST['dstmask'], $_POST['dstnot'], $_POST['dstbeginport'], $_POST['dstendport']); if ($_POST['disabled']) $filterent['disabled'] = true; else unset($filterent['disabled']); if ($_POST['log']) $filterent['log'] = true; else unset($filterent['log']); strncpy($filterent['descr'], $_POST['descr'], 52); if ($_POST['gateway'] != "") { $filterent['gateway'] = $_POST['gateway']; } if ($_POST['sched'] != "") { $filterent['sched'] = $_POST['sched']; } if (isset($id) && $a_filter[$id]) $a_filter[$id] = $filterent; else { if (is_numeric($after)) array_splice($a_filter, $after+1, 0, array($filterent)); else $a_filter[] = $filterent; } write_config(); touch($d_filterconfdirty_path); header("Location: firewall_rules.php?if=" . $_POST['interface']); exit; } } $pgtitle = "Firewall: Rules: Edit"; $closehead = false; $page_filename = "firewall_rules_edit.php"; include("head.inc"); ?>

"") $schedules[] = $schedule['name']; } } ?> "") $gateways[]=$int['gateway']; } ?>
Action
Choose what to do with packets that match the criteria specified below.
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.
Disabled > Disable this rule
Set this option to disable this rule without removing it from the list.
Interface
Choose on which interface packets must come in to match this rule.
Protocol
Choose which IP protocol this rule should match.
Hint: in most cases, you should specify TCP  here.
ICMP type
If you selected ICMP for the protocol above, you may specify an ICMP type here.
Source > not
Use this option to invert the sense of the match.

Type:  
Address:   /

- Show source port range

Source OS OS Type: 
Note: this only works for TCP rules
Destination > not
Use this option to invert the sense of the match.

Type:  
Address:   /
Destination port range
from:  
to:

Specify the port or port range for the destination of the packet for this rule.
Hint: you can leave the 'to' field empty if you only want to filter a single port
Log > Log packets that are handled by this rule
Hint: the firewall has limited local log space. Don't turn on logging for everything. If you want to do a lot of logging, consider using a remote syslog server (see the Diagnostics: System logs: Settings page).
Advanced Options
- Show advanced options
State Type
- Show state
No XMLRPC Sync >
HINT: This prevents the rule from automatically syncing to other CARP members.
Schedule

Leave as 'none' to leave the rule enabled all the time.

NOTE: schedule logic can be a bit different. Click here for more information.
Gateway

Leave as 'default' to use the system routing table. Or choose a gateway to utilize policy based routing.

Description
You may enter a description here for your reference (not parsed).