Skip to content

Commit

Permalink
Merge branch 'master' of github.com:evilsocket/pwnagotchi
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Apr 18, 2021
2 parents 4441ae8 + edc0551 commit 6b3d904
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 55 deletions.
3 changes: 2 additions & 1 deletion builder/data/etc/network/interfaces.d/usb0-cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ iface usb0 inet static
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1
gateway 10.0.0.1
metric 20
4 changes: 2 additions & 2 deletions builder/pwnagotchi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
chdir: /usr/local/src/gratis
target: rpi
params:
EPD_IO: epd_io.h
EPD_IO: epd_io_free_uart.h
PANEL_VERSION: 'V231_G2'
when: gratisgit.changed

Expand All @@ -187,7 +187,7 @@
chdir: /usr/local/src/gratis
target: rpi-install
params:
EPD_IO: epd_io.h
EPD_IO: epd_io_free_uart.h
PANEL_VERSION: 'V231_G2'
when: gratisgit.changed

Expand Down
1 change: 1 addition & 0 deletions pwnagotchi/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ main.plugins.wpa-sec.whitelist = []
main.plugins.wigle.enabled = false
main.plugins.wigle.api_key = ""
main.plugins.wigle.whitelist = []
main.plugins.wigle.donate = true

main.plugins.bt-tether.enabled = false

Expand Down
2 changes: 1 addition & 1 deletion pwnagotchi/plugins/default/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def on_ui_setup(self, ui):
lat_pos = (67, 73)
lon_pos = (62, 83)
alt_pos = (67, 93)
elif ui.is_dfrobot_v2:
elif ui.is_dfrobot_v2():
lat_pos = (127, 75)
lon_pos = (122, 84)
alt_pos = (127, 94)
Expand Down
177 changes: 133 additions & 44 deletions pwnagotchi/plugins/default/memtemp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# memtemp shows memory infos and cpu temperature
#
# mem usage, cpu load, cpu temp
# mem usage, cpu load, cpu temp, cpu frequency
#
###############################################################
#
Expand All @@ -16,8 +16,15 @@
# - Added CPU load
# - Added horizontal and vertical orientation
#
# 19-09-2020 by crahan <[email protected]>
# - Added CPU frequency
# - Made field types and order configurable (max 3 fields)
# - Made line spacing and position configurable
# - Updated code to dynamically generate UI elements
# - Changed horizontal UI elements to Text
# - Updated to version 1.0.2
###############################################################
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.components import LabeledValue, Text
from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins
Expand All @@ -27,54 +34,31 @@

class MemTemp(plugins.Plugin):
__author__ = 'https://github.com/xenDE'
__version__ = '1.0.1'
__version__ = '1.0.2'
__license__ = 'GPL3'
__description__ = 'A plugin that will display memory/cpu usage and temperature'

ALLOWED_FIELDS = {
'mem': 'mem_usage',
'cpu': 'cpu_load',
'temp': 'cpu_temp',
'freq': 'cpu_freq'
}
DEFAULT_FIELDS = ['mem', 'cpu', 'temp']
LINE_SPACING = 10
LABEL_SPACING = 0
FIELD_WIDTH = 4

def on_loaded(self):
logging.info("memtemp plugin loaded.")

def mem_usage(self):
return int(pwnagotchi.mem_usage() * 100)
return f"{int(pwnagotchi.mem_usage() * 100)}%"

def cpu_load(self):
return int(pwnagotchi.cpu_load() * 100)

def on_ui_setup(self, ui):
if ui.is_waveshare_v2():
h_pos = (180, 80)
v_pos = (180, 61)
elif ui.is_waveshare_v1():
h_pos = (170, 80)
v_pos = (170, 61)
elif ui.is_waveshare144lcd():
h_pos = (53, 77)
v_pos = (78, 67)
elif ui.is_inky():
h_pos = (140, 68)
v_pos = (165, 54)
elif ui.is_waveshare27inch():
h_pos = (192, 138)
v_pos = (216, 122)
else:
h_pos = (155, 76)
v_pos = (180, 61)
return f"{int(pwnagotchi.cpu_load() * 100)}%"

if self.options['orientation'] == "vertical":
ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value=' mem:-\n cpu:-\ntemp:-',
position=v_pos,
label_font=fonts.Small, text_font=fonts.Small))
else:
# default to horizontal
ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value='mem cpu temp\n - - -',
position=h_pos,
label_font=fonts.Small, text_font=fonts.Small))

def on_unload(self, ui):
with ui._lock:
ui.remove_element('memtemp')

def on_ui_update(self, ui):
def cpu_temp(self):
if self.options['scale'] == "fahrenheit":
temp = (pwnagotchi.temperature() * 9 / 5) + 32
symbol = "f"
Expand All @@ -85,11 +69,116 @@ def on_ui_update(self, ui):
# default to celsius
temp = pwnagotchi.temperature()
symbol = "c"
return f"{temp}{symbol}"

def cpu_freq(self):
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq', 'rt') as fp:
return f"{round(float(fp.readline())/1000000, 1)}G"

def pad_text(self, data):
return " " * (self.FIELD_WIDTH - len(data)) + data

def on_ui_setup(self, ui):
try:
# Configure field list
self.fields = self.options['fields'].split(',')
self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()]
self.fields = self.fields[:3] # limit to the first 3 fields
except Exception:
# Set default value
self.fields = self.DEFAULT_FIELDS

try:
# Configure line_spacing
line_spacing = int(self.options['linespacing'])
except Exception:
# Set default value
line_spacing = self.LINE_SPACING

try:
# Configure position
pos = self.options['position'].split(',')
pos = [int(x.strip()) for x in pos]
if self.options['orientation'] == "vertical":
v_pos = (pos[0], pos[1])
else:
h_pos = (pos[0], pos[1])
except Exception:
# Set default position based on screen type
if ui.is_waveshare_v2():
h_pos = (178, 84)
v_pos = (197, 74)
elif ui.is_waveshare_v1():
h_pos = (170, 80)
v_pos = (165, 61)
elif ui.is_waveshare144lcd():
h_pos = (53, 77)
v_pos = (73, 67)
elif ui.is_inky():
h_pos = (140, 68)
v_pos = (160, 54)
elif ui.is_waveshare27inch():
h_pos = (192, 138)
v_pos = (211, 122)
else:
h_pos = (155, 76)
v_pos = (175, 61)

if self.options['orientation'] == "vertical":
# Dynamically create the required LabeledValue objects
for idx, field in enumerate(self.fields):
v_pos_x = v_pos[0]
v_pos_y = v_pos[1] + ((len(self.fields) - 3) * -1 * line_spacing)
ui.add_element(
f"memtemp_{field}",
LabeledValue(
color=BLACK,
label=f"{self.pad_text(field)}:",
value="-",
position=(v_pos_x, v_pos_y + (idx * line_spacing)),
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
)
)
else:
# default to horizontal
h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25)
h_pos_y = h_pos[1]
ui.add_element(
'memtemp_header',
Text(
color=BLACK,
value=" ".join([self.pad_text(x) for x in self.fields]),
position=(h_pos_x, h_pos_y),
font=fonts.Small,
)
)
ui.add_element(
'memtemp_data',
Text(
color=BLACK,
value=" ".join([self.pad_text("-") for x in self.fields]),
position=(h_pos_x, h_pos_y + line_spacing),
font=fonts.Small,
)
)

def on_unload(self, ui):
with ui._lock:
if self.options['orientation'] == "vertical":
for idx, field in enumerate(self.fields):
ui.remove_element(f"memtemp_{field}")
else:
# default to horizontal
ui.remove_element('memtemp_header')
ui.remove_element('memtemp_data')

def on_ui_update(self, ui):
if self.options['orientation'] == "vertical":
ui.set('memtemp',
" mem:%s%%\n cpu:%s%%\ntemp:%s%s" % (self.mem_usage(), self.cpu_load(), temp, symbol))
for idx, field in enumerate(self.fields):
ui.set(f"memtemp_{field}", getattr(self, self.ALLOWED_FIELDS[field])())
else:
# default to horizontal
ui.set('memtemp',
" mem cpu temp\n %s%% %s%% %s%s" % (self.mem_usage(), self.cpu_load(), temp, symbol))
data = " ".join([self.pad_text(getattr(self, self.ALLOWED_FIELDS[x])()) for x in self.fields])
ui.set('memtemp_data', data)
2 changes: 1 addition & 1 deletion pwnagotchi/plugins/default/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def on_epoch(self, agent, epoch, epoch_data):
logging.info('[WATCHDOG] Blind-Bug detected. Restarting.')
mode = 'MANU' if agent.mode == 'manual' else 'AUTO'
import pwnagotchi
pwnagotchi.restart(mode=mode)
pwnagotchi.reboot(mode=mode)
16 changes: 10 additions & 6 deletions pwnagotchi/plugins/default/wigle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pwnagotchi.utils import WifiInfo, FieldNotFoundError, extract_from_pcap, StatusFile, remove_whitelisted
from threading import Lock
from pwnagotchi import plugins
from pwnagotchi._version import __version__ as __pwnagotchi_version__


def _extract_gps_data(path):
Expand All @@ -34,14 +35,14 @@ def _format_auth(data):
return out


def _transform_wigle_entry(gps_data, pcap_data):
def _transform_wigle_entry(gps_data, pcap_data, plugin_version):
"""
Transform to wigle entry in file
"""
dummy = StringIO()
# write kismet header
dummy.write(
"WigleWifi-1.4,appRelease=20190201,model=Kismet,release=2019.02.01.{},device=kismet,display=kismet,board=kismet,brand=kismet\n")
"WigleWifi-1.4,appRelease={},model=pwnagotchi,release={},device=pwnagotchi,display=kismet,board=kismet,brand=pwnagotchi\n".format(plugin_version, __pwnagotchi_version__))
dummy.write(
"MAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type")

Expand All @@ -62,7 +63,7 @@ def _transform_wigle_entry(gps_data, pcap_data):
return dummy.getvalue()


def _send_to_wigle(lines, api_key, timeout=30):
def _send_to_wigle(lines, api_key, donate=True, timeout=30):
"""
Uploads the file to wigle-net
"""
Expand All @@ -76,7 +77,7 @@ def _send_to_wigle(lines, api_key, timeout=30):

headers = {'Authorization': f"Basic {api_key}",
'Accept': 'application/json'}
data = {'donate': 'false'}
data = {'donate': 'on' if donate else 'false'}
payload = {'file': dummy, 'type': 'text/csv'}

try:
Expand Down Expand Up @@ -112,6 +113,9 @@ def on_loaded(self):
if not 'whitelist' in self.options:
self.options['whitelist'] = list()

if not 'donate' in self.options:
self.options['donate'] = True

self.ready = True

def on_internet_available(self, agent):
Expand Down Expand Up @@ -172,14 +176,14 @@ def on_internet_available(self, agent):
logging.debug("WIGLE: %s", sc_e)
self.skip.append(gps_file)
continue
new_entry = _transform_wigle_entry(gps_data, pcap_data)
new_entry = _transform_wigle_entry(gps_data, pcap_data, self.__version__)
csv_entries.append(new_entry)
no_err_entries.append(gps_file)
if csv_entries:
display.set('status', "Uploading gps-data to wigle.net ...")
display.update(force=True)
try:
_send_to_wigle(csv_entries, self.options['api_key'])
_send_to_wigle(csv_entries, self.options['api_key'], donate=self.options['donate'])
reported += no_err_entries
self.report.update(data={'reported': reported})
logging.info("WIGLE: Successfully uploaded %d files", len(no_err_entries))
Expand Down
1 change: 1 addition & 0 deletions pwnagotchi/plugins/default/wpa-sec.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def on_loaded(self):
self.options['whitelist'] = list()

self.ready = True
logging.info("WPA_SEC: plugin loaded")

def on_webhook(self, path, request):
from flask import make_response, redirect
Expand Down
6 changes: 6 additions & 0 deletions pwnagotchi/ui/hw/inky.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def initialize(self):
from pwnagotchi.ui.hw.libs.inkyphat.inkyphatfast import InkyPHATFast
self._display = InkyPHATFast('black')
self._display.set_border(InkyPHATFast.BLACK)
elif self.config['color'] == 'auto':
from inky.auto import auto
self._display = auto()
self._display.set_border(self._display.BLACK)
self._layout['width'] = self._display.WIDTH
self._layout['height'] = self._display.HEIGHT
else:
from inky import InkyPHAT
self._display = InkyPHAT(self.config['color'])
Expand Down

0 comments on commit 6b3d904

Please sign in to comment.