]> git.ipfire.org Git - people/stevee/network.git/blob - src/header-zone
Rectify config 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 function hook_info() {
23 echo "HOOK=\"${HOOK}\""
24 }
25
26 function 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
40 function hook_edit() {
41 hook_create $@
42 }
43
44 function hook_remove() {
45 cmd_not_implemented
46 }
47
48 function 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
59 function hook_up() {
60 cmd_not_implemented
61 }
62
63 function hook_down() {
64 cmd_not_implemented
65 }
66
67 function hook_discover() {
68 # This hook does not support a discovery
69 exit ${DISCOVER_NOT_SUPPORTED}
70 }
71
72 # The default help function.
73 function 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
84 function hook_parse_cmdline() {
85 return ${EXIT_OK}
86 }
87
88 function 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
110 function hook_port_add() {
111 return ${EXIT_NOT_SUPPORTED}
112 }
113
114 function hook_port_edit() {
115 return ${EXIT_NOT_SUPPORTED}
116 }
117
118 function hook_port_remove() {
119 return ${EXIT_NOT_SUPPORTED}
120 }
121
122 function hook_port_show() {
123 cmd_not_implemented
124 }
125
126 function hook_port_status() {
127 return ${EXIT_NOT_SUPPORTED}
128 }
129
130 function hook_port_up() {
131 cmd_not_implemented
132 }
133
134 function hook_port_down() {
135 cmd_not_implemented
136 }
137
138 function 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
159 function 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_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
183 }
184
185 function hook_config_create() {
186 assert [ $# -gt 2 ]
187
188 hook_config_cmd "create" "$@"
189 }
190
191 function hook_config_edit() {
192 hook_config_cmd "edit" "$@"
193 }
194
195 function hook_config_remove() {
196 hook_config_cmd "remove" "$@"
197 }
198
199 function hook_config_show() {
200 cmd_not_implemented
201 }
202
203 function hook_ppp_write_config() {
204 cmd_not_implemented
205
206 # Arguments: <zone> <filename>
207 }
208
209 function hook_ppp_ip_pre_up() {
210 local zone="${1}"
211 assert isset zone
212 shift
213
214 if ! zone_exists "${zone}"; then
215 log ERROR "Zone '${zone}' does not exist."
216 exit ${EXIT_ERROR}
217 fi
218
219 ppp_common_ip_pre_up "${zone}" "$@"
220 exit $?
221 }
222
223 function hook_ppp_ipv4_up() {
224 local zone="${1}"
225 assert isset zone
226 shift
227
228 if ! zone_exists "${zone}"; then
229 log ERROR "Zone '${zone}' does not exist."
230 exit ${EXIT_ERROR}
231 fi
232
233 ppp_common_ipv4_up "${zone}" "$@"
234 exit $?
235 }
236
237 function hook_ppp_ipv4_down() {
238 local zone="${1}"
239 assert isset zone
240 shift
241
242 if ! zone_exists "${zone}"; then
243 log ERROR "Zone '${zone}' does not exist."
244 exit ${EXIT_ERROR}
245 fi
246
247 ppp_common_ipv4_down "${zone}" "$@"
248 exit $?
249 }
250
251 function hook_ppp_ipv6_up() {
252 local zone="${1}"
253 assert isset zone
254 shift
255
256 if ! zone_exists "${zone}"; then
257 error "Zone '${zone}' does not exist."
258 exit ${EXIT_ERROR}
259 fi
260
261 ppp_common_ipv6_up "${zone}" "$@"
262 exit $?
263 }
264
265 function hook_ppp_ipv6_down() {
266 local zone="${1}"
267 assert isset zone
268 shift
269
270 if ! zone_exists "${zone}"; then
271 error "Zone '${zone}' does not exist."
272 exit ${EXIT_ERROR}
273 fi
274
275 ppp_common_ipv6_down "${zone}" "$@"
276 exit $?
277 }