]>
Commit | Line | Data |
---|---|---|
1848564d MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
d61a01d4 MT |
22 | function hook_dir() { |
23 | local type=${1} | |
24 | ||
25 | echo "${HOOKS_DIR}/${type}s" | |
26 | } | |
27 | ||
1848564d | 28 | function hook_exists() { |
d61a01d4 MT |
29 | local type=${1} |
30 | local hook=${2} | |
1848564d | 31 | |
d61a01d4 | 32 | local hook_dir=$(hook_dir ${type}) |
1848564d | 33 | |
d61a01d4 MT |
34 | [ -d "${hook_dir}/${hook}" ] && return ${EXIT_ERROR} |
35 | ||
36 | [ -x "${hook_dir}/${hook}" ] | |
1848564d MT |
37 | } |
38 | ||
d61a01d4 MT |
39 | function hook_exec() { |
40 | local type=${1} | |
41 | local hook=${2} | |
42 | shift 2 | |
43 | ||
44 | if ! hook_exists ${type} ${hook}; then | |
45 | error "Hook '${hook}' does not exist." | |
46 | return ${EXIT_ERROR} | |
47 | fi | |
48 | ||
711ffac1 | 49 | exec_cmd $(hook_dir ${type})/${hook} $@ |
d61a01d4 MT |
50 | } |
51 | ||
52 | function config_get_hook() { | |
53 | local config=${1} | |
54 | ||
55 | ( | |
56 | . ${config} | |
57 | echo "${HOOK}" | |
58 | ) | |
59 | } | |
60 | ||
61 | ## Wrappers around the hook functions for zones | |
62 | ||
63 | function hook_zone_exists() { | |
64 | hook_exists zone $@ | |
65 | } | |
66 | ||
67 | function hook_zone_port_exists() { | |
1848564d MT |
68 | local hook_zone=${1} |
69 | local hook_port=${2} | |
70 | ||
d61a01d4 | 71 | hook_zone_exists ${hook_zone} || return ${EXIT_ERROR} |
1848564d | 72 | |
d61a01d4 | 73 | [ -x "$(hook_dir zone)/${hook_zone}.ports/${hook_port}" ] |
1848564d MT |
74 | } |
75 | ||
d61a01d4 | 76 | function hook_zone_config_exists() { |
1848564d MT |
77 | local hook_zone=${1} |
78 | local hook_config=${2} | |
79 | ||
d61a01d4 | 80 | hook_zone_exists ${hook_zone} || return ${EXIT_ERROR} |
1848564d | 81 | |
d61a01d4 | 82 | [ -x "$(hook_dir zone)/${hook_zone}.configs/${hook_config}" ] |
1848564d MT |
83 | } |
84 | ||
d61a01d4 | 85 | function hook_zone_has_ports() { |
1848564d MT |
86 | local hook=${1} |
87 | ||
d61a01d4 | 88 | [ -d "$(hook_dir zone)/${hook}.ports" ] |
1848564d MT |
89 | } |
90 | ||
711ffac1 MT |
91 | function hook_zone_port_exists() { |
92 | : # XXX WANTED | |
93 | } | |
94 | ||
d61a01d4 | 95 | function hook_zone_has_configs() { |
1848564d MT |
96 | local hook=${1} |
97 | ||
d61a01d4 | 98 | [ -d "$(hook_dir zone)/${hook}.configs" ] |
1848564d MT |
99 | } |
100 | ||
d61a01d4 MT |
101 | function hook_zone_exec() { |
102 | hook_exec zone $@ | |
1848564d MT |
103 | } |
104 | ||
d61a01d4 | 105 | function hook_zone_port_exec() { |
1848564d MT |
106 | local hook_zone=${1} |
107 | local hook_port=${2} | |
108 | shift 2 | |
109 | ||
d61a01d4 | 110 | if ! hook_exists zone ${hook_zone}; then |
1848564d MT |
111 | error "Hook '${hook_zone}' does not exist." |
112 | return ${EXIT_ERROR} | |
113 | fi | |
114 | ||
d61a01d4 | 115 | if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then |
1848564d MT |
116 | error "Port hook '${hook_port}' does not exist." |
117 | return ${EXIT_ERROR} | |
118 | fi | |
119 | ||
711ffac1 | 120 | exec_cmd $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@ |
1848564d MT |
121 | } |
122 | ||
d61a01d4 | 123 | function hook_zone_config_exec() { |
1848564d MT |
124 | local hook_zone=${1} |
125 | local hook_config=${2} | |
126 | shift 2 | |
127 | ||
d61a01d4 | 128 | if ! hook_zone_exists ${hook_zone}; then |
1848564d MT |
129 | error "Hook '${hook_zone}' does not exist." |
130 | return ${EXIT_ERROR} | |
131 | fi | |
132 | ||
d61a01d4 | 133 | if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then |
1848564d MT |
134 | error "Config hook '${hook_config}' does not exist." |
135 | return ${EXIT_ERROR} | |
136 | fi | |
137 | ||
711ffac1 | 138 | exec_cmd $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@ |
1848564d MT |
139 | } |
140 | ||
d61a01d4 | 141 | function hook_zone_get_all() { |
1848564d MT |
142 | local type=${1} |
143 | ||
144 | local hook | |
d61a01d4 | 145 | for hook in $(hook_dir zone)/*; do |
1848564d | 146 | hook=$(basename ${hook}) |
d61a01d4 | 147 | hook_zone_exists ${hook} && echo "${hook}" |
1848564d MT |
148 | done | sort |
149 | } | |
150 | ||
d61a01d4 | 151 | function hook_zone_ports_get_all() { |
1848564d MT |
152 | local hook=${1} |
153 | ||
d61a01d4 | 154 | if ! hook_exists zone ${hook}; then |
1848564d MT |
155 | error "Hook '${hook}' does not exist." |
156 | return ${EXIT_ERROR} | |
157 | fi | |
158 | ||
711ffac1 MT |
159 | local h |
160 | for h in $(hook_dir zone)/${hook}.ports/*; do | |
161 | h=$(basename ${h}) | |
1848564d | 162 | ## XXX executeable? |
711ffac1 | 163 | echo "${h}" |
1848564d MT |
164 | done | sort |
165 | } | |
711ffac1 MT |
166 | |
167 | function hook_device_exists() { | |
168 | hook_exists device $@ | |
169 | } |