2020-11-23 07:27:46 +00:00
|
|
|
from log import logger
|
|
|
|
|
2020-09-16 21:41:55 +00:00
|
|
|
from flask import Flask, abort, request
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
import auth_functions
|
|
|
|
import secrets
|
|
|
|
|
|
|
|
HTTP_UNAUTHORIZED = 401
|
|
|
|
|
|
|
|
def check_auth():
|
|
|
|
auth_header = request.headers.get('Authorization', '')
|
|
|
|
if auth_header != 'Token ' + secrets.AUTH_TOKEN:
|
|
|
|
abort(HTTP_UNAUTHORIZED)
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2020-11-23 07:27:46 +00:00
|
|
|
logger.info('Index page requested')
|
|
|
|
|
2020-11-22 01:30:02 +00:00
|
|
|
return '<i>LIFE IS BUT A DREAM...</i>'
|
2020-09-16 21:41:55 +00:00
|
|
|
|
2020-11-23 07:27:46 +00:00
|
|
|
@app.route('/ping')
|
|
|
|
def ping():
|
|
|
|
return 'pong'
|
|
|
|
|
2021-09-04 06:19:57 +00:00
|
|
|
@app.route('/set-wiki-password', methods=['POST'])
|
2021-09-04 22:54:17 +00:00
|
|
|
def set_wiki_password():
|
2020-09-16 21:41:55 +00:00
|
|
|
check_auth()
|
|
|
|
|
|
|
|
username = request.form['username']
|
|
|
|
password = request.form['password']
|
|
|
|
|
2020-09-16 22:14:27 +00:00
|
|
|
auth_functions.set_wiki_password(username, password)
|
2020-09-16 21:41:55 +00:00
|
|
|
return ''
|
|
|
|
|
2021-09-04 06:19:57 +00:00
|
|
|
@app.route('/set-discourse-password', methods=['POST'])
|
2021-09-04 22:54:17 +00:00
|
|
|
def set_discourse_password():
|
2021-09-04 06:19:57 +00:00
|
|
|
check_auth()
|
|
|
|
|
|
|
|
username = request.form['username']
|
|
|
|
password = request.form['password']
|
|
|
|
first_name = request.form['first_name']
|
|
|
|
email = request.form['email']
|
|
|
|
|
|
|
|
auth_functions.set_discourse_password(username, password, first_name, email)
|
|
|
|
return ''
|
|
|
|
|
2021-09-24 23:00:39 +00:00
|
|
|
@app.route('/add-discourse-group-members', methods=['POST'])
|
|
|
|
def add_discourse_group_members():
|
|
|
|
check_auth()
|
|
|
|
|
2021-09-25 22:59:34 +00:00
|
|
|
data = request.get_json()
|
|
|
|
group_name = data['group_name']
|
|
|
|
usernames = data['usernames']
|
2021-09-24 23:00:39 +00:00
|
|
|
|
|
|
|
auth_functions.add_discourse_group_members(group_name, usernames)
|
|
|
|
return ''
|
|
|
|
|
|
|
|
@app.route('/remove-discourse-group-members', methods=['POST'])
|
|
|
|
def remove_discourse_group_members():
|
|
|
|
check_auth()
|
|
|
|
|
2021-09-25 22:59:34 +00:00
|
|
|
data = request.get_json()
|
|
|
|
group_name = data['group_name']
|
|
|
|
usernames = data['usernames']
|
2021-09-24 23:00:39 +00:00
|
|
|
|
|
|
|
auth_functions.remove_discourse_group_members(group_name, usernames)
|
|
|
|
return ''
|
|
|
|
|
2020-09-16 21:41:55 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host='0.0.0.0')
|