diff --git a/page/repo.py b/page/repo.py index 6f75931..54c8ecb 100644 --- a/page/repo.py +++ b/page/repo.py @@ -95,7 +95,7 @@ class RepoUpdatePage(Page): if not repo.can_update(): raise exception.HttpNotFound() - answer.add_uipath_entry( answer.t('Edit repository') ) + answer.add_uipath_entry( answer.t('Edit repository'), prevpath ) form = Form(request) form.begin('Details', 'repo.update') diff --git a/repoproxy.py b/repoproxy.py index cf82bd2..a59c194 100644 --- a/repoproxy.py +++ b/repoproxy.py @@ -93,6 +93,11 @@ class RepoProxy: proxy_headers[kk] = v if 'CONTENT_TYPE' in request.env: proxy_headers['content-type'] = request.env['CONTENT_TYPE'] + try: + length = int(request.env['CONTENT_LENGTH']) + if length: proxy_headers['content-length'] = str(length) + except Exception: + pass proxy_headers['host'] = host connection = None @@ -126,7 +131,6 @@ class RepoProxy: if request.method != 'GET' and request.method != 'POST': return self.forbidden() - post = request.method == 'POST' login = '' password = '' if 'HTTP_AUTHORIZATION' in request.env: @@ -158,10 +162,9 @@ class RepoProxy: if not repo: return self.forbidden() - if repo.type == 'git' and len(nextpath) == 1 and nextpath[0] == 'git-upload-pack': - post = False + writeaccess = repo.repotype.iswriteaccess(request, nextpath) - if post: + if writeaccess: if not user: return self.unauthorized() if user.id != repo.user_id and not request.model.rights.get_superuser(user.id): @@ -169,10 +172,10 @@ class RepoProxy: url = repo.gen_internalurl() - getvars = request.env.get('QUERY_STRING', '') - if nextpath: - url += '/' + '/'.join(nextpath) - if getvars: - url += '?' + getvars - return self.proxy(request, url) + getvars = request.env.get('QUERY_STRING', '') + if nextpath: + url += '/' + '/'.join(nextpath) + if getvars: + url += '?' + getvars + return self.proxy(request, url) diff --git a/repotypes/base.py b/repotypes/base.py index c9dcb89..2fb8385 100644 --- a/repotypes/base.py +++ b/repotypes/base.py @@ -46,6 +46,9 @@ class RepotypeBase: assert subpath[-1] != '/' return self.internalurl + '/' + subpath + def iswriteaccess(self, request, path): + return True + def create(self, subpath): raise Exception() diff --git a/repotypes/git.py b/repotypes/git.py index 734e082..0108095 100644 --- a/repotypes/git.py +++ b/repotypes/git.py @@ -32,6 +32,13 @@ class RepotypeGit(RepotypeBase): subprocess.run([self.command, 'init', '--bare', path], env = self.environment, cwd = parentpath) subprocess.run([self.command, 'config', 'http.receivepack', 'true'], env = self.environment, cwd = path) + def iswriteaccess(self, request, path): + if request.method == 'GET' and request.urlvars.get('service', list()).count('git-receive-pack'): + return True + if request.method == 'POST' and len(path) == 1 and path[0] == 'git-upload-pack': + return False + return request.method != 'GET' + def delete(self, subpath): path = self.gen_path(subpath) print(self.name + ': Deleting repository by path: ' + path)