40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import json
|
|
import os
|
|
import pathlib
|
|
import subprocess
|
|
|
|
class Plugin:
|
|
async def log(self, message=""):
|
|
print("frontend: " + message)
|
|
|
|
async def whoami(self, *args):
|
|
return os.getuid()
|
|
|
|
def _systemd_status(self, service = "tailscaled.service"):
|
|
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"], stdout=subprocess.PIPE)
|
|
return result.stdout.decode("utf-8").split(": ")[1].strip()
|
|
|
|
def _install_state(self):
|
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"], stdout=subprocess.PIPE)
|
|
sysexts = json.loads(sysext.stdout.decode("utf-8"))
|
|
|
|
if len(sysexts) == 0:
|
|
return "not installed"
|
|
|
|
for ext in sysexts:
|
|
if ext["name"] != "tailscale":
|
|
continue
|
|
|
|
return self._systemd_status()
|
|
|
|
return "impossible state"
|
|
|
|
async def install_state(self, *args):
|
|
result = await self.install_state()
|
|
print("status: " + result)
|
|
return result
|
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
|
async def _main(self):
|
|
pass
|