#!/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_create() {
local zone="${1}"
assert isset zone
shift
config_read $(zone_dir ${zone})/settings
hook_parse_cmdline $@
config_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}
}
# The default help function.
function hook_help() {
# If no man page has been configured, we print an error message.
if [ -z "${HOOK_MANPAGE}" ]; then
error "There is no help available for hook '${HOOK}'. Exiting."
exit ${EXIT_ERROR}
fi
cli_show_man ${HOOK_MANPAGE}
}
# 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_remove() {
return ${EXIT_NOT_SUPPORTED}
}
function hook_port_show() {
cmd_not_implemented
}
function hook_port_status() {
return ${EXIT_NOT_SUPPORTED}
}
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_zone_config_exec "${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
}
function hook_config_create() {
local zone="${1}"
assert isset zone
local hook_config="${2}"
assert isset hook_config
shift 2
if ! listmatch "${hook_config}" $(zone_get_supported_config_hooks ${zone}); then
log ERROR "Zone '${zone}' does not support configuration of type '${hook_config}'."
exit ${EXIT_ERROR}
fi
local hook_zone="$(zone_get_hook "${zone}")"
assert isset hook_zone
hook_zone_config_exec "${hook_zone}" "${hook_config}" create "${zone}" "$@"
exit $?
}
function hook_config_edit() {
hook_config_cmd edit "$@"
}
function hook_config_remove() {
cmd_not_implemented
}
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 $?
}