#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### function macro_file() { local macro=${1} assert isset macro # Make the name uppercase. macro=${macro^^} local file local dir for dir in ${FIREWALL_MACROS_DIRS}; do file="${dir}/${macro}" if [ -r "${file}" ]; then print "${file}" return ${EXIT_OK} fi done return ${EXIT_ERROR} } function macro_exists() { local macro=${1} assert isset macro macro_file ${macro} &>/dev/null \ && return ${EXIT_TRUE} || return ${EXIT_FALSE} } function macro_read() { local macro=${1} assert isset macro # Make the name uppercase. macro=${macro^^} local file=$(macro_file ${macro}) assert isset file log DEBUG "Parsing macro '${macro}' (${file})." local src dst local sport dport local proto local var local line while read src dst proto sport dport; do # Skip lines that start with a "#". [ "${src:0:1}" = "#" ] && continue if [ "${src}" = "INCLUDE" ]; then macro_read ${dst} continue fi line="" # Remove all the dashes. for var in src dst proto sport dport; do [ "${!var}" = "-" ] && continue line="${line} ${var}=\"${!var}\"" done line="$(echo ${line})" print "${line}" done < ${file} }