1ddd99e339
git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1656 eaee96b3-f302-0410-b096-c6cfd47f7835
81 lines
1.6 KiB
Ruby
81 lines
1.6 KiB
Ruby
|
|
require 'rdebug/base'
|
|
|
|
module SshfsMapper
|
|
|
|
class Map
|
|
attr_reader :path, :host, :port, :user, :map
|
|
|
|
class MapParseError < RuntimeError
|
|
end
|
|
|
|
def initialize( map_path )
|
|
@path = map_path
|
|
@host = nil
|
|
@port = 22
|
|
@user = nil
|
|
@engine = :arcfour
|
|
@maps = {}
|
|
@debug = false
|
|
end
|
|
|
|
def parse
|
|
puts "Parsing map #{@path}"
|
|
f = File.open( @path )
|
|
linect = 0
|
|
f.each do |line|
|
|
line = line.strip
|
|
linect += 1
|
|
|
|
#puts " [#{line}]"
|
|
case line
|
|
when /^\s*REMOTE_USER\s*=\s*(.*)\s*$/ then
|
|
@user = $1
|
|
rdebug "d: remote_user => #{$1}"
|
|
when /^\s*REMOTE_PORT\s*=\s*(.*)\s*$/ then
|
|
@port = $1.to_i
|
|
rdebug "d: remote_port => #{$1}"
|
|
when /^\s*REMOTE_HOST\s*=\s*(.*)\s*$/ then
|
|
@host = $1
|
|
rdebug "d: remote_host => #{$1}"
|
|
when /^\s*REMOTE_CYPHER\s*=\s*(.*)\s*$/ then
|
|
cyphers = ["arcfour", "aes-256-cbc"]
|
|
if cyphers.include? $1 then
|
|
@host = $1
|
|
end
|
|
when /^\s*MAP\s*=\s*(.*)\s+(.*)\s*$/ then
|
|
@maps[$1] = $2
|
|
rdebug "d: map #{$1} => #{$2}"
|
|
when /^\s*$/ then
|
|
rdebug "d: dropping empty line"
|
|
else
|
|
raise MapParseError, "parse error at #{@path}:#{linect}"
|
|
end
|
|
end
|
|
f.close
|
|
#
|
|
end
|
|
|
|
def alive?
|
|
#FIXME: test liveness
|
|
end
|
|
|
|
def is_connected?
|
|
#FIXME test if connected / mounted
|
|
end
|
|
|
|
def connect
|
|
puts "[#{File.basename @path}] Connecting..."
|
|
puts " #{@user}@#{@host}:#{@port}"
|
|
puts " maps = %s" % @maps.map{ |k,v| "%s => %s" % [ k, v ] }.join(', ')
|
|
# do something
|
|
# test server connection
|
|
# mount
|
|
end
|
|
|
|
def disconnect
|
|
puts "Disconnecting map #{@path}"
|
|
# umount
|
|
end
|
|
end
|
|
end
|