diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2005-01-28 21:25:01 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2005-01-28 21:25:01 +0000 |
commit | 5ba188972546226daf9285d95ea9fe0cdede10ef (patch) | |
tree | d24bede0010d1a28f10df79d2ae9c3e85cb8c047 /usr/local/www/firewall_rules_edit.php | |
parent | 5b95b5b50105e9e0d987cc5540e5cb91450e59ac (diff) | |
download | pfsense-5ba188972546226daf9285d95ea9fe0cdede10ef.zip pfsense-5ba188972546226daf9285d95ea9fe0cdede10ef.tar.gz |
Add per rule state timeout option. Good for heavily loaded http servers, etc.
Diffstat (limited to 'usr/local/www/firewall_rules_edit.php')
-rwxr-xr-x | usr/local/www/firewall_rules_edit.php | 222 |
1 files changed, 117 insertions, 105 deletions
diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php index b5a5d73..b30eb83 100755 --- a/usr/local/www/firewall_rules_edit.php +++ b/usr/local/www/firewall_rules_edit.php @@ -1,22 +1,22 @@ #!/usr/local/bin/php -<?php +<?php /* firewall_rules_edit.php part of m0n0wall (http://m0n0.ch/wall) - + Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. 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 @@ -42,7 +42,7 @@ $a_filter = &$config['filter']['rule']; $id = $_GET['id']; if (is_numeric($_POST['id'])) $id = $_POST['id']; - + $after = $_GET['after']; if (isset($_POST['after'])) @@ -55,7 +55,7 @@ if (isset($_GET['dup'])) { function is_specialnet($net) { global $specialsrcdst; - + if (in_array($net, $specialsrcdst) || strstr($net, "opt")) return true; else @@ -63,7 +63,7 @@ function is_specialnet($net) { } function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) { - + if (isset($adr['any'])) $padr = "any"; else if ($adr['network']) @@ -73,12 +73,12 @@ function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendp if (!$pmask) $pmask = 32; } - + if (isset($adr['not'])) $pnot = 1; else $pnot = 0; - + if ($adr['port']) { list($pbeginport, $pendport) = explode("-", $adr['port']); if (!$pendport) @@ -90,9 +90,9 @@ function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendp } function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) { - + $adr = array(); - + if ($padr == "any") $adr['any'] = true; else if (is_specialnet($padr)) @@ -102,9 +102,9 @@ function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) if ($pmask != 32) $adr['address'] .= "/" . $pmask; } - + $adr['not'] = $pnot ? true : false; - + if (($pbeginport != 0) && ($pbeginport != "any")) { if ($pbeginport != $pendport) $adr['port'] = $pbeginport . "-" . $pendport; @@ -115,24 +115,24 @@ function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) 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']); - + address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'], $pconfig['dstmask'], $pconfig['dstnot'], $pconfig['dstbeginport'], $pconfig['dstendport']); @@ -141,7 +141,8 @@ if (isset($id) && $a_filter[$id]) { $pconfig['log'] = isset($a_filter[$id]['log']); $pconfig['frags'] = isset($a_filter[$id]['frags']); $pconfig['descr'] = $a_filter[$id]['descr']; - + $pconfig['statetimeout'] = $a_filter[$id]['statetimeout']; + } else { /* defaults */ if ($_GET['if']) @@ -162,38 +163,38 @@ if ($_POST) { $_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 { + } 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 { + } else { if (!$_POST['dstendport']) $_POST['dstendport'] = $_POST['dstbeginport']; } if ($_POST['dstendport'] == "any") - $_POST['dstendport'] = $_POST['dstbeginport']; + $_POST['dstendport'] = $_POST['dstbeginport']; } - + if (is_specialnet($_POST['srctype'])) { $_POST['src'] = $_POST['srctype']; $_POST['srcmask'] = 0; @@ -206,7 +207,7 @@ if ($_POST) { } else if ($_POST['dsttype'] == "single") { $_POST['dstmask'] = 32; } - + unset($input_errors); $pconfig = $_POST; @@ -219,7 +220,7 @@ if ($_POST) { if( $_POST['proto'] == "udp" or $_POST['proto'] == "tcp/udp" or $_POST['proto'] == "icmp") $input_errors[] = "You cannot select udp or icmp when using modulate state or synproxy state."; - + if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) { $reqdfields[] = "srcmask"; $reqdfieldsn[] = "Source bit count"; @@ -228,9 +229,9 @@ if ($_POST) { $reqdfields[] = "dstmask"; $reqdfieldsn[] = "Destination bit count"; } - + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - + if (!$_POST['srcbeginport']) { $_POST['srcbeginport'] = 0; $_POST['srcendport'] = 0; @@ -239,7 +240,7 @@ if ($_POST) { $_POST['dstbeginport'] = 0; $_POST['dstendport'] = 0; } - + if (($_POST['srcbeginport'] && !is_port($_POST['srcbeginport']))) { $input_errors[] = "The start source port must be an integer between 1 and 65535."; } @@ -252,7 +253,7 @@ if ($_POST) { if (($_POST['dstendport'] && !is_port($_POST['dstendport']))) { $input_errors[] = "The end destination port must be an integer between 1 and 65535."; } - + if (!is_specialnet($_POST['srctype'])) { if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) { $input_errors[] = "A valid source IP address or alias must be specified."; @@ -269,7 +270,7 @@ if ($_POST) { $input_errors[] = "A valid destination bit count must be specified."; } } - + if ($_POST['srcbeginport'] > $_POST['srcendport']) { /* swap */ $tmp = $_POST['srcendport']; @@ -291,30 +292,31 @@ if ($_POST) { /* Advanced options */ $filterent['max-src-nodes'] = $_POST['max-src-nodes']; $filterent['max-src-states'] = $_POST['max-src-states']; - + $filterent['statetimeout'] = $_POST['statetimeout']; + 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']); - + $filterent['disabled'] = $_POST['disabled'] ? true : false; $filterent['log'] = $_POST['log'] ? true : false; $filterent['frags'] = $_POST['frags'] ? true : false; $filterent['descr'] = $_POST['descr']; - + if (isset($id) && $a_filter[$id]) $a_filter[$id] = $filterent; else { @@ -323,10 +325,10 @@ if ($_POST) { else $a_filter[] = $filterent; } - + write_config(); touch($d_filterconfdirty_path); - + header("Location: firewall_rules.php?if=" . $_POST['interface']); exit; } @@ -367,7 +369,7 @@ function ext_change() { document.iform.dstendport_cust.value = ""; document.iform.dstendport_cust.disabled = 1; } - + if (!portsenabled) { document.iform.srcbeginport.disabled = 1; document.iform.srcendport.disabled = 1; @@ -424,13 +426,13 @@ function proto_change() { } else { portsenabled = 0; } - + if (document.iform.proto.selectedIndex == 3) { document.iform.icmptype.disabled = 0; } else { document.iform.icmptype.disabled = 1; } - + ext_change(); } @@ -450,7 +452,7 @@ function dst_rep_change() { <?php if ($input_errors) print_input_errors($input_errors); ?> <form action="firewall_rules_edit.php" method="post" name="iform" id="iform"> <table width="100%" border="0" cellpadding="6" cellspacing="0"> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Action</td> <td width="78%" class="vtable"> <select name="type" class="formfld"> @@ -464,15 +466,15 @@ function dst_rep_change() { the criteria specified below.<br> 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> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Disabled</td> - <td width="78%" class="vtable"> + <td width="78%" class="vtable"> <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>> <strong>Disable this rule</strong><br> <span class="vexpl">Set this option to disable this rule without removing it from the list.</span></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Interface</td> <td width="78%" class="vtable"> <select name="interface" class="formfld"> @@ -486,10 +488,10 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </option> <?php endforeach; ?> </select> <br> - <span class="vexpl">Choose on which interface packets must + <span class="vexpl">Choose on which interface packets must come in to match this rule.</span></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Protocol</td> <td width="78%" class="vtable"> <select name="proto" class="formfld" onchange="proto_change()"> @@ -499,7 +501,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </option> <?php endforeach; ?> </select> <br> - <span class="vexpl">Choose which IP protocol this rule should + <span class="vexpl">Choose which IP protocol this rule should match.<br> Hint: in most cases, you should specify <em>TCP</em> here.</span></td> </tr> @@ -508,7 +510,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <td class="vtable"> <select name="icmptype" class="formfld"> <?php - + $icmptypes = array( "" => "any", "unreach" => "Destination unreachable", @@ -525,7 +527,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP "maskreq" => "Address mask request", "maskrep" => "Address mask reply" ); - + foreach ($icmptypes as $icmptype => $descr): ?> <option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>> <?=htmlspecialchars($descr);?> @@ -535,7 +537,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <br> <span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Source</td> <td width="78%" class="vtable"> <input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>> @@ -543,7 +545,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP Use this option to invert the sense of the match.<br> <br> <table border="0" cellspacing="0" cellpadding="0"> - <tr> + <tr> <td>Type: </td> <td><select name="srctype" class="formfld" onChange="typesel_change()"> <?php $sel = is_specialnet($pconfig['src']); ?> @@ -563,7 +565,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <?php endfor; ?> </select></td> </tr> - <tr> + <tr> <td>Address: </td> <td><input name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> / @@ -576,12 +578,12 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </tr> </table></td> </tr> - <tr> - <td width="22%" valign="top" class="vncellreq">Source port range + <tr> + <td width="22%" valign="top" class="vncellreq">Source port range </td> - <td width="78%" class="vtable"> + <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0"> - <tr> + <tr> <td>from: </td> <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()"> <option value="">(other)</option> @@ -596,7 +598,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <?php endforeach; ?> </select> <input name="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>"></td> </tr> - <tr> + <tr> <td>to:</td> <td><select name="srcendport" class="formfld" onchange="ext_change()"> <option value="">(other)</option> @@ -612,20 +614,20 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </select> <input name="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>"></td> </tr> </table> - <br> - <span class="vexpl">Specify the port or port range for + <br> + <span class="vexpl">Specify the port or port range for the source of the packet for this rule. This is usually not equal to the destination port range (and is often "any"). <br> - Hint: you can leave the <em>'to'</em> field empty if you only + Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span></td> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Destination</td> - <td width="78%" class="vtable"> - <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>> + <td width="78%" class="vtable"> + <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>> <strong>not</strong><br> Use this option to invert the sense of the match.<br> <br> <table border="0" cellspacing="0" cellpadding="0"> - <tr> + <tr> <td>Type: </td> <td><select name="dsttype" class="formfld" onChange="typesel_change()"> <?php $sel = is_specialnet($pconfig['dst']); ?> @@ -645,10 +647,10 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <?php endfor; ?> </select></td> </tr> - <tr> + <tr> <td>Address: </td> <td><input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>"> - / + / <select name="dstmask" class="formfld" id="dstmask"> <?php for ($i = 31; $i > 0; $i--): ?> <option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option> @@ -657,12 +659,12 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </tr> </table></td> </tr> - <tr> - <td width="22%" valign="top" class="vncellreq">Destination port + <tr> + <td width="22%" valign="top" class="vncellreq">Destination port range </td> - <td width="78%" class="vtable"> + <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0"> - <tr> + <tr> <td>from: </td> <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()"> <option value="">(other)</option> @@ -677,7 +679,7 @@ Hint: the difference between block and reject is that with reject, a packet (TCP <?php endforeach; ?> </select> <input name="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td> </tr> - <tr> + <tr> <td>to:</td> <td><select name="dstendport" class="formfld" onchange="ext_change()"> <option value="">(other)</option> @@ -693,37 +695,37 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </select> <input name="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>"></td> </tr> </table> - <br> <span class="vexpl">Specify the port or port range for + <br> <span class="vexpl">Specify the port or port range for the destination of the packet for this rule.<br> - Hint: you can leave the <em>'to'</em> field empty if you only + Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span></td> - - <tr> + + <tr> <td width="22%" valign="top" class="vncellreq">Fragments</td> - <td width="78%" class="vtable"> + <td width="78%" class="vtable"> <input name="frags" type="checkbox" id="frags" value="yes" <?php if ($pconfig['frags']) echo "checked"; ?>> <strong>Allow fragmented packets</strong><br> - <span class="vexpl">Hint: this option puts additional load - on the firewall and may make it vulnerable to DoS attacks. - In most cases, it is not needed. Try enabling it if you have + <span class="vexpl">Hint: this option puts additional load + on the firewall and may make it vulnerable to DoS attacks. + In most cases, it is not needed. Try enabling it if you have troubles connecting to certain sites.</span></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq">Log</td> - <td width="78%" class="vtable"> + <td width="78%" class="vtable"> <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>> <strong>Log packets that are handled by this rule</strong><br> - <span class="vexpl">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 <a href="diag_logs_settings.php">Diagnostics: System + <span class="vexpl">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 <a href="diag_logs_settings.php">Diagnostics: System logs: Settings</a> page).</span></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncell">Description</td> - <td width="78%" class="vtable"> - <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> - <br> <span class="vexpl">You may enter a description here + <td width="78%" class="vtable"> + <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> + <br> <span class="vexpl">You may enter a description here for your reference (not parsed).</span></td> </tr> @@ -748,22 +750,32 @@ Hint: the difference between block and reject is that with reject, a packet (TCP </select><br>HINT: Select which type of state tracking mechanism you would like to use. If in doubt, use keep state. <p><strong> <table> - <tr><td><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr> - <tr><td><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> - <tr><td><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> - <tr><td><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> + <tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr> + <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> + <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> + <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> + </table> </strong> </td> </tr> - <tr> + <tr> + <td width="22%" valign="top" class="vncell">State Timeout</td> + <td width="78%" class="vtable"> + <input name="statetimeout" value="<?php echo $pconfig['frags'] ?>"> + <p><strong>Leave blank for default. Amount is in seconds. + </strong> + </td> + </tr> + + <tr> <td width="22%" valign="top"> </td> - <td width="78%"> - <input name="Submit" type="submit" class="formbtn" value="Save"> + <td width="78%"> + <input name="Submit" type="submit" class="formbtn" value="Save"> <?php if (isset($id) && $a_filter[$id]): ?> - <input name="id" type="hidden" value="<?=$id;?>"> + <input name="id" type="hidden" value="<?=$id;?>"> <?php endif; ?> - <input name="after" type="hidden" value="<?=$after;?>"> + <input name="after" type="hidden" value="<?=$after;?>"> </td> </tr> </table> |