|
|
@ -1,7 +1,10 @@ |
|
|
|
"""This is the main flask distribusi page""" |
|
|
|
import os |
|
|
|
import zipfile |
|
|
|
import shutil |
|
|
|
from datetime import timedelta |
|
|
|
|
|
|
|
|
|
|
|
from flask import ( |
|
|
|
render_template, |
|
|
|
redirect, |
|
|
@ -31,9 +34,12 @@ from flask_wtf.csrf import CSRFError |
|
|
|
|
|
|
|
from app import create_app, db, login_manager |
|
|
|
from usermodel import User |
|
|
|
|
|
|
|
# Forms! |
|
|
|
from loginform import LoginForm |
|
|
|
from registerform import RegisterForm |
|
|
|
from uploadform import UploadForm |
|
|
|
from distribusiform import DistribusiForm |
|
|
|
|
|
|
|
# Tada! |
|
|
|
from distribusi.cli import build_argparser |
|
|
@ -112,21 +118,64 @@ def register(): |
|
|
|
return render_template("register.html", registerform=registerform) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/distribusi") |
|
|
|
@APP.route("/distribusi", methods=["GET", "POST"]) |
|
|
|
@login_required |
|
|
|
def distribusi(): |
|
|
|
uploadform = UploadForm() |
|
|
|
return render_template("distribusi.html", uploadform=uploadform) |
|
|
|
distribusiform = DistribusiForm() |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
if user.distribusiname is None: |
|
|
|
print("nothing to deploy!") |
|
|
|
if distribusiform.validate_on_submit(): |
|
|
|
zipfilename = "{}.zip".format(user.distribusiname) |
|
|
|
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename) |
|
|
|
|
|
|
|
newuserfolder = os.path.join("stash", user.distribusiname) |
|
|
|
os.mkdir(newuserfolder) |
|
|
|
shutil.copy(copyzipfile, newuserfolder) |
|
|
|
unzipfile = os.path.join(newuserfolder, zipfilename) |
|
|
|
with zipfile.ZipFile(unzipfile, "r") as zip_ref: |
|
|
|
# To do, replace extractall with inspection and extract |
|
|
|
zip_ref.extractall(newuserfolder) |
|
|
|
|
|
|
|
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) |
|
|
|
os.remove(os.path.join(newuserfolder, zipfilename)) |
|
|
|
# Make sure nothing can be executed from the upload folder |
|
|
|
parser = build_argparser() |
|
|
|
args = parser.parse_args() |
|
|
|
distribusify(args, newuserfolder) |
|
|
|
return render_template("index.html") |
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
) |
|
|
|
return template |
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/upload", methods=["POST"]) |
|
|
|
@login_required |
|
|
|
def upload(): |
|
|
|
success = False |
|
|
|
uploadform = UploadForm() |
|
|
|
if (uploadform.validate_on_submit()): |
|
|
|
distribusiform = DistribusiForm() |
|
|
|
if uploadform.validate_on_submit(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
user.distribusiname = uploadform.sitename.data |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
zipfilename = "{}.zip".format(user.distribusiname) |
|
|
|
zipfile = uploadform.zipfile.data |
|
|
|
zipfile.save(os.path.join(APP.config['UPLOAD_FOLDER'], zipfile.filename)) |
|
|
|
return render_template("distribusi.html", uploadform=uploadform) |
|
|
|
zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) |
|
|
|
|
|
|
|
success = True |
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
success=success, |
|
|
|
) |
|
|
|
return template |
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/admin") |
|
|
|