2019-12-04 20:17:10 +05:30
|
|
|
import logging
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
|
|
|
|
import pwnagotchi
|
|
|
|
import pwnagotchi.plugins as plugins
|
|
|
|
|
2024-06-12 19:47:21 +00:00
|
|
|
from flask import abort, send_from_directory, render_template_string
|
2019-12-04 20:17:10 +05:30
|
|
|
|
|
|
|
TEMPLATE = """
|
|
|
|
{% extends "base.html" %}
|
|
|
|
{% set active_page = "handshakes" %}
|
|
|
|
|
|
|
|
{% block title %}
|
|
|
|
{{ title }}
|
|
|
|
{% endblock %}
|
|
|
|
|
2020-04-14 18:15:25 +02:00
|
|
|
{% block styles %}
|
|
|
|
{{ super() }}
|
|
|
|
<style>
|
|
|
|
#filter {
|
|
|
|
width: 100%;
|
|
|
|
font-size: 16px;
|
|
|
|
padding: 12px 20px 12px 40px;
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
{% endblock %}
|
|
|
|
{% block script %}
|
|
|
|
var shakeList = document.getElementById('list');
|
|
|
|
var filter = document.getElementById('filter');
|
|
|
|
var filterVal = filter.value.toUpperCase();
|
|
|
|
|
|
|
|
filter.onkeyup = function() {
|
|
|
|
document.body.style.cursor = 'progress';
|
2024-06-12 19:47:21 +00:00
|
|
|
var li = shakeList.getElementsByTagName("li");
|
|
|
|
for (var i = 0; i < li.length; i++) {
|
|
|
|
var txtValue = li[i].textContent || li[i].innerText;
|
2020-04-14 18:15:25 +02:00
|
|
|
if (txtValue.toUpperCase().indexOf(filterVal) > -1) {
|
|
|
|
li[i].style.display = "list-item";
|
|
|
|
} else {
|
|
|
|
li[i].style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.body.style.cursor = 'default';
|
|
|
|
}
|
|
|
|
{% endblock %}
|
|
|
|
|
2019-12-04 20:17:10 +05:30
|
|
|
{% block content %}
|
2020-04-14 18:15:25 +02:00
|
|
|
<input type="text" id="filter" placeholder="Search for ..." title="Type in a filter">
|
2019-12-04 20:17:10 +05:30
|
|
|
<ul id="list" data-role="listview" style="list-style-type:disc;">
|
|
|
|
{% for handshake in handshakes %}
|
|
|
|
<li class="file">
|
2024-06-12 19:47:21 +00:00
|
|
|
<a href="/plugins/handshakes-dl/{{ handshake }}">{{ handshake }}</a>
|
2019-12-04 20:17:10 +05:30
|
|
|
</li>
|
|
|
|
{% endfor %}
|
|
|
|
</ul>
|
|
|
|
{% endblock %}
|
|
|
|
"""
|
|
|
|
|
|
|
|
class HandshakesDL(plugins.Plugin):
|
|
|
|
__author__ = 'me@sayakb.com'
|
2020-04-14 18:16:00 +02:00
|
|
|
__version__ = '0.2.1'
|
2019-12-04 20:17:10 +05:30
|
|
|
__license__ = 'GPL3'
|
|
|
|
__description__ = 'Download handshake captures from web-ui.'
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.ready = False
|
|
|
|
|
|
|
|
def on_loaded(self):
|
2024-04-25 15:43:35 +00:00
|
|
|
logging.info("HandshakesDL plugin loaded")
|
2019-12-04 20:17:10 +05:30
|
|
|
|
2020-04-11 10:14:23 +02:00
|
|
|
def on_config_changed(self, config):
|
|
|
|
self.config = config
|
2019-12-04 20:17:10 +05:30
|
|
|
self.ready = True
|
|
|
|
|
|
|
|
def on_webhook(self, path, request):
|
|
|
|
if not self.ready:
|
|
|
|
return "Plugin not ready"
|
|
|
|
|
|
|
|
if path == "/" or not path:
|
2024-04-22 04:50:16 +00:00
|
|
|
handshakes = glob.glob(os.path.join("/home/pi", "*.pcap"))
|
2024-04-22 18:02:11 +00:00
|
|
|
handshakes = [os.path.basename(handshake) for handshake in handshakes]
|
2019-12-04 20:17:10 +05:30
|
|
|
return render_template_string(TEMPLATE,
|
2024-06-12 19:47:21 +00:00
|
|
|
title="Handshakes | " + pwnagotchi.name(),
|
|
|
|
handshakes=handshakes)
|
2019-12-04 20:17:10 +05:30
|
|
|
else:
|
2024-04-22 18:02:11 +00:00
|
|
|
directory = "/home/pi"
|
2019-12-04 20:17:10 +05:30
|
|
|
try:
|
2024-04-22 18:02:11 +00:00
|
|
|
file_path = os.path.join(directory, path)
|
|
|
|
logging.info(f"[HandshakesDL] serving {file_path}")
|
2024-06-12 19:47:21 +00:00
|
|
|
return send_from_directory(directory=directory, filename=path, as_attachment=True)
|
2019-12-04 20:17:10 +05:30
|
|
|
except FileNotFoundError:
|
2024-04-22 18:02:11 +00:00
|
|
|
logging.error("File not found")
|
2019-12-04 20:17:10 +05:30
|
|
|
abort(404)
|
2024-04-22 18:02:11 +00:00
|
|
|
except Exception as e:
|
|
|
|
logging.error(f"Error: {e}")
|
|
|
|
abort(500)
|