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 settings_read $
(zone_dir
${zone})/settings
35 settings_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 return ${EXIT_NOT_SUPPORTED}
114 function hook_port_edit
() {
115 return ${EXIT_NOT_SUPPORTED}
118 function hook_port_remove
() {
119 return ${EXIT_NOT_SUPPORTED}
122 function hook_port_show
() {
126 function hook_port_status
() {
127 return ${EXIT_NOT_SUPPORTED}
130 function hook_port_up
() {
134 function hook_port_down
() {
138 function hook_config
() {
148 create|edit|rem|show
)
149 hook_config_
${action} "${zone}" "$@"
153 error
"Unrecognized argument: '${action}'"
159 function hook_config_cmd
() {
166 local hook_config
="${3}"
167 assert isset hook_config
171 local hook_zone
="$(zone_get_hook "${zone}")"
172 if ! hook_zone_exists
"${hook_zone}"; then
173 log ERROR
"Hook '${hook}' does not exist."
177 if ! hook_config_exists
"${hook_zone}" "${hook_config}"; then
178 log ERROR
"Hook '${hook_config}' is not supported for zone '${zone}'."
182 hook_zone_config_exec
"${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
185 function hook_config_create
() {
189 local hook_config
="${2}"
190 assert isset hook_config
194 if ! listmatch
"${hook_config}" $
(zone_get_supported_config_hooks
${zone}); then
195 log ERROR
"Zone '${zone}' does not support configuration of type '${hook_config}'."
199 local hook_zone
="$(zone_get_hook "${zone}")"
200 assert isset hook_zone
202 hook_zone_config_exec
"${hook_zone}" "${hook_config}" create "${zone}" "$@"
206 function hook_config_edit
() {
207 hook_config_cmd edit
"$@"
210 function hook_config_remove
() {
214 function hook_config_show
() {
218 function hook_ppp_write_config
() {
221 # Arguments: <zone> <filename>
224 function hook_ppp_ip_pre_up
() {
229 if ! zone_exists
"${zone}"; then
230 log ERROR
"Zone '${zone}' does not exist."
234 ppp_common_ip_pre_up
"${zone}" "$@"
238 function hook_ppp_ipv4_up
() {
243 if ! zone_exists
"${zone}"; then
244 log ERROR
"Zone '${zone}' does not exist."
248 ppp_common_ipv4_up
"${zone}" "$@"
252 function hook_ppp_ipv4_down
() {
257 if ! zone_exists
"${zone}"; then
258 log ERROR
"Zone '${zone}' does not exist."
262 ppp_common_ipv4_down
"${zone}" "$@"
266 function hook_ppp_ipv6_up
() {
271 if ! zone_exists
"${zone}"; then
272 error
"Zone '${zone}' does not exist."
276 ppp_common_ipv6_up
"${zone}" "$@"
280 function hook_ppp_ipv6_down
() {
285 if ! zone_exists
"${zone}"; then
286 error
"Zone '${zone}' does not exist."
290 ppp_common_ipv6_down
"${zone}" "$@"