From 06ea394f122a22d7e007ddd9a7a42a492e83c556 Mon Sep 17 00:00:00 2001 From: gashapwn Date: Fri, 27 Nov 2020 00:13:45 +0000 Subject: [PATCH] added comments --- app.py | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 24fe58d..d1f2da1 100644 --- a/app.py +++ b/app.py @@ -2,13 +2,29 @@ import glob import json from flask import Flask, redirect, url_for, render_template, request +# lyadmin +# scripts and web form for a tilde / PAUS instance +# +# gashapwn +# Nov 2020 +# +# https://git.lain.church/gashapwn/lyadmin +# gashapwn@protonmail.com +# or +# gasahwpn on irc.lainchan.org + + + + app=Flask(__name__) +# Paths for conf file, +# user list, +# directory containing +# account request files... WORKING_DIR = "/home/gashapwn/lyadmin/"; ACCOUNT_DIR = "test/"; - FULL_PATH = str(WORKING_DIR) + str(ACCOUNT_DIR) - CONF_PATH = str(WORKING_DIR) + "lyadmin.conf.json" # Account requests are given ID numbers @@ -16,13 +32,17 @@ CONF_PATH = str(WORKING_DIR) + "lyadmin.conf.json" # id number INIT_REQ_ID = "00000" +# Slurp the conf file with open(CONF_PATH) as c: conf_json_str = c.read() conf_obj = json.loads(conf_json_str) +# The main home page @app.route("/") def home(): app.route('/') + # Load the list of tilde users + # to generate links for u_list = []; with open("user_list.txt") as u_file: for line in u_file.readlines(): @@ -31,20 +51,25 @@ def home(): return render_template("index.html", u_list=u_list, page_name="home") +# The page with rules def rules(): return render_template("rules.html") -# this is a weird way to do this -# right? +# Generate HTML for a form widget def widg_fun(widg): if(widg.w_type == "input"): + # Return HTML for a single line input return "input id=id_%s name=%s type=text> 1): is_email_user = True else: email = "NO_EMAIL" + # All users requests have a sequential ID + # this checks how many requests we have + # and gives us a free ID so we can save + # our request if(len(glob.glob("./test/[0-9]*ident*")) == 0): new_id = int(INIT_REQ_ID) new_id_str = INIT_REQ_ID @@ -91,8 +127,8 @@ def signup(): new_id = int(max_id)+1 new_id_str = str(new_id).zfill(zpad) + # write the request to disk fn1 = str(FULL_PATH) + str(new_id_str) + ".ident" - with open(fn1, "w") as ident_file: ident_file.write(str(username) + "\n") ident_file.write(str(email) + "\n") @@ -115,5 +151,4 @@ if __name__=="__main__": app.add_url_rule('/login', 'login', login, methods = ['POST', 'GET']) app.add_url_rule('/req', 'req', req, methods = ['POST', 'GET']) app.add_url_rule('/req/signup', 'signup', signup, methods = ['POST']) - # app.run(host="104.248.118.130",debug=True) app.run(host=conf_obj["listen_ip"],debug=True)