multiple edits

Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-09-21 12:13:41 +02:00
parent 8b09c5c8f1
commit ddf64cb0b3
8 changed files with 61 additions and 27 deletions

View File

@ -1,10 +1,10 @@
import os
import glob
import _thread
import threading
import importlib, importlib.util
import glob
import importlib
import importlib.util
import logging
import os
import threading
default_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "default")
loaded = {}

View File

@ -473,7 +473,7 @@ class BTTether(plugins.Plugin):
devices_to_try = list()
connected_priorities = list()
any_device_connected = False # if this is true, last status on screen should be C
any_device_connected = False # if this is true, last status on screen should be C
for _, device in self.devices.items():
if device.connected():
@ -579,7 +579,7 @@ class BTTether(plugins.Plugin):
def on_ui_setup(self, ui):
with ui._lock:
ui.add_element('bluetooth', LabeledValue(color=BLACK, label='BT', value='-',
position=(ui.width() / 2 - 10, 0),
position=(ui.width() / 2 - 5, 0),
label_font=fonts.Bold, text_font=fonts.Medium))
def on_ui_update(self, ui):

View File

@ -3,14 +3,13 @@ import pwnagotchi.ui.components as components
import pwnagotchi.ui.view as view
import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins
import pwnagotchi
import subprocess
import socket
import os
class InternetConnectionPlugin(plugins.Plugin):
__author__ = 'adi1708, edited by jayofelony'
__version__ = '1.1'
__version__ = '1.2'
__license__ = 'GPL3'
__description__ = 'A plugin that displays the Internet connection status on the pwnagotchi display.'
__name__ = 'InternetConnectionPlugin'
@ -21,35 +20,44 @@ class InternetConnectionPlugin(plugins.Plugin):
'pip': ['scapy']
}
__defaults__ = {
'enabled': False,
'enabled': True,
}
def on_loaded(self):
logging.info("[Internet-Connection] plugin loaded.")
def on_ui_setup(self, ui):
if ui.is_waveshare35lcd():
v_pos = (180, 61)
with ui._lock:
ui.add_element('connection_ip', components.LabeledValue(color=view.BLACK, label='eth0:', value='',
position=v_pos, label_font=fonts.Bold,
text_font=fonts.Small))
with ui._lock:
# add a LabeledValue element to the UI with the given label and value
# the position and font can also be specified
ui.add_element('connection_status', components.LabeledValue(color=view.BLACK, label='WWW', value='-',
position=(ui.width() / 2 - 40, 0),
position=(ui.width() / 2 - 35, 0),
label_font=fonts.Bold, text_font=fonts.Medium))
def on_ui_update(self, ui):
if ui.is_wavehare35lcd():
ip = os.popen('ifconfig eth0 | grep inet | awk \'{print $2}\'').read()
ui.set('connection_ip', ip)
# check if there is an active Internet connection
try:
# See if we can resolve the host name - tells us if there is
# A DNS listening
host = socket.gethostbyname("1.1.1.1")
# Connect to the host - tells us if the host is actually reachable
s = socket.create_connection((host, 80), 2)
s.close()
socket.create_connection(("1.1.1.1", 80), 2).close()
ui.set('connection_status', 'C')
except:
except TimeoutError as err:
# if the command failed, it means there is no active Internet connection
# we could log the error, but no need really
# logging.error('[Internet-Connection] Socket creation failed: %s' % err)
ui.set('connection_status', 'D')
def on_unload(self, ui):
with ui._lock:
logging.info("[Internet-Connection] plugin unloaded")
ui.remove_element('connection_status')
if ui.is_waveshare35lcd():
ui.remove_element('connection_ip')