import sys
import os
+import os.path
import psycopg2
-
-# MUST have trailing slash
-REPOPREFIX="/home/gitlab/"
+import ConfigParser
ALLOWED_COMMANDS = ('git-upload-pack', 'git-receive-pack')
WRITE_COMMANDS = ('git-receive-pack')
class Logger:
- def __init__(self):
+ def __init__(self, cfg):
self.user = "Unknown"
+ self.logfile = cfg.get('paths','logfile')
def log(self, message):
- f = open("/home/gitlab/pggit.log","a")
+ f = open(self.logfile,"a")
f.write("(%s): %s" % (self.user, message))
f.write("\n")
f.close()
path = None
subpath = None
- def __init__(self):
- self.logger = Logger()
+ def __init__(self, cfg):
+ self.cfg = cfg
+ self.logger = Logger(cfg)
+ self.repoprefix = "%s/repos/" % cfg.get('paths','githome')
pass
def parse_commandline(self):
# FIXME: what about that single quote? Make sure it's there?
# use os.path.normpath to make sure the user does not attempt to break out of the repository root
- self.path = os.path.normpath(("%s%s" % (REPOPREFIX, args[2:].rstrip("'"))))
- if not self.path.startswith(REPOPREFIX):
+ self.path = os.path.normpath(("%s%s" % (self.repoprefix, args[2:].rstrip("'"))))
+ if not self.path.startswith(self.repoprefix):
raise Exception("Escaping the root directory is of course not permitted")
if not os.path.exists(self.path):
raise Exception('git repository "%s" does not exist' % args)
- self.subpath = self.path[len(REPOPREFIX):]
+ self.subpath = self.path[len(self.repoprefix):]
def check_permissions(self):
writeperm = False
- db = psycopg2.connect("dbname=gitlab host=/tmp/ user=mha")
+ db = psycopg2.connect(self.cfg.get('database','db'))
curs = db.cursor()
curs.execute("SELECT write FROM repository_permissions INNER JOIN repositories ON repoid=repository WHERE userid=%s AND name=%s",
(self.user, self.subpath))
raise e
if __name__ == "__main__":
- PgGit().run()
+ c = ConfigParser.ConfigParser()
+ c.read("%s/pggit.settings" % os.path.abspath(sys.path[0]))
+ PgGit(c).run()