]>
Commit | Line | Data |
---|---|---|
afb7d704 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2012 IPFire Network Development Team # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | function macro_file() { | |
23 | local macro=${1} | |
24 | assert isset macro | |
25 | ||
26 | # Make the name uppercase. | |
27 | macro=${macro^^} | |
28 | ||
29 | local file | |
30 | local dir | |
31 | for dir in ${FIREWALL_MACROS_DIRS}; do | |
32 | file="${dir}/${macro}" | |
33 | ||
34 | if [ -r "${file}" ]; then | |
35 | print "${file}" | |
36 | return ${EXIT_OK} | |
37 | fi | |
38 | done | |
39 | ||
40 | return ${EXIT_ERROR} | |
41 | } | |
42 | ||
43 | function macro_exists() { | |
44 | local macro=${1} | |
45 | assert isset macro | |
46 | ||
47 | macro_file ${macro} &>/dev/null \ | |
48 | && return ${EXIT_TRUE} || return ${EXIT_FALSE} | |
49 | } | |
50 | ||
51 | function macro_read() { | |
52 | local macro=${1} | |
53 | assert isset macro | |
54 | ||
55 | # Make the name uppercase. | |
56 | macro=${macro^^} | |
57 | ||
58 | local file=$(macro_file ${macro}) | |
59 | assert isset file | |
60 | ||
61 | log DEBUG "Parsing macro '${macro}' (${file})." | |
62 | ||
63 | local src dst | |
64 | local sport dport | |
65 | local proto | |
66 | local var | |
67 | local line | |
68 | ||
69 | while read src dst proto sport dport; do | |
70 | # Skip lines that start with a "#". | |
71 | [ "${src:0:1}" = "#" ] && continue | |
72 | ||
73 | if [ "${src}" = "INCLUDE" ]; then | |
74 | macro_read ${dst} | |
75 | continue | |
76 | fi | |
77 | ||
78 | line="" | |
79 | ||
80 | # Remove all the dashes. | |
81 | for var in src dst proto sport dport; do | |
82 | [ "${!var}" = "-" ] && continue | |
83 | ||
84 | line="${line} ${var}=\"${!var}\"" | |
85 | done | |
86 | ||
87 | line="$(echo ${line})" | |
88 | print "${line}" | |
89 | done < ${file} | |
90 | } |