parent
86f943e25a
commit
f38ad13094
|
@ -219,6 +219,36 @@ class Db
|
|||
cmd_hosts("-h")
|
||||
end
|
||||
|
||||
def change_host_info(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :info => data)
|
||||
framework.db.report_note({:host=>ip, :type=>'host.info', :note=>data})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def change_host_name(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :name => data)
|
||||
framework.db.report_note({:host=>ip, :type=>'host.name', :note=>data})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def change_host_comment(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :comments => data)
|
||||
framework.db.report_note({:host=>ip, :type=>'host.comments', :note=>data})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_hosts(*args)
|
||||
return unless active?
|
||||
::ActiveRecord::Base.connection_pool.with_connection {
|
||||
|
@ -266,7 +296,15 @@ class Db
|
|||
set_rhosts = true
|
||||
when '-S', '--search'
|
||||
search_term = /#{args.shift}/nmi
|
||||
|
||||
when '-i', '--info'
|
||||
mode = :new_info
|
||||
info_data = args.shift
|
||||
when '-n', '--name'
|
||||
mode = :new_name
|
||||
name_data = args.shift
|
||||
when '-m', '--comment'
|
||||
mode = :new_comment
|
||||
comment_data = args.shift
|
||||
when '-h','--help'
|
||||
print_line "Usage: hosts [ options ] [addr1 addr2 ...]"
|
||||
print_line
|
||||
|
@ -279,6 +317,9 @@ class Db
|
|||
print_line " -o <file> Send output to a file in csv format"
|
||||
print_line " -R,--rhosts Set RHOSTS from the results of the search"
|
||||
print_line " -S,--search Search string to filter by"
|
||||
print_line " -i,--info Change the info of a host"
|
||||
print_line " -n,--name Change the name of a host"
|
||||
print_line " -m,--comment Change the comment of a host"
|
||||
print_line
|
||||
print_line "Available columns: #{default_columns.join(", ")}"
|
||||
print_line
|
||||
|
@ -317,6 +358,18 @@ class Db
|
|||
# Sentinal value meaning all
|
||||
host_ranges.push(nil) if host_ranges.empty?
|
||||
|
||||
case mode
|
||||
when :new_info
|
||||
change_host_info(host_ranges, info_data)
|
||||
return
|
||||
when :new_name
|
||||
change_host_name(host_ranges, name_data)
|
||||
return
|
||||
when :new_comment
|
||||
change_host_comment(host_ranges, comment_data)
|
||||
return
|
||||
end
|
||||
|
||||
each_host_range_chunk(host_ranges) do |host_search|
|
||||
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
|
||||
if search_term
|
||||
|
|
Loading…
Reference in New Issue