hayabusa 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/check_running.rb +69 -0
- data/bin/hayabusa_benchmark.rb +82 -0
- data/bin/hayabusa_cgi.rb +84 -0
- data/bin/hayabusa_fcgi.fcgi +159 -0
- data/bin/hayabusa_fcgi.rb +159 -0
- data/bin/knjappserver_start.rb +42 -0
- data/conf/apache2_cgi_rhtml_conf.conf +10 -0
- data/conf/apache2_fcgi_rhtml_conf.conf +22 -0
- data/hayabusa.gemspec +151 -0
- data/lib/hayabusa.rb +518 -0
- data/lib/hayabusa_cgi_session.rb +128 -0
- data/lib/hayabusa_cgi_tools.rb +102 -0
- data/lib/hayabusa_custom_io.rb +22 -0
- data/lib/hayabusa_database.rb +125 -0
- data/lib/hayabusa_erb_handler.rb +27 -0
- data/lib/hayabusa_ext/cleaner.rb +140 -0
- data/lib/hayabusa_ext/cmdline.rb +52 -0
- data/lib/hayabusa_ext/errors.rb +135 -0
- data/lib/hayabusa_ext/logging.rb +404 -0
- data/lib/hayabusa_ext/mailing.rb +158 -0
- data/lib/hayabusa_ext/sessions.rb +71 -0
- data/lib/hayabusa_ext/threadding.rb +96 -0
- data/lib/hayabusa_ext/threadding_timeout.rb +101 -0
- data/lib/hayabusa_ext/translations.rb +43 -0
- data/lib/hayabusa_ext/web.rb +190 -0
- data/lib/hayabusa_http_server.rb +102 -0
- data/lib/hayabusa_http_session.rb +361 -0
- data/lib/hayabusa_http_session_contentgroup.rb +176 -0
- data/lib/hayabusa_http_session_page_environment.rb +66 -0
- data/lib/hayabusa_http_session_post_multipart.rb +135 -0
- data/lib/hayabusa_http_session_request.rb +219 -0
- data/lib/hayabusa_http_session_response.rb +144 -0
- data/lib/hayabusa_models.rb +8 -0
- data/lib/kernel_ext/gettext_methods.rb +22 -0
- data/lib/kernel_ext/magic_methods.rb +61 -0
- data/lib/models/log.rb +130 -0
- data/lib/models/log_access.rb +88 -0
- data/lib/models/log_data.rb +27 -0
- data/lib/models/log_data_link.rb +3 -0
- data/lib/models/log_data_value.rb +21 -0
- data/lib/models/log_link.rb +65 -0
- data/lib/models/session.rb +35 -0
- data/pages/benchmark.rhtml +0 -0
- data/pages/benchmark_print.rhtml +14 -0
- data/pages/benchmark_simple.rhtml +3 -0
- data/pages/benchmark_threadded_content.rhtml +21 -0
- data/pages/debug_database_connections.rhtml +46 -0
- data/pages/debug_http_sessions.rhtml +40 -0
- data/pages/debug_memory_usage.rhtml +16 -0
- data/pages/error_notfound.rhtml +12 -0
- data/pages/logs_latest.rhtml +57 -0
- data/pages/logs_show.rhtml +32 -0
- data/pages/spec.rhtml +41 -0
- data/pages/spec_post.rhtml +3 -0
- data/pages/spec_test_multiple_clients.rhtml +3 -0
- data/pages/spec_thread_joins.rhtml +21 -0
- data/pages/spec_threadded_content.rhtml +40 -0
- data/pages/tests.rhtml +14 -0
- data/spec/cgi_spec.rb +47 -0
- data/spec/custom_urls_spec.rb +35 -0
- data/spec/fcgi_multiple_processes_spec.rb +32 -0
- data/spec/fcgi_spec.rb +69 -0
- data/spec/hayabusa_spec.rb +194 -0
- data/spec/spec_helper.rb +12 -0
- data/tests/cgi_test/config_cgi.rb +6 -0
- data/tests/cgi_test/threadded_content_test.rhtml +23 -0
- data/tests/cgi_test/vars_get_test.rhtml +4 -0
- data/tests/cgi_test/vars_header_test.rhtml +3 -0
- data/tests/cgi_test/vars_post_test.rhtml +4 -0
- data/tests/fcgi_test/config_fcgi.rb +6 -0
- data/tests/fcgi_test/index.rhtml +3 -0
- data/tests/fcgi_test/sleeper.rhtml +4 -0
- data/tests/fcgi_test/threadded_content_test.rhtml +23 -0
- data/tests/fcgi_test/vars_get_test.rhtml +4 -0
- data/tests/fcgi_test/vars_header_test.rhtml +3 -0
- data/tests/fcgi_test/vars_post_test.rhtml +4 -0
- metadata +257 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
class Hayabusa::Models::Log_data < Knj::Datarow
|
2
|
+
def self.force(d, id_hash)
|
3
|
+
data_obj = d.ob.get_by(:Log_data, {"id_hash" => id_hash})
|
4
|
+
|
5
|
+
if !data_obj
|
6
|
+
data_obj = d.ob.add(:Log_data, {"id_hash" => id_hash})
|
7
|
+
end
|
8
|
+
|
9
|
+
return data_obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.force_id(d, id_hash)
|
13
|
+
data = d.db.query("SELECT * FROM Log_data WHERE id_hash = '#{d.db.esc(id_hash)}' LIMIT 1").fetch
|
14
|
+
return data[:id].to_i if data
|
15
|
+
return d.db.insert(:Log_data, {:id_hash => id_hash}, {:return_id => true}).to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.by_id_hash(d, id_hash)
|
19
|
+
data = d.db.query("SELECT * FROM Log_data WHERE id_hash = '#{d.db.esc(id_hash)}' LIMIT 1").fetch
|
20
|
+
return data[:id].to_i if data
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
|
24
|
+
def links(args = {})
|
25
|
+
return ob.list(:Log_data_link, {"data" => self}.merge(args))
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Hayabusa::Models::Log_data_value < Knj::Datarow
|
2
|
+
def self.force(d, value)
|
3
|
+
value_obj = d.ob.get_by(:Log_data_value, {
|
4
|
+
"value" => value.to_s
|
5
|
+
})
|
6
|
+
|
7
|
+
if !value_obj
|
8
|
+
value_obj = d.ob.add(:Log_data_value, {"value" => value})
|
9
|
+
end
|
10
|
+
|
11
|
+
return value_obj
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.force_id(d, value)
|
15
|
+
d.db.select(:Log_data_value, {"value" => value}) do |d_val|
|
16
|
+
return d_val[:id].to_i if d_val[:value].to_s == value.to_s #MySQL doesnt take upper/lower-case into consideration because value is a text-column... lame! - knj
|
17
|
+
end
|
18
|
+
|
19
|
+
return d.db.insert(:Log_data_value, {:value => value}, {:return_id => true}).to_i
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Hayabusa::Models::Log_link < Knj::Datarow
|
2
|
+
has_one [
|
3
|
+
{:class => :Log, :col => :log_id, :method => :log}
|
4
|
+
]
|
5
|
+
|
6
|
+
def self.list(d, &block)
|
7
|
+
if d.args["count"]
|
8
|
+
sql = "SELECT COUNT(id) AS count FROM #{table} WHERE 1=1"
|
9
|
+
count = true
|
10
|
+
d.args.delete("count")
|
11
|
+
else
|
12
|
+
sql = "SELECT * FROM #{table} WHERE 1=1"
|
13
|
+
end
|
14
|
+
|
15
|
+
q_args = nil
|
16
|
+
ret = self.list_helper(d)
|
17
|
+
sql << ret[:sql_joins]
|
18
|
+
|
19
|
+
d.args.each do |key, val|
|
20
|
+
case key
|
21
|
+
when "object_class"
|
22
|
+
data_val = d.db.single(:Log_data_value, {"value" => val})
|
23
|
+
return [] if !data_val #if this data-value cannot be found, nothing has been logged for the object. So just return empty array here and skip the rest.
|
24
|
+
sql << " AND object_class_value_id = '#{d.db.esc(data_val[:id])}'"
|
25
|
+
when :cloned_ubuf
|
26
|
+
q_args = {:cloned_ubuf => true}
|
27
|
+
else
|
28
|
+
raise "Invalid key: #{key}."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
sql << ret[:sql_where]
|
33
|
+
|
34
|
+
return d.db.query(sql).fetch[:count].to_i if count
|
35
|
+
|
36
|
+
sql << ret[:sql_order]
|
37
|
+
sql << ret[:sql_limit]
|
38
|
+
|
39
|
+
return d.ob.list_bysql(:Log_link, sql, q_args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.add(d)
|
43
|
+
if d.data.has_key?(:object)
|
44
|
+
class_data_id = d.ob.static(:Log_data_value, :force, d.data[:object].class.name)
|
45
|
+
d.data[:object_class_value_id] = class_data_id.id
|
46
|
+
d.data[:object_id] = d.data[:object].id
|
47
|
+
d.data.delete(:object)
|
48
|
+
end
|
49
|
+
|
50
|
+
log = d.ob.get(:Log, d.data[:log_id]) #throws exception if it doesnt exist.
|
51
|
+
end
|
52
|
+
|
53
|
+
def object(ob_use)
|
54
|
+
begin
|
55
|
+
class_name = ob.get(:Log_data_value, self[:object_class_value_id])[:value].split("::").last
|
56
|
+
return ob_use.get(class_name, self[:object_id])
|
57
|
+
rescue Errno::ENOENT
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def object_class
|
63
|
+
return ob.get(:Log_data_value, self[:object_class_value_id])[:value]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Hayabusa::Models::Session < Knj::Datarow
|
2
|
+
attr_reader :edata
|
3
|
+
attr_accessor :sess_data
|
4
|
+
|
5
|
+
def initialize(*args, &block)
|
6
|
+
@edata = {}
|
7
|
+
super(*args, &block)
|
8
|
+
|
9
|
+
if self[:sess_data].to_s.length > 0
|
10
|
+
begin
|
11
|
+
@sess_data = Marshal.load(Base64.decode64(self[:sess_data]))
|
12
|
+
rescue ArgumentError
|
13
|
+
@sess_data = {}
|
14
|
+
end
|
15
|
+
else
|
16
|
+
@sess_data = {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add(d)
|
21
|
+
d.data[:date_added] = Time.now if !d.data[:date_added]
|
22
|
+
d.data[:date_lastused] = Time.now if !d.data[:date_lastused]
|
23
|
+
end
|
24
|
+
|
25
|
+
def flush
|
26
|
+
flush_data = Base64.encode64(Marshal.dump(@sess_data))
|
27
|
+
|
28
|
+
if self[:sess_data] != flush_data
|
29
|
+
self.update(
|
30
|
+
:sess_data => flush_data,
|
31
|
+
:date_lastused => Time.now
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%
|
2
|
+
0.upto(100) do
|
3
|
+
print "Test 1<br />\n"
|
4
|
+
print "Test 2<br />\n"
|
5
|
+
print "Test 3<br />\n"
|
6
|
+
print "Test 4<br />\n"
|
7
|
+
print "Test 5<br />\n"
|
8
|
+
print "Test 6<br />\n"
|
9
|
+
print "Test 7<br />\n"
|
10
|
+
print "Test 8<br />\n"
|
11
|
+
print "Test 9<br />\n"
|
12
|
+
print "Test 10<br />\n"
|
13
|
+
end
|
14
|
+
%>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<h1>Database connections</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Key</th>
|
7
|
+
<th>Free</th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<%
|
12
|
+
thread_handler = _hb.db_handler.conns
|
13
|
+
if !thread_handler.is_a?(Knj::Threadhandler)
|
14
|
+
print "A threadhandler has not been spawned for this instance."
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
objects = thread_handler.objects.clone
|
19
|
+
|
20
|
+
objects.each_index do |key|
|
21
|
+
val = objects[key]
|
22
|
+
|
23
|
+
%>
|
24
|
+
<tr>
|
25
|
+
<td>
|
26
|
+
<%=key%>
|
27
|
+
</td>
|
28
|
+
<td>
|
29
|
+
<%=Knj::Strings.yn_str(val[:free])%>
|
30
|
+
</td>
|
31
|
+
</tr>
|
32
|
+
<%
|
33
|
+
end
|
34
|
+
|
35
|
+
if objects.empty?
|
36
|
+
%>
|
37
|
+
<tr>
|
38
|
+
<td colspan="2">
|
39
|
+
Thread handler was spawned but no active connections was spawned?
|
40
|
+
</td>
|
41
|
+
</tr>
|
42
|
+
<%
|
43
|
+
end
|
44
|
+
%>
|
45
|
+
</tbody>
|
46
|
+
</table>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<h1>HTTP sessions</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Key</th>
|
7
|
+
<th>Working</th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<%
|
12
|
+
sessions = _hb.httpserv.http_sessions.clone
|
13
|
+
|
14
|
+
sessions.each_index do |key|
|
15
|
+
http_session = sessions[key]
|
16
|
+
|
17
|
+
%>
|
18
|
+
<tr>
|
19
|
+
<td>
|
20
|
+
<%=key%>
|
21
|
+
</td>
|
22
|
+
<td>
|
23
|
+
<%=Knj::Strings.yn_str(http_session.working)%>
|
24
|
+
</td>
|
25
|
+
</tr>
|
26
|
+
<%
|
27
|
+
end
|
28
|
+
|
29
|
+
if sessions.empty?
|
30
|
+
%>
|
31
|
+
<tr>
|
32
|
+
<td colspan="2">
|
33
|
+
No HTTP-sessions has been spawned.
|
34
|
+
</td>
|
35
|
+
</tr>
|
36
|
+
<%
|
37
|
+
end
|
38
|
+
%>
|
39
|
+
</tbody>
|
40
|
+
</table>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%
|
2
|
+
if _get["choice"] == "dogarbagecollect"
|
3
|
+
GC.start
|
4
|
+
_hb.redirect("?show=debug_memory_usage")
|
5
|
+
end
|
6
|
+
%>
|
7
|
+
|
8
|
+
<h1>Memory usage</h1>
|
9
|
+
|
10
|
+
<div style="padding-bottom: 15px;">
|
11
|
+
<input type="button" value="Garbage collect" onclick="location.href='?show=debug_memory_usage&choice=dogarbagecollect';" />
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<%
|
15
|
+
Knj::Memory_analyzer.new.write
|
16
|
+
%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%
|
2
|
+
_httpsession.resp.status = 404
|
3
|
+
%>
|
4
|
+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
5
|
+
<html><head>
|
6
|
+
<title>404 Not Found</title>
|
7
|
+
</head><body>
|
8
|
+
<h1>Not Found</h1>
|
9
|
+
<p>The requested URL <%=_meta["REQUEST_URI"]%> was not found on this server.</p>
|
10
|
+
<hr>
|
11
|
+
<address>Hayabusa at <%=_meta["HTTP_HOST"]%></address>
|
12
|
+
</body></html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<%
|
2
|
+
access = _hb.events.call(:check_page_access, {:page => :logs_latest})
|
3
|
+
if !access
|
4
|
+
print _("You do not have access to this page.")
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
ob = _hb.events.call(:ob)
|
9
|
+
%>
|
10
|
+
|
11
|
+
<table class="list">
|
12
|
+
<thead>
|
13
|
+
<tr>
|
14
|
+
<th><%=_("ID")%></th>
|
15
|
+
<th><%=_("Log")%></th>
|
16
|
+
<%if ob%>
|
17
|
+
<th><%=_("Object")%></th>
|
18
|
+
<%end%>
|
19
|
+
</tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<%
|
23
|
+
logs = _hb.ob.list(:Log, {
|
24
|
+
"orderby" => [["date_saved", "desc"]],
|
25
|
+
"limit" => 200
|
26
|
+
})
|
27
|
+
|
28
|
+
logs.each do |log|
|
29
|
+
%>
|
30
|
+
<tr>
|
31
|
+
<td>
|
32
|
+
<a href="logs_show.rhtml?log_id=<%=log.id%>"><%=log.id%></a>
|
33
|
+
</td>
|
34
|
+
<td>
|
35
|
+
<%=log.first_line%>
|
36
|
+
</td>
|
37
|
+
<%if ob%>
|
38
|
+
<td>
|
39
|
+
<%=log.objects_html(ob)%>
|
40
|
+
</td>
|
41
|
+
<%end%>
|
42
|
+
</tr>
|
43
|
+
<%
|
44
|
+
end
|
45
|
+
|
46
|
+
if logs.empty?
|
47
|
+
%>
|
48
|
+
<tr>
|
49
|
+
<td class="error">
|
50
|
+
<%=_("No logs were found.")%>
|
51
|
+
</td>
|
52
|
+
</tr>
|
53
|
+
<%
|
54
|
+
end
|
55
|
+
%>
|
56
|
+
</tbody>
|
57
|
+
</table>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%
|
2
|
+
access = _hb.events.call(:check_page_access, {:page => :logs_show})
|
3
|
+
if !access
|
4
|
+
print _("You do not have access to this page.")
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
ob = _hb.events.call(:ob)
|
9
|
+
log = _hb.ob.get(:Log, _get["log_id"])
|
10
|
+
%>
|
11
|
+
|
12
|
+
<table class="form">
|
13
|
+
<%
|
14
|
+
print Knj::Web.inputs([{
|
15
|
+
:title => _("Date"),
|
16
|
+
:type => :info,
|
17
|
+
:value => Datet.in(log[:date_saved]).out
|
18
|
+
}])
|
19
|
+
|
20
|
+
if ob
|
21
|
+
print Knj::Web.input(
|
22
|
+
:title => _("Objects"),
|
23
|
+
:type => :info,
|
24
|
+
:value => log.objects_html(ob)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
%>
|
28
|
+
</table>
|
29
|
+
|
30
|
+
<div style="padding-top: 10px;">
|
31
|
+
<%=log.text%>
|
32
|
+
</div>
|
data/pages/spec.rhtml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
<%
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
if _get["choice"] == "test_cookie"
|
5
|
+
_hb.cookie(
|
6
|
+
"name" => "TestCookie",
|
7
|
+
"value" => "TestValue",
|
8
|
+
"expires" => Time.new + 3600 #add an hour
|
9
|
+
)
|
10
|
+
_hb.cookie(
|
11
|
+
"name" => "TestCookie2",
|
12
|
+
"value" => "TestValue2",
|
13
|
+
"expires" => Time.new + 7200 #add an hour
|
14
|
+
)
|
15
|
+
_hb.cookie(
|
16
|
+
"name" => "TestCookie3",
|
17
|
+
"value" => "TestValue 3 ",
|
18
|
+
"expires" => Time.new + 1200
|
19
|
+
)
|
20
|
+
exit
|
21
|
+
elsif _get["choice"] == "dopostconvert"
|
22
|
+
print JSON.generate(_post)
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
if _get["choice"] == "get_cookies"
|
27
|
+
print JSON.generate(_cookie)
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
_hb.header("TestHeader", "NormalHeader")
|
32
|
+
_hb.header_raw("TestRaw: RawHeader")
|
33
|
+
|
34
|
+
if _meta["REQUEST_METHOD"] == "POST"
|
35
|
+
print _post["postdata"]
|
36
|
+
elsif _get["choice"] == "check_get_parse"
|
37
|
+
print _get["value"]
|
38
|
+
else
|
39
|
+
print "Test"
|
40
|
+
end
|
41
|
+
%>
|