]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.zone
Cleanup code that deletes ports/zones
[people/ms/network.git] / src / functions / functions.zone
index 88c81a86181add8de65e8ffa275c3f5c4161c69d..b9d475f71745e7cbadd97bbff92bef3eb19a4228 100644 (file)
 #                                                                             #
 ###############################################################################
 
-zone_dir() {
-       local zone=${1}
-
-       echo "${NETWORK_ZONE_DIR}/zones/${zone}"
-}
-
 zone_exists() {
        local zone=${1}
        assert isset zone
 
-       [ -d "$(zone_dir ${zone})" ]
+       [ -d "${NETWORK_ZONES_DIR}/${zone}" ]
 }
 
 zone_match() {
@@ -68,7 +62,7 @@ zone_get_hook() {
        local zone=${1}
        assert isset zone
 
-       config_get_hook $(zone_dir ${zone})/settings
+       config_get_hook "${NETWORK_ZONES_DIR}/${zone}/settings"
 }
 
 zone_start() {
@@ -210,7 +204,7 @@ zone_cmd() {
        local hook="$(zone_get_hook ${zone})"
        assert isset hook
 
-       hook_exec zone "${hook}" "${cmd}" "${zone}" $@
+       hook_exec zone "${hook}" "${cmd}" "${zone}" "$@"
 }
 
 zone_new() {
@@ -233,18 +227,19 @@ zone_new() {
                return ${EXIT_ERROR}
        fi
 
-       mkdir -p $(zone_dir ${zone})
-
        # Create directories for configs and ports
-       mkdir -p $(zone_dir ${zone})/{configs,ports}
+       local what
+       for what in configs ports; do
+               make_directory "${NETWORK_ZONES_DIR}/${zone}/${what}"
+       done
 
-       hook_zone_exec "${hook}" "new" "${zone}" $@
+       hook_zone_exec "${hook}" "new" "${zone}" "$@"
        local ret=$?
 
        # Maybe the zone new hook did not exit correctly.
        # If this is the case we remove the created zone immediately.
-       if [ "${ret}" = "${EXIT_ERROR}" ]; then
-               zone_destroy_now "${zone}"
+       if [ "${ret}" != "${EXIT_OK}" ]; then
+               zone_destroy "${zone}"
                return ${EXIT_ERROR}
        fi
 
@@ -264,12 +259,6 @@ zone_edit() {
                return ${EXIT_ERROR}
        fi
 
-       # Check if the zone is tagged for removal.
-       if zone_has_destroy_tag ${zone}; then
-               error "You cannot edit a zone that is tagged for removal."
-               return ${EXIT_ERROR}
-       fi
-
        local hook="$(zone_get_hook "${zone}")"
        if [ -z "${hook}" ]; then
                error "Config file did not provide any hook."
@@ -281,7 +270,7 @@ zone_edit() {
                return ${EXIT_ERROR}
        fi
 
-       hook_zone_exec ${hook} edit ${zone} $@
+       hook_zone_exec ${hook} edit ${zone} "$@"
 }
 
 zone_rename() {
@@ -291,7 +280,6 @@ zone_rename() {
        local name="${2}"
 
        assert zone_exists "${zone}"
-       assert not zone_has_destroy_tag "${zone}"
        assert not zone_exists "${name}"
 
        # The zone must be shut down before, is then renamed and
@@ -312,7 +300,7 @@ zone_rename() {
        zone_disable "${zone}"
 
        # Rename the configuration files
-       mv -f "$(zone_dir "${zone}")" "$(zone_dir "${name}")"
+       mv -f "${NETWORK_ZONES_DIR}/${zone}" "${NETWORK_ZONES_DIR}/${name}"
 
        # Enable the zone if it was enabled before
        [ ${zone_was_enabled} -eq ${EXIT_TRUE} ] && zone_enable "${name}"
@@ -327,37 +315,26 @@ zone_rename() {
 
 zone_destroy() {
        local zone="${1}"
-       assert zone_exists "${zone}"
-
-       # Make the zone for removal.
-       touch "$(zone_dir "${zone}")/.destroy"
-
-       log INFO "Zone '${zone}' has been tagged for removal."
-}
-
-zone_has_destroy_tag() {
-       local zone="${1}"
-       assert zone_exists "${zone}"
 
-       [ -e "$(zone_dir "${zone}")/.destroy" ]
-}
-
-# This function will remove the given zone
-# RIGHT NOW. Use zone_destroy to remove it
-# at the next status change.
-zone_destroy_now() {
-       local zone="${1}"
-       assert zone_exists "${zone}"
-
-       log INFO "Removing zone '${zone}' right now."
+       # Cannot delete a zone that does not exist
+       if ! zone_exists "${zone}"; then
+               log ERROR "Zone ${zone} does not exist"
+               return ${EXIT_ERROR}
+       fi
 
        # Force the zone down.
        zone_is_active "${zone}" && zone_stop "${zone}"
 
-       # Disable zone.
+       # Disable zone auto-start
        zone_disable "${zone}"
 
-       rm -rf "$(zone_dir "${zone}")"
+       if ! rm -rf "${NETWORK_ZONES_DIR}/${zone}"; then
+               log ERROR "Could not destroy zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       log INFO "Destroyed zone ${zone}"
+       return ${EXIT_OK}
 }
 
 zone_up() {
@@ -369,12 +346,6 @@ zone_up() {
                return ${EXIT_ERROR}
        fi
 
-       # Check if a zone has got the remove tag.
-       if zone_has_destroy_tag ${zone}; then
-               error "Cannot bring up any zone which is to be removed."
-               return ${EXIT_ERROR}
-       fi
-
        local hook="$(zone_get_hook "${zone}")"
        if [ -z "${hook}" ]; then
                error "Config file did not provide any hook."
@@ -388,7 +359,7 @@ zone_up() {
 
        zone_db ${zone} starting
 
-       hook_zone_exec ${hook} up ${zone} $@
+       hook_zone_exec ${hook} up ${zone} "$@"
 
        zone_db ${zone} started
 
@@ -418,17 +389,12 @@ zone_down() {
 
        zone_db ${zone} stopping
 
-       hook_zone_exec ${hook} down ${zone} $@
+       hook_zone_exec ${hook} down ${zone} "$@"
 
        zone_db ${zone} stopped
 
        # Execute all triggers after the zone went down
        triggers_execute_all "down" ZONE="${zone}"
-
-       # Remove the zone, if it has got a remove tag.
-       if zone_has_destroy_tag "${zone}"; then
-               zone_destroy_now "${zone}"
-       fi
 }
 
 zone_status() {
@@ -453,11 +419,6 @@ zone_status() {
        fi
 
        hook_zone_exec "${hook}" "status" "${zone}" "$@"
-
-       # Show that the zone it to be removed soon.
-       if zone_has_destroy_tag ${zone}; then
-               warning "This zone is tagged for removal."
-       fi
 }
 
 zone_identify() {
@@ -475,7 +436,7 @@ zone_identify() {
        local port
        for port in $(zone_get_ports "${zone}"); do
                # Identify all the ports
-               port_identify "${port}" --background $@
+               port_identify "${port}" --background "$@"
 
                # Save the PIDs of the subprocesses
                list_append pids "$(cmd_background_get_pid)"
@@ -495,10 +456,8 @@ zone_get_ports() {
        assert isset zone
 
        local port
-       for port in $(zone_dir ${zone})/ports/*; do
-               port=$(basename ${port})
-
-               if port_exists ${port}; then
+       for port in $(list_directory "${NETWORK_ZONES_DIR}/${zone}/ports"); do
+               if port_exists "${port}"; then
                        echo "${port}"
                fi
        done
@@ -510,9 +469,7 @@ zone_get_ports_num() {
 
        local counter=0
        local port
-       for port in $(zone_dir "${zone}")/ports/*; do
-               port="$(basename "${port}")"
-
+       for port in $(list_directory "${NETWORK_ZONES_DIR}/${zone}/ports"); do
                if port_exists "${port}"; then
                        counter=$(( ${counter} + 1 ))
                fi
@@ -533,7 +490,7 @@ zone_has_port() {
        assert isset zone
        assert isset port
 
-       [ -e "$(zone_dir ${zone})/ports/${port}" ]
+       [ -e "${NETWORK_ZONES_DIR}/${zone}/ports/${port}" ]
 }
 
 zone_config() {
@@ -550,15 +507,53 @@ zone_config() {
                        zone_config_new "${zone}" "$@"
                        ;;
                destroy)
-                       zone_config_destroy "${zone}" "$@"
+                       # usually ${1} is a valid hid
+                       local hid=${1}
+                       shift 1
+
+                       # We convert the hid into an id
+                       local id=$(zone_config_convert_hid_to_id ${zone} ${hid})
+
+                       # If id isset the hid is valid and we can go on with the id
+                       if isset id; then
+                                zone_config_destroy "${zone}" "${id}" "$@"
+
+                       # If we can't get a valid hid we check if we got a valid id
+                       else
+                               if zone_config_id_is_valid ${zone} ${hid}; then
+                                       zone_config_destroy "${zone}" ${hid} "$@"
+                               else
+                                       log ERROR "${id} is not a valid id or hid"
+                               fi
+                       fi
                        ;;
-               edit)
-                       zone_config_edit "${zone}" "$@"
+               list)
+                       zone_config_list "${zone}" "$@"
                        ;;
                *)
-                       error "Unrecognized argument: ${cmd}"
-                       cli_usage root-zone-config-subcommands
-                       exit ${EXIT_ERROR}
+                       # usually ${1} is a valid hid
+                       local hid=${cmd}
+                       local cmd=${1}
+                       shift 1
+
+                       local id=$(zone_config_convert_hid_to_id ${zone} ${hid})
+
+                       # If id isset the hid is valid and we can go on with the id
+                       if isset id && [[ ${cmd} == "edit" ]]; then
+                                zone_config_edit "${zone}" "${id}" "$@"
+
+                       # If we didn't get a valid hid we check if we got a valid id
+                       else
+                               if zone_config_id_is_valid ${zone} ${id} && [[ ${cmd} == "edit" ]]; then
+                                       shift 1
+                                       zone_config_edit "${zone}" "${id}" "$@"
+                               else
+                                       # in ${hid} is saved the command after network zone ${zone} config
+                                       error "Unrecognized argument: ${hid}"
+                                       cli_usage root-zone-config-subcommands
+                                       exit ${EXIT_ERROR}
+                               fi
+                       fi
                        ;;
        esac
 }
@@ -599,33 +594,118 @@ zone_config_edit() {
        zone_config_cmd "edit" "$@"
 }
 
+zone_config_list() {
+       # This function list in an nice way all configs of a zone
+       local zone=${1}
+       assert isset zone
+
+       # Print a nice header
+       local format="%-3s %-20s %-20s"
+       print "${format}" "ID" "HOOK" "HID"
+
+       local config
+       local hook
+       local id
+       local hid
+
+       # Print for all config:
+       # id and hook
+       for config in $(zone_configs_list "${zone}"); do
+               id=${config##*.}
+               hook=$(zone_config_get_hook "${zone}" "${config}")
+               hid=$(zone_config_get_hid "${zone}" "${config}")
+               assert isset hook
+               print "${format}" "${id}" "${hook}" "${hid}"
+       done
+}
+
 zone_config_show() {
        zone_config_cmd "show" "$@"
 }
 
-zone_show() {
+# Returns a list of all used ids for a zone
+zone_config_list_ids() {
+       assert [ $# -eq 1 ]
+
        local zone=${1}
+       local config
+       local ids
+
+       for config in $(zone_configs_list ${zone}); do
+               list_append ids "$(config_get_id_from_config ${config})"
+       done
 
-       echo "${zone}"
-       echo "  Type: $(zone_get_hook ${zone})"
-       echo
+       echo ${ids}
 }
 
-zones_show() {
-       local zone
+# List all hids of a zone
+zone_config_list_hids() {
+       assert [ $# -eq 1 ]
+
+       local zone=${1}
+
+       local config
+       for config in $(zone_configs_list ${zone}); do
+               zone_config_get_hid "${zone}" "${config}"
+       done
+}
+
+# get the hid from a given config
+zone_config_get_hid() {
+       assert [ $# -eq 2 ]
+
+       local zone=${1}
+       local config=${2}
+
+       local hook="$(zone_config_get_hook "${zone}" "${config}")"
+
+       hook_exec "config" "${hook}" "hid" "${zone}" "${config}"
+}
+
+# Checks if a hid is valid for a given zone
+zone_config_hid_is_valid() {
+       assert [ $# -eq 2]
+
+       local zone=${1}
+       local hid=${2}
+
+       local _hid
+       for _hid in $(zone_config_list_hids "${zone}"); do
+               if [[ ${_hid} = ${hid} ]]; then
+                       return ${EXIT_TRUE}
+               fi
+       done
+
+       return ${EXIT_FALSE}
+}
+
+# This function converts a hid to a id
+zone_config_convert_hid_to_id() {
+       assert [ $# -eq 2 ]
+
+       local zone=${1}
+       local hid=${2}
+
+       local config
+       for config in $(zone_configs_list ${zone}); do
+               # Get hook from config
+               local hook="$(zone_config_get_hook "${zone}" "${config}")"
 
-       for zone in $(zones_get $@); do
-               zone_show ${zone}
+               if [[ "$(hook_exec "config" "${hook}" "hid" "${zone}" "${config}")" == "${hid}" ]]; then
+                       config_get_id_from_config "${config}"
+                       return ${EXIT_TRUE}
+               fi
        done
+
+       return ${EXIT_FALSE}
 }
 
 zones_get_all() {
        local zone
-       for zone in $(zone_dir)/*; do
-               zone=$(basename ${zone})
-               zone_exists ${zone} || continue
-
-               echo "${zone}"
+       for zone in $(list_directory "${NETWORK_ZONES_DIR}"); do
+               if zone_exists ${zone}; then
+                       echo "${zone}"
+               fi
        done
 }
 
@@ -714,12 +794,7 @@ zones_get() {
 zone_ports_list() {
        local zone=${1}
 
-       local port
-       for port in $(zone_dir ${zone})/ports/*; do
-               [ -e "${port}" ] || continue
-
-               echo $(basename ${port})
-       done
+       list_directory "${NETWORK_ZONES_DIR}/${zone}/ports"
 }
 
 zone_port_attach() {
@@ -854,23 +929,23 @@ zone_port_cmd() {
        assert isset hook
 
        # Dispatch command to hook
-       hook_zone_exec "${hook}" "${cmd}" "${zone}" "${port}" $@
+       hook_zone_exec "${hook}" "${cmd}" "${zone}" "${port}" "$@"
 }
 
 zone_port_create() {
-       zone_port_cmd "port_create" $@
+       zone_port_cmd "port_create" "$@"
 }
 
 zone_port_remove() {
-       zone_port_cmd "port_remove" $@
+       zone_port_cmd "port_remove" "$@"
 }
 
 zone_port_up() {
-       zone_port_cmd "port_up" $@
+       zone_port_cmd "port_up" "$@"
 }
 
 zone_port_down() {
-       zone_port_cmd "port_down" $@
+       zone_port_cmd "port_down" "$@"
 }
 
 # The next two functions automagically bring up and down
@@ -911,7 +986,7 @@ zone_port_stop() {
 }
 
 zone_port_status() {
-       zone_port_cmd "port_status" $@
+       zone_port_cmd "port_status" "$@"
 }
 
 zone_ports_cmd() {
@@ -927,28 +1002,28 @@ zone_ports_cmd() {
 
        local port
        for port in $(zone_get_ports ${zone}); do
-               hook_zone_exec "${hook}" "${cmd}" "${zone}" "${port}" $@
+               hook_zone_exec "${hook}" "${cmd}" "${zone}" "${port}" "$@"
        done
 }
 
 zone_ports_create() {
-       zone_ports_cmd "port_create" $@
+       zone_ports_cmd "port_create" "$@"
 }
 
 zone_ports_remove() {
-       zone_ports_cmd "port_remove" $@
+       zone_ports_cmd "port_remove" "$@"
 }
 
 zone_ports_up() {
-       zone_ports_cmd "port_up" $@
+       zone_ports_cmd "port_up" "$@"
 }
 
 zone_ports_down() {
-       zone_ports_cmd "port_down" $@
+       zone_ports_cmd "port_down" "$@"
 }
 
 zone_ports_status() {
-       zone_ports_cmd "port_status" $@
+       zone_ports_cmd "port_status" "$@"
 }
 
 zone_configs_cmd() {
@@ -965,31 +1040,84 @@ zone_configs_cmd() {
                local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
                assert isset config_hook
 
-               hook_config_exec "${config_hook}" "${cmd}" "${zone}" "${config}" $@
+               hook_config_exec "${config_hook}" "${cmd}" "${zone}" "${config}" "$@"
        done
 }
 
 zone_configs_up() {
-       zone_configs_cmd "up" $@
+       zone_configs_cmd "up" "$@"
 }
 
 zone_configs_down() {
-       zone_configs_cmd "down" $@
+       zone_configs_cmd "down" "$@"
 }
 
 zone_configs_status() {
-       zone_configs_cmd "status" $@
+       zone_configs_cmd "status" "$@"
 }
 
 zone_configs_list() {
        local zone=${1}
 
+       list_directory "${NETWORK_ZONES_DIR}/${zone}/configs"
+}
+
+zone_config_get_new_id() {
+       # This functions returns the next free id for a zone
+
+       assert [ $# -eq 1 ]
+       local zone=${1}
+
+       local zone_path="${NETWORK_ZONES_DIR}/${zone}"
+       local i=0
+
+       while true; do
+               if [ ! -f ${zone_path}/configs/*.${i} ]; then
+                       echo "${i}"
+                       return ${EXIT_OK}
+               fi
+               (( i++ ))
+       done
+}
+
+zone_config_check_same_setting() {
+       # This functions checks if a config hook
+       # with the same setting is already configured for this zone.
+       # Returns True when yes and False when no.
+
+       assert [ $# -eq 5 ]
+
+       local zone=${1}
+       local hook=${2}
+       local id=${3}
+       local key=${4}
+       local value=${5}
+
+       # The key should be local for this function
+       local ${key}
        local config
-       for config in $(zone_dir ${zone})/configs/*; do
-               [ -e "${config}" ] || continue
 
-               basename ${config}
+       for config in $(zone_configs_list ${zone}); do
+               # Check if the config is eqal with the config we want to edit, when continue
+               if [[ "${config}" = "${hook}.${id}" ]]; then
+                       continue
+               fi
+
+               # Check if the config is from the given hook, when not continue
+               if  [[ $(zone_config_get_hook "${zone}" "${config}") != ${hook} ]]; then
+                       continue
+               fi
+
+               # Get the value of the key for a given function
+               zone_config_settings_read "${zone}" "${config}" \
+                --ignore-superfluous-settings "${key}"
+               # Check if the value of the config and the passed value are eqal
+               if [[ "${value}" == "${!key}" ]]; then
+                       return ${EXIT_TRUE}
+               fi
        done
+
+       return ${EXIT_FALSE}
 }
 
 zone_config_get_hook() {
@@ -1008,8 +1136,80 @@ zone_config_get_hook() {
        print "${HOOK}"
 }
 
+zone_config_hook_is_configured() {
+       # Checks if a zone has already at least one config with the given hook.
+       # Returns True when yes and False when no
+
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local hook=${2}
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+               assert isset config_hook
+               if [[ ${hook} == ${config_hook} ]]; then
+                       return ${EXIT_TRUE}
+               fi
+
+       done
+
+       # If we get here the zone has no config with the given hook
+       return ${EXIT_FALSE}
+}
+
+zone_config_id_is_valid() {
+       # This function checks if a given id is valid for a zone
+       # Return True when yes and false when no
+
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local id=${2}
+
+       local zone_path="${NETWORK_ZONES_DIR}/${zone}"
+
+       [ -f ${zone_path}/configs/*.${id} ];
+}
+
+# This function checks if a given hid is valid for a zone
+# Return True when yes and false when no
+zone_config_hid_is_valid() {
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local hid=${2}
+
+       local _hid
+       for _hid in $(zone_config_list_hids ${zone}); do
+               if [[ ${_hid} == ${hid} ]]; then
+                       return ${EXIT_TRUE}
+               fi
+       done
+
+       return ${EXIT_FALSE}
+}
+
+zone_config_get_hook_from_id() {
+       # Returns the hook for a given id
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local id=${2}
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               if [[ ${config} == *.${id} ]]; then
+                       local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+                       assert isset config_hook
+                       print "${config_hook}"
+                       return "${EXIT_OK}"
+               fi
+       done
+
+       # If we get here the zone has no config with the given id
+       return ${EXIT_ERROR}
+}
+
 zone_has_ip() {
-       device_has_ip $@
+       device_has_ip "$@"
 }
 
 zone_db() {
@@ -1031,7 +1231,7 @@ zone_is_up() {
 }
 
 zone_is_down() {
-       ! zone_is_up $@
+       ! zone_is_up "$@"
 }
 
 zone_get_supported_port_hooks() {
@@ -1046,14 +1246,6 @@ zone_get_supported_config_hooks() {
        hook_config_get_all
 }
 
-zone_file() {
-       local zone=${1}
-
-       assert isset zone
-
-       echo "$(zone_dir ${zone})/settings"
-}
-
 zone_settings_read() {
        local zone=${1}
        assert isset zone
@@ -1063,13 +1255,13 @@ zone_settings_read() {
        if [ $# -eq 0 ] && [ -n "${HOOK_SETTINGS}" ]; then
                list_append args ${HOOK_SETTINGS}
        else
-               list_append args $@
+               list_append args "$@"
        fi
 
        # Save the HOOK variable.
        local hook="${HOOK}"
 
-       settings_read "$(zone_file "${zone}")" ${args}
+       settings_read "${NETWORK_ZONES_DIR}/${zone}/settings" ${args}
 
        # Restore hook.
        HOOK="${hook}"
@@ -1085,7 +1277,7 @@ zone_settings_write() {
        fi
        list_append args ${HOOK_SETTINGS}
 
-       settings_write "$(zone_file ${zone})" ${args}
+       settings_write "${NETWORK_ZONES_DIR}/${zone}/settings" ${args}
 }
 
 zone_settings_set() {
@@ -1132,10 +1324,10 @@ zone_config_settings_read() {
        if [ $# -eq 0 ] && [ -n "${HOOK_CONFIG_SETTINGS}" ]; then
                list_append args ${HOOK_CONFIG_SETTINGS}
        else
-               list_append args $@
+               list_append args "$@"
        fi
 
-       local path="$(zone_dir "${zone}")/configs/${config}"
+       local path="${NETWORK_ZONES_DIR}/${zone}/configs/${config}"
        settings_read "${path}" ${args}
 }
 
@@ -1143,8 +1335,10 @@ zone_config_settings_write() {
        assert [ $# -ge 2 ]
 
        local zone="${1}"
-       local config="${2}"
-       shift 2
+       local hook="${2}"
+       local id=${3}
+
+       assert isset id
 
        local args
        if function_exists "hook_check_config_settings"; then
@@ -1152,10 +1346,61 @@ zone_config_settings_write() {
        fi
        list_append args ${HOOK_CONFIG_SETTINGS}
 
-       local path="$(zone_dir "${zone}")/configs/${config}"
+       local path="${NETWORK_ZONES_DIR}/${zone}/configs/${hook}.${id}"
        settings_write "${path}" ${args}
 }
 
+zone_config_settings_destroy() {
+       # This function deletes the config file for a given zone and config
+       assert [ $# -ge 2 ]
+       local zone="${1}"
+       local config="${2}"
+
+       local path="${NETWORK_ZONES_DIR}/${zone}/configs/${config}"
+
+       # Check if path is valid
+       if [ ! -f ${path} ]; then
+               log ERROR "Path: '${path}' is not valid"
+               return ${EXIT_ERROR}
+       fi
+
+       log DEBUG "Deleting config file ${path}"
+       rm -f "${path}"
+
+}
+
+zone_config_find_by_hook() {
+       local zone="${1}"
+       assert isset zone
+
+       local hook="${2}"
+       assert isset hook
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               local h="$(zone_config_get_hook "${zone}" "${config}")"
+
+               [[ "${hook}" = "${h}" ]] && echo "${config}"
+       done
+
+       return ${EXIT_OK}
+}
+
+zone_config_settings_read_by_hook() {
+       local zone="${1}"
+       assert isset zone
+
+       local hook="${2}"
+       assert isset hook
+
+       local config
+       for config in $(zone_config_find_by_hook "${zone}" "${hook}"); do
+               zone_config_settings_read "${zone}" "${config}"
+       done
+
+       return ${EXIT_OK}
+}
+
 zone_port_settings_read() {
        assert [ $# -ge 2 ]
 
@@ -1167,10 +1412,10 @@ zone_port_settings_read() {
        if [ $# -eq 0 ] && [ -n "${HOOK_PORT_SETTINGS}" ]; then
                list_append args ${HOOK_PORT_SETTINGS}
        else
-               list_append args $@
+               list_append args "$@"
        fi
 
-       local path="$(zone_dir "${zone}")/ports/${port}"
+       local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}"
        settings_read "${path}" ${args}
 }
 
@@ -1187,7 +1432,7 @@ zone_port_settings_write() {
        fi
        list_append args ${HOOK_PORT_SETTINGS}
 
-       local path="$(zone_dir "${zone}")/ports/${port}"
+       local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}"
        settings_write "${path}" ${args}
 }
 
@@ -1197,6 +1442,21 @@ zone_port_settings_remove() {
        local zone="${1}"
        local port="${2}"
 
-       local path="$(zone_dir "${zone}")/ports/${port}"
+       local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}"
        settings_remove "${path}"
 }
+
+zone_get_color() {
+       # This function return the color of a zone
+       assert [ $# -eq 1 ]
+
+       local name=${1}
+       color_read "zone" ${name}
+}
+
+zone_get_description_title() {
+       assert [ $# -eq 1 ]
+
+       local name=${1}
+       description_title_read $(description_format_filename "zone" "${name}")
+}