]>
git.ipfire.org Git - people/arne_f/network.git/blob - functions.zone
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 hook_exec
${hook} up
${zone} $@
160 function zone_down
() {
164 if ! zone_exists
${zone}; then
165 error
"Zone '${zone}' does not exist."
169 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
171 if [ -z "${hook}" ]; then
172 error
"Config file did not provide any hook."
176 if ! hook_exists
${hook}; then
177 error
"Hook '${hook}' does not exist."
181 hook_exec
${hook} down
${zone} $@
184 function zone_status
() {
188 if ! zone_exists
${zone}; then
189 error
"Zone '${zone}' does not exist."
193 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
195 if [ -z "${hook}" ]; then
196 error
"Config file did not provide any hook."
200 if ! hook_exists
${hook}; then
201 error
"Hook '${hook}' does not exist."
205 hook_exec
${hook} status
${zone} $@
208 function zone_port
() {
212 if ! zone_exists
${zone}; then
213 error
"Zone '${zone}' does not exist."
217 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
219 if [ -z "${hook}" ]; then
220 error
"Config file did not provide any hook."
224 if ! hook_exists
${hook}; then
225 error
"Hook '${hook}' does not exist."
229 hook_exec
${hook} port
${zone} $@
232 function zone_config
() {
236 if ! zone_exists
${zone}; then
237 error
"Zone '${zone}' does not exist."
241 local hook
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
243 if [ -z "${hook}" ]; then
244 error
"Config file did not provide any hook."
248 if ! hook_exists
${hook}; then
249 error
"Hook '${hook}' does not exist."
253 hook_exec
${hook} config
${zone} $@
256 function zone_show
() {
260 echo " Type: $(zone_get_hook ${zone})"
264 function zones_show
() {
267 for zone
in $
(zones_get $@
); do
272 function zones_get_all
() {
274 for zone
in ${ZONE_DIR}/*; do
275 zone
=$
(basename ${zone})
276 zone_exists
${zone} ||
continue
282 function zones_get_local
() {
284 for zone
in $
(zones_get_all
); do
285 zone_is_local
${zone} && echo "${zone}"
289 function zones_get_nonlocal
() {
291 for zone
in $
(zones_get_all
); do
292 zone_is_local
${zone} ||
echo "${zone}"
296 function zones_get
() {
302 while [ $# -gt 0 ]; do
317 if zone_name_is_valid
${1}; then
318 zones
="${zones} ${1}"
320 warning
"Unrecognized argument '${1}'"
327 if [ -n "${zones}" ]; then
329 for zone
in ${zones}; do
330 zone_exists
${zone} && echo "${zone}"
335 if [ ${local} -eq 1 ] && [ ${remote} -eq 1 ]; then
337 elif [ ${local} -eq 1 ]; then
339 elif [ ${remote} -eq 1 ]; then
344 function zone_ports_list
() {
348 for port
in $
(zone_dir
${zone})/port.
*; do
349 [ -e "${port}" ] ||
continue
351 echo $
(basename ${port})
355 function zone_ports_cmd
() {
360 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
364 for port
in $
(zone_ports_list
${zone}); do
365 hook_port
=$
(config_get_hook $
(zone_dir
${zone})/${port})
367 hook_port_exec
${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
371 function zone_ports_up
() {
375 function zone_ports_down
() {
376 zone_ports_cmd down $@
379 function zone_configs_list
() {
383 for config
in $
(zone_dir
${zone})/config.
*; do
384 [ -e "${config}" ] ||
continue
386 echo $
(basename ${config})
390 function zone_configs_cmd
() {
395 local hook_zone
=$
(config_get_hook $
(zone_dir
${zone})/settings
)
399 for config
in $
(zone_configs_list
${zone}); do
400 hook_config
=$
(config_get_hook $
(zone_dir
${zone})/${config})
402 hook_config_exec
${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
406 function zone_configs_up
() {
407 zone_configs_cmd up $@
410 function zone_configs_down
() {
411 zone_configs_cmd down $@
414 function zone_has_ipv4
() {