]>
Commit | Line | Data |
---|---|---|
3647b19f 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 | # Load all global configuration files. | |
23 | function config_read_globals() { | |
24 | network_config_read | |
25 | firewall_config_read | |
26 | } | |
27 | ||
28 | function config_read() { | |
29 | local config_file=${1} | |
d2a21d01 | 30 | assert isset config_file |
3647b19f | 31 | |
3647b19f MT |
32 | if [ -e "${config_file}" ]; then |
33 | . ${config_file} | |
34 | config_check | |
35 | fi | |
36 | } | |
37 | ||
38 | function config_write() { | |
39 | local config_file=${1} | |
d2a21d01 | 40 | assert isset config_file |
3647b19f MT |
41 | shift |
42 | ||
43 | # Check if all values to be written are sane | |
44 | config_check | |
45 | ||
46 | log DEBUG "Writing configuration file ${config_file}." | |
47 | ||
48 | mkdir -p $(dirname ${config_file}) 2>/dev/null | |
49 | > ${config_file} | |
50 | ||
51 | local param | |
52 | for param in $(listsort $@); do | |
53 | echo "${param}=\"${!param}\"" >> ${config_file} | |
54 | done | |
55 | } | |
56 | ||
57 | function config_print() { | |
58 | local param | |
59 | ||
60 | for param in $(listsort $@); do | |
61 | printf "%-16s = %s\n" "${param}" "${!param}" | |
62 | done | |
63 | } | |
64 | ||
65 | function config_check() { | |
66 | # If there is a function defined that is called __check | |
67 | # we call that function | |
68 | [ -n "$(type -t _check)" ] && _check | |
69 | } | |
70 | ||
71 | function config_hostname() { | |
72 | local hostname=${1} | |
73 | ||
74 | if [ -n "${hostname}" ]; then | |
75 | echo "${hostname}" > ${CONFIG_HOSTNAME} | |
76 | else | |
77 | echo "$(<${CONFIG_HOSTNAME})" | |
78 | fi | |
79 | } | |
80 | ||
81 | function config_set() { | |
82 | while [ $# -gt 0 ]; do | |
83 | case "${1}" in | |
84 | *=*) | |
85 | log INFO "Setting configuration option '${1}'". | |
86 | eval ${1} | |
87 | ;; | |
88 | *) | |
89 | warning "Invalid parameter given: ${1}" | |
90 | ;; | |
91 | esac | |
92 | shift | |
93 | done | |
94 | } | |
95 | ||
96 | function network_config_read() { | |
97 | # Save state of DEBUG and restore it later. | |
98 | local debug=${DEBUG} | |
99 | ||
d2a21d01 | 100 | config_read ${NETWORK_CONFIG_FILE} |
3647b19f MT |
101 | |
102 | if [ -n "${debug}" ]; then | |
103 | DEBUG=${debug} | |
104 | fi | |
105 | } | |
106 | ||
107 | function network_config_write() { | |
d2a21d01 | 108 | config_write ${NETWORK_CONFIG_FILE} ${CONFIG_FILE_PARAMS} |
3647b19f MT |
109 | } |
110 | ||
111 | function network_config_print() { | |
112 | config_print ${CONFIG_FILE_PARAMS} | |
113 | } | |
114 | ||
115 | function firewall_config_read() { | |
116 | config_read ${FIREWALL_CONFIG_FILE} | |
117 | } | |
118 | ||
119 | function firewall_config_write() { | |
120 | config_write ${FIREWALL_CONFIG_FILE} \ | |
121 | ${FIREWALL_CONFIG_PARAMS} | |
122 | } | |
123 | ||
124 | function firewall_config_print() { | |
125 | config_print ${FIREWALL_CONFIG_PARAMS} | |
126 | } |