Skip to content

Commit

Permalink
Version 2.2.9:
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen Oudshoorn <[email protected]>
  • Loading branch information
jayofelony committed Sep 5, 2023
1 parent 173c0ec commit 8c9519f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 217 deletions.
27 changes: 26 additions & 1 deletion bin/pwnagotchi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from pwnagotchi.plugins import cmd as plugins_cmd
from pwnagotchi import log
from pwnagotchi import restart
from pwnagotchi import fs
from pwnagotchi.utils import DottedTomlEncoder
from pwnagotchi.utils import DottedTomlEncoder, parse_version as version_to_tuple


def do_clear(display):
Expand Down Expand Up @@ -118,6 +118,11 @@ if __name__ == '__main__':
parser.add_argument('--print-config', dest="print_config", action="store_true", default=False,
help="Print the configuration.")

parser.add_argument('--check-update', dest="check_update", action="store_true", default=False,
help="Check for updates on Pwnagotchi.")
parser.add_argument('--donate', dest="donate", action="store_true", default=False,
help="How to donate to this project.")

args = parser.parse_args()

if plugins_cmd.used_plugin_cmd(args):
Expand All @@ -126,6 +131,26 @@ if __name__ == '__main__':
rc = plugins_cmd.handle_cmd(args, config)
sys.exit(rc)

if args.donate:
print("Donations can made @ https://www.patreon.com/pwnagotchi_torch \n\nBut only if you really want to!")

if args.check_update:
resp = requests.get("https://api.github.com/repos/jayofelony/pwnagotchi/releases/latest")
latest = resp.json()
latest_ver = latest['tag_name'].replace('v', '')

local = version_to_tuple(pwnagotchi.__version__)
remote = version_to_tuple(latest_ver)
if remote > local:
user_input = input("There is a new version available! Update to %s? [y(es)/n(o)]" % latest_ver)
# input validation
if user_input.lower() in ('y', 'yes'):
os.system("rm /root/.auto-update && systemctl restart pwnagotchi")
elif user_input.lower() in ('n', 'no'): # using this elif for readability
print("Okay, guess not!")
else:
print("You are currently on the latest release, %s." % pwnagotchi.__version__)

if args.version:
print(pwnagotchi.__version__)
sys.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion pwnagotchi/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.8'
__version__ = '2.2.9'
17 changes: 14 additions & 3 deletions pwnagotchi/bettercap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ async def start_websocket(self, consumer):
logging.debug("Lost websocket connection. Reconnecting...")
except websockets.exceptions.WebSocketException as wex:
logging.debug("Websocket exception (%s)", wex)
except Exception as e:
logging.exception("Other error while opening websocket (%s) with parameter %s", e, s)

def run(self, command, verbose_errors=True):
r = requests.post("%s/session" % self.url, auth=self.auth, json={'cmd': command})
return decode(r, verbose_errors=verbose_errors)

def run(self, command, verbose_errors=True):
for _ in range(0, 2):
try:
r = requests.post("%s/session" % self.url, auth=self.auth, json={'cmd': command})
except requests.exceptions.ConnectionError as e:
logging.exception("Request connection error (%s) while running command (%s)", e, command)
sleep(1) # Sleep for 1-s before trying a second time
else:
break

return decode(r, verbose_errors=verbose_errors)
32 changes: 3 additions & 29 deletions pwnagotchi/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ main.plugins.grid.exclude = [
"YourHomeNetworkHere"
]

main.plugins.auto-update.enabled = false
main.plugins.auto-update.install = false
main.plugins.auto-update.interval = 24
main.plugins.auto-update.enabled = true
main.plugins.auto-update.install = true
main.plugins.auto-update.interval = 1

main.plugins.net-pos.enabled = false
main.plugins.net-pos.api_key = "test"
Expand Down Expand Up @@ -119,32 +119,6 @@ main.plugins.ups_lite.shutdown = 2

main.plugins.gpio_buttons.enabled = false

main.plugins.led.enabled = false
main.plugins.led.led = 0
main.plugins.led.delay = 200
main.plugins.led.patterns.loaded = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.updating = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.unread_inbox = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.ready = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.ai_ready = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.ai_training_start = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.ai_best_reward = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.ai_worst_reward = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.bored = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.sad = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.excited = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.lonely = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.rebooting = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.wait = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.sleep = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.wifi_update = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.association = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.deauthentication = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.handshake = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.epoch = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.peer_detected = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.peer_lost = "oo oo oo oo oo oo oo"

main.plugins.webcfg.enabled = true

main.plugins.logtail.enabled = false
Expand Down
2 changes: 1 addition & 1 deletion pwnagotchi/plugins/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pwnagotchi.plugins import default_path


SAVE_DIR = '/usr/local/share/pwnagotchi/availaible-plugins/'
SAVE_DIR = '/usr/local/share/pwnagotchi/available-plugins/'
DEFAULT_INSTALL_PATH = '/usr/local/share/pwnagotchi/installed-plugins/'


Expand Down
11 changes: 8 additions & 3 deletions pwnagotchi/plugins/default/auto-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ def install(display, update):
if not os.path.exists(source_path):
source_path = "%s-%s" % (source_path, update['available'])

# setup.py is going to install data files for us
os.system("cd %s && pip3 install ." % source_path)
if "pwngrid" in source_path:
os.system("cd %s && make && make install" % source_path)
elif "bettercap" in source_path:
os.system("cd %s && make && make install" % source_path)
else:
# setup.py is going to install data files for us
os.system("cd %s && pip3 install ." % source_path)

return True

Expand Down Expand Up @@ -182,7 +187,7 @@ def on_internet_available(self, agent):
to_install = []
to_check = [
('jayofelony/bettercap', parse_version('bettercap -version'), True, 'bettercap'),
('evilsocket/pwngrid', parse_version('pwngrid -version'), True, 'pwngrid-peer'),
('jayofelony/pwngrid', parse_version('pwngrid -version'), True, 'pwngrid-peer'),
('jayofelony/pwnagotchi', pwnagotchi.__version__, False, 'pwnagotchi')
]

Expand Down
25 changes: 6 additions & 19 deletions pwnagotchi/plugins/default/fix_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def __init__(self):
self.options = dict()
self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed')
self.pattern2 = re.compile(r'wifi error while hopping to channel')
self.pattern3 = re.compile(r'Firmware has halted or crashed')
self.pattern3 = re.compile(r'error 400: could not find interface wlan0mon')
self.pattern4 = re.compile(r'AI not loaded!')
self.pattern5 = re.compile(r'ConnectionError')
self.isReloadingMon = False
self.connection = None
self.LASTTRY = 0
Expand Down Expand Up @@ -113,6 +112,8 @@ def on_epoch(self, agent, epoch, epoch_data):
stdout=subprocess.PIPE).stdout))[-10:])
other_last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl', '-n10'],
stdout=subprocess.PIPE).stdout))[-10:])
other_other_last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['tail', '-n10', '/var/log/pwnagotchi.log'],
stdout=subprocess.PIPE).stdout))[-10:])
# don't check if we ran a reset recently
logging.debug("[FixBRCMF]**** epoch")
if time.time() - self.LASTTRY > 180:
Expand Down Expand Up @@ -159,22 +160,22 @@ def on_epoch(self, agent, epoch, epoch_data):
logging.error("[FixBRCMF wifi.recon flip] %s" % repr(err))

# Look for pattern 3
elif len(self.pattern3.findall(other_last_lines)) >= 1:
elif len(self.pattern3.findall(other_other_last_lines)) >= 1:
logging.info("[FixBRCMF] Firmware has halted or crashed. Restarting wlan0mon.")
if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Firmware has halted or crashed. Restarting wlan0mon.')
display.update(force=True)
try:
# Run the monstart command to restart wlan0mon
cmd_output = restart("AUTO")
cmd_output = subprocess.check_output("monstart", shell=True)
self._status = "up"
logging.info("[FixBRCMF monstart]: %s" % repr(cmd_output))
except Exception as err:
logging.error("[FixBRCMF monstart]: %s" % repr(err))

# Look for pattern 4
elif len(self.pattern4.findall(other_last_lines)) >= 1:
elif len(self.pattern4.findall(other_other_last_lines)) >= 1:
logging.info("[FixBRCMF] Having a brain meltdown. Deleting myself.")
if hasattr(agent, 'view'):
display = agent.view()
Expand All @@ -190,20 +191,6 @@ def on_epoch(self, agent, epoch, epoch_data):
except Exception as err:
logging.error("[FixBRCMF brain]: %s" % repr(err))

# Look for pattern 5
elif len(self.pattern5.findall(other_last_lines)) >= 1:
logging.info("[FixBRCMF] Bettercap connection failure. Restarting Bettercap.")
if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Bettercap connection failure. Restarting Bettercap.')
try:
# Delete brain /root/brain.nn and restarting pwnagotchi service
cmd_output = subprocess.check_output("systemctl restart bettercap",
shell=True)
self._status = "up"
logging.info("[FixBRCMF bettercap]: %s" % repr(cmd_output))
except Exception as err:
logging.error("[FixBRCMF bettercap]: %s" % repr(err))
else:
print("logs look good")

Expand Down
159 changes: 0 additions & 159 deletions pwnagotchi/plugins/default/led.py

This file was deleted.

2 changes: 2 additions & 0 deletions pwnagotchi/ui/hw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class DisplayImpl(object):
def __init__(self, config, name):
if fonts.Medium is None:
fonts.init(config)
self.name = name
self.config = config['ui']['display']
self._layout = {
Expand Down
Loading

0 comments on commit 8c9519f

Please sign in to comment.