2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
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 ###############################################################################
22 # Load all global configuration files.
23 function config_read_globals
() {
28 function config_read
() {
35 # Exit if the file cannot be read.
36 [ -r "${file}" ] ||
return ${EXIT_ERROR}
39 while read -r line
; do
42 key
=$
(cli_get_key
${line})
44 # If valid keys is set, key must be in the list.
45 if [ -n "${valid_keys}" ]; then
46 if ! listmatch
${key} ${valid_keys}; then
47 log DEBUG
"Ignoring configuration setting: ${key}"
52 val
=$
(cli_get_val
${line})
53 val
=$
(config_strip
${val})
56 printf -v ${key} "%s" "${val}"
59 log DEBUG
"Invalid line in configuration file: ${line}"
65 function config_read_array
() {
76 # Exit if the file cannot be read.
77 [ -r "${file}" ] ||
return ${EXIT_ERROR}
80 while read -r line
; do
83 key
=$
(cli_get_key
${line})
85 # If valid_keys is set, key must be in the list.
86 if [ -n "${valid_keys}" ]; then
87 if ! listmatch
${key} ${valid_keys}; then
88 log DEBUG
"Ignoring configuration setting: ${key}"
93 val
=$
(cli_get_val
${line})
94 val
=$
(config_strip
${val})
97 printf -v "${array}["${key}"]" "%s" "${val}"
100 log DEBUG
"Invalid line in configuration file: ${line}"
106 # Strip leading and trailing "s.
107 function config_strip
() {
110 # Do nothing for strings that contain spaces.
111 if contains_spaces
${var}; then
119 function config_write
() {
120 local config_file
=${1}
121 assert isset config_file
124 # Check if all values to be written are sane
127 log DEBUG
"Writing configuration file ${config_file}."
129 mkdir
-p $
(dirname ${config_file}) 2>/dev
/null
133 for param
in $
(listsort $@
); do
134 echo "${param}=\"${!param}\"" >> ${config_file}
138 function config_print() {
141 for param in $(listsort $@); do
142 printf "%-24s = %s
\n" "${param}" "${!param}"
146 function config_check() {
147 # If there is a function defined that is called __check
148 # we call that function
149 [ -n "$
(type -t _check
)" ] && _check
152 function config_header() {
158 echo "# This is a ${what}."
159 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND"
160 echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!"
167 function config_hostname
() {
170 if [ -n "${hostname}" ]; then
171 echo "${hostname}" > ${CONFIG_HOSTNAME}
173 echo "$(<${CONFIG_HOSTNAME})"
177 function config_domainname
() {
178 local hostname
=$
(config_hostname
)
180 # Strip off the hostname part and just return
182 print
"${hostname#*.}"
185 function config_set
() {
186 while [ $# -gt 0 ]; do
189 local key
=$
(cli_get_key
${1})
190 local val
=$
(cli_get_val
${1})
192 log INFO
"Setting configuration option '${key}=${val}'".
194 printf -v ${key} "%s" "${val}"
197 warning
"Invalid parameter given: ${1}"
204 function network_config_read
() {
205 local options
=${NETWORK_CONFIG_FILE_PARAMS}
207 # If the DEBUG variable has already been set,
208 # don't overwrite it.
209 if [ -n "${DEBUG}" ]; then
210 list_remove options DEBUG
213 config_read
${NETWORK_CONFIG_FILE} ${options}
216 function network_config_write
() {
217 config_write
${NETWORK_CONFIG_FILE} ${NETWORK_CONFIG_FILE_PARAMS}
219 # Update DNS configuration.
220 dns_generate_resolvconf
223 function network_config_print
() {
224 config_print
${NETWORK_CONFIG_FILE_PARAMS}
227 function firewall_config_read
() {
228 config_read
${FIREWALL_CONFIG_FILE} ${FIREWALL_CONFIG_PARAMS}
231 function firewall_config_write
() {
232 config_write
${FIREWALL_CONFIG_FILE} \
233 ${FIREWALL_CONFIG_PARAMS}
236 function firewall_config_print
() {
237 config_print
${FIREWALL_CONFIG_PARAMS}