forked from nestorInc/jukebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_debug.rb
47 lines (44 loc) · 1.58 KB
/
web_debug.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'http.rb'
class DebugPage < HttpNode
def on_request(s, req)
obj_kind = {}
GC.start
ObjectSpace.each_object { |obj|
obj_kind[obj.class] = [] if(obj_kind[obj.class] == nil)
obj_kind[obj.class].push(obj);
}
rep = HttpResponse.new(req.proto, 200, "OK");
page = "<html><head><title>status</title></head><body>";
if(obj_kind[Connection])
page << "<table>";
page << "<tr><th>Peer</th><th>SSL</th><th>User</th><th>Song</th><th>Sock out queue</th><tr>";
obj_kind[Connection].each { |c|
meta = c.ch.meta();
page << "<tr>"
page << "<td>#{c.socket.remote_address.inspect_sockaddr}</td>"
page << "<td>#{c.socket.ssl == true}</td>"
page << "<td>#{c.socket.user}</td>"
page << "<td>#{meta.title.gsub("\'", " ")} - #{meta.artist.gsub("\'", " ")} - #{meta.album.gsub("\'", " ")}</td>"
page << "<td>#{c.socket.output_buffer_size}</td>"
page << "<tr>";
}
end
if(obj_kind[EncodingThread])
page << "<table>";
page << "<tr><th>PID</th><th>File</th><th>Song</th><th>Bitrate</th></tr>";
obj_kind[EncodingThread].each { |e|
page << "<tr>"
page << "<td>#{e.pid}</td>"
page << "<td>#{e.file[1]}</td>"
page << "<td>#{meta.title.gsub("\'", " ")} - #{meta.artist.gsub("\'", " ")} - #{meta.album.gsub("\'", " ")}</td>"
page << "<td>#{e.file}</td>"
page << "<td>#{e.bitrate}</td>"
page << "<tr>";
}
page << "</table>";
end
page << "</body></head>";
rep.setData(page);
s.write(rep.to_s);
end
end