]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/network
bash-completion: Add some basic completion for DHCP servers
[people/stevee/network.git] / src / network
index 3d3b31ab80fb23063d8087873e2149421cfbcb02..867e3a8b433aa957cc7d77b2a829969890366f48 100644 (file)
@@ -58,35 +58,45 @@ function cli_device() {
                exit ${EXIT_OK}
        fi
 
-       local device=${1}
-       local action=${2}
-       shift 2
-
-       if ! isset device; then
-               cli_show_man network-device
-               return ${EXIT_ERROR}
-       fi
-
-       assert device_exists ${device}
+       local action="${1}"
+       shift
 
        case "${action}" in
-               discover)
-                       cli_device_discover ${device} $@
-                       ;;
-               monitor)
-                       cli_device_monitor "${device}" $@
-                       ;;
-               status)
-                       cli_device_status ${device}
-                       ;;
-               unlock)
-                       cli_device_serial_unlock ${device} $@
-                       ;;
-               ussd)
-                       cli_device_send_ussd_command "${device}" $@
+               list)
+                       cli_device_list $@
                        ;;
                *)
-                       cli_show_man network-device
+                       local device="${action}"
+                       action="${1}"
+                       shift
+
+                       if ! isset device; then
+                               cli_show_man network-device
+                               return ${EXIT_ERROR}
+                       fi
+
+                       assert device_exists ${device}
+
+                       case "${action}" in
+                               discover)
+                                       cli_device_discover ${device} $@
+                                       ;;
+                               monitor)
+                                       cli_device_monitor "${device}" $@
+                                       ;;
+                               status)
+                                       cli_device_status ${device}
+                                       ;;
+                               unlock)
+                                       cli_device_serial_unlock ${device} $@
+                                       ;;
+                               ussd)
+                                       cli_device_send_ussd_command "${device}" $@
+                                       ;;
+                               *)
+                                       cli_show_man network-device
+                                       ;;
+                       esac
                        ;;
        esac
 
@@ -94,8 +104,8 @@ function cli_device() {
 }
 
 function cli_device_status() {
-       local device=${1}
-       assert device_exists ${device}
+       local device="${1}"
+       assert isset device
 
        # Disable debugging output here.
        local log_disable_stdout=${LOG_DISABLE_STDOUT}
@@ -107,11 +117,17 @@ function cli_device_status() {
        cli_headline 1 "Device status: ${device}"
        cli_print_fmt1 1 "Name"         "${device}"
 
-       # Handle serial devices.
-       if [ "${type}" = "serial" ]; then
-               cli_device_status_serial ${device}
-               return $?
-       fi
+       # Handle special devices
+       case "${type}" in
+               phy)
+                       cli_device_status_phy "${device}"
+                       return $?
+                       ;;
+               serial)
+                       cli_device_status_serial "${device}"
+                       return $?
+                       ;;
+       esac
 
        # Print the device status.
        device_is_up ${device} &>/dev/null
@@ -170,6 +186,18 @@ function cli_device_status() {
                cli_space
        fi
 
+       case "${type}" in
+               wireless*)
+                       local phy="$(device_get_phy "${device}")"
+                       if isset phy; then
+                               cli_headline 2 "PHY"
+                               cli_print_fmt1 2 "Name" "${phy}"
+                               cli_print_fmt1 2 "Address" "$(phy_get_address "${phy}")"
+                               cli_space
+                       fi
+                       ;;
+       esac
+
        # Reset the logging level.
        LOG_DISABLE_STDOUT=${log_disable_stdout}
 }
@@ -235,6 +263,28 @@ function cli_device_status_serial() {
        cli_space
 }
 
+function cli_device_status_phy() {
+       local phy="${1}"
+       assert phy_exists "${phy}"
+
+       local address="$(phy_get_address "${phy}")"
+       cli_print_fmt1 1 "Address" "${address}"
+       cli_space
+
+       local devices="$(phy_get_devices "${phy}")"
+       if isset devices; then
+               cli_headline 2 "Soft interfaces"
+
+               local device
+               for device in ${devices}; do
+                       cli_print 2 "* %s" "${device}"
+               done
+               cli_space
+       fi
+
+       return ${EXIT_OK}
+}
+
 function cli_device_discover() {
        local device=${1}
        shift
@@ -440,6 +490,15 @@ function cli_device_monitor() {
        exit $?
 }
 
+function cli_device_list() {
+       local device
+       for device in $(device_list); do
+               cli_device_status "${device}"
+       done
+
+       exit ${EXIT_OK}
+}
+
 function cli_hostname() {
        if cli_help_requested $@; then
                cli_show_man network
@@ -937,7 +996,7 @@ function cli_dhcpd_subnet_show() {
                cli_headline $(( ${level} + 2 )) "Options"
 
                local option
-               for option in $(dhcpd_subnet_options ${proto}); do
+               for option in $(dhcpd_subnet_options_list ${proto}); do
                        [ -n "${options[${option}]}" ] || continue
 
                        cli_print_fmt1 $(( ${level} + 2 )) \
@@ -965,7 +1024,7 @@ function cli_dhcpd_subnet_show() {
        cli_space
 }
 
-function cli_dhcpd_options() {
+function cli_dhcpd_subnet_options() {
        local proto=${1}
        assert isset proto
        shift
@@ -974,8 +1033,6 @@ function cli_dhcpd_options() {
        assert isset subnet_id
        shift
 
-       local valid_options=$(dhcpd_subnet_options ${proto})
-
        local key val
        while [ $# -gt 0 ]; do
                case "${1}" in
@@ -1149,7 +1206,7 @@ function cli_dns_server() {
 
        case "${cmd}" in
                list)
-                       dns_server_list
+                       dns_server_show
                        exit ${EXIT_OK}
                        ;;
                add)
@@ -1185,6 +1242,57 @@ function cli_dns_server() {
        exit ${EXIT_OK}
 }
 
+function cli_raw() {
+       local cmd="${1}"
+       assert isset cmd
+       shift
+
+       case "${cmd}" in
+               list-devices)
+                       device_list
+                       ;;
+               list-dhcpd-ranges-of-subnet)
+                       dhcpd_subnet_range_list $@
+                       ;;
+               list-dhcpd-settings)
+                       dhcpd_global_settings_list $@
+                       ;;
+               list-dhcpd-subnets)
+                       dhcpd_subnet_list $@
+                       ;;
+               list-dhcpd-subnet-options)
+                       dhcpd_subnet_options_list $@
+                       ;;
+               list-dns-servers)
+                       dns_server_list
+                       ;;
+               list-free-ports)
+                       port_list_free
+                       ;;
+               list-hooks)
+                       hook_list $@
+                       ;;
+               list-ports)
+                       port_list
+                       ;;
+               list-ports-of-zone)
+                       zone_get_ports $@
+                       ;;
+               list-settings)
+                       network_settings_list
+                       ;;
+               list-zones)
+                       zones_get_all
+                       ;;
+               *)
+                       error "No such command: ${cmd}"
+                       exit ${EXIT_ERROR}
+                       ;;
+       esac
+
+       exit ${EXIT_OK}
+}
+
 # Process the given action
 case "${action}" in
        init)
@@ -1209,6 +1317,10 @@ case "${action}" in
                cli_help $@
                ;;
 
+       raw)
+               cli_raw $@
+               ;;
+
        *)
                error "Invalid command given: ${action}"
                cli_usage "network help"