function list_append() {
local list=${1}
+ assert isset list
+ shift
+
+ local arg
+ for arg in $@; do
+ list_append_one "${list}" "${arg}"
+ done
+}
+
+function list_append_one() {
+ assert [ $# -eq 2 ]
+
+ local list="${1}"
shift
assert isset list
function port_settings_read() {
local port="${1}"
assert isset port
- shift
# Save the HOOK variable.
local hook="${HOOK}"
- settings_read "$(port_file "${port}")" "$@"
+ settings_read "$(port_file "${port}")" ${HOOK_SETTINGS}
# Restore hook.
HOOK="${hook}"
assert isset port
shift
- settings_write "$(port_file "${port}")" "$@"
+ local args
+ if function_exists "hook_check_settings"; then
+ list_append args "--check=\"hook_check_settings\""
+ fi
+ list_append args ${HOOK_SETTINGS}
+
+ settings_write "$(port_file "${port}")" ${args}
}
function ports_get_all() {
}
function settings_write() {
- local settings_file=${1}
+ local settings_file="${1}"
assert isset settings_file
shift
+ local check_func
+
+ local arg
+ while read arg; do
+ case "${arg}" in
+ --check=*)
+ check_func="$(cli_get_val "${arg}")"
+ ;;
+
+ # Stop argument processing when reaching the first
+ # configuration parameter
+ *)
+ break
+ ;;
+ esac
+ shift
+ done <<< "$(args $@)"
+
# Check if all values to be written are sane
- if ! settings_check; then
- log CRITICAL "Configuration check failed. No settings have been written."
+ if isset check_func && ! settings_check "${check_func}"; then
return ${EXIT_ERROR}
fi
}
function settings_check() {
- # If there is a function defined that is called __check
- # we call that function
- if [ -n "$(type -t hook_check)" ]; then
- hook_check || return $?
- fi
-
- return ${EXIT_OK}
+ local check_func="${1}"
+
+ # Execute the check function
+ "${check_func}"
+ local ret="${?}"
+
+ case "${ret}" in
+ # OK
+ ${EXIT_OK}|${EXIT_TRUE})
+ log DEBUG "Configuration check succeeded."
+ return ${EXIT_TRUE}
+ ;;
+
+ # Error
+ ${EXIT_ERROR}|${EXIT_FALSE})
+ log CRITICAL "Configuration check failed. No settings have been written."
+ return ${EXIT_FALSE}
+ ;;
+
+ # Command not found
+ ${EXIT_COMMAND_NOT_FOUND})
+ log CRITICAL "Configuration check function '${check_func}' was not found."
+ return ${EXIT_FALSE}
+ ;;
+ esac
+
+ log CRITICAL "Unhandled exit code for '${check_func}': ${ret}"
+ return ${EXIT_ERROR}
}
function settings_set() {
return ${EXIT_ERROR}
}
+function function_exists() {
+ local function="${1}"
+
+ if [ "$(type -t "${function}")" = "function" ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
function process_kill() {
local process=${1}
function zone_settings_read() {
local zone=${1}
-
assert isset zone
# Save the HOOK variable.
local hook="${HOOK}"
- settings_read $(zone_file ${zone})
+ settings_read "${zone}" ${HOOK_SETTINGS}
# Restore hook.
HOOK="${hook}"
}
function zone_settings_write() {
- local zone=${1}
-
+ local zone="${1}"
assert isset zone
- settings_write $(zone_file ${zone}) ${HOOK_SETTINGS}
+ local args
+ if function_exists "hook_check_settings"; then
+ list_append args "--check=\"hook_check_settings\""
+ fi
+ list_append args ${HOOK_SETTINGS}
+
+ settings_write "$(zone_file ${zone})" ${args}
}
function zone_settings_set() {
assert isset key
(
- zone_settings_read ${zone}
+ zone_settings_read "${zone}" "${key}" \
+ --ignore-superfluous-settings
echo "${!key}"
)
local port="${2}"
shift 2
+ local args
+ if function_exists "hook_check_port_settings"; then
+ list_append args "--check=\"hook_check_port_settings\""
+ fi
+ list_append args $@
+
local path="$(zone_dir "${zone}")/ports/${port}"
- settings_write "${path}" "$@"
+ settings_write "${path}" ${args}
}
function zone_port_settings_remove() {
assert isset zone
shift
- settings_read $(zone_dir ${zone})/settings
+ zone_settings_read "${zone}"
hook_parse_cmdline $@
- settings_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
+ zone_settings_write "${zone}"
exit ${EXIT_OK}
}
function hook_edit() {
- hook_create $@
+ hook_new $@
}
function hook_remove() {
ADDRESS=$(mac_generate)
SLAVES=
-function hook_check() {
+function hook_check_settings() {
assert isset ADDRESS
assert ismac ADDRESS
}
MIIMON=100
MODE="balance-rr"
-function hook_check() {
+function hook_check_settings() {
assert isset ADDRESS
assert ismac ADDRESS
HOOK_SETTINGS="HOOK ADDRESS"
-function hook_check() {
+function hook_check_settings() {
assert ismac ADDRESS
}
HOOK_SETTINGS="HOOK ADDRESS DEVICE"
-function hook_check() {
+function hook_check_settings() {
assert ismac DEVICE
if isset ADDRESS; then
PORT_PARENTS_VAR="PARENT"
-function hook_check() {
+function hook_check_settings() {
assert isset PARENT_DEVICE
assert isinteger TAG
PHY=
SSID=
-function hook_check() {
+function hook_check_settings() {
assert isset ADDRESS
assert ismac ADDRESS
assert isset CHANNEL
MODE="g"
SSID=
-function hook_check() {
+function hook_check_settings() {
assert isset ADDRESS
assert ismac ADDRESS
assert isset BROADCAST_SSID
# The public IPv4 address of the tunnel client.
PUBLIC_ADDRESS=""
-function hook_check() {
+function hook_check_settings() {
assert isset SIX_RD_PREFIX
assert isset PUBLIC_ADDRESS
assert isset SERVER_ADDRESS
assert isset zone
# Read configuration options.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Configure the tunnel.
if ! device_exists "${zone}"; then
cli_device_headline ${zone}
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
local server_line="${SERVER_ADDRESS}"
local server_hostname=$(dns_get_hostname ${SERVER_ADDRESS})
USERNAME=
PASSWORD=
-function hook_check() {
+function hook_check_settings() {
assert isset SERVER_ADDRESS
assert isset LOCAL_ADDRESS
assert isset LOCAL_ADDRESS6
assert isset zone
# Read configuration options.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
if enabled AUTO_UPDATE_ENDPOINT; then
log DEBUG "Updating tunnel endpoint"
cli_device_headline ${zone}
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
local server_line="${SERVER_ADDRESS}"
local server_hostname=$(dns_get_hostname ${SERVER_ADDRESS})
TUNNEL_ID=
REQUIRE_TLS="true"
-function hook_check() {
+function hook_check_settings() {
assert isset USERNAME
assert isset PASSWORD
assert isset SERVER
cli_device_headline ${zone}
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
cli_headline 2 "Configuration"
cli_print_fmt1 2 "User" "${USERNAME}"
STP_MAXAGE=20
STP_PRIORITY=512
-function hook_check() {
+function hook_check_settings() {
assert ismac MAC
assert isbool STP
assert isoneof STP_MODE stp rstp
local zone=${1}
assert isset zone
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Create the bridge if it does not already exist.
if ! device_exists "${zone}"; then
IMSI=
HOOK_SETTINGS="${HOOK_SETTINGS} IMSI"
-function hook_check() {
+function hook_check_settings() {
assert isset DEVICE
assert isset PHONE_NUMBER
assert isset zone
# Load configuration file.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# If we have got a PIN, we try to unlock the device first.
if isset PIN; then
if ! modem_sim_auto_unlock "${DEVICE}" "${PIN}"; then
# Reset the PIN setting.
PIN=""
- zone_settings_write "${zone}" ${HOOK_SETTINGS}
+ zone_settings_write "${zone}"
error "Could not unlock the SIM card. Removing PIN from settings."
fi
cli_device_headline ${zone}
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
cli_headline 2 "Configuration"
cli_print_fmt1 2 "Username" "${USERNAME}"
assert isset file
# Read in the configuration files.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
pppd_write_config ${file} \
--interface="${zone}" \
# Use IPv6 prefix delegation.
PREFIX_DELEGATION="false"
-function hook_check() {
+function hook_check_settings() {
assert isset USERNAME
assert isset PASSWORD
local zone=${1}
assert isset zone
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Bring up the port.
local port=$(__hook_get_port "${zone}")
local zone=${1}
assert isset zone
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Stop the ppp daemon.
pppd_stop ${zone}
cli_device_headline ${zone}
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
cli_headline 2 "Configuration"
cli_print_fmt1 2 "Username" "${USERNAME}"
assert isset file
# Read in the configuration files.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# A port has to be assigned for this action
local port=$(__hook_get_port "${zone}")
# A list of refused authentification methods.
REFUSED_AUTH_METHODS=""
-function hook_check() {
+function hook_check_settings() {
assert isset USERNAME
assert isset PASSWORD
assert isset PEER_ADDRESS
local zone="${1}"
assert isset zone
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Check if a port will be used.
if isset PORT; then
local zone="${1}"
assert isset zone
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Stop the ppp daemon.
pppd_stop "${zone}"
cli_device_headline "${zone}"
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Display port configuration if a port is used.
if isset PORT; then
assert isset file
# Read in the configuration files.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
# Prepare the command line options for the pptp plugin.
local pptp_commandline="pptp ${PEER_ADDRESS} --nolaunchpppd"
KEY=
ENCRYPTION_MODE=
-function hook_check() {
+function hook_check_settings() {
assert isset SSID
if isset ADDRESS; then
assert isset zone
# Read zone configuration.
- zone_settings_read "${zone}" ${HOOK_SETTINGS}
+ zone_settings_read "${zone}"
if ! device_exists ${zone}; then
# Create the wireless interface.