summaryrefslogtreecommitdiff
path: root/scriptlets/old_veepeen_toggler.sh
blob: ad48082d15583efbd28c32728f59195dd9b92b73 (plain)
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
#!/bin/bash

passentry="shigoto/vpn"
CONN_NAME="cscotun0"

if [ -n "$(ip address show | grep -iE "^[0-9]+: $CONN_NAME")" ]; then
    echo "ALREADY CONNECTED. DISCONNECTING..."
    /opt/cisco/anyconnect/bin/vpn disconnect
else
    CONN_HOST="$( pass $passentry | grep "url: "| sed -r "s|url: ||g" )"
    CONN_CREDS_USERNAME="$( pass $passentry | grep "username: "| sed -r "s|username: ||g" )"
    CONN_CREDS_PASSWORD="$( pass $passentry | head -n1 )"
    echo "CONNECTING... DON'T FORGET YOUR PHONE VERIFICATION"
    printf '%s\n%s' "$CONN_CREDS_USERNAME" "$CONN_CREDS_PASSWORD" | /opt/cisco/anyconnect/bin/vpn -s connect "$CONN_HOST"
fi

: '
Note the single quotes instead of double quotes - this is because double quotes tell Bash to interpret certain characters within strings, such as exclamation marks, as Bash history commands. Double quotes will make this command fail with an "event not found" error if the password contains an exclamation mark. Single-quoted strings pass exclamation marks along without interpreting them.

In case your client does not connect due to certificate validation error Certificate is from an untrusted source,
and you still want to connect then pass a y parameter in the above method so that the command to connect becomes:
printf "y\nUSERNAME\nPASSWORD\ny" | /opt/cisco/anyconnect/bin/vpn -s connect HOST.
Note that do this only in the case that you absolutely trust your connection;
otherwise there might be a middleman sitting in and snooping onto you.
'