Compare commits
No commits in common. "b1557ae5f5eff44b885f5f1368f5963e17f0d86f" and "f6ca5b2f7a1ef0f3c1c3ee1d77ee5b203226ac3e" have entirely different histories.
b1557ae5f5
...
f6ca5b2f7a
73
app.py
73
app.py
@ -2,29 +2,13 @@ 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
|
||||
@ -32,17 +16,13 @@ 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():
|
||||
@ -51,25 +31,28 @@ 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")
|
||||
|
||||
# Generate HTML for a form widget
|
||||
def home2(name):
|
||||
# app.route('/home2/<name>')
|
||||
# return redirect(url_for('home'))
|
||||
return render_template("home.html")
|
||||
|
||||
def success(name):
|
||||
return "welcome %s" % name
|
||||
|
||||
# this is a weird way to do this
|
||||
# right?
|
||||
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></input"%(widg.w_name, widg.w_name)
|
||||
elif(widg.w_type == "textarea"):
|
||||
# Return HTML for a big text input box
|
||||
return "textarea cols=40 id=id_%s name=%s rows=10 required=\"\""%(widg.w_name, widg.w_name)
|
||||
elif(widg.w_type == "check"):
|
||||
# Return HTML for a check box
|
||||
return "input id=id_%s name=%s type=checkbox required=\"\""%(widg.w_name, widg.w_name)
|
||||
return widg.w_type;
|
||||
|
||||
# Generate HTML for request form
|
||||
# probably a strange way to do this...
|
||||
def req():
|
||||
app.route('/req')
|
||||
class Widg:
|
||||
@ -77,8 +60,7 @@ def req():
|
||||
self.w_name = w_name
|
||||
self.w_type = w_type
|
||||
self.w_opt = w_opt
|
||||
|
||||
# Configuration for our request form
|
||||
|
||||
rt = {
|
||||
"username": Widg("username", "input", None),
|
||||
"email for account lockout / registration confirmation (optional)": Widg("email", "input", None),
|
||||
@ -86,14 +68,13 @@ def req():
|
||||
"shell of choice": Widg("shell", "choice", map(lambda k : (k, conf_obj["shell"][k]), list(conf_obj["shell"].keys()))),
|
||||
"have you read the rules?": Widg("rule_read", "check", None)
|
||||
};
|
||||
|
||||
# uhhh is this how you're supposed to do this?
|
||||
return render_template("req.html", req_tab = rt, widg_fun = widg_fun, page_name="req")
|
||||
|
||||
# Process input from the /req page
|
||||
def signup():
|
||||
app.route('/req/signup')
|
||||
|
||||
# Get all the params from the POST
|
||||
# request
|
||||
username = request.form["username"]
|
||||
email = request.form["email"]
|
||||
shell = request.form["shell"]
|
||||
@ -101,23 +82,14 @@ def signup():
|
||||
|
||||
is_email_user = False;
|
||||
|
||||
# If a user didnt read the rules
|
||||
# send them back
|
||||
# Browser validations should
|
||||
# prevent this....
|
||||
if(rule_read != "on"):
|
||||
return redirect(url_for('req'))
|
||||
|
||||
# Set placeholder if user didnt send an email
|
||||
if(len(email) > 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
|
||||
@ -127,8 +99,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")
|
||||
@ -137,9 +109,20 @@ def signup():
|
||||
|
||||
print(username + " " + email + " " + shell + " " + rule_read)
|
||||
return render_template("signup.html", is_email_user = is_email_user)
|
||||
|
||||
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
user = request.form["nm"]
|
||||
return redirect(url_for('success', name = user))
|
||||
else:
|
||||
return redirect(url_for('home'))
|
||||
|
||||
if __name__=="__main__":
|
||||
app.add_url_rule('/home2/<name>', 'home2', home2)
|
||||
app.add_url_rule('/rules', 'rules', rules)
|
||||
app.add_url_rule('/success/<name>', 'success', success)
|
||||
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=conf_obj["listen_ip"],debug=True)
|
||||
app.run(host="104.248.118.130",debug=True)
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"instance_name": "lingy.in",
|
||||
"listen_ip": "104.248.118.130",
|
||||
"shell": {
|
||||
"SHELL_BASH": "/usr/local/bin/bash",
|
||||
"SHELL_KSH": "/bin/ksh"
|
||||
|
@ -2,26 +2,16 @@
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use JSON;
|
||||
|
||||
my $WORKING_DIR = "/home/gashapwn/lyadmin/";
|
||||
my $ACCOUNT_DIR = "test/";
|
||||
|
||||
my $FULL_PATH = "$WORKING_DIR$ACCOUNT_DIR";
|
||||
my $CONF_PATH = $WORKING_DIR."lyadmin.conf.json";
|
||||
my $SHELL_ENUM;
|
||||
|
||||
open FILE, $CONF_PATH or die "could not open file $CONF_PATH";
|
||||
{
|
||||
my $conf_str;
|
||||
my $conf_obj;
|
||||
local $/=undef;
|
||||
$conf_str = <FILE>;
|
||||
chomp $conf_str;
|
||||
$conf_obj = decode_json($conf_str);
|
||||
$SHELL_ENUM = $conf_obj->{"shell"};
|
||||
my $SHELL_ENUM = {
|
||||
"SHELL_BASH" => "/usr/local/bin/bash",
|
||||
"SHELL_KSH" => "/bin/ksh"
|
||||
};
|
||||
close FILE;
|
||||
|
||||
my @g;
|
||||
|
||||
@ -38,16 +28,13 @@ sub create($){
|
||||
open FILE, $fn1 or die "could not open file $fn1";
|
||||
$username = <FILE>;
|
||||
chomp $username;
|
||||
|
||||
|
||||
$user_email = <FILE>;
|
||||
chomp $user_email;
|
||||
|
||||
{
|
||||
my $s0 = <FILE>;
|
||||
chomp $s0;
|
||||
unless($SHELL_ENUM->{$s0}){
|
||||
die "invalid shell setting $s0 in file $id.ident";
|
||||
}
|
||||
$shell_pref = $SHELL_ENUM->{$s0};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user