dandelion_s1 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/dandelion_s1.rb +92 -57
- data.tar.gz.sig +0 -0
- metadata +49 -30
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: defb22aa3bc5c08f20627b62117b79956d26fae9
|
4
|
+
data.tar.gz: f05f2b8d594b2d71d824d69c47e96ed5ef657a96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c8aa85c39e7bdfbcd5a5bbe40dc299de87b50d21021dac0fccaefc4042e72f1fb2940357303f57eea9a054ae655ea780d1cbdbda575322c0aee71f79ad7896
|
7
|
+
data.tar.gz: 6ea4b45538e936120c85c2db335898b88ade4b3acff7dbad93d242908a8c0a990b053307ab1d917d5e64f3bf4f7de920a24c847a3ac6d73bd1e90da86c19e0d5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/dandelion_s1.rb
CHANGED
@@ -2,94 +2,129 @@
|
|
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(
|
12
|
+
def initialize(opts={})
|
12
13
|
|
13
|
-
|
14
|
+
h = {root: 'www', static: []}.merge(opts)
|
15
|
+
|
16
|
+
access_list = h[:access]
|
14
17
|
@app_root = Dir.pwd
|
15
18
|
|
16
|
-
@static = raw_opts[:static]
|
17
|
-
@root = raw_opts[:root]
|
18
|
-
|
19
19
|
#@access_list = {'/do/r/hello3' => 'user'}
|
20
|
-
access_list = raw_opts[:access]
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
if access_list then
|
22
|
+
|
23
|
+
h2 = SimpleConfig.new(access_list).to_h
|
24
|
+
conf_access = h2[:body] || h2
|
25
|
+
@access_list = conf_access.inject({}) \
|
26
|
+
{|r,x| k,v = x; r.merge(k.to_s => v.split)}
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
h3 = %i(log pkg_src rsc_host rsc_package_src root static debug)\
|
31
|
+
.inject({}) {|r,x| r.merge(x => h[x])}
|
32
|
+
|
33
|
+
super(h3)
|
26
34
|
|
27
|
-
super(log: h[:log], pkg_src: h[:pkg_src], rsc_host: h[:rsc_host],
|
28
|
-
rsc_package_src: h[:rsc_package_src])
|
29
35
|
end
|
30
36
|
|
31
37
|
def call(e)
|
32
38
|
|
33
39
|
request = e['REQUEST_PATH']
|
34
|
-
|
40
|
+
|
41
|
+
return super(e) if request == '/login'
|
42
|
+
r = @access_list.detect {|k,v| request =~ Regexp.new(k)} if @access_list
|
35
43
|
private_user = r ? r.last : nil
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
45
|
+
req = Rack::Request.new(e)
|
46
|
+
user = req.session[:username]
|
47
|
+
#return [status_code=401, {"Content-Type" => 'text/plain'}, [user.inspect]]
|
48
|
+
return jumpto '/login' unless user
|
49
|
+
|
50
|
+
if private_user.nil? then
|
40
51
|
super(e)
|
41
|
-
elsif private_user.is_a?
|
42
|
-
private_user.any? {|x| x ==
|
52
|
+
elsif (private_user.is_a? String and private_user == user) \
|
53
|
+
or (private_user.is_a? Array and private_user.any? {|x| x == user})
|
43
54
|
super(e)
|
44
55
|
else
|
45
|
-
|
46
|
-
content, content_type, status_code = run_route(request)
|
47
|
-
content_type ||= 'text/html'
|
48
|
-
[status_code=401, {"Content-Type" => content_type}, [content]]
|
56
|
+
jumpto '/unauthorised'
|
49
57
|
end
|
50
58
|
|
51
59
|
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def default_routes(env, params)
|
64
|
+
|
65
|
+
get '/login' do
|
66
|
+
|
67
|
+
s=<<EOF
|
68
|
+
login
|
69
|
+
username: [ ]
|
70
|
+
password: [ ]
|
71
|
+
|
72
|
+
[login]('/login')
|
73
|
+
EOF
|
74
|
+
|
75
|
+
Martile.new(s).to_html
|
76
|
+
end
|
77
|
+
|
78
|
+
post '/login' do
|
79
|
+
|
80
|
+
h = @req.params
|
81
|
+
@req.session[:username] = h['username']
|
52
82
|
|
53
|
-
|
54
|
-
|
55
|
-
super(env, params)
|
56
|
-
|
57
|
-
get /^(\/(?:#{@static.join('|')}).*)/ do |path|
|
58
|
-
|
59
|
-
filepath = File.join(@app_root, @root, path)
|
60
|
-
|
61
|
-
if @log then
|
62
|
-
@log.info 'DandelionS1/default_routes: ' +
|
63
|
-
"root: %s path: %s" % [@root, path]
|
64
|
-
end
|
65
|
-
|
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
|
-
else
|
78
|
-
'oops, file ' + filepath + ' not found'
|
79
|
-
end
|
80
|
-
|
83
|
+
'you are now logged in as ' + h['username']
|
84
|
+
|
81
85
|
end
|
82
|
-
|
83
|
-
get
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
|
87
|
+
get '/logout' do
|
88
|
+
|
89
|
+
@req.session.clear
|
90
|
+
'you are now logged out'
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
get '/session' do
|
95
|
+
|
96
|
+
#@req.session.expires
|
97
|
+
#@req.session.options[:expire_after] = 1
|
98
|
+
@req.session.options.inspect
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
get '/user' do
|
103
|
+
|
104
|
+
if @req.session[:username] then
|
105
|
+
'You are ' + @req.session[:username]
|
106
|
+
else
|
107
|
+
'you need to log in to view this page'
|
108
|
+
end
|
109
|
+
|
87
110
|
end
|
88
111
|
|
89
|
-
get '/unauthorised
|
112
|
+
get '/unauthorised' do
|
90
113
|
'unauthorised user'
|
91
114
|
end
|
115
|
+
|
116
|
+
super(env, params)
|
92
117
|
|
93
|
-
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def jumpto(request)
|
123
|
+
|
124
|
+
content, content_type, status_code = run_route(request)
|
125
|
+
content_type ||= 'text/html'
|
126
|
+
[status_code=401, {"Content-Type" => content_type}, [content]]
|
127
|
+
|
128
|
+
end
|
94
129
|
|
95
130
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,27 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
+
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Zfqb8EuDqrBL9w==
|
13
|
+
MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb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ZIQKcP2zU4/Vha3btUrOKjLdL48mFpU5W1JmHVcGalvG12WPInaxSNhcldbbNK
|
30
|
+
1N8hBgTHd/hcz/i08u1weglfL0QBkOx9HzswCq9Iuesya/Zb40PJIbW4/A2pKm0o
|
31
|
+
eek=
|
33
32
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
33
|
+
date: 2018-07-23 00:00:00.000000000 Z
|
35
34
|
dependencies:
|
36
35
|
- !ruby/object:Gem::Dependency
|
37
36
|
name: rack-rscript
|
@@ -39,20 +38,20 @@ dependencies:
|
|
39
38
|
requirements:
|
40
39
|
- - "~>"
|
41
40
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
41
|
+
version: '1.1'
|
43
42
|
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
44
|
+
version: 1.1.2
|
46
45
|
type: :runtime
|
47
46
|
prerelease: false
|
48
47
|
version_requirements: !ruby/object:Gem::Requirement
|
49
48
|
requirements:
|
50
49
|
- - "~>"
|
51
50
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1.
|
51
|
+
version: '1.1'
|
53
52
|
- - ">="
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
54
|
+
version: 1.1.2
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
56
|
name: simple-config
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +61,7 @@ dependencies:
|
|
62
61
|
version: '0.6'
|
63
62
|
- - ">="
|
64
63
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.6.
|
64
|
+
version: 0.6.4
|
66
65
|
type: :runtime
|
67
66
|
prerelease: false
|
68
67
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,7 +71,27 @@ dependencies:
|
|
72
71
|
version: '0.6'
|
73
72
|
- - ">="
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.6.
|
74
|
+
version: 0.6.4
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: martile
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.9'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.9.1
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.9'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.9.1
|
76
95
|
description:
|
77
96
|
email: james@jamesrobertson.eu
|
78
97
|
executables: []
|
@@ -103,6 +122,6 @@ rubyforge_project:
|
|
103
122
|
rubygems_version: 2.6.13
|
104
123
|
signing_key:
|
105
124
|
specification_version: 4
|
106
|
-
summary: A kind of Rack-Rscript web server which facilitates static files,
|
107
|
-
and private pages.
|
125
|
+
summary: A kind of Rack-Rscript web server which facilitates static files, cookie
|
126
|
+
based authentication, and private pages.
|
108
127
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|