fixed genshi template loader search path
fixed wsgi detection added "htpasswd_directory" setting
This commit is contained in:
parent
397b19c591
commit
8dd0b23e74
1 changed files with 28 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python2.5
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
$Id$
|
$Id$
|
||||||
|
@ -21,13 +21,17 @@ You should have received a copy of the GNU General Public License
|
||||||
along with This module. If not, see <http://www.gnu.org/licenses/>.
|
along with This module. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
# add the current path to the python path - for "htpasswd"
|
||||||
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
# necessary for etch
|
||||||
|
sys.path.insert(1, '/usr/share/pyshared')
|
||||||
import htpasswd
|
import htpasswd
|
||||||
import bobo
|
import bobo
|
||||||
import genshi.template
|
import genshi.template
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(__file__)
|
BASE_DIR = os.path.dirname(__file__)
|
||||||
CONFIG_FILE_LOCATIONS = [os.path.join(BASE_DIR, "htman.conf"), '/etc/htman/htman.conf']
|
CONFIG_FILE_LOCATIONS = [os.path.join(BASE_DIR, "htman.conf"), '/etc/htman/htman.conf']
|
||||||
|
@ -54,7 +58,9 @@ def show_files():
|
||||||
# The template expects a list of tuples: (mapping name, admin-url).
|
# The template expects a list of tuples: (mapping name, admin-url).
|
||||||
# We assume, that the admin-url is just below the main admin URL. Thus
|
# We assume, that the admin-url is just below the main admin URL. Thus
|
||||||
# there is no need for generating a specific URL.
|
# there is no need for generating a specific URL.
|
||||||
values["mapping"] = [(mapping, mapping) for mapping in mapping.keys()]
|
all_zones = mapping.keys()
|
||||||
|
all_zones.sort()
|
||||||
|
values["mapping"] = [(zone_name, "%s%s/%s" % (web_defaults["base_url"], "admin/manage", zone_name)) for zone_name in all_zones]
|
||||||
return render("list_mappings.html", **values)
|
return render("list_mappings.html", **values)
|
||||||
|
|
||||||
@bobo.query('/manage')
|
@bobo.query('/manage')
|
||||||
|
@ -67,7 +73,7 @@ def show_htpasswd(htname=None):
|
||||||
|
|
||||||
# the alternative "/admin" URL allows to define super-user htaccess rules via
|
# the alternative "/admin" URL allows to define super-user htaccess rules via
|
||||||
# Apache's "Location" directive
|
# Apache's "Location" directive
|
||||||
@bobo.query('/admin/:htname')
|
@bobo.query('/admin/manage/:htname')
|
||||||
@bobo.query('/manage/:htname')
|
@bobo.query('/manage/:htname')
|
||||||
def manage_htpasswd(htname=None, action=None, username=None, password=None):
|
def manage_htpasswd(htname=None, action=None, username=None, password=None):
|
||||||
values = web_defaults.copy()
|
values = web_defaults.copy()
|
||||||
|
@ -76,7 +82,7 @@ def manage_htpasswd(htname=None, action=None, username=None, password=None):
|
||||||
if (htname is None) or (not htname in mapping) or (not re.match(REGEX["mapping"], htname)):
|
if (htname is None) or (not htname in mapping) or (not re.match(REGEX["mapping"], htname)):
|
||||||
return bobo.redirect(web_defaults["base_url"])
|
return bobo.redirect(web_defaults["base_url"])
|
||||||
values["htname"] = htname
|
values["htname"] = htname
|
||||||
htpasswd_file = mapping[htname]
|
htpasswd_file = get_htpasswd_filename(htname)
|
||||||
do_create_file = not os.path.isfile(htpasswd_file)
|
do_create_file = not os.path.isfile(htpasswd_file)
|
||||||
try:
|
try:
|
||||||
htdb = htpasswd.HtpasswdFile(htpasswd_file, create=do_create_file)
|
htdb = htpasswd.HtpasswdFile(htpasswd_file, create=do_create_file)
|
||||||
|
@ -169,6 +175,20 @@ def get_mapping(config):
|
||||||
mapping[name] = location
|
mapping[name] = location
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
|
def get_htpasswd_filename(htname):
|
||||||
|
basename = mapping[htname]
|
||||||
|
if basename and (basename != os.path.abspath(basename)):
|
||||||
|
# relative filename in mapping file
|
||||||
|
# let's try the htpasswd_directory setting
|
||||||
|
try:
|
||||||
|
htpasswd_directory = config.get("Locations", "htpasswd_directory")
|
||||||
|
return os.path.join(htpasswd_directory, basename)
|
||||||
|
except ConfigParser.NoOptionError:
|
||||||
|
return os.path.abspath(basename)
|
||||||
|
else:
|
||||||
|
return basename
|
||||||
|
|
||||||
|
|
||||||
def get_templates_dir(config):
|
def get_templates_dir(config):
|
||||||
try:
|
try:
|
||||||
templates_dir = config.get("Locations", "templates")
|
templates_dir = config.get("Locations", "templates")
|
||||||
|
@ -193,12 +213,12 @@ config = get_config()
|
||||||
mapping = get_mapping(config)
|
mapping = get_mapping(config)
|
||||||
templates_dir = get_templates_dir(config)
|
templates_dir = get_templates_dir(config)
|
||||||
web_defaults = dict(config.items("Web"))
|
web_defaults = dict(config.items("Web"))
|
||||||
loader = genshi.template.TemplateLoader(templates_dir, auto_reload=False)
|
loader = genshi.template.TemplateLoader([templates_dir], auto_reload=False)
|
||||||
|
|
||||||
|
|
||||||
# this line allows to use mod_wsgi
|
# this line allows to use mod_wsgi
|
||||||
# see: http://groups.google.com/group/bobo-web/msg/2ba55fc381658cd1
|
# see: http://groups.google.com/group/bobo-web/msg/2ba55fc381658cd1
|
||||||
# see: http://blog.dscpl.com.au/2009/08/using-bobo-on-top-of-modwsgi.html
|
# see: http://blog.dscpl.com.au/2009/08/using-bobo-on-top-of-modwsgi.html
|
||||||
if __name__ == "__main__":
|
if __name__.startswith("_mod_wsgi_"):
|
||||||
application = bobo.Application(bobo_resources=__name__)
|
application = bobo.Application(bobo_resources=__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue