]>
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 | |
acc9efd5 | 61 | printf "%-24s = %s\n" "${param}" "${!param}" |
3647b19f MT |
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 | ||
97cb552e MT |
71 | function config_header() { |
72 | local what=${1} | |
73 | assert isset what | |
74 | ||
75 | # Print the header. | |
76 | echo "#" | |
77 | echo "# This is a ${what}." | |
cd464143 MT |
78 | echo "# THIS FILE IS AUTOMATICALLY GENERATED AND" |
79 | echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!" | |
97cb552e MT |
80 | echo "#" |
81 | echo "# $(date -u)" | |
82 | echo "#" | |
83 | echo | |
84 | } | |
85 | ||
3647b19f MT |
86 | function config_hostname() { |
87 | local hostname=${1} | |
88 | ||
89 | if [ -n "${hostname}" ]; then | |
90 | echo "${hostname}" > ${CONFIG_HOSTNAME} | |
91 | else | |
92 | echo "$(<${CONFIG_HOSTNAME})" | |
93 | fi | |
94 | } | |
95 | ||
96 | function config_set() { | |
97 | while [ $# -gt 0 ]; do | |
98 | case "${1}" in | |
99 | *=*) | |
6c8635c9 MT |
100 | local key=$(cli_get_key ${1}) |
101 | local val=$(cli_get_val ${1}) | |
102 | ||
103 | log INFO "Setting configuration option '${key}=${val}'". | |
104 | ||
105 | eval ${key}="${val}" | |
3647b19f MT |
106 | ;; |
107 | *) | |
108 | warning "Invalid parameter given: ${1}" | |
109 | ;; | |
110 | esac | |
111 | shift | |
112 | done | |
113 | } | |
114 | ||
115 | function network_config_read() { | |
116 | # Save state of DEBUG and restore it later. | |
117 | local debug=${DEBUG} | |
118 | ||
d2a21d01 | 119 | config_read ${NETWORK_CONFIG_FILE} |
3647b19f MT |
120 | |
121 | if [ -n "${debug}" ]; then | |
122 | DEBUG=${debug} | |
123 | fi | |
124 | } | |
125 | ||
126 | function network_config_write() { | |
519d9b82 | 127 | config_write ${NETWORK_CONFIG_FILE} ${NETWORK_CONFIG_FILE_PARAMS} |
acc9efd5 MT |
128 | |
129 | # Update DNS configuration. | |
130 | dns_generate_resolvconf | |
3647b19f MT |
131 | } |
132 | ||
133 | function network_config_print() { | |
519d9b82 | 134 | config_print ${NETWORK_CONFIG_FILE_PARAMS} |
3647b19f MT |
135 | } |
136 | ||
137 | function firewall_config_read() { | |
138 | config_read ${FIREWALL_CONFIG_FILE} | |
139 | } | |
140 | ||
141 | function firewall_config_write() { | |
142 | config_write ${FIREWALL_CONFIG_FILE} \ | |
143 | ${FIREWALL_CONFIG_PARAMS} | |
144 | } | |
145 | ||
146 | function firewall_config_print() { | |
147 | config_print ${FIREWALL_CONFIG_PARAMS} | |
148 | } |