Class: Watobo::Gui::ConversationTable

Inherits:
FXTable
  • Object
show all
Includes:
Icons
Defined in:
lib/watobo/gui/conversation_table.rb

Constant Summary

Constants included from Icons

Icons::ICON_ADD_PROJECT, Icons::ICON_BROWSER_MEDIUM, Icons::ICON_BROWSER_SMALL, Icons::ICON_BTN_DOWN, Icons::ICON_BTN_UP, Icons::ICON_CB_CHECKED, Icons::ICON_CB_CHECKED_ORANGE, Icons::ICON_CB_UNCHECKED, Icons::ICON_CONVERSATION, Icons::ICON_DASHBOARD, Icons::ICON_DIFFER, Icons::ICON_FOLDER, Icons::ICON_FOLDER_SMALL, Icons::ICON_FUZZER, Icons::ICON_FUZZER_MEDIUM, Icons::ICON_FUZZER_SMALL, Icons::ICON_FUZZ_FILTER, Icons::ICON_FUZZ_GENERATOR, Icons::ICON_FUZZ_TAG, Icons::ICON_HINTS, Icons::ICON_HINTS_INFO, Icons::ICON_HINTS_INFO_SMALL, Icons::ICON_HINTS_SMALL, Icons::ICON_INFO, Icons::ICON_INFO_INFO, Icons::ICON_INFO_INFO_SMALL, Icons::ICON_INFO_SMALL, Icons::ICON_INFO_USER, Icons::ICON_INFO_USER_SMALL, Icons::ICON_INTERCEPTOR, Icons::ICON_LOGIN_WIZZARD, Icons::ICON_MANUAL_REQUEST, Icons::ICON_MANUAL_REQUEST_MEDIUM, Icons::ICON_MANUAL_REQUEST_SMALL, Icons::ICON_PAUSE, Icons::ICON_PLUGIN, Icons::ICON_PROJECT, Icons::ICON_PROJECT_SMALL, Icons::ICON_REPORT, Icons::ICON_REQUEST, Icons::ICON_REQUEST_SMALL, Icons::ICON_SEND_REQUEST, Icons::ICON_SITE, Icons::ICON_SITE_SMALL, Icons::ICON_START, Icons::ICON_STOP, Icons::ICON_TOKEN, Icons::ICON_TRANSCODER, Icons::ICON_VULN, Icons::ICON_VULN_BP, Icons::ICON_VULN_BP_SMALL, Icons::ICON_VULN_CRITICAL, Icons::ICON_VULN_CRITICAL_SMALL, Icons::ICON_VULN_HIGH, Icons::ICON_VULN_HIGH_SMALL, Icons::ICON_VULN_LOW, Icons::ICON_VULN_LOW_SMALL, Icons::ICON_VULN_MEDIUM, Icons::ICON_VULN_MEDIUM_SMALL, Icons::ICON_VULN_SMALL, Icons::ICON_WATOBO, Icons::SIBERAS_ICON, Icons::TBL_ICON_LOCK, Icons::WATOBO_LOGO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, unused = nil) ⇒ ConversationTable

Returns a new instance of ConversationTable.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/watobo/gui/conversation_table.rb', line 242

def initialize( owner, unused = nil )
  @event_dispatcher_listeners = Hash.new

  super(owner, :opts => TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y|TABLE_READONLY|LAYOUT_SIDE_TOP, :padding => 2)
  
   @filter = {}

  @url_decode = true

  self.setBackColor(FXRGB(255, 255, 255))
  self.setCellColor(0, 0, FXRGB(255, 255, 255))
  self.setCellColor(0, 1, FXRGB(255, 240, 240))
  self.setCellColor(1, 0, FXRGB(240, 255, 240))
  self.setCellColor(1, 1, FXRGB(240, 240, 255))

#  reset_filter
  #   FXMAPFUNC(SEL_CLICKED, FXTable::ID_SELECT_CELL, :onSelectCell)
  @current_chat_list = []
  @uniq_chats = Hash.new

  @columns = Hash.new
  @cell_width = Hash.new
  @col_order = []
  @autoscroll = false

  @columns = Hash.new

  @columns[TABLE_COL_METHOD] = "Method"
  @columns[TABLE_COL_HOST] = "Host"
  @columns[TABLE_COL_PATH] = "Path"
  @columns[TABLE_COL_PARMS] = "Parameters"
  @columns[TABLE_COL_STATUS] = "Status"
  @columns[TABLE_COL_COOKIE] = "Set-Cookie"
  @columns[TABLE_COL_COMMENT] = "Comment"
  @columns[TABLE_COL_SSL] = ""

  # initialize columns order
  @col_order = [ TABLE_COL_SSL, TABLE_COL_METHOD, TABLE_COL_HOST, TABLE_COL_PATH, TABLE_COL_PARMS, TABLE_COL_STATUS, TABLE_COL_COOKIE, TABLE_COL_COMMENT ]

  # init cell width
  @cell_width = Hash.new
  @cell_width[TABLE_COL_METHOD] = 50
  @cell_width[TABLE_COL_HOST] = 120
  @cell_width[TABLE_COL_PATH] = 200
  @cell_width[TABLE_COL_PARMS] = 150
  @cell_width[TABLE_COL_STATUS] = 50
  @cell_width[TABLE_COL_COOKIE] = 70
  @cell_width[TABLE_COL_COMMENT] = 100
  @cell_width[TABLE_COL_SSL] = 20

  @cell_width_defaults = Hash.new
  @cell_width_defaults.update YAML.load(YAML.dump(@cell_width))

  @cell_auto_max = 400
  @cell_min_width = 30

  initColumns()

  self.columnHeader.connect(SEL_CHANGED) do |sender, sel, index|
    type = @col_order[index]
    @cell_width[type] = self.getColumnWidth(index)
  end

  self.columnHeader.connect(SEL_COMMAND) do |sender, sel, index|
    type = @col_order[index]
    column_width = self.getColumnWidth(index)

    new_width = case column_width
    when column_width > @cell_auto_max
      @cell_auto_max
    when ( column_width > @cell_width_defaults[type] )
      @cell_width_defaults[type]
    when @cell_width_defaults[type]
      self.fitColumnsToContents(index)
      w = self.getColumnWidth(index)
      w = @cell_auto_max if self.getColumnWidth(index) > @cell_auto_max
      w = @cell_width_defaults[type] if self.getColumnWidth(index) < @cell_width_defaults[type]
      w
    else
    @cell_width_defaults[type]
    end
    self.setColumnWidth(index, new_width)
    @cell_width[type] = new_width
    self.rowHeaderMode = 0

    adjustCellWidth()
  end
  
  self.connect(SEL_CHANGED){ |sender, sel, item|
   # puts "SEL_CHANGED #{item.row}"
    self.selectRow(item.row, false)
     chat = self.getItemData(item.row, 0)
     notify(:chat_selected, chat) if chat.respond_to? :request
  }
  
  self.connect(SEL_COMMAND){ |sender, sel, item|
   # puts "SEL_COMMAND #{item.row}"
    self.selectRow(item.row, false)
     chat = self.getItemData(item.row, 0)
     notify(:chat_selected, chat) if chat.respond_to? :request
  }
  
  self.connect(SEL_DOUBLECLICKED){ |sender, sel, item|
    #   puts "SEL_DOUBLECLICKED #{item.row}"
    self.selectRow(item.row, false)
     chat = self.getItemData(item.row, 0)
     notify(:chat_doubleclicked, chat) if chat.respond_to? :request
  }
  
  self.connect(SEL_SELECTED){ |sender, sel, item|
     #  puts "SEL_SELECTED #{item.row}"
    self.selectRow(item.row, false)
     chat = self.getItemData(item.row, 0)
     notify(:chat_selected, chat) if chat.respond_to? :request
  }

  adjustCellWidth()

  addHotkeyHandler(self)
end

Instance Attribute Details

#autoscrollObject

Returns the value of attribute autoscroll.



82
83
84
# File 'lib/watobo/gui/conversation_table.rb', line 82

def autoscroll
  @autoscroll
end

#filterObject (readonly)

class ConversationTable < FXColoredTable



80
81
82
# File 'lib/watobo/gui/conversation_table.rb', line 80

def filter
  @filter
end

#url_decodeObject

Returns the value of attribute url_decode.



83
84
85
# File 'lib/watobo/gui/conversation_table.rb', line 83

def url_decode
  @url_decode
end

Instance Method Details

#addChat(chat, *prefs) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/watobo/gui/conversation_table.rb', line 213

def addChat(chat, *prefs)
  if self.getNumRows <= 0 then
    clearConversation()
  # initColumns()
  end

  @current_chat_list.push chat unless chat.nil?
  if prefs.include? :ignore_filter
    add_chat_row(chat)
  return true
  end
  add_chat_row(chat) # if chat_visible?(chat)
  return true

end

#apply_filter(filter = {}) ⇒ Object



113
114
115
116
117
# File 'lib/watobo/gui/conversation_table.rb', line 113

def apply_filter(filter={})
  @filter = filter      
  puts @filter.to_yaml if $DEBUG
  update_table
end

#chat_visible?(chat) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/watobo/gui/conversation_table.rb', line 129

def chat_visible?(chat)
  begin
    return false if @filter[:ok_only] == true and chat.response.responseCode !~ /200/ 
     
    if @filter[:unique]
      unless Watobo::Gui.project.nil?
        uniq_hash = Watobo::Gui.project.uniqueRequestHash chat.request
        return false if @uniq_chats.has_key? uniq_hash
        @uniq_chats[uniq_hash] = nil
      end
    end

    if @filter[:show_scope_only]
      unless Watobo::Gui.project.nil?
        return false unless Watobo::Scope.match_site?(chat.request.site)
      end
    end
    # puts "* passed scope"
    if @filter[:hide_tested]
    return false if chat.tested?
    end
    # puts "* passed hide tested"
    unless @filter[:doc_filter].include?(chat.request.doctype)
      return true if @filter[:text].empty?

      return true if @filter[:url] == true and chat.request.first =~ /#{@filter[:text]}/i

      return true if @filter[:request] == true and chat.request.join =~ /#{@filter[:text]}/i
      # puts @filter.to_yaml
      # puts chat.response.responseCode

      if @filter[:response] == true 
        return false if @filter[:text_only] == true and chat.response.content_type !~ /(text|javascript|xml|json)/ 
        return true if chat.response.join.unpack("C*").pack("C*") =~ /#{@filter[:text]}/i
      end

    end
  rescue => bang
    puts "! could not add chat to table !".upcase
    #  puts chat.id
    puts bang
    puts bang.backtrace if $DEBUG
  end
  false
end

#clearConversationObject



371
372
373
374
375
376
# File 'lib/watobo/gui/conversation_table.rb', line 371

def clearConversation()
  self.clearItems
  @current_chat_list = []
  initColumns()
  adjustCellWidth()
end

#clearEvents(event) ⇒ Object



90
91
92
93
# File 'lib/watobo/gui/conversation_table.rb', line 90

def clearEvents(event)
  @event_dispatcher_listeners[event] ||= []
  @event_dispatcher_listeners[event].clear
end

#current_chatObject



119
120
121
122
123
124
125
126
127
# File 'lib/watobo/gui/conversation_table.rb', line 119

def current_chat
  # puts currentRow
  if currentRow >= 0
    chatid = getRowText(currentRow).to_i
    chat = Watobo::Chats.get_by_id(chatid)
  return chat
  end
  return nil
end

#initColumnsObject



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/watobo/gui/conversation_table.rb', line 229

def initColumns()
  self.setTableSize(0, @columns.length)
  self.visibleRows = 20
  self.visibleColumns = @columns.length

  @columns.each do |type, name|
    index = @col_order.index(type)
    self.setColumnText( index, name )
    self.setColumnIcon(@col_order.index(TABLE_COL_SSL), TBL_ICON_LOCK)# puts self.getItem(@col_order.index(col), 0  ).class.to_s
  end

end

#notify(event, *args) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/watobo/gui/conversation_table.rb', line 95

def notify(event, *args)
  if @event_dispatcher_listeners[event]
    #  puts "NOTIFY: #{self}(:#{event}) [#{@event_dispatcher_listeners[event].length}]" if $DEBUG
    @event_dispatcher_listeners[event].each do |m|
      m.call(*args) if m.respond_to? :call
    end
  end
end

#num_totalObject



104
105
106
# File 'lib/watobo/gui/conversation_table.rb', line 104

def num_total
  @current_chat_list.length
end

#num_visibleObject



108
109
110
# File 'lib/watobo/gui/conversation_table.rb', line 108

def num_visible
  self.numRows
end

#scrollDownObject



367
368
369
# File 'lib/watobo/gui/conversation_table.rb', line 367

def scrollDown()
  self.makePositionVisible(self.numRows-1, 0)
end

#scrollUpObject



363
364
365
# File 'lib/watobo/gui/conversation_table.rb', line 363

def scrollUp()
  self.makePositionVisible(0, 0)
end

#setNewFont(font_type = nil, size = nil) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/watobo/gui/conversation_table.rb', line 189

def setNewFont(font_type=nil, size=nil)
  begin
    new_size = size.nil? ? GUI_REGULAR_FONT_SIZE : size
    new_font_type = font_type.nil? ? "helvetica" : font_type
    new_font = FXFont.new(getApp(), new_font_type, new_size)
    new_font.create

    self.font = new_font
    self.rowHeader.font = new_font
    self.defRowHeight = new_size+10

    update_table()

  rescue => bang
    puts bang
    puts bang.backtrace if $DEBUG
  end
end

#showConversation(chat_list = nil, prefs = {}) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/watobo/gui/conversation_table.rb', line 175

def showConversation( chat_list = nil, prefs = {} )
  clearConversation()
  if chat_list.nil?
    Watobo::Chats.each do |chat|
      addChat(chat, prefs)
    end
  else
    chat_list.each do |chat|
      addChat(chat, prefs)
    end
  end
  adjustCellWidth()
end

#subscribe(event, &callback) ⇒ Object



86
87
88
# File 'lib/watobo/gui/conversation_table.rb', line 86

def subscribe(event, &callback)
  (@event_dispatcher_listeners[event] ||= []) << callback
end

#updateComment(row, comment) ⇒ Object



208
209
210
211
# File 'lib/watobo/gui/conversation_table.rb', line 208

def updateComment(row, comment)
  col = @col_order.index(TABLE_COL_COMMENT)
  self.setItemText(row, col, comment.gsub(/[^[:print:]]/,' '))
end