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 if [ -n "${type}" ]; then
29 echo "${NETWORK_HOOKS_DIR}${type}"
31 NETWORK_HOOKS_DIR_ZONES
="$(hook_dir zone)"
33 function hook_exists
() {
40 # Add the path prefix.
41 hook
="$(hook_dir ${type})/${hook}"
43 [ ! -d "${hook}" ] && [ -x "${hook}" ]
46 function hook_exec
() {
56 assert hook_exists
"${type}" "${hook}"
58 # For performance reasons, all hooks are executed
59 # in a subshell and so will inherit the currently
60 # running environment.
62 # Set the name of the hook.
63 HOOK
=$
(basename ${hook})
65 # Source the code of the hook.
66 source "$(hook_dir ${type})/${hook}"
68 # Make sure HOOK is still properly set.
71 # Execute the requested command.
76 if [ ${ret} -eq ${EXIT_ERROR_ASSERT} ]; then
77 log ERROR
"Hook exited with an assertion error."
84 function config_get_hook
() {
88 assert
[ -e "${config}" ]
96 function hook_zone_exists
() {
100 function hook_zone_port_exists
() {
104 hook_exists zone
"${hook_zone}.ports/${hook_port}"
107 function hook_zone_config_exists
() {
109 local hook_config
=${2}
111 hook_exists zone
"${hook_zone}.configs/${hook_config}"
114 function hook_zone_has_ports
() {
117 [ -d "${NETWORK_HOOKS_DIR_ZONES}/${hook}.ports" ]
120 function hook_zone_has_configs
() {
123 [ -d "${NETWORK_HOOKS_DIR_ZONES}/${hook}.configs" ]
126 function hook_zone_exec
() {
130 function hook_zone_port_exec
() {
135 hook_zone_exec
"${hook_zone}.ports/${hook_port}" $@
138 function hook_zone_config_exec
() {
143 hook_zone_exec
"${hook_zone}.configs/${hook_port}" $@
146 function hook_zone_get_all
() {
150 for hook
in $
(hook_dir zone
)/*; do
151 hook
=$
(basename ${hook})
152 hook_zone_exists
${hook} && echo "${hook}"
156 function hook_zone_ports_get_all
() {
159 if ! hook_exists zone
${hook}; then
160 error
"Hook '${hook}' does not exist."
164 # If the zone hook has got no ports we exit silently
165 if ! hook_zone_has_ports
${hook}; then
170 for h
in $
(hook_dir zone
)/${hook}.ports
/*; do
172 if hook_zone_port_exists
${hook} ${h}; then
178 function hook_zone_configs_get_all
() {
181 if ! hook_exists zone
${hook}; then
182 error
"Hook '${hook}' does not exist."
186 # If the zone hook has got no configurations we exit silently
187 if ! hook_zone_has_configs
${hook}; then
192 for h
in $
(hook_dir zone
)/${hook}.configs
/*; do
194 if hook_zone_config_exists
${hook} ${h}; then