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)"
35 assert isoneof
type port zone
37 local dir
="$(hook_dir "${type}")"
41 for hook
in ${dir}/*; do
42 hook_exists
"${hook}" ||
continue
56 # Add the path prefix.
57 hook
="$(hook_dir ${type})/${hook}"
59 [ ! -d "${hook}" ] && [ -x "${hook}" ]
72 assert hook_exists
"${type}" "${hook}"
75 # Complete the hook command by prepending "hook_"
76 local hook_cmd
="hook_${cmd}"
78 # Check if the hook action is valid.
79 assert hook_valid_command
"${type}" "${cmd}"
81 local hook_path
="$(hook_dir ${type})/${hook}"
83 # For performance reasons, all hooks are executed
84 # in a subshell and so will inherit the currently
85 # running environment.
87 # Set the name of the hook.
88 HOOK
=$
(basename ${hook})
90 # Source the code of the hook.
93 # Make sure HOOK is still properly set.
96 # Execute the requested command.
102 ${EXIT_COMMAND_NOT_FOUND}|
${EXIT_NOT_SUPPORTED})
103 log ERROR
"Hook '${hook}' does not implement the method '${cmd}':"
104 log ERROR
" arguments: $@"
105 return ${EXIT_COMMAND_NOT_FOUND}
107 ${EXIT_ERROR_ASSERT})
108 log ERROR
"Hook exited with an assertion error."
109 return ${EXIT_ERROR_ASSERT}
119 local dir
="$(hook_dir "${type}")"
123 for hook
in ${dir}/*; do
124 hook
="$(basename "${hook}")"
126 if hook_exists
"${type}" "${hook}"; then
132 # The default help function.
134 # If no man page has been configured, we print an error message.
135 if [ -z "${HOOK_MANPAGE}" ]; then
136 error
"There is no help available for hook '${HOOK}'. Exiting."
140 cli_show_man
"${HOOK_MANPAGE}"
149 assert
[ -e "${config}" ]
165 hook_zone_get_all
() {
169 hook_config_exists
() {
170 hook_exists config $@
177 hook_config_get_all
() {
181 hook_valid_command
() {
187 hook_valid_command_config
"${cmd}"
191 hook_valid_command_port
"${cmd}"
195 hook_valid_command_zone
"${cmd}"
203 hook_valid_command_config
() {
207 new|destroy|edit|up|down|status|hid
)
215 hook_valid_command_port
() {
219 # Configuration hooks
225 create|remove|up|down
)
230 hotplug|hotplug_rename
)
243 hook_valid_command_zone
() {
247 # Configuration hooks
252 config_new|config_destroy|config_edit|config_show
)
267 port_attach|port_detach|port_edit|port_create|port_remove|port_status|port_up|port_down
)
282 ppp_ip_pre_up|ppp_ipv
[64]_up|ppp_ipv
[64]_down|ppp_write_config
)