check tailscale install status

Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-05-09 17:39:23 +00:00
parent a677216388
commit 1de35c673c
3 changed files with 33 additions and 9 deletions

27
main.py
View File

@ -1,16 +1,31 @@
import json
import os
import pathlib
import subprocess
class Plugin:
async def whoami(self, *args):
return os.getuid()
# A normal method. It can be called from JavaScript using call_plugin_function("method_1", argument1, argument2)
async def method_1(self, *args):
pass
def _systemd_status(self, service = "tailscaled.service"):
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"])
return result.stdout.parse().split(": ")[1]
# A normal method. It can be called from JavaScript using call_plugin_function("method_2", argument1, argument2)
async def method_2(self, *args):
pass
async def install_state(self, *args):
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=shot"])
sysexts = json.load(sysext.stdout)
for hier in sysexts:
if hier.hierarchy != "/usr":
continue
if hier.extensions == "none":
if pathlib.Path("/etc/extensions/tailscale").exists():
return "installed"
if "tailscale" in hier.extensions:
return self._systemd_status()
return "impossible state"
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):

View File

@ -9,16 +9,25 @@
return call_plugin_method("whoami", {});
}
async function getInstallState() {
return call_plugin_method("install_state", {});
}
async function onReady() {
let heading = document.getElementById("heading");
let id = await getUID();
heading.innerText = `Hello ${id}`;
let status = document.getElementById("status");
let install_status = await getInstallState();
status.inner_text = install_status;
}
</script>
</head>
<body onload="onReady()">
<h2 id="heading">Hello World</h2>
<div class="gamepaddialog_GamepadDialogContent_InnerWidth_2ywyS DialogContent_InnerWidth Panel Focusable">
<h3 id="status">Status: loading</h3>
</body>
</html>

View File

@ -3,5 +3,5 @@
"author": "Xe Iaso",
"main_view_html": "main_view.html",
"tile_view_html": "",
"flags": ["hot_reload", "root"]
"flags": ["hot_reload", "root", "debug"]
}