2020-11-30 05:09:18 +00:00
|
|
|
require 'msf/core/db_manager/session'
|
|
|
|
|
|
2014-10-13 11:23:37 -05:00
|
|
|
module Msf::DBManager::Route
|
2020-11-30 05:09:18 +00:00
|
|
|
def report_session_route(opts)
|
2014-10-13 11:23:37 -05:00
|
|
|
return if not active
|
2020-11-30 05:09:18 +00:00
|
|
|
session = opts[:session]
|
|
|
|
|
route = opts[:route]
|
2014-10-13 11:23:37 -05:00
|
|
|
if session.respond_to? :db_record
|
|
|
|
|
s = session.db_record
|
2020-12-14 15:47:59 +00:00
|
|
|
elsif session.is_a?(Hash) && session.key?(:id)
|
|
|
|
|
s = Mdm::Session.find(session[:id])
|
2014-10-13 11:23:37 -05:00
|
|
|
else
|
|
|
|
|
s = session
|
|
|
|
|
end
|
|
|
|
|
unless s.respond_to?(:routes)
|
|
|
|
|
raise ArgumentError.new("Invalid :session, expected Session object got #{session.class}")
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-03 09:38:15 -05:00
|
|
|
::ApplicationRecord.connection_pool.with_connection {
|
2014-10-13 11:23:37 -05:00
|
|
|
|
|
|
|
|
subnet, netmask = route.split("/")
|
|
|
|
|
s.routes.create(:subnet => subnet, :netmask => netmask)
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2020-11-30 05:09:18 +00:00
|
|
|
def report_session_route_remove(opts)
|
2014-10-13 11:23:37 -05:00
|
|
|
return if not active
|
2020-11-30 05:09:18 +00:00
|
|
|
session = opts[:session]
|
|
|
|
|
route = opts[:route]
|
2014-10-13 11:23:37 -05:00
|
|
|
if session.respond_to? :db_record
|
|
|
|
|
s = session.db_record
|
2020-12-14 15:47:59 +00:00
|
|
|
elsif session.is_a?(Hash) && session.key?(:id)
|
|
|
|
|
s = Mdm::Session.find(session[:id])
|
2014-10-13 11:23:37 -05:00
|
|
|
else
|
|
|
|
|
s = session
|
|
|
|
|
end
|
|
|
|
|
unless s.respond_to?(:routes)
|
|
|
|
|
raise ArgumentError.new("Invalid :session, expected Session object got #{session.class}")
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-03 09:38:15 -05:00
|
|
|
::ApplicationRecord.connection_pool.with_connection {
|
2014-10-13 11:23:37 -05:00
|
|
|
subnet, netmask = route.split("/")
|
|
|
|
|
r = s.routes.find_by_subnet_and_netmask(subnet, netmask)
|
|
|
|
|
r.destroy if r
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-03 09:38:15 -05:00
|
|
|
end
|