]> git.ipfire.org Git - people/ms/network.git/commitdiff
DHCP: Format lease time in human-readable format
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Sep 2016 08:35:42 +0000 (10:35 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Sep 2016 08:35:42 +0000 (10:35 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.util
src/network

index 91b5148ca56d1836a09f910539f51833acd7693e..9c3601b1b18c843ae83d9865b8764a37ac944985 100644 (file)
@@ -113,6 +113,26 @@ format() {
        printf -v "${key}" "${format}" "$@"
 }
 
+format_time() {
+       local s=${1}
+       local ret m
+
+       local units="s m h"
+
+       local unit
+       for unit in ${units}; do
+               m=$(( ${s} % 60 ))
+               s=$(( ${s} / 60 ))
+
+               if [ ${m} -gt 0 ]; then
+                       ret="${m}${unit} ${ret}"
+               fi
+       done
+
+       # Remove whitespace
+       echo ${ret}
+}
+
 assign() {
        local key=${1}
        assert isset key
index e45e8ada5f07e5103db26f8a739c15af8655bafb..719664e5293baa6f8660fa6e6c59e7e3beda429b 100644 (file)
@@ -840,11 +840,11 @@ cli_dhcpd_show() {
                ipv6)
                        cli_headline 2 "Lease times"
                        if isinteger VALID_LIFETIME; then
-                               cli_print_fmt1 2 "Valid lifetime" "${VALID_LIFETIME}s"
+                               cli_print_fmt1 2 "Valid lifetime" "$(format_time ${VALID_LIFETIME})"
                        fi
 
                        if isinteger PREFERRED_LIFETIME; then
-                               cli_print_fmt1 2 "Preferred lifetime" "${PREFERRED_LIFETIME}s"
+                               cli_print_fmt1 2 "Preferred lifetime" "$(format_time ${PREFERRED_LIFETIME})"
                        fi
 
                        cli_space
@@ -854,11 +854,11 @@ cli_dhcpd_show() {
                        cli_space
 
                        cli_headline 2 "Lease times"
-                       cli_print_fmt1 2 "Default lease time" "${DEFAULT_LEASE_TIME}s"
-                       cli_print_fmt1 2 "Max. lease time" "${MAX_LEASE_TIME}s"
+                       cli_print_fmt1 2 "Default lease time" "$(format_time ${DEFAULT_LEASE_TIME})"
+                       cli_print_fmt1 2 "Max. lease time" "$(format_time ${MAX_LEASE_TIME})"
 
                        if isset MIN_LEASE_TIME; then
-                               cli_print_fmt1 2 "Min. lease time" "${MIN_LEASE_TIME}s"
+                               cli_print_fmt1 2 "Min. lease time" "$(format_time ${MIN_LEASE_TIME})"
                        fi
 
                        cli_space