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.
5 6 7 8 |
# File 'lib/net/openvpn/client_config.rb', line 5 def initialize(hostname) @hostname = hostname load if exists? end |
Instance Method Details
#exists? ⇒ Boolean
21 22 23 |
# File 'lib/net/openvpn/client_config.rb', line 21 def exists? File.exists? path end |
#ip=(ip) ⇒ Object
25 26 27 |
# File 'lib/net/openvpn/client_config.rb', line 25 def ip=(ip) @ip = ip end |
#load ⇒ Object
10 11 12 13 14 15 |
# File 'lib/net/openvpn/client_config.rb', line 10 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
29 30 31 |
# File 'lib/net/openvpn/client_config.rb', line 29 def network=(network) @network = network end |
#path ⇒ Object
17 18 19 |
# File 'lib/net/openvpn/client_config.rb', line 17 def path Net::Openvpn.ccdpath @hostname end |
#remove ⇒ Object
38 39 40 |
# File 'lib/net/openvpn/client_config.rb', line 38 def remove File.delete path end |
#save ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/net/openvpn/client_config.rb', line 42 def save validate! File.open(path, "w") do |f| f.puts "ifconfig-push #{@ip} #{@network}" end end |
#validate! ⇒ Object
33 34 35 36 |
# File 'lib/net/openvpn/client_config.rb', line 33 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 |