...
 
Commits (6)
......@@ -86,10 +86,15 @@ network_id = None
#########################
@get('/test_elevate')
def test_elevate():
return do_priv('get_nodeid')
@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 })
......@@ -249,6 +254,8 @@ def step4_api2():
global network_id
network_id = SecretBox(from_server_key).decrypt(resp).decode()
#XXX Do we need to leave networks with overlapping IP space? Better to warn?
do_priv("leaveall private")
do_priv("join %s" % network_id)
return "ok"
......@@ -318,6 +325,12 @@ def privsub_run():
netid = line.split(' ')[1]
zt_delete(authtoken, "network/%s" % netid)
print("ok") #XXX Error handling
elif line.startswith("leaveall "):
name = line.split(' ')[1]
networks = zt_get(authtoken, "network")
for netid in [ n['id'] for n in networks if n['name']==name ]:
zt_delete(authtoken, "network/%s" % netid)
print("ok")
elif line == "exit":
sys.exit()
except Exception as e:
......
import os, subprocess
def get_mounts():
#XXX Check for /sys/sda/sdd/removable?
ret = []
with open("/proc/mounts", 'r') as f:
for line in f:
......@@ -40,5 +41,4 @@ def get_ssids():
continue
ssids.append(ssid[1:])
ssids = [ (i[0] == 'yes', int(i[1]), i[2]) for i in ssids ]
ssids.sort(key=lambda i: (i[0], i[1]), reverse=True)
return ssids
......@@ -5,7 +5,7 @@ import site
site.addsitedir(next(filter(lambda i: i.endswith('app_packages'), sys.path), ''))
from . import win32wifi
import pywintypes, win32pipe, win32file, msvcrt
import win32pipe, win32file, msvcrt
from win32api import GetLogicalDriveStrings
from win32file import GetDriveType
......@@ -15,22 +15,6 @@ def get_mounts():
drives = [i for i in drives.split("\x00") if i]
return [i[:2] for i in drives if GetDriveType(i) == win32file.DRIVE_REMOVABLE]
def _pipe_handle(pipe):
try:
win32pipe.ConnectNamedPipe(pipe, None)
while True:
result, resp = win32file.ReadFile(pipe, 64*1024)
print("message: %s" % resp)
print("Client connected")
except pywintypes.error as e:
if e.args[0] == 109:
print("broken pipe, bye bye")
else:
print("other? %s" % e)
finally:
win32file.CloseHandle(pipe)
class NPWrapper:
def __init__(self, pipe):
win32pipe.ConnectNamedPipe(pipe, None)
......@@ -70,4 +54,5 @@ def get_zerotier_token_path():
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() ]
......@@ -26,7 +26,7 @@ def pipe_client():
print("Starting: '%s' -- '%s'" % (cmdargs, sys.path), file=out, flush=True)
stdin = open(msvcrt.open_osfhandle(pipe, os.O_RDONLY), 'r')
stdout = open(msvcrt.open_osfhandle(pipe, os.O_WRONLY), 'w')
p = subprocess.Popen(cmdargs, stdin=stdin, stdout=stdout, stderr=subprocess.STDOUT)
subprocess.Popen(cmdargs, stdin=stdin, stdout=stdout, stderr=subprocess.STDOUT)
quit=True
except pywintypes.error as e:
......