Module: HotSpotLogin

Defined in:
lib/hotspotlogin/app.rb,
lib/hotspotlogin/config.rb,
lib/hotspotlogin/constants.rb,
lib/hotspotlogin/app/helpers.rb

Defined Under Namespace

Modules: Result Classes: App

Constant Summary collapse

VERSION =
'1.5.0'
DEFAULT_CONFIG =
{
  'listen-address'        => '0.0.0.0',
  'port'                  => 4990,
  'log-http'              => false,
  'userpassword'          => true, # like $userpassword in hotpotlgin.(cgi|php)
  'interval'              => 300,
  'remember-credentials'  => true
}
ROOTDIR =
File.join(File.dirname(File.expand_path __FILE__), '../..')
@@config =
DEFAULT_CONFIG

Class Method Summary collapse

Class Method Details

.configObject



10
# File 'lib/hotspotlogin/config.rb', line 10

def self.config; @@config; end

.config!Object

Parses command line and configuration file



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/hotspotlogin/config.rb', line 18

def self.config!
  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"

    # Configuration file, if specified.

    opts.on('--conf FILE', 'configuration file') do |filename|
      @@config['conf'] = filename
      @@config.merge! YAML.load(File.read filename) 
    end

    # Command line switches override configuration file.
    
    opts.on('--interval SECONDS', 'autorefresh accounting/session data every SECONDS seconds') do |seconds|
      @@config['interval'] = seconds.to_i
    end

    opts.on('--custom-headline TEXT', 'display <h1>TEXT</h1> on top of the login page, tipically your Organization name') do |text|
      @@config['custom-headline'] == text
    end

    opts.on('--custom-text FILE', 'display HTML fragment FILE before the user stats table/login form') do |file|
      @@config['custom-text'] == file
    end

    opts.on('--custom-footer FILE', 'display HTML fragment FILE after the user stats table/login form') do |file|
      @@config['custom-footer'] == file
    end

    opts.on('--logo FILE', 'logo (of your Organization etc.)') do |file|
      @@config['logo'] = file
    end

    opts.on('--logo-link URL', 'add an hyperlink to the logo') do |url|
      @@config['logo-link'] = url
    end

    opts.on('--my-url URL', 'display a "My Account" link, -USER- will be dinamically replaced by the actual username, e.g. https://accounts.myorg.com/?id=-USER-') do |url|
      @@config['my-url'] = url
    end

    opts.on('--signup-url URL', 'display an external link where end-user may create a new account') do |url|
      @@config['signup-url'] = url
    end

    opts.on('--password-recovery-url URL', 'display an external link where end-user may recover/reset her password') do |url|
      @@config['password-recovery-url'] = url
    end

    opts.on('--[no-]remember-credentials', 'allow users to save username/password in cookies') do |rcred|
      @@config['remember-credentials'] = rcred
    end

    opts.on('--favicon FILE', 'well, favicon ;)') do |file|
      @@config['favicon'] = file
    end
   
    opts.on('--[no-]daemon', 'become a daemon') do |daemonize|
      @@config['daemon'] = daemonize
    end

    opts.on('--log FILE', 'log file (overwrite existing)') do |filename|
      @@config['log'] = filename
    end

    opts.on('--pid FILE', 'pid file') do |filename|
      @@config['pid'] = filename
    end

    opts.on('--uamsecret PASS', 'as in chilli.conf(5)') do |uamsecret|
      @@config['uamsecret'] = uamsecret
    end

    opts.on('--[no-]userpassword', 'like setting $userpassword=1 in hotspotlogin.cgi (use PAP instead of CHAP)') do |userpassword|
      @@config['userpassword'] = userpassword
    end

    opts.on('--port PORT', 'TCP port to listen on') do |port|
      @@config['port'] = port.to_i
    end

    opts.on('--listen-address ADDR', 'IP address or hostname to listen on') do |addr|
      @@config['listen-address'] = addr
    end

    opts.on('--[no-]log-http', 'output an Apache-like log') do |log|
      @@config['log-http'] = log
    end

  end.parse!

  self.config_sinatra!

  return @@config
end

.config=(h) ⇒ Object



12
13
14
15
# File 'lib/hotspotlogin/config.rb', line 12

def self.config=(h) 
  @@config = h
  config_sinatra!
end