From 987d6a671ff66aafe6ca14bd14855665c896253e Mon Sep 17 00:00:00 2001 From: RageLtMan Date: Wed, 10 Jul 2013 20:00:40 -0400 Subject: [PATCH] Allow passing MaxChar to Rex::Ui::Text::Table cols Passing MaxChar allows setting the maximum number of characters printed within a specific column during the row_to_s method. This does not affect CSV output nor truncate the actual data. Meant for tidying up long console ouput. Example: cleaned up cmd_creds to show proof and not maul tables with unix session data. --- lib/msf/ui/console/command_dispatcher/db.rb | 19 +++++++++++++------ lib/rex/ui/text/table.rb | 10 ++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 8496cf5036..1eff45e3aa 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -794,11 +794,18 @@ class Db # normalize ports = port_ranges.flatten.uniq svcs.flatten! + tbl_opts = { + 'Header' => "Credentials", + 'Columns' => [ 'host', 'port', 'user', 'pass', 'type', 'proof', 'active?' ] + } - tbl = Rex::Ui::Text::Table.new({ - 'Header' => "Credentials", - 'Columns' => [ 'host', 'port', 'user', 'pass', 'type', 'active?' ], - }) + tbl_opts.merge!( + 'ColProps' => { + 'pass' => { 'MaxChar' => 64 }, + 'proof' => { 'MaxChar' => 64 } + } + ) if search_term.nil? + tbl = Rex::Ui::Text::Table.new(tbl_opts) creds_returned = 0 # Now do the actual search @@ -828,8 +835,8 @@ class Db end row = [ cred.service.host.address, cred.service.port, - cred.user, cred.pass, cred.ptype, - (cred.active ? "true" : "false") + cred.user, cred.pass, cred.ptype, cred.proof, + cred.active.to_s ] tbl << row if mode == :delete diff --git a/lib/rex/ui/text/table.rb b/lib/rex/ui/text/table.rb index 56ca8a61a7..5f11014a16 100644 --- a/lib/rex/ui/text/table.rb +++ b/lib/rex/ui/text/table.rb @@ -283,9 +283,15 @@ protected if (last_cell) line << pad(' ', last_cell.to_s, last_idx) end - line << cell.to_s # line << pad(' ', cell.to_s, idx) - last_cell = cell + # Limit wide cells + if colprops[idx]['MaxChar'] + last_cell = cell.to_s[0..colprops[idx]['MaxChar'].to_i] + line << last_cell + else + line << cell.to_s + last_cell = cell + end last_idx = idx }