check tailscale install status
Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
parent
a677216388
commit
1de35c673c
29
main.py
29
main.py
|
@ -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
|
||||
|
||||
# A normal method. It can be called from JavaScript using call_plugin_function("method_2", argument1, argument2)
|
||||
async def method_2(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]
|
||||
|
||||
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):
|
||||
|
|
|
@ -8,17 +8,26 @@
|
|||
async function getUID() {
|
||||
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>
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue