]> git.ipfire.org Git - people/stevee/network.git/blame - src/header-zone
Rectify config creation
[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
ea699552
MT
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
1848564d 181
ea699552 182 hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
1848564d
MT
183}
184
2181765d 185function hook_config_create() {
ea699552 186 assert [ $# -gt 2 ]
a5ebb169 187
ea699552 188 hook_config_cmd "create" "$@"
1848564d
MT
189}
190
2181765d 191function hook_config_edit() {
ea699552 192 hook_config_cmd "edit" "$@"
1848564d
MT
193}
194
2181765d 195function hook_config_remove() {
ea699552 196 hook_config_cmd "remove" "$@"
1848564d
MT
197}
198
2181765d
MT
199function hook_config_show() {
200 cmd_not_implemented
1848564d
MT
201}
202
2181765d
MT
203function hook_ppp_write_config() {
204 cmd_not_implemented
97cb552e
MT
205
206 # Arguments: <zone> <filename>
207}
208
2181765d
MT
209function hook_ppp_ip_pre_up() {
210 local zone="${1}"
211 assert isset zone
c7ad7801
MT
212 shift
213
2181765d
MT
214 if ! zone_exists "${zone}"; then
215 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
216 exit ${EXIT_ERROR}
217 fi
218
2181765d 219 ppp_common_ip_pre_up "${zone}" "$@"
c7ad7801 220 exit $?
b4038eca
MT
221}
222
2181765d
MT
223function hook_ppp_ipv4_up() {
224 local zone="${1}"
225 assert isset zone
c7ad7801
MT
226 shift
227
2181765d
MT
228 if ! zone_exists "${zone}"; then
229 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
230 exit ${EXIT_ERROR}
231 fi
232
2181765d 233 ppp_common_ipv4_up "${zone}" "$@"
c7ad7801 234 exit $?
b4038eca
MT
235}
236
2181765d
MT
237function hook_ppp_ipv4_down() {
238 local zone="${1}"
239 assert isset zone
c7ad7801
MT
240 shift
241
2181765d
MT
242 if ! zone_exists "${zone}"; then
243 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
244 exit ${EXIT_ERROR}
245 fi
246
2181765d 247 ppp_common_ipv4_down "${zone}" "$@"
c7ad7801 248 exit $?
b4038eca
MT
249}
250
2181765d
MT
251function hook_ppp_ipv6_up() {
252 local zone="${1}"
253 assert isset zone
201b7dff
MT
254 shift
255
2181765d 256 if ! zone_exists "${zone}"; then
201b7dff
MT
257 error "Zone '${zone}' does not exist."
258 exit ${EXIT_ERROR}
259 fi
260
2181765d 261 ppp_common_ipv6_up "${zone}" "$@"
201b7dff
MT
262 exit $?
263}
264
2181765d
MT
265function hook_ppp_ipv6_down() {
266 local zone="${1}"
267 assert isset zone
201b7dff
MT
268 shift
269
2181765d 270 if ! zone_exists "${zone}"; then
201b7dff
MT
271 error "Zone '${zone}' does not exist."
272 exit ${EXIT_ERROR}
273 fi
274
2181765d 275 ppp_common_ipv6_down "${zone}" "$@"
201b7dff
MT
276 exit $?
277}