2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2009 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
28 if [ "${file:0:1}" != "/" ]; then
29 file="/usr/share/firewall/macros/$file"
33 if _config_is_sqlite
$file; then
34 rules
=$
(macro_parse $@
< $file)
36 rules
=$
(sqlite3
-noheader -column $file | macro_parse $@
)
39 while read line
<<< ${rules}; do
44 function macro_parse
() {
46 grep -v "^#" |
while read ACTION SOURCE DESTINATION PROTOCOL LOCAL_PORT REMOTE_PORT RATE
; do
50 if [ "$ACTION" = "INCLUDE" ]; then
55 STRING
="$STRING $(iptables_protocol $PROTOCOL)"
57 if [ -n "$PORT_SWITCH" ]; then
58 # Switch ports for upload rule
59 STRING
="$STRING $(iptables_source_port $REMOTE_PORT)"
60 STRING
="$STRING $(iptables_destination_port $LOCAL_PORT)"
62 STRING
="$STRING $(iptables_source_port $LOCAL_PORT)"
63 STRING
="$STRING $(iptables_destination_port $REMOTE_PORT)"
66 if [ "$ACTION" = "ACCEPT" ]; then
67 STRING
="$STRING -j ACCEPT"
69 elif [ "$ACTION" = "DROP" ]; then
70 STRING
="$STRING -j DROP"
73 [ -n "$STRING" ] && echo "$STRING $@"