furthering some changes that really should require a refactor
This commit is contained in:
parent
cc8be4e7ec
commit
aeb3c02989
@ -34,7 +34,7 @@ class BfLogin
|
||||
end
|
||||
|
||||
def add_pin_to_db(ip, pin)
|
||||
if @dbh[:pins].where(:ip => ip).count.eql?(0)
|
||||
unless self.pin_known?(ip)
|
||||
@dbh[:pins].insert(
|
||||
:ip => ip,
|
||||
:pin => pin,
|
||||
@ -46,6 +46,14 @@ class BfLogin
|
||||
@found[ip] = pin
|
||||
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+
|
||||
def get_request(uri, pin)
|
||||
request = Net::HTTP::Post.new(uri.request_uri)
|
||||
@ -76,8 +84,14 @@ class BfLogin
|
||||
|
||||
# return True|False
|
||||
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.open_timeout = 5
|
||||
@ -109,7 +123,7 @@ if address.nil?
|
||||
exit 1
|
||||
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
|
||||
|
||||
if mode.eql?(:ip)
|
||||
|
Loading…
Reference in New Issue
Block a user