module Kytoon module Vpn class VpnOpenVpn < VpnConnection def initialize(group, client = nil) super(group, client) end def connect create_certs @up_script=get_cfile('up.bash') File.open(@up_script, 'w') do |f| f << < /etc/resolv.conf echo 'nameserver #{@group.vpn_network.chomp("0")+"1"}' >> /etc/resolv.conf grep ^nameserver /etc/resolv.conf.bak >> /etc/resolv.conf EOF_UP f.chmod(0700) end @down_script=get_cfile('down.bash') File.open(@down_script, 'w') do |f| f << < /dev/null") end def clean delete_certs end private def poll_vpn_interface interface_name=@group.vpn_device+"0" 1.upto(30) do |i| break if system("/sbin/ifconfig #{interface_name} > /dev/null 2>&1") if i == 30 then disconnect raise "Failed to connect to VPN." end sleep 0.5 end end end end end