htman: vorlaeufige Ruecknahme der flask-Umstellung
This commit is contained in:
parent
d15403403b
commit
50c8d6f75c
6 changed files with 47 additions and 62 deletions
|
@ -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()
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, '/data/htman/src')
|
||||
|
||||
from htman import app as application
|
|
@ -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
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% block head %}
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
{% block styles %}
|
||||
<!-- Bootstrap CSS -->
|
||||
{{ bootstrap.load_css() }}
|
||||
{% endblock %}
|
||||
<title>Wiki-Zugangsverwaltung</title>
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
{% block scripts %}
|
||||
{{ bootstrap.load_js() }}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -1,11 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
<!DOCTYPE html>
|
||||
<html xml:lang="de" lang="de"
|
||||
xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
xmlns:py="http://genshi.edgewall.org/">
|
||||
<xi:include href="layout.html" />
|
||||
|
||||
{% block content %}
|
||||
<head/>
|
||||
|
||||
<body>
|
||||
<form name="show_htpasswd" action="manage" method="POST">
|
||||
<label for="name">Wiki:</label>
|
||||
<input type="text" size="30" name="zone" id="name" />
|
||||
<input type="submit" name="submit" value="Show" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:py="http://genshi.edgewall.org/" py:strip="">
|
||||
|
||||
<py:match path="head" once="true">
|
||||
# <head py:attrs="select('@*')">
|
||||
<head py:attrs="select('@*')">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<title>${title}</title>
|
||||
<link rel="stylesheet" href="${css_url}" type="text/css" />
|
||||
|
|
Loading…
Reference in a new issue