~hokiegeek/bin

ref: 83cf299aef2ad8a4fff2b6da8127b2f9144aa39e bin/bwvpn -rwxr-xr-x 887 bytes
83cf299aHokieGeek so much goodness 5 months ago
                                                                                
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
#!/bin/sh
vpncfg=$2

if [[ "$1" == "stop" ]]; then
    openvpn3 sessions-list | awk 'BEGIN{ FS=":" } $1 ~ /Path/ { p=$2 } $1 ~ /Config name/ && $2 = "'${vpncfg}'" { print p }' | while read p; do
        echo -n "$p\n\t"
        openvpn3 session-manage --disconnect --path $p
    done
elif [[ "$1" == "start" ]]; then
    bwsession=$(bw unlock | awk -F= '$1 ~ /export BW_SESSION/ { gsub(/"/, "", $2); print $2 }')
    item=vpn.sonatype.dev
    expect <<-EOF
    spawn openvpn3 session-start --config ${vpncfg}

    set timeout 60

    expect "Auth User name:"
    send -- "$(bw --session ${bwsession} get username ${item})\r"

    expect "Auth Password:"
    send -- "$(bw --session ${bwsession} get password ${item})\r"

    expect "Enter Authenticator Code:"
    send -- "$(bw --session ${bwsession} get totp ${item})\r"

    expect eof

EOF
else
    echo "just start or stop, dude"
fi