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() {
73 ## Wrappers around the hook functions for zones
75 function hook_zone_exists() {
79 function hook_zone_port_exists() {
83 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
85 [ -x "$
(hook_dir zone
)/${hook_zone}.ports
/${hook_port}" ]
88 function hook_zone_config_exists() {
90 local hook_config=${2}
92 hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
94 [ -x "$
(hook_dir zone
)/${hook_zone}.configs
/${hook_config}" ]
97 function hook_zone_has_ports() {
100 [ -d "$
(hook_dir zone
)/${hook}.ports
" ]
103 function hook_zone_port_exists() {
107 function hook_zone_has_configs() {
110 [ -d "$
(hook_dir zone
)/${hook}.configs
" ]
113 function hook_zone_exec() {
117 function hook_zone_port_exec() {
122 if ! hook_exists zone ${hook_zone}; then
123 error "Hook
'${hook_zone}' does not exist.
"
127 if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
128 error "Port hook
'${hook_port}' does not exist.
"
132 exec_cmd $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@
135 function hook_zone_config_exec() {
137 local hook_config=${2}
140 if ! hook_zone_exists ${hook_zone}; then
141 error "Hook
'${hook_zone}' does not exist.
"
145 if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then
146 error "Config hook
'${hook_config}' does not exist.
"
150 exec_cmd $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@
153 function hook_zone_get_all() {
157 for hook in $(hook_dir zone)/*; do
158 hook=$(basename ${hook})
159 hook_zone_exists ${hook} && echo "${hook}"
163 function hook_zone_ports_get_all() {
166 if ! hook_exists zone ${hook}; then
167 error "Hook
'${hook}' does not exist.
"
172 for h in $(hook_dir zone)/${hook}.ports/*; do
179 function hook_device_exists() {
180 warning_log "Deprecated
function called hook_device_exists
"
182 hook_exists device $@