]> git.ipfire.org Git - people/ms/network.git/commitdiff
Update the output of some hooks.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jun 2012 22:38:25 +0000 (22:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jun 2012 22:38:25 +0000 (22:38 +0000)
functions.cli
functions.dhclient
functions.logging
hooks/zones/bridge
hooks/zones/bridge.configs/ipv4-dhcp
hooks/zones/bridge.configs/ipv4-static
hooks/zones/bridge.ports/ethernet
hooks/zones/pppoe.ports/ethernet

index 579a263fc986202f4bd804924e44d0e3f6cf1522..34bfd71409b5a84e979e865a5e14ff9393759af0 100644 (file)
@@ -57,16 +57,29 @@ function cli_device_headline() {
                        ;;
        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
@@ -103,25 +116,26 @@ function cli_device_stats() {
        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() {
index e20ad149cd4e50284ad590528aa30d586017b72a..f8f4c12d3214dbd94b4317a0d9dccaeeaaa68e72 100644 (file)
@@ -42,6 +42,16 @@ dhclient_stop() {
        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
index 6cb827815b4ef02ef998045754e114859b506f00..e43f64b81cbb87dbfe8f57f9d4c324bd7e69cc6a 100644 (file)
@@ -50,9 +50,9 @@ function log() {
 
        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
 }
index 19959247a811eb327dfd4bf0058a2e2bb899bbbe..e5cf9c78f88d7609d6beecd33995ee20e06e1ac4 100755 (executable)
@@ -198,10 +198,11 @@ function _status() {
 
        cli_headline 2 "Ports:"
        zone_ports_status ${zone}
+       cli_space
 
        cli_headline 2 "Configurations:"
        zone_configs_cmd status ${zone}
-
        cli_space
+
        exit ${EXIT_OK}
 }
index eb9ad33ce97f68c1a4e1fea20cd04940a9c7b62c..903839b4bab650e4ea0d0fd6cecd678be7b6149f 100755 (executable)
@@ -93,16 +93,18 @@ function _status() {
        
        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}
index fb72bcb311bd6f8bf19c6bf9d2a5789c6aad7d58..d6ea3534f92076120d3f6bf7b42783a9e0a75faa 100755 (executable)
@@ -119,16 +119,17 @@ function _status() {
        
        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}
index dcb6f84032804d515a49e4ebaaddec846e3e77ee..a25141ad3a9cbfb7f8761ea4ce0a5589c8a03532 100755 (executable)
@@ -135,23 +135,22 @@ function _status() {
        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}
 }
index 67a781ff6a9f92015fe1112a7e03dc665946fdab..46411a7496aa7ae53332f5eace0ad0da7b43c210 100644 (file)
@@ -111,5 +111,3 @@ function _status() {
 
        exit ${EXIT_OK}
 }
-
-run $@