]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | function hook_info() { | |
23 | echo "HOOK=\"${HOOK}\"" | |
24 | } | |
25 | ||
26 | function hook_create() { | |
27 | local zone="${1}" | |
28 | assert isset zone | |
29 | shift | |
30 | ||
31 | settings_read $(zone_dir ${zone})/settings | |
32 | ||
33 | hook_parse_cmdline $@ | |
34 | ||
35 | settings_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS} | |
36 | ||
37 | exit ${EXIT_OK} | |
38 | } | |
39 | ||
40 | function hook_edit() { | |
41 | hook_create $@ | |
42 | } | |
43 | ||
44 | function hook_remove() { | |
45 | cmd_not_implemented | |
46 | } | |
47 | ||
48 | function hook_status() { | |
49 | local zone="${1}" | |
50 | assert isset zone | |
51 | ||
52 | if device_is_up ${zone}; then | |
53 | exit ${STATUS_UP} | |
54 | fi | |
55 | ||
56 | exit ${STATUS_DOWN} | |
57 | } | |
58 | ||
59 | function hook_up() { | |
60 | cmd_not_implemented | |
61 | } | |
62 | ||
63 | function hook_down() { | |
64 | cmd_not_implemented | |
65 | } | |
66 | ||
67 | function hook_discover() { | |
68 | # This hook does not support a discovery | |
69 | exit ${DISCOVER_NOT_SUPPORTED} | |
70 | } | |
71 | ||
72 | # Do nothing | |
73 | function hook_parse_cmdline() { | |
74 | return ${EXIT_OK} | |
75 | } | |
76 | ||
77 | function hook_port() { | |
78 | local zone="${1}" | |
79 | assert isset zone | |
80 | ||
81 | local action="${2}" | |
82 | shift 2 | |
83 | ||
84 | local ret | |
85 | case "${action}" in | |
86 | add|create|edit|rem|show) | |
87 | hook_port_${action} "${zone}" $@ | |
88 | ret=$? | |
89 | ;; | |
90 | *) | |
91 | error "Unrecognized argument: '${action}'" | |
92 | exit ${EXIT_ERROR} | |
93 | ;; | |
94 | esac | |
95 | ||
96 | exit ${ret} | |
97 | } | |
98 | ||
99 | function hook_port_add() { | |
100 | return ${EXIT_NOT_SUPPORTED} | |
101 | } | |
102 | ||
103 | function hook_port_edit() { | |
104 | return ${EXIT_NOT_SUPPORTED} | |
105 | } | |
106 | ||
107 | function hook_port_remove() { | |
108 | return ${EXIT_NOT_SUPPORTED} | |
109 | } | |
110 | ||
111 | function hook_port_show() { | |
112 | cmd_not_implemented | |
113 | } | |
114 | ||
115 | function hook_port_status() { | |
116 | return ${EXIT_NOT_SUPPORTED} | |
117 | } | |
118 | ||
119 | function hook_port_up() { | |
120 | cmd_not_implemented | |
121 | } | |
122 | ||
123 | function hook_port_down() { | |
124 | cmd_not_implemented | |
125 | } | |
126 | ||
127 | function hook_config() { | |
128 | local zone="${1}" | |
129 | assert isset zone | |
130 | ||
131 | local action="${2}" | |
132 | assert isset action | |
133 | shift 2 | |
134 | ||
135 | local ret | |
136 | case "${action}" in | |
137 | create|edit|rem|show) | |
138 | hook_config_${action} "${zone}" "$@" | |
139 | exit $? | |
140 | ;; | |
141 | *) | |
142 | error "Unrecognized argument: '${action}'" | |
143 | exit ${EXIT_ERROR} | |
144 | ;; | |
145 | esac | |
146 | } | |
147 | ||
148 | function hook_config_cmd() { | |
149 | local cmd="${1}" | |
150 | assert isset cmd | |
151 | ||
152 | local zone="${2}" | |
153 | assert isset zone | |
154 | ||
155 | local hook_config="${3}" | |
156 | assert isset hook_config | |
157 | ||
158 | shift 3 | |
159 | ||
160 | local hook_zone="$(zone_get_hook "${zone}")" | |
161 | if ! hook_zone_exists "${hook_zone}"; then | |
162 | log ERROR "Hook '${hook}' does not exist." | |
163 | exit ${EXIT_ERROR} | |
164 | fi | |
165 | ||
166 | #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then | |
167 | # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'." | |
168 | # exit ${EXIT_ERROR} | |
169 | #fi | |
170 | ||
171 | hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@" | |
172 | } | |
173 | ||
174 | function hook_config_create() { | |
175 | assert [ $# -gt 2 ] | |
176 | ||
177 | hook_config_cmd "create" "$@" | |
178 | } | |
179 | ||
180 | function hook_config_edit() { | |
181 | hook_config_cmd "edit" "$@" | |
182 | } | |
183 | ||
184 | function hook_config_remove() { | |
185 | hook_config_cmd "remove" "$@" | |
186 | } | |
187 | ||
188 | function hook_config_show() { | |
189 | cmd_not_implemented | |
190 | } | |
191 | ||
192 | function hook_ppp_write_config() { | |
193 | cmd_not_implemented | |
194 | ||
195 | # Arguments: <zone> <filename> | |
196 | } | |
197 | ||
198 | function hook_ppp_ip_pre_up() { | |
199 | local zone="${1}" | |
200 | assert isset zone | |
201 | shift | |
202 | ||
203 | if ! zone_exists "${zone}"; then | |
204 | log ERROR "Zone '${zone}' does not exist." | |
205 | exit ${EXIT_ERROR} | |
206 | fi | |
207 | ||
208 | ppp_common_ip_pre_up "${zone}" "$@" | |
209 | exit $? | |
210 | } | |
211 | ||
212 | function hook_ppp_ipv4_up() { | |
213 | local zone="${1}" | |
214 | assert isset zone | |
215 | shift | |
216 | ||
217 | if ! zone_exists "${zone}"; then | |
218 | log ERROR "Zone '${zone}' does not exist." | |
219 | exit ${EXIT_ERROR} | |
220 | fi | |
221 | ||
222 | ppp_common_ipv4_up "${zone}" "$@" | |
223 | exit $? | |
224 | } | |
225 | ||
226 | function hook_ppp_ipv4_down() { | |
227 | local zone="${1}" | |
228 | assert isset zone | |
229 | shift | |
230 | ||
231 | if ! zone_exists "${zone}"; then | |
232 | log ERROR "Zone '${zone}' does not exist." | |
233 | exit ${EXIT_ERROR} | |
234 | fi | |
235 | ||
236 | ppp_common_ipv4_down "${zone}" "$@" | |
237 | exit $? | |
238 | } | |
239 | ||
240 | function hook_ppp_ipv6_up() { | |
241 | local zone="${1}" | |
242 | assert isset zone | |
243 | shift | |
244 | ||
245 | if ! zone_exists "${zone}"; then | |
246 | error "Zone '${zone}' does not exist." | |
247 | exit ${EXIT_ERROR} | |
248 | fi | |
249 | ||
250 | ppp_common_ipv6_up "${zone}" "$@" | |
251 | exit $? | |
252 | } | |
253 | ||
254 | function hook_ppp_ipv6_down() { | |
255 | local zone="${1}" | |
256 | assert isset zone | |
257 | shift | |
258 | ||
259 | if ! zone_exists "${zone}"; then | |
260 | error "Zone '${zone}' does not exist." | |
261 | exit ${EXIT_ERROR} | |
262 | fi | |
263 | ||
264 | ppp_common_ipv6_down "${zone}" "$@" | |
265 | exit $? | |
266 | } |