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