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.

93 lines
2.9KB

  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.readlines():
  9. u_list.append(line.strip());
  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. app.route('/req')
  31. class Widg:
  32. def __init__(self, w_name, w_type, w_opt):
  33. self.w_name = w_name
  34. self.w_type = w_type
  35. self.w_opt = w_opt
  36. rt = {
  37. "username": Widg("username", "input", None),
  38. "email for account lockout / registration confirmation (optional)": Widg("email", "input", None),
  39. "SSH public key": Widg("pub_key", "textarea", None),
  40. "shell of choice": Widg("shell", "choice", [("bash", "/bin/bash"), ("ksh", "/bin/ksh")]),
  41. "have you read the rules?": Widg("rule_read", "check", None)
  42. };
  43. # uhhh is this how you're supposed to do this?
  44. return render_template("req.html", req_tab = rt, widg_fun = widg_fun, page_name="req")
  45. def signup():
  46. app.route('/req/signup')
  47. username = request.form["username"]
  48. email = request.form["email"]
  49. shell = request.form["shell"]
  50. rule_read = request.form["rule_read"]
  51. is_email_user = False;
  52. if(rule_read != "on"):
  53. return redirect(url_for('req'))
  54. if(len(email) > 1):
  55. is_email_user = True
  56. print(username + " " + email + " " + shell + " " + rule_read)
  57. return render_template("signup.html", is_email_user = is_email_user)
  58. def login():
  59. if request.method == "POST":
  60. user = request.form["nm"]
  61. return redirect(url_for('success', name = user))
  62. else:
  63. return redirect(url_for('home'))
  64. if __name__=="__main__":
  65. app.add_url_rule('/home2/<name>', 'home2', home2)
  66. app.add_url_rule('/rules', 'rules', rules)
  67. app.add_url_rule('/success/<name>', 'success', success)
  68. app.add_url_rule('/login', 'login', login, methods = ['POST', 'GET'])
  69. app.add_url_rule('/req', 'req', req, methods = ['POST', 'GET'])
  70. app.add_url_rule('/req/signup', 'signup', signup, methods = ['POST'])
  71. app.run(host="104.248.118.130",debug=True)