From 6b841f3a78286402362488dea80e37574651268b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 16 Sep 2020 22:14:27 +0000 Subject: [PATCH] Set a user's wiki password with auth server --- authserver/auth_functions.py | 31 +++++++++++++++++++++++++++---- authserver/secrets.py.example | 5 +++++ authserver/server.py | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/authserver/auth_functions.py b/authserver/auth_functions.py index 74bdd1d..e429384 100644 --- a/authserver/auth_functions.py +++ b/authserver/auth_functions.py @@ -1,15 +1,38 @@ from log import logger import time import secrets +import subprocess from flask import abort HTTP_NOTFOUND = 404 -def set_password(username, password): - # TODO - print(username, password) +def set_wiki_password(username, password): + # sets a user's wiki password + # creates the account if it doesn't exist + + if not username: + logger.error('Empty username, aborting') + abort(400) + + logger.info('Setting wiki password for: ' + username) + + if not password: + logger.error('Empty password, aborting') + abort(400) + + script = secrets.WIKI_MAINTENANCE + '/createAndPromote.php' + + result = subprocess.run(['php', script, '--force', username, password], + shell=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + output = result.stdout or result.stderr + + logger.info('Output: ' + output) + + if result.stderr: + abort(400) if __name__ == '__main__': - print(set_password('test.test', 'password')) + set_wiki_password('tanner.collin', 'protospace1') pass diff --git a/authserver/secrets.py.example b/authserver/secrets.py.example index d7312bb..9a8f8aa 100644 --- a/authserver/secrets.py.example +++ b/authserver/secrets.py.example @@ -5,3 +5,8 @@ # For example, use the first output of this: # head /dev/urandom | sha1sum AUTH_TOKEN = '' + +# Absolute path of Mediawiki maintenance directory +# Probably: +# /var/www/wiki/maintenance +WIKI_MAINTENANCE = '' diff --git a/authserver/server.py b/authserver/server.py index 8e1fdf1..69d7517 100644 --- a/authserver/server.py +++ b/authserver/server.py @@ -22,7 +22,7 @@ def set_password(): username = request.form['username'] password = request.form['password'] - auth_functions.set_password(username, password) + auth_functions.set_wiki_password(username, password) return '' if __name__ == '__main__':