#!/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 . # # # ############################################################################### # Load all global configuration files. function config_read_globals() { network_config_read firewall_config_read } function config_read() { local config_file=${1} assert isset config_file if [ -e "${config_file}" ]; then . ${config_file} config_check fi } function config_write() { local config_file=${1} assert isset config_file shift # Check if all values to be written are sane config_check log DEBUG "Writing configuration file ${config_file}." mkdir -p $(dirname ${config_file}) 2>/dev/null > ${config_file} local param for param in $(listsort $@); do echo "${param}=\"${!param}\"" >> ${config_file} done } function config_print() { local param for param in $(listsort $@); do printf "%-24s = %s\n" "${param}" "${!param}" done } function config_check() { # If there is a function defined that is called __check # we call that function [ -n "$(type -t _check)" ] && _check } function config_header() { local what=${1} assert isset what # Print the header. echo "#" echo "# This is a ${what}." echo "# THIS FILE IS AUTOMATICALLY GENERATED AND" echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!" echo "#" echo "# $(date -u)" echo "#" echo } function config_hostname() { local hostname=${1} if [ -n "${hostname}" ]; then echo "${hostname}" > ${CONFIG_HOSTNAME} else echo "$(<${CONFIG_HOSTNAME})" fi } function config_set() { while [ $# -gt 0 ]; do case "${1}" in *=*) log INFO "Setting configuration option '${1}'". eval ${1} ;; *) warning "Invalid parameter given: ${1}" ;; esac shift done } function network_config_read() { # Save state of DEBUG and restore it later. local debug=${DEBUG} config_read ${NETWORK_CONFIG_FILE} if [ -n "${debug}" ]; then DEBUG=${debug} fi } function network_config_write() { config_write ${NETWORK_CONFIG_FILE} ${NETWORK_CONFIG_FILE_PARAMS} # Update DNS configuration. dns_generate_resolvconf } function network_config_print() { config_print ${NETWORK_CONFIG_FILE_PARAMS} } function firewall_config_read() { config_read ${FIREWALL_CONFIG_FILE} } function firewall_config_write() { config_write ${FIREWALL_CONFIG_FILE} \ ${FIREWALL_CONFIG_PARAMS} } function firewall_config_print() { config_print ${FIREWALL_CONFIG_PARAMS} }