|
@ -37,10 +37,11 @@ from app import create_app, db, login_manager |
|
|
from usermodel import User |
|
|
from usermodel import User |
|
|
|
|
|
|
|
|
# Forms! |
|
|
# Forms! |
|
|
from loginform import LoginForm |
|
|
from forms.loginform import LoginForm |
|
|
from registerform import RegisterForm |
|
|
from forms.registerform import RegisterForm |
|
|
from uploadform import UploadForm |
|
|
from forms.uploadform import UploadForm |
|
|
from distribusiform import DistribusiForm |
|
|
from forms.distribusiform import DistribusiForm |
|
|
|
|
|
from forms.themeform import ThemeForm |
|
|
|
|
|
|
|
|
# Tada! |
|
|
# Tada! |
|
|
from distribusi.cli import build_argparser |
|
|
from distribusi.cli import build_argparser |
|
@ -129,32 +130,35 @@ def register(): |
|
|
def distribusi(): |
|
|
def distribusi(): |
|
|
uploadform = UploadForm() |
|
|
uploadform = UploadForm() |
|
|
distribusiform = DistribusiForm() |
|
|
distribusiform = DistribusiForm() |
|
|
|
|
|
themeform = ThemeForm() |
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
if user.distribusiname is None: |
|
|
if user.distribusiname is None: |
|
|
print("nothing to deploy!") |
|
|
print("nothing to deploy!") |
|
|
if distribusiform.validate_on_submit(): |
|
|
if distribusiform.validate_on_submit(): |
|
|
zipfilename = "{}.zip".format(user.distribusiname) |
|
|
zipfilename = "{}.zip".format(user.distribusiname) |
|
|
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename) |
|
|
userfolder = os.path.join("stash", user.distribusiname) |
|
|
|
|
|
unzipfile = os.path.join(userfolder, 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: |
|
|
with zipfile.ZipFile(unzipfile, "r") as zip_ref: |
|
|
# To do, replace extractall with inspection and extract |
|
|
# 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() |
|
|
parser = build_argparser() |
|
|
args = parser.parse_args() |
|
|
args = parser.parse_args(['-s', cssfile]) |
|
|
distribusify(args, newuserfolder) |
|
|
distribusify(args, userfolder) |
|
|
return redirect(url_for("index")) |
|
|
return redirect(url_for("index")) |
|
|
template = render_template( |
|
|
template = render_template( |
|
|
"distribusi.html", |
|
|
"distribusi.html", |
|
|
uploadform=uploadform, |
|
|
uploadform=uploadform, |
|
|
distribusiform=distribusiform, |
|
|
distribusiform=distribusiform, |
|
|
|
|
|
themeform=themeform, |
|
|
) |
|
|
) |
|
|
return template |
|
|
return template |
|
|
|
|
|
|
|
@ -165,6 +169,7 @@ def upload(): |
|
|
success = False |
|
|
success = False |
|
|
uploadform = UploadForm() |
|
|
uploadform = UploadForm() |
|
|
distribusiform = DistribusiForm() |
|
|
distribusiform = DistribusiForm() |
|
|
|
|
|
themeform = ThemeForm() |
|
|
if uploadform.validate_on_submit(): |
|
|
if uploadform.validate_on_submit(): |
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
user.distribusiname = uploadform.sitename.data |
|
|
user.distribusiname = uploadform.sitename.data |
|
@ -174,14 +179,45 @@ def upload(): |
|
|
zipfile = uploadform.zipfile.data |
|
|
zipfile = uploadform.zipfile.data |
|
|
zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) |
|
|
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 |
|
|
success = True |
|
|
template = render_template( |
|
|
template = render_template( |
|
|
"distribusi.html", |
|
|
"distribusi.html", |
|
|
uploadform=uploadform, |
|
|
uploadform=uploadform, |
|
|
distribusiform=distribusiform, |
|
|
distribusiform=distribusiform, |
|
|
success=success, |
|
|
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>") |
|
|
@APP.route("/stash/<path:path>") |
|
|