|
|
@ -37,10 +37,11 @@ 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 |
|
|
|
from forms.loginform import LoginForm |
|
|
|
from forms.registerform import RegisterForm |
|
|
|
from forms.uploadform import UploadForm |
|
|
|
from forms.distribusiform import DistribusiForm |
|
|
|
from forms.themeform import ThemeForm |
|
|
|
|
|
|
|
# Tada! |
|
|
|
from distribusi.cli import build_argparser |
|
|
@ -129,32 +130,35 @@ def register(): |
|
|
|
def distribusi(): |
|
|
|
uploadform = UploadForm() |
|
|
|
distribusiform = DistribusiForm() |
|
|
|
themeform = ThemeForm() |
|
|
|
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) |
|
|
|
userfolder = os.path.join("stash", user.distribusiname) |
|
|
|
unzipfile = os.path.join(userfolder, zipfilename) |
|
|
|
with zipfile.ZipFile(unzipfile, "r") as zip_ref: |
|
|
|
# To do, replace extractall with inspection and extract |
|
|
|
zip_ref.extractall(newuserfolder) |
|
|
|
zip_ref.extractall(userfolder) |
|
|
|
|
|
|
|
os.remove(os.path.join(userfolder, zipfilename)) |
|
|
|
# To Do: Make sure nothing can be executed from the upload folder |
|
|
|
# add the css file |
|
|
|
cssfile = "" |
|
|
|
for filename in os.listdir(userfolder): |
|
|
|
if filename.endswith('.css'): |
|
|
|
cssfile = os.path.join(userfolder, filename) |
|
|
|
|
|
|
|
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) |
|
|
|
args = parser.parse_args(['-s', cssfile]) |
|
|
|
distribusify(args, userfolder) |
|
|
|
return redirect(url_for("index")) |
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
themeform=themeform, |
|
|
|
) |
|
|
|
return template |
|
|
|
|
|
|
@ -165,6 +169,7 @@ def upload(): |
|
|
|
success = False |
|
|
|
uploadform = UploadForm() |
|
|
|
distribusiform = DistribusiForm() |
|
|
|
themeform = ThemeForm() |
|
|
|
if uploadform.validate_on_submit(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
user.distribusiname = uploadform.sitename.data |
|
|
@ -174,14 +179,45 @@ def upload(): |
|
|
|
zipfile = uploadform.zipfile.data |
|
|
|
zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) |
|
|
|
|
|
|
|
newuserfolder = os.path.join("stash", user.distribusiname) |
|
|
|
if not os.path.exists(newuserfolder): |
|
|
|
os.mkdir(newuserfolder) |
|
|
|
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename) |
|
|
|
shutil.copy(copyzipfile, newuserfolder) |
|
|
|
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) |
|
|
|
success = True |
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
success=success, |
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
success=success, |
|
|
|
themeform=themeform, |
|
|
|
) |
|
|
|
return template |
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/theme", methods=["POST"]) |
|
|
|
@login_required |
|
|
|
def theme(): |
|
|
|
uploadform = UploadForm() |
|
|
|
distribusiform = DistribusiForm() |
|
|
|
themeform = ThemeForm() |
|
|
|
if themeform.validate_on_submit(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
newuserfolder = os.path.join("stash", user.distribusiname) |
|
|
|
copycssfile = os.path.join( |
|
|
|
"themes", |
|
|
|
"{}.css".format(themeform.theme.data), |
|
|
|
) |
|
|
|
return template |
|
|
|
shutil.copy(copycssfile, newuserfolder) |
|
|
|
|
|
|
|
template = render_template( |
|
|
|
"distribusi.html", |
|
|
|
uploadform=uploadform, |
|
|
|
distribusiform=distribusiform, |
|
|
|
themeform=themeform, |
|
|
|
) |
|
|
|
return template |
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/stash/<path:path>") |
|
|
|