From f877e8ad7899be2804dbb596468b81dfeb769bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Mon, 31 Jul 2017 23:45:31 +0200 Subject: [PATCH] write filenames of uploaded files to log file --- server.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server.rb b/server.rb index 2a870c1..8c90e19 100644 --- a/server.rb +++ b/server.rb @@ -1,9 +1,9 @@ require 'sinatra' -set :bind, '0.0.0.0' +set :bind, '127.0.0.1' set :port, '35257' -USERS = { 'christoffermadsen' => 'lolol', 'gre' => 'lol'} +USERS = { 'christoffermadsen' => 'lolol' } FILENAME_GENERATOR = lambda {rand(36**6).to_s(36)} @@ -25,9 +25,14 @@ post '/upload' do impure_filename = (request['filename'] || FILENAME_GENERATOR.call) << ".png" filename = sanitize_filename(impure_filename) - File.open filename, 'w+' do |f| + puts ENV['HOME'] + File.open "#{ENV['HOME']}/public_html/screenshots/#{filename}", 'w+' do |f| f << request['imagedata'][:tempfile].read end + + File.open "uploads.log", 'a+' do |log| + log << filename + end return [200, filename] end