diff -Nur redmine-0.6.3/app/apis/sys_api.rb redmine-0.6.3-patched/app/apis/sys_api.rb
--- redmine-0.6.3/app/apis/sys_api.rb 2007-12-18 19:17:39.000000000 +0100
+++ redmine-0.6.3-patched/app/apis/sys_api.rb 2008-04-11 22:10:28.000000000 +0200
@@ -22,4 +22,10 @@
api_method :repository_created,
:expects => [:string, :string],
:returns => [:int]
+ api_method :is_public_project,
+ :expects => [:string],
+ :returns => [:int]
+ api_method :can_access_repository,
+ :expects => [:string, :string, :string, :string],
+ :returns => [:int]
end
diff -Nur redmine-0.6.3/app/controllers/sys_controller.rb redmine-0.6.3-patched/app/controllers/sys_controller.rb
--- redmine-0.6.3/app/controllers/sys_controller.rb 2007-12-18 19:17:39.000000000 +0100
+++ redmine-0.6.3-patched/app/controllers/sys_controller.rb 2008-04-11 22:28:10.000000000 +0200
@@ -15,6 +15,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+require 'openssl'
+require 'digest/sha2'
+
class SysController < ActionController::Base
wsdl_service_name 'Sys'
web_service_api SysApi
@@ -39,6 +50,48 @@
repository.id || 0
end
+ def is_public_project(repository)
+ begin
+ project = Project.find_by_repository(Regexp.new('.*/'+Regexp.escape(repository)+'/?$'))
+
+ return 0 if project.nil?
+ return 0 unless project.is_public
+ return 1
+ rescue
+ return 0
+ end
+ end
+
+ def can_access_repository(repository,login,ciphered_pwd_hex,iv_hex)
+ begin
+ # Decipher the password
+ key = Digest::SHA256.digest(Setting.repositories_key)
+ ciphered_pwd = ciphered_pwd_hex.gsub(/(..)/){|h| h.hex.chr}
+ iv = iv_hex.gsub(/(..)/){|h| h.hex.chr}
+
+ cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
+ cipher.key = key
+ cipher.iv = iv
+ cipher.decrypt
+
+ pwd = cipher.update(ciphered_pwd)
+ pwd << cipher.final
+
+ # Then, try to login
+ user = User.try_to_login(login, pwd)
+ return 0 unless user!=nil
+
+ project = Project.find_by_repository(Regexp.new('.*/'+Regexp.escape(repository)+'/?$'))
+ logger.debug "Requesting access for project: #{project.name}"
+ return 0 unless user.member_of?(project)
+ return 0 unless user.allowed_to?(:browse_repository, project)
+ return 1 unless user.allowed_to?(:commit_repository, project)
+ return 2
+ rescue
+ return 0
+ end
+ end
+
protected
def check_enabled(name, args)
diff -Nur redmine-0.6.3/app/models/project.rb redmine-0.6.3-patched/app/models/project.rb
--- redmine-0.6.3/app/models/project.rb 2007-12-18 19:17:39.000000000 +0100
+++ redmine-0.6.3-patched/app/models/project.rb 2008-04-09 15:05:50.000000000 +0200
@@ -182,6 +182,14 @@
end
end
+ def self.find_by_repository(repository_wildcard)
+ project = Project.find_by_identifier(repository_wildcard)
+ return project unless project.nil? || project.repository.nil? || !project.repository.url=~repository_wildcard
+ Project.find(:all, :include => :repository).each do |project|
+ return project if !project.repository.nil? && project.repository.url=~repository_wildcard
+ end
+ end
+
protected
def validate
errors.add(parent_id, " must be a root project") if parent and parent.parent
diff -Nur redmine-0.6.3/app/views/settings/edit.rhtml redmine-0.6.3-patched/app/views/settings/edit.rhtml
--- redmine-0.6.3/app/views/settings/edit.rhtml 2007-12-18 19:17:41.000000000 +0100
+++ redmine-0.6.3-patched/app/views/settings/edit.rhtml 2008-04-11 22:24:01.000000000 +0200
@@ -56,6 +56,9 @@
<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>
+
+
+<%= text_field_tag 'settings[repositories_key]', Setting.repositories_key, :size => 60 %>