furthering some changes that really should require a refactor

This commit is contained in:
Conor Horan-Kates 2017-02-09 15:57:58 -08:00
parent cc8be4e7ec
commit aeb3c02989

View File

@ -34,7 +34,7 @@ class BfLogin
end end
def add_pin_to_db(ip, pin) def add_pin_to_db(ip, pin)
if @dbh[:pins].where(:ip => ip).count.eql?(0) unless self.pin_known?(ip)
@dbh[:pins].insert( @dbh[:pins].insert(
:ip => ip, :ip => ip,
:pin => pin, :pin => pin,
@ -46,6 +46,14 @@ class BfLogin
@found[ip] = pin @found[ip] = pin
end end
def pin_known?(ip)
@dbh[:pins].where(:ip => ip).count > 0
end
def get_pin(ip)
@dbh[:pins].select(:pin).where(:ip => ip).all.first[:pin]
end
# return a Net::HTTP::Post request suitable for validating +pin+ # return a Net::HTTP::Post request suitable for validating +pin+
def get_request(uri, pin) def get_request(uri, pin)
request = Net::HTTP::Post.new(uri.request_uri) request = Net::HTTP::Post.new(uri.request_uri)
@ -76,8 +84,14 @@ class BfLogin
# return True|False # return True|False
def check_pin(url, pin) def check_pin(url, pin)
uri = URI.parse(url)
if self.pin_known?(uri.host)
kp = self.get_pin(uri.host)
raise BfLoginError.new(sprintf('host[%s] pin is already known[%s]', uri.host, kp))
end
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 5 http.open_timeout = 5
@ -109,7 +123,7 @@ if address.nil?
exit 1 exit 1
end end
mode = address.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) ? :ip : :range mode = address.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) ? :ip : :range
targets = Array.new targets = Array.new
if mode.eql?(:ip) if mode.eql?(:ip)