Class: VPNMaker::ConfigGenerator
- Inherits:
-
Object
- Object
- VPNMaker::ConfigGenerator
- Defined in:
- lib/vpnmaker/config_generator.rb
Instance Method Summary collapse
- #client(client) ⇒ Object
- #client_conf(client) ⇒ Object
- #default_template ⇒ Object
-
#initialize(*args) ⇒ ConfigGenerator
constructor
A new instance of ConfigGenerator.
- #server ⇒ Object
- #server_conf ⇒ Object
Constructor Details
#initialize(*args) ⇒ ConfigGenerator
Returns a new instance of ConfigGenerator.
3 4 5 6 |
# File 'lib/vpnmaker/config_generator.rb', line 3 def initialize(*args) @mgr = args.shift.first args.empty? ? (@runtime_cfg = default_template) : (@runtime_cfg = args.shift) end |
Instance Method Details
#client(client) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/vpnmaker/config_generator.rb', line 53 def client(client) haml_vars = client_conf(client).dup template = File.read(@mgr.tracker.path + \ "/" + @mgr.config[:site][:template_dir] + \ "/" + 'client.haml') Haml::Engine.new(template).render(Object.new, haml_vars) end |
#client_conf(client) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vpnmaker/config_generator.rb', line 18 def client_conf(client) fname = client[:user] + '-' + ((client[:revoked].max || - 1) + 1).to_s separator = '-----BEGIN CERTIFICATE-----' cert = File.read(@dirname + "/#{fname}.crt").split(separator).last.insert(0, separator) { :gen_host => Socket.gethostname, :server => @mgr.config[:server], :client => @mgr.config[:client] }.merge(client).merge(:key => File.read(@dirname + "/#{fname}.key" ), :cert => cert).merge(@runtime_cfg) end |
#default_template ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/vpnmaker/config_generator.rb', line 8 def default_template @dirname = (@mgr.tracker.path + "/" + @mgr.config[:site][:data_dir]) { :type => :default, :dh => File.read(@dirname + "/dh.pem"), :ca => File.read(@dirname + "/ca.crt"), :ta => File.read(@dirname + "/ta.key") } end |
#server ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vpnmaker/config_generator.rb', line 42 def server haml_vars = server_conf.dup haml_vars[:base_ip] = ((a = IPAddr.new haml_vars[:base_ip]); {:net => a.to_s, :mask => a.subnet_mask.to_s}) haml_vars[:bridgednets] ? (haml_vars[:bridgednets] = haml_vars[:bridgednets].map {|net| a = (IPAddr.new net); {:net => a.to_s, :mask => a.subnet_mask.to_s}}) : (haml_vars[:bridgednets] = Hash.new) haml_vars[:subnets] ? (haml_vars[:subnets] = haml_vars[:subnets].map {|net| a = (IPAddr.new net); {:net => a.to_s, :mask => a.subnet_mask.to_s}}) : (haml_vars[:subnets] = Hash.new) template = File.read(@mgr.tracker.path + \ "/" + @mgr.config[:site][:template_dir] + \ "/" + 'server.haml') Haml::Engine.new(template).render(Object.new, haml_vars) end |
#server_conf ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vpnmaker/config_generator.rb', line 31 def server_conf separator = '-----BEGIN CERTIFICATE-----' cert = File.read(@dirname + "/server.crt").split(separator).last.insert(0, separator) { :gen_host => Socket.gethostname, :crl_path => @mgr.tracker.path }.merge(@mgr.config[:server]).merge(@runtime_cfg).merge(:key => File.read(@dirname + "/server.key"), :cert => cert, :crl => File.read(@dirname + "/crl.pem")) end |