2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2014 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 ###############################################################################
28 local ignore_superfluous_settings
="false"
33 --ignore-superfluous-settings)
34 ignore_superfluous_settings
="true"
37 list_append valid_keys
"${arg}"
40 done <<< "$(args "$@
")"
42 if [ -d "${file}" ]; then
43 error
"Not a configuration file: '${file}'"
47 # Exit if the file cannot be read.
48 [ -r "${file}" ] ||
return ${EXIT_ERROR}
51 while read -r line
; do
54 key
=$
(cli_get_key
${line})
56 # If valid keys is set, key must be in the list.
57 if [ -n "${valid_keys}" ]; then
58 list_match
${key} ${valid_keys} ||
continue
61 val
=$
(cli_get_val
"${line}")
62 val
=$
(settings_strip
${val})
65 printf -v ${key} "%s" "${val}"
68 log DEBUG
"Invalid line in configuration file: ${line}"
74 settings_read_array
() {
85 # Exit if the file cannot be read.
86 [ -r "${file}" ] ||
return ${EXIT_ERROR}
89 while read -r line
; do
92 key
=$
(cli_get_key
${line})
94 # If valid_keys is set, key must be in the list.
95 if [ -n "${valid_keys}" ]; then
96 if ! list_match
${key} ${valid_keys}; then
97 log DEBUG
"Ignoring configuration setting: ${key}"
102 val
=$
(cli_get_val
"${line}")
103 val
=$
(settings_strip
${val})
106 printf -v "${array}["${key}"]" "%s" "${val}"
109 log DEBUG
"Invalid line in configuration file: ${line}"
115 # Strip leading and trailing "s.
119 # Do nothing for strings that contain spaces.
120 #if contains_spaces ${var}; then
129 local settings_file
="${1}"
130 assert isset settings_file
139 check_func
="$(cli_get_val "${arg}")"
142 # Stop argument processing when reaching the first
143 # configuration parameter
149 done <<< "$(args "$@
")"
151 # Check if all values to be written are sane
152 if isset check_func
&& ! settings_check
"${check_func}"; then
156 log DEBUG
"Writing settings file '${settings_file}'"
158 mkdir
-p $
(dirname ${settings_file}) 2>/dev
/null
162 for param
in $
(list_sort
"$@"); do
163 echo "${param}=\"${!param}\"" >> ${settings_file}
168 local settings_file="${1}"
170 local abspath="$
(readlink
-e "${settings_file}")"
171 if [ "${settings_file}" != "${abspath}" ]; then
172 log ERROR "Can only handle absolute paths
"
176 file_delete "${settings_file}"
182 for param in $(list_sort "$@
"); do
183 printf "%-32s = %s
\n" "${param}" "${!param}"
188 local check_func="${1}"
190 # Execute the check function
196 ${EXIT_OK}|${EXIT_TRUE})
197 log DEBUG "Configuration check succeeded.
"
202 ${EXIT_ERROR}|${EXIT_FALSE})
203 log CRITICAL "Configuration check failed. No settings have been written.
"
208 ${EXIT_COMMAND_NOT_FOUND})
209 log CRITICAL "Configuration check
function '${check_func}' was not found.
"
214 log CRITICAL "Unhandled
exit code
for '${check_func}': ${ret}"
219 while [ $# -gt 0 ]; do
222 local key=$(cli_get_key "${1}")
223 local val=$(cli_get_val "${1}")
225 log INFO "Setting configuration option
'${key}=${val}'".
227 printf -v ${key} "%s
" "${val}"
230 warning "Invalid parameter given
: ${1}"
237 network_settings_read() {
238 local options="${NETWORK_SETTINGS_FILE_PARAMS}"
240 # If the DEBUG variable has already been set,
241 # don't overwrite it.
242 if [ -n "${DEBUG}" ]; then
243 list_remove options DEBUG
246 settings_read "${NETWORK_SETTINGS_FILE}" ${options}
249 network_settings_write() {
250 settings_write "${NETWORK_SETTINGS_FILE}" ${NETWORK_SETTINGS_FILE_PARAMS}
253 network_settings_set() {
254 # Process any settings that require immediate actin
255 while [ $# -gt 0 ]; do
261 local key=$(cli_get_key "${arg}")
262 local val=$(cli_get_val "${arg}")
265 DNS_RANDOMIZE|DNS_SEARCH_DOMAIN|DNS_USE_LOCAL_RESOLVER)
266 dns_generate_resolvconf
269 WIRELESS_REGULATORY_DOMAIN)
270 if ! wireless_valid_reg_domain "${val}"; then
271 warning "Ignoring invalid wireless regulatory domain
: ${val}"
275 if ! wireless_set_reg_domain "${val}"; then
276 error "Error setting wireless regulatory domain
: ${val}"
290 network_settings_print() {
291 settings_print ${NETWORK_SETTINGS_FILE_PARAMS}
294 network_settings_list() {
295 print "${NETWORK_SETTINGS_FILE_PARAMS}"
298 firewall_settings_read() {
299 settings_read "${FIREWALL_SETTINGS_FILE}" "${FIREWALL_SETTINGS_PARAMS}"
302 firewall_settings_write() {
303 settings_write "${FIREWALL_SETTINGS_FILE}" "${FIREWALL_SETTINGS_PARAMS}"
306 firewall_settings_print() {
307 settings_print "${FIREWALL_SETTINGS_PARAMS}"