2009-05-22 21:01:23 +00:00
|
|
|
module SshfsMapper
|
|
|
|
class Map
|
2009-12-14 23:56:06 +00:00
|
|
|
attr_reader :path, :host, :port, :user, :map
|
|
|
|
|
2009-06-12 15:49:30 +00:00
|
|
|
def initialize( map_path )
|
|
|
|
@path = map_path
|
2009-05-22 21:01:23 +00:00
|
|
|
@host = nil
|
|
|
|
@port = 22
|
|
|
|
@user = nil
|
2010-01-13 23:46:48 +00:00
|
|
|
@engine = :arcfour
|
|
|
|
@maps = {}
|
2009-05-22 21:01:23 +00:00
|
|
|
end
|
|
|
|
|
2009-06-12 15:49:30 +00:00
|
|
|
def parse()
|
2009-09-19 23:51:18 +00:00
|
|
|
puts "Parsing map #{@path}"
|
2010-01-13 23:46:48 +00:00
|
|
|
f = File.open( @path )
|
|
|
|
f.each do |line|
|
|
|
|
case line
|
|
|
|
when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/
|
|
|
|
@user = $1
|
|
|
|
when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/
|
|
|
|
@port = $1.to_i
|
|
|
|
when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/
|
|
|
|
@host = $1
|
|
|
|
when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/
|
|
|
|
idx = ["arcfour", "aes-256-cbc"].index( $1 )
|
|
|
|
if not idx.nil? then
|
2009-12-14 23:56:06 +00:00
|
|
|
@host = $1
|
|
|
|
end
|
2010-01-13 23:46:48 +00:00
|
|
|
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/
|
|
|
|
@maps[$1] = $2
|
|
|
|
else
|
|
|
|
puts "dropping #{line}"
|
2009-12-14 23:56:06 +00:00
|
|
|
end
|
|
|
|
end
|
2010-01-13 23:46:48 +00:00
|
|
|
f.close
|
|
|
|
#
|
2009-12-14 23:56:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_alive?
|
|
|
|
#FIXME: test liveness
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_connected?
|
|
|
|
#FIXME test if connected / mounted
|
2009-09-19 23:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def connect()
|
2010-01-13 23:46:48 +00:00
|
|
|
puts "[#{File.basename @path}] Connecting..."
|
|
|
|
puts " #{@user}@#{@host}:#{@port}"
|
|
|
|
puts " maps = #{@maps}"
|
2009-09-19 23:51:18 +00:00
|
|
|
# do something
|
|
|
|
# test server connection
|
|
|
|
# mount
|
|
|
|
end
|
|
|
|
|
|
|
|
def disconnect()
|
|
|
|
puts "Disconnecting map #{@path}"
|
|
|
|
# umount
|
2009-06-12 15:49:30 +00:00
|
|
|
end
|
2009-05-22 21:01:23 +00:00
|
|
|
end
|
2009-04-03 16:27:49 +00:00
|
|
|
end
|