Last active
May 15, 2021 13:56
-
-
Save shubhamgupta0122/96e61b1ee4c6bcd16a8d7e9b8c35b6a6 to your computer and use it in GitHub Desktop.
This file contains 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 ruby | |
require 'yaml' | |
require 'rotp' | |
status_only = (ARGV[0].to_s == '--status-only') | |
conf = YAML.load(File.read('./conf.yml')) | |
totp = ROTP::TOTP.new(conf['totp'], interval: 60).now | |
vpn_conf_name = conf['conf_name'] | |
username = conf['user'] | |
password = conf['pass'] + totp.to_s | |
applescript = File.read('./tunnelblick_toggle.applescript'); | |
applescript.gsub!('%NAME%', vpn_conf_name); | |
applescript.gsub!('%USER%', username); | |
applescript.gsub!('%PASS%', password); | |
applescript.gsub!('%TOGGLE%', (!status_only).to_s) | |
output = `osascript -e '#{applescript}'` | |
if output.start_with?("CONNECT") | |
puts "YES" | |
else | |
puts "NO" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment