]> git.ipfire.org Git - people/stevee/network.git/blame_incremental - src/header-zone
wireless-ap: Bring up hostapd, too when device is plugged in
[people/stevee/network.git] / src / header-zone
... / ...
CommitLineData
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
22function hook_info() {
23 echo "HOOK=\"${HOOK}\""
24}
25
26function 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
40function hook_edit() {
41 hook_create $@
42}
43
44function hook_remove() {
45 cmd_not_implemented
46}
47
48function 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
59function hook_up() {
60 cmd_not_implemented
61}
62
63function hook_down() {
64 cmd_not_implemented
65}
66
67function hook_discover() {
68 # This hook does not support a discovery
69 exit ${DISCOVER_NOT_SUPPORTED}
70}
71
72# The default help function.
73function hook_help() {
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
83# Do nothing
84function hook_parse_cmdline() {
85 return ${EXIT_OK}
86}
87
88function hook_port() {
89 local zone="${1}"
90 assert isset zone
91
92 local action="${2}"
93 shift 2
94
95 local ret
96 case "${action}" in
97 add|create|edit|rem|show)
98 hook_port_${action} "${zone}" $@
99 ret=$?
100 ;;
101 *)
102 error "Unrecognized argument: '${action}'"
103 exit ${EXIT_ERROR}
104 ;;
105 esac
106
107 exit ${ret}
108}
109
110function hook_port_add() {
111 return ${EXIT_NOT_SUPPORTED}
112}
113
114function hook_port_edit() {
115 return ${EXIT_NOT_SUPPORTED}
116}
117
118function hook_port_remove() {
119 return ${EXIT_NOT_SUPPORTED}
120}
121
122function hook_port_show() {
123 cmd_not_implemented
124}
125
126function hook_port_status() {
127 return ${EXIT_NOT_SUPPORTED}
128}
129
130function hook_port_up() {
131 cmd_not_implemented
132}
133
134function hook_port_down() {
135 cmd_not_implemented
136}
137
138function hook_config() {
139 local zone="${1}"
140 assert isset zone
141
142 local action="${2}"
143 assert isset action
144 shift 2
145
146 local ret
147 case "${action}" in
148 create|edit|rem|show)
149 hook_config_${action} "${zone}" "$@"
150 exit $?
151 ;;
152 *)
153 error "Unrecognized argument: '${action}'"
154 exit ${EXIT_ERROR}
155 ;;
156 esac
157}
158
159function hook_config_cmd() {
160 local cmd="${1}"
161 assert isset cmd
162
163 local zone="${2}"
164 assert isset zone
165
166 local hook_config="${3}"
167 assert isset hook_config
168
169 shift 3
170
171 local hook_zone="$(zone_get_hook "${zone}")"
172 if ! hook_zone_exists "${hook_zone}"; then
173 log ERROR "Hook '${hook}' does not exist."
174 exit ${EXIT_ERROR}
175 fi
176
177 if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
178 log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
179 exit ${EXIT_ERROR}
180 fi
181
182 hook_zone_config_exec "${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
183}
184
185function hook_config_create() {
186 local zone="${1}"
187 assert isset zone
188
189 local hook_config="${2}"
190 assert isset hook_config
191
192 shift 2
193
194 if ! listmatch "${hook_config}" $(zone_get_supported_config_hooks ${zone}); then
195 log ERROR "Zone '${zone}' does not support configuration of type '${hook_config}'."
196 exit ${EXIT_ERROR}
197 fi
198
199 local hook_zone="$(zone_get_hook "${zone}")"
200 assert isset hook_zone
201
202 hook_zone_config_exec "${hook_zone}" "${hook_config}" create "${zone}" "$@"
203 exit $?
204}
205
206function hook_config_edit() {
207 hook_config_cmd edit "$@"
208}
209
210function hook_config_remove() {
211 cmd_not_implemented
212}
213
214function hook_config_show() {
215 cmd_not_implemented
216}
217
218function hook_ppp_write_config() {
219 cmd_not_implemented
220
221 # Arguments: <zone> <filename>
222}
223
224function hook_ppp_ip_pre_up() {
225 local zone="${1}"
226 assert isset zone
227 shift
228
229 if ! zone_exists "${zone}"; then
230 log ERROR "Zone '${zone}' does not exist."
231 exit ${EXIT_ERROR}
232 fi
233
234 ppp_common_ip_pre_up "${zone}" "$@"
235 exit $?
236}
237
238function hook_ppp_ipv4_up() {
239 local zone="${1}"
240 assert isset zone
241 shift
242
243 if ! zone_exists "${zone}"; then
244 log ERROR "Zone '${zone}' does not exist."
245 exit ${EXIT_ERROR}
246 fi
247
248 ppp_common_ipv4_up "${zone}" "$@"
249 exit $?
250}
251
252function hook_ppp_ipv4_down() {
253 local zone="${1}"
254 assert isset zone
255 shift
256
257 if ! zone_exists "${zone}"; then
258 log ERROR "Zone '${zone}' does not exist."
259 exit ${EXIT_ERROR}
260 fi
261
262 ppp_common_ipv4_down "${zone}" "$@"
263 exit $?
264}
265
266function hook_ppp_ipv6_up() {
267 local zone="${1}"
268 assert isset zone
269 shift
270
271 if ! zone_exists "${zone}"; then
272 error "Zone '${zone}' does not exist."
273 exit ${EXIT_ERROR}
274 fi
275
276 ppp_common_ipv6_up "${zone}" "$@"
277 exit $?
278}
279
280function hook_ppp_ipv6_down() {
281 local zone="${1}"
282 assert isset zone
283 shift
284
285 if ! zone_exists "${zone}"; then
286 error "Zone '${zone}' does not exist."
287 exit ${EXIT_ERROR}
288 fi
289
290 ppp_common_ipv6_down "${zone}" "$@"
291 exit $?
292}