def embed_image(self, fileId, description): """ Embed the given image file in the html file. """ fileId = sofi_crypt.hex(fileId) html = ('<h3>%s:</h3><br /><img alt="%s" src="/download/?fileId=%s" />' %(description,description,fileId)) return html
def _eval_sofi_ie(self, ie): """ Evaluate the parsed Information Elements. """ logging.info("Evaluating So-Fi Information Elements.") if (COMMON.PWIFI_EID_IP in ie): subprocess.call( ["sudo", "ifconfig", WIFI_INTERFACE, ie[COMMON.PWIFI_EID_IP]]) logging.info("Setting IP to: %s" % ie[COMMON.PWIFI_EID_IP]) if (COMMON.PWIFI_EID_URL in ie): url = "%s/index?address=%s&request=%s&solution=%s" % ( ie[COMMON.PWIFI_EID_URL], sofi_crypt.hex(sofi_iftools.getHwAddrBin(WIFI_INTERFACE)), sofi_crypt.hex(self.request[0]), sofi_crypt.hex(self.solution)) subprocess.Popen(["xdg-open", url]) logging.info("Opening URL: %s" % url)
def add_link(self, fileId, description): """ Add a link to the given filename to the given html file. """ fileId = sofi_crypt.hex(fileId) html = ('<a href="/download/?fileId=' + fileId + '">' + description + "</a> <br />") return html
def embed_image(self, fileId, description): """ Embed the given image file in the html file. """ fileId = sofi_crypt.hex(fileId) html = ( '<h3>%s:</h3><br /><img alt="%s" src="/download/?fileId=%s" />' % (description, description, fileId)) return html
def listen(self): """ Listen for incoming service requests and provide as necessary. """ self.init_sockets() self.dnsmasq = pwifi_dnsmasq.DnsmasqCTRL() self.dnsmasq.start() self.webserver = sofi_web.sofi_web(self.database,self.stateIndex) while True: logging.info("Waiting for messages...") data, addr = self.receive_msg() s = addr if s is None: s = "hostapd" logging.info("Received message from %s: %s" % (s, data)) split_data = data.split() ssid = split_data[-1] request = split_data[0] source_address = sofi_iftools.sanitizeMac(split_data[1]) #source_address MAC # Requests from legacy clients only contain the request keyword # and SSID. Requests from hostapd provide the IP address which # will be used for the BSS as well. ip = None if len(split_data) == 4: ip = split_data[2] if(sofi_ssid.isSofiSSID(ssid)): ssidObject = sofi_ssid.ssid(SSID=ssid) if request == IPC.PWIFI_IPC_REQUEST: reply = self.handle_request(ssidObject,source_address, ip=ip) if len(reply) != 0: if addr is None: logging.info("Sending reply to hostapd: %s" %reply) logging.info("Hex encoded reply: %s" %(sofi_crypt.hex(reply))) self.sock_hostapd.sendto(reply, IPC.PWIFI_HOSTAPD_INTERFACE) else: logging.info("Sending reply to legacy client " + addr) self.sock_legacy.sendto(reply, addr) else: logging.info("Empty reply. Not sending a reply.") elif request == IPC.PWIFI_IPC_DISBAND: reply = self.handle_disband(ssidObject,source_address) # hostapd does not expect a reply on disband messages -> reply is empty String else: logging.error("Invalid message format. Ignored: %s" %data) continue else: logging.error("Not a valid SSID! Ignored!") continue
def _eval_sofi_ie(self,ie): """ Evaluate the parsed Information Elements. """ logging.info("Evaluating So-Fi Information Elements.") if(COMMON.PWIFI_EID_IP in ie): subprocess.call(["sudo", "ifconfig", WIFI_INTERFACE, ie[COMMON.PWIFI_EID_IP]]) logging.info("Setting IP to: %s" %ie[COMMON.PWIFI_EID_IP]) if(COMMON.PWIFI_EID_URL in ie): url = "%s/index?address=%s&request=%s&solution=%s" %(ie[COMMON.PWIFI_EID_URL],sofi_crypt.hex(sofi_iftools.getHwAddrBin(WIFI_INTERFACE)),sofi_crypt.hex(self.request[0]),sofi_crypt.hex(self.solution)) subprocess.Popen(["xdg-open", url]) logging.info("Opening URL: %s" %url)