new: button to restart in auto or manu mode

This commit is contained in:
Simone Margaritelli 2019-11-04 17:35:06 +01:00
parent e336fca0de
commit 364af70ad5
4 changed files with 37 additions and 12 deletions

View File

@ -65,6 +65,7 @@ if __name__ == '__main__':
elif args.do_manual: elif args.do_manual:
logging.info("entering manual mode ...") logging.info("entering manual mode ...")
agent.mode = 'manual'
agent.last_session.parse(agent.view(), args.skip_session) agent.last_session.parse(agent.view(), args.skip_session)
if not args.skip_session: if not args.skip_session:
logging.info( logging.info(
@ -85,6 +86,7 @@ if __name__ == '__main__':
else: else:
logging.info("entering auto mode ...") logging.info("entering auto mode ...")
agent.mode = 'auto'
agent.start() agent.start()
while True: while True:

View File

@ -108,6 +108,18 @@ def shutdown():
os.system("halt") os.system("halt")
def restart(mode):
logging.warning("restarting in %s mode ..." % mode)
if mode == 'AUTO':
os.system("touch /root/.pwnagotchi-auto")
else:
os.system("touch /root/.pwnagotchi-manual")
os.system("service bettercap restart")
os.system("service pwnagotchi restart")
def reboot(mode=None): def reboot(mode=None):
if mode is not None: if mode is not None:
mode = mode.upper() mode = mode.upper()
@ -122,6 +134,8 @@ def reboot(mode=None):
if mode == 'AUTO': if mode == 'AUTO':
os.system("touch /root/.pwnagotchi-auto") os.system("touch /root/.pwnagotchi-auto")
elif mode == 'MANU':
os.system("touch /root/.pwnagotchi-manual")
os.system("sync") os.system("sync")
os.system("shutdown -r now") os.system("shutdown -r now")

View File

@ -18,6 +18,8 @@ RECOVERY_DATA_FILE = '/root/.pwnagotchi-recovery'
class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer): class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
INSTANCE = None
def __init__(self, view, config, keypair): def __init__(self, view, config, keypair):
Client.__init__(self, config['bettercap']['hostname'], Client.__init__(self, config['bettercap']['hostname'],
config['bettercap']['scheme'], config['bettercap']['scheme'],
@ -39,10 +41,13 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
self._history = {} self._history = {}
self._handshakes = {} self._handshakes = {}
self.last_session = LastSession(self._config) self.last_session = LastSession(self._config)
self.mode = 'auto'
if not os.path.exists(config['bettercap']['handshakes']): if not os.path.exists(config['bettercap']['handshakes']):
os.makedirs(config['bettercap']['handshakes']) os.makedirs(config['bettercap']['handshakes'])
Agent.INSTANCE = self
def config(self): def config(self):
return self._config return self._config

View File

@ -6,6 +6,7 @@ import shutil
import logging import logging
import pwnagotchi import pwnagotchi
from pwnagotchi.agent import Agent
from pwnagotchi import plugins from pwnagotchi import plugins
frame_path = '/root/pwnagotchi.png' frame_path = '/root/pwnagotchi.png'
@ -65,8 +66,8 @@ INDEX = """<html>
<form style="display:inline;" method="POST" action="/shutdown" onsubmit="return confirm('This will halt the unit, continue?');"> <form style="display:inline;" method="POST" action="/shutdown" onsubmit="return confirm('This will halt the unit, continue?');">
<input style="display:inline;" type="submit" class="block" value="Shutdown"/> <input style="display:inline;" type="submit" class="block" value="Shutdown"/>
</form> </form>
<form style="display:inline;" method="POST" action="/reboot_into_auto" onsubmit="return confirm('This will reboot the unit into AUTO mode, continue?');"> <form style="display:inline;" method="POST" action="/restart" onsubmit="return confirm('This will restart the service in %s mode, continue?');">
<input style="display:inline;" type="submit" class="block" value="Reboot into AUTO mode"/> <input style="display:inline;" type="submit" class="block" value="Restart in %s mode"/>
</form> </form>
</div> </div>
@ -122,17 +123,22 @@ class Handler(BaseHTTPRequestHandler):
# serve the main html page # serve the main html page
def _index(self): def _index(self):
self._html(INDEX % (pwnagotchi.name(), 1000)) other_mode = 'AUTO' if Agent.INSTANCE.mode == 'manual' else 'MANU'
self._html(INDEX % (
pwnagotchi.name(),
1000, other_mode,
other_mode))
# serve a message and shuts down the unit # serve a message and shuts down the unit
def _shutdown(self): def _shutdown(self):
self._html(STATUS_PAGE % (pwnagotchi.name(), 'Shutting down ...')) self._html(STATUS_PAGE % (pwnagotchi.name(), 'Shutting down ...'))
pwnagotchi.shutdown() pwnagotchi.shutdown()
# serve a message and reboot the unit into auto mode # serve a message and restart the unit in the other mode
def _reboot(self): def _reboot(self):
self._html(STATUS_PAGE % (pwnagotchi.name(), 'Rebooting into AUTO mode ...')) other_mode = 'AUTO' if Agent.INSTANCE.mode == 'manual' else 'MANU'
pwnagotchi.reboot(mode='AUTO') self._html(STATUS_PAGE % (pwnagotchi.name(), 'Restart in %s mode ...' % other_mode))
pwnagotchi.restart(other_mode)
# serve the PNG file with the display image # serve the PNG file with the display image
def _image(self): def _image(self):
@ -174,21 +180,20 @@ class Handler(BaseHTTPRequestHandler):
def do_POST(self): def do_POST(self):
if not self._is_allowed(): if not self._is_allowed():
return return
if self.path.startswith('/shutdown'): elif self.path.startswith('/shutdown'):
self._shutdown() self._shutdown()
elif self.path.startswith('/restart'):
self._restart()
else: else:
self.send_response(404) self.send_response(404)
def do_GET(self): def do_GET(self):
if not self._is_allowed(): if not self._is_allowed():
return return
elif self.path == '/':
if self.path == '/':
self._index() self._index()
elif self.path.startswith('/ui'): elif self.path.startswith('/ui'):
self._image() self._image()
elif self.path.startswith('/plugins'): elif self.path.startswith('/plugins'):
matches = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path) matches = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path)
if matches: if matches:
@ -196,7 +201,6 @@ class Handler(BaseHTTPRequestHandler):
plugin_name = groups[0] plugin_name = groups[0]
right_path = groups[1] if len(groups) == 2 else None right_path = groups[1] if len(groups) == 2 else None
plugins.one(plugin_name, 'webhook', self, right_path) plugins.one(plugin_name, 'webhook', self, right_path)
else: else:
self.send_response(404) self.send_response(404)