Skip to content

Enable manual mode for entering password #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ sudo ln -s ~/.lazy-connect/lazy-connect /usr/local/bin/lazy-connect
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
and connect to it automatically.

-i - Initialize lazy-connect.
-n - Connect to VPN by autofilling password
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list
Stores the secret and VPN list to ~/.config/lazy-connect/
-u - Update lazy-connect
-r - refresh vpn list in ~/.config/lazy-connect
-h - Show this help
```

## Configuration

* The connection to VPN could be made with filling password automatically. To enable autofill set `LAZY_CONNECT_AUTOFILL` variable to true.

```
export LAZY_CONNECT_AUTOFILL="true"
```
When disabled, the password is copied to clipboard, and you can use it manually when it prompts for password.

### YubiKey Support

#### Prerequisite
Expand Down
78 changes: 47 additions & 31 deletions lazy-connect
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ USAGE:
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
and connect to it automatically.

-n - Connect to VPN by autofilling password
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list
-r - Refresh vpn list in ~/.config/lazy-connect
-h - Show this help
EOF
}

function _lazy_connect_get_totp() {
secret_key=$1
local secret_key=$1
case $TOTP_MODE in
oathtool)
password=$(oathtool --totp --base32 $secret_key)
Expand All @@ -93,7 +94,7 @@ function _lazy_connect_get_totp() {
}

function _lazy_connect() {
vpn_name=$1
local vpn_name=$1
_lazy_connect_get_totp $2

if [ -z "$password" ]; then
Expand All @@ -109,17 +110,26 @@ function _lazy_connect() {
esac
fi

if [ "$3" = "true" ]; then
local _lazy_connect_auto_fill_pwd="true"
else
echo -n "$password" | pbcopy
fi

osascript <<EOF
on connectVpn(vpnName, password)
on connectVpn(vpnName, password, autofill)
tell application "System Events"
tell process "SystemUIServer"
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
tell vpnMenu to click
try
click menu item vpnName of menu 1 of vpnMenu
delay 2
keystroke password
keystroke return
delay 1
if (autofill is equal to "true")
keystroke $password
keystroke return
end if
return
on error errorStr
if errorStr does not contain "Can’t get menu item" and errorStr does not contain vpnName then
display dialog errorStr
Expand All @@ -129,39 +139,45 @@ function _lazy_connect() {
end tell
end connectVpn

connectVpn("$vpn_name", "$password")
connectVpn("$vpn_name", "$password", "$_lazy_connect_auto_fill_pwd")
EOF
}

function lazy-connect() {
local OPTIND
mkdir -p $_lazy_connect_config_dir

while getopts "iruh" opt; do
while getopts "irhn" opt; do
case $opt in
h)
_lazy_connect_usage
return 0
;;
i)
_lazy_connect_init
return 0
;;
r)
echo "Refreshing VPN list..."
_lazy_connect_vpn_refresh
return 0
;;
\?)
echo "Invalid Option: -$OPTARG."
_lazy_connect_usage
return 1
;;
:)
echo "Option -$OPTARG requires an argument."
_lazy_connect_usage
return 1
;;
h)
_lazy_connect_usage
return 0
;;
i)
_lazy_connect_init
return 0
;;
r)
echo "Refreshing VPN list..."
_lazy_connect_vpn_refresh
return 0
;;
n)
local _secret=$(security find-generic-password -a lazy-connect -w 2>/dev/null | tr -d '\n')
local _vpn_name=$(cat $_lazy_connect_config_dir/vpns | fzf --height=10 --ansi --reverse --select-1)
_lazy_connect "$_vpn_name" "$_secret" true
return 0
;;
\?)
echo "Invalid Option: -$OPTARG."
_lazy_connect_usage
return 1
;;
:)
echo "Option -$OPTARG requires an argument."
_lazy_connect_usage
return 1
;;
esac
done

Expand Down