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