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.


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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/watobo/gui/session_management_dialog.rb', line 418

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


350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/watobo/gui/session_management_dialog.rb', line 350

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


342
343
344
345
346
347
348
# File 'lib/watobo/gui/session_management_dialog.rb', line 342

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

#onPatternClick(sender, sel, item) ⇒ Object


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

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


327
328
329
330
331
332
333
334
335
336
# File 'lib/watobo/gui/session_management_dialog.rb', line 327

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


387
388
389
390
391
392
# File 'lib/watobo/gui/session_management_dialog.rb', line 387

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

#showBadPatternMessageObject


338
339
340
# File 'lib/watobo/gui/session_management_dialog.rb', line 338

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


394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/watobo/gui/session_management_dialog.rb', line 394

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