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 # Dummy functions being overlayed by hooks
128 hook_check_settings
() {
132 hook_check_config_settings
() {
136 hook_check_port_settings
() {
140 # Sets all settings in HOOK_SETTINGS to their DEFAULT_* values
141 hook_set_defaults
() {
143 for setting
in ${HOOK_SETTINGS[*]}; do
144 local default
="DEFAULT_${setting}"
146 # Sets the default or empty
147 assign
"${setting}" "${!default}"
155 assert
[ -e "${config}" ]
164 hook_exists zone
"$@"
171 hook_zone_get_all
() {
175 hook_config_exists
() {
176 hook_exists config
"$@"
180 hook_exec config
"$@"
183 hook_config_get_all
() {
187 hook_valid_command
() {
193 hook_valid_command_config
"${cmd}"
197 hook_valid_command_port
"${cmd}"
201 hook_valid_command_zone
"${cmd}"
209 hook_valid_command_config
() {
213 new|destroy|edit|up|down|status|hid
)
221 hook_valid_command_port
() {
225 # Configuration hooks
231 create|remove|up|down
)
236 hotplug|hotplug_rename
)
249 hook_valid_command_zone
() {
253 # Configuration hooks
258 config_new|config_destroy|config_edit|config_show
)
273 port_attach|port_detach|port_edit|port_create|port_remove|port_status|port_up|port_down
)
288 ppp_ip_pre_up|ppp_ipv
[64]_up|ppp_ipv
[64]_down|ppp_write_config
)