Functions for publish website by ftp or sftp
This commit is contained in:
@@ -15,6 +15,8 @@ from app.forms import Login
|
||||
from functools import wraps
|
||||
from app.utils import login_required
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
@@ -27,6 +29,7 @@ bcrypt = Bcrypt(app)
|
||||
|
||||
EXT_IMG = {'.jpg', '.JPG', '.png', '.PNG', '.gif', '.GIF', '.bmp', '.BMP', '.jpeg', '.JPEG' }
|
||||
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
form = Login()
|
||||
@@ -44,6 +47,7 @@ def login():
|
||||
|
||||
if bcrypt.check_password_hash(passwd_bcrypt, password) is True:
|
||||
session['username'] = login
|
||||
session['upload'] = None
|
||||
resp = redirect(url_for('edit', _external=True))
|
||||
else:
|
||||
flash(u'Mauvais mot de passe', 'error')
|
||||
@@ -68,19 +72,17 @@ def edit(page):
|
||||
user = '%s'% escape(session['username'])
|
||||
page = '%s' % escape(page)
|
||||
db = DataSite(user, USERS_FOLDER)
|
||||
mypages = db.get_pages()
|
||||
theme = db.datas['config']['theme']
|
||||
menu = db.datas['menu']
|
||||
myblocs = db.get_blocs(page)['blocs']
|
||||
|
||||
print(myblocs)
|
||||
return render_template('/edit.html.tpl',
|
||||
blocEdit="",
|
||||
config=db.datas['config'],
|
||||
menu=menu,
|
||||
theme=theme,
|
||||
pagesList=mypages,
|
||||
menu=db.datas['menu'],
|
||||
theme=db.datas['config']['theme'],
|
||||
pagesList=db.get_pages(),
|
||||
page=page,
|
||||
myblocs=myblocs
|
||||
myblocs=myblocs,
|
||||
serverInfos=db.datas['publish']
|
||||
)
|
||||
|
||||
|
||||
@@ -102,7 +104,7 @@ def edit_photo(page, image, bloc):
|
||||
if request.method == 'POST':
|
||||
myblocs[bloc][image] = db.update_img(image, form)
|
||||
db.save_blocs(page, myblocs)
|
||||
form = MyBlocs.makeForm(db.datas['blocs'][bloc])
|
||||
form = MyBlocs.make_form(db.datas['blocs'][bloc])
|
||||
if "hx-request" in request.headers:
|
||||
return make_response(('Image modified', 200))
|
||||
else:
|
||||
@@ -149,7 +151,7 @@ def drop_upload(page, bloc):
|
||||
img.thumbnail((640,480))
|
||||
img.save(os.path.join(save_path, 'thumbnails', filename ) )
|
||||
|
||||
myblocs[bloc][filename] = db.addImg(filename)
|
||||
myblocs[bloc][filename] = db.add_img(filename)
|
||||
db.save_blocs(page, myblocs)
|
||||
return make_response(('Chunk upload succesfull', 200))
|
||||
|
||||
@@ -209,7 +211,7 @@ def edit_bloc(page, blocname):
|
||||
bg_custom = 'bg_custom_'+bloc['name']+filename
|
||||
file.save(os.path.join(USERS_FOLDER, user, 'public', 'img', bg_custom ))
|
||||
if 'bg_img' in bloc.keys():
|
||||
db.delImg(bloc, bloc['bg_img'])
|
||||
db.del_img(bloc, bloc['bg_img'])
|
||||
|
||||
|
||||
myblocs[blocname]['bg_img'] = bg_custom
|
||||
@@ -340,7 +342,7 @@ def rm_page(pageName):
|
||||
def sortblocs(page):
|
||||
user = '%s'% escape(session['username'])
|
||||
page = '%s' % escape(page)
|
||||
|
||||
|
||||
db = DataSite(user, USERS_FOLDER)
|
||||
config = db.datas['config']
|
||||
menu = db.datas['menu']
|
||||
@@ -403,6 +405,39 @@ def favicon():
|
||||
return make_response(('Ok! ', 200))
|
||||
|
||||
|
||||
@app.route('/publish_progress/', methods=['GET'])
|
||||
@login_required
|
||||
def publish_progress():
|
||||
user = '%s' % escape(session['username'])
|
||||
db = DataSite(user, USERS_FOLDER)
|
||||
progress = 0
|
||||
|
||||
error = False
|
||||
completed = False
|
||||
status = db.get_status_publish()
|
||||
|
||||
match status:
|
||||
case "Generated" :
|
||||
progress = 30
|
||||
case "Login Incorrect" | "Upload error" :
|
||||
progress = 100
|
||||
error = True
|
||||
case "Identification verified":
|
||||
progress = 50
|
||||
status = "Upload ..."
|
||||
case "Uploaded":
|
||||
progress = 80
|
||||
status = "Set permissions ..."
|
||||
case str(x) if "Uploaded at:" in x:
|
||||
progress = 100
|
||||
completed = True
|
||||
status = status.replace("Uploaded at:", "")
|
||||
|
||||
return render_template('admin/_publish-progress.html', progress=progress,
|
||||
status=status,
|
||||
error = error,
|
||||
completed = completed)
|
||||
|
||||
|
||||
|
||||
@app.route('/publish', methods=['POST'])
|
||||
@@ -416,12 +451,13 @@ def publish():
|
||||
test_alphanum = "^[A-Za-z0-9/_-]*$"
|
||||
|
||||
|
||||
serverAddress = str(request.form['serverAddress'])
|
||||
serverPort = str(request.form['serverPort'])
|
||||
username = str(request.form['username'])
|
||||
password = str(request.form['password'])
|
||||
folder = str(request.form['folder'])
|
||||
|
||||
serverInfos = dict()
|
||||
serverInfos['Address'] = str(request.form['serverAddress'])
|
||||
serverInfos['Port'] = str(request.form['serverPort'])
|
||||
serverInfos['username'] = str(request.form['username'])
|
||||
serverInfos['folder'] = str(request.form['folder'])
|
||||
|
||||
for page in listPages:
|
||||
myblocs = db.get_blocs(page)['blocs']
|
||||
@@ -433,6 +469,7 @@ def publish():
|
||||
myblocs=myblocs)
|
||||
db.writeHTML(theme, page, htmlExport)
|
||||
|
||||
|
||||
# Export index.html landing page
|
||||
myblocs = db.get_blocs('')['blocs']
|
||||
htmlExport = render_template('/index.html.tpl',
|
||||
@@ -444,21 +481,34 @@ def publish():
|
||||
|
||||
db.writeHTML(theme, '/', htmlExport)
|
||||
db.copy_static_files()
|
||||
db.update_status_publish("Generated")
|
||||
|
||||
if serverPort == '' or serverPort.isdigit() == False :
|
||||
|
||||
if serverInfos['Port'] == '' or serverInfos['Port'].isdigit() == False :
|
||||
serverPort = '22'
|
||||
|
||||
|
||||
|
||||
if folder == '' :
|
||||
folder = '/'
|
||||
elif(bool(re.match(test_alphanum, folder)) == False):
|
||||
if serverInfos['folder'] == '' :
|
||||
folder = '/'
|
||||
elif(bool(re.match(test_alphanum, serverInfos['folder'])) == False):
|
||||
serverInfos['folder'] = '/'
|
||||
|
||||
|
||||
if db.publish(username, password, serverAddress, serverPort, folder) == False:
|
||||
return make_response(('Impossible de publier le site ', 500))
|
||||
if db.test_server_login(serverInfos, password ) == False:
|
||||
db.update_status_publish ("Identification Incorrect")
|
||||
return make_response(('Login Incorrect', 500))
|
||||
else:
|
||||
db.update_status_publish("Identification verified")
|
||||
if db.publish(serverInfos, password) == False:
|
||||
db.update_status_publish ("Upload error")
|
||||
return make_response('Upload Error !')
|
||||
|
||||
#Generate date of success upload
|
||||
now = datetime.now()
|
||||
date_upload = now.strftime("%d/%m/%Y, %H:%M:%S")
|
||||
db.update_status_publish ("Uploaded at: "+date_upload)
|
||||
db.save_server_info(serverInfos)
|
||||
|
||||
return redirect(url_for('edit'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user