forked from Sniffleupagus/pwnagotchi_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_settings.py
241 lines (204 loc) · 8.46 KB
/
display_settings.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import logging
import pwnagotchi.plugins as plugins
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts
class DisplaySettings(plugins.Plugin):
__author__ = 'Sniffleupagus'
__version__ = '1.0.0'
__license__ = 'GPL3'
__description__ = 'Control backlight, and maybe other settings for displays. (but only pimoroni displayhatmini for now)'
def __init__(self):
logging.debug("DisplaySettings plugin created")
# called when http://<host>:<port>/plugins/<plugin>/ is called
# must return a html page
# IMPORTANT: If you use "POST"s, add a csrf-token (via csrf_token() and render_template_string)
def on_webhook(self, path, request):
# show sliders and control and shit :)
pass
# called when the plugin is loaded
def on_loaded(self):
logging.info("DisplaySettings options = %s" % self.options)
# called before the plugin is unloaded
def on_unload(self, ui):
logging.info("goodbye")
pass
# called hen there's internet connectivity
def on_internet_available(self, agent):
pass
# called to setup the ui elements
def on_ui_setup(self, ui):
try:
self._ui = ui
self._display = ui._implementation
if hasattr(self._display, "get_backlight"):
logging.info("UI backlight ready")
if hasattr(self._ui, "set_backgroundcolor"):
logging.info("UI backgrounds ready")
# add custom UI elements
except Exception as err:
logging.warn("Display: %s, err: %s" % (repr(self._display), repr(err)))
# called when the ui is updated
def on_ui_update(self, ui):
# update those elements
pass
# called when the hardware display setup is done, display is an hardware specific object
def on_display_setup(self, display):
self._display = display
#if hasattr(display, "get_backlight"):
pass
# called when everything is ready and the main loop is about to start
def on_ready(self, agent):
logging.info("unit is ready")
# you can run custom bettercap commands if you want
# agent.run('ble.recon on')
# or set a custom state
# agent.set_bored()
# called when the AI finished loading
def on_ai_ready(self, agent):
pass
# called when the AI finds a new set of parameters
def on_ai_policy(self, agent, policy):
pass
# called when the AI starts training for a given number of epochs
def on_ai_training_start(self, agent, epochs):
pass
# called after the AI completed a training epoch
def on_ai_training_step(self, agent, _locals, _globals):
pass
# called when the AI has done training
def on_ai_training_end(self, agent):
pass
# called when the AI got the best reward so far
def on_ai_best_reward(self, agent, reward):
if hasattr(self._display, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#708090")
pass
# called when the AI got the worst reward so far
def on_ai_worst_reward(self, agent, reward):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#203040")
pass
# called when a non overlapping wifi channel is found to be free
def on_free_channel(self, agent, channel):
pass
# called when the status is set to bored
def on_bored(self, agent):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#308080")
pass
# called when the status is set to sad
def on_sad(self, agent):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#302080")
pass
# called when the status is set to excited
def on_excited(self, agent):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.9)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#c08080")
except Exception as err:
logging.warn(repr(err))
pass
# called when the status is set to lonely
def on_lonely(self, agent):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.4)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#101090")
except Exception as err:
logging.warn(repr(err))
pass
# called when the agent is rebooting the board
def on_rebooting(self, agent):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#101010")
pass
# called when the agent is waiting for t seconds
def on_wait(self, agent, t):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.2)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#600000")
except Exception as err:
logging.warn(repr(err))
pass
# called when the agent is sleeping for t seconds
def on_sleep(self, agent, t):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.1)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#000080")
except Exception as err:
logging.warn(repr(err))
pass
# called when the agent refreshed its access points list
def on_wifi_update(self, agent, access_points):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.6)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#208030")
except Exception as err:
logging.warn(repr(err))
pass
# called when the agent refreshed an unfiltered access point list
# this list contains all access points that were detected BEFORE filtering
def on_unfiltered_ap_list(self, agent, access_points):
pass
# called when the agent is sending an association frame
def on_association(self, agent, access_point):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(0.8)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#208020")
except Exception as err:
logging.warn(repr(err))
pass
# called when the agent is deauthenticating a client station from an AP
def on_deauthentication(self, agent, access_point, client_station):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#400000")
pass
# callend when the agent is tuning on a specific channel
def on_channel_hop(self, agent, channel):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#00a000")
pass
# called when a new handshake is captured, access_point and client_station are json objects
# if the agent could match the BSSIDs to the current list, otherwise they are just the strings of the BSSIDs
def on_handshake(self, agent, filename, access_point, client_station):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(1.0)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#00FF00")
except Exception as err:
logging.warn(repr(err))
pass
# called when an epoch is over (where an epoch is a single loop of the main algorithm)
def on_epoch(self, agent, epoch, epoch_data):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#305070")
pass
# called when a new peer is detected
def on_peer_detected(self, agent, peer):
try:
if hasattr(self._display, "set_backlight"):
self._display.set_backlight(1.0)
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#008080")
except Exception as err:
logging.warn(repr(err))
pass
# called when a known peer is lost
def on_peer_lost(self, agent, peer):
if hasattr(self._ui, "set_backgroundcolor"):
self._ui.set_backgroundcolor("#800080")
pass