def home(): """ Main page :return: """ if my_wlan0_ip() not in request.url_root and my_eth0_ip() not in request.url_root: return redirect("http://" + my_wlan0_ip()) ip_address = request.remote_addr arp_address = read_arp_table()[ip_address] q = sessiondb.get_key(ip_address, arp_address) if not q: k = addrgen.gen_eckey() log.debug(k) if shortcuts["no_ssl"]: adds = ["abcdefg","1234567"] else: adds = addrgen.get_addr(k) sessiondb.create_key(pub_key=adds[0], priv_key=adds[1], ip_address=ip_address, mac_address=arp_address) bitcoin_address = adds[0] else: logging.debug("Found an entry", q) bitcoin_address = q.pub_key payment_options = sessiondb.get_prices() return render_template('index.html', ip=ip_address, arp=arp_address, bitcoinaddress=bitcoin_address, paymentoptions=payment_options)
def home(): """ Main page :return: """ if my_wlan0_ip() not in request.url_root and my_eth0_ip( ) not in request.url_root: return redirect("http://" + my_wlan0_ip()) ip_address = request.remote_addr arp_address = read_arp_table()[ip_address] q = sessiondb.get_key(ip_address, arp_address) if not q: k = addrgen.gen_eckey() log.debug(k) if shortcuts["no_ssl"]: adds = ["abcdefg", "1234567"] else: adds = addrgen.get_addr(k) sessiondb.create_key(pub_key=adds[0], priv_key=adds[1], ip_address=ip_address, mac_address=arp_address) bitcoin_address = adds[0] else: logging.debug("Found an entry", q) bitcoin_address = q.pub_key payment_options = sessiondb.get_prices() return render_template('index.html', ip=ip_address, arp=arp_address, bitcoinaddress=bitcoin_address, paymentoptions=payment_options)
def qr_code(choice): """ Returns a GIF of the QR code for given payment choice :param choice: :return: """ amount = None payment_options = sessiondb.get_prices() for p in payment_options: if p.id == choice: amount = p.rate # TODO handle not getting a rate back better if not amount: log.error("Didn't find a payment for choice: %s" % choice) amount = 0.0000001 ip_address = request.remote_addr arp_address = read_arp_table()[ip_address] q = sessiondb.get_key(ip_address, arp_address) bitcoin_address = q.pub_key output = StringIO.StringIO() qr = qrcode.make(bitcoin_format % ({ "address": bitcoin_address, "amount": amount })) qr._img.save(output, "GIF") return Response(output.getvalue(), mimetype='image/gif')
def check_access(): ip = request.remote_addr mac = read_arp_table()[ip] q = sessiondb.get_key(ip, mac) if get_balance(q.pub_key): tx = get_last_transaction(q.pub_key) length = get_payment_length(tx.amount) enable_access(length, tx.id) flush_funds(q.pub_key) return render_template("access_enabled.html") else: return render_template("no_access_yet.html")
def status(): """ Return the status info to Angular :return: """ resp = {} resp['arp'] = [] for k,v in read_arp_table().iteritems(): resp['arp'].append({ "ip": k, "mac": v }) resp['prices'] = [] for p in sessiondb.get_prices(): resp['prices'].append({"id": p.id, "name": p.shortname, "length": p.length, "price": p.rate, "desc": p.longname}) return Response(json.dumps(resp), mimetype='text/json')
def status(): """ Return the status info to Angular :return: """ resp = {} resp['arp'] = [] for k, v in read_arp_table().iteritems(): resp['arp'].append({"ip": k, "mac": v}) resp['prices'] = [] for p in sessiondb.get_prices(): resp['prices'].append({ "id": p.id, "name": p.shortname, "length": p.length, "price": p.rate, "desc": p.longname }) return Response(json.dumps(resp), mimetype='text/json')
def qr_code(choice): """ Returns a GIF of the QR code for given payment choice :param choice: :return: """ amount = None payment_options = sessiondb.get_prices() for p in payment_options: if p.id == choice: amount = p.rate # TODO handle not getting a rate back better if not amount: log.error("Didn't find a payment for choice: %s" % choice) amount = 0.0000001 ip_address = request.remote_addr arp_address = read_arp_table()[ip_address] q = sessiondb.get_key(ip_address, arp_address) bitcoin_address = q.pub_key output = StringIO.StringIO() qr = qrcode.make(bitcoin_format % ({"address":bitcoin_address,"amount":amount })) qr._img.save(output, "GIF") return Response(output.getvalue(), mimetype='image/gif')
def enable_access(length, tx): ip = request.remote_addr mac = read_arp_table()[ip] sessions.append(TimedSession(mac, length)) sessiondb.add_session(mac, length, tx)