~hokiegeek/bin

ref: 939801a857c79f0ef571ea7be898cd2a8cefd950 bin/bwvpn -rwxr-xr-x 944 bytes
939801a8HokieGeek [bwvpn] fixes several bugs and usability issues 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
32
33
#!/bin/sh
cmd=$1
item=$2
vpncfg=$3

if [[ "$cmd" == "stop" ]]; then
    openvpn3 sessions-list | awk 'BEGIN{ FS=":" } $1 ~ /Path/ { p=$2 } $1 ~ /Config name/ && $2 = "'${vpncfg}'" { print p }' | while read p; do
        echo "[$p]"
        openvpn3 session-manage --disconnect --path $p
    done
elif [[ "$cmd" == "start" ]]; then
    bwsession=$(bw unlock | awk -F= '$1 ~ /export BW_SESSION/ { gsub(/"/, "", $2); print $2 }')
    [ -z "${bwsession}" ] && exit 1
    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 "USAGE: bwvpn [start|stop] BWITEMNAME OVPNCONFIG"
    exit 1
fi