]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/header-zone
hooks: Import zone default settings, too
[people/ms/network.git] / src / header-zone
index 219b0d624e477cec4d6487483d17842a945a6589..7ad3e39e5e7bf1033e8439e61f6bb28c3354acc6 100644 (file)
@@ -34,7 +34,12 @@ hook_new() {
        assert isset zone
        shift
 
-       if ! hook_parse_cmdline $@; then
+       local ${HOOK_SETTINGS}
+
+       # Import all default variables
+       hook_set_defaults
+
+       if ! hook_parse_cmdline "$@"; then
                return ${EXIT_ERROR}
        fi
 
@@ -56,7 +61,7 @@ hook_edit() {
                return ${EXIT_ERROR}
        fi
 
-       if ! hook_parse_cmdline $@; then
+       if ! hook_parse_cmdline "$@"; then
                return ${EXIT_ERROR}
        fi
 
@@ -112,7 +117,7 @@ hook_port() {
        local ret
        case "${action}" in
                add|create|edit|rem|show)
-                       hook_port_${action} "${zone}" $@
+                       hook_port_${action} "${zone}" "$@"
                        ret=$?
                        ;;
                *)
@@ -150,7 +155,7 @@ hook_default_port_create() {
 }
 
 hook_port_create() {
-       hook_default_port_create $@
+       hook_default_port_create "$@"
 }
 
 hook_default_port_remove() {
@@ -163,7 +168,7 @@ hook_default_port_remove() {
 }
 
 hook_port_remove() {
-       hook_default_port_remove $@
+       hook_default_port_remove "$@"
 }
 
 hook_port_up() {
@@ -243,7 +248,21 @@ hook_config_destroy() {
        local hook=$(zone_config_get_hook_from_id ${zone}  ${id})
        assert isset hook
 
-       hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"
+       # First we bring the hook down
+       hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"
+
+       # If a hook_destroy function is implemented in the hook this function will be executed.
+       # If not a empty defined in header-config is executed.
+       if ! hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
+
+               # A better error message should printed inside the hook.
+               # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
+               log ERROR "Could not destroy config with the follwoing id: ${id}"
+               return ${EXIT_ERROR}
+       fi
+
+       # Now we delete the config of the zone
+       zone_config_settings_destroy "${zone}" "${hook}.${id}"
 }
 
 hook_config_edit() {