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 ###############################################################################
22 function hook_info
() {
23 echo "HOOK=\"${HOOK}\""
26 function hook_create
() {
31 config_read $
(zone_dir
${zone})/settings
35 config_write $
(zone_dir
${zone})/settings
${HOOK_SETTINGS}
40 function hook_edit
() {
44 function hook_remove
() {
48 function hook_status
() {
52 if device_is_up
${zone}; then
63 function hook_down
() {
67 function hook_discover
() {
68 # This hook does not support a discovery
69 exit ${DISCOVER_NOT_SUPPORTED}
72 # The default help function.
73 function hook_help
() {
74 # If no man page has been configured, we print an error message.
75 if [ -z "${HOOK_MANPAGE}" ]; then
76 error
"There is no help available for hook '${HOOK}'. Exiting."
80 cli_show_man
${HOOK_MANPAGE}
84 function hook_parse_cmdline
() {
88 function hook_port
() {
97 add|create|edit|rem|show
)
98 hook_port_
${action} "${zone}" $@
102 error
"Unrecognized argument: '${action}'"
110 function hook_port_add
() {
111 hook_port_cmd add
"$@"
114 function hook_port_edit
() {
115 hook_port_cmd edit
"$@"
118 function hook_port_rem
() {
119 hook_port_cmd remove
"$@"
122 function hook_port_show
() {
126 function hook_port_status
() {
127 hook_port_cmd status
"$@"
130 function hook_port_cmd
() {
142 local hook_zone
="$(zone_get_hook ${zone})"
143 assert isset hook_zone
145 local hook_port
="$(port_get_hook ${port})"
146 assert isset hook_port
148 if ! listmatch
"${hook_port}" $
(zone_get_supported_port_hooks
${zone}); then
149 log ERROR
"Zone '${zone}' does not support port of type '${hook_port}'."
153 hook_zone_port_exec
"${hook_zone}" "${hook_port}" "${cmd}" "${zone}" "${port}" "$@"
157 function hook_port_up
() {
158 hook_port_cmd up
"$@"
161 function hook_port_down
() {
162 hook_port_cmd down
"$@"
165 function hook_config
() {
175 create|edit|rem|show
)
176 hook_config_
${action} "${zone}" "$@"
180 error
"Unrecognized argument: '${action}'"
186 function hook_config_cmd
() {
193 local hook_config
="${3}"
194 assert isset hook_config
198 local hook_zone
="$(zone_get_hook "${zone}")"
199 if ! hook_zone_exists
"${hook_zone}"; then
200 log ERROR
"Hook '${hook}' does not exist."
204 if ! hook_config_exists
"${hook_zone}" "${hook_config}"; then
205 log ERROR
"Hook '${hook_config}' is not supported for zone '${zone}'."
209 hook_zone_config_exec
"${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
212 function hook_config_create
() {
216 local hook_config
="${2}"
217 assert isset hook_config
221 if ! listmatch
"${hook_config}" $
(zone_get_supported_config_hooks
${zone}); then
222 log ERROR
"Zone '${zone}' does not support configuration of type '${hook_config}'."
226 local hook_zone
="$(zone_get_hook "${zone}")"
227 assert isset hook_zone
229 hook_zone_config_exec
"${hook_zone}" "${hook_config}" create "${zone}" "$@"
233 function hook_config_edit
() {
234 hook_config_cmd edit
"$@"
237 function hook_config_remove
() {
241 function hook_config_show
() {
245 function hook_ppp_write_config
() {
248 # Arguments: <zone> <filename>
251 function hook_ppp_ip_pre_up
() {
256 if ! zone_exists
"${zone}"; then
257 log ERROR
"Zone '${zone}' does not exist."
261 ppp_common_ip_pre_up
"${zone}" "$@"
265 function hook_ppp_ipv4_up
() {
270 if ! zone_exists
"${zone}"; then
271 log ERROR
"Zone '${zone}' does not exist."
275 ppp_common_ipv4_up
"${zone}" "$@"
279 function hook_ppp_ipv4_down
() {
284 if ! zone_exists
"${zone}"; then
285 log ERROR
"Zone '${zone}' does not exist."
289 ppp_common_ipv4_down
"${zone}" "$@"
293 function hook_ppp_ipv6_up
() {
298 if ! zone_exists
"${zone}"; then
299 error
"Zone '${zone}' does not exist."
303 ppp_common_ipv6_up
"${zone}" "$@"
307 function hook_ppp_ipv6_down
() {
312 if ! zone_exists
"${zone}"; then
313 error
"Zone '${zone}' does not exist."
317 ppp_common_ipv6_down
"${zone}" "$@"