]>
git.ipfire.org Git - network.git/blob - functions.hook
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_exists
() {
25 [ -d "${HOOKS_DIR}/${hook}" ] && return ${EXIT_ERROR}
27 [ -x "${HOOKS_DIR}/${hook}" ]
30 function hook_port_exists() {
34 hook_exists ${hook_zone} || return ${EXIT_ERROR}
36 [ -x "${HOOKS_DIR}/${hook_zone}.ports/${hook_port}" ]
39 function hook_config_exists() {
41 local hook_config=${2}
43 hook_exists ${hook_zone} || return ${EXIT_ERROR}
45 [ -x "${HOOKS_DIR}/${hook_zone}.configs/${hook_config}" ]
48 function hook_has_ports() {
51 [ -d "${HOOKS_DIR}/${hook}.ports
" ]
54 function hook_has_configs() {
57 [ -d "${HOOKS_DIR}/${hook}.configs
" ]
60 function hook_exec() {
64 if ! hook_exists ${hook}; then
65 error "Hook
'${hook}' does not exist.
"
69 ${SHELL} ${HOOKS_DIR}/${hook} $@
72 function hook_port_exec() {
77 if ! hook_exists ${hook_zone}; then
78 error "Hook
'${hook_zone}' does not exist.
"
82 if ! hook_port_exists ${hook_zone} ${hook_port}; then
83 error "Port hook
'${hook_port}' does not exist.
"
87 ${SHELL} ${HOOKS_DIR}/${hook_zone}.ports/${hook_port} $@
90 function hook_config_exec() {
92 local hook_config=${2}
95 if ! hook_exists ${hook_zone}; then
96 error "Hook
'${hook_zone}' does not exist.
"
100 if ! hook_config_exists ${hook_zone} ${hook_config}; then
101 error "Config hook
'${hook_config}' does not exist.
"
105 ${SHELL} ${HOOKS_DIR}/${hook_zone}.configs/${hook_config} $@
108 function hooks_get_all() {
112 for hook in ${HOOKS_DIR}/*; do
113 hook=$(basename ${hook})
114 hook_exists ${hook} && echo "${hook}"
118 function hook_ports_get_all() {
121 if ! hook_exists ${hook}; then
122 error "Hook
'${hook}' does not exist.
"
127 for hook in ${HOOKS_DIR}/${zone}.ports/*; do
128 hook=$(basename ${hook})
134 function config_get_hook() {