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