Update README and minor updates

This commit is contained in:
Léo 2020-11-05 15:31:31 +01:00
parent 8b129324e4
commit 031f620486
3 changed files with 29 additions and 18 deletions

View File

@ -1,27 +1,36 @@
# Jeu de belote # SFS - Simple file system
Simple file server to be used easily with curl. Simple file server (web-based) to be used easily with curl. Written in python with framework flask. By default it used a simple SQLite database, but this can be adapted to your needs by editing config files.
L'ensemble de ce dépôt est sous licence GPL v3. Scripts to use with bash and curl are available in the scripts folder. You can set your default server, username and password in the header of the script.
This repository is licensed under GPL v3.
## Installation ## Installation
1. Créer un environnement virtuel `venv` (`python3 -m venv venv`) 1. Create a virtual environment `venv` (`python3 -m venv venv`)
2. Activer l'environnement virtuel (`. venv/bin/activate`) 2. Activate (`. venv/bin/activate`)
3. Installer les prérequis (`pip install -r requirements.txt`) 3. Install prerequisite python packages (`pip install -r requirements.txt`)
4. Vous pouvez démarrer le serveur `python fs.py` ! 4. You will have to create a folder to store uploaded files (default is `./data`)
5. Copy files `settings.example.cfg` and `settings.example.py` to `settings.cfg` and `settings.py` and adjust parameters
6. You can start the test server with `python fs.py`
## Configuration an deployment
For deployment, see [Flask documentation](https://flask.palletsprojects.com/en/1.1.x/deploying/).
Configuration of uploading server and limitation of file size, as well as listening url for web server is configured in `settings.py`. Configuration of database is done in `settings.cfg` (use of SQLAlchemy, see corresponding documentation for advanced parameterizations).
## Principe ## Principe
* `fs.py` définit les routes * `fs.py` is the core file
* `db.py` gère le jeu et l'enregistrement en base de donnée * `db.py` defines the database structure
* Le dossier `templates` contient les template jinja2 pour le rendu web * `templates` folder contains all web views to be rendered with Jinja2
* Le dossier `static` contient les scripts, images et feuilles de style * `static` folder contains scripts, css and images
Si aucun utilisateur n'existe dans la base de donnée, un premier utilisateur If at running time, there is no user in database, a first user is created with admin
de login `admin` et de mot de passe `admin` est créé. rights. The login is `admin` and password is `admin`. You have to change it before
A vous de changer le mot de passe avant mise en ligne ! deployment, of course !
## Licence ## Licence

7
fs.py
View File

@ -143,7 +143,7 @@ def uploaderpage():
graphical = True graphical = True
else: else:
graphical = False graphical = False
if 'visible' in flask.request.form and flask.request.form['visible']: if 'visible' in flask.request.form and '1' in flask.request.form['visible']:
visible = True visible = True
else: else:
visible = False visible = False
@ -154,6 +154,7 @@ def uploaderpage():
# Check auth first # Check auth first
if user is None: if user is None:
print(flask.request.form)
if 'username' not in flask.request.form or 'password' not in flask.request.form: if 'username' not in flask.request.form or 'password' not in flask.request.form:
return returnuploader(graphical, 'ERR: You have to provide creedentials or log in', None) return returnuploader(graphical, 'ERR: You have to provide creedentials or log in', None)
username = flask.request.form['username'] username = flask.request.form['username']
@ -172,7 +173,7 @@ def uploaderpage():
ldesc = flask.request.form.getlist('desc[]') ldesc = flask.request.form.getlist('desc[]')
done = 0 done = 0
ret="OK" ret="OK\n"
for i in range(len(lfiles)): for i in range(len(lfiles)):
# if user does not select file, browser also # if user does not select file, browser also
# submit an empty part without filename # submit an empty part without filename
@ -204,7 +205,7 @@ def uploaderpage():
if not os.path.isdir(os.path.dirname(path)): if not os.path.isdir(os.path.dirname(path)):
os.mkdir(os.path.dirname(path)) os.mkdir(os.path.dirname(path))
f.save(path) f.save(path)
ret += "\n/d/{}/{}".format(user.login, name1) ret += "/d/{}/{}\n".format(user.login, name1)
except IOError as err: except IOError as err:
return returnuploader(graphical, 'ERR: Something went wrong when trying to write file to disk', user) return returnuploader(graphical, 'ERR: Something went wrong when trying to write file to disk', user)

View File

@ -38,7 +38,7 @@
<br /> <br />
<table> <table>
<tr> <tr>
<td>Publicly visible: </td><td><input type="checkbox" name="visible" id="visible"> </td> <td>Publicly visible: </td><td><input type="checkbox" name="visible" id="visible" value="1"></td>
</tr><tr> </tr><tr>
<td>Set a password: </td><td><input type="password" name="filepwd" id="filepwd" value=""></td> <td>Set a password: </td><td><input type="password" name="filepwd" id="filepwd" value=""></td>
</tr> </tr>
@ -70,6 +70,7 @@
maxline++; maxline++;
var html = `<td><input type="file" name="file[]"></td> var html = `<td><input type="file" name="file[]"></td>
<td> <input type="text" name="filename[]" placeholder="Change file name" /></td> <td> <input type="text" name="filename[]" placeholder="Change file name" /></td>
<td> <input type="text" name="desc[]" placeholder="Description" /></td>
<td><a href="javascript:dellinef('line${maxline}')"><img src="static/croix.png" alt="Del" /></a></td>` <td><a href="javascript:dellinef('line${maxline}')"><img src="static/croix.png" alt="Del" /></a></td>`
addElement('filelist', 'tr', 'line' + maxline, html); addElement('filelist', 'tr', 'line' + maxline, html);
} }