summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-10-18 17:30:49 -0600
committermo khan <mo@mokhan.ca>2015-10-18 17:30:49 -0600
commit5fbea49f99605e79a63bad0ab8800c0766424e3e (patch)
treea5652be3a4f57db9c018774528a2edf057deabe6
parenta6933053f397c476ad209aefe8a320cfa0a1e6a2 (diff)
update ping to publish a new message and sanitize html.
-rw-r--r--lib/killjoy/web.rb19
-rw-r--r--lib/killjoy/web/views/index.erb6
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/killjoy/web.rb b/lib/killjoy/web.rb
index d8b2ab0..da16a35 100644
--- a/lib/killjoy/web.rb
+++ b/lib/killjoy/web.rb
@@ -1,5 +1,11 @@
-require 'sinatra'
require 'killjoy'
+require 'sinatra'
+
+helpers do
+ def h(text)
+ Rack::Utils.escape_html(text)
+ end
+end
set :bind, '0.0.0.0'
set :port, 9292
@@ -26,5 +32,16 @@ get '/ip/:ipaddress' do
end
get '/ping' do
+ message = Killjoy::LogLine.new(
+ http_status: 200,
+ http_verb: request["REQUEST_METHOD"],
+ http_version: request["SERVER_PROTOCOL"],
+ ipaddress: request["REMOTE_HOST"],
+ timestamp: DateTime.now.to_time.to_i,
+ url: request["PATH_INFO"],
+ user_agent: request["HTTP_USER_AGENT"],
+ )
+ Killjoy::Publisher.new.publish(message)
+
"Hello World!"
end
diff --git a/lib/killjoy/web/views/index.erb b/lib/killjoy/web/views/index.erb
index 3561cf6..17e2e8b 100644
--- a/lib/killjoy/web/views/index.erb
+++ b/lib/killjoy/web/views/index.erb
@@ -17,10 +17,10 @@
<td><a href="/ip/<%= log.ipaddress %>"><%= log.ipaddress %></a></td>
<td><%= log.http_status %></td>
<td><%= log.http_verb %></td>
- <td><%= log.url %></td>
- <td><%= log.http_version %></td>
+ <td><%= h log.url %></td>
+ <td><%= h log.http_version %></td>
<td><%= log.timestamp %></td>
- <td><%= log.user_agent %></td>
+ <td><%= h log.user_agent %></td>
</tr>
<% end %>
</tbody>