2007-05-18 22:37:27 +00:00
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Gtk2
|
|
|
|
|
|
|
|
class Stdapi
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# The file system portion of the standard API extension.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Fs < Msf::Ui::Gtk2::SkeletonBasic
|
|
|
|
COL_PATH, COL_DISPLAY_NAME, COL_IS_DIR, COL_PIXBUF = (0..4).to_a
|
|
|
|
|
|
|
|
include Msf::Ui::Gtk2::MyControls
|
|
|
|
|
|
|
|
def initialize(client)
|
|
|
|
@client = client
|
2007-05-18 23:51:10 +00:00
|
|
|
super("MsfBrowser on #{@client.tunnel_peer}")
|
2007-05-19 20:23:24 +00:00
|
|
|
@model_view = Gtk::ListStore.new(String, String, TrueClass, Gdk::Pixbuf)
|
2007-05-18 22:37:27 +00:00
|
|
|
@parent = "/"
|
2007-05-18 23:51:10 +00:00
|
|
|
|
|
|
|
@file_pixbuf = Gdk::Pixbuf.new(driver.get_image("msf_file.png"))
|
|
|
|
@folder_pixbuf = Gdk::Pixbuf.new(driver.get_image("msf_folder.png"))
|
|
|
|
|
2007-05-19 20:23:24 +00:00
|
|
|
@model_view.set_default_sort_func do |a, b|
|
2007-05-18 22:37:27 +00:00
|
|
|
if !a[COL_IS_DIR] and b[COL_IS_DIR]
|
|
|
|
1
|
|
|
|
elsif a[COL_IS_DIR] and !b[COL_IS_DIR]
|
|
|
|
-1
|
|
|
|
else
|
|
|
|
a[COL_DISPLAY_NAME] <=> b[COL_DISPLAY_NAME]
|
|
|
|
end
|
|
|
|
end
|
2007-05-19 20:23:24 +00:00
|
|
|
@model_view.set_sort_column_id(Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID, Gtk::SORT_ASCENDING)
|
2007-05-18 22:37:27 +00:00
|
|
|
|
2007-05-18 23:51:10 +00:00
|
|
|
# Populate the ListStore
|
2007-05-18 22:37:27 +00:00
|
|
|
cmd_ls
|
2007-05-18 23:51:10 +00:00
|
|
|
|
|
|
|
# Define the size and border
|
2007-05-19 20:23:24 +00:00
|
|
|
set_default_size(800, 600)
|
2007-05-18 23:51:10 +00:00
|
|
|
set_border_width(10)
|
2007-05-18 22:37:27 +00:00
|
|
|
|
|
|
|
vbox = Gtk::VBox.new(false, 0)
|
|
|
|
add(vbox)
|
|
|
|
|
2007-05-18 23:51:10 +00:00
|
|
|
# Add the view in the scrolled window
|
2007-05-18 22:37:27 +00:00
|
|
|
sw = Gtk::ScrolledWindow.new
|
|
|
|
sw.shadow_type = Gtk::SHADOW_ETCHED_IN
|
|
|
|
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
|
|
|
vbox.pack_start(sw, true, true, 0)
|
|
|
|
|
2007-05-19 20:23:24 +00:00
|
|
|
iconview = Gtk::IconView.new(@model_view)
|
2007-05-18 22:37:27 +00:00
|
|
|
iconview.selection_mode = Gtk::SELECTION_MULTIPLE
|
|
|
|
iconview.text_column = COL_DISPLAY_NAME
|
|
|
|
iconview.pixbuf_column = COL_PIXBUF
|
|
|
|
iconview.signal_connect("item_activated") do |iview, path|
|
2007-05-19 20:23:24 +00:00
|
|
|
iter = @model_view.get_iter(path)
|
2007-05-19 22:42:27 +00:00
|
|
|
if ( iter[COL_DISPLAY_NAME] and iter[COL_IS_DIR] )
|
2007-05-19 20:23:24 +00:00
|
|
|
cmd_ls(@parent + "\\" + iter[COL_DISPLAY_NAME])
|
2007-05-18 22:37:27 +00:00
|
|
|
end
|
|
|
|
end
|
2007-05-18 23:51:10 +00:00
|
|
|
|
2007-05-18 22:37:27 +00:00
|
|
|
sw.add(iconview)
|
|
|
|
iconview.grab_focus
|
|
|
|
|
|
|
|
show_all
|
|
|
|
end
|
2007-05-19 20:23:24 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Lists file on the remote machine
|
|
|
|
#
|
2007-05-18 22:37:27 +00:00
|
|
|
def cmd_ls(*args)
|
2007-05-19 21:09:40 +00:00
|
|
|
|
|
|
|
# Just ignore the invalid UTF8
|
|
|
|
# Don't know why GLib.filename_to_utf8() don't work ;-(
|
|
|
|
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
|
|
|
|
2007-05-19 20:23:24 +00:00
|
|
|
@model_view.clear
|
2007-05-18 22:37:27 +00:00
|
|
|
path = args[0] || @client.fs.dir.getwd
|
2007-05-19 21:09:40 +00:00
|
|
|
@parent = path
|
2007-05-18 22:37:27 +00:00
|
|
|
|
|
|
|
# Enumerate each item...
|
|
|
|
@client.fs.dir.entries_with_info(path).sort { |a,b| a['FileName'] <=> b['FileName'] }.each do |p|
|
|
|
|
if p['StatBuf'].ftype[0,3] == "dir"
|
|
|
|
is_dir = true
|
|
|
|
elsif p['StatBuf'].ftype[0,3] == "fil"
|
|
|
|
is_dir = false
|
|
|
|
end
|
2007-05-19 20:23:24 +00:00
|
|
|
iter = @model_view.append
|
2007-05-19 21:09:40 +00:00
|
|
|
iter[COL_DISPLAY_NAME] = ic.iconv(p['FileName'] + ' ')[0..-2] || 'unknown'
|
2007-05-18 22:37:27 +00:00
|
|
|
iter[COL_PATH] = path
|
|
|
|
iter[COL_IS_DIR] = is_dir
|
|
|
|
iter[COL_PIXBUF] = is_dir ? @folder_pixbuf : @file_pixbuf
|
|
|
|
end
|
|
|
|
end # cmd_ls
|
|
|
|
|
|
|
|
end # Fs
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|