From c860c460a404a68c32b68b0607627f02af9126c0 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 13 Apr 2013 16:44:22 +0200 Subject: [PATCH] Generate lighttpd config output instead of .htaccess files This is what we use to publish and hide repositories for access over http (actualy git over http, not gitweb). And since we switched to lighttpd, we no longer use .htaccess. --- gitdump.py | 31 ++++++++++++++++++++++++------- pggit.settings.sample | 4 ++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gitdump.py b/gitdump.py index 0fede92..35e6ac3 100644 --- a/gitdump.py +++ b/gitdump.py @@ -17,6 +17,7 @@ import shutil import psycopg2 import ConfigParser import urllib +import filecmp from util.LockFile import LockFile class TabRemover(object): @@ -67,6 +68,9 @@ SELECT name,anonymous,web,description,initialclone,tabwidth, THEN 1 ELSE 0 END FROM repositories AS r WHERE approved ORDER BY name""") f = open("%s.tmp" % self.conf.get("paths", "gitweblist"), "w") + accessfile = open("%s.tmp" % self.conf.get("paths", "lighttpdconf"), "w") + accessfile.write("alias.url += (\n") + for name, anon, web, description, initialclone, tabwidth, owner, remoterepo in curs: allrepos[name] = 1 repopath = "%s/repos/%s.git" % (self.conf.get("paths", "githome"), name) @@ -132,24 +136,37 @@ FROM repositories AS r WHERE approved ORDER BY name""") cf.close() anonfile = "%s/git-daemon-export-ok" % repopath - htafile = "%s/.htaccess" % repopath if anon: if not os.path.isfile(anonfile): open(anonfile, "w").close() - if os.path.isfile(htafile): - os.remove(htafile) + # When anonymous access is allowed, create an entry so + # we can access it with http git. + accessfile.write(' "/git/%s.git/" => "%s/",' % (name, repopath)) + accessfile.write("\n") else: if os.path.isfile(anonfile): os.remove(anonfile) - if not os.path.isfile(htafile): - hf = open(htafile, "w") - hf.write("order allow,deny\ndeny from all\noptions -indexes\n") - hf.close() f.close() os.chmod("%s.tmp" % self.conf.get("paths", "gitweblist"), 0644) os.rename("%s.tmp" % self.conf.get("paths", "gitweblist"), self.conf.get("paths", "gitweblist")) + accessfile.write(")\n") + accessfile.close() + # Only rewrite the access file if it is actually different. And if + # it is, we need to also reload lighttpd at this point. + if os.path.isfile(self.conf.get("paths", "lighttpdconf")) and filecmp.cmp( + self.conf.get("paths", "lighttpdconf"), + "%s.tmp" % self.conf.get("paths", "lighttpdconf")): + # No changes, so just get rid of the temp file + os.remove("%s.tmp" % self.conf.get("paths", "lighttpdconf")) + else: + # File changed, so we need to overwrite the old one *and* + # reload lighttpd so the changes take effect. + os.rename("%s.tmp" % self.conf.get("paths", "lighttpdconf"), + self.conf.get("paths", "lighttpdconf")) + os.system(self.conf.get("webserver", "reloadcommand")) + # Now remove any repositories that have been deleted self._removerepos("%s/repos/" % self.conf.get("paths", "githome"), '/', allrepos) diff --git a/pggit.settings.sample b/pggit.settings.sample index 191bbd3..3b748e1 100644 --- a/pggit.settings.sample +++ b/pggit.settings.sample @@ -12,6 +12,10 @@ githome=/home/gitlab pggit=/opt/pgsql/pggit/pggit.py gitweblist=/opt/pgsql/pggit/__temp__gitweb.list logfile=/home/gitlab/pggit.log +lighttpdconf=/home/gitlab/lighttpd/pggit.conf + +[webserver] +reloadcommand=sudo /usr/sbin/service lighttpd reload [trigger] pushtrigger=triggers.test -- 2.39.5