From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonatan Schlag To: network@lists.ipfire.org Subject: [PATCH 6/6] ipsec: add basic bash completion for ipsec Date: Thu, 03 Aug 2017 12:51:27 +0200 Message-ID: <1501757487-5782-6-git-send-email-jonatan.schlag@ipfire.org> In-Reply-To: <1501757487-5782-1-git-send-email-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1082309386335927986==" List-Id: --===============1082309386335927986== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Jonatan Schlag --- src/bash-completion/network | 185 ++++++++++++++++++++++++++++++++++++++++++= +- 1 file changed, 184 insertions(+), 1 deletion(-) diff --git a/src/bash-completion/network b/src/bash-completion/network index 34d3f2f..4e392b9 100644 --- a/src/bash-completion/network +++ b/src/bash-completion/network @@ -340,6 +340,186 @@ _network_settings() { COMPREPLY=3D( $(compgen -W "${keys}" -- "${cur}") ) } =20 +_network_vpn() { + local words=3D( $@ ) + + local commands=3D"ipsec" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${words[@]:1}" + case "${cmd}" in + ipsec) + _network_vpn_ipsec ${args} + ;; + esac +} + +_network_vpn_ipsec() { + local words=3D( $@ ) + + local commands=3D"connection" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${words[@]:1}" + case "${cmd}" in + connection) + _network_vpn_ipsec_connection ${args} + ;; + esac +} + +_network_vpn_ipsec_connection() { + local words=3D( $@ ) + + local commands=3D"destroy new $(network raw list-ipsec-connections)" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${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=3D${1} + shift + local words=3D( $@ ) + + local commands=3D"authentication inactivity-timout local mode peer remote s= ecurity-policy show" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${words[@]:1}" + case "${cmd}" in + authentication) + _network_vpn_ipsec_connection_subcommands_authentication ${connection} ${= args} + ;; + local) + _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "loc= al" ${args} + ;; + mode) + _network_vpn_ipsec_connection_subcommands_mode ${args} + ;; + remote) + _network-vpn_ipsec_connection_subcommands_local_remote ${connection} "rem= ote" ${args} + ;; + security-policy) + _network_vpn_ipsec_connection_subcommands_security_policy ${args} + ;; + esac +} + +_network_vpn_ipsec_connection_subcommands_authentication() { + local connection=3D${1} + shift + local words=3D( $@ ) + + local commands=3D"psk mode" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${words[@]:1}" + case "${cmd}" in + mode) + _network_vpn_ipsec_connection_subcommands_authentication_mode ${connectio= n} ${args} + ;; + esac +} + +_network_vpn_ipsec_connection_subcommands_local_remote() { + local connection=3D${1} + local type=3D${2} + shift 2 + local words=3D( $@ ) + + local commands=3D"id prefix" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + + local args=3D"${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=3D${1} + shift + local words=3D( $@ ) + + local commands=3D"PSK" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi +} + +_network_vpn_ipsec_connection_subcommands_mode() { + local words=3D( $@ ) + + local commands=3D"gre-transport tunnel vti" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi +} + +_network_vpn_ipsec_connection_subcommands_security_policy() { + local words=3D( $@ ) + + local commands=3D"$(network raw list-vpn-security-policies-all)" + local cmd=3D"$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=3D( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi +} + _network_zone() { local words=3D( $@ ) =20 @@ -543,7 +723,7 @@ _network() { ;; *) COMPREPLY=3D( $(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 @@ -575,6 +755,9 @@ _network() { # start, stop and status optionally take a zone _network_complete_zones ;; + vpn) + _network_vpn ${args} + ;; zone) _network_zone ${args} ;; --=20 2.6.3 --===============1082309386335927986==--