Class: Watobo::Gui::SessionIdSettings

Inherits:
FXHorizontalFrame
  • Object
show all
Includes:
Utils
Defined in:
lib/watobo/gui/session_management_dialog.rb

Defined Under Namespace

Classes: SidPreview

Instance Method Summary collapse

Methods included from Utils

#addDecoder, #addEncoder, #addStringInfo, #cleanupHTTP, load_plugins, #removeTags, #replace_text

Constructor Details

#initialize(parent) ⇒ SessionIdSettings

Returns a new instance of SessionIdSettings.



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/watobo/gui/session_management_dialog.rb', line 397

def initialize(parent)
  @project = Watobo.project
  @pattern = FXDataTarget.new('')

  super(parent, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)

  main_frame = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_Y|LAYOUT_FILL_X|FRAME_GROOVE)
  frame = FXVerticalFrame.new(main_frame, :opts => LAYOUT_FILL_Y)
  label = FXLabel.new(frame, "Session ID Patterns:")

  @pattern_field = FXTextField.new(frame, 40, :target => @pattern, :selector => FXDataTarget::ID_VALUE, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_LEFT)

  b_frame = FXHorizontalFrame.new(frame, :opts => LAYOUT_FILL_X)
  @addSidButton = FXButton.new(b_frame, "Add" , :opts => BUTTON_NORMAL|LAYOUT_LEFT)
  @addSidButton.connect(SEL_COMMAND, method(:addPattern))
  @remSidButton=FXButton.new(b_frame, "Remove" , :opts => BUTTON_NORMAL|LAYOUT_LEFT)
  @remSidButton.connect(SEL_COMMAND, method(:remPattern))

  list_frame = FXVerticalFrame.new(frame, :opts => LAYOUT_FILL_X|FRAME_SUNKEN, :padding => 0)
  @pattern_list = FXList.new(list_frame, :opts => LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @pattern_list.numVisible = 25

  @pattern_list.connect(SEL_COMMAND,method(:onPatternClick))

  frame = FXVerticalFrame.new(main_frame, :opts => LAYOUT_FILL_Y|LAYOUT_FILL_X)
  label = FXLabel.new(frame, "Login Requests:")
  @requestCombo = FXComboBox.new(frame, 5, nil, 0,
  COMBOBOX_STATIC|FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
  #@filterCombo.width =200

  @requestCombo.numVisible = 0
  @requestCombo.numColumns = 50
  @requestCombo.editable = false
  @requestCombo.connect(SEL_COMMAND, method(:onRequestChanged))

  chat_viewer_frame = FXVerticalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y, :height => 300, :padding => 0)
  tabBook = FXTabBook.new(chat_viewer_frame, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_RIGHT, :padding => 0)

  req_tab = FXTabItem.new(tabBook, "Request", nil)
  frame = FXVerticalFrame.new(tabBook, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_RAISED)
  sunken = FXVerticalFrame.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN, :padding => 0)
  @request_viewer = SidPreview.new(sunken, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN)

  resp_tab = FXTabItem.new(tabBook, "Response", nil)
  frame = FXVerticalFrame.new(tabBook, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_RAISED)
  sunken = FXVerticalFrame.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN, :padding => 0)
  @response_viewer = SidPreview.new(sunken, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)

  
  Watobo::Conf::SidCache.patterns.each do |p|
      item = @pattern_list.appendItem("#{p}")
      @pattern_list.setItemData(item, p)
    end
  
end

Instance Method Details

#addPattern(sender, sel, id) ⇒ Object



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
362
363
364
# File 'lib/watobo/gui/session_management_dialog.rb', line 329

def addPattern(sender,sel,id)
  pattern = @pattern.value
  if pattern != "" then
    begin
      dummy = pattern.split('(')
      if dummy.length < 2 then
        # no good pattern
        puts "!!!ERROR: Bad pattern"
        showBadPatternMessage()
        return -1
      end

      dummy = pattern.split(')')
      if dummy.length < 2 then
        # no good pattern
        puts "!!!ERROR: Bad pattern"
        showBadPatternMessage()
        return -1
      end

      # test if pattern looks like a valid regex
      if "test" =~ /#{pattern}/i then
        #looks good
      end

    rescue => bang
      puts "!!!ERROR: Bad pattern"
      showBadPatternMessage()
      return -1
    end
    item = @pattern_list.appendItem("#{@pattern.value}")
    @pattern_list.setItemData(item, @pattern.value)
    return 0
    # item.
  end
end

#getSidPatternListObject



321
322
323
324
325
326
327
# File 'lib/watobo/gui/session_management_dialog.rb', line 321

def getSidPatternList()
  sids = []
  @pattern_list.numItems.times do |index|
    sids.push @pattern_list.getItemData(index)
  end
  return sids
end

#onPatternClick(sender, sel, item) ⇒ Object



299
300
301
302
303
304
# File 'lib/watobo/gui/session_management_dialog.rb', line 299

def onPatternClick(sender,sel,item)
  @request_viewer.highlight(@pattern_list.getItemText(item))
  @response_viewer.highlight(@pattern_list.getItemText(item))
  @pattern.value = @pattern_list.getItemText(item)
  @pattern_field.handle(self, FXSEL(SEL_UPDATE, 0), nil)
end

#onRequestChanged(sender, sel, item) ⇒ Object



306
307
308
309
310
311
312
313
314
315
# File 'lib/watobo/gui/session_management_dialog.rb', line 306

def onRequestChanged(sender, sel, item)
  begin
    chat = @requestCombo.getItemData(@requestCombo.currentItem)
    @request_viewer.setText(cleanupHTTP(chat.request))
    @response_viewer.setText(cleanupHTTP(chat.response))
  rescue => bang
    puts "could not update request"
    puts bang
  end
end

#remPattern(sender, sel, id) ⇒ Object



366
367
368
369
370
371
# File 'lib/watobo/gui/session_management_dialog.rb', line 366

def remPattern(sender,sel,id)
  index = @pattern_list.currentItem
  if  index >= 0
    @pattern_list.removeItem(index)
  end
end

#showBadPatternMessageObject



317
318
319
# File 'lib/watobo/gui/session_management_dialog.rb', line 317

def showBadPatternMessage()
  FXMessageBox.information(self, MBOX_OK, "Wrong Pattern Format", "SID Pattern Format is wrong, e.g.(<PATTERN>) <(session)=([a-z]*)>\nRegex must contain two selectors \"()\" to satisfy $1 and $2.")
end

#updateRequests(req_id_list) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/watobo/gui/session_management_dialog.rb', line 373

def updateRequests(req_id_list)

  if @project then
    @requestCombo.clearItems()

    req_id_list.each do |id|
      chat = Watobo::Chats.get_by_id(id)
      text = "[#{id}] #{chat.request.first}"
      @requestCombo.appendItem(text.slice(0..60), chat)
    end
    if @requestCombo.numItems > 0 then
      if @requestCombo.numItems < 10 then
        @requestCombo.numVisible = @requestCombo.numItems
      else
        @requestCombo.numVisible = 10
      end
      @requestCombo.setCurrentItem(0, true)
      chat = @requestCombo.getItemData(0)
      @request_viewer.setText(cleanupHTTP(chat.request))
      @response_viewer.setText(cleanupHTTP(chat.response))
    end
  end
end