spiderfw 0.6.23 → 0.6.24
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.
- data/CHANGELOG +10 -1
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/apps/config_editor/_init.rb +1 -2
- data/apps/config_editor/controllers/config_editor_controller.rb +1 -7
- data/apps/core/admin/controllers/admin_controller.rb +1 -1
- data/apps/core/admin/public/css/sass/admin.css +35 -31
- data/apps/core/admin/public/sass/admin.scss +6 -1
- data/apps/core/components/widgets/crud/crud.shtml +2 -2
- data/apps/core/components/widgets/table/table.rb +5 -5
- data/apps/core/forms/tags/element_row.erb +15 -10
- data/apps/core/forms/widgets/form/form.rb +35 -22
- data/apps/core/forms/widgets/inputs/checkbox/checkbox.shtml +2 -2
- data/apps/core/forms/widgets/inputs/date_time/date_time.shtml +2 -2
- data/apps/core/forms/widgets/inputs/file_input/file_input.shtml +2 -2
- data/apps/core/forms/widgets/inputs/html_area/html_area.shtml +2 -2
- data/apps/core/forms/widgets/inputs/input/input.shtml +2 -2
- data/apps/core/forms/widgets/inputs/password/password.shtml +2 -2
- data/apps/core/forms/widgets/inputs/search_select/search_select.shtml +1 -1
- data/apps/core/forms/widgets/inputs/select/select.shtml +2 -2
- data/apps/core/forms/widgets/inputs/text/text.shtml +2 -2
- data/apps/core/forms/widgets/inputs/text_area/text_area.shtml +2 -2
- data/apps/core/forms/widgets/inputs/time_span/time_span.shtml +1 -1
- data/blueprints/home/config.ru +8 -0
- data/lib/spiderfw/app.rb +416 -224
- data/lib/spiderfw/cmd/commands/app.rb +243 -239
- data/lib/spiderfw/cmd/commands/cert.rb +421 -417
- data/lib/spiderfw/cmd/commands/config.rb +85 -82
- data/lib/spiderfw/cmd/commands/console.rb +64 -40
- data/lib/spiderfw/cmd/commands/content.rb +29 -25
- data/lib/spiderfw/cmd/commands/create.rb +58 -54
- data/lib/spiderfw/cmd/commands/model.rb +118 -114
- data/lib/spiderfw/cmd/commands/setup.rb +55 -51
- data/lib/spiderfw/cmd/commands/test.rb +63 -59
- data/lib/spiderfw/cmd/commands/webserver.rb +56 -51
- data/lib/spiderfw/config/options/spider.rb +4 -3
- data/lib/spiderfw/controller/controller.rb +2 -0
- data/lib/spiderfw/controller/http_controller.rb +1 -2
- data/lib/spiderfw/controller/mixins/static_content.rb +3 -3
- data/lib/spiderfw/controller/mixins/visual.rb +30 -15
- data/lib/spiderfw/controller/response.rb +84 -0
- data/lib/spiderfw/controller/session/file_session.rb +2 -2
- data/lib/spiderfw/http/adapters/rack.rb +12 -13
- data/lib/spiderfw/http/server.rb +80 -46
- data/lib/spiderfw/i18n/cldr.rb +6 -9
- data/lib/spiderfw/model/base_model.rb +103 -23
- data/lib/spiderfw/model/condition.rb +110 -25
- data/lib/spiderfw/model/mappers/db_mapper.rb +14 -6
- data/lib/spiderfw/model/mappers/mapper.rb +440 -197
- data/lib/spiderfw/model/model.rb +105 -21
- data/lib/spiderfw/model/model_hash.rb +9 -1
- data/lib/spiderfw/model/query.rb +50 -9
- data/lib/spiderfw/model/query_set.rb +211 -44
- data/lib/spiderfw/model/request.rb +28 -21
- data/lib/spiderfw/model/storage/base_storage.rb +125 -10
- data/lib/spiderfw/model/storage/db/db_storage.rb +7 -4
- data/lib/spiderfw/model/storage.rb +8 -1
- data/lib/spiderfw/setup/spider_setup_wizard.rb +9 -7
- data/lib/spiderfw/spider.rb +270 -43
- data/lib/spiderfw/templates/layout.rb +9 -4
- data/lib/spiderfw/templates/resources/sass.rb +3 -2
- data/lib/spiderfw/templates/template.rb +1 -0
- data/lib/spiderfw/utils/annotations.rb +3 -1
- data/lib/spiderfw/utils/logger.rb +1 -1
- data/lib/spiderfw/utils/monkey/symbol.rb +4 -2
- data/lib/spiderfw/utils/shared_store/file_shared_store.rb +2 -2
- data/lib/spiderfw/utils/thread_out.rb +3 -1
- data/public/css/error_page.css +83 -0
- data/public/js/error_page.js +5 -0
- data/spider.gemspec +4 -1
- data/templates/email/error.erb +9 -0
- metadata +28 -12
- data/apps/config_editor/widgets/edit_bool/edit_bool.rb +0 -8
- data/apps/config_editor/widgets/edit_bool/edit_bool.shtml +0 -5
@@ -1,7 +1,7 @@
|
|
1
1
|
module Spider
|
2
2
|
|
3
3
|
config_option('runmode', "production, test, devel", :default => 'devel', :choices => ['production', 'test', 'devel'],
|
4
|
-
:action => Proc.new{ |option|
|
4
|
+
:action => Proc.new{ |option| $SPIDER_RUNMODE = option }
|
5
5
|
)
|
6
6
|
|
7
7
|
config_option('apps', _('Apps to load'), :type => Array, :yaml_style => :inline)
|
@@ -34,8 +34,6 @@ module Spider
|
|
34
34
|
config_option 'webserver.timeout', _("Time allowed for each request (in seconds)"), :type=> Fixnum, :default => nil
|
35
35
|
config_option 'webserver.respawn_on_change', _("Restart the webserver when application code changes"), :type => Spider::Bool,
|
36
36
|
:default => Proc.new{ RUBY_PLATFORM !~ /win32|mingw32/ && Spider.config.get('runmode') == 'devel' ? true : false }
|
37
|
-
config_option 'webserver.respawn.core_devel', _('Respawn on changes to the framework'),
|
38
|
-
:type => Spider::Bool, :default => false
|
39
37
|
config_option 'process.shutdown_timeout', _("Number of seconds a process is given to end"), :type => Fixnum, :default => 60
|
40
38
|
config_option 'static_content.mode', _("Mode to use for serving static files"), :type => String,
|
41
39
|
:choices => [nil, 'x-sendfile', 'x-accel-redirect', 'published'], :default => nil
|
@@ -81,6 +79,9 @@ module Spider
|
|
81
79
|
|
82
80
|
config_option 'debugger.start', _("Start the debugger"), :type => Spider::DataTypes::Bool,
|
83
81
|
:default => lambda{ ['test', 'devel'].include?(Spider.runmode) ? true : false }
|
82
|
+
config_option 'debugger.pry', _("User Pry for debugging"), :type => Spider::Bool, :default => lambda{
|
83
|
+
RUBY_VERSION_PARTS[1] == '9'
|
84
|
+
}
|
84
85
|
config_option 'profiling.enable', _("Enable on-request profiling"), :type => Spider::DataTypes::Bool
|
85
86
|
config_option 'request.mutex', _("Respond to requests sequentially"), :default => false
|
86
87
|
|
@@ -235,6 +235,7 @@ module Spider
|
|
235
235
|
end
|
236
236
|
|
237
237
|
def call_before(action='', *arguments)
|
238
|
+
return if respond_to?(:serving_static?) && self.serving_static?
|
238
239
|
@call_path = action
|
239
240
|
before(action, *arguments)
|
240
241
|
catch(:done) do
|
@@ -251,6 +252,7 @@ module Spider
|
|
251
252
|
|
252
253
|
|
253
254
|
def call_after(action='', *arguments)
|
255
|
+
return if respond_to?(:serving_static?) && self.serving_static?
|
254
256
|
after(action, *arguments)
|
255
257
|
catch(:done) do
|
256
258
|
d_next = dispatch_next(action)
|
@@ -11,8 +11,7 @@ module Spider
|
|
11
11
|
def initialize(request, response, scene=nil)
|
12
12
|
response.status = Spider::HTTP::OK
|
13
13
|
response.headers = {
|
14
|
-
'Content-Type' => 'text/plain'
|
15
|
-
'Connection' => 'close'
|
14
|
+
'Content-Type' => 'text/plain'
|
16
15
|
}
|
17
16
|
@previous_stdout = $stdout
|
18
17
|
Thread.current[:stdout] = response.server_output
|
@@ -103,8 +103,8 @@ module Spider; module ControllerMixins
|
|
103
103
|
ct = ct.to_s if ct
|
104
104
|
ct ||= "application/octet-stream"
|
105
105
|
end
|
106
|
-
@response.
|
107
|
-
@response.
|
106
|
+
@response.content_type = ct
|
107
|
+
@response.content_length = stat.size
|
108
108
|
@response.headers['Last-Modified'] = mtime.httpdate
|
109
109
|
|
110
110
|
if mode == 'x-sendfile'
|
@@ -112,7 +112,7 @@ module Spider; module ControllerMixins
|
|
112
112
|
elsif mode == 'x-accel-redirect'
|
113
113
|
@response.headers['X-Accel-Redirect'] = full_path
|
114
114
|
else
|
115
|
-
f = File.open(full_path, '
|
115
|
+
f = File.open(full_path, 'rb')
|
116
116
|
while (block = f.read(1024)) do
|
117
117
|
$out << block
|
118
118
|
end
|
@@ -22,8 +22,20 @@ module Spider; module ControllerMixins
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def before(action='', *params)
|
25
|
-
|
26
|
-
|
25
|
+
unless self.respond_to?(:serving_static?) && self.serving_static?
|
26
|
+
@layout ||= self.class.get_layout(action)
|
27
|
+
@layout ||= @dispatcher_layout
|
28
|
+
n_route = dispatch_next(action)
|
29
|
+
obj = n_route.obj if n_route
|
30
|
+
if obj.is_a?(Visual) && !(obj.respond_to?(:serving_static?) && obj.serving_static?)
|
31
|
+
set_layout = @layout
|
32
|
+
if set_layout
|
33
|
+
set_layout = [set_layout] unless set_layout.is_a?(Array)
|
34
|
+
set_layout.map{ |l| self.class.load_layout(l) }
|
35
|
+
obj.dispatcher_layout = set_layout
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
27
39
|
return super unless action_target?
|
28
40
|
format = nil
|
29
41
|
req_format = self.is_a?(Widget) && @is_target && @request.params['_wf'] ? @request.params['_wf'].to_sym : @request.format
|
@@ -44,16 +56,7 @@ module Spider; module ControllerMixins
|
|
44
56
|
if Spider.runmode != 'devel' && File.exists?(File.join(Spider.paths[:tmp], 'maintenance.txt'))
|
45
57
|
raise Spider::Controller::Maintenance
|
46
58
|
end
|
47
|
-
|
48
|
-
obj = n_route.obj if n_route
|
49
|
-
if obj.is_a?(Visual) && !(obj.respond_to?(:serving_static?) && obj.serving_static?)
|
50
|
-
set_layout = @layout || @dispatcher_layout
|
51
|
-
if set_layout
|
52
|
-
set_layout = [set_layout] unless set_layout.is_a?(Array)
|
53
|
-
set_layout.map{ |l| self.class.load_layout(l) }
|
54
|
-
obj.dispatcher_layout = set_layout
|
55
|
-
end
|
56
|
-
end
|
59
|
+
|
57
60
|
super
|
58
61
|
end
|
59
62
|
|
@@ -144,6 +147,13 @@ module Spider; module ControllerMixins
|
|
144
147
|
@template = template
|
145
148
|
return template
|
146
149
|
end
|
150
|
+
|
151
|
+
def load_template_from_path(path, definer)
|
152
|
+
t = Spider::Template.new(path)
|
153
|
+
t.owner_class = self.class
|
154
|
+
t.definer_class = definer
|
155
|
+
t
|
156
|
+
end
|
147
157
|
|
148
158
|
def prepare_template(template)
|
149
159
|
template.owner = self
|
@@ -543,12 +553,17 @@ module Spider; module ControllerMixins
|
|
543
553
|
search_paths ||= template_paths
|
544
554
|
resource = Spider::Template.find_resource(name, cur_path, owner, search_paths)
|
545
555
|
raise "Template #{name} not found" unless resource && resource.path
|
546
|
-
t =
|
547
|
-
t.owner_class = self
|
548
|
-
t.definer_class = resource.definer
|
556
|
+
t = load_template_from_path(resource.path, resource.definer)
|
549
557
|
return t
|
558
|
+
end
|
550
559
|
|
560
|
+
def load_template_from_path(path, definer)
|
561
|
+
t = Spider::Template.new(path)
|
562
|
+
t.owner_class = self
|
563
|
+
t.definer_class = definer
|
564
|
+
t
|
551
565
|
end
|
566
|
+
|
552
567
|
|
553
568
|
def template_exists?(name, paths=nil)
|
554
569
|
if (name[0..5] == 'SPIDER' || name[0..3] == 'ROOT')
|
@@ -49,6 +49,90 @@ module Spider
|
|
49
49
|
# end
|
50
50
|
end
|
51
51
|
|
52
|
+
def buffering?
|
53
|
+
@prev_io != nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_buffering
|
57
|
+
@buffer = StringIO.new
|
58
|
+
@prev_io = ThreadOut.output_to(@buffer)
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop_buffering
|
62
|
+
ThreadOut.output_to(@prev_io)
|
63
|
+
@prev_io = nil
|
64
|
+
@buffer.rewind
|
65
|
+
end
|
66
|
+
|
67
|
+
def output_buffer
|
68
|
+
stop_buffering if buffering?
|
69
|
+
return unless @buffer
|
70
|
+
while d = @buffer.read(1024)
|
71
|
+
$out << d
|
72
|
+
end
|
73
|
+
buffer = @buffer
|
74
|
+
@buffer = nil
|
75
|
+
buffer
|
76
|
+
end
|
77
|
+
|
78
|
+
def buffer
|
79
|
+
@buffer
|
80
|
+
end
|
81
|
+
|
82
|
+
def clear_buffer
|
83
|
+
@buffer = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def content_type=(val)
|
87
|
+
@headers['Content-Type'] = val
|
88
|
+
end
|
89
|
+
|
90
|
+
def content_type
|
91
|
+
@headers['Content-Type']
|
92
|
+
end
|
93
|
+
|
94
|
+
def content_length=(val)
|
95
|
+
@headers['Content-Length'] = val
|
96
|
+
if @buffer_until_length && val
|
97
|
+
output_buffer
|
98
|
+
@buffer_until_length = false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def content_length
|
103
|
+
@headers['Content-Length']
|
104
|
+
end
|
105
|
+
|
106
|
+
def buffer_until_length
|
107
|
+
unless content_length
|
108
|
+
start_buffering
|
109
|
+
@buffer_until_length = true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def finish!
|
114
|
+
if buffering?
|
115
|
+
stop_buffering
|
116
|
+
needs_length = @needs_length
|
117
|
+
self.content_length = @buffer.length
|
118
|
+
output_buffer unless needs_length
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def connection_keep_alive
|
123
|
+
@headers['Connection'] = 'Keep-Alive'
|
124
|
+
buffer_until_length unless Spider.conf.get('webserver.has_buffering_proxy')
|
125
|
+
end
|
126
|
+
|
127
|
+
def do_not_buffer!
|
128
|
+
unless Spider.conf.get('webserver.has_buffering_proxy')
|
129
|
+
@headers['Connection'] = 'Close'
|
130
|
+
end
|
131
|
+
output_buffer
|
132
|
+
@buffer_until_length = false
|
133
|
+
end
|
134
|
+
|
135
|
+
|
52
136
|
|
53
137
|
end
|
54
138
|
|
@@ -17,7 +17,7 @@ module Spider
|
|
17
17
|
path = "#{dir}/#{sid}"
|
18
18
|
|
19
19
|
@sync.lock(Sync::EX)
|
20
|
-
f = File.new(path, '
|
20
|
+
f = File.new(path, 'wb+')
|
21
21
|
f.flock(File::LOCK_EX)
|
22
22
|
f.puts(Marshal.dump(data))
|
23
23
|
f.flush
|
@@ -33,7 +33,7 @@ module Spider
|
|
33
33
|
data = nil
|
34
34
|
if (File.exist?(path))
|
35
35
|
@sync.lock(Sync::SH)
|
36
|
-
f = File.new(path, '
|
36
|
+
f = File.new(path, 'rb+')
|
37
37
|
f.flock(File::LOCK_SH)
|
38
38
|
begin
|
39
39
|
data = Marshal.restore(f.read)
|
@@ -20,12 +20,13 @@ module Spider; module HTTP
|
|
20
20
|
|
21
21
|
class RackIO < ControllerIO
|
22
22
|
|
23
|
-
def initialize(response, controller_response, w)
|
23
|
+
def initialize(response, controller_response, w, options={})
|
24
24
|
@response = response
|
25
25
|
@controller_response = controller_response
|
26
26
|
@w = w
|
27
27
|
@headers_sent = false
|
28
28
|
@rack_thread = Thread.current
|
29
|
+
@options = options
|
29
30
|
end
|
30
31
|
|
31
32
|
def write(msg)
|
@@ -46,7 +47,7 @@ module Spider; module HTTP
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
@headers_sent = true
|
49
|
-
@rack_thread.run if
|
50
|
+
@rack_thread.run if @options[:multithread]
|
50
51
|
end
|
51
52
|
|
52
53
|
def headers_sent?
|
@@ -83,10 +84,11 @@ module Spider; module HTTP
|
|
83
84
|
|
84
85
|
w = nil
|
85
86
|
controller_response = Spider::Response.new
|
86
|
-
|
87
|
+
multithread = env['rack.multithread'] || Spider.conf.get('webserver.force_threads')
|
88
|
+
if multithread
|
87
89
|
r, w = IO.pipe
|
88
90
|
rack_response_hash = {:body => r}
|
89
|
-
controller_response.server_output = RackIO.new(rack_response_hash, controller_response, w)
|
91
|
+
controller_response.server_output = RackIO.new(rack_response_hash, controller_response, w, :multithread => true)
|
90
92
|
else
|
91
93
|
w = StringIO.new
|
92
94
|
rack_response_hash = {:body => w}
|
@@ -103,21 +105,19 @@ module Spider; module HTTP
|
|
103
105
|
controller.extend(Spider::FirstResponder)
|
104
106
|
controller.call_before(path)
|
105
107
|
controller.execute(path)
|
106
|
-
if
|
108
|
+
if multithread
|
107
109
|
w.close
|
108
110
|
controller_response.server_output.send_headers unless controller_response.server_output.headers_sent?
|
109
111
|
end
|
110
112
|
controller.call_after(path)
|
111
113
|
controller_done = true
|
112
|
-
Spider::Logger.debug("Controller done")
|
113
114
|
rescue => exc
|
114
|
-
Spider.logger.
|
115
|
-
Spider.logger.debug(exc)
|
115
|
+
Spider.logger.error(exc)
|
116
116
|
controller.ensure if controller
|
117
117
|
controller = nil
|
118
118
|
ensure
|
119
119
|
begin
|
120
|
-
if
|
120
|
+
if multithread
|
121
121
|
controller_response.server_output.send_headers unless controller_response.server_output.headers_sent?
|
122
122
|
else
|
123
123
|
controller_response.prepare_headers
|
@@ -134,7 +134,7 @@ module Spider; module HTTP
|
|
134
134
|
end
|
135
135
|
Spider.request_finished
|
136
136
|
ensure
|
137
|
-
if
|
137
|
+
if multithread
|
138
138
|
begin
|
139
139
|
w.close
|
140
140
|
rescue
|
@@ -146,8 +146,8 @@ module Spider; module HTTP
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
if
|
150
|
-
controllerThread = Thread.start
|
149
|
+
if multithread
|
150
|
+
controllerThread = Thread.start(&run_block)
|
151
151
|
t = Time.now
|
152
152
|
while !controller_done && !controller_response.server_output.headers_sent? && (Time.now - t) < 60
|
153
153
|
Thread.stop
|
@@ -160,7 +160,6 @@ module Spider; module HTTP
|
|
160
160
|
run_block.call
|
161
161
|
end
|
162
162
|
|
163
|
-
Spider.logger.debug("Rack responding")
|
164
163
|
return [rack_response_hash[:status], rack_response_hash[:headers], rack_response_hash[:body]]
|
165
164
|
end
|
166
165
|
|
data/lib/spiderfw/http/server.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'spiderfw/http/adapters/rack'
|
3
|
+
|
1
4
|
module Spider; module HTTP
|
2
5
|
|
3
6
|
class Server
|
@@ -33,64 +36,87 @@ module Spider; module HTTP
|
|
33
36
|
|
34
37
|
def request_received
|
35
38
|
end
|
36
|
-
|
37
|
-
def self.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
|
40
|
+
def self.get_opts(server_name, options)
|
41
|
+
server_name ||= Spider.conf.get('http.server')
|
42
|
+
options[:port] ||= Spider.conf.get('webserver.port')
|
43
|
+
opts = {
|
44
|
+
:server => server_name,
|
45
|
+
:Port => options[:port],
|
46
|
+
:config => File.join(Spider.paths[:root], 'config.ru')
|
42
47
|
}
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
case server_name
|
49
|
+
when 'thin'
|
50
|
+
opts[:threaded] = true unless options[:no_threads]
|
51
|
+
options[:daemonize] = true
|
52
|
+
end
|
53
|
+
opts[:app] = Spider::HTTP::RackApplication.new unless File.file?(opts[:config])
|
54
|
+
ssl_opts = nil
|
55
|
+
if options[:ssl]
|
56
|
+
require 'openssl'
|
57
|
+
options[:ssl_cert] ||= Spider.conf.get('orgs.default.cert')
|
58
|
+
options[:ssl_key] ||= Spider.conf.get('orgs.default.private_key')
|
59
|
+
raise "SSL Certificate not set" unless options[:ssl_cert]
|
60
|
+
raise "SSL Key not set" unless options[:ssl_key]
|
61
|
+
raise "SSL Certificate (#{options[:ssl_cert]}) not found" unless File.file?(options[:ssl_cert])
|
62
|
+
raise "SSL Key (#{options[:ssl_key]}) not found" unless File.file?(options[:ssl_key])
|
63
|
+
ssl_opts = opts.clone
|
64
|
+
ssl_opts[:Port] = options[:ssl]
|
65
|
+
private_key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]).read)
|
66
|
+
certificate = OpenSSL::X509::Certificate.new(File.open(options[:ssl_cert]).read)
|
67
|
+
case server_name
|
68
|
+
when 'webrick'
|
69
|
+
require 'webrick/https'
|
70
|
+
ssl_opts[:SSLEnable] = true
|
71
|
+
ssl_opts[:SSLVerifyClient] = ::OpenSSL::SSL::VERIFY_NONE
|
72
|
+
ssl_opts[:SSLCertificate] = certificate
|
73
|
+
ssl_opts[:SSLPrivateKey] = private_key
|
74
|
+
# when 'thin'
|
75
|
+
# ssl_opts[:ssl] = true
|
76
|
+
# ssl_opts[:verify_peer] = ::OpenSSL::SSL::VERIFY_NONE
|
77
|
+
# ssl_opts[:ssl_key_file] = private_key
|
78
|
+
# ssl_opts[:ssl_cert_file] = certificate
|
79
|
+
else
|
80
|
+
raise "SSL not supported with #{server_name} server"
|
51
81
|
end
|
52
|
-
|
82
|
+
end
|
83
|
+
return [opts, ssl_opts]
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.start(server_name, options={})
|
87
|
+
start = lambda{
|
88
|
+
|
53
89
|
|
54
|
-
port ||= Spider.conf.get('webserver.port')
|
55
|
-
server_name ||= Spider.conf.get('http.server')
|
56
90
|
pid_file = File.join(Spider.paths[:var], 'run/server.pid')
|
57
91
|
puts _("Using webserver %s") % server_name if options[:verbose]
|
58
|
-
puts _("Listening on port %s") % port if options[:verbose]
|
59
|
-
|
92
|
+
puts _("Listening on port %s") % opts[:port] if options[:verbose]
|
93
|
+
rack = nil
|
94
|
+
ssl_rack = nil
|
95
|
+
server = nil
|
60
96
|
ssl_server = nil
|
97
|
+
|
98
|
+
require 'spiderfw/init'
|
99
|
+
Spider.logger.info{ "Routes: \n"+Spider::HomeController.print_app_routes }
|
61
100
|
Spider.startup
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
101
|
+
opts, ssl_opts = self.get_opts(server_name, options)
|
102
|
+
|
103
|
+
if opts
|
104
|
+
thread = Thread.new do
|
105
|
+
rack = Rack::Server.start(opts)
|
106
|
+
server = rack.server if rack
|
68
107
|
end
|
69
|
-
|
70
|
-
Spider.logger.warn "Unable to start debugger"
|
108
|
+
$stdout << "Spider server running on port #{opts[:Port]}\n"
|
71
109
|
end
|
72
110
|
|
73
|
-
|
74
|
-
server.start(:port => port, :cgi => options[:cgi])
|
75
|
-
end
|
76
|
-
$stdout << "Spider server running on port #{port}\n"
|
77
|
-
if options[:ssl]
|
78
|
-
options[:ssl_cert] ||= Spider.conf.get('orgs.default.cert')
|
79
|
-
options[:ssl_key] ||= Spider.conf.get('orgs.default.private_key')
|
80
|
-
raise "SSL Certificate not set" unless options[:ssl_cert]
|
81
|
-
raise "SSL Key not set" unless options[:ssl_key]
|
82
|
-
raise "SSL Certificate (#{options[:ssl_cert]}) not found" unless File.file?(options[:ssl_cert])
|
83
|
-
raise "SSL Key (#{options[:ssl_key]}) not found" unless File.file?(options[:ssl_key])
|
111
|
+
if ssl_opts
|
84
112
|
ssl_thread = Thread.new do
|
85
|
-
|
86
|
-
ssl_server
|
87
|
-
:ssl_cert => options[:ssl_cert], :ssl_private_key => options[:ssl_key])
|
113
|
+
ssl_rack = Rack::Server.start(ssl_opts)
|
114
|
+
ssl_server = ssl_rack.server if ssl_rack
|
88
115
|
end
|
89
116
|
end
|
90
117
|
do_shutdown = lambda{
|
91
118
|
Debugger.post_mortem = false if defined?(Debugger)
|
92
|
-
|
93
|
-
server.shutdown
|
119
|
+
server.shutdown if server
|
94
120
|
ssl_server.shutdown if ssl_server
|
95
121
|
pid_file = File.join(Spider.paths[:var], 'run/server.pid')
|
96
122
|
begin
|
@@ -100,8 +126,11 @@ module Spider; module HTTP
|
|
100
126
|
}
|
101
127
|
Spider.on_shutdown(&do_shutdown)
|
102
128
|
|
103
|
-
|
104
|
-
|
129
|
+
begin
|
130
|
+
thread.join if thread
|
131
|
+
ssl_thread.join if ssl_thread
|
132
|
+
rescue SystemExit
|
133
|
+
end
|
105
134
|
}
|
106
135
|
if options[:daemonize]
|
107
136
|
require 'spiderfw/init'
|
@@ -201,7 +230,12 @@ module Spider; module HTTP
|
|
201
230
|
rd.close
|
202
231
|
Spider.spawner = wr
|
203
232
|
return unless @actions[action]
|
204
|
-
|
233
|
+
begin
|
234
|
+
@actions[action].call
|
235
|
+
rescue Exception => exc
|
236
|
+
Spider.logger.debug(exc)
|
237
|
+
Process.kill 'KILL', Process.pid
|
238
|
+
end
|
205
239
|
end
|
206
240
|
end
|
207
241
|
|
data/lib/spiderfw/i18n/cldr.rb
CHANGED
@@ -14,7 +14,6 @@ module Spider; module I18n
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def localize_date_time(object, format = 'medium', options={})
|
17
|
-
raise "Localize format is nil" unless format
|
18
17
|
options[:calendar] ||= 'gregorian'
|
19
18
|
format = 'medium' if format == :default
|
20
19
|
|
@@ -41,8 +40,8 @@ module Spider; module I18n
|
|
41
40
|
# FIXME: handle more efficiently
|
42
41
|
d = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
|
43
42
|
obj_d = d[object.wday]
|
44
|
-
days = @cldr.calendar.days[options[:calendar].to_sym]
|
45
|
-
months = @cldr.calendar.months[options[:calendar].to_sym]
|
43
|
+
days = @cldr.calendar.days[options[:calendar].to_sym]
|
44
|
+
months = @cldr.calendar.months[options[:calendar].to_sym]
|
46
45
|
replacements = [
|
47
46
|
[/y{1,4}/, '%Y'], # year don't use two digits year, they cause confusion [/y{1,2}/, '%y']
|
48
47
|
[/M{5}/, months[:narrow][object.month.to_s]], [/M{4}/, months[:wide][object.month.to_s]], #month
|
@@ -116,9 +115,9 @@ module Spider; module I18n
|
|
116
115
|
end
|
117
116
|
end
|
118
117
|
|
119
|
-
def day_names(format = :wide,
|
118
|
+
def day_names(format = :wide, calendar = self.default_calendar)
|
120
119
|
begin
|
121
|
-
days = @cldr.calendar.days[calendar][format]
|
120
|
+
days = @cldr.calendar.days[calendar][format]
|
122
121
|
return [days['sun'], days['mon'], days['tue'], days['wed'], days['thu'], days['fri'], days['sat']]
|
123
122
|
rescue NoMethodError
|
124
123
|
raise ArgumentError, "Calendar #{calendar} not found" unless @cldr.days[calendar]
|
@@ -127,12 +126,10 @@ module Spider; module I18n
|
|
127
126
|
|
128
127
|
end
|
129
128
|
|
130
|
-
def month_names(format = :wide,
|
129
|
+
def month_names(format = :wide, calendar = self.default_calendar)
|
131
130
|
months = []
|
132
131
|
begin
|
133
|
-
|
134
|
-
months = @cldr.calendar.months[calendar][format] || @cldr.calendar.months[calendar][context][format]
|
135
|
-
months.each do |k, v|
|
132
|
+
@cldr.calendar.months[calendar][format].each do |k, v|
|
136
133
|
months[k.to_i] = v
|
137
134
|
end
|
138
135
|
rescue NoMethodError
|