2015-04-09 20:01:23 +00:00
|
|
|
# encoding: utf-8
|
2015-07-15 13:15:18 +00:00
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
2015-04-09 20:01:23 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
|
|
|
require 'utils/simpleconfig'
|
|
|
|
|
2015-08-28 17:10:03 +00:00
|
|
|
class SshConf < Vulcano.resource(1)
|
|
|
|
name 'ssh_config'
|
2015-04-09 20:01:23 +00:00
|
|
|
|
2015-08-28 17:10:03 +00:00
|
|
|
def initialize( conf_path = nil, type = nil )
|
2015-08-28 03:02:38 +00:00
|
|
|
@conf_path = conf_path || '/etc/ssh/ssh_conf'
|
2015-04-09 20:01:23 +00:00
|
|
|
@conf_dir = File.expand_path(File.dirname @conf_path)
|
2015-08-28 03:02:38 +00:00
|
|
|
@conf = nil
|
|
|
|
@params = {}
|
|
|
|
typename = ( @conf_path.include?('sshd') ? 'Server' : 'Client' )
|
2015-05-14 16:30:38 +00:00
|
|
|
@type = type || "SSH #{typename} configuration #{conf_path}"
|
2015-04-09 20:01:23 +00:00
|
|
|
read_content
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
@type
|
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
2015-08-29 09:10:36 +00:00
|
|
|
@conf.content
|
2015-04-09 20:01:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def params *opts
|
|
|
|
res = @params
|
|
|
|
opts.each do |opt|
|
|
|
|
res = res[opt] unless res.nil?
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing name
|
|
|
|
@params[name.to_s]
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_content
|
2015-08-28 03:02:38 +00:00
|
|
|
@conf = @vulcano.file(@conf_path)
|
2015-06-21 14:33:08 +00:00
|
|
|
# read the file
|
2015-08-30 00:13:53 +00:00
|
|
|
if !@conf.file?
|
2015-06-21 14:33:08 +00:00
|
|
|
return skip_resource "Can't find file \"#{@conf_path}\""
|
|
|
|
end
|
2015-08-28 03:02:38 +00:00
|
|
|
|
2015-08-29 09:10:36 +00:00
|
|
|
if @conf.content.empty? && @conf.size > 0
|
2015-06-21 14:33:08 +00:00
|
|
|
return skip_resource "Can't read file \"#{@conf_path}\""
|
|
|
|
end
|
2015-08-28 03:02:38 +00:00
|
|
|
|
2015-06-21 14:33:08 +00:00
|
|
|
# parse the file
|
2015-08-29 09:10:36 +00:00
|
|
|
@params = SimpleConfig.new(@conf.content,
|
2015-04-17 13:36:55 +00:00
|
|
|
assignment_re: /^\s*(\S+?)\s+(.*?)\s*$/,
|
|
|
|
multiple_values: false
|
|
|
|
).params
|
2015-04-09 20:01:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-08-28 17:10:03 +00:00
|
|
|
class SshdConf < SshConf
|
|
|
|
name 'sshd_config'
|
|
|
|
|
|
|
|
def initialize(path = nil)
|
2015-08-28 03:02:38 +00:00
|
|
|
super(path || '/etc/ssh/sshd_config')
|
2015-08-01 07:43:38 +00:00
|
|
|
end
|
|
|
|
end
|