dandelion_s1 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/dandelion_s1.rb +109 -51
- data.tar.gz.sig +0 -0
- metadata +59 -35
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c59a8096fccc922ca6c3100e5e393282995c5a482d173330ddcb85f8e3490d7
|
4
|
+
data.tar.gz: 3e47b63dc991f237c69e3c6c9a90a84fa6b1d4b767569a2304ac1b33751f09c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
12
|
+
def initialize(opts={})
|
12
13
|
|
13
|
-
|
14
|
-
@app_root = Dir.pwd
|
14
|
+
h = {root: 'www', static: [], passwords: {'user' => 'us3r'}}.merge(opts)
|
15
15
|
|
16
|
-
@
|
17
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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?
|
42
|
-
private_user.any? {|x| x ==
|
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
|
-
|
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
|
-
|
71
|
+
log = @log
|
72
|
+
|
73
|
+
get '/login2/*' do
|
74
|
+
params[:splat].inspect
|
75
|
+
redirect '/login' + params[:splat].first
|
76
|
+
end
|
56
77
|
|
57
|
-
get
|
78
|
+
get '/login/*' do
|
79
|
+
url = params[:splat].any? ? params[:splat][0][/(?<=referer=).*/] : '/'
|
80
|
+
login_form(referer: url)
|
81
|
+
end
|
58
82
|
|
59
|
-
|
83
|
+
post '/login' do
|
60
84
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
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
|
90
|
-
'unauthorised user'
|
127
|
+
get '/unauthorised' do
|
128
|
+
['unauthorised user', 'text/plain', 403]
|
91
129
|
end
|
92
|
-
|
93
|
-
|
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.
|
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 C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zAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUfSCCglAL
|
26
|
+
TLGYNZXPFdevytu+E5owJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAMWGLNvh2P5idDQH6p+wxxVKnt/b2fDjXlAx8/A8Q
|
29
|
+
3q+6iEM1rEvmNsnYvagbyDczPEhvoxuWvVUL0huwa99R4nX5o4yqr4IOR6NVZ724
|
30
|
+
tiC022XXJ0ysp2jIlttnzKeYtadjPecS8MXy2XiIpHqNpAfRfxu3XHz6ZPDs2Ein
|
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:
|
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.
|
46
|
+
version: '1.2'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
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.
|
56
|
+
version: '1.2'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
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.
|
66
|
+
version: '0.7'
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
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.
|
76
|
+
version: '0.7'
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
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:
|
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:
|
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.
|
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,
|
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
|