]>
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 if [ -n "${type}" ]; then
29 echo "${HOOKS_DIR}${type}"
32 function hook_exists
() {
39 local hook_dir
=$
(hook_dir
${type})
41 [ -d "${hook_dir}/${hook}" ] && return ${EXIT_ERROR}
43 [ -x "${hook_dir}/${hook}" ]
46 function hook_exec() {
54 if ! hook_exists ${type} ${hook}; then
55 error "Hook
'${hook}' does not exist.
"
59 exec_cmd $(hook_dir ${type})/${hook} $@
62 function config_get_hook() {
66 assert [ -e "${config}" ]
74 ## Wrappers around the hook functions for zones
76 function hook_zone_exists() {
80 function hook_zone_port_exists() {
84 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
86 [ -x "$
(hook_dir zone
)/${hook_zone}.ports
/${hook_port}" ]
89 function hook_zone_config_exists() {
91 local hook_config=${2}
93 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
95 [ -x "$
(hook_dir zone
)/${hook_zone}.configs
/${hook_config}" ]
98 function hook_zone_has_ports() {
101 [ -d "$
(hook_dir zone
)/${hook}.ports
" ]
104 function hook_zone_port_exists() {
108 function hook_zone_has_configs() {
111 [ -d "$
(hook_dir zone
)/${hook}.configs
" ]
114 function hook_zone_exec() {
118 function hook_zone_port_exec() {
123 if ! hook_exists zone ${hook_zone}; then
124 error "Hook
'${hook_zone}' does not exist.
"
128 if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
129 error "Port hook
'${hook_port}' does not exist.
"
133 exec_cmd $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@
136 function hook_zone_config_exec() {
138 local hook_config=${2}
141 assert isset hook_zone
142 assert isset hook_config
144 if ! hook_zone_exists ${hook_zone}; then
145 error "Hook
'${hook_zone}' does not exist.
"
149 if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then
150 error "Config hook
'${hook_config}' does not exist.
"
154 exec_cmd $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@
157 function hook_zone_get_all() {
161 for hook in $(hook_dir zone)/*; do
162 hook=$(basename ${hook})
163 hook_zone_exists ${hook} && echo "${hook}"
167 function hook_zone_ports_get_all() {
170 if ! hook_exists zone ${hook}; then
171 error "Hook
'${hook}' does not exist.
"
175 # If the zone hook has got no ports we exit silently
176 if ! hook_zone_has_ports ${hook}; then
181 for h in $(hook_dir zone)/${hook}.ports/*; do
183 if hook_zone_port_exists ${hook} ${h}; then
189 function hook_zone_configs_get_all() {
192 if ! hook_exists zone ${hook}; then
193 error "Hook
'${hook}' does not exist.
"
197 # If the zone hook has got no configurations we exit silently
198 if ! hook_zone_has_configs ${hook}; then
203 for h in $(hook_dir zone)/${hook}.configs/*; do
205 if hook_zone_config_exists ${hook} ${h}; then