mirror of
https://github.com/neocities/neocities.git
synced 2025-04-28 11:12:30 +02:00
PAY NO ATTENTION TO THIS COMMIT, NOTHING TO SEE HERE
This commit is contained in:
parent
2a54b5c0c3
commit
5e7346300e
4 changed files with 64 additions and 14 deletions
17
app.rb
17
app.rb
|
@ -209,6 +209,23 @@ get '/privacy' do
|
||||||
slim :'privacy'
|
slim :'privacy'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/admin' do
|
||||||
|
require_admin
|
||||||
|
slim :'admin'
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/admin/banhammer' do
|
||||||
|
require_admin
|
||||||
|
site = Site[username: params[:username]]
|
||||||
|
binding.pry
|
||||||
|
|
||||||
|
flash[:success] = 'MISSION ACCOMPLISHED'
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_admin
|
||||||
|
redirect '/' unless signed_in? && current_site.is_admin
|
||||||
|
end
|
||||||
|
|
||||||
def dashboard_if_signed_in
|
def dashboard_if_signed_in
|
||||||
redirect '/dashboard' if signed_in?
|
redirect '/dashboard' if signed_in?
|
||||||
end
|
end
|
||||||
|
|
9
migrations/011_add_admin_flag.rb
Normal file
9
migrations/011_add_admin_flag.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Sequel.migration do
|
||||||
|
up {
|
||||||
|
DB.add_column :sites, :is_admin, :boolean, default: false
|
||||||
|
}
|
||||||
|
|
||||||
|
down {
|
||||||
|
DB.add_column :sites, :is_admin
|
||||||
|
}
|
||||||
|
end
|
|
@ -39,18 +39,6 @@ class Site < Sequel::Model
|
||||||
values[:password] = BCrypt::Password.create plaintext, cost: (self.class.bcrypt_cost || BCrypt::Engine::DEFAULT_COST)
|
values[:password] = BCrypt::Password.create plaintext, cost: (self.class.bcrypt_cost || BCrypt::Engine::DEFAULT_COST)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_save
|
|
||||||
if @new_tag_strings
|
|
||||||
@new_tag_strings.each do |new_tag_string|
|
|
||||||
add_tag Tag[name: new_tag_string] || Tag.create(name: new_tag_string)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_create
|
|
||||||
DB['update servers set slots_available=slots_available-1 where id=?', self.server.id].first
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_tags=(tags_string)
|
def new_tags=(tags_string)
|
||||||
tags_string.gsub! /[^a-zA-Z0-9, ]/, ''
|
tags_string.gsub! /[^a-zA-Z0-9, ]/, ''
|
||||||
tags = tags_string.split ','
|
tags = tags_string.split ','
|
||||||
|
@ -60,6 +48,26 @@ class Site < Sequel::Model
|
||||||
|
|
||||||
def before_validation
|
def before_validation
|
||||||
self.server ||= Server.with_slots_available
|
self.server ||= Server.with_slots_available
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_save
|
||||||
|
if @new_tag_strings
|
||||||
|
@new_tag_strings.each do |new_tag_string|
|
||||||
|
add_tag Tag[name: new_tag_string] || Tag.create(name: new_tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_create
|
||||||
|
DB['update servers set slots_available=slots_available-1 where id=?', self.server.id].first
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_destroy
|
||||||
|
FileUtils.rm_rf file_path
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
|
@ -88,12 +96,16 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_path
|
||||||
|
File.join DIR_ROOT, 'public', 'sites', username
|
||||||
|
end
|
||||||
|
|
||||||
def file_list
|
def file_list
|
||||||
Dir.glob(File.join(DIR_ROOT, 'public', 'sites', username, '*')).collect {|p| File.basename(p)}.sort.collect {|sitename| SiteFile.new sitename}
|
Dir.glob(File.join(file_path, '*')).collect {|p| File.basename(p)}.sort.collect {|sitename| SiteFile.new sitename}
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_space
|
def total_space
|
||||||
space = Dir.glob(File.join(DIR_ROOT, 'public', 'sites', username, '*')).collect {|p| File.size(p)}.inject {|sum,x| sum += x}
|
space = Dir.glob(File.join(file_path, '*')).collect {|p| File.size(p)}.inject {|sum,x| sum += x}
|
||||||
space.nil? ? 0 : space
|
space.nil? ? 0 : space
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
12
views/admin.slim
Normal file
12
views/admin.slim
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
.row
|
||||||
|
.span12
|
||||||
|
h1 SECRET NSA BACKDOOR REPORTING ZONE
|
||||||
|
|
||||||
|
h2 Ban User for REASONS OF TERRRROROR!
|
||||||
|
|
||||||
|
form action="/admin/banhammer" method="POST"
|
||||||
|
input name="csrf_token" type="hidden" value="#{csrf_token}"
|
||||||
|
p TerrRRRROR Suspect:
|
||||||
|
input type="text" name="username" place=""
|
||||||
|
br
|
||||||
|
input.btn.btn-danger type="submit" value="Warrantlessly Delete"
|
Loading…
Add table
Reference in a new issue