diff options
Diffstat (limited to 'app/models/intruder.rb')
-rw-r--r-- | app/models/intruder.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/intruder.rb b/app/models/intruder.rb new file mode 100644 index 0000000..db14bf8 --- /dev/null +++ b/app/models/intruder.rb @@ -0,0 +1,37 @@ +class Intruder < ActiveRecord::Base + attr_accessible :list_type, :key, :points, :bans, :ban_last, :ban_end, :contact_ip, :contact_port, :contact_count, :contact_last, :contacts_per_second, :contacts_per_second_max, :user_agent, :to_user, :comment + + LIST_TYPES = ['blacklist', 'whitelist'] + + validates :list_type, + :presence => true, + :inclusion => { :in => LIST_TYPES } + + validates :key, + :presence => true, + :uniqueness => true + + validates :contact_ip, + :presence => true, + :uniqueness => true + + before_validation :set_key_if_empty + + + def whois + if ! self.contact_ip.blank? + begin + return Whois.whois(self.contact_ip) + rescue + return nil + end + end + end + + private + def set_key_if_empty + if self.key.blank? + self.key = self.contact_ip + end + end +end |