Class: Arachni::UI::Web::OutputStream
- Defined in:
- lib/ui/web/output_stream.rb
Overview
Lame hack to make XMLRPC output appear stream-ish to Sinatra in order to send it back to the browser.
Instance Method Summary collapse
- #<<(output) ⇒ Object
- #data ⇒ Object
-
#each ⇒ Object
Sinatra (or Rack, not sure) expects the output to respond to “each” so we oblige.
-
#initialize(instance, lines, &block) ⇒ OutputStream
constructor
A new instance of OutputStream.
Constructor Details
#initialize(instance, lines, &block) ⇒ OutputStream
Returns a new instance of OutputStream.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ui/web/output_stream.rb', line 26 def initialize( instance, lines, &block ) @lines = lines @instance = instance @buffer = [] @icon_whitelist = {} [ 'status', 'ok', 'error', 'info' ].each { |icon| @icon_whitelist[icon] = "<img src='/icons/#{icon}.png' />" } end |
Instance Method Details
#<<(output) ⇒ Object
43 44 45 46 |
# File 'lib/ui/web/output_stream.rb', line 43 def <<( output ) @buffer << output.reverse @buffer.flatten! end |
#data ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/ui/web/output_stream.rb', line 48 def data data = '' each { |line| data << line } data end |
#each ⇒ Object
Sinatra (or Rack, not sure) expects the output to respond to “each” so we oblige.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ui/web/output_stream.rb', line 61 def each self << @instance.service.output @@last_output ||= '' cnt = 0 if @buffer.empty? yield @@last_output else @@last_output = '' end while( ( out = @buffer.pop ) && ( ( cnt += 1 ) < @lines ) ) type = out.keys[0] msg = out.values[0] next if out.values[0].empty? icon = @icon_whitelist[type] || '' str = icon + CGI.escapeHTML( " #{out.values[0]}" ) + "<br/>" @@last_output << str yield str end self << @instance.service.output end |