]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/bash-completion/network
ipsec: security policies: Make integrity command plural
[people/ms/network.git] / src / bash-completion / network
index 27272e9b09c1eabef8a6102a37f36e251f38db22..2621628a1e4b6a3c43a9eb7c0b75af1b2d884dd9 100644 (file)
@@ -48,6 +48,27 @@ _network_complete_zones() {
        COMPREPLY=( $(compgen -W "$(network raw list-zones)" -- "${cur}") )
 }
 
+_network_color() {
+       local words=( $@ )
+
+       local commands="set reset"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_description() {
+       local words=( $@ )
+
+       local commands="edit show"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
 _network_device() {
        local words=( $@ )
 
@@ -78,7 +99,7 @@ _network_device_subcommand() {
                COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
                return 0
        fi
-                       
+
        case "${cmd}" in
                ussd)
                        # TODO
@@ -247,17 +268,47 @@ _network_port() {
 _network_port_subcommand() {
        local words=( $@ )
 
-       local commands="create down edit identify remove status up"
+       local commands="color create description down edit identify remove status up"
        local cmd="$(_network_find_on_cmdline "${commands}")"
        if [[ -z "${cmd}" ]]; then
                COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
                return 0
        fi
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               color)
+                       _network_color ${args}
+                       ;;
+               description)
+                       _network_description ${args}
+                       ;;
+       esac
+
 }
 
 _network_route() {
        local words=( $@ )
 
+       local commands="static"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+       case "${cmd}" in
+               static)
+                       local args="${words[@]}"
+                       _network_route_static ${args}
+                       ;;
+       esac
+
+}
+
+_network_route_static() {
+       local words=( $@ )
+
        local commands="add list remove reload"
        local cmd="$(_network_find_on_cmdline "${commands}")"
        if [[ -z "${cmd}" ]]; then
@@ -289,6 +340,289 @@ _network_settings() {
        COMPREPLY=( $(compgen -W "${keys}" -- "${cur}") )
 }
 
+_network_vpn() {
+       local words=( $@ )
+
+       local commands="ipsec security-policies"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               ipsec)
+                       _network_vpn_ipsec ${args}
+                       ;;
+               security-policies)
+                       _network_vpn_security_policies ${args}
+                       ;;
+               esac
+}
+
+_network_vpn_ipsec() {
+       local words=( $@ )
+
+       local commands="connection"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               connection)
+                       _network_vpn_ipsec_connection ${args}
+                       ;;
+               esac
+}
+
+_network_vpn_ipsec_connection() {
+       local words=( $@ )
+
+       local commands="destroy new $(network raw list-ipsec-connections)"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               destroy)
+                       :
+                       ;;
+               new)
+                       :
+                       ;;
+               *)
+                       if network raw ipsec-connection-exists ${cmd}; then
+                               _network_vpn_ipsec_connection_subcommands ${cmd} ${args}
+                       fi
+                       ;;
+               esac
+}
+
+_network_vpn_ipsec_connection_subcommands() {
+       local connection=${1}
+       shift
+       local words=( $@ )
+
+       local commands="authentication color description down inactivity-timeout local mode peer remote security-policy show up"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               authentication)
+                       _network_vpn_ipsec_connection_subcommands_authentication ${connection} ${args}
+                       ;;
+               color)
+                       _network_color ${args}
+                       ;;
+               description)
+                       _network_description ${args}
+                       ;;
+               local)
+                       _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "local" ${args}
+                       ;;
+               mode)
+                       _network_vpn_ipsec_connection_subcommands_mode ${args}
+                       ;;
+               remote)
+                       _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "remote" ${args}
+                       ;;
+               security-policy)
+                       _network_vpn_ipsec_connection_subcommands_security_policy ${args}
+                       ;;
+               esac
+}
+
+_network_vpn_ipsec_connection_subcommands_authentication() {
+       local connection=${1}
+       shift
+       local words=( $@ )
+
+       local commands="mode pre-shared-key"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               mode)
+                       _network_vpn_ipsec_connection_subcommands_authentication_mode ${connection} ${args}
+                       ;;
+                       esac
+}
+
+_network_vpn_ipsec_connection_subcommands_local_remote() {
+       local connection=${1}
+       local type=${2}
+       shift 2
+       local words=( $@ )
+
+       local commands="id prefix"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               prefix)
+                       _network_vpn_ipsec_connection_subcommands_prefix "${connection}" "${type}" ${args}
+                       ;;
+                       esac
+}
+
+_network_vpn_ipsec_connection_subcommands_prefix() {
+       :
+}
+
+_network_vpn_ipsec_connection_subcommands_authentication_mode() {
+       local connection=${1}
+       shift
+       local words=( $@ )
+
+       local commands="PSK"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_vpn_ipsec_connection_subcommands_mode() {
+       local words=( $@ )
+
+       local commands="gre-transport tunnel vti"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_vpn_ipsec_connection_subcommands_security_policy() {
+       local words=( $@ )
+
+       local commands="$(network raw list-vpn-security-policies-all)"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_vpn_security_policies() {
+       local words=( $@ )
+
+       local commands="destroy new $(network raw list-vpn-security-policies-all)"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               destroy)
+                       :
+                       ;;
+               new)
+                       :
+                       ;;
+               *)
+                       if network raw vpn-security-policy-exists ${cmd}; then
+                               _network_vpn_security_policies_subcommands ${cmd} ${args}
+                       fi
+                       ;;
+               esac
+}
+
+_network_vpn_security_policies_subcommands() {
+       local policy=${1}
+       shift
+       local words=( $@ )
+
+       local commands="ciphers compression group-types integrities key-exchange lifetime pfs pseudo-random-functions show"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               ciphers)
+                       _network_vpn_security_policies_subcommands_ciphers ${policy} ${args}
+                       ;;
+               compression)
+                       _network_vpn_security_policies_subcommands_compression ${policy} ${args}
+                       ;;
+               group-types)
+                       _network_vpn_security_policies_subcommands_group_types ${policy} ${args}
+                       ;;
+               integrities)
+                       _network_vpn_security_policies_subcommands_integrities ${policy} ${args}
+                       ;;
+               pseudo-random-functions)
+                       _network_vpn_security_policies_subcommands_pseudo_random_functions ${policy} ${args}
+                       ;;
+               key-exchange)
+                       _network_vpn_security_policies_subcommands_key_exchange ${policy} ${args}
+                       ;;
+               pfs)
+                       _network_vpn_security_policies_subcommands_pfs ${policy} ${args}
+                       ;;
+               esac
+}
+
+_network_vpn_security_policies_subcommands_ciphers() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_compression() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_group_types() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_integrities() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_pseudo_random_functions() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_key_exchange() {
+       :
+}
+
+_network_vpn_security_policies_subcommands_pfs() {
+       :
+}
+
 _network_zone() {
        local words=( $@ )
 
@@ -299,11 +633,11 @@ _network_zone() {
                return 0
        fi
 
+
        local args="${words[@]:1}"
        case "${cmd}" in
                new)
-                       # TODO
-                       return 0
+                       _network_zone_new ${args}
                        ;;
                destroy)
                        _network_complete_zones
@@ -316,19 +650,37 @@ _network_zone() {
        esac
 }
 
+_network_zone_new() {
+       local words=( $@ )
+       local cmd=${words[@]:0:1}
+
+       # Suggest useful zone names
+       if [[ -z "${cmd}" ]]; then
+               local commands="$(network raw list-next-free-zones)"
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+
+       # If a valid zone name was entered, we can move on
+       elif network raw zone-name-is-valid ${cmd}; then
+               local args="${words[@]:1}"
+               _network_complete_hooks zone ${args}
+       fi
+
+       return 0
+}
+
 _network_zone_subcommand() {
        local zone="${1}"
        shift
 
        local words=( $@ )
 
-       local commands="config disable down edit enable identify port rename status up"
+       local commands="color config description disable down edit enable identify port rename status up"
        local cmd="$(_network_find_on_cmdline "${commands}")"
        if [[ -z "${cmd}" ]]; then
                COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
                return 0
        fi
-                       
+
        local args="${words[@]:1}"
        case "${cmd}" in
                config)
@@ -337,6 +689,12 @@ _network_zone_subcommand() {
                port)
                        _network_zone_subcommand_port "${zone}" ${args}
                        ;;
+               color)
+                       _network_color ${args}
+                       ;;
+               description)
+                       _network_description ${args}
+                       ;;
        esac
 }
 
@@ -346,20 +704,60 @@ _network_zone_subcommand_config() {
 
        local words=( $@ )
 
-       local commands="new destroy"
+       local commands="destroy list new $(network raw list-zone-config-hids ${zone})"
+
        local cmd="$(_network_find_on_cmdline "${commands}")"
        if [[ -z "${cmd}" ]]; then
                COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
                return 0
        fi
 
+       local args="${words[@]:1}"
        case "${cmd}" in
                new)
                        _network_complete_hooks "config"
                        ;;
+               destroy)
+                       _network_zone_subcommand_config_destroy ${zone} ${args}
+                       ;;
+               *)
+                       if network raw zone-config-id-is-valid ${zone} ${cmd} || network raw zone-config-hid-is-valid ${zone} ${cmd}; then
+                               _network_zone_subcommand_config_subcommand ${zone} ${args}
+                       fi
+                       ;;
        esac
 }
 
+_network_zone_subcommand_config_subcommand() {
+       local zone="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="edit"
+
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_zone_subcommand_config_destroy() {
+       local zone="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="$(network raw list-zone-config-ids ${zone})"
+
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
 _network_zone_subcommand_port() {
        local zone="${1}"
        shift
@@ -428,7 +826,7 @@ _network() {
                                ;;
                        *)
                                COMPREPLY=( $(compgen -W "device dhcpv4 dhcpv6 dns-server \
-                                       help hostname port reset route settings status zone" \
+                                       help hostname port reset route settings status vpn zone" \
                                        -- "${cur}") )
                                ;;
                esac
@@ -460,6 +858,9 @@ _network() {
                        # start, stop and status optionally take a zone
                        _network_complete_zones
                        ;;
+               vpn)
+                       _network_vpn ${args}
+                       ;;
                zone)
                        _network_zone ${args}
                        ;;