On Wed, 08 Jun 2005 17:57:29 +0200, Roy Schestowitz
<newsgroups@schestowitz.com> wrote:
Mitja wrote:
On Wed, 08 Jun 2005 17:18:12 +0200, Roy Schestowitz
<newsgroups@schestowitz.com> wrote:
Martin Magnusson wrote:
diablo wrote:
I want to offer a download to people for a certain amount of time -
after the link expires.
I don't believe that's possible using only HTML. You would have to
remove the file manually or have a server-side script to automate it.
Set up a cron job for the day of expiry, say:
20 22 24 * * cp ~/index2.html ~/index.html; rm ~/index2.html
Which is still a server side script, although admittedly not one that
interacts with the server. And using cron for this kind of job is at
best
not overly elegant, either...
I'd go for a database (can ba plain-textfile based one) with
valid/active "passwords".
That's still quite laborious. How about changing that cron job to a
simple chmod command.
Hmm.... can't help, still think my way is cleaner, easier to automate and
therefore less prone to errors - not to mention /less/ laborious in the
long run. No manual messing with cron.tab. Just to show you such a script
is not too complicated, here's an example in python (not tested, very
probably has some errors):
import string
import random
import time
import sys
def makeLink():
"returns the hash from which to create the link of form
getBook.py?hash=..."
hash = ''.join([random.choice(string.ascii_uppercase) for i in
range(32)]);
f = open('hash.db','a')
f.write(hash+' '+`time.time()`)
f.close()
return hash
def get(hash):
"when the script is called with an actual hash, call this func to check
if it's a valid one"
db = dict([line.split() for line in open('hash.db')])
try:
assert time.time()-db[hash] < 3600*24*7
sys.out.write('content-type:
application/x-pdf\n\n'+open('theBook.pdf').read())
except KeyError, AssertionError:
sys.out.write('content-type: text/plain\n\nInvalid or expired hash.')
Now for a real, running script of course you'd want to fancy it up a bit,
but the above few lines generally cover all of idea.
|
|