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