]>
git.ipfire.org Git - people/arne_f/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 ###############################################################################
25 echo "${HOOKS_DIR}/${type}s"
28 function hook_exists
() {
32 local hook_dir
=$
(hook_dir
${type})
34 [ -d "${hook_dir}/${hook}" ] && return ${EXIT_ERROR}
36 [ -x "${hook_dir}/${hook}" ]
39 function hook_exec() {
44 if ! hook_exists ${type} ${hook}; then
45 error "Hook
'${hook}' does not exist.
"
49 ${SHELL} $(hook_dir ${type})/${hook} $@
52 function config_get_hook() {
61 ## Wrappers around the hook functions for zones
63 function hook_zone_exists() {
67 function hook_zone_port_exists() {
71 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
73 [ -x "$
(hook_dir zone
)/${hook_zone}.ports
/${hook_port}" ]
76 function hook_zone_config_exists() {
78 local hook_config=${2}
80 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
82 [ -x "$
(hook_dir zone
)/${hook_zone}.configs
/${hook_config}" ]
85 function hook_zone_has_ports() {
88 [ -d "$
(hook_dir zone
)/${hook}.ports
" ]
91 function hook_zone_has_configs() {
94 [ -d "$
(hook_dir zone
)/${hook}.configs
" ]
97 function hook_zone_exec() {
101 function hook_zone_port_exec() {
106 if ! hook_exists zone ${hook_zone}; then
107 error "Hook
'${hook_zone}' does not exist.
"
111 if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
112 error "Port hook
'${hook_port}' does not exist.
"
116 ${SHELL} $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@
119 function hook_zone_config_exec() {
121 local hook_config=${2}
124 if ! hook_zone_exists ${hook_zone}; then
125 error "Hook
'${hook_zone}' does not exist.
"
129 if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then
130 error "Config hook
'${hook_config}' does not exist.
"
134 ${SHELL} $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@
137 function hook_zone_get_all() {
141 for hook in $(hook_dir zone)/*; do
142 hook=$(basename ${hook})
143 hook_zone_exists ${hook} && echo "${hook}"
147 function hook_zone_ports_get_all() {
150 if ! hook_exists zone ${hook}; then
151 error "Hook
'${hook}' does not exist.
"
156 for hook in $(hook_dir zone)/${zone}.ports/*; do
157 hook=$(basename ${hook})