aboutsummaryrefslogtreecommitdiffstats
path: root/src/_openvpn-install
blob: 3fd204a6cc6d6d53cc8ed8400212b98565e6516f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#compdef openvpn-install openvpn-install.sh
# ------------------------------------------------------------------------------
# Copyright (c) 2025 Github zsh-users - https://github.com/zsh-users
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for openvpn-install (https://github.com/angristan/openvpn-install)
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Shohei Yoshida (https://github.com/syohex) <syohex@gmail.com>
#
# ------------------------------------------------------------------------------

_openvpn_install() {
  typeset -A opt_args
  local context state line

  local curcontext="$curcontext"

  local ret=1

  _arguments -C \
    '--verbose[show detailed output]' \
    '(--log --no-log)--log[log file path]:file:_files' \
    '(--log --no-log)--no-log[disable file logging]' \
    '--no-color[disable colored output]' \
    '(- *)'{-h,--help}'[show help]' \
    '1: :_openvpn_install_commands' \
    '*:: :->args' \
    && ret=0;

  case "$state" in
    (args)
      case $words[1] in
        (install)
          local -a dns_providers=(
            system unbound cloudflare quad9 quad9-uncensored
            fdn dnswatch opendns google yandex adguard nextdns custom
          )

          local -a ciphers=(
            AES-128-GCM AES-192-GCM AES-256-GCM AES-128-CBC
            AES-192-CBC AES-256-CBC CHACHA20-POLY1305
          )

          _arguments \
            '(-i --interactive)'{-i,--interactive}'[run interactive install wizard]' \
            '--endpoint[public IP or hostname for clients]:host_or_ip' \
            '--endpoint-type[endpoint IP version(default: 4)]:version:(4 6)' \
            '--ip[server listening IP]:addr' \
            '(--client-ipv4 --no-client-ipv4)--client-ipv4[enable IPv4 for VPN clients]' \
            '(--client-ipv4 --no-client-ipv4)--no-client-ipv4[disable IPv4 for VPN clients]' \
            '(--client-ipv6 --no-client-ipv6)--client-ipv6[enable IPv6 for VPN clients]' \
            '(--client-ipv6 --no-client-ipv6)--no-client-ipv6[disable IPv6 for VPN clients]' \
            '--subnet-ipv4[IPv4 VPN subnet(default: 10.8.0.0)]:subnet' \
            '--subnet-ipv6[IPv6 VPN subnet(default: fd42:42:42:42::)]:subnet' \
            '(--port --port-random)--port[OpenVPN port]:port' \
            '(--port --port-random)--port-random[use random port(49152-65535)]:port' \
            '--protocol[UDP or TCP(default: udp)]:proto:(udp tcp)' \
            '--mtu[tunnel MTU(default: 1500)]:size' \
            '--dns[DNS provider(default: cloudflare)]:provider:(($dns_providers))' \
            '--dns-primary[custom primary DNS]:ip' \
            '--dns-secondary[custom secondary DNS]:ip' \
            '--cipher[data channel cipher(default: AES-128-GCM)]:cipher:(($ciphers))' \
            '--cert-type[certificate type(default: ecdsa)]:type:(ecdsa rsa)' \
            '--cert-curve[ECDSA curve(default: prime256v1)]:curve:(prime256v1 secp384r1 secp521r1)' \
            '--rsa-bits[RSA key size(default: 2048)]:size:(2048 3072 4096)' \
            '--cc-cipher[control channel cipher]:cipher' \
            '--tls-version-min[minimum TLS version(default: 1.2)]:min_ver:(1.2 1.3)' \
            '--tls-ciphersuites[TLS 1.3 cipher suites, colon-separated]:list' \
            '--tls-groups[key exchange groups, colon-separated]:list' \
            '--hmac[HMAC algorithm(default: SHA256)]:alg:(SHA256 SHA384 SHA512)' \
            '--tls-sig[TLS mode(default: crypt-v2)]:mode:(crypt-v2 crypt auth)' \
            '--server-cert-days[server cert validity in days(default: 3650)]:days' \
            '--multi-client[allow same cert on multiple devices]' \
            '--client[initial client name(default: client)]:name' \
            '--client-password[password-protect client]:password' \
            '--client-cert-days[client cert validity in days(default: 3650)]:days' \
            '--no-client[skip initial client creation]' \
            && ret=0
          ;;
        (uninstall)
          _arguments \
            '(-f --force)'{-f,--force}'[skip confirmation prompt]' \
            && ret=0
          ;;
        (client)
          _openvpn_install_client && ret=0
          ;;
        (server)
          _openvpn_install_server && ret=0
          ;;
      esac
  esac

  return ret
}

_openvpn_install_commands() {
  local -a commands=(
    'install:Install and configure OpenVPN server'
    'uninstall:Remove OpenVPN server'
    'client:Manage client certificates'
    'server:Server management'
    'interactive:Launch interactive menu'
  )

  _describe -t 'commands' 'commands' commands
}

_openvpn_install_client() {
  local ret=1

  _arguments -C \
    '(- *)'{-h,--help}'[Print this usage information]' \
    '1: :_openvpn_install_client_commands' \
    '*:: :->args' \
    && ret=0

  case $state in
    (args)
      case $words[1] in
        (add)
          _arguments \
            '--password[password-protect client]:password' \
            '--cert-days[certificate validity in days(default: 3650)]:days' \
            '--output[output path for .ovpn file(default: ~/<name>.ovpn)]:file:_files' \
            '1:name' \
            && ret=0
          ;;
        (list)
          _arguments \
            '--format[output format(default: table)]:format:(table json)' \
            && ret=0
          ;;
        (revoke)
          _arguments \
            '(-f --force)'{-f,--force}'[skip confirmation/warning]' \
            && ret=0
          ;;
        (renew)
          _arguments \
            '--cert-days[new certificate validity in days(default: 3650)]:days' \
            && ret=0
          ;;
      esac
    ;;
  esac

  return ret
}

_openvpn_install_client_commands() {
  local -a commands=(
    'add:add a new client'
    'list:list all clients'
    'revoke:revoke a client certificate'
    'renew:renew a client certificate'
  )

  _describe -t commands 'command' commands "$@"
}

_openvpn_install_server() {
  local ret=1

  _arguments -C \
    '(- *)'{-h,--help}'[Print this usage information]' \
    '1: :_openvpn_install_server_commands' \
    '*:: :->args' \
    && ret=0

  case $state in
    (args)
      case $words[1] in
        (status)
          _arguments \
            '--format[output format(default: table)]:format:(table json)' \
            && ret=0
          ;;
        (renew)
          _arguments \
            '--cert-days[new certificate validity in days(default: 3650)]:days' \
            '(-f --force)'{-f,--force}'[skip confirmation/warning]' \
            && ret=0
          ;;
      esac
    ;;
  esac

  return ret
}

_openvpn_install_server_commands() {
  local -a commands=(
    'status:list currently connected clients'
    'renew:renew server certificate'
  )
  _describe -t commands 'command' commands "$@"
}

_openvpn_install "$@"

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et