2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 ###############################################################################
25 echo "${ZONE_DIR}/${zone}"
28 function zone_exists
() {
31 [ -d "$(zone_dir ${zone})" ]
34 function zone_match
() {
38 for i
in ${VALID_ZONES}; do
39 match
="${match}|${i}[0-9]{1,5}"
42 echo "${match:1:${#match}}"
45 function zone_name_is_valid
() {
48 [[ ${zone} =~ $
(zone_match
) ]]
51 function zone_is_local
() {
54 ! zone_is_nonlocal
${zone}
57 function zone_is_nonlocal
() {
60 [[ ${zone} =~ ^red
[0-9]{1,5} ]]
63 function zone_get_hook
() {
66 config_get_hook $
(zone_dir
${zone})/settings
69 function zone_create
() {
74 if ! zone_name_is_valid
${zone}; then
75 error
"Zone name '${zone}' is not valid."
79 if zone_exists
${zone}; then
80 error
"Zone '${zone}' does already exist."
84 if ! hook_exists
${hook}; then
85 error
"Hook '${hook}' does not exist."
89 mkdir
-p $
(zone_dir
${zone})
91 hook_exec
${hook} create
${zone} $@
94 # Maybe the zone create hook did not exit correctly.
95 # If this is the case we remove the created zone immediately.
96 if [ "${ret}" = "${EXIT_ERROR}" ]; then
101 function zone_edit
() {
105 if ! zone_exists
${zone}; then
106 error
"Zone '${zone}' does not exist."
110 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
112 if [ -z "${hook}" ]; then
113 error
"Config file did not provide any hook."
117 if ! hook_exists
${hook}; then
118 error
"Hook '${hook}' does not exist."
122 hook_exec
${hook} edit
${zone} $@
125 function zone_remove
() {
129 if ! zone_exists
${zone}; then
130 error
"Zone '${zone}' does not exist."
134 # XXX Tear this down here?
136 rm -rf $
(zone_dir
${zone})
143 if ! zone_exists
${zone}; then
144 error
"Zone '${zone}' does not exist."
148 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
150 if [ -z "${hook}" ]; then
151 error
"Config file did not provide any hook."
155 if ! hook_exists
${hook}; then
156 error
"Hook '${hook}' does not exist."
160 zone_db
${zone} starting
162 hook_exec
${hook} up
${zone} $@
164 zone_db
${zone} started
167 function zone_down
() {
171 if ! zone_exists
${zone}; then
172 error
"Zone '${zone}' does not exist."
176 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
178 if [ -z "${hook}" ]; then
179 error
"Config file did not provide any hook."
183 if ! hook_exists
${hook}; then
184 error
"Hook '${hook}' does not exist."
188 zone_db
${zone} stopping
190 hook_exec
${hook} down
${zone} $@
192 zone_db
${zone} stopped
195 function zone_status
() {
199 if ! zone_exists
${zone}; then
200 error
"Zone '${zone}' does not exist."
204 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
206 if [ -z "${hook}" ]; then
207 error
"Config file did not provide any hook."
211 if ! hook_exists
${hook}; then
212 error
"Hook '${hook}' does not exist."
216 hook_exec
${hook} status
${zone} $@
219 function zone_port
() {
223 if ! zone_exists
${zone}; then
224 error
"Zone '${zone}' does not exist."
228 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
230 if [ -z "${hook}" ]; then
231 error
"Config file did not provide any hook."
235 if ! hook_exists
${hook}; then
236 error
"Hook '${hook}' does not exist."
240 hook_exec
${hook} port
${zone} $@
243 function zone_config
() {
247 if ! zone_exists
${zone}; then
248 error
"Zone '${zone}' does not exist."
252 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
254 if [ -z "${hook}" ]; then
255 error
"Config file did not provide any hook."
259 if ! hook_exists
${hook}; then
260 error
"Hook '${hook}' does not exist."
264 hook_exec
${hook} config
${zone} $@
267 function zone_show
() {
271 echo " Type: $(zone_get_hook ${zone})"
275 function zones_show
() {
278 for zone
in $
(zones_get $@
); do
283 function zones_get_all
() {
285 for zone
in ${ZONE_DIR}/*; do
286 zone
=$
(basename ${zone})
287 zone_exists
${zone} ||
continue
293 function zones_get_local
() {
295 for zone
in $
(zones_get_all
); do
296 zone_is_local
${zone} && echo "${zone}"
300 function zones_get_nonlocal
() {
302 for zone
in $
(zones_get_all
); do
303 zone_is_nonlocal
${zone} && echo "${zone}"
307 function zones_get
() {
313 while [ $# -gt 0 ]; do
328 if zone_name_is_valid
${1}; then
329 zones
="${zones} ${1}"
331 warning
"Unrecognized argument '${1}'"
338 if [ -n "${zones}" ]; then
340 for zone
in ${zones}; do
341 zone_exists
${zone} && echo "${zone}"
346 if [ ${local} -eq 1 ] && [ ${remote} -eq 1 ]; then
348 elif [ ${local} -eq 1 ]; then
350 elif [ ${remote} -eq 1 ]; then
355 function zone_ports_list
() {
359 for port
in $
(zone_dir
${zone})/port.
*; do
360 [ -e "${port}" ] ||
continue
362 echo $
(basename ${port})
366 function zone_ports_cmd
() {
371 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
375 for port
in $
(zone_ports_list
${zone}); do
376 hook_port
=$
(config_get_hook $
(zone_dir
${zone})/${port})
378 hook_port_exec
${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
382 function zone_ports_up
() {
386 function zone_ports_down
() {
387 zone_ports_cmd down $@
390 function zone_configs_list
() {
394 for config
in $
(zone_dir
${zone})/config.
*; do
395 [ -e "${config}" ] ||
continue
397 echo $
(basename ${config})
401 function zone_configs_cmd
() {
406 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
410 for config
in $
(zone_configs_list
${zone}); do
411 hook_config
=$
(config_get_hook $
(zone_dir
${zone})/${config})
413 hook_config_exec
${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
417 function zone_configs_up
() {
418 zone_configs_cmd up $@
421 function zone_configs_down
() {
422 zone_configs_cmd down $@
425 function zone_has_ipv4
() {
435 starting|started|stopping|stopped
)
436 db_connection_update
${zone} ${action}
441 function zone_is_up
() {
447 function zone_is_down
() {