Added Dns::Server attribute to DNS REST router.

This is primarily intended to add clarity by reducing clutter. Moreover,
it also has the side effect of improving performance very slightly by
removing the overhead of calling #instance numerous times.
This commit is contained in:
soh_cah_toa
2014-04-25 10:14:05 -04:00
parent 2e318030da
commit 1d5afbb81e

View File

@@ -12,6 +12,7 @@ module BeEF
# Filters out bad requests before performing any routing # Filters out bad requests before performing any routing
before do before do
@dns ||= BeEF::Extension::Dns::Server.instance
config = BeEF::Core::Configuration.instance config = BeEF::Core::Configuration.instance
# Require a valid API token from a valid IP address # Require a valid API token from a valid IP address
@@ -27,7 +28,7 @@ module BeEF
# Returns the entire current DNS ruleset # Returns the entire current DNS ruleset
get '/ruleset' do get '/ruleset' do
begin begin
ruleset = BeEF::Extension::Dns::Server.instance.get_ruleset ruleset = @dns.get_ruleset
count = ruleset.length count = ruleset.length
result = {} result = {}
@@ -45,7 +46,7 @@ module BeEF
begin begin
id = params[:id] id = params[:id]
rule = BeEF::Extension::Dns::Server.instance.get_rule(id) rule = @dns.get_rule(id)
raise InvalidParamError, 'id' if rule.nil? raise InvalidParamError, 'id' if rule.nil?
halt 404 if rule.empty? halt 404 if rule.empty?
@@ -80,7 +81,7 @@ module BeEF
raise InvalidJsonError, 'Wrong "resource" key passed to endpoint /api/dns/rule' unless valid_resources.include?(resource) raise InvalidJsonError, 'Wrong "resource" key passed to endpoint /api/dns/rule' unless valid_resources.include?(resource)
id = BeEF::Extension::Dns::Server.instance.add_rule( id = @dns.add_rule(
:pattern => pattern, :pattern => pattern,
:resource => eval("Resolv::DNS::Resource::IN::#{resource}"), :resource => eval("Resolv::DNS::Resource::IN::#{resource}"),
:response => response :response => response
@@ -105,7 +106,7 @@ module BeEF
begin begin
id = params[:id] id = params[:id]
removed = BeEF::Extension::Dns::Server.instance.remove_rule!(id) removed = @dns.remove_rule!(id)
raise InvalidParamError, 'id' if removed.nil? raise InvalidParamError, 'id' if removed.nil?
result = {} result = {}