Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created July 25, 2010 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/489633 to your computer and use it in GitHub Desktop.
Save dtinth/489633 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from subprocess import Popen
from random import choice
port = 60506
key = ''
for i in range(6):
key += choice('123456789')
print ':' + str(port) + '/' + key
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
global key
if (self.path == '/' + key + '.zip'):
self.send_response (200)
self.send_header ('Content-Type', 'application/zip')
self.send_header ('Content-Disposition', 'attachment; filename=' + key + '.zip')
self.end_headers ()
Popen(['zip', '-r', '-', '.'], stdout=self.wfile).wait()
print "Sent it!"
elif (self.path == '/' + key):
self.send_response (200)
self.send_header ('Content-Type', 'text/html')
self.end_headers ()
self.wfile.write ('<li><a href="/' + key + '.zip">Download</a>')
else:
self.send_response (403)
self.send_header ('Content-Type', 'text/html')
self.end_headers ()
self.wfile.write ('Forbidden.')
server = HTTPServer(('', port), MyHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment