Skip to content

Instantly share code, notes, and snippets.

@shubhamgupta0122
Last active May 15, 2021 13:56
Show Gist options
  • Save shubhamgupta0122/96e61b1ee4c6bcd16a8d7e9b8c35b6a6 to your computer and use it in GitHub Desktop.
Save shubhamgupta0122/96e61b1ee4c6bcd16a8d7e9b8c35b6a6 to your computer and use it in GitHub Desktop.
#!/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