Commits

Brian Mearns committed c9481f2

Added fingerprint to link, but not using it yet.

Comments (0)

Files changed (1)

             self.serveFile(method)
 
     def serveFile(self, method="GET"):
+        parsed = urlparse.urlparse(self.path)
+
         start = None
         end = None
         if "Range" in self.headers:
         self.send_response(200)
         self.__sendStdHeaders()
         self.send_header("Content-Type", "text/html")
+        #FIXME: Make this HTML5 valid with charset and DOCTYPE.
         content = """
 <html>
     <head>
     </head>
     <body>
         %(message)s
-        <a href='/get' title='Download the file'>download</a>
+        <a href='/get?fpr=%(fpr)s' title='Download the file'>download</a>
 
         <hr />
         <footer>
 </html>
 """ % {
     "filename": self.server.filename(),
+    "fpr": self.server.fingerprint(),
     "message": self.server.customMessage(),
     "vmaj": VER_MAJOR,
     "vmin": VER_MINOR,
         self.__handleRequest("HEAD")
 
     def __handleRequest(self, method):
+        print "--->", self.path
         addr, port = self.client_address
         message = "(%(addr)s:%(port)d) - %(method)s %(path)s" % {
             "addr": addr, "port": port, "method": self.command, "path": self.path
         self.__password = password
         self.__activeNonces = []
         self.__contentLength = None
+        self.__fingerprint = (
+            ("%.3f" % time.time())
+            + ("%d" % address[1])
+            + base64.urlsafe_b64encode(os.urandom(16))
+        )
+
         if filename is None:
             self.__filename = os.path.basename(filepath)
         else:
         self.__https = https
         if https:
             self.__origSocket = self.socket
-            self.socket = ssl.wrap_socket(self.socket, keyfile=keyfile, certfile=certfile, server_side=True)
+            self.socket = ssl.wrap_socket(
+                self.socket, keyfile=keyfile, certfile=certfile, server_side=True
+            )
 
+    def fingerprint(self):
+        return self.__fingerprint
 
     def getContentLength(self, start=None, end=None):
         if self.__contentLength is None:
             self.__contentLength = os.path.getsize(self.__filepath)
         if start is None:
-            if end is None:
+            if end is not None:
                 #Both are none
                 return (None, None, self.__contentLength)