]>
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 | ||
e9df08ad | 31 | settings_read $(zone_dir ${zone})/settings |
1848564d | 32 | |
2181765d | 33 | hook_parse_cmdline $@ |
1848564d | 34 | |
e9df08ad | 35 | settings_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 | ||
72 | # Do nothing | |
c2441156 | 73 | function hook_parse_cmdline() { |
1848564d MT |
74 | return ${EXIT_OK} |
75 | } | |
76 | ||
2181765d MT |
77 | function hook_port() { |
78 | local zone="${1}" | |
79 | assert isset zone | |
80 | ||
81 | local action="${2}" | |
1848564d MT |
82 | shift 2 |
83 | ||
84 | local ret | |
1848564d | 85 | case "${action}" in |
e5f78859 | 86 | add|create|edit|rem|show) |
2181765d | 87 | hook_port_${action} "${zone}" $@ |
1848564d MT |
88 | ret=$? |
89 | ;; | |
90 | *) | |
91 | error "Unrecognized argument: '${action}'" | |
92 | exit ${EXIT_ERROR} | |
93 | ;; | |
94 | esac | |
95 | ||
96 | exit ${ret} | |
97 | } | |
98 | ||
2181765d | 99 | function hook_port_add() { |
828eb94a | 100 | return ${EXIT_NOT_SUPPORTED} |
e5f78859 MT |
101 | } |
102 | ||
2181765d | 103 | function hook_port_edit() { |
828eb94a | 104 | return ${EXIT_NOT_SUPPORTED} |
e5f78859 MT |
105 | } |
106 | ||
828eb94a MT |
107 | function hook_port_remove() { |
108 | return ${EXIT_NOT_SUPPORTED} | |
e5f78859 MT |
109 | } |
110 | ||
2181765d MT |
111 | function hook_port_show() { |
112 | cmd_not_implemented | |
e5f78859 MT |
113 | } |
114 | ||
2181765d | 115 | function hook_port_status() { |
828eb94a | 116 | return ${EXIT_NOT_SUPPORTED} |
1848564d MT |
117 | } |
118 | ||
2181765d | 119 | function hook_port_up() { |
828eb94a | 120 | cmd_not_implemented |
1848564d MT |
121 | } |
122 | ||
2181765d | 123 | function hook_port_down() { |
828eb94a | 124 | cmd_not_implemented |
1848564d MT |
125 | } |
126 | ||
2181765d MT |
127 | function hook_config() { |
128 | local zone="${1}" | |
129 | assert isset zone | |
130 | ||
131 | local action="${2}" | |
132 | assert isset action | |
1848564d MT |
133 | shift 2 |
134 | ||
135 | local ret | |
1848564d MT |
136 | case "${action}" in |
137 | create|edit|rem|show) | |
2181765d MT |
138 | hook_config_${action} "${zone}" "$@" |
139 | exit $? | |
1848564d MT |
140 | ;; |
141 | *) | |
142 | error "Unrecognized argument: '${action}'" | |
143 | exit ${EXIT_ERROR} | |
144 | ;; | |
145 | esac | |
1848564d MT |
146 | } |
147 | ||
2181765d MT |
148 | function hook_config_cmd() { |
149 | local cmd="${1}" | |
150 | assert isset cmd | |
1848564d | 151 | |
2181765d MT |
152 | local zone="${2}" |
153 | assert isset zone | |
1848564d | 154 | |
2181765d MT |
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." | |
1848564d MT |
163 | exit ${EXIT_ERROR} |
164 | fi | |
165 | ||
ea699552 MT |
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 | |
1848564d | 170 | |
ea699552 | 171 | hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@" |
1848564d MT |
172 | } |
173 | ||
2181765d | 174 | function hook_config_create() { |
ea699552 | 175 | assert [ $# -gt 2 ] |
a5ebb169 | 176 | |
ea699552 | 177 | hook_config_cmd "create" "$@" |
1848564d MT |
178 | } |
179 | ||
2181765d | 180 | function hook_config_edit() { |
ea699552 | 181 | hook_config_cmd "edit" "$@" |
1848564d MT |
182 | } |
183 | ||
2181765d | 184 | function hook_config_remove() { |
ea699552 | 185 | hook_config_cmd "remove" "$@" |
1848564d MT |
186 | } |
187 | ||
2181765d MT |
188 | function hook_config_show() { |
189 | cmd_not_implemented | |
1848564d MT |
190 | } |
191 | ||
2181765d MT |
192 | function hook_ppp_write_config() { |
193 | cmd_not_implemented | |
97cb552e MT |
194 | |
195 | # Arguments: <zone> <filename> | |
196 | } | |
197 | ||
2181765d MT |
198 | function hook_ppp_ip_pre_up() { |
199 | local zone="${1}" | |
200 | assert isset zone | |
c7ad7801 MT |
201 | shift |
202 | ||
2181765d MT |
203 | if ! zone_exists "${zone}"; then |
204 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
205 | exit ${EXIT_ERROR} |
206 | fi | |
207 | ||
2181765d | 208 | ppp_common_ip_pre_up "${zone}" "$@" |
c7ad7801 | 209 | exit $? |
b4038eca MT |
210 | } |
211 | ||
2181765d MT |
212 | function hook_ppp_ipv4_up() { |
213 | local zone="${1}" | |
214 | assert isset zone | |
c7ad7801 MT |
215 | shift |
216 | ||
2181765d MT |
217 | if ! zone_exists "${zone}"; then |
218 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
219 | exit ${EXIT_ERROR} |
220 | fi | |
221 | ||
2181765d | 222 | ppp_common_ipv4_up "${zone}" "$@" |
c7ad7801 | 223 | exit $? |
b4038eca MT |
224 | } |
225 | ||
2181765d MT |
226 | function hook_ppp_ipv4_down() { |
227 | local zone="${1}" | |
228 | assert isset zone | |
c7ad7801 MT |
229 | shift |
230 | ||
2181765d MT |
231 | if ! zone_exists "${zone}"; then |
232 | log ERROR "Zone '${zone}' does not exist." | |
c7ad7801 MT |
233 | exit ${EXIT_ERROR} |
234 | fi | |
235 | ||
2181765d | 236 | ppp_common_ipv4_down "${zone}" "$@" |
c7ad7801 | 237 | exit $? |
b4038eca MT |
238 | } |
239 | ||
2181765d MT |
240 | function hook_ppp_ipv6_up() { |
241 | local zone="${1}" | |
242 | assert isset zone | |
201b7dff MT |
243 | shift |
244 | ||
2181765d | 245 | if ! zone_exists "${zone}"; then |
201b7dff MT |
246 | error "Zone '${zone}' does not exist." |
247 | exit ${EXIT_ERROR} | |
248 | fi | |
249 | ||
2181765d | 250 | ppp_common_ipv6_up "${zone}" "$@" |
201b7dff MT |
251 | exit $? |
252 | } | |
253 | ||
2181765d MT |
254 | function hook_ppp_ipv6_down() { |
255 | local zone="${1}" | |
256 | assert isset zone | |
201b7dff MT |
257 | shift |
258 | ||
2181765d | 259 | if ! zone_exists "${zone}"; then |
201b7dff MT |
260 | error "Zone '${zone}' does not exist." |
261 | exit ${EXIT_ERROR} | |
262 | fi | |
263 | ||
2181765d | 264 | ppp_common_ipv6_down "${zone}" "$@" |
201b7dff MT |
265 | exit $? |
266 | } |