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 if [[ ${zone} =~ ^red
[0-9]{1,5} ]]; then
60 function zone_get_hook
() {
63 config_get_hook $
(zone_dir
${zone})/settings
66 function zone_create
() {
71 if ! zone_name_is_valid
${zone}; then
72 error
"Zone name '${zone}' is not valid."
76 if zone_exists
${zone}; then
77 error
"Zone '${zone}' does already exist."
81 if ! hook_exists
${hook}; then
82 error
"Hook '${hook}' does not exist."
86 mkdir
-p $
(zone_dir
${zone})
88 hook_exec
${hook} create
${zone} $@
91 # Maybe the zone create hook did not exit correctly.
92 # If this is the case we remove the created zone immediately.
93 if [ "${ret}" = "${EXIT_ERROR}" ]; then
98 function zone_edit
() {
102 if ! zone_exists
${zone}; then
103 error
"Zone '${zone}' does not exist."
107 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
109 if [ -z "${hook}" ]; then
110 error
"Config file did not provide any hook."
114 if ! hook_exists
${hook}; then
115 error
"Hook '${hook}' does not exist."
119 hook_exec
${hook} edit
${zone} $@
122 function zone_remove
() {
126 if ! zone_exists
${zone}; then
127 error
"Zone '${zone}' does not exist."
131 # XXX Tear this down here?
133 rm -rf $
(zone_dir
${zone})
140 if ! zone_exists
${zone}; then
141 error
"Zone '${zone}' does not exist."
145 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
147 if [ -z "${hook}" ]; then
148 error
"Config file did not provide any hook."
152 if ! hook_exists
${hook}; then
153 error
"Hook '${hook}' does not exist."
157 zone_db
${zone} starting
159 hook_exec
${hook} up
${zone} $@
161 zone_db
${zone} started
164 function zone_down
() {
168 if ! zone_exists
${zone}; then
169 error
"Zone '${zone}' does not exist."
173 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
175 if [ -z "${hook}" ]; then
176 error
"Config file did not provide any hook."
180 if ! hook_exists
${hook}; then
181 error
"Hook '${hook}' does not exist."
185 zone_db
${zone} stopping
187 hook_exec
${hook} down
${zone} $@
189 zone_db
${zone} stopped
192 function zone_status
() {
196 if ! zone_exists
${zone}; then
197 error
"Zone '${zone}' does not exist."
201 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
203 if [ -z "${hook}" ]; then
204 error
"Config file did not provide any hook."
208 if ! hook_exists
${hook}; then
209 error
"Hook '${hook}' does not exist."
213 hook_exec
${hook} status
${zone} $@
216 function zone_port
() {
220 if ! zone_exists
${zone}; then
221 error
"Zone '${zone}' does not exist."
225 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
227 if [ -z "${hook}" ]; then
228 error
"Config file did not provide any hook."
232 if ! hook_exists
${hook}; then
233 error
"Hook '${hook}' does not exist."
237 hook_exec
${hook} port
${zone} $@
240 function zone_config
() {
244 if ! zone_exists
${zone}; then
245 error
"Zone '${zone}' does not exist."
249 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
251 if [ -z "${hook}" ]; then
252 error
"Config file did not provide any hook."
256 if ! hook_exists
${hook}; then
257 error
"Hook '${hook}' does not exist."
261 hook_exec
${hook} config
${zone} $@
264 function zone_show
() {
268 echo " Type: $(zone_get_hook ${zone})"
272 function zones_show
() {
275 for zone
in $
(zones_get $@
); do
280 function zones_get_all
() {
282 for zone
in ${ZONE_DIR}/*; do
283 zone
=$
(basename ${zone})
284 zone_exists
${zone} ||
continue
290 function zones_get_local
() {
292 for zone
in $
(zones_get_all
); do
293 zone_is_local
${zone} && echo "${zone}"
297 function zones_get_nonlocal
() {
299 for zone
in $
(zones_get_all
); do
300 zone_is_local
${zone} ||
echo "${zone}"
304 function zones_get
() {
310 while [ $# -gt 0 ]; do
325 if zone_name_is_valid
${1}; then
326 zones
="${zones} ${1}"
328 warning
"Unrecognized argument '${1}'"
335 if [ -n "${zones}" ]; then
337 for zone
in ${zones}; do
338 zone_exists
${zone} && echo "${zone}"
343 if [ ${local} -eq 1 ] && [ ${remote} -eq 1 ]; then
345 elif [ ${local} -eq 1 ]; then
347 elif [ ${remote} -eq 1 ]; then
352 function zone_ports_list
() {
356 for port
in $
(zone_dir
${zone})/port.
*; do
357 [ -e "${port}" ] ||
continue
359 echo $
(basename ${port})
363 function zone_ports_cmd
() {
368 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
372 for port
in $
(zone_ports_list
${zone}); do
373 hook_port
=$
(config_get_hook $
(zone_dir
${zone})/${port})
375 hook_port_exec
${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
379 function zone_ports_up
() {
383 function zone_ports_down
() {
384 zone_ports_cmd down $@
387 function zone_configs_list
() {
391 for config
in $
(zone_dir
${zone})/config.
*; do
392 [ -e "${config}" ] ||
continue
394 echo $
(basename ${config})
398 function zone_configs_cmd
() {
403 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
407 for config
in $
(zone_configs_list
${zone}); do
408 hook_config
=$
(config_get_hook $
(zone_dir
${zone})/${config})
410 hook_config_exec
${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
414 function zone_configs_up
() {
415 zone_configs_cmd up $@
418 function zone_configs_down
() {
419 zone_configs_cmd down $@
422 function zone_has_ipv4
() {
432 starting|started|stopping|stopped
)
433 db_connection_update
${zone} ${action}