#!/bin/bash
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see . #
# #
###############################################################################
function hook_info() {
echo "HOOK=\"${HOOK}\""
}
function hook_hotplug() {
# If the hook does not handle the hotplug event, it
# must return EXIT_NOT_HANDLED.
exit ${EXIT_NOT_HANDLED}
}
function hook_create() {
local zone="${1}"
assert isset zone
shift
settings_read $(zone_dir ${zone})/settings
hook_parse_cmdline $@
settings_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
exit ${EXIT_OK}
}
function hook_edit() {
hook_create $@
}
function hook_remove() {
cmd_not_implemented
}
function hook_status() {
local zone="${1}"
assert isset zone
if device_is_up ${zone}; then
exit ${STATUS_UP}
fi
exit ${STATUS_DOWN}
}
function hook_up() {
cmd_not_implemented
}
function hook_down() {
cmd_not_implemented
}
function hook_discover() {
# This hook does not support a discovery
exit ${DISCOVER_NOT_SUPPORTED}
}
# Do nothing
function hook_parse_cmdline() {
return ${EXIT_OK}
}
function hook_port() {
local zone="${1}"
assert isset zone
local action="${2}"
shift 2
local ret
case "${action}" in
add|create|edit|rem|show)
hook_port_${action} "${zone}" $@
ret=$?
;;
*)
error "Unrecognized argument: '${action}'"
exit ${EXIT_ERROR}
;;
esac
exit ${ret}
}
function hook_port_add() {
return ${EXIT_NOT_SUPPORTED}
}
function hook_port_edit() {
return ${EXIT_NOT_SUPPORTED}
}
function hook_port_destroy() {
return ${EXIT_NOT_SUPPORTED}
}
function hook_port_show() {
cmd_not_implemented
}
function hook_port_status() {
return ${EXIT_NOT_SUPPORTED}
}
function hook_default_port_create() {
assert [ $# -ge 2 ]
local zone="${1}"
local port="${2}"
port_create "${port}"
}
function hook_port_create() {
hook_default_port_create $@
}
function hook_default_port_remove() {
assert [ $# -ge 2 ]
local zone="${1}"
local port="${2}"
port_remove "${port}"
}
function hook_port_remove() {
hook_default_port_remove $@
}
function hook_port_up() {
cmd_not_implemented
}
function hook_port_down() {
cmd_not_implemented
}
function hook_config() {
local zone="${1}"
assert isset zone
local action="${2}"
assert isset action
shift 2
local ret
case "${action}" in
create|edit|rem|show)
hook_config_${action} "${zone}" "$@"
exit $?
;;
*)
error "Unrecognized argument: '${action}'"
exit ${EXIT_ERROR}
;;
esac
}
function hook_config_cmd() {
local cmd="${1}"
assert isset cmd
local zone="${2}"
assert isset zone
local hook_config="${3}"
assert isset hook_config
shift 3
local hook_zone="$(zone_get_hook "${zone}")"
if ! hook_zone_exists "${hook_zone}"; then
log ERROR "Hook '${hook}' does not exist."
exit ${EXIT_ERROR}
fi
#if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
# log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
# exit ${EXIT_ERROR}
#fi
hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
}
function hook_config_create() {
assert [ $# -gt 2 ]
hook_config_cmd "create" "$@"
}
function hook_config_edit() {
hook_config_cmd "edit" "$@"
}
function hook_config_remove() {
hook_config_cmd "remove" "$@"
}
function hook_config_show() {
cmd_not_implemented
}
function hook_ppp_write_config() {
cmd_not_implemented
# Arguments:
}
function hook_ppp_ip_pre_up() {
local zone="${1}"
assert isset zone
shift
if ! zone_exists "${zone}"; then
log ERROR "Zone '${zone}' does not exist."
exit ${EXIT_ERROR}
fi
ppp_common_ip_pre_up "${zone}" "$@"
exit $?
}
function hook_ppp_ipv4_up() {
local zone="${1}"
assert isset zone
shift
if ! zone_exists "${zone}"; then
log ERROR "Zone '${zone}' does not exist."
exit ${EXIT_ERROR}
fi
ppp_common_ipv4_up "${zone}" "$@"
exit $?
}
function hook_ppp_ipv4_down() {
local zone="${1}"
assert isset zone
shift
if ! zone_exists "${zone}"; then
log ERROR "Zone '${zone}' does not exist."
exit ${EXIT_ERROR}
fi
ppp_common_ipv4_down "${zone}" "$@"
exit $?
}
function hook_ppp_ipv6_up() {
local zone="${1}"
assert isset zone
shift
if ! zone_exists "${zone}"; then
error "Zone '${zone}' does not exist."
exit ${EXIT_ERROR}
fi
ppp_common_ipv6_up "${zone}" "$@"
exit $?
}
function hook_ppp_ipv6_down() {
local zone="${1}"
assert isset zone
shift
if ! zone_exists "${zone}"; then
error "Zone '${zone}' does not exist."
exit ${EXIT_ERROR}
fi
ppp_common_ipv6_down "${zone}" "$@"
exit $?
}