-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (65 loc) · 2.5 KB
/
Copy pathmain.py
File metadata and controls
74 lines (65 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import subprocess
import os
import decky
def _clean_env():
env = os.environ.copy()
env.pop("LD_LIBRARY_PATH", None)
env.pop("LD_PRELOAD", None)
return env
class Plugin:
async def get_ssh_active(self) -> bool:
try:
result = subprocess.run(
["/usr/bin/systemctl", "is-active", "sshd"],
capture_output=True, text=True, env=_clean_env()
)
return result.returncode == 0
except Exception as e:
decky.logger.error(f"Error getting SSH active state: {e}")
return False
async def set_ssh_active(self, enabled: bool) -> bool:
try:
action = "start" if enabled else "stop"
result = subprocess.run(
["/usr/bin/systemctl", action, "sshd"],
capture_output=True, text=True, env=_clean_env()
)
if result.returncode != 0:
decky.logger.error(f"systemctl {action} sshd failed: {result.stderr.strip()}")
return False
return True
except Exception as e:
decky.logger.error(f"Error setting SSH active state: {e}")
return False
async def get_ssh_enabled(self) -> bool:
try:
result = subprocess.run(
["/usr/bin/systemctl", "is-enabled", "sshd"],
capture_output=True, text=True, env=_clean_env()
)
return result.stdout.strip() in ("enabled", "enabled-runtime")
except Exception as e:
decky.logger.error(f"Error getting SSH enabled state: {e}")
return False
async def set_ssh_enabled(self, enabled: bool) -> bool:
try:
action = "enable" if enabled else "disable"
result = subprocess.run(
["/usr/bin/systemctl", action, "sshd"],
capture_output=True, text=True, env=_clean_env()
)
if result.returncode != 0:
decky.logger.error(f"systemctl {action} sshd failed: {result.stderr.strip()}")
return False
return True
except Exception as e:
decky.logger.error(f"Error setting SSH enabled state: {e}")
return False
async def _main(self):
decky.logger.info("SSH Toggle plugin loaded")
async def _unload(self):
decky.logger.info("SSH Toggle plugin unloaded")
async def _uninstall(self):
decky.logger.info("SSH Toggle plugin uninstalled")
async def _migration(self):
pass