diff --git a/htman.py b/htman.py index 881309f..28cc9b9 100644 --- a/htman.py +++ b/htman.py @@ -1,7 +1,5 @@ -#!/usr/bin/python2.5 -# -*- coding: utf-8 -*- +#!/usr/bin/env python2 """ -$Id$ A web interface for managing htpasswd files. @@ -25,14 +23,13 @@ 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 bobo -import genshi.template -import genshi.filters + +from flask_bootstrap import Bootstrap +from flask import * import ConfigParser import re +import htpasswd + BASE_DIR = os.path.dirname(__file__) CONFIG_FILE_LOCATIONS = [os.path.join(BASE_DIR, "htman.conf"), '/etc/htman/htman.conf'] @@ -42,24 +39,30 @@ REGEX = { "password": r"[a-zA-Z0-9_\-\.%\$_\;,<>=+\[\]\{\}\(\)#\'\"\/\&\*@]+$", "mapping": r"[a-zA-Z0-9_\-\.]+$", } + +app = Flask(__name__) +app.config['BOOTSTRAP_SERVE_LOCAL'] = False +bootstrap = Bootstrap(app) + # use the environment variable HTMAN_CONFIG as the config file location if the # variable is defined if "HTMAN_CONFIG" in os.environ: CONFIG_FILE_LOCATIONS = [os.environ["HTMAN_CONFIG"]] -@bobo.query('') -def redirect_frontpage(): - return bobo.redirect(web_defaults["base_url"]) +#@app.route('') +#def redirect_frontpage(): +# return bobo.redirect(web_defaults["base_url"]) -@bobo.query('/') +@app.route('/') def show_frontpage(): values = web_defaults.copy() - return render("frontpage.html", **values) +# return render("frontpage.html", **values) + return render_template("frontpage.html") -@bobo.query('/password') +@app.route('/password') def change_password(zone=None, username=None, old_password=None, new_password=None, new_password2=None): if zone: @@ -95,10 +98,10 @@ def change_password(zone=None, username=None, old_password=None, values["success"] = "Password changed successfully." else: values["error"] = "Authentication error: zone, username or password is invalid." - return render("password_change.html", input_data=input_data, **values) + return render_template("password_change.html", input_data=input_data, **values) -@bobo.query('/admin') +@app.route('/admin') def show_files(): values = web_defaults.copy() # The template expects a list of tuples: (mapping name, admin-url). @@ -107,14 +110,14 @@ def show_files(): all_zones = get_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_template("list_mappings.html", **values) def is_zone_valid(zone): return zone and (zone in get_mapping()) and re.match(REGEX["mapping"], zone) -@bobo.query('/manage') +@app.route('/manage') def show_htpasswd(zone=None): if not is_zone_valid(zone): return bobo.redirect(web_defaults["base_url"]) @@ -134,8 +137,8 @@ def get_htpasswd(zone, auto_create=False): # the alternative "/admin" URL allows to define super-user htaccess rules via # Apache's "Location" directive -@bobo.query('/admin/manage/:zone') -@bobo.query('/manage/:zone') +@app.route('/admin/manage/:zone') +@app.route('/manage/:zone') def manage_htpasswd(zone=None, action=None, username=None, password=None): values = web_defaults.copy() values["error"] = None @@ -184,7 +187,7 @@ def manage_htpasswd(zone=None, action=None, username=None, password=None): values["error"] = "Invalid action" values["usernames"] = htdb.get_usernames() # show the current htpasswd file - return render("manage_users.html", **values) + return render_template("manage_users.html", **values) def get_config(): @@ -272,14 +275,9 @@ config = get_config() mapping = get_mapping() templates_dir = get_templates_dir(config) web_defaults = dict(config.items("Web")) -if not web_defaults["base_url"].endswith("/"): - web_defaults["base_url"] += "/" -loader = genshi.template.TemplateLoader([templates_dir], auto_reload=False) - - -# this line allows to use mod_wsgi -# 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 -if __name__.startswith("_mod_wsgi_"): - application = bobo.Application(bobo_resources=__name__) +#if not web_defaults["base_url"].endswith("/"): +# web_defaults["base_url"] += "/" +#loader = genshi.template.TemplateLoader([templates_dir], auto_reload=False) +if __name__ == '__main__': + app.run() diff --git a/htman.wsgi b/htman.wsgi new file mode 100644 index 0000000..a5046b3 --- /dev/null +++ b/htman.wsgi @@ -0,0 +1,6 @@ +#!/usr/bin/env python2 + +import sys +sys.path.insert(0, '/data/htman/src') + +from htman import app as application diff --git a/htpasswd.py b/htpasswd.py index 454302b..9b0a8cc 100644 --- a/htpasswd.py +++ b/htpasswd.py @@ -1,8 +1,5 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 """ -$Id$ - A python module for managing htpasswd files. The code is based on http://trac.edgewall.org/export/9825/trunk/contrib/htpasswd.py diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..4225656 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,21 @@ + + + + {% block head %} + + + + {% block styles %} + + {{ bootstrap.load_css() }} + {% endblock %} + Wiki-Zugangsverwaltung + {% endblock %} + + + {% block content %}{% endblock %} + {% block scripts %} + {{ bootstrap.load_js() }} + {% endblock %} + + diff --git a/templates/frontpage.html b/templates/frontpage.html index 7b7d88a..99b6458 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -1,18 +1,11 @@ - - - +{% extends "base.html" %} - +{% block content %} -
- - +{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index 0fdad16..f4ecc74 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -3,7 +3,7 @@ xmlns:py="http://genshi.edgewall.org/" py:strip=""> - +# ${title}