2022-05-09 17:39:23 +00:00
|
|
|
import json
|
2022-05-09 17:17:53 +00:00
|
|
|
import os
|
2022-05-09 17:39:23 +00:00
|
|
|
import pathlib
|
|
|
|
import subprocess
|
2022-05-09 17:17:53 +00:00
|
|
|
|
2022-04-03 18:43:50 +00:00
|
|
|
class Plugin:
|
2022-05-09 18:13:31 +00:00
|
|
|
async def log(self, message=""):
|
|
|
|
print("frontend: " + message)
|
|
|
|
|
2022-05-09 17:17:53 +00:00
|
|
|
async def whoami(self, *args):
|
|
|
|
return os.getuid()
|
2022-04-03 18:43:50 +00:00
|
|
|
|
2022-05-09 17:39:23 +00:00
|
|
|
def _systemd_status(self, service = "tailscaled.service"):
|
2022-05-09 17:46:51 +00:00
|
|
|
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"], stdout=subprocess.PIPE)
|
2022-05-09 17:57:08 +00:00
|
|
|
return result.stdout.decode("utf-8").split(": ")[1].strip()
|
2022-05-09 17:39:23 +00:00
|
|
|
|
2022-05-09 18:08:12 +00:00
|
|
|
def _install_state(self):
|
2022-05-09 17:46:51 +00:00
|
|
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"], stdout=subprocess.PIPE)
|
2022-05-09 17:57:08 +00:00
|
|
|
sysexts = json.loads(sysext.stdout.decode("utf-8"))
|
2022-05-09 17:46:51 +00:00
|
|
|
|
2022-05-09 17:57:08 +00:00
|
|
|
if len(sysexts) == 0:
|
2022-05-09 17:46:51 +00:00
|
|
|
return "not installed"
|
2022-05-09 17:39:23 +00:00
|
|
|
|
2022-05-09 17:46:51 +00:00
|
|
|
for ext in sysexts:
|
2022-05-09 17:57:08 +00:00
|
|
|
if ext["name"] != "tailscale":
|
2022-05-09 17:46:51 +00:00
|
|
|
continue
|
2022-05-09 17:39:23 +00:00
|
|
|
|
2022-05-09 17:46:51 +00:00
|
|
|
return self._systemd_status()
|
|
|
|
|
2022-05-09 17:39:23 +00:00
|
|
|
return "impossible state"
|
2022-04-04 15:30:38 +00:00
|
|
|
|
2022-05-09 18:08:12 +00:00
|
|
|
async def install_state(self, *args):
|
|
|
|
result = await self.install_state()
|
|
|
|
print("status: " + result)
|
|
|
|
return result
|
|
|
|
|
2022-04-04 15:30:38 +00:00
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
2022-04-12 22:31:39 +00:00
|
|
|
async def _main(self):
|
2022-05-09 17:17:53 +00:00
|
|
|
pass
|