Skip to content

Commit

Permalink
vpn, proxy and tor detection working
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadKennedyx committed Jan 11, 2024
1 parent 12a3d10 commit 8e611f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/usual_suspect/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# lib/usual_suspect/configuration.rb
module UsualSuspect
class Configuration
attr_accessor :block_criteria
attr_accessor :vpn_api_key

def initialize
@block_criteria = []
@vpn_api_key = nil
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class CreateUsualSuspectEvents < ActiveRecord::Migration[6.0]
t.datetime :sign_in_at
t.boolean :password_change_after_login
t.boolean :geovelocity_failed
t.boolean :vpn_usage
t.boolean :using_vpn
t.boolean :using_proxy
t.boolean :using_tor
t.string :sign_in_ip
t.string :city
t.string :country
Expand Down
6 changes: 5 additions & 1 deletion lib/usual_suspect/user_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ module UserExtension

def update_login(ip, location, session_token)
event = UsualSuspectEvent.new(user: self, session_token: session_token)
vpn_tor_proxy_usage = UsualSuspect::VpnChecker.check_vpn(ip)

event.assign_attributes(
sign_in_at: Time.current,
sign_in_ip: ip,
city: location.city,
country: location.country,
latitude: location.latitude,
longitude: location.longitude
longitude: location.longitude,
using_vpn: vpn_tor_proxy_usage['security']['vpn'],
using_proxy: vpn_tor_proxy_usage['security']['proxy'],
using_tor: vpn_tor_proxy_usage['security']['tor'],
)

event.save
Expand Down
20 changes: 20 additions & 0 deletions lib/usual_suspect/vpn_checker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module UsualSuspect
module VpnChecker
def self.check_vpn(ip_address)
api_key = UsualSuspect.configuration.vpn_api_key
return false unless api_key

# Call IP2Location API
# Example URL (adjust according to IP2Location's API documentation)
url = "https://vpnapi.io/api/#{ip_address}?key=#{api_key}"

response = Net::HTTP.get(URI(url))
result = JSON.parse(response)

result
rescue => e
# Handle errors (e.g., network issues, invalid response)
false
end
end
end

0 comments on commit 8e611f5

Please sign in to comment.