uploader with progress bar. reown log file
This commit is contained in:
11
code/app.py
11
code/app.py
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os,sys,time,stat
|
import os, sys, time
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import Flask, render_template, jsonify, current_app, Response, \
|
from flask import Flask, render_template, jsonify, current_app, Response, \
|
||||||
@@ -883,15 +883,6 @@ def secure_filename_hidden(filename):
|
|||||||
return secure
|
return secure
|
||||||
|
|
||||||
|
|
||||||
def set_rights(path):
|
|
||||||
os.chown(path, app.config['UID'], app.config['GID'])
|
|
||||||
st = os.stat(path)
|
|
||||||
if app.config['UID'] > 0:
|
|
||||||
os.chmod(path, st.st_mode | stat.S_IRUSR | stat.S_IWUSR)
|
|
||||||
if app.config['GID'] > 0:
|
|
||||||
os.chmod(path, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)
|
|
||||||
|
|
||||||
|
|
||||||
def zip_share(share):
|
def zip_share(share):
|
||||||
if not os.path.exists(app.config['ZIP_FOLDER']):
|
if not os.path.exists(app.config['ZIP_FOLDER']):
|
||||||
os.makedirs(app.config['ZIP_FOLDER'])
|
os.makedirs(app.config['ZIP_FOLDER'])
|
||||||
|
|||||||
@@ -3,18 +3,15 @@ test -n "$1" || {
|
|||||||
echo "Add files to upload as argument"
|
echo "Add files to upload as argument"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
CAT=$( which cat )
|
|
||||||
which pv &> /dev/null && CAT=$( which pv )
|
|
||||||
ROOTURL="{{ rooturl }}"
|
ROOTURL="{{ rooturl }}"
|
||||||
SHARE="{{ name }}"
|
SHARE="{{ name }}"
|
||||||
TOKEN="{{ token }}"
|
TOKEN="{{ token }}"
|
||||||
|
|
||||||
send_file() {
|
send_file() {
|
||||||
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" "${ROOTURL}upload/${SHARE}/${TOKEN}"
|
cat "$file_name" | curl --progress-bar -F "file=@-;filename=${base_name}" "${ROOTURL}upload/${SHARE}/${TOKEN}" | cat -
|
||||||
}
|
}
|
||||||
send_folder() {
|
send_folder() {
|
||||||
which pv &> /dev/null && printf -v dusize -- "--size %dk" $( du -s -k "$file_name" | cut -f1 )
|
tar cz "$file_name" | curl --progress-bar -F "file=@-;filename=${base_name}.tgz" "${ROOTURL}upload/${SHARE}/${TOKEN}" | cat -
|
||||||
tar cz "$file_name" | $CAT $dusize - | curl -F "file=@-;filename=${base_name}.tgz" ${ROOTURL}upload/${SHARE}/${TOKEN}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for file_name in "$@"; do
|
for file_name in "$@"; do
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from flask import current_app as app
|
|||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
import stat
|
||||||
try:
|
try:
|
||||||
import magic
|
import magic
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -21,8 +22,10 @@ except ImportError:
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, uid = 0, gid = 0):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.uid = uid
|
||||||
|
self.gid = gid
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +35,26 @@ class Logger:
|
|||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.info("Service started")
|
self.info("Service started")
|
||||||
|
self.set_rights()
|
||||||
|
|
||||||
|
|
||||||
|
def set_rights(self):
|
||||||
|
os.chown(
|
||||||
|
self.filename,
|
||||||
|
self.uid,
|
||||||
|
self.gid
|
||||||
|
)
|
||||||
|
st = os.stat(self.filename)
|
||||||
|
if self.uid > 0:
|
||||||
|
os.chmod(
|
||||||
|
self.filename,
|
||||||
|
st.st_mode | stat.S_IRUSR | stat.S_IWUSR
|
||||||
|
)
|
||||||
|
if self.gid > 0:
|
||||||
|
os.chmod(
|
||||||
|
self.filename,
|
||||||
|
st.st_mode | stat.S_IRGRP | stat.S_IWGRP
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def warning(self, message):
|
def warning(self, message):
|
||||||
@@ -230,7 +253,6 @@ def read_config(app):
|
|||||||
app.config['LOG_FILE'] = config_values['log_file']
|
app.config['LOG_FILE'] = config_values['log_file']
|
||||||
else:
|
else:
|
||||||
app.config['LOG_FILE'] = os.path.join(app.config['UPLOAD_FOLDER'], 'flees.log')
|
app.config['LOG_FILE'] = os.path.join(app.config['UPLOAD_FOLDER'], 'flees.log')
|
||||||
app.config['LOGGER'] = Logger(app.config['LOG_FILE'])
|
|
||||||
app.config['ZIP_FOLDER'] = config_values['zip_folder']
|
app.config['ZIP_FOLDER'] = config_values['zip_folder']
|
||||||
app.config['MAX_ZIP_SIZE'] = config_values['max_zip_size'] # megabytes
|
app.config['MAX_ZIP_SIZE'] = config_values['max_zip_size'] # megabytes
|
||||||
app.config['DATE_FORMAT'] = config_values['date_format']
|
app.config['DATE_FORMAT'] = config_values['date_format']
|
||||||
@@ -239,6 +261,11 @@ def read_config(app):
|
|||||||
app.config['DEBUG'] = config_values['debug']
|
app.config['DEBUG'] = config_values['debug']
|
||||||
app.config['VERSION_FOLDER'] = config_values['version_folder']
|
app.config['VERSION_FOLDER'] = config_values['version_folder']
|
||||||
app.config['SESSION_COOKIE_NAME'] = secure_filename(config_values['site_name'])
|
app.config['SESSION_COOKIE_NAME'] = secure_filename(config_values['site_name'])
|
||||||
|
app.config['LOGGER'] = Logger(
|
||||||
|
app.config['LOG_FILE'],
|
||||||
|
app.config['UID'],
|
||||||
|
app.config['GID']
|
||||||
|
)
|
||||||
return config_values
|
return config_values
|
||||||
|
|
||||||
def safe_name(s):
|
def safe_name(s):
|
||||||
@@ -255,3 +282,12 @@ def safe_string(s, valid, no_repeat = False):
|
|||||||
if no_repeat:
|
if no_repeat:
|
||||||
safe = re.sub(r'_+', '_', safe)
|
safe = re.sub(r'_+', '_', safe)
|
||||||
return safe
|
return safe
|
||||||
|
|
||||||
|
|
||||||
|
def set_rights(path):
|
||||||
|
os.chown(path, app.config['UID'], app.config['GID'])
|
||||||
|
st = os.stat(path)
|
||||||
|
if app.config['UID'] > 0:
|
||||||
|
os.chmod(path, st.st_mode | stat.S_IRUSR | stat.S_IWUSR)
|
||||||
|
if app.config['GID'] > 0:
|
||||||
|
os.chmod(path, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)
|
||||||
|
|||||||
Reference in New Issue
Block a user