See #3104. Make exporting/importing funny characters more convenient. Export inactive credentials by default.
git-svn-id: file:///home/svn/framework3/trunk@10867 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
6048580919
commit
492268b066
|
@ -2047,6 +2047,7 @@ class DBManager
|
|||
data = args[:data]
|
||||
wspace = args[:wspace] || workspace
|
||||
bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : []
|
||||
last_host = nil
|
||||
|
||||
addr = nil
|
||||
port = nil
|
||||
|
@ -2088,7 +2089,8 @@ class DBManager
|
|||
if bl.include? addr
|
||||
next
|
||||
else
|
||||
yield(:address,addr) if block
|
||||
yield(:address,addr) if block and addr != last_host
|
||||
last_host = addr
|
||||
end
|
||||
|
||||
cred_info = {
|
||||
|
|
|
@ -75,6 +75,12 @@ class Export
|
|||
return sz
|
||||
end
|
||||
|
||||
# Converts binary and whitespace characters to a hex notation.
|
||||
def ascii_safe_hex(str)
|
||||
str.gsub!(/([\x00-\x20\x80-\xFF])/){ |x| "\\x%.2x" % x.unpack("C*")[0] }
|
||||
return str
|
||||
end
|
||||
|
||||
# Formats credentials according to their type, and writes it out to the
|
||||
# supplied report file. Note for reimporting: Blank values are <BLANK>
|
||||
def write_credentials(ptype,creds,report_file)
|
||||
|
@ -106,8 +112,8 @@ class Export
|
|||
end
|
||||
else "text"
|
||||
data.each do |c|
|
||||
user = (c.user.nil? || c.user.empty?) ? "<BLANK>" : c.user
|
||||
pass = (c.pass.nil? || c.pass.empty?) ? "<BLANK>" : c.pass
|
||||
user = (c.user.nil? || c.user.empty?) ? "<BLANK>" : ascii_safe_hex(c.user)
|
||||
pass = (c.pass.nil? || c.pass.empty?) ? "<BLANK>" : ascii_safe_hex(c.pass)
|
||||
report_file.write "%s %s\n" % [user,pass]
|
||||
end
|
||||
end
|
||||
|
@ -136,7 +142,7 @@ class Export
|
|||
next unless host_allowed?(cred.service.host.address)
|
||||
# Skip anything that's not associated with a specific host and port
|
||||
next unless (cred.service && cred.service.host && cred.service.host.address && cred.service.port)
|
||||
# Skip anything that's not active.
|
||||
# TODO: Toggle active/all
|
||||
next unless cred.active
|
||||
svc = "%s:%d/%s (%s)" % [cred.service.host.address,cred.service.port,cred.service.proto,cred.service.name]
|
||||
case cred.ptype
|
||||
|
|
|
@ -1157,12 +1157,12 @@ class Db
|
|||
export_formats = %W{xml pwdump}
|
||||
format = 'xml'
|
||||
output = nil
|
||||
|
||||
|
||||
while (arg = args.shift)
|
||||
case arg
|
||||
when '-h','--help'
|
||||
print_line("Usage:")
|
||||
print_line(" db_export -f <format> [filename]")
|
||||
print_line(" db_export -f <format> [-a] [filename]")
|
||||
print_line(" Format can be one of: #{export_formats.join(", ")}")
|
||||
when '-f','--format'
|
||||
format = args.shift.to_s.downcase
|
||||
|
@ -1178,6 +1178,7 @@ class Db
|
|||
|
||||
if not export_formats.include?(format)
|
||||
print_error("Unsupported file format: #{format}")
|
||||
print_error("Unsupported file format: '#{format}'. Must be one of: #{export_formats.join(", ")}")
|
||||
return
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue