from flask import Flask, render_template, request, Response, Markup, jsonify, make_response from config import * import base64, hashlib from dmr_utils3.utils import int_id, bytes_4 auth_dict = {} app = Flask(__name__) def gen_passphrase(dmr_id): _new_peer_id = bytes_4(int(str(dmr_id)[:7])) calc_passphrase = base64.b64encode((_new_peer_id) + append_int.to_bytes(2, 'big')) return str(calc_passphrase)[2:-1] @app.route('/gen', methods = ['POST', 'GET']) def gen(): #content = Markup('The HTML String') user_id = request.args.get('user_id') print(user_id) auth_dict[int(user_id)] = '' content = '''

Your passphrase for ''' + str(user_id) + ''':

''' + str(gen_passphrase(int(user_id))) + '''

''' print(auth_dict) return render_template('generic.html', title = title, url = url, logo = logo, content = Markup(content)) @app.route('/') def index(): #content = Markup('The HTML String') content = '''

''' return render_template('generic.html', title = title, url = url, logo = logo, content = Markup(content)) @app.route('/auth', methods=['POST']) def auth(): hblink_req = request.json print((hblink_req)) if hblink_req['secret'] in shared_secrets: if hblink_req['id'] in auth_dict: if auth_dict[hblink_req['id']] == 0: response = jsonify( allow=True, mode='legacy', ) elif auth_dict[hblink_req['id']] == '': # normal response = jsonify( allow=True, mode='normal', ) elif auth_dict[hblink_req['id']] != '' or auth_dict[hblink_req['id']] != 0: response = jsonify( allow=True, mode='override', value=auth_dict[hblink_req['id']] ) if hblink_req['id'] not in auth_dict: response = jsonify( allow=False) else: message = jsonify(message='Authentication error') response = make_response(message, 401) return response if __name__ == '__main__': app.run(debug = True, port=ums_port, host=ums_host)