Commit ec9e54ea9496ed98b6400b479f50e19b89f3dcb4

Authored by gitlabhq
1 parent d7ea9052

gitosis error handle

app/controllers/application_controller.rb
@@ -4,6 +4,10 @@ class ApplicationController < ActionController::Base @@ -4,6 +4,10 @@ class ApplicationController < ActionController::Base
4 4
5 helper_method :abilities, :can? 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 protected 11 protected
8 12
9 def abilities 13 def abilities
app/controllers/errors_controller.rb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +class ErrorsController < ApplicationController
  2 + def gitosis
  3 + render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false
  4 + end
  5 +end
app/controllers/projects_controller.rb
@@ -105,6 +105,8 @@ class ProjectsController &lt; ApplicationController @@ -105,6 +105,8 @@ class ProjectsController &lt; ApplicationController
105 format.json { render json: @project.errors, status: :unprocessable_entity } 105 format.json { render json: @project.errors, status: :unprocessable_entity }
106 end 106 end
107 end 107 end
  108 + rescue Gitosis::AccessDenied
  109 + render :js => "location.href = '#{errors_gitosis_path}'" and return
108 rescue StandardError => ex 110 rescue StandardError => ex
109 @project.errors.add(:base, "Cant save project. Please try again later") 111 @project.errors.add(:base, "Cant save project. Please try again later")
110 respond_to do |format| 112 respond_to do |format|
config/application.rb
@@ -16,7 +16,7 @@ module Gitlab @@ -16,7 +16,7 @@ module Gitlab
16 # -- all .rb files in that directory are automatically loaded. 16 # -- all .rb files in that directory are automatically loaded.
17 17
18 # Custom directories with classes and modules you want to be autoloadable. 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 # Only load the plugins named here, in the order given (default is alphabetical). 21 # Only load the plugins named here, in the order given (default is alphabetical).
22 # :all can be used as a placeholder for all plugins not explicitly named. 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,6 +10,7 @@ Gitlab::Application.routes.draw do
10 root :to => "users#index" 10 root :to => "users#index"
11 end 11 end
12 12
  13 + get "errors/gitosis"
13 get "profile/password", :to => "profile#password" 14 get "profile/password", :to => "profile#password"
14 put "profile/password", :to => "profile#password_update" 15 put "profile/password", :to => "profile#password_update"
15 get "profile", :to => "profile#show" 16 get "profile", :to => "profile#show"
lib/gitosis.rb
1 require 'inifile' 1 require 'inifile'
2 - 2 +require 'timeout'
3 class Gitosis 3 class Gitosis
  4 + class AccessDenied < StandardError; end
4 5
5 def pull 6 def pull
6 # create tmp dir 7 # create tmp dir
@@ -20,15 +21,19 @@ class Gitosis @@ -20,15 +21,19 @@ class Gitosis
20 end 21 end
21 22
22 def configure 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 f.flock(File::LOCK_EX) 26 f.flock(File::LOCK_EX)
25 - 27 +
26 pull 28 pull
27 yield(self) 29 yield(self)
28 push 30 push
29 - 31 +
30 f.flock(File::LOCK_UN) 32 f.flock(File::LOCK_UN)
31 - end 33 + end
  34 + }
  35 + rescue Exception => ex
  36 + raise Gitosis::AccessDenied.new("gitosis timeout")
32 end 37 end
33 38
34 def destroy_project(project) 39 def destroy_project(project)
@@ -51,7 +56,7 @@ class Gitosis @@ -51,7 +56,7 @@ class Gitosis
51 `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub` 56 `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
52 end 57 end
53 58
54 - #update or create 59 + #update or create
55 def update_project(repo_name, name_writers) 60 def update_project(repo_name, name_writers)
56 # write config file 61 # write config file
57 conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) 62 conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
@@ -61,5 +66,4 @@ class Gitosis @@ -61,5 +66,4 @@ class Gitosis
61 66
62 conf.write 67 conf.write
63 end 68 end
64 -  
65 end 69 end
public/gitosis_error.html 0 → 100644
@@ -0,0 +1,26 @@ @@ -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>