]> git.ipfire.org Git - people/stevee/network.git/blame - src/header-config
hook: Rename HOOK_CONFIG_SETTINGS to HOOK_SETTINGS
[people/stevee/network.git] / src / header-config
CommitLineData
711ffac1
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###############################################################################
2a6b2397
MT
21
22hook_new() {
46a28dcd
MT
23 local zone="${1}"
24 shift
25
320f1fda
JS
26 local id=$(zone_config_get_new_id ${zone})
27 log DEBUG "ID for the config is: ${id}"
28
636f1b96
MT
29 # Import all default variables
30 hook_set_defaults
31
46a28dcd 32 # Parse command line arguments
320f1fda
JS
33 if ! hook_parse_cmdline "${id}" "$@"; then
34 # Return an error if the parsing of the cmd line fails
46a28dcd
MT
35 return ${EXIT_ERROR}
36 fi
37
38 # Write configuration to disk
39 if ! zone_config_settings_write "${zone}" "${HOOK}"; then
40 return ${EXIT_ERROR}
41 fi
42
43 return ${EXIT_OK}
2a6b2397 44}
a14382e2
JS
45
46hook_edit() {
47 local zone=${1}
48 local config=${2}
49 shift 2
50
51 local hook=$(config_get_hook_from_config ${config})
52 local id=$(config_get_id_from_config ${config})
53
54 assert isset hook
55 assert isset id
56
57 if ! zone_exists ${zone}; then
58 error "Zone '${zone}' doesn't exist."
59 exit ${EXIT_ERROR}
60 fi
61
62 # Bring the config down
63 if device_exists ${zone}; then
64 if ! hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"; then
65 log ERROR "Could not bring config ${config} down for zone ${zone}"
66 return ${EXIT_ERROR}
67 fi
68 fi
69
636f1b96 70 local ${HOOK_SETTINGS}
a14382e2
JS
71
72 # If reading the config fails we cannot go on
73 if ! zone_config_settings_read "${zone}" "${config}"; then
74 log ERROR "Could read the config ${config} for zone ${zone}"
75 return ${EXIT_ERROR}
76 fi
77
320f1fda 78 if ! hook_parse_cmdline "${id}" "$@"; then
a14382e2
JS
79 # Return an error if the parsing of the cmd line fails
80 return ${EXIT_ERROR}
81 fi
82
83 # Write the settings to the config file
84 if ! zone_config_settings_write "${zone}" "${hook}" ${id}; then
85 log ERROR "Could not write config settings file ${config} for ${zone}"
86 return ${EXIT_ERROR}
87 fi
88
89 # Bring the config up
90 if device_exists ${zone}; then
91 if ! hook_config_cmd "up" "${zone}" "${hook}" "${hook}.${id}"; then
92 log ERROR "Could not bring config ${config} up for zone ${zone}"
93 return ${EXIT_ERROR}
94 fi
95 fi
96
97 exit ${EXIT_OK}
98}
a6ef0714
JS
99
100hook_destroy() {
101 return ${EXIT_OK}
102}
196b3149
JS
103
104
105# Returns the ID as a unique identifier
106# Should always be overwritten by a hook
107hook_hid() {
108 local zone=${1}
109 local config=${2}
110
111 config_get_id_from_config "${config}"
112}