From 4b517a736e5d1d24eabed0dd9d0da316af2593a3 Mon Sep 17 00:00:00 2001 From: lars Date: Tue, 9 Feb 2021 20:05:41 +0000 Subject: [PATCH] htman: vorlaeufige Ruecknahme der flask-Umstellung --- htman.py | 62 +++++++++++++++++++++------------------- htman.wsgi | 6 ---- htpasswd.py | 5 +++- templates/base.html | 21 -------------- templates/frontpage.html | 13 +++++++-- templates/layout.html | 2 +- 6 files changed, 47 insertions(+), 62 deletions(-) delete mode 100644 htman.wsgi delete mode 100644 templates/base.html diff --git a/htman.py b/htman.py index 28cc9b9..881309f 100644 --- a/htman.py +++ b/htman.py @@ -1,5 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/python2.5 +# -*- coding: utf-8 -*- """ +$Id$ A web interface for managing htpasswd files. @@ -23,13 +25,14 @@ import sys import os # add the current path to the python path - for "htpasswd" sys.path.insert(0, os.path.dirname(__file__)) - -from flask_bootstrap import Bootstrap -from flask import * +# necessary for etch +sys.path.insert(1, '/usr/share/pyshared') +import htpasswd +import bobo +import genshi.template +import genshi.filters 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'] @@ -39,30 +42,24 @@ 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"]] -#@app.route('') -#def redirect_frontpage(): -# return bobo.redirect(web_defaults["base_url"]) +@bobo.query('') +def redirect_frontpage(): + return bobo.redirect(web_defaults["base_url"]) -@app.route('/') +@bobo.query('/') def show_frontpage(): values = web_defaults.copy() -# return render("frontpage.html", **values) - return render_template("frontpage.html") + return render("frontpage.html", **values) -@app.route('/password') +@bobo.query('/password') def change_password(zone=None, username=None, old_password=None, new_password=None, new_password2=None): if zone: @@ -98,10 +95,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_template("password_change.html", input_data=input_data, **values) + return render("password_change.html", input_data=input_data, **values) -@app.route('/admin') +@bobo.query('/admin') def show_files(): values = web_defaults.copy() # The template expects a list of tuples: (mapping name, admin-url). @@ -110,14 +107,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_template("list_mappings.html", **values) + return render("list_mappings.html", **values) def is_zone_valid(zone): return zone and (zone in get_mapping()) and re.match(REGEX["mapping"], zone) -@app.route('/manage') +@bobo.query('/manage') def show_htpasswd(zone=None): if not is_zone_valid(zone): return bobo.redirect(web_defaults["base_url"]) @@ -137,8 +134,8 @@ def get_htpasswd(zone, auto_create=False): # the alternative "/admin" URL allows to define super-user htaccess rules via # Apache's "Location" directive -@app.route('/admin/manage/:zone') -@app.route('/manage/:zone') +@bobo.query('/admin/manage/:zone') +@bobo.query('/manage/:zone') def manage_htpasswd(zone=None, action=None, username=None, password=None): values = web_defaults.copy() values["error"] = None @@ -187,7 +184,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_template("manage_users.html", **values) + return render("manage_users.html", **values) def get_config(): @@ -275,9 +272,14 @@ 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) +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 __name__ == '__main__': - app.run() diff --git a/htman.wsgi b/htman.wsgi deleted file mode 100644 index a5046b3..0000000 --- a/htman.wsgi +++ /dev/null @@ -1,6 +0,0 @@ -#!/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 9b0a8cc..454302b 100644 --- a/htpasswd.py +++ b/htpasswd.py @@ -1,5 +1,8 @@ -#!/usr/bin/env python3 +#!/usr/bin/python +# -*- coding: utf-8 -*- """ +$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 deleted file mode 100644 index 4225656..0000000 --- a/templates/base.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - {% 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 99b6458..7b7d88a 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -1,11 +1,18 @@ -{% extends "base.html" %} + + + -{% block content %} + +
+ + -{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index f4ecc74..0fdad16 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -3,7 +3,7 @@ xmlns:py="http://genshi.edgewall.org/" py:strip=""> -# + ${title}