Generate lighttpd config output instead of .htaccess files
authorMagnus Hagander <magnus@hagander.net>
Sat, 13 Apr 2013 14:44:22 +0000 (16:44 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 13 Apr 2013 14:44:22 +0000 (16:44 +0200)
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
pggit.settings.sample

index 0fede92c8fba2e34630f04ca607dd429f0f1926e..35e6ac3c08a57fcaed70f7f72ae4641603a802de 100644 (file)
@@ -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)
 
index 191bbd3a78c09e6ebcb6a5e01458578fbe2c50c2..3b748e146987cb8912b0aab4380c01edbfb32f9d 100644 (file)
@@ -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