Commit ec9e54ea9496ed98b6400b479f50e19b89f3dcb4
1 parent
d7ea9052
Exists in
master
and in
4 other branches
gitosis error handle
Showing
7 changed files
with
50 additions
and
8 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -4,6 +4,10 @@ class ApplicationController < ActionController::Base |
4 | 4 | |
5 | 5 | helper_method :abilities, :can? |
6 | 6 | |
7 | + rescue_from Gitosis::AccessDenied do |exception| | |
8 | + render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false | |
9 | + end | |
10 | + | |
7 | 11 | protected |
8 | 12 | |
9 | 13 | def abilities | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -105,6 +105,8 @@ class ProjectsController < ApplicationController |
105 | 105 | format.json { render json: @project.errors, status: :unprocessable_entity } |
106 | 106 | end |
107 | 107 | end |
108 | + rescue Gitosis::AccessDenied | |
109 | + render :js => "location.href = '#{errors_gitosis_path}'" and return | |
108 | 110 | rescue StandardError => ex |
109 | 111 | @project.errors.add(:base, "Cant save project. Please try again later") |
110 | 112 | respond_to do |format| | ... | ... |
config/application.rb
... | ... | @@ -16,7 +16,7 @@ module Gitlab |
16 | 16 | # -- all .rb files in that directory are automatically loaded. |
17 | 17 | |
18 | 18 | # Custom directories with classes and modules you want to be autoloadable. |
19 | - # config.autoload_paths += %W(#{config.root}/extras) | |
19 | + config.autoload_paths += %W(#{config.root}/lib) | |
20 | 20 | |
21 | 21 | # Only load the plugins named here, in the order given (default is alphabetical). |
22 | 22 | # :all can be used as a placeholder for all plugins not explicitly named. | ... | ... |
config/routes.rb
... | ... | @@ -10,6 +10,7 @@ Gitlab::Application.routes.draw do |
10 | 10 | root :to => "users#index" |
11 | 11 | end |
12 | 12 | |
13 | + get "errors/gitosis" | |
13 | 14 | get "profile/password", :to => "profile#password" |
14 | 15 | put "profile/password", :to => "profile#password_update" |
15 | 16 | get "profile", :to => "profile#show" | ... | ... |
lib/gitosis.rb
1 | 1 | require 'inifile' |
2 | - | |
2 | +require 'timeout' | |
3 | 3 | class Gitosis |
4 | + class AccessDenied < StandardError; end | |
4 | 5 | |
5 | 6 | def pull |
6 | 7 | # create tmp dir |
... | ... | @@ -20,15 +21,19 @@ class Gitosis |
20 | 21 | end |
21 | 22 | |
22 | 23 | def configure |
23 | - File.open(File.join(Dir.tmpdir,"gitme-gitosis.lock"), "w+") do |f| | |
24 | + status = Timeout::timeout(5) { | |
25 | + File.open(File.join(Dir.tmpdir,"gitme-gitosis.lock"), "w+") do |f| | |
24 | 26 | f.flock(File::LOCK_EX) |
25 | - | |
27 | + | |
26 | 28 | pull |
27 | 29 | yield(self) |
28 | 30 | push |
29 | - | |
31 | + | |
30 | 32 | f.flock(File::LOCK_UN) |
31 | - end | |
33 | + end | |
34 | + } | |
35 | + rescue Exception => ex | |
36 | + raise Gitosis::AccessDenied.new("gitosis timeout") | |
32 | 37 | end |
33 | 38 | |
34 | 39 | def destroy_project(project) |
... | ... | @@ -51,7 +56,7 @@ class Gitosis |
51 | 56 | `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub` |
52 | 57 | end |
53 | 58 | |
54 | - #update or create | |
59 | + #update or create | |
55 | 60 | def update_project(repo_name, name_writers) |
56 | 61 | # write config file |
57 | 62 | conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) |
... | ... | @@ -61,5 +66,4 @@ class Gitosis |
61 | 66 | |
62 | 67 | conf.write |
63 | 68 | end |
64 | - | |
65 | 69 | end | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html> | |
3 | +<head> | |
4 | + <title>We're sorry, but we cant get access to your gitosis</title> | |
5 | + <style type="text/css"> | |
6 | + body { background-color: #EAEAEA; color: #666; text-align: center; font-family: arial, sans-serif; } | |
7 | + div.dialog { | |
8 | + width: 600px; | |
9 | + padding: 0 4em; | |
10 | + margin: 4em auto 0 auto; | |
11 | + } | |
12 | + h1 { font-size: 48px; color: #444; line-height: 1.5em; } | |
13 | + h2 { font-size: 24px; color: #666; line-height: 1.5em; } | |
14 | + </style> | |
15 | +</head> | |
16 | + | |
17 | +<body> | |
18 | + <!-- This file lives in public/500.html --> | |
19 | + <div class="dialog"> | |
20 | + <h1>Gitosis Error</h1> | |
21 | + <h2>We're sorry, but we cant get access to your gitosis.</h2> | |
22 | + <h3> 1. Check 'config/gitosis.yml' for correct settings.</h3> | |
23 | + <h3> 2. Be sure web server user has access to gitosis.</h3> | |
24 | + </div> | |
25 | +</body> | |
26 | +</html> | ... | ... |