knjappserver 0.0.26 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,6 +7,8 @@ gem "knjrbfw"
7
7
  gem "erubis"
8
8
  gem "mail"
9
9
  gem "tsafe"
10
+ gem "datet"
11
+ gem "http2"
10
12
 
11
13
  # Add dependencies to develop your gem here.
12
14
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,9 +1,12 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ datet (0.0.0)
4
5
  diff-lcs (1.1.3)
5
6
  erubis (2.7.0)
6
7
  git (1.2.5)
8
+ http2 (0.0.0)
9
+ knjrbfw
7
10
  i18n (0.6.0)
8
11
  jeweler (1.6.4)
9
12
  bundler (~> 1.0)
@@ -40,7 +43,9 @@ PLATFORMS
40
43
 
41
44
  DEPENDENCIES
42
45
  bundler (>= 1.0.0)
46
+ datet
43
47
  erubis
48
+ http2
44
49
  jeweler (~> 1.6.3)
45
50
  json
46
51
  knjrbfw
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.26
1
+ 0.0.28
data/knjappserver.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjappserver}
8
- s.version = "0.0.26"
8
+ s.version = "0.0.28"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-07-04}
12
+ s.date = %q{2012-07-14}
13
13
  s.description = %q{Which supports a lot of undocumented stuff.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.executables = ["check_running.rb", "knjappserver_start.rb"]
@@ -104,6 +104,8 @@ Gem::Specification.new do |s|
104
104
  s.add_runtime_dependency(%q<erubis>, [">= 0"])
105
105
  s.add_runtime_dependency(%q<mail>, [">= 0"])
106
106
  s.add_runtime_dependency(%q<tsafe>, [">= 0"])
107
+ s.add_runtime_dependency(%q<datet>, [">= 0"])
108
+ s.add_runtime_dependency(%q<http2>, [">= 0"])
107
109
  s.add_development_dependency(%q<json>, [">= 0"])
108
110
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
109
111
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
@@ -114,6 +116,8 @@ Gem::Specification.new do |s|
114
116
  s.add_dependency(%q<erubis>, [">= 0"])
115
117
  s.add_dependency(%q<mail>, [">= 0"])
116
118
  s.add_dependency(%q<tsafe>, [">= 0"])
119
+ s.add_dependency(%q<datet>, [">= 0"])
120
+ s.add_dependency(%q<http2>, [">= 0"])
117
121
  s.add_dependency(%q<json>, [">= 0"])
118
122
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
119
123
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -125,6 +129,8 @@ Gem::Specification.new do |s|
125
129
  s.add_dependency(%q<erubis>, [">= 0"])
126
130
  s.add_dependency(%q<mail>, [">= 0"])
127
131
  s.add_dependency(%q<tsafe>, [">= 0"])
132
+ s.add_dependency(%q<datet>, [">= 0"])
133
+ s.add_dependency(%q<http2>, [">= 0"])
128
134
  s.add_dependency(%q<json>, [">= 0"])
129
135
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
130
136
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -93,7 +93,7 @@ class Knjappserver
93
93
  {"name" => "idhash", "type" => "varchar"},
94
94
  {"name" => "sess_data", "type" => "text"},
95
95
  {"name" => "date_added", "type" => "datetime"},
96
- {"name" => "date_lastused", "type" => "datetime", "on_created" => proc{|d| d["db"].query("UPDATE Session SET date_lastused = '#{Knj::Datet.new.dbstr}'")}},
96
+ {"name" => "date_lastused", "type" => "datetime", "on_created" => proc{|d| d["db"].query("UPDATE Session SET date_lastused = '#{Datet.new.dbstr}'")}},
97
97
  {"name" => "ip", "type" => "varchar", "maxlength" => 15},
98
98
  {"name" => "user_agent", "type" => "text"},
99
99
  {"name" => "remember", "type" => "enum", "maxlength" => "'0','1'", "default" => 0, "comment" => "If the session should be remembered or not."}
@@ -11,8 +11,13 @@ class Knjappserver::CustomIO < StringIO
11
11
  end
12
12
  end
13
13
 
14
+ def puts(str)
15
+ res = self.print(str)
16
+ self.print "\n"
17
+ return res
18
+ end
19
+
14
20
  alias << print
15
21
  alias write print
16
22
  alias p print
17
- alias puts print
18
23
  end
@@ -261,7 +261,7 @@ class Knjappserver::Httpsession
261
261
 
262
262
  begin
263
263
  @session, @session_hash = @kas.session_fromid(@ip, @session_id, @meta)
264
- rescue Knj::Errors::InvalidData => e
264
+ rescue ArgumentError => e
265
265
  #User should not have the session he asked for because of invalid user-agent or invalid IP.
266
266
  @session_id = @kas.session_generate_id(@meta)
267
267
  @session, @session_hash = @kas.session_fromid(@ip, @session_id, @meta)
@@ -334,7 +334,7 @@ class Knjappserver::Httpsession
334
334
  @resp.header("Expires", (Time.now + 86400).httpdate) #next day.
335
335
 
336
336
  if !cache_dont and @headers["if-modified-since"] and @headers["if-modified-since"][0]
337
- request_mod = Knj::Datet.parse(@headers["if-modified-since"].first).time
337
+ request_mod = Datet.in(@headers["if-modified-since"].first).time
338
338
 
339
339
  if request_mod == lastmod
340
340
  @resp.status = 304
@@ -204,7 +204,7 @@ class Knjappserver::Httpsession::Http_request
204
204
  mod_match = @meta["HTTP_IF_MODIFIED_SINCE"].match(/^([A-z]+),\s+(\d+)\s+([A-z]+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(.+)$/)
205
205
  raise "Could not parse 'HTTP_IF_MODIFIED_SINCE'." if !mod_match
206
206
 
207
- month_no = Knj::Datet.month_str_to_no(mod_match[3])
207
+ month_no = Datet.month_str_to_no(mod_match[3])
208
208
  @modified_since = Time.utc(mod_match[4].to_i, month_no, mod_match[2].to_i, mod_match[5].to_i, mod_match[6].to_i, mod_match[7].to_i)
209
209
 
210
210
  return @modified_since
@@ -138,7 +138,7 @@ class Knjappserver
138
138
  require "base64"
139
139
  require "stringio"
140
140
  require "socket"
141
- require "tsafe"
141
+ require "tsafe" if !Kernel.const_defined?(:Tsafe)
142
142
 
143
143
  files += [
144
144
  "#{@path_knjrbfw}knj/event_handler.rb",
@@ -34,8 +34,8 @@ class Knjappserver
34
34
  if error_email[:messages].length == 1
35
35
  html = error_email[:messages].first
36
36
  else
37
- html = "<b>First time:</b> #{Knj::Datet.in(error_email[:first_time]).out}<br />"
38
- html << "<b>Last time:</b> #{Knj::Datet.in(error_email[:last_time]).out}<br />"
37
+ html = "<b>First time:</b> #{Datet.in(error_email[:first_time]).out}<br />"
38
+ html << "<b>Last time:</b> #{Datet.in(error_email[:last_time]).out}<br />"
39
39
  html << "<b>Number of errors:</b> #{error_email[:messages].length}<br />"
40
40
  count = 0
41
41
 
@@ -179,7 +179,7 @@ class Knjappserver
179
179
  begin
180
180
  keys_data_obj = @ob.get(:Log_data, keys_id)
181
181
  values_data_obj = @ob.get(:Log_data, values_id)
182
- rescue Knj::Errors::NotFound
182
+ rescue Errno::ENOENT
183
183
  return {}
184
184
  end
185
185
 
@@ -357,4 +357,42 @@ class Knjappserver
357
357
 
358
358
  return html
359
359
  end
360
+
361
+ #Removes all logs for objects that have been deleted.
362
+ #===Examples
363
+ #Remember to pass Knj::Objects-object handler to the method.
364
+ # appsrv.logs_delete_dead(:ob => ob, :debug => false)
365
+ def logs_delete_dead(args)
366
+ raise "No :ob-argument given." if !args[:ob]
367
+
368
+ @db.q_buffer do |db_buffer|
369
+ STDOUT.puts "Starting to look for dead log-links." if @debug or args[:debug]
370
+ @ob.list(:Log_link, :cloned_ubuf => true) do |log_link|
371
+ classname = log_link.object_class.to_s.split("::").last
372
+ obj_exists = args[:ob].exists?(classname, log_link[:object_id])
373
+ next if obj_exists
374
+
375
+ log = log_link.log
376
+
377
+ STDOUT.puts "Deleting log-link #{log_link.id} for #{classname}(#{log_link[:object_id]})." if @debug or args[:debug]
378
+ @ob.delete(log_link, :db_buffer => db_buffer)
379
+
380
+ links_count = log.links("count" => true)
381
+
382
+ if links_count <= 0
383
+ STDOUT.puts "Deleting log #{log.id} because it has no more links." if @debug or args[:debug]
384
+ @ob.delete(log, :db_buffer => db_buffer)
385
+ end
386
+ end
387
+
388
+ STDOUT.puts "Starting to look for logs with no links." if @debug or args[:debug]
389
+ @ob.list(:Log, {
390
+ [:Log_link, "id"] => {:type => :sqlval, :val => :null},
391
+ :cloned_ubuf => true
392
+ }) do |log|
393
+ STDOUT.puts "Deleting log #{log.id} because it has no links: '#{log.text}'." if @debug or args[:debug]
394
+ @ob.delete(log, :db_buffer => db_buffer)
395
+ end
396
+ end
397
+ end
360
398
  end
@@ -1,6 +1,6 @@
1
1
  class Knjappserver
2
2
  def initialize_sessions
3
- require "tsafe"
3
+ require "tsafe" if !Kernel.const_defined?(:Tsafe)
4
4
  @sessions = Tsafe::MonHash.new
5
5
  end
6
6
 
@@ -29,7 +29,7 @@ class Knjappserver
29
29
  end
30
30
 
31
31
  if ip != "bot" and !session.remember? and ip.to_s != session[:ip].to_s
32
- raise Knj::Errors::InvalidData, "Invalid IP."
32
+ raise ArgumentError, "Invalid IP."
33
33
  end
34
34
 
35
35
  @sessions[idhash][:time_lastused] = Time.now
@@ -2,7 +2,7 @@ class Knjappserver
2
2
  #Imports a .rhtml-file and executes it.
3
3
  def import(filepath)
4
4
  if filepath.to_s.index("../proc/self") != nil
5
- raise Knj::Errors::NoAccess, "Possible attempt to hack the appserver."
5
+ raise Errno::EACCES, "Possible attempt to hack the appserver."
6
6
  end
7
7
 
8
8
  _httpsession.eruby.import(filepath)
@@ -18,10 +18,13 @@ class Knjappserver::Log < Knj::Datarow
18
18
  "
19
19
  end
20
20
 
21
+ q_args = nil
21
22
  return_sql = false
23
+ ret = self.list_helper(d)
24
+
25
+ sql << ret[:sql_joins]
22
26
  sql << " WHERE 1=1"
23
27
 
24
- ret = list_helper(d)
25
28
  d.args.each do |key, val|
26
29
  case key
27
30
  when "object_lookup"
@@ -35,6 +38,8 @@ class Knjappserver::Log < Knj::Datarow
35
38
  else
36
39
  sql << " AND Log.tag_data_id = '#{d.db.esc(data_val.id)}'"
37
40
  end
41
+ when :cloned_ubuf
42
+ q_args = {:cloned_ubuf => true}
38
43
  else
39
44
  raise "Invalid key: #{key}."
40
45
  end
@@ -46,7 +51,7 @@ class Knjappserver::Log < Knj::Datarow
46
51
 
47
52
  return sql if return_sql
48
53
 
49
- return d.ob.list_bysql(:Log, sql, &block)
54
+ return d.ob.list_bysql(:Log, sql, q_args, &block)
50
55
  end
51
56
 
52
57
  def self.add(d)
@@ -11,14 +11,19 @@ class Knjappserver::Log_link < Knj::Datarow
11
11
  else
12
12
  sql = "SELECT * FROM #{table} WHERE 1=1"
13
13
  end
14
-
14
+
15
+ q_args = nil
15
16
  ret = self.list_helper(d)
17
+ sql << ret[:sql_joins]
18
+
16
19
  d.args.each do |key, val|
17
20
  case key
18
21
  when "object_class"
19
22
  data_val = d.db.single(:Log_data_value, {"value" => val})
20
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.
21
24
  sql << " AND object_class_value_id = '#{d.db.esc(data_val[:id])}'"
25
+ when :cloned_ubuf
26
+ q_args = {:cloned_ubuf => true}
22
27
  else
23
28
  raise "Invalid key: #{key}."
24
29
  end
@@ -31,7 +36,7 @@ class Knjappserver::Log_link < Knj::Datarow
31
36
  sql << ret[:sql_order]
32
37
  sql << ret[:sql_limit]
33
38
 
34
- return d.ob.list_bysql(:Log_link, sql, &block)
39
+ return d.ob.list_bysql(:Log_link, sql, q_args, &block)
35
40
  end
36
41
 
37
42
  def self.add(d)
@@ -49,7 +54,7 @@ class Knjappserver::Log_link < Knj::Datarow
49
54
  begin
50
55
  class_name = ob.get(:Log_data_value, self[:object_class_value_id])[:value].split("::").last
51
56
  return ob_use.get(class_name, self[:object_id])
52
- rescue Knj::Errors::NotFound
57
+ rescue Errno::ENOENT
53
58
  return false
54
59
  end
55
60
  end
@@ -14,7 +14,7 @@
14
14
  print Knj::Web.inputs([{
15
15
  :title => _("Date"),
16
16
  :type => :info,
17
- :value => Knj::Datet.in(log[:date_saved]).out
17
+ :value => Datet.in(log[:date_saved]).out
18
18
  }])
19
19
 
20
20
  if ob
@@ -57,7 +57,7 @@ count_requests = 0
57
57
  Knj::Thread.new(count_thread) do |count_thread|
58
58
  print "Thread #{count_thread} started.\n"
59
59
 
60
- http = Knj::Http2.new(
60
+ http = Http2.new(
61
61
  :host => "localhost",
62
62
  :port => 15081,
63
63
  :user_agent => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1; debugid:#{count_thread}) Gecko/20060111 Firefox/3.6.0.1",
@@ -65,7 +65,7 @@ count_requests = 0
65
65
  )
66
66
 
67
67
  loop do
68
- resp = http.get(args[:filename])
68
+ resp = http.get(:url => args[:filename])
69
69
  count_requests += 1
70
70
  raise "Invalid code: #{resp.code}\n" if resp.code.to_i != 200
71
71
  end
@@ -71,7 +71,7 @@ begin
71
71
  port = knjappserver.port
72
72
 
73
73
  #Make request.
74
- http = Knj::Http2.new(:host => "localhost", :port => port)
74
+ http = Http2.new(:host => "localhost", :port => port)
75
75
 
76
76
  #Spawn CGI-variable to emulate FCGI part.
77
77
  cgi = Cgi_is_retarded.new
@@ -102,7 +102,7 @@ begin
102
102
 
103
103
  if cgi.request_method == "POST" and cgi.content_type.to_s.downcase.index("multipart/form-data") != nil
104
104
  count = 0
105
- http.post_multipart(url, Knjappserver.convert_fcgi_post(cgi.params), {
105
+ http.post_multipart(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
106
106
  :default_headers => headers,
107
107
  :cookies => false,
108
108
  :on_content => proc{|line|
@@ -112,7 +112,7 @@ begin
112
112
  })
113
113
  elsif cgi.request_method == "POST"
114
114
  count = 0
115
- http.post(url, Knjappserver.convert_fcgi_post(cgi.params), {
115
+ http.post(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
116
116
  :default_headers => headers,
117
117
  :cookies => false,
118
118
  :on_content => proc{|line|
@@ -34,7 +34,7 @@ class Knjappserver
34
34
  knjappserver.start
35
35
 
36
36
  port = knjappserver.port
37
- http = Knj::Http2.new(:host => "localhost", :port => port)
37
+ http = Http2.new(:host => "localhost", :port => port)
38
38
 
39
39
  return [knjappserver, http]
40
40
  end
@@ -94,7 +94,7 @@ FCGI.each_cgi do |cgi|
94
94
 
95
95
  if cgi.request_method == "POST" and cgi.content_type.to_s.downcase.index("multipart/form-data") != nil
96
96
  count = 0
97
- http.post_multipart(url, Knjappserver.convert_fcgi_post(cgi.params), {
97
+ http.post_multipart(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
98
98
  :default_headers => headers,
99
99
  :cookies => false,
100
100
  :on_content => proc{|line|
@@ -104,7 +104,7 @@ FCGI.each_cgi do |cgi|
104
104
  })
105
105
  elsif cgi.request_method == "POST"
106
106
  count = 0
107
- http.post(url, Knjappserver.convert_fcgi_post(cgi.params), {
107
+ http.post(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
108
108
  :default_headers => headers,
109
109
  :cookies => false,
110
110
  :on_content => proc{|line|
@@ -114,7 +114,7 @@ FCGI.each_cgi do |cgi|
114
114
  })
115
115
  else
116
116
  count = 0
117
- http.get(url, {
117
+ http.get(:url => url,
118
118
  :default_headers => headers,
119
119
  :cookies => false,
120
120
  :on_content => proc{|line|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjappserver
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.26
5
+ version: 0.0.28
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-04 00:00:00 +02:00
13
+ date: 2012-07-14 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -58,19 +58,41 @@ dependencies:
58
58
  prerelease: false
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: json
61
+ name: datet
62
62
  requirement: &id005 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: "0"
68
- type: :development
68
+ type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: rspec
72
+ name: http2
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: json
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: rspec
95
+ requirement: &id008 !ruby/object:Gem::Requirement
74
96
  none: false
75
97
  requirements:
76
98
  - - ~>
@@ -78,10 +100,10 @@ dependencies:
78
100
  version: 2.3.0
79
101
  type: :development
80
102
  prerelease: false
81
- version_requirements: *id006
103
+ version_requirements: *id008
82
104
  - !ruby/object:Gem::Dependency
83
105
  name: bundler
84
- requirement: &id007 !ruby/object:Gem::Requirement
106
+ requirement: &id009 !ruby/object:Gem::Requirement
85
107
  none: false
86
108
  requirements:
87
109
  - - ">="
@@ -89,10 +111,10 @@ dependencies:
89
111
  version: 1.0.0
90
112
  type: :development
91
113
  prerelease: false
92
- version_requirements: *id007
114
+ version_requirements: *id009
93
115
  - !ruby/object:Gem::Dependency
94
116
  name: jeweler
95
- requirement: &id008 !ruby/object:Gem::Requirement
117
+ requirement: &id010 !ruby/object:Gem::Requirement
96
118
  none: false
97
119
  requirements:
98
120
  - - ~>
@@ -100,10 +122,10 @@ dependencies:
100
122
  version: 1.6.3
101
123
  type: :development
102
124
  prerelease: false
103
- version_requirements: *id008
125
+ version_requirements: *id010
104
126
  - !ruby/object:Gem::Dependency
105
127
  name: sqlite3
106
- requirement: &id009 !ruby/object:Gem::Requirement
128
+ requirement: &id011 !ruby/object:Gem::Requirement
107
129
  none: false
108
130
  requirements:
109
131
  - - ">="
@@ -111,7 +133,7 @@ dependencies:
111
133
  version: "0"
112
134
  type: :development
113
135
  prerelease: false
114
- version_requirements: *id009
136
+ version_requirements: *id011
115
137
  description: Which supports a lot of undocumented stuff.
116
138
  email: k@spernj.org
117
139
  executables:
@@ -208,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
230
  requirements:
209
231
  - - ">="
210
232
  - !ruby/object:Gem::Version
211
- hash: -3766508252438613801
233
+ hash: -3350207244681983238
212
234
  segments:
213
235
  - 0
214
236
  version: "0"