10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ssh_config_to_vuls_config/cli.rb', line 10
def convert
begin
stdin = timeout(1) { $stdin.read }
rescue Timeout::Error
end
parsed = Sconb::SSHConfig.parse(stdin)
config = { servers: {} }
parsed.each do |host, detail|
next if host =~ /\*/
next if detail.key?('Match')
next unless detail.key?('Host')
next unless detail.key?('IdentityFile')
key_path = File.expand_path(detail['IdentityFile'].first)
config[:servers][detail['Host']] = {
host: detail['Hostname'],
user: detail['User'] || 'root',
port: detail['Port'] || '22',
keyPath: key_path
}
end
puts TOML.dump(config)
end
|