]>
Commit | Line | Data |
---|---|---|
bae37360 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2014 Michael Tremer # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | # network(8) completion | |
22 | ||
1c6a4e30 | 23 | _network_find_on_cmdline () { |
bae37360 MT |
24 | local word subcommand c=0 |
25 | while [ ${c} -lt ${cword} ]; do | |
26 | word="${words[c]}" | |
27 | for subcommand in ${1}; do | |
28 | if [ "${subcommand}" = "${word}" ]; then | |
29 | echo "${subcommand}" | |
30 | return | |
31 | fi | |
32 | done | |
33 | ((c++)) | |
34 | done | |
35 | } | |
36 | ||
1c6a4e30 | 37 | _network_complete_hooks() { |
bae37360 MT |
38 | local type="${1}" |
39 | ||
40 | COMPREPLY=( $(compgen -W "$(network raw list-hooks "${type}")" -- "${cur}") ) | |
41 | } | |
42 | ||
1c6a4e30 | 43 | _network_complete_ports() { |
bae37360 MT |
44 | COMPREPLY=( $(compgen -W "$(network raw list-ports)" -- "${cur}") ) |
45 | } | |
46 | ||
1c6a4e30 | 47 | _network_complete_zones() { |
bae37360 MT |
48 | COMPREPLY=( $(compgen -W "$(network raw list-zones)" -- "${cur}") ) |
49 | } | |
50 | ||
b7fbb0cd JS |
51 | _network_color() { |
52 | local words=( $@ ) | |
53 | ||
54 | local commands="set reset" | |
55 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
56 | if [[ -z "${cmd}" ]]; then | |
57 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
58 | return 0 | |
59 | fi | |
60 | } | |
61 | ||
9d3ac4e4 JS |
62 | _network_description() { |
63 | local words=( $@ ) | |
64 | ||
65 | local commands="edit show" | |
66 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
67 | if [[ -z "${cmd}" ]]; then | |
68 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
69 | return 0 | |
70 | fi | |
71 | } | |
1c6a4e30 | 72 | _network_device() { |
bae37360 MT |
73 | local words=( $@ ) |
74 | ||
75 | local commands="list $(network raw list-devices)" | |
76 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
77 | if [[ -z "${cmd}" ]]; then | |
78 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
79 | return 0 | |
80 | fi | |
81 | ||
82 | local args="${words[@]:1}" | |
83 | case "${cmd}" in | |
84 | list) | |
85 | return 0 | |
86 | ;; | |
87 | *) | |
88 | _network_device_subcommand ${args} | |
89 | ;; | |
90 | esac | |
91 | } | |
92 | ||
1c6a4e30 | 93 | _network_device_subcommand() { |
bae37360 MT |
94 | local words=( $@ ) |
95 | ||
f5ee091e | 96 | local commands="discover identify monitor status unlock ussd" |
bae37360 | 97 | local cmd="$(_network_find_on_cmdline "${commands}")" |
bae37360 | 98 | if [[ -z "${cmd}" ]]; then |
8d1d2745 | 99 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) |
bae37360 MT |
100 | return 0 |
101 | fi | |
b7fbb0cd | 102 | |
bae37360 MT |
103 | case "${cmd}" in |
104 | ussd) | |
105 | # TODO | |
106 | ;; | |
107 | esac | |
108 | } | |
109 | ||
1c6a4e30 | 110 | _network_dhcpd() { |
cc02f6be MT |
111 | local proto="${1}" |
112 | shift | |
113 | ||
114 | local words=( $@ ) | |
115 | ||
116 | local commands="edit reload restart show start stop subnet" | |
117 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
118 | if [[ -z "${cmd}" ]]; then | |
119 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
120 | return 0 | |
121 | fi | |
122 | ||
123 | local args="${words[@]:1}" | |
124 | case "${cmd}" in | |
125 | subnet) | |
126 | _network_dhcpd_subnet "${proto}" ${args} | |
127 | ;; | |
128 | esac | |
129 | } | |
130 | ||
1c6a4e30 | 131 | _network_dhcpd_subnet() { |
cc02f6be MT |
132 | local proto="${1}" |
133 | shift | |
134 | ||
135 | local words=( $@ ) | |
136 | ||
137 | local commands="new remove show $(network raw list-dhcpd-subnets "${proto}")" | |
138 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
139 | if [[ -z "${cmd}" ]]; then | |
140 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
141 | return 0 | |
142 | fi | |
143 | ||
144 | local subnet="${words[0]}" | |
145 | local args="${words[@]:1}" | |
146 | case "${cmd}" in | |
147 | new) | |
148 | : # TODO | |
149 | ;; | |
150 | remove) | |
151 | : # TODO | |
152 | ;; | |
153 | [0-9]*) | |
154 | _network_dhcpd_subnet_subcommand "${proto}" "${subnet}" ${args} | |
155 | ;; | |
156 | esac | |
157 | } | |
158 | ||
1c6a4e30 | 159 | _network_dhcpd_subnet_subcommand() { |
cc02f6be MT |
160 | local proto="${1}" |
161 | local subnet="${2}" | |
162 | shift 2 | |
163 | ||
164 | local words=( $@ ) | |
165 | ||
166 | local commands="edit options range show" | |
167 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
168 | if [[ -z "${cmd}" ]]; then | |
169 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
170 | return 0 | |
171 | fi | |
172 | ||
173 | local args="${words[@]:1}" | |
174 | case "${cmd}" in | |
175 | edit) | |
176 | : # TODO | |
177 | ;; | |
178 | options) | |
179 | _network_dhcpd_subnet_subcommand_options "${proto}" "${subnet}" ${args} | |
180 | ;; | |
181 | range) | |
182 | _network_dhcpd_subnet_subcommand_range "${proto}" "${subnet}" ${args} | |
183 | ;; | |
184 | esac | |
185 | } | |
186 | ||
1c6a4e30 | 187 | _network_dhcpd_subnet_subcommand_options() { |
cc02f6be MT |
188 | local proto="${1}" |
189 | local subnet="${2}" | |
190 | shift 2 | |
191 | ||
192 | local options option | |
193 | for option in $(network raw list-dhcpd-subnet-options "${proto}"); do | |
194 | options="${options} ${option}=" | |
195 | done | |
196 | ||
197 | COMPREPLY=( $(compgen -W "${options}" -- "${cur}") ) | |
198 | } | |
199 | ||
1c6a4e30 | 200 | _network_dhcpd_subnet_subcommand_range() { |
cc02f6be MT |
201 | local proto="${1}" |
202 | local subnet="${2}" | |
203 | shift 2 | |
204 | ||
205 | local words=( $@ ) | |
206 | ||
207 | local commands="new remove" | |
208 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
209 | if [[ -z "${cmd}" ]]; then | |
210 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
211 | return 0 | |
212 | fi | |
213 | ||
214 | case "${cmd}" in | |
215 | new) | |
216 | COMPREPLY=( $(compgen -W "--end= --start=" -- "${cur}") ) | |
217 | ;; | |
218 | remove) | |
219 | COMPREPLY=( $(compgen -W "$(network raw list-dhcpd-ranges-of-subnet "${proto}" "${subnet}")" \ | |
220 | -- "${cur}") ) | |
221 | ;; | |
222 | esac | |
223 | } | |
224 | ||
1c6a4e30 | 225 | _network_dns_server() { |
8d1d2745 MT |
226 | local words=( $@ ) |
227 | ||
228 | local commands="add list remove update" | |
229 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
230 | if [[ -z "${cmd}" ]]; then | |
231 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
232 | return 0 | |
233 | fi | |
234 | ||
235 | case "${cmd}" in | |
236 | remove) | |
237 | COMPREPLY=( $(compgen -W "$(network raw list-dns-servers)" \ | |
238 | -- "${cur}") ) | |
239 | ;; | |
240 | esac | |
241 | } | |
242 | ||
1c6a4e30 | 243 | _network_port() { |
bae37360 MT |
244 | local words=( $@ ) |
245 | ||
246 | local commands="new destroy $(network raw list-ports)" | |
247 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
248 | if [[ -z "${cmd}" ]]; then | |
249 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
250 | return 0 | |
251 | fi | |
252 | ||
253 | local args="${words[@]:1}" | |
254 | case "${cmd}" in | |
255 | new) | |
256 | _network_complete_hooks "port" | |
257 | ;; | |
258 | destroy) | |
259 | _network_complete_ports | |
260 | ;; | |
261 | *) | |
262 | local args="${words[@]:1}" | |
263 | _network_port_subcommand ${args} | |
264 | ;; | |
265 | esac | |
266 | } | |
267 | ||
1c6a4e30 | 268 | _network_port_subcommand() { |
bae37360 MT |
269 | local words=( $@ ) |
270 | ||
9d3ac4e4 | 271 | local commands="color create description down edit identify remove status up" |
bae37360 MT |
272 | local cmd="$(_network_find_on_cmdline "${commands}")" |
273 | if [[ -z "${cmd}" ]]; then | |
274 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
275 | return 0 | |
276 | fi | |
b7fbb0cd JS |
277 | |
278 | local args="${words[@]:1}" | |
279 | case "${cmd}" in | |
280 | color) | |
281 | _network_color ${args} | |
282 | ;; | |
9d3ac4e4 JS |
283 | description) |
284 | _network_description ${args} | |
285 | ;; | |
b7fbb0cd JS |
286 | esac |
287 | ||
bae37360 MT |
288 | } |
289 | ||
1c6a4e30 | 290 | _network_route() { |
8d1d2745 MT |
291 | local words=( $@ ) |
292 | ||
240367ba JS |
293 | local commands="static" |
294 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
295 | if [[ -z "${cmd}" ]]; then | |
296 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
297 | return 0 | |
298 | fi | |
299 | ||
300 | case "${cmd}" in | |
301 | static) | |
302 | local args="${words[@]}" | |
303 | _network_route_static ${args} | |
304 | ;; | |
305 | esac | |
306 | ||
307 | } | |
308 | ||
309 | _network_route_static() { | |
310 | local words=( $@ ) | |
311 | ||
86c225b8 | 312 | local commands="add list remove reload" |
8d1d2745 MT |
313 | local cmd="$(_network_find_on_cmdline "${commands}")" |
314 | if [[ -z "${cmd}" ]]; then | |
315 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
316 | return 0 | |
317 | fi | |
318 | ||
319 | case "${cmd}" in | |
320 | add) | |
321 | if [[ "${cur}" = -* ]]; then | |
322 | COMPREPLY=( $(compgen -W "--blackhole --gateway= --mtu= \ | |
323 | --prohibit --unreachable" -- "${cur}") ) | |
324 | fi | |
325 | ;; | |
326 | list) | |
327 | # TODO auto-complete options like --protocol here | |
328 | COMPREPLY=( $(compgen -W "--protocol=" -- "${cur}") ) | |
329 | ;; | |
330 | esac | |
331 | } | |
332 | ||
1c6a4e30 | 333 | _network_settings() { |
bae37360 MT |
334 | local words=( $@ ) |
335 | ||
336 | local key keys | |
337 | for key in $(network raw list-settings); do | |
338 | keys="${keys} ${key}=" | |
339 | done | |
340 | COMPREPLY=( $(compgen -W "${keys}" -- "${cur}") ) | |
341 | } | |
342 | ||
93097eca JS |
343 | _network_vpn() { |
344 | local words=( $@ ) | |
345 | ||
98699861 | 346 | local commands="ipsec security-policies" |
93097eca JS |
347 | local cmd="$(_network_find_on_cmdline "${commands}")" |
348 | if [[ -z "${cmd}" ]]; then | |
349 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
350 | return 0 | |
351 | fi | |
352 | ||
353 | ||
354 | local args="${words[@]:1}" | |
355 | case "${cmd}" in | |
356 | ipsec) | |
357 | _network_vpn_ipsec ${args} | |
358 | ;; | |
98699861 JS |
359 | security-policies) |
360 | _network_vpn_security_policies ${args} | |
361 | ;; | |
93097eca JS |
362 | esac |
363 | } | |
364 | ||
365 | _network_vpn_ipsec() { | |
366 | local words=( $@ ) | |
367 | ||
368 | local commands="connection" | |
369 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
370 | if [[ -z "${cmd}" ]]; then | |
371 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
372 | return 0 | |
373 | fi | |
374 | ||
375 | ||
376 | local args="${words[@]:1}" | |
377 | case "${cmd}" in | |
378 | connection) | |
379 | _network_vpn_ipsec_connection ${args} | |
380 | ;; | |
381 | esac | |
382 | } | |
383 | ||
384 | _network_vpn_ipsec_connection() { | |
385 | local words=( $@ ) | |
386 | ||
387 | local commands="destroy new $(network raw list-ipsec-connections)" | |
388 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
389 | if [[ -z "${cmd}" ]]; then | |
390 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
391 | return 0 | |
392 | fi | |
393 | ||
394 | ||
395 | local args="${words[@]:1}" | |
396 | case "${cmd}" in | |
397 | destroy) | |
398 | : | |
399 | ;; | |
400 | new) | |
401 | : | |
402 | ;; | |
403 | *) | |
404 | if network raw ipsec-connection-exists ${cmd}; then | |
405 | _network_vpn_ipsec_connection_subcommands ${cmd} ${args} | |
406 | fi | |
407 | ;; | |
408 | esac | |
409 | } | |
410 | ||
411 | _network_vpn_ipsec_connection_subcommands() { | |
412 | local connection=${1} | |
413 | shift | |
414 | local words=( $@ ) | |
415 | ||
80a752f2 | 416 | local commands="authentication color description down inactivity-timeout local mode peer remote security-policy show up zone" |
93097eca JS |
417 | local cmd="$(_network_find_on_cmdline "${commands}")" |
418 | if [[ -z "${cmd}" ]]; then | |
419 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
420 | return 0 | |
421 | fi | |
422 | ||
423 | ||
424 | local args="${words[@]:1}" | |
425 | case "${cmd}" in | |
426 | authentication) | |
427 | _network_vpn_ipsec_connection_subcommands_authentication ${connection} ${args} | |
428 | ;; | |
5bcadc60 JS |
429 | color) |
430 | _network_color ${args} | |
431 | ;; | |
dc5dcfaf JS |
432 | description) |
433 | _network_description ${args} | |
434 | ;; | |
93097eca JS |
435 | local) |
436 | _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "local" ${args} | |
437 | ;; | |
438 | mode) | |
439 | _network_vpn_ipsec_connection_subcommands_mode ${args} | |
440 | ;; | |
441 | remote) | |
faf53925 | 442 | _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "remote" ${args} |
93097eca JS |
443 | ;; |
444 | security-policy) | |
445 | _network_vpn_ipsec_connection_subcommands_security_policy ${args} | |
446 | ;; | |
80a752f2 MT |
447 | zone) |
448 | _network_vpn_ipsec_connection_subcommands_zone "${connection}" ${args} | |
449 | ;; | |
450 | esac | |
93097eca JS |
451 | } |
452 | ||
453 | _network_vpn_ipsec_connection_subcommands_authentication() { | |
454 | local connection=${1} | |
455 | shift | |
456 | local words=( $@ ) | |
457 | ||
6fe4b2fd | 458 | local commands="mode pre-shared-key" |
93097eca JS |
459 | local cmd="$(_network_find_on_cmdline "${commands}")" |
460 | if [[ -z "${cmd}" ]]; then | |
461 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
462 | return 0 | |
463 | fi | |
464 | ||
465 | ||
466 | local args="${words[@]:1}" | |
467 | case "${cmd}" in | |
468 | mode) | |
469 | _network_vpn_ipsec_connection_subcommands_authentication_mode ${connection} ${args} | |
470 | ;; | |
471 | esac | |
472 | } | |
473 | ||
474 | _network_vpn_ipsec_connection_subcommands_local_remote() { | |
475 | local connection=${1} | |
476 | local type=${2} | |
477 | shift 2 | |
478 | local words=( $@ ) | |
479 | ||
480 | local commands="id prefix" | |
481 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
482 | if [[ -z "${cmd}" ]]; then | |
483 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
484 | return 0 | |
485 | fi | |
486 | ||
487 | ||
488 | local args="${words[@]:1}" | |
489 | case "${cmd}" in | |
490 | prefix) | |
491 | _network_vpn_ipsec_connection_subcommands_prefix "${connection}" "${type}" ${args} | |
492 | ;; | |
493 | esac | |
494 | } | |
495 | ||
496 | _network_vpn_ipsec_connection_subcommands_prefix() { | |
497 | : | |
498 | } | |
499 | ||
500 | _network_vpn_ipsec_connection_subcommands_authentication_mode() { | |
501 | local connection=${1} | |
502 | shift | |
503 | local words=( $@ ) | |
504 | ||
505 | local commands="PSK" | |
506 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
507 | if [[ -z "${cmd}" ]]; then | |
508 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
509 | return 0 | |
510 | fi | |
511 | } | |
512 | ||
513 | _network_vpn_ipsec_connection_subcommands_mode() { | |
514 | local words=( $@ ) | |
515 | ||
c856b4ea | 516 | local commands="transport tunnel" |
93097eca JS |
517 | local cmd="$(_network_find_on_cmdline "${commands}")" |
518 | if [[ -z "${cmd}" ]]; then | |
519 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
520 | return 0 | |
521 | fi | |
522 | } | |
523 | ||
524 | _network_vpn_ipsec_connection_subcommands_security_policy() { | |
525 | local words=( $@ ) | |
526 | ||
527 | local commands="$(network raw list-vpn-security-policies-all)" | |
528 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
529 | if [[ -z "${cmd}" ]]; then | |
530 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
531 | return 0 | |
532 | fi | |
533 | } | |
534 | ||
80a752f2 MT |
535 | _network_vpn_ipsec_connection_subcommands_zone() { |
536 | local connection="${1}" | |
537 | shift | |
538 | ||
539 | local words=( $@ ) | |
540 | ||
541 | # XXX TODO find zones that can be attached here | |
542 | } | |
543 | ||
98699861 JS |
544 | _network_vpn_security_policies() { |
545 | local words=( $@ ) | |
546 | ||
547 | local commands="destroy new $(network raw list-vpn-security-policies-all)" | |
548 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
549 | if [[ -z "${cmd}" ]]; then | |
550 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
551 | return 0 | |
552 | fi | |
553 | ||
554 | ||
555 | local args="${words[@]:1}" | |
556 | case "${cmd}" in | |
557 | destroy) | |
558 | : | |
559 | ;; | |
560 | new) | |
561 | : | |
562 | ;; | |
563 | *) | |
564 | if network raw vpn-security-policy-exists ${cmd}; then | |
565 | _network_vpn_security_policies_subcommands ${cmd} ${args} | |
566 | fi | |
567 | ;; | |
568 | esac | |
569 | } | |
570 | ||
571 | _network_vpn_security_policies_subcommands() { | |
572 | local policy=${1} | |
573 | shift | |
574 | local words=( $@ ) | |
575 | ||
0c1844c0 | 576 | local commands="ciphers compression group-types integrities key-exchange lifetime pfs pseudo-random-functions show" |
98699861 JS |
577 | local cmd="$(_network_find_on_cmdline "${commands}")" |
578 | if [[ -z "${cmd}" ]]; then | |
579 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
580 | return 0 | |
581 | fi | |
582 | ||
583 | ||
584 | local args="${words[@]:1}" | |
585 | case "${cmd}" in | |
57d62b96 MT |
586 | ciphers) |
587 | _network_vpn_security_policies_subcommands_ciphers ${policy} ${args} | |
98699861 JS |
588 | ;; |
589 | compression) | |
590 | _network_vpn_security_policies_subcommands_compression ${policy} ${args} | |
591 | ;; | |
a6d140eb MT |
592 | group-types) |
593 | _network_vpn_security_policies_subcommands_group_types ${policy} ${args} | |
98699861 | 594 | ;; |
0c1844c0 MT |
595 | integrities) |
596 | _network_vpn_security_policies_subcommands_integrities ${policy} ${args} | |
98699861 | 597 | ;; |
cd9cba7d | 598 | pseudo-random-functions) |
a6d140eb | 599 | _network_vpn_security_policies_subcommands_pseudo_random_functions ${policy} ${args} |
cd9cba7d | 600 | ;; |
98699861 JS |
601 | key-exchange) |
602 | _network_vpn_security_policies_subcommands_key_exchange ${policy} ${args} | |
603 | ;; | |
604 | pfs) | |
605 | _network_vpn_security_policies_subcommands_pfs ${policy} ${args} | |
606 | ;; | |
607 | esac | |
608 | } | |
609 | ||
57d62b96 | 610 | _network_vpn_security_policies_subcommands_ciphers() { |
98699861 JS |
611 | : |
612 | } | |
613 | ||
614 | _network_vpn_security_policies_subcommands_compression() { | |
615 | : | |
616 | } | |
617 | ||
a6d140eb | 618 | _network_vpn_security_policies_subcommands_group_types() { |
98699861 JS |
619 | : |
620 | } | |
621 | ||
0c1844c0 | 622 | _network_vpn_security_policies_subcommands_integrities() { |
98699861 JS |
623 | : |
624 | } | |
625 | ||
cd9cba7d MT |
626 | _network_vpn_security_policies_subcommands_pseudo_random_functions() { |
627 | : | |
628 | } | |
629 | ||
98699861 JS |
630 | _network_vpn_security_policies_subcommands_key_exchange() { |
631 | : | |
632 | } | |
633 | ||
634 | _network_vpn_security_policies_subcommands_pfs() { | |
635 | : | |
636 | } | |
637 | ||
1c6a4e30 | 638 | _network_zone() { |
bae37360 MT |
639 | local words=( $@ ) |
640 | ||
641 | local commands="new destroy $(network raw list-zones)" | |
642 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
643 | if [[ -z "${cmd}" ]]; then | |
644 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
645 | return 0 | |
646 | fi | |
647 | ||
1ca5fe9f | 648 | |
bae37360 MT |
649 | local args="${words[@]:1}" |
650 | case "${cmd}" in | |
651 | new) | |
1ca5fe9f | 652 | _network_zone_new ${args} |
bae37360 MT |
653 | ;; |
654 | destroy) | |
655 | _network_complete_zones | |
656 | ;; | |
657 | *) | |
658 | local zone="${cmd}" | |
659 | local args="${words[@]:1}" | |
660 | _network_zone_subcommand "${zone}" ${args} | |
661 | ;; | |
662 | esac | |
663 | } | |
664 | ||
1ca5fe9f JS |
665 | _network_zone_new() { |
666 | local words=( $@ ) | |
667 | local cmd=${words[@]:0:1} | |
668 | ||
669 | # Suggest useful zone names | |
670 | if [[ -z "${cmd}" ]]; then | |
671 | local commands="$(network raw list-next-free-zones)" | |
672 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
673 | ||
674 | # If a valid zone name was entered, we can move on | |
675 | elif network raw zone-name-is-valid ${cmd}; then | |
676 | local args="${words[@]:1}" | |
677 | _network_complete_hooks zone ${args} | |
678 | fi | |
679 | ||
680 | return 0 | |
681 | } | |
682 | ||
1c6a4e30 | 683 | _network_zone_subcommand() { |
bae37360 MT |
684 | local zone="${1}" |
685 | shift | |
686 | ||
687 | local words=( $@ ) | |
688 | ||
9d3ac4e4 | 689 | local commands="color config description disable down edit enable identify port rename status up" |
bae37360 MT |
690 | local cmd="$(_network_find_on_cmdline "${commands}")" |
691 | if [[ -z "${cmd}" ]]; then | |
692 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
693 | return 0 | |
694 | fi | |
b7fbb0cd | 695 | |
bae37360 MT |
696 | local args="${words[@]:1}" |
697 | case "${cmd}" in | |
698 | config) | |
2a6b2397 | 699 | _network_zone_subcommand_config "${zone}" ${args} |
bae37360 MT |
700 | ;; |
701 | port) | |
702 | _network_zone_subcommand_port "${zone}" ${args} | |
703 | ;; | |
b7fbb0cd JS |
704 | color) |
705 | _network_color ${args} | |
706 | ;; | |
9d3ac4e4 JS |
707 | description) |
708 | _network_description ${args} | |
709 | ;; | |
bae37360 MT |
710 | esac |
711 | } | |
712 | ||
2a6b2397 MT |
713 | _network_zone_subcommand_config() { |
714 | local zone="${1}" | |
715 | shift | |
716 | ||
717 | local words=( $@ ) | |
718 | ||
c8aafc4e | 719 | local commands="destroy list new $(network raw list-zone-config-hids ${zone})" |
cbf7473c | 720 | |
2a6b2397 MT |
721 | local cmd="$(_network_find_on_cmdline "${commands}")" |
722 | if [[ -z "${cmd}" ]]; then | |
723 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
724 | return 0 | |
725 | fi | |
726 | ||
cbf7473c | 727 | local args="${words[@]:1}" |
2a6b2397 MT |
728 | case "${cmd}" in |
729 | new) | |
730 | _network_complete_hooks "config" | |
731 | ;; | |
cbf7473c JS |
732 | destroy) |
733 | _network_zone_subcommand_config_destroy ${zone} ${args} | |
734 | ;; | |
cbf7473c | 735 | *) |
c8aafc4e | 736 | if network raw zone-config-id-is-valid ${zone} ${cmd} || network raw zone-config-hid-is-valid ${zone} ${cmd}; then |
cbf7473c JS |
737 | _network_zone_subcommand_config_subcommand ${zone} ${args} |
738 | fi | |
739 | ;; | |
2a6b2397 MT |
740 | esac |
741 | } | |
742 | ||
cbf7473c JS |
743 | _network_zone_subcommand_config_subcommand() { |
744 | local zone="${1}" | |
745 | shift | |
746 | ||
747 | local words=( $@ ) | |
748 | ||
749 | local commands="edit" | |
750 | ||
751 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
752 | if [[ -z "${cmd}" ]]; then | |
753 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
754 | return 0 | |
755 | fi | |
756 | } | |
757 | ||
758 | _network_zone_subcommand_config_destroy() { | |
759 | local zone="${1}" | |
760 | shift | |
761 | ||
762 | local words=( $@ ) | |
763 | ||
764 | local commands="$(network raw list-zone-config-ids ${zone})" | |
765 | ||
766 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
767 | if [[ -z "${cmd}" ]]; then | |
768 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
769 | return 0 | |
770 | fi | |
771 | } | |
772 | ||
1c6a4e30 | 773 | _network_zone_subcommand_port() { |
bae37360 MT |
774 | local zone="${1}" |
775 | shift | |
776 | ||
777 | local words=( $@ ) | |
778 | ||
779 | local commands="attach detach $(network raw list-ports-of-zone "${zone}")" | |
780 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
781 | if [[ -z "${cmd}" ]]; then | |
782 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
783 | return 0 | |
784 | fi | |
785 | ||
786 | case "${cmd}" in | |
787 | attach) | |
788 | COMPREPLY=( $(compgen -W "$(network raw list-free-ports "${zone}")" \ | |
789 | -- "${cur}") ) | |
790 | ;; | |
791 | detach) | |
792 | COMPREPLY=( $(compgen -W "$(network raw list-ports-of-zone "${zone}")" \ | |
793 | -- "${cur}") ) | |
794 | ;; | |
795 | *) | |
796 | local port="${cmd}" | |
797 | local args="${words[@]:1}" | |
798 | _network_zone_subcommand_port_subcommand "${zone}" "${port}" ${args} | |
799 | ;; | |
800 | esac | |
801 | } | |
802 | ||
1c6a4e30 | 803 | _network_zone_subcommand_port_subcommand() { |
bae37360 MT |
804 | local zone="${1}" |
805 | local port="${2}" | |
806 | shift 2 | |
807 | ||
808 | local words=( $@ ) | |
809 | ||
810 | local commands="edit" | |
811 | local cmd="$(_network_find_on_cmdline "${commands}")" | |
812 | if [[ -z "${cmd}" ]]; then | |
813 | COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) | |
814 | return 0 | |
815 | fi | |
816 | ||
817 | case "${cmd}" in | |
818 | edit) | |
819 | # TODO auto-complete the zone-port hook | |
820 | ;; | |
821 | esac | |
822 | } | |
823 | ||
1c6a4e30 | 824 | _network() { |
bae37360 MT |
825 | local cur prev words cword |
826 | _init_completion || return | |
827 | ||
828 | local cmd i | |
829 | for (( i=1; i < ${#words[@]} - 1; i++ )); do | |
830 | [[ "${words[i]}" = -* ]] && continue | |
831 | cmd="${words[i]}" && break | |
832 | done | |
833 | ||
834 | if [[ -z "${cmd}" ]]; then | |
835 | case "${cur}" in | |
836 | -*) | |
837 | COMPREPLY=( $(compgen -W "--debug" -- "${cur}") ) | |
838 | ;; | |
839 | *) | |
cc02f6be | 840 | COMPREPLY=( $(compgen -W "device dhcpv4 dhcpv6 dns-server \ |
93097eca | 841 | help hostname port reset route settings status vpn zone" \ |
cc02f6be | 842 | -- "${cur}") ) |
bae37360 MT |
843 | ;; |
844 | esac | |
845 | ||
846 | return 0 | |
847 | fi | |
848 | ||
849 | local args="${words[@]:i+1}" | |
850 | case "${cmd}" in | |
851 | device) | |
852 | _network_device ${args} | |
853 | ;; | |
cc02f6be MT |
854 | dhcpv[64]) |
855 | _network_dhcpd "${cmd/dhcpv/ipv}" ${args} | |
856 | ;; | |
8d1d2745 MT |
857 | dns-server) |
858 | _network_dns_server ${args} | |
859 | ;; | |
bae37360 MT |
860 | port) |
861 | _network_port ${args} | |
862 | ;; | |
8d1d2745 MT |
863 | route) |
864 | _network_route ${args} | |
865 | ;; | |
bae37360 MT |
866 | settings) |
867 | _network_settings ${args} | |
868 | ;; | |
869 | start|stop|status) | |
870 | # start, stop and status optionally take a zone | |
871 | _network_complete_zones | |
872 | ;; | |
93097eca JS |
873 | vpn) |
874 | _network_vpn ${args} | |
875 | ;; | |
bae37360 MT |
876 | zone) |
877 | _network_zone ${args} | |
878 | ;; | |
879 | esac | |
880 | } && complete -F _network network |