misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
0830e0c74b
commit
aba5b938bc
pwnagotchi
@ -8,6 +8,7 @@ import _thread
|
||||
import pwnagotchi
|
||||
import pwnagotchi.utils as utils
|
||||
import pwnagotchi.plugins as plugins
|
||||
from pwnagotchi.ui.web.server import Server
|
||||
from pwnagotchi.automata import Automata
|
||||
from pwnagotchi.log import LastSession
|
||||
from pwnagotchi.bettercap import Client
|
||||
@ -18,8 +19,6 @@ RECOVERY_DATA_FILE = '/root/.pwnagotchi-recovery'
|
||||
|
||||
|
||||
class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
||||
INSTANCE = None
|
||||
|
||||
def __init__(self, view, config, keypair):
|
||||
Client.__init__(self, config['bettercap']['hostname'],
|
||||
config['bettercap']['scheme'],
|
||||
@ -36,6 +35,8 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
||||
self._supported_channels = utils.iface_channels(config['main']['iface'])
|
||||
self._view = view
|
||||
self._view.set_agent(self)
|
||||
self._web_ui = Server(self, self.config['ui']['display'])
|
||||
|
||||
self._access_points = []
|
||||
self._last_pwnd = None
|
||||
self._history = {}
|
||||
@ -46,8 +47,6 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
||||
if not os.path.exists(config['bettercap']['handshakes']):
|
||||
os.makedirs(config['bettercap']['handshakes'])
|
||||
|
||||
Agent.INSTANCE = self
|
||||
|
||||
def config(self):
|
||||
return self._config
|
||||
|
||||
|
@ -4,8 +4,6 @@ import threading
|
||||
|
||||
import pwnagotchi.plugins as plugins
|
||||
import pwnagotchi.ui.hw as hw
|
||||
import pwnagotchi.ui.web as web
|
||||
from pwnagotchi.ui.web.server import Server
|
||||
from pwnagotchi.ui.view import View
|
||||
|
||||
|
||||
@ -16,7 +14,6 @@ class Display(View):
|
||||
|
||||
self._enabled = config['enabled']
|
||||
self._rotation = config['rotation']
|
||||
self._webui = Server(config)
|
||||
|
||||
self.init_display()
|
||||
|
||||
@ -28,6 +25,9 @@ class Display(View):
|
||||
)
|
||||
self._render_thread_instance.start()
|
||||
|
||||
def set_ready(self):
|
||||
self._webui.start()
|
||||
|
||||
def is_inky(self):
|
||||
return self._implementation.name == 'inky'
|
||||
|
||||
@ -90,7 +90,6 @@ class Display(View):
|
||||
self._implementation.render(self._canvas_next)
|
||||
|
||||
def _on_view_rendered(self, img):
|
||||
web.update_frame(img)
|
||||
try:
|
||||
if self._config['ui']['display']['video']['on_frame'] != '':
|
||||
os.system(self._config['ui']['display']['video']['on_frame'])
|
||||
|
@ -10,6 +10,7 @@ import pwnagotchi.utils as utils
|
||||
import pwnagotchi.plugins as plugins
|
||||
from pwnagotchi.voice import Voice
|
||||
|
||||
import pwnagotchi.ui.web as web
|
||||
import pwnagotchi.ui.fonts as fonts
|
||||
import pwnagotchi.ui.faces as faces
|
||||
from pwnagotchi.ui.components import *
|
||||
@ -369,6 +370,8 @@ class View(object):
|
||||
for key, lv in self._state.items():
|
||||
lv.draw(self._canvas, drawer)
|
||||
|
||||
web.update_frame(self._canvas)
|
||||
|
||||
for cb in self._render_cbs:
|
||||
cb(self._canvas)
|
||||
|
||||
|
@ -8,7 +8,6 @@ os.environ['WERKZEUG_RUN_MAIN'] = 'true'
|
||||
|
||||
import pwnagotchi
|
||||
import pwnagotchi.ui.web as web
|
||||
from pwnagotchi.agent import Agent
|
||||
from pwnagotchi import plugins
|
||||
|
||||
from flask import send_file
|
||||
@ -87,7 +86,8 @@ STATUS_PAGE = """<html>
|
||||
|
||||
|
||||
class Handler:
|
||||
def __init__(self, app):
|
||||
def __init__(self, agent, app):
|
||||
self._agent = agent
|
||||
self._app = app
|
||||
self._app.add_url_rule('/', 'index', self.index)
|
||||
self._app.add_url_rule('/ui', 'ui', self.ui)
|
||||
@ -102,7 +102,7 @@ class Handler:
|
||||
|
||||
def index(self):
|
||||
return render_template_string(INDEX, title=pwnagotchi.name(),
|
||||
other_mode='AUTO' if Agent.INSTANCE.mode == 'manual' else 'MANU')
|
||||
other_mode='AUTO' if self._agent.mode == 'manual' else 'MANU')
|
||||
|
||||
def plugins(self, name, subpath):
|
||||
if name is None:
|
||||
|
@ -15,12 +15,12 @@ from pwnagotchi.ui.web.handler import Handler
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, config):
|
||||
def __init__(self, agent, config):
|
||||
self._enabled = config['video']['enabled']
|
||||
self._port = config['video']['port']
|
||||
self._address = config['video']['address']
|
||||
self._origin = None
|
||||
|
||||
self._agent = agent
|
||||
if 'origin' in config['video']:
|
||||
self._origin = config['video']['origin']
|
||||
|
||||
@ -36,7 +36,7 @@ class Server:
|
||||
CORS(app, resources={r"*": {"origins": self._origin}})
|
||||
|
||||
CSRFProtect(app)
|
||||
Handler(app)
|
||||
Handler(agent, app)
|
||||
|
||||
app.run(host=self._address, port=self._port, debug=False)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user