2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
23 # - All functions in this scope must start with an underline (_) to not
24 # conflict with any functions that were defined somewhere else.
28 # Returns a soft error if a function was not implemented, yet.
30 function _notimplemented
() {
31 warning
"'$@' was not implemented."
32 exit ${EXIT_CONF_ERROR}
36 echo "HOOK=\"${HOOK}\""
43 config_read $
(zone_dir
${zone})/settings
47 config_write $
(zone_dir
${zone})/settings
${HOOK_SETTINGS}
63 if device_is_up
${zone}; then
78 function _discover
() {
79 # This hook does not support a discovery
80 exit ${DISCOVER_NOT_SUPPORTED}
83 # The default help function.
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."
91 cli_show_man
${HOOK_MANPAGE}
95 function _parse_cmdline
() {
107 add|create|edit|rem|show
)
108 _port_
${action} ${zone} $@
112 error
"Unrecognized argument: '${action}'"
120 function _port_add
() {
124 function _port_edit
() {
128 function _port_rem
() {
132 function _port_show
() {
133 _notimplemented _port_show
136 function _port_status
() {
140 function _port_cmd
() {
150 local hook_zone
=$
(zone_get_hook
${zone})
151 local hook_port
=$
(port_get_hook
${port})
153 assert isset hook_zone
154 assert isset hook_port
156 if ! listmatch
${hook_port} $
(zone_get_supported_port_hooks
${zone}); then
157 error_log
"Zone '${zone}' does not support port of type '${hook_port}'."
161 hook_zone_port_exec
${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
166 function _port_up
() {
170 function _port_down
() {
182 create|edit|rem|show
)
183 _config_
${action} ${zone} $@
187 error
"Unrecognized argument: '${action}'"
195 # This function is not a public one
196 function __configcmd
() {
199 local hook_config
=${3}
202 local hook_zone
=$
(zone_get_hook
${zone})
204 if ! hook_zone_exists
${hook_zone}; then
205 error
"Hook '${hook}' does not exist."
209 if ! hook_config_exists
${hook_zone} ${hook_config}; then
210 error
"Hook '${hook_config}' is not supported for zone '${zone}'."
214 hook_zone_config_exec
${hook_zone} ${hook_config} ${cmd} ${zone} $@
217 function _config_create
() {
219 local hook_config
=${2}
223 assert isset hook_config
224 assert zone_exists
${zone}
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}'."
231 local hook_zone
=$
(zone_get_hook
${zone})
232 assert isset hook_zone
234 hook_zone_config_exec
${hook_zone} ${hook_config} create ${zone} $@
239 function _config_edit
() {
243 function _config_rem
() {
244 _notimplemented _config_rem
247 function _config_show
() {
248 _notimplemented _config_show
251 function _ppp-write-config
() {
252 _notimplemented _ppp_write_config
254 # Arguments: <zone> <filename>
257 function _ppp-ip-pre-up
() {
261 if ! zone_exists
${zone}; then
262 error
"Zone '${zone}' does not exist."
266 ppp_common_ip_pre_up
${zone} $@
271 function _ppp-ip-up
() {
275 if ! zone_exists
${zone}; then
276 error
"Zone '${zone}' does not exist."
280 ppp_common_ip_up
${zone} $@
285 function _ppp-ip-down
() {
289 if ! zone_exists
${zone}; then
290 error
"Zone '${zone}' does not exist."
294 ppp_common_ip_down
${zone} $@
299 function _ppp-ipv6-up
() {
303 if ! zone_exists
${zone}; then
304 error
"Zone '${zone}' does not exist."
308 ppp_common_ipv6_up
${zone} $@
313 function _ppp-ipv6-down
() {
317 if ! zone_exists
${zone}; then
318 error
"Zone '${zone}' does not exist."
322 ppp_common_ipv6_down
${zone} $@