2022-07-04 22:52:06 +02:00
|
|
|
#!/usr/local/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from flask import Flask, request, flash, render_template, url_for, session, redirect, abort, make_response, send_file, escape, send_from_directory
|
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
from wtforms import BooleanField, StringField, IntegerField, PasswordField, validators
|
|
|
|
import sqlite3
|
|
|
|
from flask_bcrypt import Bcrypt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from views.blog import blog
|
|
|
|
from views.filesupload import filesupload
|
|
|
|
from views.inscription import inscription
|
|
|
|
from views.profil import profil
|
|
|
|
from views.logs import logs
|
|
|
|
from views.loginlogout import loginlogout
|
|
|
|
|
|
|
|
from tools.databaseinit import init_db, init_dir
|
|
|
|
|
|
|
|
import glob, os, sys, time
|
|
|
|
|
|
|
|
app = Flask( 'pywallter' )
|
|
|
|
bcrypt = Bcrypt(app)
|
|
|
|
|
|
|
|
if init_db():
|
|
|
|
print ("La base de données a été créer")
|
|
|
|
exit()
|
|
|
|
|
|
|
|
if init_dir():
|
|
|
|
print ("Le repertoire des utilisateurs a été créer")
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set the secret key. Keep this really secret
|
|
|
|
app.secret_key = 'klfkdlfkdslfkln234325;cx!' # Chiffre les cookies si j'ai bien capté.
|
|
|
|
# À générer aléatoirement impérativement avant de mettre en ligne.
|
|
|
|
|
|
|
|
#### Variables ####################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
DOSSIER_PERSO='users/'
|
|
|
|
|
|
|
|
extensionimg = {'.jpg', '.JPG', '.png', '.PNG', '.gif', '.GIF', '.bmp', '.BMP', '.jpeg', '.JPEG' }
|
|
|
|
|
|
|
|
##################################################################################################
|
|
|
|
|
|
|
|
app.register_blueprint(inscription)
|
|
|
|
app.register_blueprint(blog)
|
|
|
|
app.register_blueprint(filesupload)
|
|
|
|
app.register_blueprint(profil)
|
|
|
|
app.register_blueprint(logs)
|
|
|
|
app.register_blueprint(loginlogout)
|
|
|
|
|
|
|
|
@app.route( '/gallery/')
|
|
|
|
def gallery():
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
THUMBNAILS=DOSSIER_PERSO + UTILISATEUR + '/images/thumbnails/'
|
|
|
|
fichiers = [fich for fich in os.listdir(THUMBNAILS)]
|
|
|
|
return render_template('gallery.html', THUMBNAILS=THUMBNAILS, fichiers=fichiers)
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
@app.route( '/parametres/', methods=['GET','POST'] )
|
|
|
|
def parametres() :
|
|
|
|
if 'username' in session :
|
|
|
|
return render_template('parametres.html')
|
|
|
|
else:
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
@app.route('/up/view/<nom>')
|
|
|
|
def download(nom):
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
nom = secure_filename(nom)
|
|
|
|
if os.path.isfile(DOSSIER_PERSO + UTILISATEUR + '/files/' + nom): # si le fichier existe
|
|
|
|
return send_file(DOSSIER_PERSO + UTILISATEUR + '/files/' + nom, as_attachment=True) # on l'envoie
|
|
|
|
else:
|
|
|
|
flash(u'Fichier {nom} inexistant.'.format(nom=nom), 'error')
|
|
|
|
return redirect(url_for('list')) # sinon on redirige vers la liste, avec un message d'erreur
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
@app.route('/remove/<nom>')
|
|
|
|
def remove(nom):
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
nom = secure_filename(nom)
|
|
|
|
if os.path.isfile(DOSSIER_PERSO + UTILISATEUR + '/files/' + nom): # si le fichier existe
|
|
|
|
os.remove(DOSSIER_PERSO + UTILISATEUR + '/files/' + nom) # on le supprime
|
|
|
|
return redirect(url_for('filesupload.list', _external=True))
|
|
|
|
else:
|
|
|
|
if os.path.isfile(DOSSIER_PERSO + UTILISATEUR + '/images/thumbnails/' + nom): # si le fichier existe
|
|
|
|
os.remove(DOSSIER_PERSO + UTILISATEUR + '/images/thumbnails/' + nom) # on le supprime
|
|
|
|
os.remove(DOSSIER_PERSO + UTILISATEUR + '/images/' + nom) # on le supprime
|
|
|
|
return redirect(url_for('gallery'))
|
|
|
|
else:
|
|
|
|
flash(u'Fichier {nom} inexistant.'.format(nom=nom), 'error')
|
|
|
|
return redirect(url_for('filesupload.list', _external=True)) # sinon on redirige vers la liste, avec un message d'erreur
|
|
|
|
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/myfiles/<filename>')
|
|
|
|
def myfiles(filename):
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
return send_from_directory(
|
|
|
|
os.path.join(DOSSIER_PERSO, UTILISATEUR, 'files'), filename )
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route('/myfiles/images/<filename>')
|
|
|
|
def myimg(filename):
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
return send_from_directory(
|
|
|
|
os.path.join(DOSSIER_PERSO, UTILISATEUR, 'images'), filename )
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
@app.route('/myfiles/images/thumbnails/<filename>')
|
|
|
|
def mythumbnails(filename):
|
|
|
|
if 'username' in session :
|
|
|
|
UTILISATEUR='%s' % escape(session['username'])
|
|
|
|
return send_from_directory(
|
|
|
|
os.path.join(DOSSIER_PERSO, UTILISATEUR, 'images/thumbnails'), filename )
|
|
|
|
else :
|
2022-07-05 01:18:52 +02:00
|
|
|
return redirect(url_for('loginlogout.login'))
|
2022-07-04 22:52:06 +02:00
|
|
|
|
|
|
|
@app.route( '/' )
|
|
|
|
def index():
|
|
|
|
if 'username' in session :
|
|
|
|
return redirect(url_for('filesupload.uploadfiles'))
|
|
|
|
else :
|
|
|
|
return redirect(url_for('loginlogout.login', _external=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
app.run(host='127.0.0.1', port=8080, debug=True)
|