Implement url and scriptname autodetection.
Mon Jul 31 04:10:20 UTC 2006 Alberto Bertogli <albertito@gmail.com>
* Implement url and scriptname autodetection.
This patch implements autodetection of the url and scriptname of darcsweb.
It's based on a suggestion from Tobias Gruetzmacher.
It relies on variables according to the CGI/1.1 standard, and works only if
cache is not enabled. If it is, the variables must be set manually as before.
The problem with the cache is multi-host access: if a page not in the cache is
accesed as http://hosta/dw/..., then the cached page will reference "hosta".
If then it's accessed from hostb, there will be a reference to hosta that it's
possibly broken. It's actually a quite common case when you have localhost and
external access.
diff -rN -u old-darcsweb/config.py.sample new-darcsweb/config.py.sample
--- old-darcsweb/config.py.sample 2015-10-09 16:59:00.000000000 +0000
+++ new-darcsweb/config.py.sample 2015-10-09 16:59:00.000000000 +0000
@@ -1,12 +1,6 @@
# base configuration, common to all repos
class base:
- # this script's name, usually just "darcsweb.cgi" unless you rename it
- myname = "darcsweb.cgi"
-
- # our url, used only to generate RSS links, without the script name
- myurl = "http://example.com/darcsweb"
-
# location of the darcs logo
darcslogo = "darcs.png"
@@ -16,6 +10,14 @@
# the CSS file to use
cssfile = 'style.css'
+ # this script's name, usually just "darcsweb.cgi" unless you rename
+ # it; if you leave this commented it will be detected automatically
+ #myname = "darcsweb.cgi"
+
+ # our url, used only to generate RSS links, without the script name;
+ # if you leave this commented it will be detected automatically
+ #myurl = "http://example.com/darcsweb"
+
# optionally, you can specify the path to the darcs executable; if you
# leave this commented, the one on $PATH will be used (this is
# normally what you want)
@@ -38,6 +40,8 @@
# fine.
# If you leave the entry commented, no cache will be ever used;
# otherwise the directory is assumed to exist and be writeable.
+ # If you use this option you must set the "myname" and "myurl"
+ # variables.
#cachedir = '/tmp/darcsweb-cache'
# By default, darcsweb's search looks in the last 100 commits; you can
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-10-09 16:59:00.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-10-09 16:59:00.000000000 +0000
@@ -2057,6 +2057,7 @@
def do_listrepos():
import config as all_configs
+ expand_multi_config(all_configs)
# the header here is special since we don't have a repo
print "Content-type: text/html; charset=utf-8\n"
@@ -2100,7 +2101,6 @@
# some python magic
alt = True
- expand_multi_config(all_configs)
for conf in dir(all_configs):
if conf.startswith('__'):
continue
@@ -2123,7 +2123,7 @@
</td>
</tr>
""" % {
- 'myname': all_configs.base.myname,
+ 'myname': config.myname,
'dname': name,
'name': urllib.quote(name),
'desc': shorten_str(desc, 60)
@@ -2229,13 +2229,29 @@
# fill the configuration
base = all_configs.base
- config.myname = base.myname
- config.myurl = base.myurl
+ if 'myname' not in dir(base):
+ # SCRIPT_NAME has the full path, we only take the file name
+ config.myname = os.path.basename(os.environ['SCRIPT_NAME'])
+ else:
+ config.myname = base.myname
+
+ if 'myurl' not in dir(base) and 'cachedir' not in dir(base):
+ n = os.environ['SERVER_NAME']
+ p = os.environ['SERVER_PORT']
+ s = os.environ['SCRIPT_NAME']
+ if p == '80':
+ p = ''
+ else:
+ p = ':' + p
+ config.myurl = 'http://%s%s%s' % (n, p, s)
+ else:
+ config.myurl = base.myurl
+
config.darcslogo = base.darcslogo
config.darcsfav = base.darcsfav
config.cssfile = base.cssfile
if name:
- config.myreponame = base.myname + '?r=' + urllib.quote(name)
+ config.myreponame = config.myname + '?r=' + urllib.quote(name)
config.reponame = c.reponame
config.repodesc = c.repodesc
config.repodir = c.repodir