;;
esac
- cli_headline 1 "${headline_prefix}:"
-
# Print the hook for all zones.
if [ "${type}" = "zone" ]; then
- cli_print_fmt1 1 "Hook" "$(zone_get_hook ${device})"
+ headline_prefix="${headline_prefix} ($(zone_get_hook ${device}))"
fi
+ cli_headline 1 "${headline_prefix}"
# Print the device status.
- local status=$(device_get_status ${device})
- cli_print_fmt1 1 "Status" "${STATUS_COLOUR[${status}]}${STATUS_TEXT[${status}]}${COLOUR_NORMAL}"
+ local status
+ case "$(device_get_status ${device})" in
+ ${STATUS_UP})
+ status=${MSG_DEVICE_STATUS_UP}
+ ;;
+ ${STATUS_DOWN})
+ status=${MSG_DEVICE_STATUS_DOWN}
+ ;;
+ ${STATUS_NOCARRIER})
+ status=${MSG_DEVICE_STATUS_NOCARRIER}
+ ;;
+ *)
+ status=${MSG_DEVICE_STATUS_UNKNOWN}
+ ;;
+ esac
+ cli_print_fmt1 1 "Status" "${status}"
if device_is_up ${device}; then
cli_print_fmt1 1 "MTU" "$(device_get_mtu ${device})"
fi
cli_space
}
-function cli_status_headline() {
- echo "XXX THIS FUNCTION IS DEPRECATED"
-
- local zone=${1}
+function cli_headline() {
+ local level=${1}
+ local format=${2}
+ shift 2
- local state="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
- zone_is_up ${zone} && state="${COLOUR_UP}UP${COLOUR_NORMAL}"
+ local ident=$(cli_ident ${level})
- echo -e "${zone} - ${state} - $(zone_get_hook ${zone})"
+ local out
+ printf -v out "${ident}${COLOUR_BOLD}${format}${COLOUR_NORMAL}\n" "$@"
+ printf "${out}"
}
-function cli_headline() {
+function cli_statusline() {
local level=${1}
shift
- local message="$@"
- local ident=$(cli_ident ${level})
+ local head=${1}
+ shift
- printf "${ident}${COLOUR_BOLD}$@${COLOUR_NORMAL}\n"
+ cli_print $(( ${level} - 1 )) "%-12s %s" "${head}" "$@"
}
function cli_print() {
service_stop "${service}@${interface}"
}
+dhclient_status() {
+ local interface=${1}
+ local proto=${2}
+
+ local service=$(dhclient_proto2service ${proto})
+ assert isset service
+
+ service_status "${service}@${interface}"
+}
+
dhclient_proto2service() {
local proto=${1}
assert isset proto
case "${level}" in
DEBUG|INFO|WARNING|ERROR)
- message="${COLOUR_LOG[${level}]}${message}${COLOUR_NORMAL}"
+ message="${CLR_LOG[${level}]}${message}${CLR_RESET_ALL}"
;;
esac
- echo -e "${message}" >&2
+ printf "${message}\n" >&2
}
cli_headline 2 "Ports:"
zone_ports_status ${zone}
+ cli_space
cli_headline 2 "Configurations:"
zone_configs_cmd status ${zone}
-
cli_space
+
exit ${EXIT_OK}
}
config_read $(zone_dir ${zone})/configs/${config}
- printf " %10s - " "${HOOK}"
- if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
- echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}"
+ local status
+ if dhclient_status ${zone} ipv4; then
+ status="${MSG_HOOK_UP}"
else
- echo -ne "${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
+ status="${MSG_HOOK_DOWN}"
fi
- echo " - ${ADDRESS}/${PREFIX}"
+ cli_statusline 3 "${HOOK}" "${status}"
- if [ -n "${GATEWAY}" ]; then
- echo " Gateway: ${GATEWAY}"
+ cli_print_fmt1 3 "IPv4 address" "$(routing_db_get ${zone} ipv4 local-ip-address)"
+ local gateway=$(routing_db_get ${zone} ipv4 remote-ip-address)
+ if isset gateway; then
+ cli_print_fmt1 3 "Gateway" "${gateway}"
fi
exit ${EXIT_OK}
config_read $(zone_dir ${zone})/configs/${config}
- printf " %10s - " "${HOOK}"
+ local status
if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
- echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}"
+ status=${MSG_HOOK_UP}
else
- echo -ne "${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
+ status=${MSG_HOOK_DOWN}
fi
- echo " - ${ADDRESS}/${PREFIX}"
+ cli_statusline 3 "${HOOK}" "${status}"
+ cli_print_fmt1 3 "IPv4 address" "${ADDRESS}/${PREFIX}"
if [ -n "${GATEWAY}" ]; then
- echo " Gateway: ${GATEWAY}"
+ cli_print_fmt1 3 "Gateway" "${GATEWAY}"
fi
exit ${EXIT_OK}
local zone=${1}
local port=${2}
- printf " %-10s - " "${port}"
+ local status
if ! device_is_up ${port}; then
- echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
+ status=${MSG_DEVICE_STATUS_UP}
elif ! device_has_carrier ${port}; then
- echo -ne "${COLOUR_DOWN}NO-CARRIER${COLOUR_NORMAL}"
+ status=${MSG_DEVICE_STATUS_NOCARRIER}
elif [ -n "$(stp_bridge_get_protocol ${zone})" ]; then
local state=$(stp_port_get_state ${zone} ${port})
- local colour="COLOUR_STP_${state}"
- printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
+ state="MSG_STP_${state}"
+ status="${!state}"
- echo -n " - DSR: $(stp_port_get_designated_root ${zone} ${port})"
- echo -n " - Cost: $(stp_port_get_cost ${zone} ${port})"
+ status="${status} - DSR: $(stp_port_get_designated_root ${zone} ${port})"
+ status="${status} - Cost: $(stp_port_get_cost ${zone} ${port})"
else
- echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}"
+ status=${MSG_DEVICE_STATUS_UP}
fi
-
- echo
+ cli_statusline 3 "${port}" "${status}"
exit ${EXIT_OK}
}
exit ${EXIT_OK}
}
-
-run $@