]>
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 | ############################################################################### | |
1848564d | 21 | |
2181765d | 22 | function hook_info() { |
1848564d MT |
23 | echo "HOOK=\"${HOOK}\"" |
24 | } | |
25 | ||
2181765d MT |
26 | function hook_create() { |
27 | local zone="${1}" | |
28 | assert isset zone | |
1848564d MT |
29 | shift |
30 | ||
e5f78859 | 31 | config_read $(zone_dir ${zone})/settings |
1848564d | 32 | |
2181765d | 33 | hook_parse_cmdline $@ |
1848564d | 34 | |
e5f78859 | 35 | config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS} |
1848564d MT |
36 | |
37 | exit ${EXIT_OK} | |
38 | } | |
39 | ||
2181765d MT |
40 | function hook_edit() { |
41 | hook_create $@ | |
1848564d MT |
42 | } |
43 | ||
2181765d MT |
44 | function hook_remove() { |
45 | cmd_not_implemented | |
1848564d MT |
46 | } |
47 | ||
2181765d MT |
48 | function hook_status() { |
49 | local zone="${1}" | |
50 | assert isset zone | |
1848564d MT |
51 | |
52 | if device_is_up ${zone}; then | |
53 | exit ${STATUS_UP} | |
54 | fi | |
55 | ||
56 | exit ${STATUS_DOWN} | |
57 | } | |
58 | ||
2181765d MT |
59 | function hook_up() { |
60 | cmd_not_implemented | |
1848564d MT |
61 | } |
62 | ||
2181765d MT |
63 | function hook_down() { |
64 | cmd_not_implemented | |
1848564d MT |
65 | } |
66 | ||
2181765d | 67 | function hook_discover() { |
1848564d MT |
68 | # This hook does not support a discovery |
69 | exit ${DISCOVER_NOT_SUPPORTED} | |
70 | } | |
71 | ||
85afd775 | 72 | # The default help function. |
2181765d | 73 | function hook_help() { |
85afd775 MT |
74 | # If no man page has been configured, we print an error message. |
75 | if [ -z "${HOOK_MANPAGE}" ]; then | |
76 | error "There is no help available for hook '${HOOK}'. Exiting." | |
77 | exit ${EXIT_ERROR} | |
78 | fi | |
79 | ||
80 | cli_show_man ${HOOK_MANPAGE} | |
81 | } | |
82 | ||
1848564d MT |
83 | # Do nothing |
84 | function _parse_cmdline() { | |
85 | return ${EXIT_OK} | |
86 | } | |
87 | ||
2181765d MT |
88 | function hook_port() { |
89 | local zone="${1}" | |
90 | assert isset zone | |
91 | ||
92 | local action="${2}" | |
1848564d MT |
93 | shift 2 |
94 | ||
95 | local ret | |
1848564d | 96 | case "${action}" in |
e5f78859 | 97 | add|create|edit|rem|show) |
2181765d | 98 | hook_port_${action} "${zone}" $@ |
1848564d MT |
99 | ret=$? |
100 | ;; | |
101 | *) | |
102 | error "Unrecognized argument: '${action}'" | |
103 | exit ${EXIT_ERROR} | |
104 | ;; | |
105 | esac | |
106 | ||
107 | exit ${ret} | |
108 | } | |
109 | ||
2181765d MT |
110 | function hook_port_add() { |
111 | hook_port_cmd add "$@" | |
e5f78859 MT |
112 | } |
113 | ||
2181765d MT |
114 | function hook_port_edit() { |
115 | _port_cmd edit "$@" | |
e5f78859 MT |
116 | } |
117 | ||
2181765d MT |
118 | function hook_port_rem() { |
119 | hook_port_cmd remove "$@" | |
e5f78859 MT |
120 | } |
121 | ||
2181765d MT |
122 | function hook_port_show() { |
123 | cmd_not_implemented | |
e5f78859 MT |
124 | } |
125 | ||
2181765d MT |
126 | function hook_port_status() { |
127 | hook_port_cmd status "$@" | |
e5f78859 MT |
128 | } |
129 | ||
2181765d MT |
130 | function hook_port_cmd() { |
131 | local cmd="${1}" | |
e5f78859 | 132 | assert isset cmd |
2181765d MT |
133 | |
134 | local zone="${2}" | |
e5f78859 | 135 | assert isset zone |
2181765d MT |
136 | |
137 | local port="${3}" | |
e5f78859 MT |
138 | assert isset port |
139 | ||
2181765d | 140 | shift 3 |
1848564d | 141 | |
2181765d | 142 | local hook_zone="$(zone_get_hook ${zone})" |
e5f78859 | 143 | assert isset hook_zone |
2181765d MT |
144 | |
145 | local hook_port="$(port_get_hook ${port})" | |
e5f78859 | 146 | assert isset hook_port |
1848564d | 147 | |
2181765d MT |
148 | if ! listmatch "${hook_port}" $(zone_get_supported_port_hooks ${zone}); then |
149 | log ERROR "Zone '${zone}' does not support port of type '${hook_port}'." | |
1848564d MT |
150 | exit ${EXIT_ERROR} |
151 | fi | |
152 | ||
2181765d | 153 | hook_zone_port_exec "${hook_zone}" "${hook_port}" "${cmd}" "${zone}" "${port}" "$@" |
e5f78859 | 154 | exit $? |
1848564d MT |
155 | } |
156 | ||
2181765d MT |
157 | function hook_port_up() { |
158 | hook_port_cmd up "$@" | |
1848564d MT |
159 | } |
160 | ||
2181765d MT |
161 | function hook_port_down() { |
162 | hook_port_cmd down "$@" | |
1848564d MT |
163 | } |
164 | ||
2181765d MT |
165 | function hook_config() { |
166 | local zone="${1}" | |
167 | assert isset zone | |
168 | ||
169 | local action="${2}" | |
170 | assert isset action | |
1848564d MT |
171 | shift 2 |
172 | ||
173 | local ret | |
1848564d MT |
174 | case "${action}" in |
175 | create|edit|rem|show) | |
2181765d MT |
176 | hook_config_${action} "${zone}" "$@" |
177 | exit $? | |
1848564d MT |
178 | ;; |
179 | *) | |
180 | error "Unrecognized argument: '${action}'" | |
181 | exit ${EXIT_ERROR} | |
182 | ;; | |
183 | esac | |
1848564d MT |
184 | } |
185 | ||
2181765d MT |
186 | function hook_config_cmd() { |
187 | local cmd="${1}" | |
188 | assert isset cmd | |
1848564d | 189 | |
2181765d MT |
190 | local zone="${2}" |
191 | assert isset zone | |
1848564d | 192 | |
2181765d MT |
193 | local hook_config="${3}" |
194 | assert isset hook_config | |
195 | ||
196 | shift 3 | |
197 | ||
198 | local hook_zone="$(zone_get_hook "${zone}")" | |
199 | if ! hook_zone_exists "${hook_zone}"; then | |
200 | log ERROR "Hook '${hook}' does not exist." | |
1848564d MT |
201 | exit ${EXIT_ERROR} |
202 | fi | |
203 | ||
2181765d MT |
204 | if ! hook_config_exists "${hook_zone}" "${hook_config}"; then |
205 | log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'." | |
1848564d MT |
206 | exit ${EXIT_ERROR} |
207 | fi | |
208 | ||
2181765d | 209 | hook_zone_config_exec "${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@" |
1848564d MT |
210 | } |
211 | ||
2181765d MT |
212 | function hook_config_create() { |
213 | local zone="${1}" | |
a5ebb169 | 214 | assert isset zone |
2181765d MT |
215 | |
216 | local hook_config="${2}" | |
a5ebb169 | 217 | assert isset hook_config |
a5ebb169 | 218 | |
2181765d MT |
219 | shift 2 |
220 | ||
221 | if ! listmatch "${hook_config}" $(zone_get_supported_config_hooks ${zone}); then | |
222 | log ERROR "Zone '${zone}' does not support configuration of type '${hook_config}'." | |
a5ebb169 MT |
223 | exit ${EXIT_ERROR} |
224 | fi | |
225 | ||
2181765d | 226 | local hook_zone="$(zone_get_hook "${zone}")" |
a5ebb169 MT |
227 | assert isset hook_zone |
228 | ||
2181765d | 229 | hook_zone_config_exec "${hook_zone}" "${hook_config}" create "${zone}" "$@" |
a5ebb169 | 230 | exit $? |
1848564d MT |
231 | } |
232 | ||
2181765d MT |
233 | function hook_config_edit() { |
234 | hook_config_cmd edit "$@" | |
1848564d MT |
235 | } |
236 | ||
2181765d MT |
237 | function hook_config_remove() { |
238 | cmd_not_implemented | |
1848564d MT |
239 | } |
240 | ||
2181765d MT |
241 | function hook_config_show() { |
242 | cmd_not_implemented | |
1848564d MT |
243 | } |
244 | ||
2181765d MT |
245 | function hook_ppp_write_config() { |
246 | cmd_not_implemented | |
97cb552e MT |
247 | |
248 | # Arguments: <zone> <filename> | |
249 | } | |
250 | ||
2181765d MT |
251 | function hook_ppp_ip_pre_up() { |
252 | local zone="${1}" | |
253 | assert isset zone | |
c7ad7801 MT |
254 | shift |
255 | ||
2181765d MT |
256 | if ! zone_exists "${zone}"; then |
257 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
258 | exit ${EXIT_ERROR} |
259 | fi | |
260 | ||
2181765d | 261 | ppp_common_ip_pre_up "${zone}" "$@" |
c7ad7801 | 262 | exit $? |
b4038eca MT |
263 | } |
264 | ||
2181765d MT |
265 | function hook_ppp_ipv4_up() { |
266 | local zone="${1}" | |
267 | assert isset zone | |
c7ad7801 MT |
268 | shift |
269 | ||
2181765d MT |
270 | if ! zone_exists "${zone}"; then |
271 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
272 | exit ${EXIT_ERROR} |
273 | fi | |
274 | ||
2181765d | 275 | ppp_common_ipv4_up "${zone}" "$@" |
c7ad7801 | 276 | exit $? |
b4038eca MT |
277 | } |
278 | ||
2181765d MT |
279 | function hook_ppp_ipv4_down() { |
280 | local zone="${1}" | |
281 | assert isset zone | |
c7ad7801 MT |
282 | shift |
283 | ||
2181765d MT |
284 | if ! zone_exists "${zone}"; then |
285 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
286 | exit ${EXIT_ERROR} |
287 | fi | |
288 | ||
2181765d | 289 | ppp_common_ipv4_down "${zone}" "$@" |
c7ad7801 | 290 | exit $? |
b4038eca MT |
291 | } |
292 | ||
2181765d MT |
293 | function hook_ppp_ipv6_up() { |
294 | local zone="${1}" | |
295 | assert isset zone | |
201b7dff MT |
296 | shift |
297 | ||
2181765d | 298 | if ! zone_exists "${zone}"; then |
201b7dff MT |
299 | error "Zone '${zone}' does not exist." |
300 | exit ${EXIT_ERROR} | |
301 | fi | |
302 | ||
2181765d | 303 | ppp_common_ipv6_up "${zone}" "$@" |
201b7dff MT |
304 | exit $? |
305 | } | |
306 | ||
2181765d MT |
307 | function hook_ppp_ipv6_down() { |
308 | local zone="${1}" | |
309 | assert isset zone | |
201b7dff MT |
310 | shift |
311 | ||
2181765d | 312 | if ! zone_exists "${zone}"; then |
201b7dff MT |
313 | error "Zone '${zone}' does not exist." |
314 | exit ${EXIT_ERROR} | |
315 | fi | |
316 | ||
2181765d | 317 | ppp_common_ipv6_down "${zone}" "$@" |
201b7dff MT |
318 | exit $? |
319 | } |