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}"
59 # Complete the hook command by prepending "hook_"
60 local hook_cmd
="hook_${cmd}"
62 # Check if the hook action is valid.
63 assert hook_valid_command
"${type}" "${cmd}"
65 local hook_path
="$(hook_dir ${type})/${hook}"
67 # For performance reasons, all hooks are executed
68 # in a subshell and so will inherit the currently
69 # running environment.
71 # Set the name of the hook.
72 HOOK
=$
(basename ${hook})
74 # Source the code of the hook.
77 # Make sure HOOK is still properly set.
80 # Execute the requested command.
86 ${EXIT_COMMAND_NOT_FOUND}|
${EXIT_NOT_SUPPORTED})
87 log ERROR
"Hook '${hook}' does not implement the method '${cmd}':"
88 log ERROR
" arguments: $@"
89 exit ${EXIT_COMMAND_NOT_FOUND}
92 log ERROR
"Hook exited with an assertion error."
93 exit ${EXIT_ERROR_ASSERT}
100 function hook_list
() {
103 local dir
="$(hook_dir "${type}")"
107 for hook
in ${dir}/*; do
108 hook
="$(basename "${hook}")"
110 if hook_exists
"${type}" "${hook}"; then
116 # The default help function.
117 function hook_help
() {
118 # If no man page has been configured, we print an error message.
119 if [ -z "${HOOK_MANPAGE}" ]; then
120 error
"There is no help available for hook '${HOOK}'. Exiting."
124 cli_show_man
"${HOOK_MANPAGE}"
129 function config_get_hook
() {
133 assert
[ -e "${config}" ]
141 function hook_zone_exists
() {
145 function hook_zone_exec
() {
149 function hook_zone_get_all
() {
153 function hook_config_exists
() {
154 hook_exists config $@
157 function hook_config_exec
() {
161 function hook_config_get_all
() {
165 function hook_valid_command
() {
171 hook_valid_command_config
"${cmd}"
175 hook_valid_command_port
"${cmd}"
179 hook_valid_command_zone
"${cmd}"
187 function hook_valid_command_config
() {
191 create|remove|edit|up|down|status
)
199 function hook_valid_command_port
() {
203 # Configuration hooks
209 create|remove|up|down
)
214 hotplug|hotplug_rename
)
227 function hook_valid_command_zone
() {
231 # Configuration hooks
236 config_create|config_edit|config_remove|config_show
)
251 port_add|port_edit|port_create|port_remove|port_show|port_status|port_up|port_down
)
266 ppp_ip_pre_up|ppp_ipv
[64]_up|ppp_ipv
[64]_down|ppp_write_config
)