mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
- hosts:
|
- hosts:
|
||||||
- all
|
- 127.0.0.1
|
||||||
|
gather_facts: true
|
||||||
become: true
|
become: true
|
||||||
vars:
|
vars:
|
||||||
pwnagotchi:
|
pwnagotchi:
|
||||||
@ -137,8 +138,20 @@
|
|||||||
- libpcap-dev
|
- libpcap-dev
|
||||||
- libusb-1.0-0-dev
|
- libusb-1.0-0-dev
|
||||||
- libnetfilter-queue-dev
|
- libnetfilter-queue-dev
|
||||||
|
environment:
|
||||||
|
ARCHFLAGS: "-arch armv8"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: System details
|
||||||
|
debug:
|
||||||
|
msg="{{ item }}"
|
||||||
|
with_items:
|
||||||
|
- "{{ ansible_distribution }}"
|
||||||
|
- "{{ ansible_distribution_version }}"
|
||||||
|
- "{{ ansible_distribution_major_version }}"
|
||||||
|
- "{{ ansible_architecture }}"
|
||||||
|
- "{{ ansible_machine }}"
|
||||||
|
|
||||||
- name: change hostname
|
- name: change hostname
|
||||||
lineinfile:
|
lineinfile:
|
||||||
dest: /etc/hostname
|
dest: /etc/hostname
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import websockets
|
import websockets
|
||||||
@ -8,12 +7,14 @@ import random
|
|||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
requests.adapters.DEFAULT_RETRIES = 5 # increase retries number
|
requests.adapters.DEFAULT_RETRIES = 5 # increase retries number
|
||||||
|
|
||||||
ping_timeout = 90
|
ping_timeout = 180
|
||||||
ping_interval = 60
|
ping_interval = 15
|
||||||
|
max_queue = 10000
|
||||||
|
|
||||||
max_sleep = 2.0
|
min_sleep = 0.5
|
||||||
|
max_sleep = 5.0
|
||||||
|
|
||||||
|
|
||||||
def decode(r, verbose_errors=True):
|
def decode(r, verbose_errors=True):
|
||||||
@ -59,7 +60,7 @@ class Client(object):
|
|||||||
# logging.debug("Error while parsing event (%s)", ex)
|
# logging.debug("Error while parsing event (%s)", ex)
|
||||||
# except websockets.exceptions.ConnectionClosedError:
|
# except websockets.exceptions.ConnectionClosedError:
|
||||||
# sleep_time = max_sleep*random.random()
|
# sleep_time = max_sleep*random.random()
|
||||||
# logger.warning('Retrying websocket connection in {} sec'.format(sleep_time))
|
# logging.warning('Retrying websocket connection in {} sec'.format(sleep_time))
|
||||||
# await asyncio.sleep(sleep_time)
|
# await asyncio.sleep(sleep_time)
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ class Client(object):
|
|||||||
while True:
|
while True:
|
||||||
logging.info("creating new websocket...")
|
logging.info("creating new websocket...")
|
||||||
try:
|
try:
|
||||||
async with websockets.connect(s, ping_interval=ping_interval, ping_timeout=ping_timeout) as ws:
|
async with websockets.connect(s, ping_interval=ping_interval, ping_timeout=ping_timeout, max_queue=max_queue) as ws:
|
||||||
# listener loop
|
# listener loop
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -75,35 +76,41 @@ class Client(object):
|
|||||||
try:
|
try:
|
||||||
await consumer(msg)
|
await consumer(msg)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.debug("error while parsing event (%s)", ex)
|
logging.debug("error while parsing event (%s)", ex)
|
||||||
except websockets.exceptions.ConnectionClosedError:
|
except websockets.ConnectionClosedError:
|
||||||
try:
|
try:
|
||||||
pong = await ws.ping()
|
pong = await ws.ping()
|
||||||
await asyncio.wait_for(pong, timeout=ping_timeout)
|
await asyncio.wait_for(pong, timeout=ping_timeout)
|
||||||
logging.warning('ping OK, keeping connection alive...')
|
logging.warning('ping OK, keeping connection alive...')
|
||||||
continue
|
continue
|
||||||
except:
|
except:
|
||||||
sleep_time = max_sleep*random.random()
|
sleep_time = min_sleep + max_sleep*random.random()
|
||||||
logging.warning('ping error - retrying connection in {} sec'.format(sleep_time))
|
logging.warning('ping error - retrying connection in {} sec'.format(sleep_time))
|
||||||
await asyncio.sleep(sleep_time)
|
await asyncio.sleep(sleep_time)
|
||||||
break
|
break
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
sleep_time = max_sleep*random.random()
|
sleep_time = min_sleep + max_sleep*random.random()
|
||||||
logging.warning('nobody seems to listen to the bettercap endpoint...')
|
logging.warning('nobody seems to be listening at the bettercap endpoint...')
|
||||||
|
logging.warning('retrying connection in {} sec'.format(sleep_time))
|
||||||
|
await asyncio.sleep(sleep_time)
|
||||||
|
continue
|
||||||
|
except OSError:
|
||||||
|
sleep_time = min_sleep + max_sleep*random.random()
|
||||||
|
logging.warning('connection to the bettercap endpoint failed...')
|
||||||
logging.warning('retrying connection in {} sec'.format(sleep_time))
|
logging.warning('retrying connection in {} sec'.format(sleep_time))
|
||||||
await asyncio.sleep(sleep_time)
|
await asyncio.sleep(sleep_time)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def run(self, command, verbose_errors=True):
|
def run(self, command, verbose_errors=True):
|
||||||
for _ in range(0, 2):
|
while True:
|
||||||
try:
|
try:
|
||||||
r = requests.post("%s/session" % self.url, auth=self.auth, json={'cmd': command})
|
r = requests.post("%s/session" % self.url, auth=self.auth, json={'cmd': command})
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
sleep_time = max_sleep*random.random()
|
sleep_time = min_sleep + max_sleep*random.random()
|
||||||
logging.exception("Request connection error (%s) while running command (%s)", e, command)
|
logging.warning("can't run my request... connection to the bettercap endpoint failed...")
|
||||||
logging.warning('Retrying run in {} sec'.format(sleep_time))
|
logging.warning('retrying run in {} sec'.format(sleep_time))
|
||||||
sleep(sleep_time)
|
sleep(sleep_time)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
return decode(r, verbose_errors=verbose_errors)
|
return decode(r, verbose_errors=verbose_errors)
|
Reference in New Issue
Block a user