scripts and tools to administer the lingy.in public unix / tilde
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6KB

  1. from flask import Flask, redirect, url_for, render_template, request
  2. app=Flask(__name__)
  3. @app.route("/")
  4. def home():
  5. app.route('/')
  6. u_list = [];
  7. with open("user_list.txt") as u_file:
  8. for line in u_file:
  9. u_list.append(line);
  10. return render_template("index.html", u_list=u_list, page_name="home")
  11. def rules():
  12. return render_template("rules.html")
  13. def home2(name):
  14. # app.route('/home2/<name>')
  15. # return redirect(url_for('home'))
  16. return render_template("home.html")
  17. def success(name):
  18. return "welcome %s" % name
  19. # this is a weird way to do this
  20. # right?
  21. def widg_fun(widg):
  22. if(widg.w_type == "input"):
  23. return "input id=id_%s name=%s type=text></input"%(widg.w_name, widg.w_name)
  24. elif(widg.w_type == "textarea"):
  25. return "textarea cols=40 id=id_%s name=%s rows=10 required=\"\""%(widg.w_name, widg.w_name)
  26. elif(widg.w_type == "check"):
  27. return "input id=id_%s name=%s type=checkbox required=\"\""%(widg.w_name, widg.w_name)
  28. return widg.w_type;
  29. def req():
  30. class Widg:
  31. def __init__(self, w_name, w_type, w_opt):
  32. self.w_name = w_name
  33. self.w_type = w_type
  34. self.w_opt = w_opt
  35. rt = {
  36. "username": Widg("username", "input", None),
  37. "email for account lockout / registration confirmation (optional)": Widg("email", "input", None),
  38. "SSH public key": Widg("pub_key", "textarea", None),
  39. "shell of choice": Widg("shell", "choice", [("bash", "/bin/bash"), ("ksh", "/bin/ksh")]),
  40. "have you read the rules?": Widg("rule_read", "check", None)
  41. };
  42. # uhhh is this how you're supposed to do this?
  43. return render_template("req.html", req_tab = rt, widg_fun = widg_fun, page_name="req")
  44. def signup():
  45. username = request.form["username"]
  46. email = request.form["email"]
  47. shell = request.form["shell"]
  48. rule_read = request.form["rule_read"]
  49. if(rule_read != "on"):
  50. print("some fail condition")
  51. def login():
  52. if request.method == "POST":
  53. user = request.form["nm"]
  54. return redirect(url_for('success', name = user))
  55. else:
  56. return redirect(url_for('home'))
  57. if __name__=="__main__":
  58. app.add_url_rule('/home2/<name>', 'home2', home2)
  59. app.add_url_rule('/rules', 'rules', rules)
  60. app.add_url_rule('/success/<name>', 'success', success)
  61. app.add_url_rule('/login', 'login', login, methods = ['POST', 'GET'])
  62. app.add_url_rule('/req', 'req', req, methods = ['POST', 'GET'])
  63. app.add_url_rule('/req/signup', 'req', req, methods = ['POST'])
  64. app.run(host="104.248.118.130",debug=True)