commit
2f86874c6c
@ -1,2 +1,3 @@
|
||||
require 'trustie/utils'
|
||||
require 'trustie/utils/image'
|
||||
require 'trustie/grack/grack'
|
||||
|
@ -0,0 +1,55 @@
|
||||
require 'rack/auth/basic'
|
||||
require 'rack/auth/abstract/handler'
|
||||
require 'rack/auth/abstract/request'
|
||||
|
||||
module Grack
|
||||
class Auth < Rack::Auth::Basic
|
||||
def call(env)
|
||||
@env = env
|
||||
@request = Rack::Request.new(env)
|
||||
@auth = Request.new(env)
|
||||
|
||||
if not @auth.provided?
|
||||
unauthorized
|
||||
elsif not @auth.basic?
|
||||
bad_request
|
||||
else
|
||||
result = if (access = valid?(@auth) and access == true)
|
||||
@env['REMOTE_USER'] = @auth.username
|
||||
@app.call(env)
|
||||
else
|
||||
if access == '404'
|
||||
render_not_found
|
||||
elsif access == '403'
|
||||
#render_no_access
|
||||
unauthorized
|
||||
else
|
||||
unauthorized
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
end# method call
|
||||
|
||||
|
||||
def render_not_found
|
||||
[404, {"Content-Type" => "text/plain"}, ["Not Found"]]
|
||||
end
|
||||
|
||||
def valid?(auth)
|
||||
match = @request.path_info.match(/(\/.+\.git)\//)
|
||||
if match
|
||||
rep = Repository.where("root_url like ?", "%#{match[1]}")
|
||||
return "404" if rep.empty?
|
||||
username, password = auth.credentials
|
||||
user, last_login_on = User.try_to_login(username, password)
|
||||
return '403' unless user
|
||||
if user.member_of?(rep.first.project) || user.admin?
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
end# class Auth
|
||||
end# module Grack
|
||||
|
@ -0,0 +1,18 @@
|
||||
require_relative 'auth'
|
||||
|
||||
module Trustie
|
||||
module Grack
|
||||
|
||||
def self.new
|
||||
Rack::Builder.new do
|
||||
use ::Grack::Auth
|
||||
run ::Grack::Server.new(
|
||||
project_root: Redmine::Configuration['repository_root_path'] || "/home/pdl/redmine-2.3.2-0/apache2/htdocs",
|
||||
upload_pack: true,
|
||||
receive_pack:true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in new issue