Class: VPNMaker::Manager
- Inherits:
-
Object
- Object
- VPNMaker::Manager
- Defined in:
- lib/vpnmaker/manager.rb
Instance Attribute Summary collapse
-
#tracker ⇒ Object
readonly
Returns the value of attribute tracker.
Class Method Summary collapse
Instance Method Summary collapse
- #build_ca ⇒ Object
- #build_server ⇒ Object
- #config ⇒ Object
- #config_generator(*args) ⇒ Object
- #create_user(user, name, email, pass = nil) ⇒ Object
- #delete_user(user) ⇒ Object
-
#initialize(dir) ⇒ Manager
constructor
A new instance of Manager.
- #regenerate_user(user, pass = nil) ⇒ Object
- #revoke_all(user) ⇒ Object
- #user(user) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(dir) ⇒ Manager
Returns a new instance of Manager.
7 8 9 10 |
# File 'lib/vpnmaker/manager.rb', line 7 def initialize(dir) name = self.class.vpn_name(File.(dir)) @tracker = KeyTracker.new(name, File.(dir)) end |
Instance Attribute Details
#tracker ⇒ Object (readonly)
Returns the value of attribute tracker.
3 4 5 |
# File 'lib/vpnmaker/manager.rb', line 3 def tracker @tracker end |
Class Method Details
.vpn_name(dir) ⇒ Object
5 |
# File 'lib/vpnmaker/manager.rb', line 5 def self.vpn_name(dir); dir =~ /(^|\/)([^\/\.]+)\.vpn/ ? $2 : nil; end |
Instance Method Details
#build_ca ⇒ Object
14 |
# File 'lib/vpnmaker/manager.rb', line 14 def build_ca; @tracker.builder.build_ca; end |
#build_server ⇒ Object
15 16 17 18 19 |
# File 'lib/vpnmaker/manager.rb', line 15 def build_server @tracker.builder.build_server_key @tracker.builder.build_ta_key @tracker.builder.build_dh_key end |
#config ⇒ Object
12 |
# File 'lib/vpnmaker/manager.rb', line 12 def config; @tracker.config; end |
#config_generator(*args) ⇒ Object
53 |
# File 'lib/vpnmaker/manager.rb', line 53 def config_generator(*args); ConfigGenerator.new([self] + args); end |
#create_user(user, name, email, pass = nil) ⇒ Object
21 22 23 |
# File 'lib/vpnmaker/manager.rb', line 21 def create_user(user, name, email, pass=nil) @tracker.builder.build_key(user, name, email, pass, :add_user) end |
#delete_user(user) ⇒ Object
41 42 43 |
# File 'lib/vpnmaker/manager.rb', line 41 def delete_user(user) revoke_all(user) end |
#regenerate_user(user, pass = nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/vpnmaker/manager.rb', line 35 def regenerate_user(user, pass=nil) revoke_all(user) u = @tracker.user(user) @tracker.builder.build_key(user, u[:name], u[:email], pass, :add_user_key) end |
#revoke_all(user) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/vpnmaker/manager.rb', line 25 def revoke_all(user) cur = @tracker.active_key_version(user) while cur >= 0 unless @tracker.revoked?(user, cur) @tracker.builder.revoke_key(user, cur) end cur -= 1 end end |
#user(user) ⇒ Object
49 50 51 |
# File 'lib/vpnmaker/manager.rb', line 49 def user(user) @tracker.user(user) end |
#users ⇒ Object
45 46 47 |
# File 'lib/vpnmaker/manager.rb', line 45 def users @tracker.users.keys end |