secret zone dont look at this commit

This commit is contained in:
Kyle Drake 2013-06-22 23:21:41 -07:00
parent 5e7346300e
commit 7ed7ad183e
4 changed files with 49 additions and 14 deletions

33
app.rb
View file

@ -20,7 +20,7 @@ end
get '/browse' do get '/browse' do
@current_page = params[:current_page] || 1 @current_page = params[:current_page] || 1
@current_page = @current_page.to_i @current_page = @current_page.to_i
site_dataset = Site.order(:hits.desc, :updated_at.desc).filter(~{updated_at: nil}).paginate(@current_page, 100) site_dataset = Site.order(:hits.desc, :updated_at.desc).filter(is_banned: false).filter(~{updated_at: nil}).paginate(@current_page, 100)
@page_count = site_dataset.page_count || 1 @page_count = site_dataset.page_count || 1
@sites = site_dataset.all @sites = site_dataset.all
slim :browse slim :browse
@ -55,10 +55,7 @@ post '/create' do
DB.transaction { DB.transaction {
@site.save @site.save
begin FileUtils.mkdir base_path
FileUtils.mkdir base_path
rescue Errno::EEXIST
end
File.write File.join(base_path, 'index.html'), slim(:'templates/index', pretty: true, layout: false) File.write File.join(base_path, 'index.html'), slim(:'templates/index', pretty: true, layout: false)
File.write File.join(base_path, 'not_found.html'), slim(:'templates/not_found', pretty: true, layout: false) File.write File.join(base_path, 'not_found.html'), slim(:'templates/not_found', pretty: true, layout: false)
@ -77,6 +74,12 @@ post '/signin' do
dashboard_if_signed_in dashboard_if_signed_in
if Site.valid_login? params[:username], params[:password] if Site.valid_login? params[:username], params[:password]
site = Site[username: params[:username]] site = Site[username: params[:username]]
if site.is_banned
flash[:error] = 'Invalid login.'
redirect '/signin'
end
session[:id] = site.id session[:id] = site.id
redirect '/dashboard' redirect '/dashboard'
else else
@ -211,15 +214,31 @@ end
get '/admin' do get '/admin' do
require_admin require_admin
@banned_sites = Site.filter(is_banned: true).order(:username).all
slim :'admin' slim :'admin'
end end
post '/admin/banhammer' do post '/admin/banhammer' do
require_admin require_admin
site = Site[username: params[:username]] site = Site[username: params[:username]]
binding.pry
if site.is_banned
flash[:error] = 'User is already banned'
redirect '/admin'
end
if site.nil?
flash[:error] = 'User not found'
redirect '/admin'
end
DB.transaction {
FileUtils.mv site_base_path(site.username), File.join(settings.public_folder, 'banned_sites', site.username)
site.update is_banned: true
}
flash[:success] = 'MISSION ACCOMPLISHED' flash[:success] = 'MISSION ACCOMPLISHED'
redirect '/admin'
end end
def require_admin def require_admin

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :is_banned, :boolean, default: false
}
down {
DB.add_column :sites, :is_banned
}
end

View file

@ -65,10 +65,10 @@ class Site < Sequel::Model
super super
end end
def after_destroy # def after_destroy
FileUtils.rm_rf file_path # FileUtils.rm_rf file_path
super # super
end # end
def validate def validate
super super

View file

@ -1,12 +1,19 @@
.row .row
.span12 .span12
h1 SECRET NSA BACKDOOR REPORTING ZONE h1 SECRET NSA BACKDOOR REPORTING ZONE
.row
.span6
h2 Ban User for REASONS OF TERRRROROR! h2 Ban User for REASONS OF TERRRROROR!
form action="/admin/banhammer" method="POST" form action="/admin/banhammer" method="POST"
input name="csrf_token" type="hidden" value="#{csrf_token}" input name="csrf_token" type="hidden" value="#{csrf_token}"
p TerrRRRROR Suspect: p TerrRRRROR Suspect:
input type="text" name="username" place="" input type="text" name="username" placeholder="edwardsnowden"
br br
input.btn.btn-danger type="submit" value="Warrantlessly Delete" input.btn.btn-danger type="submit" value="Ban"
.span6
h2 Banned Terrorists
- @banned_sites.each do |banned_site|
= banned_site.username