From 669ce7abd7d6b632bf1844afdb2cf0b28e1efed6 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Wed, 22 Jun 2016 07:04:12 +0200 Subject: faster, better, stronger --- .gitignore | 2 ++ README | 2 ++ config.ru | 2 +- file_upload.rb | 13 ++++++++----- public/main.css | 16 ++++++++++++++++ public/upload.html | 7 +++++-- views/index.haml | 43 +++++++++++++++++++++++++++---------------- 7 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 public/main.css diff --git a/.gitignore b/.gitignore index 8b13789..40dee6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +upload/* +log diff --git a/README b/README index 51f5daa..691b440 100644 --- a/README +++ b/README @@ -1,2 +1,4 @@ rackup config.ru +iptables -i eth2 -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000 + diff --git a/config.ru b/config.ru index 0c8b758..55c1ebc 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ require './file_upload' -run FileUpload +FileUpload.run! diff --git a/file_upload.rb b/file_upload.rb index 5bb1d44..0599ef3 100644 --- a/file_upload.rb +++ b/file_upload.rb @@ -1,4 +1,4 @@ -require 'sinatra/base' +require 'sinatra' require 'haml' class FileUpload < Sinatra::Base @@ -6,6 +6,9 @@ class FileUpload < Sinatra::Base enable :static enable :sessions + #set :bind, 'upload.simianer.de' + set :port, 8000 + set :environment, :production set :views, File.join(File.dirname(__FILE__), 'views') set :public_folder, File.join(File.dirname(__FILE__), 'public') end @@ -30,12 +33,12 @@ class FileUpload < Sinatra::Base saved_token = `cat #{dir}/.token`.strip if token == saved_token return true - end + end return false end def check_dirname dirname - return dirname.match /^[a-zA-Z0-9_-]+$/ + return dirname.match /^[a-zA-Z0-9_]+$/ end def get_dir dirname @@ -101,7 +104,7 @@ class FileUpload < Sinatra::Base get "/list_dir/:dirname/:token" do log '/list_dir', params - + dirname = params[:dirname] dir = get_dir dirname token = params[:token] @@ -110,7 +113,7 @@ class FileUpload < Sinatra::Base if allowed s = "