dandelion_s1 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7e9ff3cb5efdc68ee7385d5c1b8d975202d96526
4
- data.tar.gz: 52f232490fdfdf27eeb3ddb9a875545a9710971e
2
+ SHA256:
3
+ metadata.gz: 1c59a8096fccc922ca6c3100e5e393282995c5a482d173330ddcb85f8e3490d7
4
+ data.tar.gz: 3e47b63dc991f237c69e3c6c9a90a84fa6b1d4b767569a2304ac1b33751f09c5
5
5
  SHA512:
6
- metadata.gz: f54b7004459dfd27f7c62ca188bfea688a1035c9707cc3f5c6b45a7bfcd71e1c8acfd5c31f6f1aeadbd2f0b01a32ade832fcb9db2a434b9479ae89ccad9d368d
7
- data.tar.gz: 7dd3280337401fe36b4d6834508b622b801cbfaef7749e582f3790f128d6f216f332a44adc26cf99e6252d2db331c20173a0ba851764916083cc35d631ebad7b
6
+ metadata.gz: 439b570707d88cd65f9a2e7569c68146c165bc32277196d451849ec28648e7e675cb6f96db693f8c6bdf0bd53073c525a6d4bfecae8eb6def45243e27ace596d
7
+ data.tar.gz: c31007f28494b3019556eb21c0b9a42d4e04ce6327e7557e9c629878e0e40096df80610dc984b3e07fadc7271c771fb521a90dc1471db64afb8214068968d55b
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dandelion_s1.rb CHANGED
@@ -2,94 +2,152 @@
2
2
 
3
3
  # file: dandelion_s1.rb
4
4
 
5
+ require 'martile'
5
6
  require 'rack-rscript'
6
7
  require 'simple-config'
7
8
 
8
9
 
9
10
  class DandelionS1 < RackRscript
10
11
 
11
- def initialize(h={})
12
+ def initialize(opts={})
12
13
 
13
- raw_opts = {root: 'www', access: {}, static: [], log: nil}.merge h
14
- @app_root = Dir.pwd
14
+ h = {root: 'www', static: [], passwords: {'user' => 'us3r'}}.merge(opts)
15
15
 
16
- @static = raw_opts[:static]
17
- @root = raw_opts[:root]
16
+ @passwords = h[:passwords]
17
+ access_list = h[:access]
18
+ @app_root = Dir.pwd
18
19
 
19
20
  #@access_list = {'/do/r/hello3' => 'user'}
20
- access_list = raw_opts[:access]
21
-
22
- h2 = SimpleConfig.new(access_list).to_h
23
- conf_access = h2[:body] || h2
24
- @access_list = conf_access.inject({}) \
25
- {|r,x| k,v = x; r.merge(k.to_s => v.split)}
26
-
27
- super(log: h[:log], pkg_src: h[:pkg_src], rsc_host: h[:rsc_host],
28
- rsc_package_src: h[:rsc_package_src])
21
+
22
+ if access_list then
23
+
24
+ h2 = SimpleConfig.new(access_list).to_h
25
+ conf_access = h2[:body] || h2
26
+ @access_list = conf_access.inject({}) \
27
+ {|r,x| k,v = x; r.merge(k.to_s => v.split)}
28
+
29
+ end
30
+
31
+ h3 = %i(log pkg_src rsc_host rsc root static debug)\
32
+ .inject({}) {|r,x| r.merge(x => h[x])}
33
+
34
+ super(**h3)
35
+ @log.debug '@access_list: ' + @access_list.inspect if @log
36
+ @log.debug 'end of initialize' if @log
37
+
29
38
  end
30
39
 
31
40
  def call(e)
32
41
 
33
42
  request = e['REQUEST_PATH']
34
- r = @access_list.detect {|k,v| request =~ Regexp.new(k)}
43
+ @log.debug 'request: ' + request.inspect if @log
44
+
45
+ return super(e) if request == '/login'
46
+ r = @access_list.detect {|k,v| request =~ Regexp.new(k)} if @access_list
35
47
  private_user = r ? r.last : nil
36
-
37
- if private_user.nil? then
38
- super(e)
39
- elsif private_user.is_a? String and private_user == e['REMOTE_USER']
48
+
49
+ req = Rack::Request.new(e)
50
+ user = req.session[:username]
51
+
52
+ @log.debug 'user: ' + user.inspect if @log
53
+ #@log.debug '@e: ' + e.inspect if @log
54
+ return jumpto '/login2?referer=' + e['PATH_INFO'] unless user
55
+
56
+ if private_user.nil? then
40
57
  super(e)
41
- elsif private_user.is_a? Array and
42
- private_user.any? {|x| x == e['REMOTE_USER']}
58
+ elsif (private_user.is_a? String and private_user == user) \
59
+ or (private_user.is_a? Array and private_user.any? {|x| x == user})
43
60
  super(e)
44
61
  else
45
- request = '/unauthorised/'
46
- content, content_type, status_code = run_route(request)
47
- content_type ||= 'text/html'
48
- [status_code=401, {"Content-Type" => content_type}, [content]]
62
+ jumpto '/unauthorised'
49
63
  end
50
64
 
51
65
  end
52
66
 
67
+ protected
68
+
53
69
  def default_routes(env, params)
54
70
 
55
- super(env, params)
71
+ log = @log
72
+
73
+ get '/login2/*' do
74
+ params[:splat].inspect
75
+ redirect '/login' + params[:splat].first
76
+ end
56
77
 
57
- get /^(\/(?:#{@static.join('|')}).*)/ do |path|
78
+ get '/login/*' do
79
+ url = params[:splat].any? ? params[:splat][0][/(?<=referer=).*/] : '/'
80
+ login_form(referer: url)
81
+ end
58
82
 
59
- filepath = File.join(@app_root, @root, path)
83
+ post '/login' do
60
84
 
61
- if @log then
62
- @log.info 'DandelionS1/default_routes: ' +
63
- "root: %s path: %s" % [@root, path]
64
- end
85
+ h = @req.params
86
+
87
+ if @passwords[h['username']] == h['password'] then
88
+
89
+ @req.session[:username] = h['username']
90
+ #'you are now logged in as ' + h['username']
91
+ redirect h['referer']
65
92
 
66
- if path.length < 1 or path[-1] == '/' then
67
- path += 'index.html'
68
- File.read filepath
69
- elsif File.directory? filepath then
70
- Redirect.new (path + '/')
71
- elsif File.exists? filepath then
72
- h = {xml: 'application/xml', html: 'text/html', png: 'image/png',
73
- jpg: 'image/jpeg', txt: 'text/plain', css: 'text/css',
74
- xsl: 'application/xml', svg: 'image/svg+xml'}
75
- content_type = h[filepath[/\w+$/].to_sym]
76
- [File.read(filepath), content_type || 'text/plain']
77
93
  else
78
- 'oops, file ' + filepath + ' not found'
94
+
95
+ login_form('Invalid username or password, try again.',401)
96
+
79
97
  end
80
98
 
99
+
100
+ end
101
+
102
+ get '/logout' do
103
+
104
+ @req.session.clear
105
+ 'you are now logged out'
106
+
107
+ end
108
+
109
+ get '/session' do
110
+
111
+ #@req.session.expires
112
+ #@req.session.options[:expire_after] = 1
113
+ @req.session.options.inspect
114
+
81
115
  end
82
116
 
83
- get /^\/$/ do
117
+ get '/user' do
118
+
119
+ if @req.session[:username] then
120
+ 'You are ' + @req.session[:username]
121
+ else
122
+ 'you need to log in to view this page'
123
+ end
84
124
 
85
- file = File.join(@root, 'index.html')
86
- File.read file
87
125
  end
88
126
 
89
- get '/unauthorised/' do
90
- 'unauthorised user'
127
+ get '/unauthorised' do
128
+ ['unauthorised user', 'text/plain', 403]
91
129
  end
92
-
93
- end
130
+
131
+ super(env, params)
132
+
133
+ end
134
+
135
+ def login_form(msg='Log in to this site.', http_code=200, referer: '/')
136
+
137
+ s=<<EOF
138
+ p #{msg}
139
+
140
+ login
141
+ username: [ ]
142
+ password: [ ]
143
+ [! referer: #{referer}
144
+ ]
145
+ [login](/login)
146
+ EOF
147
+
148
+ [Martile.new(s).to_s, 'text/slim', http_code]
149
+
150
+ end
151
+
94
152
 
95
153
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandelion_s1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE3MDQyNzIyMTQ1NVoXDTE4MDQyNzIyMTQ1NVowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAMGzM9MfeWs/zG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J0ysp2jIlttnzKeYtadjPecS8MXy2XiIpHqNpAfRfxu3XHz6ZPDs2Ein
31
+ 76MsY6p7rsKjhd6NfzEzWrudixdPXHEDRsWhvc4D8yJ8sXRRlsqvYyJzWPAxjYDP
32
+ dGYM0uAJz9SVDPY+Vtc5SxUSjcxum8Q9AxhIyRhN6fELUh/aWKXnCX6oxLLvtsNu
33
+ woIuTfN3+nievIwQikkOMmmOHoKClutOf/QvliSCEBWgPEYNitoCAbt5kde/pLqm
34
+ gHDzDElZg+1jI3TgwZ+kIKwt7Vun9eZH2g8dc31fjlfxzKBRnOh5p7CoxbW4rx7M
35
+ JtmSOhu/qtu75iQs8PmwtvhDACcdpf0Q5VGHeyLvKq5LqZMqX9BK9BOD41uV9rt/
36
+ k7EFkjCAj62C0O4oFjSMVJQW
33
37
  -----END CERTIFICATE-----
34
- date: 2017-11-13 00:00:00.000000000 Z
38
+ date: 2022-01-15 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: rack-rscript
@@ -39,42 +43,62 @@ dependencies:
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '1.0'
46
+ version: '1.2'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 1.0.2
49
+ version: 1.2.3
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
54
  - - "~>"
51
55
  - !ruby/object:Gem::Version
52
- version: '1.0'
56
+ version: '1.2'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 1.0.2
59
+ version: 1.2.3
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: simple-config
58
62
  requirement: !ruby/object:Gem::Requirement
59
63
  requirements:
60
64
  - - "~>"
61
65
  - !ruby/object:Gem::Version
62
- version: '0.6'
66
+ version: '0.7'
63
67
  - - ">="
64
68
  - !ruby/object:Gem::Version
65
- version: 0.6.3
69
+ version: 0.7.1
66
70
  type: :runtime
67
71
  prerelease: false
68
72
  version_requirements: !ruby/object:Gem::Requirement
69
73
  requirements:
70
74
  - - "~>"
71
75
  - !ruby/object:Gem::Version
72
- version: '0.6'
76
+ version: '0.7'
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: 0.6.3
79
+ version: 0.7.1
80
+ - !ruby/object:Gem::Dependency
81
+ name: martile
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '1.4'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.4.6
76
100
  description:
77
- email: james@jamesrobertson.eu
101
+ email: digital.robertson@gmail.com
78
102
  executables: []
79
103
  extensions: []
80
104
  extra_rdoc_files: []
@@ -92,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
116
  requirements:
93
117
  - - ">="
94
118
  - !ruby/object:Gem::Version
95
- version: 2.1.2
119
+ version: 3.0.2
96
120
  required_rubygems_version: !ruby/object:Gem::Requirement
97
121
  requirements:
98
122
  - - ">="
@@ -100,9 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
124
  version: '0'
101
125
  requirements: []
102
126
  rubyforge_project:
103
- rubygems_version: 2.6.13
127
+ rubygems_version: 2.7.10
104
128
  signing_key:
105
129
  specification_version: 4
106
- summary: A kind of Rack-Rscript web server which facilitates static files, basic authentication,
107
- and private pages.
130
+ summary: A kind of Rack-Rscript web server which facilitates static files, cookie
131
+ based authentication, and private pages.
108
132
  test_files: []
metadata.gz.sig CHANGED
Binary file