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