use web app for bans, not system

This commit is contained in:
Kyle Drake 2014-06-27 21:23:28 -04:00
parent ab95fa01af
commit a420132632
5 changed files with 26 additions and 8 deletions

View file

@ -59,6 +59,8 @@ class Site < Sequel::Model
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205']
THUMBNAIL_RESOLUTIONS = ['105x63', '90x63']
BANNED_TIME = 2592000 # 30 days in seconds
many_to_one :server
many_to_many :tags
@ -103,6 +105,13 @@ class Site < Sequel::Model
end
end
def self.banned_ip?(ip)
!Site.where(is_banned: true).
where(ip: ip).
where(['updated_at > ?', Time.now-BANNED_TIME]).
first.nil?
end
def is_following?(site)
followings_dataset.select(:id).filter(site_id: site.id).first ? true : false
end
@ -186,11 +195,7 @@ class Site < Sequel::Model
DB.transaction {
FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username)
self.is_banned = true
if !['127.0.0.1', nil, ''].include? ip
`sudo ufw insert 1 deny from #{ip}`
end
self.updated_at = Time.now
save(validate: false)
}
end