|
@@ -41,15 +41,19 @@ module RSeed
|
|
|
end
|
|
|
|
|
|
def auth!
|
|
|
- throw(:halt, [401, "Aweurglaweurglglglwargl !\n"]) if not auth?
|
|
|
+ if not auth?
|
|
|
+ redirect '/signin'
|
|
|
+ else
|
|
|
+ true
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
def auth?
|
|
|
@user = request.cookies["user"]
|
|
|
- @token = request.cookies["token"]
|
|
|
- check = Session.valid?(@user, @token)
|
|
|
+ @session = request.cookies["session"]
|
|
|
+ check = Session.valid?(@user, @session)
|
|
|
if !check
|
|
|
- puts "I think we have a problem with this session : #{@user.inspect}, #{@token.inspect}"
|
|
|
+ puts "I think we have a problem with this session : #{@user.inspect}, #{@session.inspect}"
|
|
|
end
|
|
|
check
|
|
|
end
|
|
@@ -75,17 +79,19 @@ module RSeed
|
|
|
end
|
|
|
|
|
|
post '/signin' do
|
|
|
- token = Session.signin(params[:username], params[:password])
|
|
|
+ user, session = Session.signin(params[:username], params[:password])
|
|
|
response.set_cookie("user", :value => params[:username], :path => '/', :expires => Time.now + 60*60*24*90)
|
|
|
- response.set_cookie("token", :value => token, :path => '/', :expires => Time.now + 60*60*24*90)
|
|
|
+ response.set_cookie("session", :value => session, :path => '/', :expires => Time.now + 60*60*24*90)
|
|
|
redirect '/'
|
|
|
end
|
|
|
|
|
|
# Index
|
|
|
# -----
|
|
|
get '/' do
|
|
|
- tlist = @rtorrent.getAll
|
|
|
- haml :index, :locals => { :tlist => tlist }
|
|
|
+ if auth!
|
|
|
+ tlist = @rtorrent.getAll
|
|
|
+ haml :index, :locals => { :tlist => tlist }
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
# DDL
|
|
@@ -116,13 +122,15 @@ module RSeed
|
|
|
# Public link generator
|
|
|
# ---------------------
|
|
|
post '/share' do
|
|
|
- fullhash = @rtorrent.getHash(params[:hash]).downcase
|
|
|
- if not publicLink(fullhash)
|
|
|
- File.open(@config.get('public_link_file_path'), 'a+') do |fd|
|
|
|
- fd.puts fullhash
|
|
|
+ if auth!
|
|
|
+ fullhash = @rtorrent.getHash(params[:hash]).downcase
|
|
|
+ if not publicLink(fullhash)
|
|
|
+ File.open(@config.get('public_link_file_path'), 'a+') do |fd|
|
|
|
+ fd.puts fullhash
|
|
|
+ end
|
|
|
end
|
|
|
+ return { "url" => url("/d/#{fullhash}"), "name" => @rtorrent.getName(fullhash) }.to_json
|
|
|
end
|
|
|
- return { "url" => url("/d/#{fullhash}"), "name" => @rtorrent.getName(fullhash) }.to_json
|
|
|
end
|
|
|
|
|
|
# Add Torrent File
|
|
@@ -134,10 +142,10 @@ module RSeed
|
|
|
post '/add/:type' do
|
|
|
case params[:type]
|
|
|
when 'file'
|
|
|
- File.open(@config.get("data_path") + "/" + params['torrentFile'][:filename], "w") do |f|
|
|
|
+ File.open(@config.get("data_path") + "/" + params[:torrentFile][:filename], "w") do |f|
|
|
|
f.write(params['torrentFile'][:tempfile].read)
|
|
|
end
|
|
|
- return "OK" if @rtorrent.add(params['torrentFile'][:filename])
|
|
|
+ return "Torrent added !" if @rtorrent.add(params[:torrentFile][:filename])
|
|
|
when 'link'
|
|
|
return "Torrent added !" if @rtorrent.add(params[:link])
|
|
|
when 't411'
|