mirror of
https://github.com/FAUSheppy/jeffrey_miller_flask_ftp
synced 2025-12-06 07:51:34 +01:00
skeleton routes
This commit is contained in:
19
server.py
19
server.py
@@ -14,11 +14,18 @@ from sqlalchemy.sql import func
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
app = flask.Flask("Flask-VSFTP-User-Tool")
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
HTTP_FORBIDDEN = 401
|
||||
HTTP_NOT_FOUND = 404
|
||||
HTTP_UNPROCESSABLE = 422
|
||||
HTTP_INTERNAL_ERR = 500
|
||||
|
||||
# unix useradd requires exactly this salt, do not change
|
||||
PAM_PASSWD_SALT = "22"
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return flask.render_template("index.html")
|
||||
@@ -29,20 +36,20 @@ def createUser():
|
||||
return ("Success", 200)
|
||||
|
||||
@app.route('/delete-user', methods=["POST"])
|
||||
def createUser():
|
||||
deleteUser(user=flask.request.get('user')
|
||||
def deleteUser():
|
||||
deleteUser(user=flask.request.get('user'))
|
||||
return ("Success", 200)
|
||||
|
||||
@app.route('/list-user')
|
||||
def listUsers(''):
|
||||
@app.route('/list-users')
|
||||
def listUsers():
|
||||
users = db.session.query(FTPUser)
|
||||
return flask.render_template("list_users.html", users=users)
|
||||
|
||||
def createUser(webform):
|
||||
|
||||
# command line useradd requires a pre-encrypted password
|
||||
cryptPass = crypt.crypt(password, webform.password)
|
||||
subprocess.run(["./scripts/create_user.sh", cryptPass, webform.username])
|
||||
cryptPass = crypt.crypt(webform['password'], PAM_PASSWD_SALT)
|
||||
subprocess.run(["./scripts/create_user.sh", cryptPass, webform['username']])
|
||||
|
||||
# track added users to prevent deletion of other users and listing #
|
||||
db.session.add(FTPUser(webform.username))
|
||||
|
||||
Reference in New Issue
Block a user