...
 
Commits (7)
......@@ -56,7 +56,7 @@ macos-gui:
.PHONY: dev
dev:
@python3 boundery/app.py --debug --local
@python3 -m boundery --debug --local
.PHONY: check
check:
......
......@@ -97,6 +97,9 @@ Vagrant.configure("2") do |config|
config.vm.define "macos", autostart: false do |mac|
mac.vm.box = "jhcook/macos-sierra"
mac.vm.network "forwarded_port", host: 5900, guest: 5900
#XXX Needed for ZT to actually work in VirtualBox:
#mac.vm.network "public_network"
#sudo networksetup -ordernetworkservices "Ethernet Adaptor (en1)" "Ethernet"
mac.vm.provider "virtualbox" do |vb|
#vb.gui = true
......
......@@ -93,16 +93,32 @@ def test_elevate():
@get('/')
@get('/step1')
def step1():
ssids = osal.get_ssids()
ssids.sort(key=lambda i: (i[0], i[1]), reverse=True)
ssids = [ ("%s (signal %s)" % (ssid[2], ssid[1]), ssid[2], ssid[0]) for ssid in ssids ]
return template("step1", { "mountlist": step1_api1(), "ssids": ssids })
return template("step1", { "mountlist": step1_api1(), "ssidlist": step1_api2() })
@get('/step1_api1')
def step1_api1():
#XXX Emit a useful message if there are no mounts!
return template("step1_api1", { "mounts": osal.get_mounts() })
ssid_dict = {}
@get('/step1_api2')
def step1_api2():
global ssid_dict
for ssid in osal.get_ssids(): #(is_connected, signal, name)
if len(ssid[2].strip()) == 0:
continue
old_ssid = ssid_dict.get(ssid[2], None)
if old_ssid:
if (ssid[0] != old_ssid[0]) or (ssid[1] > old_ssid[1]):
ssid_dict[ssid[2]] = ssid
else:
ssid_dict[ssid[2]] = ssid
ssids = list(ssid_dict.values())
ssids.sort(key=lambda i: (i[0], i[1]), reverse=True)
ssids = [ ("%s (signal %s)" % (ssid[2], ssid[1]), ssid[2], ssid[0]) for ssid in ssids ]
return template("step1_api2", { "ssids": ssids })
step1_thread = None
@post('/step1')
def step1_post():
......@@ -110,8 +126,9 @@ def step1_post():
if mount not in osal.get_mounts():
raise Exception("Bad mountpoint from client!")
#XXX This is busted if your ssid is actually '__other'
ssid = request.forms.get("ssid").strip()
if ssid == "other":
if ssid == "__other":
ssid = request.forms.get("other_ssid").strip()
else:
ssid = ssid[1:]
......@@ -129,7 +146,6 @@ def step1_post():
def step1_handler(ssid, wifi_pw, mount):
if "ZIPFILE" not in os.environ:
#XXX More granular progress than just per-file. Monkeypatch shutil.copyfileobj?
r = requests.get(CENTRAL_URL + "/static/images/rpi3.zip", stream=True)
bio = io.BytesIO()
zip_length = r.headers.get('content-length')
......@@ -152,6 +168,7 @@ def step1_handler(ssid, wifi_pw, mount):
zis = zf.infolist()
num_bytes = reduce(add, [ zi.file_size for zi in zis ])
bytes_written = 0
#XXX More frequent progress than just per-file. Monkeypatch shutil.copyfileobj?
for zi in zis:
zf.extract(zi, path=mount)
bytes_written += zi.file_size
......@@ -181,8 +198,8 @@ def step1_handler(ssid, wifi_pw, mount):
step1_thread.cur += 1
@get('/step1_api2')
def step1_api2():
@get('/step1_post_api1')
def step1_post_api2():
global step1_thread
if step1_thread.cur == step1_thread.max:
step1_thread.join()
......
......@@ -95,7 +95,7 @@ def self_test():
return 20
print("Testing get_ssids")
ssids = get_ssids()
get_ssids()
print("Testing complete")
except:
logging.error("foo", exc_info=True)
......
......@@ -60,7 +60,7 @@ def self_test():
import logging
try:
print("Testing get_mounts")
mounts = get_mounts()
get_mounts()
#if '/Volumes/BOUNDERYTST' not in mounts:
# logging.error("get_mounts failed: '%s'" % mounts)
# return 10
......@@ -73,7 +73,7 @@ def self_test():
return 20
print("Testing get_ssids")
ssids = get_ssids()
get_ssids()
print("Testing complete")
except:
logging.error("foo", exc_info=True)
......
__author__ = 'Pedro Gomes'
#Based on code by Pedro Gomes
import time
from ctypes import *
from ctypes.wintypes import *
......@@ -221,47 +220,6 @@ if wlanapi:
WlanScan.argtypes = (HANDLE, POINTER(GUID),c_void_p,c_void_p, c_void_p)
WlanScan.restype = DWORD
def get_interface():
NegotiatedVersion = DWORD()
ClientHandle = HANDLE()
ret = WlanOpenHandle(1, None, byref(NegotiatedVersion), byref(ClientHandle))
if ret != ERROR_SUCCESS:
raise(Exception(FormatError(ret)))
# find all wireless network interfaces
pInterfaceList = pointer(WLAN_INTERFACE_INFO_LIST())
ret = WlanEnumInterfaces(ClientHandle, None, byref(pInterfaceList))
if ret != ERROR_SUCCESS:
raise(Exception(FormatError(ret)))
try:
ifaces = customresize(pInterfaceList.contents.InterfaceInfo,
pInterfaceList.contents.NumberOfItems)
# find each available network for each interface
for iface in ifaces:
#print "Interface: %s" % (iface.strInterfaceDescription)
interface = iface.strInterfaceDescription
finally:
WlanFreeMemory(pInterfaceList)
return interface
class MAC_BSSID_POWER:
"""Classe para os valores retirados"""
def __init__(self, mac, bssid):
self.mac = str(mac)
self.bssid = str(bssid)
self.valores = []
def addPower(self,power):
self.valores.append(int(power))
def getBssid(self):
return self.bssid
def getPowers(self):
return self.valores
def getMac(self):
return self.mac
def get_BSSI():
if not wlanapi:
class N:
......
......@@ -67,26 +67,20 @@
<h1>Choose Wifi settings, then choose the device to use to create the boot card.</h1>
<p>If you are installing to a raspberry pi (or any other computer that doesn't support 5Ghz wifi), make sure to pick a 2.4Ghz Wifi network.</p>
<p>If you are installing to a raspberry pi 3B (not 3B+), or any other computer that doesn't support 5GHz wifi, make sure to pick a 2.4GHz Wifi network.</p>
<form action="/step1" method="post">
<div>
<label for="ssid">Wifi Network Name (SSID):</label>
<br>
% for ssid in ssids:
% if ssid[2]:
<input type="radio" name="ssid" value="={{ssid[1]}}" checked="checked">{{ssid[0]}}<br>
% else:
<input type="radio" name="ssid" value="={{ssid[1]}}">{{ssid[0]}}<br>
% end
% end
<div id="ssidlist">{{!ssidlist}}</div>
<div>
<input type="radio" name="ssid" value="other">Other <input class="hideshow" type="text" name="other_ssid" value=""><br>
<input type="radio" name="ssid" value="__other">Other <input class="hideshow" type="text" name="other_ssid" value=""><br>
</div>
<input type="radio" name="ssid" value="" required>None. I'm using wired ethernet.
</div>
<div>
<label for="wifi_pw">Wifi Password (Blank for none):</label>
<label for="wifi_pw">Wifi Password (Leave blank for none):</label>
<input type="text" name="wifi_pw" value="">
</div>
<br>
......@@ -112,5 +106,25 @@
xhr.open("GET", "/step1_api1", true);
xhr.send();
}
window.onload = poll1();
function poll2() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
var results = document.getElementById("ssidlist");
if (results.innerHTML != this.responseText) {
results.innerHTML = this.responseText;
}
}
setTimeout(poll2, 5000);
}
};
xhr.open("GET", "/step1_api2", true);
xhr.send();
}
function poll_all() {
poll1()
poll2()
}
window.onload = poll_all();
</script>
% for ssid in ssids:
% if ssid[2]:
<input type="radio" name="ssid" value="={{ssid[1]}}" checked="checked">{{ssid[0]}}<br>
% else:
<input type="radio" name="ssid" value="={{ssid[1]}}">{{ssid[0]}}<br>
% end
% end
......@@ -40,7 +40,7 @@
setTimeout(poll1, 1000);
}
};
xhr.open("GET", "/step1_api2", true);
xhr.open("GET", "/step1_post_api1", true);
xhr.send();
}
window.onload = poll1();
......