def _parse_ie(self, ie): """ Parse the Information Elements received from a BSSID. """ if (ie == None): return None, None ie = sofi_crypt.unhex(ie) pos = 0 ie_map = {} while ((pos + 1) < len(ie)): pos += 1 length = ord(ie[pos]) pos += 1 ie_map[ord(ie[pos - 2])] = ie[pos:(pos + length)] pos += length if (COMMON.PWIFI_EID in ie_map): sofi = ie_map[COMMON.PWIFI_EID] pos = 0 sofi_ie_map = {} while ((pos + 1) < len(sofi)): pos += 1 length = ord(sofi[pos]) pos += 1 sofi_ie_map[ord(sofi[pos - 2])] = sofi[pos:(pos + length)] pos += length return ie_map, sofi_ie_map else: return ie_map, None
def _parse_ie(self,ie): """ Parse the Information Elements received from a BSSID. """ if(ie == None): return None,None ie = sofi_crypt.unhex(ie) pos = 0 ie_map = {} while ((pos+1) < len(ie)): pos +=1 length = ord(ie[pos]) pos +=1 ie_map[ord(ie[pos-2])]=ie[pos:(pos+length)] pos +=length if(COMMON.PWIFI_EID in ie_map): sofi = ie_map[COMMON.PWIFI_EID] pos = 0 sofi_ie_map = {} while ((pos+1) < len(sofi)): pos +=1 length = ord(sofi[pos]) pos +=1 sofi_ie_map[ord(sofi[pos-2])]= sofi[pos:(pos+length)] pos +=length return ie_map,sofi_ie_map else: return ie_map,None
def index(self, address="", request="", solution=""): logging.info("Request received. Address: %s Request: %s Solution: %s" % (address, request, solution)) html = """<html><head><title>So-Fi</title></head><body>""" address = sofi_iftools.convertMacString(sofi_crypt.unhex(address)) request = sofi_crypt.unhex(request) solution = sofi_crypt.unhex(solution) if (address != "" and (address in self.stateIndex)): localState = self.stateIndex[address] if ((localState.PuzzleSolved) and ((localState.PuzzleSolution == solution) or NO_PUZZLE)): if (len(localState.DataItems) > 0): hashValue = localState.hashList[0] logging.debug("Now using Hash: %s" % hashValue) if (request == hashValue): html += """<h2>Here are the selected file(s):</h2>""" for item in localState.DataItems: fileId = str(sofi_crypt.randomKey(10)) self.fileIds[fileId] = item if (is_image(item.getLocation())): html += self.embed_image( fileId, item.getName()) else: html += self.add_link(fileId, item.getName()) else: logging.info("Wrong request!") html += """<h2>Wrong Request!</h2>""" else: logging.error( "No files were found for this request! This should never happen!" ) html += """<h2>No files returned for your request!</h2>""" else: logging.info("Puzzle was not solved!") html += """<h2>Puzzle not solved!</h2>""" else: logging.info("Address was not found in state list.") html += """<h2>There is nothing for you here.</h2>""" html += """</body></html>""" return html
def index(self, fileId): logging.info("File Id requested: %s" %fileId) fileId = sofi_crypt.unhex(fileId) if(fileId in self.fileIds): dataItem = self.fileIds[fileId] logging.info("File Id found in File Id Dictonary!") if(dataItem.doSelfCheck()): logging.info("File ok! Serving file!") location = dataItem.getLocation() return serve_file(location, "application/x-download", "attachment") logging.info("File or File Id not found!") return "<html><head><title>NOT FOUND</title></head><body><h1>File not found!</h1></body></html>"
def index(self, fileId): logging.info("File Id requested: %s" % fileId) fileId = sofi_crypt.unhex(fileId) if (fileId in self.fileIds): dataItem = self.fileIds[fileId] logging.info("File Id found in File Id Dictonary!") if (dataItem.doSelfCheck()): logging.info("File ok! Serving file!") location = dataItem.getLocation() return serve_file(location, "application/x-download", "attachment") logging.info("File or File Id not found!") return "<html><head><title>NOT FOUND</title></head><body><h1>File not found!</h1></body></html>"
def index(self, address="", request="", solution=""): logging.info("Request received. Address: %s Request: %s Solution: %s" %(address,request,solution)) html = """<html><head><title>So-Fi</title></head><body>""" address = sofi_iftools.convertMacString(sofi_crypt.unhex(address)) request = sofi_crypt.unhex(request) solution = sofi_crypt.unhex(solution) if(address!="" and (address in self.stateIndex)): localState = self.stateIndex[address] if((localState.PuzzleSolved) and ((localState.PuzzleSolution == solution) or NO_PUZZLE)): if(len(localState.DataItems)>0): hashValue = localState.hashList[0] logging.debug("Now using Hash: %s" %hashValue) if(request == hashValue): html += """<h2>Here are the selected file(s):</h2>""" for item in localState.DataItems: fileId = str(sofi_crypt.randomKey(10)) self.fileIds[fileId] = item if(is_image(item.getLocation())): html +=self.embed_image(fileId, item.getName()) else: html +=self.add_link(fileId,item.getName()) else: logging.info("Wrong request!") html += """<h2>Wrong Request!</h2>""" else: logging.error("No files were found for this request! This should never happen!") html += """<h2>No files returned for your request!</h2>""" else: logging.info("Puzzle was not solved!") html += """<h2>Puzzle not solved!</h2>""" else: logging.info("Address was not found in state list.") html += """<h2>There is nothing for you here.</h2>""" html += """</body></html>""" return html