check tailscale install status
Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
parent
a677216388
commit
1de35c673c
27
main.py
27
main.py
|
@ -1,16 +1,31 @@
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
import subprocess
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
async def whoami(self, *args):
|
async def whoami(self, *args):
|
||||||
return os.getuid()
|
return os.getuid()
|
||||||
|
|
||||||
# A normal method. It can be called from JavaScript using call_plugin_function("method_1", argument1, argument2)
|
def _systemd_status(self, service = "tailscaled.service"):
|
||||||
async def method_1(self, *args):
|
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"])
|
||||||
pass
|
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 install_state(self, *args):
|
||||||
async def method_2(self, *args):
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=shot"])
|
||||||
pass
|
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
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
||||||
async def _main(self):
|
async def _main(self):
|
||||||
|
|
|
@ -9,16 +9,25 @@
|
||||||
return call_plugin_method("whoami", {});
|
return call_plugin_method("whoami", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getInstallState() {
|
||||||
|
return call_plugin_method("install_state", {});
|
||||||
|
}
|
||||||
|
|
||||||
async function onReady() {
|
async function onReady() {
|
||||||
let heading = document.getElementById("heading");
|
let heading = document.getElementById("heading");
|
||||||
let id = await getUID();
|
let id = await getUID();
|
||||||
|
|
||||||
heading.innerText = `Hello ${id}`;
|
heading.innerText = `Hello ${id}`;
|
||||||
|
|
||||||
|
let status = document.getElementById("status");
|
||||||
|
let install_status = await getInstallState();
|
||||||
|
|
||||||
|
status.inner_text = install_status;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="onReady()">
|
<body onload="onReady()">
|
||||||
<h2 id="heading">Hello World</h2>
|
<h2 id="heading">Hello World</h2>
|
||||||
<div class="gamepaddialog_GamepadDialogContent_InnerWidth_2ywyS DialogContent_InnerWidth Panel Focusable">
|
<h3 id="status">Status: loading</h3>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
"author": "Xe Iaso",
|
"author": "Xe Iaso",
|
||||||
"main_view_html": "main_view.html",
|
"main_view_html": "main_view.html",
|
||||||
"tile_view_html": "",
|
"tile_view_html": "",
|
||||||
"flags": ["hot_reload", "root"]
|
"flags": ["hot_reload", "root", "debug"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue