From 1e50d523962155bf88a4d18f686203ad3930d974 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 11 Dec 2008 10:38:53 +0100 Subject: generate htpasswd files --- index.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/index.py b/index.py index 38512e3..8d4fe29 100644 --- a/index.py +++ b/index.py @@ -82,6 +82,22 @@ def generate_sha_base64(password): return "{SHA}" + base64.encodestring(sha.new(password).digest()).rstrip('\n') +# this function calls /var/www/localhost/scripts/bin/generate_users to create +# project specific htpasswd files +def generate_users_file(cursor): + cursor.execute("SELECT project_name FROM project WHERE project_name != 'ALL'") + projects = cursor.fetchall() + + for project in projects: + cursor.execute("SELECT DISTINCT login, password FROM project_members WHERE password IS NOT NULL AND (project_name = %s OR project_name = 'ALL')", (project[0],)) + users = cursor.fetchall() + htpasswd = open("/var/www/localhost/users/" + project[0], "w") + + for user in users: + htpasswd.write("%s:%s\n" % (user[0], user[1])) + + htpasswd.close() + # generate a new random password, save it to the database and send it to the user # WARNING: this function will do an implicit commit/rollback to the database! def set_random_password(req, user_id, length): @@ -109,6 +125,7 @@ def set_random_password(req, user_id, length): # otherwise commit to database and confirm req.dbc.commit() + generate_users_file(req.cursor) return None @@ -304,6 +321,7 @@ def profile(req, **formdata): new_pw_hash = generate_sha_base64(formdata['new_pw1']) cursor.execute("UPDATE user SET password = %s WHERE login = %s", (new_pw_hash, s['login'])) req.dbc.commit() + generate_users_file(req.cursor) c['info_msg'] = "new password has been set" return render_to_string("index.html", c) @@ -405,6 +423,7 @@ def members(req, **formdata): if what == "delete": cursor.execute("delete from member where user_id = %s and project_id = %s", (user_id, project_id)) req.dbc.commit() + generate_users_file(req.cursor) c['info_msg'] = "you deleted " + who + " from project " + proj elif what == "add": @@ -428,6 +447,7 @@ def del_profile(req): cursor.execute("delete from user where login = %s", (s['login'], )) req.dbc.commit() + generate_users_file(req.cursor) s['login'] = None s.save() @@ -461,7 +481,11 @@ def list_projects(req): return render_to_string("list_projects.html", c) +def genusers(req): + (c, s, cursor) = session_start(req, None) + generate_users_file(cursor) + return "OK" + # this is returned whenever a db error occurs def db_error(req): return render_to_string("db_error.html") - -- cgit v1.2.3