Class: VPNMaker::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/vpnmaker/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Manager


7
8
9
10
# File 'lib/vpnmaker/manager.rb', line 7

def initialize(dir)
  name = self.class.vpn_name(File.expand_path(dir))
  @tracker = KeyTracker.new(name, File.expand_path(dir))
end

Instance Attribute Details

#trackerObject (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_caObject


14
# File 'lib/vpnmaker/manager.rb', line 14

def build_ca; @tracker.builder.build_ca; end

#build_serverObject


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

#configObject


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

#usersObject


45
46
47
# File 'lib/vpnmaker/manager.rb', line 45

def users
  @tracker.users.keys
end