class Net::Openvpn::ClientConfig

Public Class Methods

new(hostname) click to toggle source
# File lib/net/openvpn/client_config.rb, line 7
def initialize(hostname)
  @hostname = hostname
  load if exists?
end

Public Instance Methods

exists?() click to toggle source
# File lib/net/openvpn/client_config.rb, line 23
def exists?
  File.exists? path
end
ip=(ip) click to toggle source
# File lib/net/openvpn/client_config.rb, line 27
def ip=(ip)
  @ip = ip
end
load() click to toggle source
# File lib/net/openvpn/client_config.rb, line 12
def load
  ccd = File.read(path)
  matches = ccd.match /ifconfig-push ([0-9\.]+) ([0-9\.]+)/
  @ip = matches[1]
  @network = matches[2]
end
network=(network) click to toggle source
# File lib/net/openvpn/client_config.rb, line 31
def network=(network)
  @network = network
end
path() click to toggle source
# File lib/net/openvpn/client_config.rb, line 19
def path
  Net::Openvpn.ccdpath @hostname
end
remove() click to toggle source
# File lib/net/openvpn/client_config.rb, line 40
def remove
  return true if !File.exist? path
  FileUtils.rm path
end
save() click to toggle source
# File lib/net/openvpn/client_config.rb, line 45
def save
  validate!
  
  File.open(path, "w") do |f|
    f.puts "ifconfig-push #{@ip} #{@network}"
  end
end
validate!() click to toggle source
# File lib/net/openvpn/client_config.rb, line 35
def validate!
  raise ArgumentError, "No IP set!" if @ip.nil? or @ip.empty?
  raise ArgumentError, "No network set!" if @network.nil? or @network.empty?
end