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