96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
#!/data/data/com.termux/files/usr/bin/python
|
|
|
|
import eculocate
|
|
import termuxgui as tg
|
|
import threading
|
|
import time
|
|
import sys
|
|
from nacl.signing import SigningKey
|
|
from nacl.encoding import RawEncoder
|
|
|
|
hosts = {}
|
|
|
|
def add_host(activity, name, parent):
|
|
button = tg.Button(activity, "?", parent)
|
|
button.setlinearlayoutparams(0)
|
|
button.setheight(tg.View.WRAP_CONTENT)
|
|
hosts[name] = button
|
|
return button
|
|
|
|
with open("privkey.bin", "rb") as f:
|
|
signing_key = SigningKey(f.read(), encoder=RawEncoder)
|
|
|
|
with tg.Connection() as c:
|
|
a = tg.Activity(c)
|
|
|
|
vertical = tg.LinearLayout(a)
|
|
instances = tg.LinearLayout(a, vertical)
|
|
|
|
tg.Space(a, vertical)
|
|
|
|
status = tg.TextView(a, "initializing", vertical)
|
|
|
|
tg.Space(a, vertical)
|
|
|
|
buttons = tg.LinearLayout(a, vertical, False)
|
|
|
|
start_button = tg.Button(a, "(start)", buttons)
|
|
start_button.setlinearlayoutparams(0)
|
|
start_button.setheight(tg.View.WRAP_CONTENT)
|
|
# start_button.setwidth(tg.View.WRAP_CONTENT)
|
|
start_button.setgravity(1, 1)
|
|
|
|
def repaint(client):
|
|
if client.selected_service_name == None:
|
|
start_button.settext("----")
|
|
else:
|
|
start_button.settext("STOP" if client.started else "START")
|
|
|
|
class GuiClient(eculocate.Client):
|
|
def on_services_changed(self):
|
|
for name, service in self.host_addresses.items():
|
|
widget = hosts.get(name, None)
|
|
if widget == None:
|
|
widget = add_host(a, name, instances)
|
|
if name == self.selected_service_name:
|
|
label = f"* {name}"
|
|
else:
|
|
label = name
|
|
widget.settext(label)
|
|
print("hosts")
|
|
print(hosts)
|
|
repaint(self)
|
|
|
|
def fake_host_add(self):
|
|
self.host_addresses = {
|
|
'Bike3._keihin._udp.local.': ('192.168.8.125', 5002)
|
|
}
|
|
self.on_services_changed()
|
|
|
|
def __init__(self, key):
|
|
super().__init__(key)
|
|
# threading.Thread(target = self.fake_host_add, daemon = True).start()
|
|
|
|
with open("privkey.bin", "rb") as f:
|
|
signing_key = SigningKey(f.read(), encoder=RawEncoder)
|
|
client = GuiClient(signing_key)
|
|
|
|
def update_byte_counter():
|
|
while True:
|
|
label = f"recorded {client.bytes_recorded} bytes" if client.started else "not recording"
|
|
status.settext(label)
|
|
time.sleep(1)
|
|
|
|
threading.Thread(target = update_byte_counter, daemon = True).start()
|
|
|
|
for ev in c.events(): # waits for events from the gui
|
|
if ev.type == tg.Event.destroy:
|
|
sys.exit()
|
|
if ev.type == tg.Event.click:
|
|
for k, v in hosts.items():
|
|
if v == ev.value["id"]:
|
|
client.select_service_name(k)
|
|
if ev.value["id"] == start_button:
|
|
client.stop_recording() if client.started else client.start_recording()
|
|
repaint(client)
|