sbsm 1.3.0 → 1.3.1

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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: chrono_logger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,48 @@ dependencies:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry-byebug
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: nokogiri
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rack-test
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
181
237
  description: Application framework for state based session management
182
238
  email: mhatakeyama@ywesee.com, zdavatz@ywesee.com
183
239
  executables: []
@@ -200,16 +256,18 @@ files:
200
256
  - data/zone_uri.grammar
201
257
  - install.rb
202
258
  - lib/cgi/drbsession.rb
259
+ - lib/sbsm.rb
260
+ - lib/sbsm/app.rb
203
261
  - lib/sbsm/cgi.rb
204
262
  - lib/sbsm/drb.rb
205
263
  - lib/sbsm/drbserver.rb
206
264
  - lib/sbsm/exception.rb
207
265
  - lib/sbsm/index.rb
266
+ - lib/sbsm/logger.rb
208
267
  - lib/sbsm/lookandfeel.rb
209
268
  - lib/sbsm/lookandfeelfactory.rb
210
269
  - lib/sbsm/lookandfeelwrapper.rb
211
270
  - lib/sbsm/redirector.rb
212
- - lib/sbsm/request.rb
213
271
  - lib/sbsm/session.rb
214
272
  - lib/sbsm/state.rb
215
273
  - lib/sbsm/time.rb
@@ -223,10 +281,13 @@ files:
223
281
  - test/data/dos_file.txt
224
282
  - test/data/lnf_file.txt
225
283
  - test/data/mac_file.txt
284
+ - test/simple_sbsm.rb
226
285
  - test/stub/cgi.rb
227
286
  - test/suite.rb
287
+ - test/test_application.rb
228
288
  - test/test_drbserver.rb
229
289
  - test/test_index.rb
290
+ - test/test_logger.rb
230
291
  - test/test_lookandfeel.rb
231
292
  - test/test_session.rb
232
293
  - test/test_state.rb
@@ -262,10 +323,13 @@ test_files:
262
323
  - test/data/dos_file.txt
263
324
  - test/data/lnf_file.txt
264
325
  - test/data/mac_file.txt
326
+ - test/simple_sbsm.rb
265
327
  - test/stub/cgi.rb
266
328
  - test/suite.rb
329
+ - test/test_application.rb
267
330
  - test/test_drbserver.rb
268
331
  - test/test_index.rb
332
+ - test/test_logger.rb
269
333
  - test/test_lookandfeel.rb
270
334
  - test/test_session.rb
271
335
  - test/test_state.rb
data/lib/sbsm/request.rb DELETED
@@ -1,234 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- #
4
- # State Based Session Management
5
- # Copyright (C) 2004 Hannes Wyss
6
- #
7
- # This library is free software; you can redistribute it and/or
8
- # modify it under the terms of the GNU Lesser General Public
9
- # License as published by the Free Software Foundation; either
10
- # version 2.1 of the License, or (at your option) any later version.
11
- #
12
- # This library is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- # Lesser General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU Lesser General Public
18
- # License along with this library; if not, write to the Free Software
19
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
- #
21
- # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zürich, Switzerland
22
- # hwyss@ywesee.com
23
- #
24
- # SBSM::Request -- sbsm -- 24.10.2012 -- yasaka@ywesee.com
25
- # SBSM::Request -- sbsm -- 24.01.2012 -- mhatakeyama@ywesee.com
26
- # SBSM::Request -- sbsm -- hwyss@ywesee.com
27
-
28
- require 'cgi'
29
-
30
- require 'sbsm/cgi'
31
- require 'sbsm/drb'
32
- require 'cgi/session'
33
- require 'cgi/drbsession'
34
- require 'delegate'
35
-
36
- module SBSM
37
- class Request < SimpleDelegator
38
- include DRbUndumped
39
- attr_reader :cgi
40
- def initialize(drb_uri, html_version = "html4", cgiclass = CGI)
41
- @cgi = CGI.initialize_without_offline_prompt('html4')
42
- @drb_uri = drb_uri
43
- @thread = nil
44
- @request = Apache.request
45
- super(@cgi)
46
- end
47
- def cookies
48
- @cgi.cookies
49
- end
50
- def is_crawler?
51
- crawler_pattern = /archiver|slurp|bot|crawler|jeeves|spider|\.{6}/i
52
- !!crawler_pattern.match(@cgi.user_agent)
53
- end
54
- def passthru(path, disposition='attachment')
55
- # the variable @passthru is set by a trusted source
56
- @passthru = path.untaint
57
- @disposition = disposition
58
- ''
59
- end
60
- def process
61
- begin
62
- @cgi.params.store('default_flavor', ENV['DEFAULT_FLAVOR'])
63
- @request.notes.each { |key, val|
64
- @cgi.params.store(key, val)
65
- }
66
- drb_process()
67
- #drb_request()
68
- #drb_response()
69
- rescue StandardError => e
70
- handle_exception(e)
71
- ensure
72
- @session.close if @session.respond_to?(:close)
73
- end
74
- end
75
- def remote_host(lookup_type=Apache::REMOTE_NOLOOKUP)
76
- @request.remote_host(lookup_type)
77
- end
78
- def unparsed_uri
79
- @request.unparsed_uri
80
- end
81
- private
82
- def lock
83
- lock_file = '/tmp/sbsm_lock'
84
- open(lock_file, 'a') do |st|
85
- st.flock(File::LOCK_EX)
86
- yield
87
- st.flock(File::LOCK_UN)
88
- end
89
- end
90
- def drb_server_threads
91
- threads = 0
92
- status = '/var/www/oddb.org/doc/resources/downloads/status'
93
- if File.exist?(status)
94
- open(status) do |file|
95
- if file.gets =~ /threads:\s+(\d+)/
96
- threads = $1.to_i
97
- end
98
- end
99
- end
100
- threads
101
- end
102
- def drop_flag(flag = nil)
103
- file = '/tmp/sbsm_drop_flag'
104
- if flag != nil # write
105
- lock do
106
- open(file, 'w') do |f|
107
- f.print flag.to_s
108
- end
109
- end
110
- else # read
111
- unless File.exist?(file)
112
- lock do
113
- open(file, 'w') do |f|
114
- f.print false
115
- flag = false
116
- end
117
- end
118
- else
119
- open(file, 'r') do |f|
120
- flag = if f.gets.chomp =~ /true/
121
- true
122
- else
123
- false
124
- end
125
- end
126
- end
127
- end
128
- flag
129
- end
130
- def check_threads
131
- time = Time.now.sec.to_i % 5
132
- if time == 0
133
- #if drb_server_threads > 50
134
- if drb_server_threads > 30
135
- drop_flag true
136
- else
137
- drop_flag false
138
- end
139
- end
140
- end
141
- def is_drop?
142
- if unparsed_uri =~ /pointer/ or (is_crawler? && drop_flag)
143
- true
144
- end
145
- end
146
- def drb_process
147
- args = {
148
- 'database_manager' => CGI::Session::DRbSession,
149
- 'drbsession_uri' => @drb_uri,
150
- 'session_path' => '/',
151
- }
152
- check_threads
153
- if is_drop?
154
- return
155
- end
156
- if(is_crawler?)
157
- sleep 2.0
158
- sid = [ENV['DEFAULT_FLAVOR'], @cgi.params['language'], @cgi.user_agent].join('-')
159
- args.store('session_id', sid)
160
- end
161
- @session = CGI::Session.new(@cgi, args)
162
- @proxy = @session[:proxy]
163
- res = @proxy.drb_process(self)
164
- cookie_input = @proxy.cookie_input
165
- # view.to_html can call passthru instead of sending data
166
- if(@passthru)
167
- unless(cookie_input.empty?)
168
- cookie = generate_cookie(cookie_input)
169
- @request.headers_out.add('Set-Cookie', cookie.to_s)
170
- end
171
- basename = File.basename(@passthru)
172
- fullpath = File.expand_path(
173
- @passthru,
174
- @request.server.document_root.untaint)
175
- subreq = @request.lookup_file(fullpath)
176
- @request.content_type = subreq.content_type
177
- @request.headers_out.add('Content-Disposition',
178
- "#@disposition; filename=#{basename}")
179
- @request.headers_out.add('Content-Length',
180
- File.size(fullpath).to_s)
181
- begin
182
- File.open(fullpath) { |fd| @request.send_fd(fd) }
183
- rescue Errno::ENOENT, IOError => err
184
- @request.log_reason(err.message, @passthru)
185
- return Apache::NOT_FOUND
186
- end
187
- else
188
- begin
189
- headers = @proxy.http_headers
190
- unless(cookie_input.empty?)
191
- cookie = generate_cookie(cookie_input)
192
- headers.store('Set-Cookie', cookie.to_s)
193
- end
194
- @cgi.out(headers) {
195
- (@cgi.params.has_key?("pretty")) ? CGI.pretty( res ) : res
196
- }
197
- rescue StandardError => e
198
- handle_exception(e)
199
- end
200
- end
201
- end
202
- def generate_cookie(cookie_input)
203
- cookie_pairs = cookie_input.collect { |pair|
204
- pair.join('=')
205
- }.join(';')
206
- cookie_hash = {
207
- "name" => @proxy.cookie_name || 'sbsm-persistent-cookie',
208
- "value" => cookie_pairs,
209
- "path" => "/",
210
- "expires" => (Time.now + (60 * 60 * 24 * 365 * 10)),
211
- }
212
- CGI::Cookie.new(cookie_hash).to_s
213
- end
214
- def handle_exception(e)
215
- if defined?(Apache)
216
- msg = [
217
- [Time.now, self.object_id].join(' - '),
218
- e.class,
219
- e.message,
220
- ].join(" - ")
221
- uri = unparsed_uri
222
- @request.log_reason(msg, uri)
223
- e.backtrace.each { |line|
224
- @request.log_reason(line, uri)
225
- }
226
- end
227
- hdrs = {
228
- 'Status' => '302 Moved',
229
- 'Location' => '/resources/errors/appdown.html',
230
- }
231
- @cgi.header(hdrs)
232
- end
233
- end
234
- end