]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/header-zone
wireless-ap: Add support for WPA3 and rewrite WPA2
[people/ms/network.git] / src / header-zone
index fdd6e51051bad464f6dce7eb38088573f70bfa15..2174b0187bd92da0103a2f9f7b179e53461b0767 100644 (file)
@@ -34,17 +34,44 @@ hook_new() {
        assert isset zone
        shift
 
-       zone_settings_read "${zone}"
+       local ${HOOK_SETTINGS[*]}
 
-       hook_parse_cmdline $@
+       # Import all default variables
+       hook_set_defaults
 
-       zone_settings_write "${zone}"
+       if ! hook_parse_cmdline "$@"; then
+               return ${EXIT_ERROR}
+       fi
+
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
 
        exit ${EXIT_OK}
 }
 
 hook_edit() {
-       hook_new $@
+       local zone="${1}"
+       assert isset zone
+       shift
+
+       if ! zone_settings_read "${zone}"; then
+               log ERROR "Could not read settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       if ! hook_parse_cmdline "$@"; then
+               return ${EXIT_ERROR}
+       fi
+
+       if ! zone_settings_write "${zone}"; then
+               log ERROR "Could not write settings for zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       exit ${EXIT_OK}
+
 }
 
 hook_remove() {
@@ -90,7 +117,7 @@ hook_port() {
        local ret
        case "${action}" in
                add|create|edit|rem|show)
-                       hook_port_${action} "${zone}" $@
+                       hook_port_${action} "${zone}" "$@"
                        ret=$?
                        ;;
                *)
@@ -128,7 +155,7 @@ hook_default_port_create() {
 }
 
 hook_port_create() {
-       hook_default_port_create $@
+       hook_default_port_create "$@"
 }
 
 hook_default_port_remove() {
@@ -141,7 +168,7 @@ hook_default_port_remove() {
 }
 
 hook_port_remove() {
-       hook_default_port_remove $@
+       hook_default_port_remove "$@"
 }
 
 hook_port_up() {
@@ -221,11 +248,40 @@ 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() {
-       hook_config_cmd "edit" "$@"
+       assert [ $# -ge 2 ]
+       local zone=${1}
+       # The id must be the id and not the hid.
+       local id=${2}
+
+       shift 2
+
+       # Check if we get a valid id
+       if ! zone_config_id_is_valid ${zone} ${id}; then
+               log ERROR "ID: ${id} is not a valid id for zone ${zone}"
+       fi
+
+       local hook=$(zone_config_get_hook_from_id ${zone} ${id})
+       assert isset hook
+
+       hook_config_cmd "edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
 }
 
 hook_config_show() {