Class: DandelionS1
- Inherits:
-
RackRscript
- Object
- RackRscript
- DandelionS1
- Defined in:
- lib/dandelion_s1.rb
Instance Method Summary collapse
- #call(e) ⇒ Object
-
#initialize(opts = {}) ⇒ DandelionS1
constructor
A new instance of DandelionS1.
Constructor Details
#initialize(opts = {}) ⇒ DandelionS1
Returns a new instance of DandelionS1.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dandelion_s1.rb', line 12 def initialize(opts={}) h = {root: 'www', static: [], passwords: {'user' => 'us3r'}}.merge(opts) @passwords = h[:passwords] access_list = h[:access] @app_root = Dir.pwd #@access_list = {'/do/r/hello3' => 'user'} if access_list then h2 = SimpleConfig.new(access_list).to_h conf_access = h2[:body] || h2 @access_list = conf_access.inject({}) \ {|r,x| k,v = x; r.merge(k.to_s => v.split)} end h3 = %i(log pkg_src rsc_host rsc_package_src root static debug)\ .inject({}) {|r,x| r.merge(x => h[x])} super(h3) end |
Instance Method Details
#call(e) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dandelion_s1.rb', line 38 def call(e) request = e['REQUEST_PATH'] return super(e) if request == '/login' r = @access_list.detect {|k,v| request =~ Regexp.new(k)} if @access_list private_user = r ? r.last : nil req = Rack::Request.new(e) user = req.session[:username] return jumpto '/login' unless user if private_user.nil? then super(e) elsif (private_user.is_a? String and private_user == user) \ or (private_user.is_a? Array and private_user.any? {|x| x == user}) super(e) else jumpto '/unauthorised' end end |