class VpnService
Public Class Methods
connect(address)
click to toggle source
# File lib/vpn_service.rb, line 2 def self.connect(address) system( %x{ osascript <<APPLESCRIPT tell application "Tunnelblick" connect "#{address}" get state of first configuration where name = "#{address}" repeat until result = "CONNECTED" delay 1 get state of first configuration where name = "#{address}" end repeat end tell APPLESCRIPT} ) return "Connected to #{address}" end
connected?()
click to toggle source
# File lib/vpn_service.rb, line 40 def self.connected? output = ` osascript <<APPLESCRIPT tell application "Tunnelblick" get state of first configuration return result end tell APPLESCRIPT ` return output == "CONNECTED\n" end
disconnect(address)
click to toggle source
# File lib/vpn_service.rb, line 20 def self.disconnect(address) raise 'No connection exists' unless connected? system( %x{ osascript <<APPLESCRIPT tell application "Tunnelblick" disconnect "#{address}" end tell APPLESCRIPT} ) return 'Disconnected' end
switch(address)
click to toggle source
# File lib/vpn_service.rb, line 33 def self.switch(address) raise 'No connection exists' unless connected? self.disconnect self.connect(address) return "Connected to #{address}" end