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 ###############################################################################
23 echo "HOOK=\"${HOOK}\""
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
37 if ! hook_parse_cmdline
"$@"; then
41 if ! zone_settings_write
"${zone}"; then
42 log ERROR
"Could not write settings for zone ${zone}"
54 if ! zone_settings_read
"${zone}"; then
55 log ERROR
"Could not read settings for zone ${zone}"
59 if ! hook_parse_cmdline
"$@"; then
63 if ! zone_settings_write
"${zone}"; then
64 log ERROR
"Could not write settings for zone ${zone}"
80 if device_is_up
${zone}; then
96 # This hook does not support a discovery
97 exit ${DISCOVER_NOT_SUPPORTED}
101 hook_parse_cmdline
() {
114 add|create|edit|rem|show
)
115 hook_port_
${action} "${zone}" "$@"
119 error
"Unrecognized argument: '${action}'"
128 return ${EXIT_NOT_SUPPORTED}
132 return ${EXIT_NOT_SUPPORTED}
136 return ${EXIT_NOT_SUPPORTED}
140 return ${EXIT_NOT_SUPPORTED}
143 hook_default_port_create
() {
149 port_create
"${port}"
153 hook_default_port_create
"$@"
156 hook_default_port_remove
() {
162 port_remove
"${port}"
166 hook_default_port_remove
"$@"
187 new|destroy|edit|show
)
188 hook_config_
${action} "${zone}" "$@"
192 error
"Unrecognized argument: '${action}'"
205 local hook_config
="${3}"
206 assert isset hook_config
210 local hook_zone
="$(zone_get_hook "${zone}")"
211 if ! hook_zone_exists
"${hook_zone}"; then
212 log ERROR
"Hook '${hook}' does not exist."
216 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
217 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
221 hook_config_exec
"${hook_config}" "${cmd}" "${zone}" "$@"
227 hook_config_cmd
"new" "$@"
230 hook_config_destroy
() {
233 # The id must be the id and not the hid.
238 # Check if we get a valid id
239 if ! zone_config_id_is_valid
${zone} ${id}; then
240 log ERROR
"ID: ${id} is not a valid id for zone ${zone}"
243 local hook
=$
(zone_config_get_hook_from_id
${zone} ${id})
246 # First we bring the hook down
247 hook_config_cmd
"down" "${zone}" "${hook}" "${hook}.${id}"
249 # If a hook_destroy function is implemented in the hook this function will be executed.
250 # If not a empty defined in header-config is executed.
251 if ! hook_config_cmd
"destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
253 # A better error message should printed inside the hook.
254 # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
255 log ERROR
"Could not destroy config with the follwoing id: ${id}"
259 # Now we delete the config of the zone
260 zone_config_settings_destroy
"${zone}" "${hook}.${id}"
266 # The id must be the id and not the hid.
271 # Check if we get a valid id
272 if ! zone_config_id_is_valid
${zone} ${id}; then
273 log ERROR
"ID: ${id} is not a valid id for zone ${zone}"
276 local hook
=$
(zone_config_get_hook_from_id
${zone} ${id})
279 hook_config_cmd
"edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
286 hook_ppp_write_config
() {
289 # Arguments: <zone> <filename>
292 hook_ppp_ip_pre_up
() {
297 if ! zone_exists
"${zone}"; then
298 log ERROR
"Zone '${zone}' does not exist."
302 ppp_common_ip_pre_up
"${zone}" "$@"
311 if ! zone_exists
"${zone}"; then
312 log ERROR
"Zone '${zone}' does not exist."
316 ppp_common_ipv4_up
"${zone}" "$@"
320 hook_ppp_ipv4_down
() {
325 if ! zone_exists
"${zone}"; then
326 log ERROR
"Zone '${zone}' does not exist."
330 ppp_common_ipv4_down
"${zone}" "$@"
339 if ! zone_exists
"${zone}"; then
340 error
"Zone '${zone}' does not exist."
344 ppp_common_ipv6_up
"${zone}" "$@"
348 hook_ppp_ipv6_down
() {
353 if ! zone_exists
"${zone}"; then
354 error
"Zone '${zone}' does not exist."
358 ppp_common_ipv6_down
"${zone}" "$@"