notifier support

This commit is contained in:
Ville Rantanen
2018-02-19 14:37:08 +02:00
parent 1be6a713a6
commit 43e45f0592
4 changed files with 77 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ import hashlib
import zipfile
from revprox import ReverseProxied
__FLEES_VERSION__ = "20180218.1"
__FLEES_VERSION__ = "20180219.0"
app = Flask(__name__)
app.config.from_object(__name__)
# Read config from json !
@@ -25,6 +25,16 @@ app.config['DATE_FORMAT'] = config_values['date_format']
app.config['UID'] = config_values['uid']
app.config['GID'] = config_values['gid']
app.config['DEBUG'] = config_values['debug']
if 'notifier' in config_values:
if len(config_values['notifier']) > 0:
notifier_config = config_values['notifier'].split(":")
imported = getattr(__import__(
notifier_config[0],
fromlist=[notifier_config[1]]
),
notifier_config[1]
)
app.config['notifier'] = imported()
app.secret_key = config_values['app_secret_key']
app.wsgi_app = ReverseProxied(app.wsgi_app)
@@ -93,6 +103,12 @@ def upload(name = None, password = None):
return "Overwrite forbidden", 403
file.save(filename)
set_rights(filename)
notify({
"recipient": get_or_none(share,'recipient'),
"share": name,
"filename": filename,
"operation": "upload"
})
if 'from_gui' in request.form:
if request.form['from_gui'] == "true":
return redirect(url_for('list_view',name=name))
@@ -169,6 +185,12 @@ def download_direct(name,password,filename):
file_path = os.path.join(share['path'], filename)
if not os.path.exists(file_path):
return 'no such file', 404
notify({
"recipient": get_or_none(share,'recipient'),
"share": name,
"filename": file_path,
"operation": "direct_download"
})
return send_from_directory(directory=share['path'], filename=filename)
@@ -183,6 +205,12 @@ def download_file(name,filename,password = None):
file_path = os.path.join(share['path'], filename)
if not os.path.exists(file_path):
return 'no such file', 404
notify({
"recipient": get_or_none(share,'recipient'),
"share": name,
"filename": file_path,
"operation": "download"
})
return send_from_directory(directory=share['path'], filename=filename)
@@ -199,6 +227,12 @@ def download_zip(name,password = None):
return "Maximum ZIP size exceeded", 400
zip_clean()
zip_path = zip_share(share)
notify({
"recipient": get_or_none(share,'recipient'),
"share": name,
"filename": name + ".zip",
"operation": "zip_download"
})
return send_file(
zip_path,
as_attachment = True,
@@ -342,6 +376,10 @@ def makedirs_rights(path):
os.mkdir(current_path)
set_rights(current_path)
def notify(msg):
if 'notifier' in app.config:
app.config['notifier'].notify(msg)
def set_rights(path):
os.chown(path, app.config['UID'], app.config['GID'])