...
 
Commits (4)
......@@ -25,9 +25,16 @@ windows:
$(VAGRANT) provision --provision-with build windows
while [ ! -f "windows/builddone" ]; do sleep 1; done
$(VAGRANT) halt windows
.PHONY: windows-test #XXX Make this depend on the built .msi!
windows-test:
rm -f windows/tests_passed
$(VAGRANT) up windows
$(VAGRANT) provision --provision-with test windows
[ -f windows/tests_passed ]
$(VAGRANT) halt windows
.PHONY: windows-gui
windows-gui:
$(VAGRANT) rdp windows -- /cert-ignore
$(VAGRANT) rdp windows -- /cert-ignore +clipboard
.PHONY: macos
macos:
......
......@@ -74,9 +74,24 @@ Vagrant.configure("2") do |config|
echo " ****** Build done *******"
echo "" > \\vagrant\\windows\\builddone
SHELL
#Package up into an exe (also with zerotier's .msi?):
#XXX Package up into an exe (also with zerotier's .msi?):
#https://www.firegiant.com/wix/tutorial/net-and-net/bootstrapping/
win.vm.provision "test", type: "shell", run: "never", privileged: false, inline: <<-SHELL
echo " ****** Installing ZeroTier ******"
choco install -y zerotier-one
echo " ****** Install client ******"
Start-Process msiexec.exe -Wait -ArgumentList '/I "C:\\vagrant\\windows\\Boundery Client-0.0.1.msi" /qn'
echo " ****** Run tests *******"
cd "\\Program Files (x86)\\Boundery Client"
$env:BOUNDERY_APP_TEST = '1'
& "\\Program Files (x86)\\Boundery Client\\python\\python.exe" app\\start.py
echo "" > \\vagrant\\windows\\tests_passed
echo " ****** Tests done *******"
SHELL
end
config.vm.define "macos", autostart: false do |mac|
......@@ -145,7 +160,7 @@ Vagrant.configure("2") do |config|
mac.vm.provision "test", type: "shell", run: "never", privileged: false, inline: <<-SHELL
set -e
echo " ****** Install ZeroTier ******"
echo " ****** Installing ZeroTier ******"
if [ -z "`which zerotier-cli`" ]; then
curl -# -L -o /tmp/zt.pkg https://download.zerotier.com/dist/ZeroTier%20One.pkg
sudo installer -pkg /tmp/zt.pkg -target /
......
......@@ -10,7 +10,9 @@ import appdirs
import site
site.addsitedir(next(filter(lambda i: i.endswith('app_packages'), sys.path), ''))
out = open(os.path.join(appdirs.user_data_dir("boundery"), "elevate.log"), 'w')
log_dir = appdirs.user_data_dir("boundery")
os.makedirs(log_dir, exist_ok=True)
out = open(os.path.join(log_dir, "elevate.log"), 'w')
if os.name == "nt":
import pywintypes, win32file, msvcrt
......
......@@ -81,16 +81,22 @@ def get_ssids():
def self_test():
import logging
try:
print("Testing get_mounts")
mounts = get_mounts()
if '/Volumes/BOUNDERYTST' not in mounts:
logging.error("get_mounts failed: '%s'" % mounts)
mp = sudo('cat', '/etc/master.passwd')
if len(mp.stdout.read()) == 0:
logging.error("sudo failed")
return 10
print("Testing ZT info")
zt = sudo('zerotier-cli', 'info')
zt_out = zt.stdout.read()
if not zt_out.startswith('200 info '):
logging.error("sudo failed: '%s'" % zt_out)
return 20
print("Testing get_ssids")
ssids = get_ssids()
print("Testing complete")
except:
logging.error("foo", exc_info=True)
return 99
......@@ -45,8 +45,7 @@ def sudo(cmd, *args):
if fullargs[1].upper().endswith('\\PYTHON.EXE'):
fullargs[1] = fullargs[1][:-len('python.exe')] + 'pythonw.exe'
ctypes.windll.shell32.ShellExecuteW(None, "runas",
python, subprocess.list2cmdline(fullargs), None, 1)
python, subprocess.list2cmdline(fullargs), None, 1)
return NPWrapper(pipe)
def get_zerotier_token_path():
......@@ -56,3 +55,26 @@ def get_ssids():
#XXX Figure out which SSID client is currently connected to.
#XXX Filter out non AP mode aps here.
return [ (False, min(max(2 * (x[1] + 100), 0), 100), x[0]) for x in win32wifi.get_BSSI().values() ]
def self_test():
import logging
try:
print("Testing get_mounts")
mounts = get_mounts()
#if '/Volumes/BOUNDERYTST' not in mounts:
# logging.error("get_mounts failed: '%s'" % mounts)
# return 10
print("Testing ZT info")
zt = sudo('c:\Program Files (x86)\ZeroTier\One\zerotier-cli.bat', 'info')
zt_out = zt.stdout.read()
if not zt_out.startswith('200 info '):
logging.error("sudo failed: '%s'" % zt_out)
return 20
print("Testing get_ssids")
ssids = get_ssids()
print("Testing complete")
except:
logging.error("foo", exc_info=True)
return 99
......@@ -7,7 +7,10 @@ from ctypes.wintypes import *
def customresize(array, new_size):
return (array._type_*new_size).from_address(addressof(array))
wlanapi = windll.LoadLibrary('wlanapi.dll')
try:
wlanapi = windll.LoadLibrary('wlanapi.dll')
except:
wlanapi = None
ERROR_SUCCESS = 0
......@@ -187,43 +190,38 @@ class WLAN_AVAILABLE_NETWORK_LIST_BSS(Structure):
("Network", WLAN_BSS_ENTRY * 1)
]
WlanOpenHandle = wlanapi.WlanOpenHandle
WlanOpenHandle.argtypes = (DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE))
WlanOpenHandle.restype = DWORD
if wlanapi:
WlanOpenHandle = wlanapi.WlanOpenHandle
WlanOpenHandle.argtypes = (DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE))
WlanOpenHandle.restype = DWORD
WlanCloseHandle = wlanapi.WlanCloseHandle
WlanCloseHandle.argtypes = (HANDLE, c_void_p)
WlanCloseHandle.restype = DWORD
WlanCloseHandle = wlanapi.WlanCloseHandle
WlanCloseHandle.argtypes = (HANDLE, c_void_p)
WlanCloseHandle.restype = DWORD
WlanEnumInterfaces = wlanapi.WlanEnumInterfaces
WlanEnumInterfaces.argtypes = (HANDLE, c_void_p,
POINTER(POINTER(WLAN_INTERFACE_INFO_LIST)))
WlanEnumInterfaces.restype = DWORD
WlanEnumInterfaces = wlanapi.WlanEnumInterfaces
WlanEnumInterfaces.argtypes = (HANDLE, c_void_p,
POINTER(POINTER(WLAN_INTERFACE_INFO_LIST)))
WlanEnumInterfaces.restype = DWORD
WlanGetAvailableNetworkList = wlanapi.WlanGetAvailableNetworkList
WlanGetAvailableNetworkList.argtypes = (HANDLE, POINTER(GUID), DWORD, c_void_p,
POINTER(POINTER(WLAN_AVAILABLE_NETWORK_LIST)))
WlanGetAvailableNetworkList.restype = DWORD
WlanGetNetworkBssList = wlanapi.WlanGetNetworkBssList
WlanGetNetworkBssList.argtypes = (HANDLE, POINTER(GUID),POINTER(GUID),POINTER(GUID), c_bool, c_void_p,
POINTER(POINTER(WLAN_BSS_LIST)))
WlanGetNetworkBssList.restype = DWORD
WlanFreeMemory = wlanapi.WlanFreeMemory
WlanFreeMemory.argtypes = [c_void_p]
WlanScan = wlanapi.WlanScan
WlanScan.argtypes = (HANDLE, POINTER(GUID),c_void_p,c_void_p, c_void_p)
WlanScan.restype = DWORD
WlanGetAvailableNetworkList = wlanapi.WlanGetAvailableNetworkList
WlanGetAvailableNetworkList.argtypes = (HANDLE, POINTER(GUID), DWORD, c_void_p,
POINTER(POINTER(WLAN_AVAILABLE_NETWORK_LIST)))
WlanGetAvailableNetworkList.restype = DWORD
WlanGetNetworkBssList = wlanapi.WlanGetNetworkBssList
WlanGetNetworkBssList.argtypes = (HANDLE, POINTER(GUID),POINTER(GUID),POINTER(GUID), c_bool, c_void_p,
POINTER(POINTER(WLAN_BSS_LIST)))
WlanGetNetworkBssList.restype = DWORD
WlanFreeMemory = wlanapi.WlanFreeMemory
WlanFreeMemory.argtypes = [c_void_p]
WlanScan = wlanapi.WlanScan
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))
......@@ -264,8 +262,12 @@ class MAC_BSSID_POWER:
def getMac(self):
return self.mac
def get_BSSI():
if not wlanapi:
class N:
def values(self):
return []
return N()
BSSI_Values={}
......@@ -288,7 +290,6 @@ def get_BSSI():
pAvailableNetworkList2 = pointer(WLAN_BSS_LIST())
ret2 = WlanGetNetworkBssList(ClientHandle,
byref(iface.InterfaceGuid),
None,
......@@ -323,44 +324,3 @@ def get_BSSI():
finally:
WlanFreeMemory(pInterfaceList)
return BSSI_Values
def get_BSSI_times_and_total_seconds(times,seconds):
BSSI_to_return = {}
for i in range(0,seconds*times):
time_to_sleep = float(1.0/times)
time.sleep(time_to_sleep)
got_bssi_temp = get_BSSI()
for bssi in got_bssi_temp:
if not BSSI_to_return.get(bssi):
BSSI_to_return[bssi] = MAC_BSSID_POWER(bssi,got_bssi_temp[bssi][0])
BSSI_to_return[bssi].addPower( got_bssi_temp[bssi][1] )
#BSSI_to_return[bssi] = [got_bssi_temp[bssi][1]]
else:
BSSI_to_return[bssi].addPower( got_bssi_temp[bssi][1] )
#BSSI_to_return[bssi].append(got_bssi_temp[bssi][1])
print("Medicao "+str(i)+" de "+str(seconds*times))
print(BSSI_to_return)
return BSSI_to_return
if __name__ == '__main__':
import time
test = get_BSSI()
for i in range(0,10):
time.sleep(0.5)
oldTest = test
test = get_BSSI()
print("Teste: "+str(i))
if oldTest == test:
print("IGUAL")
else:
print("DIFERENTE")
print(test)
print("End")