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.

62 lines
2.1KB

  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. return render_template("index.html")
  7. def home2(name):
  8. # app.route('/home2/<name>')
  9. # return redirect(url_for('home'))
  10. return render_template("home.html")
  11. def success(name):
  12. return "welcome %s" % name
  13. # this is a weird way to do this
  14. # right?
  15. def widg_fun(widg):
  16. if(widg.w_type == "input"):
  17. return "input id=id_%s name=%s type=text></input"%(widg.w_name, widg.w_name)
  18. elif(widg.w_type == "textarea"):
  19. return "textarea cols=40 id=id_%s name=%s rows=10 required=\"\""%(widg.w_name, widg.w_name)
  20. elif(widg.w_type == "check"):
  21. return "input id=id_%s name=%s type=checkbox required=\"\""%(widg.w_name, widg.w_name)
  22. return widg.w_type;
  23. def req():
  24. class Widg:
  25. def __init__(self, w_name, w_type, w_opt):
  26. self.w_name = w_name
  27. self.w_type = w_type
  28. self.w_opt = w_opt
  29. rt = {
  30. "username": Widg("username", "input", None),
  31. "displayname": Widg("displayname", "input", None),
  32. "prefer display name?": Widg("default_disp", "check", None),
  33. "email for account lockout / registration confirmation (optional)": Widg("email", "input", None),
  34. "SSH public key": Widg("pub_key", "textarea", None),
  35. "shell of choice": Widg("shell", "choice", [("bash", "/bin/bash"), ("ksh", "/bin/ksh")]),
  36. "have you read the rules?": Widg("rule_read", "check", None)
  37. };
  38. # uhhh is this how you're supposed to do this?
  39. return render_template("req.html", req_tab = rt, widg_fun = widg_fun)
  40. def login():
  41. if request.method == "POST":
  42. user = request.form["nm"]
  43. return redirect(url_for('success', name = user))
  44. else:
  45. return redirect(url_for('home'))
  46. if __name__=="__main__":
  47. app.add_url_rule('/home2/<name>', 'home2', home2)
  48. app.add_url_rule('/success/<name>', 'success', success)
  49. app.add_url_rule('/login', 'login', login, methods = ['POST', 'GET'])
  50. app.add_url_rule('/req', 'req', req, methods = ['POST', 'GET'])
  51. app.run(host="104.248.118.130",debug=True)