]> git.ipfire.org Git - people/stevee/network.git/blame - header-zone
firewall: Re-unity firewall6/4 configuration again.
[people/stevee/network.git] / 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###############################################################################
21#
22# Notes:
23# - All functions in this scope must start with an underline (_) to not
24# conflict with any functions that were defined somewhere else.
25#
26
1848564d
MT
27# _notimplemented
28# Returns a soft error if a function was not implemented, yet.
29#
30function _notimplemented() {
31 warning "'$@' was not implemented."
32 exit ${EXIT_CONF_ERROR}
33}
34
35function _info() {
36 echo "HOOK=\"${HOOK}\""
37}
38
39function _create() {
40 local zone=${1}
41 shift
42
e5f78859 43 config_read $(zone_dir ${zone})/settings
1848564d
MT
44
45 _parse_cmdline $@
46
e5f78859 47 config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
1848564d
MT
48
49 exit ${EXIT_OK}
50}
51
52function _edit() {
53 _create $@
54}
55
56function _rem() {
57 _notimplemented _rem
58}
59
60function _status() {
61 local zone=${1}
62
63 if device_is_up ${zone}; then
64 exit ${STATUS_UP}
65 fi
66
67 exit ${STATUS_DOWN}
68}
69
70function _up() {
71 _notimplemented _up
72}
73
74function _down() {
75 _notimplemented _down
76}
77
78function _discover() {
79 # This hook does not support a discovery
80 exit ${DISCOVER_NOT_SUPPORTED}
81}
82
85afd775
MT
83# The default help function.
84function _help() {
85 # If no man page has been configured, we print an error message.
86 if [ -z "${HOOK_MANPAGE}" ]; then
87 error "There is no help available for hook '${HOOK}'. Exiting."
88 exit ${EXIT_ERROR}
89 fi
90
91 cli_show_man ${HOOK_MANPAGE}
92}
93
1848564d
MT
94# Do nothing
95function _parse_cmdline() {
96 return ${EXIT_OK}
97}
98
99function _port() {
100 local zone=${1}
101 local action=${2}
102 shift 2
103
104 local ret
105
106 case "${action}" in
e5f78859 107 add|create|edit|rem|show)
1848564d
MT
108 _port_${action} ${zone} $@
109 ret=$?
110 ;;
111 *)
112 error "Unrecognized argument: '${action}'"
113 exit ${EXIT_ERROR}
114 ;;
115 esac
116
117 exit ${ret}
118}
119
e5f78859
MT
120function _port_add() {
121 _port_cmd add $@
122}
123
124function _port_edit() {
125 _port_cmd edit $@
126}
127
128function _port_rem() {
129 _port_cmd rem $@
130}
131
132function _port_show() {
133 _notimplemented _port_show
134}
135
136function _port_status() {
137 _port_cmd status $@
138}
139
140function _port_cmd() {
1848564d
MT
141 local cmd=${1}
142 local zone=${2}
e5f78859 143 local port=${3}
1848564d
MT
144 shift 3
145
e5f78859
MT
146 assert isset cmd
147 assert isset zone
148 assert isset port
149
1848564d 150 local hook_zone=$(zone_get_hook ${zone})
e5f78859 151 local hook_port=$(port_get_hook ${port})
1848564d 152
e5f78859
MT
153 assert isset hook_zone
154 assert isset hook_port
1848564d 155
a5ebb169 156 if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
e5f78859 157 error_log "Zone '${zone}' does not support port of type '${hook_port}'."
1848564d
MT
158 exit ${EXIT_ERROR}
159 fi
160
e5f78859 161 hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
1848564d 162
e5f78859 163 exit $?
1848564d
MT
164}
165
e5f78859
MT
166function _port_up() {
167 _port_cmd up $@
1848564d
MT
168}
169
e5f78859
MT
170function _port_down() {
171 _port_cmd down $@
1848564d
MT
172}
173
174function _config() {
175 local zone=${1}
176 local action=${2}
177 shift 2
178
179 local ret
180
181 case "${action}" in
182 create|edit|rem|show)
183 _config_${action} ${zone} $@
184 ret=$?
185 ;;
186 *)
187 error "Unrecognized argument: '${action}'"
188 exit ${EXIT_ERROR}
189 ;;
190 esac
191
192 exit ${ret}
193}
194
195# This function is not a public one
196function __configcmd() {
197 local cmd=${1}
198 local zone=${2}
199 local hook_config=${3}
200 shift 3
201
202 local hook_zone=$(zone_get_hook ${zone})
203
d61a01d4 204 if ! hook_zone_exists ${hook_zone}; then
1848564d
MT
205 error "Hook '${hook}' does not exist."
206 exit ${EXIT_ERROR}
207 fi
208
209 if ! hook_config_exists ${hook_zone} ${hook_config}; then
210 error "Hook '${hook_config}' is not supported for zone '${zone}'."
211 exit ${EXIT_ERROR}
212 fi
213
d61a01d4 214 hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
1848564d
MT
215}
216
217function _config_create() {
a5ebb169
MT
218 local zone=${1}
219 local hook_config=${2}
220 shift 2
221
222 assert isset zone
223 assert isset hook_config
224 assert zone_exists ${zone}
225
226 if ! listmatch ${hook_config} $(zone_get_supported_config_hooks ${zone}); then
227 error_log "Zone '${zone}' does not support configuration of type '${hook_config}'."
228 exit ${EXIT_ERROR}
229 fi
230
231 local hook_zone=$(zone_get_hook ${zone})
232 assert isset hook_zone
233
234 hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
235
236 exit $?
1848564d
MT
237}
238
239function _config_edit() {
240 __configcmd edit $@
241}
242
243function _config_rem() {
244 _notimplemented _config_rem
245}
246
247function _config_show() {
248 _notimplemented _config_show
249}
250
97cb552e
MT
251function _ppp-write-config() {
252 _notimplemented _ppp_write_config
253
254 # Arguments: <zone> <filename>
255}
256
b4038eca 257function _ppp-ip-pre-up() {
c7ad7801
MT
258 local zone=${1}
259 shift
260
261 if ! zone_exists ${zone}; then
262 error "Zone '${zone}' does not exist."
263 exit ${EXIT_ERROR}
264 fi
265
266 ppp_common_ip_pre_up ${zone} $@
267
268 exit $?
b4038eca
MT
269}
270
271function _ppp-ip-up() {
c7ad7801
MT
272 local zone=${1}
273 shift
274
275 if ! zone_exists ${zone}; then
276 error "Zone '${zone}' does not exist."
277 exit ${EXIT_ERROR}
278 fi
279
280 ppp_common_ip_up ${zone} $@
281
282 exit $?
b4038eca
MT
283}
284
285function _ppp-ip-down() {
c7ad7801
MT
286 local zone=${1}
287 shift
288
289 if ! zone_exists ${zone}; then
290 error "Zone '${zone}' does not exist."
291 exit ${EXIT_ERROR}
292 fi
293
294 ppp_common_ip_down ${zone} $@
295
296 exit $?
b4038eca
MT
297}
298
201b7dff
MT
299function _ppp-ipv6-up() {
300 local zone=${1}
301 shift
302
303 if ! zone_exists ${zone}; then
304 error "Zone '${zone}' does not exist."
305 exit ${EXIT_ERROR}
306 fi
307
308 ppp_common_ipv6_up ${zone} $@
309
310 exit $?
311}
312
313function _ppp-ipv6-down() {
314 local zone=${1}
315 shift
316
317 if ! zone_exists ${zone}; then
318 error "Zone '${zone}' does not exist."
319 exit ${EXIT_ERROR}
320 fi
321
322 ppp_common_ipv6_down ${zone} $@
323
324 exit $?
325}