How to write a minimal example of secure downloads with lighttpd?
There is quite a good wiki on how to use Lighttpd to do secure downloads
with django. The idea is to do this (in your view?) and use the
mod_secdownloads module:
def gen_sec_link(rel_path):
import time, hashlib
secret = 'verysecret'
uri_prefix = '/dl/'
hextime = "%08x" % time.time()
token = hashlib.md5(secret + rel_path + hextime).hexdigest()
return '%s%s/%s%s' % (uri_prefix, token, hextime, rel_path)
The only problem is the implementation. I have an app in which a number of
models have a field that determines whether they are public.
public = models.BooleanField(default = False)
Now if that field is True I want to file to be easily downloadable using a
standard /media/file.txt link. If that field is False I want that file to
be only accesible for secure downloads both frontend and in the admin. I
do not want to rewrite every single view that has a link to a file.
How can I implement this? Should this be in models.py? Can anyone give me
a minimal example?
No comments:
Post a Comment