Repository navigation
Expand file tree
/
Copy pathfancyserver.py
More file actions
98 lines (83 loc) · 3.72 KB
/
Copy pathfancyserver.py
File metadata and controls
98 lines (83 loc) · 3.72 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# modified code from powerutils plugin of https://gitlab.com/sn0wflake
from multiprocessing.connection import Listener
import pwnagotchi
import pwnagotchi.plugins as plugins
import logging
from pwnagotchi.plugins import toggle_plugin
import time
class fancyserver(plugins.Plugin):
__GitHub__ = ""
__author__ = "(edited by: itsdarklikehell bauke.molenaar@gmail.com), @V0rT3x https://github.com/V0r-T3x"
__version__ = "1.0.0"
__license__ = "MIT"
__description__ = "A server to receive extra commands to control your Pwnagotchi"
__name__ = "fancyserver"
__help__ = "A server to receive extra commands to control your Pwnagotchi"
__dependencies__ = {
"apt": ["none"],
"pip": ["scapy"],
}
__defaults__ = {
"enabled": False,
}
def __init__(self):
self.running = True
self.ready = False
logging.debug(f"[{self.__class__.__name__}] plugin init")
self.title = ""
def on_loaded(self):
while self.running:
try:
logging.info(f"[{self.__class__.__name__}] plugin loaded")
address = ("localhost", 3699)
listener = Listener(address)
while self.running:
try:
logging.warn("start loop fancyserver")
conn = listener.accept()
command = (
conn.recv()
) # Blocking - waits here for incoming message.
conn.close()
msg = command[0]
if len(command) > 1:
name = command[1]
state = command[2]
if msg == "shutdown":
pwnagotchi.shutdown()
elif msg == "restart-auto":
pwnagotchi.restart("auto")
elif msg == "restart-manual":
logging.warn("restart in manual mode")
pwnagotchi.restart("manual")
elif msg == "reboot-auto":
pwnagotchi.reboot("auto")
elif msg == "reboot-manual":
pwnagotchi.reboot("manual")
elif msg == "plugin":
logging.warn("plugin command " +
name + " " + state)
if state == "True":
is_change = toggle_plugin(name, enable=True)
# logging.warn('enable: '+is_change)
else:
is_change = toggle_plugin(name, enable=False)
# logging.warn('disable: '+is_change)
if is_change:
logging.warn(name + " changed state")
else:
logging.warn(name + " didn't changed state")
except ConnectionRefusedError as cre:
logging.warn(f"Connection refused error: {cre}")
time.sleep(
5
) # wait for a few seconds before attempting to reconnect
except Exception as e:
logging.warn(f"An unexpected error occurred: {e}")
logging.warn(traceback.format_exc())
time.sleep(
5
) # wait for a few seconds before attempting to restart the script
def on_unload(self, ui):
self.running = False
logging.info(f"[{self.__class__.__name__}] plugin unloaded")