from flask import Flask, render_template_string, request from werkzeug.middleware.proxy_fix import ProxyFix import os app = Flask(__name__) USER1 = os.environ.get("USER1") ROLE1 = os.environ.get("ROLE1") USER2 = os.environ.get("USER2") ROLE2 = os.environ.get("ROLE2") DOCUMENTTYPE = os.environ.get("DOCUMENTTYPE") # Define the HTML template for the list HTML_TEMPLATE = ''' ''' + str(USER1) + " and " + str(USER2) + " " + str(ROLE1) + " and " + str(ROLE2) + " " + DOCUMENTTYPE + '''

''' + str(ROLE1) + " " + str(USER1) + '''

''' + str(ROLE2) + " " + str(USER2) + '''

''' + str(DOCUMENTTYPE) + '''

''' # Define the HTML template for the editable list READ_ONLY_HTML_TEMPLATE = ''' ''' + str(USER1) + " and " + str(USER2) + " " + str(ROLE1) + " and " + str(ROLE2) + " " + DOCUMENTTYPE + ''' (Read Only)

''' + str(ROLE1) + " " + str(USER1) + '''

''' + str(ROLE2) + " " + str(USER2) + '''

''' + str(DOCUMENTTYPE) + '''

''' # Function to read the list from a file def read_list(): try: with open('list.txt', 'r') as file: return [line.strip() for line in file.readlines()] except FileNotFoundError: return [] # Function to write the list to a file def write_list(items): with open('list.txt', 'w') as file: for item in items: file.write(f"{item}\n") @app.route('/') def manage(): items = read_list() return render_template_string(READ_ONLY_HTML_TEMPLATE, items=items) @app.route('/add', methods=['POST']) def add_item(): data = request.get_json() new_item = data['item'] items = read_list() items.append(new_item) write_list(items) return '', 204 @app.route('/delete/', methods=['DELETE']) def delete_item(index): items = read_list() if index < len(items): del items[index] write_list(items) return '', 204 @app.route('/manage/') def manage_read_only(): items = read_list() return render_template_string(HTML_TEMPLATE, items=items) from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix( app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1 ) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=5000)