Moved all reset logging to debug, except for plugin loaded.

Removed the counter from display
This commit is contained in:
jayofelony
2024-02-29 23:01:05 +01:00
parent e800c66e57
commit d5384d5a81

View File

@ -35,14 +35,11 @@ class FixServices(plugins.Plugin):
self.isReloadingMon = False self.isReloadingMon = False
self.connection = None self.connection = None
self.LASTTRY = 0 self.LASTTRY = 0
self._status = "--"
self._count = 0
def on_loaded(self): def on_loaded(self):
""" """
Gets called when the plugin gets loaded Gets called when the plugin gets loaded
""" """
self._status = "ld"
logging.info("[Fix_Services] plugin loaded.") logging.info("[Fix_Services] plugin loaded.")
def on_ready(self, agent): def on_ready(self, agent):
@ -50,31 +47,27 @@ class FixServices(plugins.Plugin):
stdout=subprocess.PIPE).stdout))[-10:]) stdout=subprocess.PIPE).stdout))[-10:])
try: try:
cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True) cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True)
logging.info("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output)) logging.debug("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output))
if ",UP," in str(cmd_output): if ",UP," in str(cmd_output):
logging.info("wlan0mon is up.") logging.debug("wlan0mon is up.")
self._status = "up"
if len(self.pattern.findall(last_lines)) >= 3: if len(self.pattern.findall(last_lines)) >= 3:
self._status = "XX"
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting.') display.set('status', 'Blind-Bug detected. Restarting.')
display.update(force=True) display.update(force=True)
logging.info('[Fix_Services] Blind-Bug detected. Restarting.') logging.debug('[Fix_Services] Blind-Bug detected. Restarting.')
try: try:
self._tryTurningItOffAndOnAgain(agent) self._tryTurningItOffAndOnAgain(agent)
except Exception as err: except Exception as err:
logging.warning("[Fix_Services turnOffAndOn] %s" % repr(err)) logging.warning("[Fix_Services turnOffAndOn] %s" % repr(err))
else: else:
logging.info("[Fix_Services] Logs look good!") logging.debug("[Fix_Services] Logs look good!")
self._status = ""
except Exception as err: except Exception as err:
logging.error("[Fix_Services ip link show wlan0mon]: %s" % repr(err)) logging.error("[Fix_Services ip link show wlan0mon]: %s" % repr(err))
try: try:
self._status = "xx"
self._tryTurningItOffAndOnAgain(agent) self._tryTurningItOffAndOnAgain(agent)
except Exception as err: except Exception as err:
logging.error("[Fix_Services OffNOn]: %s" % repr(err)) logging.error("[Fix_Services OffNOn]: %s" % repr(err))
@ -84,12 +77,12 @@ class FixServices(plugins.Plugin):
# apparently this only gets messages from bettercap going to syslog, not from syslog # apparently this only gets messages from bettercap going to syslog, not from syslog
def on_bcap_sys_log(self, agent, event): def on_bcap_sys_log(self, agent, event):
if re.search('wifi error while hopping to channel', event['data']['Message']): if re.search('wifi error while hopping to channel', event['data']['Message']):
logging.info("[Fix_Services]SYSLOG MATCH: %s" % event['data']['Message']) logging.debug("[Fix_Services]SYSLOG MATCH: %s" % event['data']['Message'])
logging.info("[Fix_Services]**** restarting wifi.recon") logging.debug("[Fix_Services]**** restarting wifi.recon")
try: try:
result = agent.run("wifi.recon off; wifi.recon on") result = agent.run("wifi.recon off; wifi.recon on")
if result["success"]: if result["success"]:
logging.info("[Fix_Services] wifi.recon flip: success!") logging.debug("[Fix_Services] wifi.recon flip: success!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
if display: if display:
@ -121,12 +114,12 @@ class FixServices(plugins.Plugin):
# Look for pattern 1 # Look for pattern 1
if len(self.pattern.findall(last_lines)) >= 3: if len(self.pattern.findall(last_lines)) >= 3:
logging.info("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines) logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines)
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting.') display.set('status', 'Blind-Bug detected. Restarting.')
display.update(force=True) display.update(force=True)
logging.info('[Fix_Services] Blind-Bug detected. Restarting.') logging.debug('[Fix_Services] Blind-Bug detected. Restarting.')
try: try:
self._tryTurningItOffAndOnAgain(agent) self._tryTurningItOffAndOnAgain(agent)
except Exception as err: except Exception as err:
@ -134,20 +127,19 @@ class FixServices(plugins.Plugin):
# Look for pattern 2 # Look for pattern 2
elif len(self.pattern2.findall(other_last_lines)) >= 5: elif len(self.pattern2.findall(other_last_lines)) >= 5:
logging.info("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines) logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines)
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
display.set('status', 'Wifi channel stuck. Restarting recon.') display.set('status', 'Wifi channel stuck. Restarting recon.')
display.update(force=True) display.update(force=True)
logging.info('[Fix_Services] Wifi channel stuck. Restarting recon.') logging.debug('[Fix_Services] Wifi channel stuck. Restarting recon.')
try: try:
result = agent.run("wifi.recon off; wifi.recon on") result = agent.run("wifi.recon off; wifi.recon on")
if result["success"]: if result["success"]:
logging.info("[Fix_Services] wifi.recon flip: success!") logging.debug("[Fix_Services] wifi.recon flip: success!")
if display: if display:
display.update(force=True, new_data={"status": "Wifi recon flipped!", display.update(force=True, new_data={"status": "Wifi recon flipped!",
"brcmfmac_status": self._status,
"face": faces.COOL}) "face": faces.COOL})
else: else:
print("Wifi recon flipped\nthat was easy!") print("Wifi recon flipped\nthat was easy!")
@ -159,7 +151,7 @@ class FixServices(plugins.Plugin):
# Look for pattern 3 # Look for pattern 3
elif len(self.pattern3.findall(other_last_lines)) >= 1: elif len(self.pattern3.findall(other_last_lines)) >= 1:
logging.info("[Fix_Services] Firmware has halted or crashed. Restarting wlan0mon.") logging.debug("[Fix_Services] Firmware has halted or crashed. Restarting wlan0mon.")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
display.set('status', 'Firmware has halted or crashed. Restarting wlan0mon.') display.set('status', 'Firmware has halted or crashed. Restarting wlan0mon.')
@ -167,13 +159,13 @@ class FixServices(plugins.Plugin):
try: try:
# Run the monstart command to restart wlan0mon # Run the monstart command to restart wlan0mon
cmd_output = subprocess.check_output("monstart", shell=True) cmd_output = subprocess.check_output("monstart", shell=True)
logging.info("[Fix_Services monstart]: %s" % repr(cmd_output)) logging.debug("[Fix_Services monstart]: %s" % repr(cmd_output))
except Exception as err: except Exception as err:
logging.error("[Fix_Services monstart]: %s" % repr(err)) logging.error("[Fix_Services monstart]: %s" % repr(err))
# Look for pattern 4 # Look for pattern 4
elif len(self.pattern4.findall(other_other_last_lines)) >= 3: elif len(self.pattern4.findall(other_other_last_lines)) >= 3:
logging.info("[Fix_Services] wlan0 is down!") logging.debug("[Fix_Services] wlan0 is down!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
display.set('status', 'Restarting wlan0 now!') display.set('status', 'Restarting wlan0 now!')
@ -181,7 +173,7 @@ class FixServices(plugins.Plugin):
try: try:
# Run the monstart command to restart wlan0mon # Run the monstart command to restart wlan0mon
cmd_output = subprocess.check_output("monstart", shell=True) cmd_output = subprocess.check_output("monstart", shell=True)
logging.info("[Fix_Services monstart]: %s" % repr(cmd_output)) logging.debug("[Fix_Services monstart]: %s" % repr(cmd_output))
except Exception as err: except Exception as err:
logging.error("[Fix_Services monstart]: %s" % repr(err)) logging.error("[Fix_Services monstart]: %s" % repr(err))
@ -197,7 +189,7 @@ class FixServices(plugins.Plugin):
elif level == "debug": elif level == "debug":
logging.debug(message) logging.debug(message)
else: else:
logging.info(message) logging.debug(message)
if ui: if ui:
ui.update(force=force, new_data=displayData) ui.update(force=force, new_data=displayData)
@ -212,17 +204,16 @@ class FixServices(plugins.Plugin):
# avoid overlapping restarts, but allow it if it's been a while # avoid overlapping restarts, but allow it if it's been a while
# (in case the last attempt failed before resetting "isReloadingMon") # (in case the last attempt failed before resetting "isReloadingMon")
if self.isReloadingMon and (time.time() - self.LASTTRY) < 180: if self.isReloadingMon and (time.time() - self.LASTTRY) < 180:
logging.info("[Fix_Services] Duplicate attempt ignored") logging.debug("[Fix_Services] Duplicate attempt ignored")
else: else:
self.isReloadingMon = True self.isReloadingMon = True
self.LASTTRY = time.time() self.LASTTRY = time.time()
self._status = "BL"
if hasattr(connection, 'view'): if hasattr(connection, 'view'):
display = connection.view() display = connection.view()
if display: if display:
display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again", display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again",
"brcmfmac_status": self._status, "face": faces.BORED}) "face": faces.BORED})
else: else:
display = None display = None
@ -238,9 +229,9 @@ class FixServices(plugins.Plugin):
# is it up? # is it up?
try: try:
cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True) cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True)
logging.info("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output)) logging.debug("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output))
if ",UP," in str(cmd_output): if ",UP," in str(cmd_output):
logging.info("wlan0mon is up. Skip reset?") logging.debug("wlan0mon is up. Skip reset?")
# not reliable, so don't skip just yet # not reliable, so don't skip just yet
# print("wlan0mon is up. Skipping reset.") # print("wlan0mon is up. Skipping reset.")
# self.isReloadingMon = False # self.isReloadingMon = False
@ -261,11 +252,10 @@ class FixServices(plugins.Plugin):
except Exception as err: except Exception as err:
logging.error("[Fix_Services wifi.recon off] error %s" % (repr(err))) logging.error("[Fix_Services wifi.recon off] error %s" % (repr(err)))
logging.info("[Fix_Services] recon paused. Now trying wlan0mon reload") logging.debug("[Fix_Services] recon paused. Now trying wlan0mon reload")
try: try:
cmd_output = subprocess.check_output("monstop", shell=True) cmd_output = subprocess.check_output("monstop", shell=True)
self._status = "dn"
self.logPrintView("info", "[Fix_Services] wlan0mon down and deleted: %s" % cmd_output, self.logPrintView("info", "[Fix_Services] wlan0mon down and deleted: %s" % cmd_output,
display, {"status": "wlan0mon d-d-d-down!", "face": faces.BORED}) display, {"status": "wlan0mon d-d-d-down!", "face": faces.BORED})
except Exception as nope: except Exception as nope:
@ -285,7 +275,6 @@ class FixServices(plugins.Plugin):
cmd_output = subprocess.check_output("sudo modprobe -r brcmfmac", shell=True) cmd_output = subprocess.check_output("sudo modprobe -r brcmfmac", shell=True)
self.logPrintView("info", "[Fix_Services] unloaded brcmfmac", display, self.logPrintView("info", "[Fix_Services] unloaded brcmfmac", display,
{"status": "Turning it off #%s" % tries, "face": faces.SMART}) {"status": "Turning it off #%s" % tries, "face": faces.SMART})
self._status = "ul"
# reload the module # reload the module
try: try:
@ -293,28 +282,24 @@ class FixServices(plugins.Plugin):
cmd_output = subprocess.check_output("sudo modprobe brcmfmac", shell=True) cmd_output = subprocess.check_output("sudo modprobe brcmfmac", shell=True)
self.logPrintView("info", "[Fix_Services] reloaded brcmfmac") self.logPrintView("info", "[Fix_Services] reloaded brcmfmac")
self._status = "rl"
# success! now make the mon0 # success! now make the mon0
try: try:
cmd_output = subprocess.check_output("monstart", shell=True) cmd_output = subprocess.check_output("monstart", shell=True)
self.logPrintView("info", "[Fix_Services interface add wlan0mon worked #%s: %s" self.logPrintView("info", "[Fix_Services interface add wlan0mon worked #%s: %s"
% (tries, cmd_output)) % (tries, cmd_output))
self._status = "up"
try: try:
# try accessing mon0 in bettercap # try accessing mon0 in bettercap
result = connection.run("set wifi.interface wlan0mon") result = connection.run("set wifi.interface wlan0mon")
if "success" in result: if "success" in result:
logging.info("[Fix_Services set wifi.interface wlan0mon worked!") logging.debug("[Fix_Services set wifi.interface wlan0mon worked!")
self._status = ""
self._count = self._count + 1
# stop looping and get back to recon # stop looping and get back to recon
break break
else: else:
logging.info( logging.debug(
"[Fix_Services set wifi.interfaceface wlan0mon] failed? %s" % repr(result)) "[Fix_Services set wifi.interfaceface wlan0mon] failed? %s" % repr(result))
except Exception as err: except Exception as err:
logging.info( logging.debug(
"[Fix_Services set wifi.interface wlan0mon] except: %s" % repr(err)) "[Fix_Services set wifi.interface wlan0mon] except: %s" % repr(err))
except Exception as cerr: # except Exception as cerr: #
if not display: if not display:
@ -333,41 +318,38 @@ class FixServices(plugins.Plugin):
tries = tries + 1 tries = tries + 1
if tries < 3: if tries < 3:
logging.info("[Fix_Services] wlan0mon didn't make it. trying again") logging.debug("[Fix_Services] wlan0mon didn't make it. trying again")
if not display: if not display:
print(" wlan0mon didn't make it. trying again") print(" wlan0mon didn't make it. trying again")
else: else:
logging.info("[Fix_Services] wlan0mon loading failed, no choice but to reboot ..") logging.debug("[Fix_Services] wlan0mon loading failed, no choice but to reboot ..")
pwnagotchi.reboot() pwnagotchi.reboot()
# exited the loop, so hopefully it loaded # exited the loop, so hopefully it loaded
if tries < 3: if tries < 3:
if display: if display:
display.update(force=True, new_data={"status": "And back on again...", display.update(force=True, new_data={"status": "And back on again...",
"brcmfmac_status": self._status,
"face": faces.INTENSE}) "face": faces.INTENSE})
else: else:
print("And back on again...") print("And back on again...")
logging.info("[Fix_Services] wlan0mon back up") logging.debug("[Fix_Services] wlan0mon back up")
else: else:
self.LASTTRY = time.time() self.LASTTRY = time.time()
time.sleep(8 + tries * 2) # give it a bit before restarting recon in bettercap time.sleep(8 + tries * 2) # give it a bit before restarting recon in bettercap
self.isReloadingMon = False self.isReloadingMon = False
logging.info("[Fix_Services] re-enable recon") logging.debug("[Fix_Services] re-enable recon")
try: try:
result = connection.run("wifi.clear; wifi.recon on") result = connection.run("wifi.clear; wifi.recon on")
if "success" in result: # and result["success"] is True: if "success" in result: # and result["success"] is True:
self._status = ""
if display: if display:
display.update(force=True, new_data={"status": "I can see again! (probably)", display.update(force=True, new_data={"status": "I can see again! (probably)",
"brcmfmac_status": self._status,
"face": faces.HAPPY}) "face": faces.HAPPY})
else: else:
print("I can see again") print("I can see again")
logging.info("[Fix_Services] wifi.recon on") logging.debug("[Fix_Services] wifi.recon on")
self.LASTTRY = time.time() + 120 # 2-minute pause until next time. self.LASTTRY = time.time() + 120 # 2-minute pause until next time.
else: else:
logging.error("[Fix_Services] wifi.recon did not start up") logging.error("[Fix_Services] wifi.recon did not start up")
@ -388,25 +370,14 @@ class FixServices(plugins.Plugin):
else: else:
pos = (ui.width() / 2 + 35, ui.height() - 11) pos = (ui.width() / 2 + 35, ui.height() - 11)
logging.info("Got here") logging.debug("Got here")
ui.add_element('brcmfmac_status', Text(color=BLACK, value='--', position=pos, font=fonts.Small))
# called when the ui is updated # called when the ui is updated
def on_ui_update(self, ui): def on_ui_update(self, ui):
# update those elements return
if self._status:
ui.set('brcmfmac_status', "wlan0mon %s" % self._status)
else:
ui.set('brcmfmac_status', "rst#%s" % self._count)
def on_unload(self, ui): def on_unload(self, ui):
with ui._lock: return
try:
ui.remove_element('brcmfmac_status')
logging.info("[Fix_Services] unloaded")
except Exception as err:
logging.info("[Fix_Services] unload err %s " % repr(err))
pass
# run from command line to brute force a reload # run from command line to brute force a reload