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)"
40 # Add the path prefix.
41 hook
="$(hook_dir ${type})/${hook}"
43 [ ! -d "${hook}" ] && [ -x "${hook}" ]
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 return ${EXIT_COMMAND_NOT_FOUND}
92 log ERROR
"Hook exited with an assertion error."
93 return ${EXIT_ERROR_ASSERT}
103 local dir
="$(hook_dir "${type}")"
107 for hook
in $
(list_directory
"${dir}"); do
108 if hook_exists
"${type}" "${hook}"; then
114 # The default help function.
116 # If no man page has been configured, we print an error message.
117 if [ -z "${HOOK_MANPAGE}" ]; then
118 error
"There is no help available for hook '${HOOK}'. Exiting."
122 cli_show_man
"${HOOK_MANPAGE}"
127 # Sets all settings in HOOK_SETTINGS to their DEFAULT_* values
128 hook_set_defaults
() {
130 for setting
in ${HOOK_SETTINGS}; do
131 local default
="DEFAULT_${setting}"
133 if isset
${default}; then
134 assign
"${setting}" "${!default}"
143 assert
[ -e "${config}" ]
152 hook_exists zone
"$@"
159 hook_zone_get_all
() {
163 hook_config_exists
() {
164 hook_exists config
"$@"
168 hook_exec config
"$@"
171 hook_config_get_all
() {
175 hook_valid_command
() {
181 hook_valid_command_config
"${cmd}"
185 hook_valid_command_port
"${cmd}"
189 hook_valid_command_zone
"${cmd}"
197 hook_valid_command_config
() {
201 new|destroy|edit|up|down|status|hid
)
209 hook_valid_command_port
() {
213 # Configuration hooks
219 create|remove|up|down
)
224 hotplug|hotplug_rename
)
237 hook_valid_command_zone
() {
241 # Configuration hooks
246 config_new|config_destroy|config_edit|config_show
)
261 port_attach|port_detach|port_edit|port_create|port_remove|port_status|port_up|port_down
)
276 ppp_ip_pre_up|ppp_ipv
[64]_up|ppp_ipv
[64]_down|ppp_write_config
)