Class: Net::Openvpn::ClientConfig
- Inherits:
-
Object
- Object
- Net::Openvpn::ClientConfig
- Defined in:
- lib/net/openvpn/client_config.rb
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(hostname) ⇒ ClientConfig
constructor
A new instance of ClientConfig.
- #ip=(ip) ⇒ Object
- #load ⇒ Object
- #network=(network) ⇒ Object
- #path ⇒ Object
- #remove ⇒ Object
- #save ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(hostname) ⇒ ClientConfig
Returns a new instance of ClientConfig.
7 8 9 10 |
# File 'lib/net/openvpn/client_config.rb', line 7 def initialize(hostname) @hostname = hostname load if exists? end |
Instance Method Details
#exists? ⇒ Boolean
23 24 25 |
# File 'lib/net/openvpn/client_config.rb', line 23 def exists? File.exists? path end |
#ip=(ip) ⇒ Object
27 28 29 |
# File 'lib/net/openvpn/client_config.rb', line 27 def ip=(ip) @ip = ip end |
#load ⇒ Object
12 13 14 15 16 17 |
# 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) ⇒ Object
31 32 33 |
# File 'lib/net/openvpn/client_config.rb', line 31 def network=(network) @network = network end |
#path ⇒ Object
19 20 21 |
# File 'lib/net/openvpn/client_config.rb', line 19 def path Net::Openvpn.ccdpath @hostname end |
#remove ⇒ Object
40 41 42 43 |
# File 'lib/net/openvpn/client_config.rb', line 40 def remove return true if !File.exist? path FileUtils.rm path end |
#save ⇒ Object
45 46 47 48 49 50 51 |
# 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! ⇒ Object
35 36 37 38 |
# 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 |