diff --git a/Docker-readme.md b/Docker-readme.md new file mode 100644 index 0000000..c9d58c8 --- /dev/null +++ b/Docker-readme.md @@ -0,0 +1,16 @@ +# How to use Droopy with docker +First build the container +``` +docker build -t droopy . +``` + +Then run with +``` +docker run droopy +``` +With appropriate options added. +As an example, I run +``` +docker run -d -v /path/to/datadir/on/host:/app/data -v /path/to/config/on/host:/app/config -p 8000:8000 --name droopy --restart always droopy +``` + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d46fa7f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3-alpine + +MAINTAINER Filippo Cremonese (fcremo) + +RUN mkdir -p /app/data && mkdir -p /app/config + +COPY droopy /app/droopy +COPY config/config /app/config/config + +EXPOSE 8000 + +CMD [ "python", "/app/droopy", "--config-file", "/app/config/config" ] + + diff --git a/Readme.md b/Readme.md index 4546794..27ea779 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,9 @@ # Droopy ### Easy File Sharing +Fork by Filippo Cremonese (fcremo). +I added the --randomize-filenames option and a Dockerfile. +Below, the original author Readme.md + Copyright 2008-2013 (c) Pierre Duquesne Licensed under the New BSD License. Originally shared at [Pierre's Blog, stackp.online.fr](http://stackp.online.fr/droopy). diff --git a/config/config b/config/config new file mode 100644 index 0000000..e3d8469 --- /dev/null +++ b/config/config @@ -0,0 +1,4 @@ +--randomize-filenames +-d /app/data +-m Message +--chmod 220 diff --git a/droopy b/droopy index 5945cda..f5f9cdf 100755 --- a/droopy +++ b/droopy @@ -6,6 +6,7 @@ Copyright 2008-2013 (c) Pierre Duquesne Licensed under the New BSD License. Changelog + 20151129 * Added --randomize-filenames option 20151025 * Global variables removed * Code refactoring and re-layout * Python 2 and 3 compatibility @@ -87,6 +88,7 @@ import tempfile import socket import base64 import functools +import binascii def _decode_str_if_py2(inputstr, encoding='utf-8'): @@ -327,11 +329,19 @@ class HTTPUploadHandler(httpserver.BaseHTTPRequestHandler): continue localpath = _encode_str_if_py2(os.path.join(self.directory, filename), "utf-8") root, ext = os.path.splitext(localpath) - i = 1 - # TODO: race condition... - while os.path.exists(localpath): - localpath = "%s-%d%s" % (root, i, ext) - i = i + 1 + + if self.randomize_filenames: + rand = binascii.hexlify(os.urandom(4)).decode() + localpath = "%s-%s%s" % (root, rand, ext) + while os.path.exists(localpath): + rand = binascii.hexlify(os.urandom(4)).decode() + localpath = "%s-%s%s" % (root, rand, ext) + else: + i = 1 + # TODO: race condition... + while os.path.exists(localpath): + localpath = "%s-%d%s" % (root, i, ext) + i = i + 1 if hasattr(item, 'tmpfile'): # DroopyFieldStorage.make_file() has been called item.tmpfile.close() @@ -421,6 +431,7 @@ def run(hostname='', message='', file_mode=None, publish_files=False, + randomize_filenames=False, auth='', certfile=None, permitted_ciphers=( @@ -443,6 +454,7 @@ def run(hostname='', HTTPUploadHandler.localisations = localisations HTTPUploadHandler.certfile = certfile HTTPUploadHandler.publish_files = publish_files + HTTPUploadHandler.randomize_filenames = randomize_filenames HTTPUploadHandler.picture = picture HTTPUploadHandler.message = message HTTPUploadHandler.file_mode = file_mode @@ -1020,6 +1032,8 @@ def parse_args(cmd=None, ignore_defaults=False): help='set the picture') parser.add_argument('--publish-files', '--dl', action='store_true', default=False, help='provide download links') + parser.add_argument('--randomize-filenames', '--rand', action='store_true', default=False, + help='randomize filenames of stored files') parser.add_argument('-a', '--auth', type=str, default='', help='set the authentication credentials, in form USER:PASS') parser.add_argument('--ssl', type=str, default='', @@ -1104,6 +1118,7 @@ def main(): directory=args['directory'], file_mode=args['chmod'], publish_files=args['publish_files'], + randomize_filenames=args['randomize_filenames'], auth=args['auth'], templates=default_templates, localisations=default_localisations) diff --git a/man/droopy.1 b/man/droopy.1 index 25a2503..f3ad00f 100644 --- a/man/droopy.1 +++ b/man/droopy.1 @@ -31,6 +31,10 @@ Set the picture. .br Provide download links. .TP 5 +\fB\-\-randomize-filenames\fP +.br +Randomize stored files names. +.TP 5 \fB\-a USER:PASS, \-\-auth USER:PASS\fP .br Set the authentication credentials.