Last active
April 6, 2021 08:06
-
-
Save kdrdmr/4e8d150052ca60daee26f715bc407e54 to your computer and use it in GitHub Desktop.
vpn-otp-tunnelblick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import hmac, base64, struct, hashlib, time, subprocess | |
# change this parameters | |
vpn_entry_name = 'aws-vpn' | |
otp_secret = 'your OTP secret' | |
# change this parameters | |
h = hmac.new(base64.b32decode(otp_secret, True), struct.pack(">Q", int(time.time())//30), hashlib.sha1).digest() | |
o = ord(h[19]) & 15 | |
code = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000 | |
sub_proc = subprocess.Popen('/usr/bin/osascript', shell=False, | |
stdout=subprocess.PIPE, stderr = subprocess.PIPE, | |
stdin=subprocess.PIPE) | |
#cmd = 'tell app "Tunnelblick" to connect "%s"\n' % name | |
cmd = """tell application "Tunnelblick" | |
connect "%s" | |
tell application "Tunnelblick" to activate | |
tell application "System Events" | |
tell process "Tunnelblick" to set value of text field 2 of window "Tunnelblick: Login Required" to "%s" | |
tell process "Tunnelblick" to click button "OK" of window "Tunnelblick: Login Required" | |
end tell | |
end tell""" % (vpn_entry_name, code) | |
sub_proc.communicate(cmd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import hmac, base64, struct, hashlib, time, subprocess | |
# change this parameters | |
vpn_entry_name = 'google-cloud-vpn' | |
otp_secret = 'your OTP secret' | |
ldap_login = 'your LDAP user.name' | |
ldap_password = 'your LDAP password' | |
# change this parameters | |
h = hmac.new(base64.b32decode(otp_secret, True), | |
struct.pack(">Q", int(time.time()) // 30), | |
hashlib.sha1).digest() | |
o = ord(h[19]) & 15 | |
code = (struct.unpack(">I", h[o:o + 4])[0] & 0x7fffffff) % 1000000 | |
sub_proc = subprocess.Popen('/usr/bin/osascript', | |
shell=False, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
stdin=subprocess.PIPE) | |
cmd = """tell application "Tunnelblick" | |
connect "%s" | |
tell application "Tunnelblick" to activate | |
tell application "System Events" | |
tell process "Tunnelblick" to set value of text field 1 of window "Tunnelblick: Login Required" to "%s" | |
tell process "Tunnelblick" to set value of text field 2 of window "Tunnelblick: Login Required" to "%s%s" | |
tell process "Tunnelblick" to click button "OK" of window "Tunnelblick: Login Required" | |
end tell | |
end tell""" % (vpn_entry_name, ldap_login, ldap_password, code) | |
sub_proc.communicate(cmd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
vpn_entry_name="all" # all for all active connection, elsewhere write connection name | |
osascript -e "tell application \"Tunnelblick\"" -e "disconnect \"$vpn_entry_name\"" -e "end tell" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment