Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --randomize-filenames option #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Docker-readme.md
Original file line number Diff line number Diff line change
@@ -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
```

14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]


4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Licensed under the New BSD License.
Originally shared at [Pierre's Blog, stackp.online.fr](http://stackp.online.fr/droopy).
Expand Down
4 changes: 4 additions & 0 deletions config/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--randomize-filenames
-d /app/data
-m Message
--chmod 220
25 changes: 20 additions & 5 deletions droopy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Copyright 2008-2013 (c) Pierre Duquesne <[email protected]>
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
Expand Down Expand Up @@ -87,6 +88,7 @@ import tempfile
import socket
import base64
import functools
import binascii


def _decode_str_if_py2(inputstr, encoding='utf-8'):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -421,6 +431,7 @@ def run(hostname='',
message='',
file_mode=None,
publish_files=False,
randomize_filenames=False,
auth='',
certfile=None,
permitted_ciphers=(
Expand All @@ -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
Expand Down Expand Up @@ -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='',
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions man/droopy.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down