Update public source
This commit is contained in:
+120
-245
@@ -21,6 +21,7 @@ sys.path.insert(
|
||||
|
||||
from flask import (
|
||||
Flask,
|
||||
abort,
|
||||
Response,
|
||||
jsonify,
|
||||
redirect,
|
||||
@@ -49,9 +50,6 @@ from reports.hashcat import (
|
||||
build_export_filename,
|
||||
import_hashcat_show,
|
||||
)
|
||||
from reports.hashcat_page import (
|
||||
render_hashcat_page,
|
||||
)
|
||||
from reports.trips_page import render_trips_page
|
||||
from reports.wifitrip import (
|
||||
export_wifitrip,
|
||||
@@ -67,6 +65,7 @@ from vendor_service import VendorService
|
||||
from sudo import SudoChecker
|
||||
from config import Config
|
||||
from gps_test import GPSTestService
|
||||
from logger import setup_logger
|
||||
|
||||
app = Flask(
|
||||
__name__,
|
||||
@@ -78,10 +77,119 @@ app = Flask(
|
||||
)
|
||||
)
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
app.register_blueprint(
|
||||
cracklab_bp
|
||||
)
|
||||
|
||||
def wants_json_error():
|
||||
return (
|
||||
request.path.startswith((
|
||||
"/api/",
|
||||
"/gps-test/",
|
||||
"/config/",
|
||||
"/scanner/",
|
||||
"/reports/vendors/update",
|
||||
"/reports/search/data"
|
||||
))
|
||||
or request.is_json
|
||||
or request.headers.get("X-Requested-With") == "XMLHttpRequest"
|
||||
or request.accept_mimetypes.best == "application/json"
|
||||
)
|
||||
|
||||
|
||||
def render_http_error(status_code, title, message):
|
||||
if wants_json_error():
|
||||
return jsonify({
|
||||
"error": message
|
||||
}), status_code
|
||||
|
||||
return render_template(
|
||||
"error.html",
|
||||
status_code=status_code,
|
||||
title=title,
|
||||
message=message
|
||||
), status_code
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error):
|
||||
logger.warning(
|
||||
"HTTP 404 method=%s path=%s",
|
||||
request.method,
|
||||
request.path
|
||||
)
|
||||
|
||||
return render_http_error(
|
||||
404,
|
||||
"Страница не найдена",
|
||||
"Запрошенная страница не существует или была перемещена."
|
||||
)
|
||||
|
||||
|
||||
@app.errorhandler(403)
|
||||
def access_forbidden(error):
|
||||
logger.warning(
|
||||
"HTTP 403 method=%s path=%s",
|
||||
request.method,
|
||||
request.path
|
||||
)
|
||||
|
||||
return render_http_error(
|
||||
403,
|
||||
"Доступ запрещён",
|
||||
"У вас нет разрешения на выполнение этого действия."
|
||||
)
|
||||
|
||||
|
||||
@app.errorhandler(405)
|
||||
def method_not_allowed(error):
|
||||
logger.warning(
|
||||
"HTTP 405 method=%s path=%s",
|
||||
request.method,
|
||||
request.path
|
||||
)
|
||||
|
||||
return render_http_error(
|
||||
405,
|
||||
"Действие недоступно",
|
||||
"Этот способ обращения к странице не поддерживается."
|
||||
)
|
||||
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(error):
|
||||
original_exception = getattr(
|
||||
error,
|
||||
"original_exception",
|
||||
None
|
||||
)
|
||||
|
||||
if original_exception is not None:
|
||||
logger.error(
|
||||
"Unhandled exception method=%s path=%s",
|
||||
request.method,
|
||||
request.path,
|
||||
exc_info=(
|
||||
type(original_exception),
|
||||
original_exception,
|
||||
original_exception.__traceback__
|
||||
)
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
"HTTP 500 method=%s path=%s",
|
||||
request.method,
|
||||
request.path
|
||||
)
|
||||
|
||||
return render_http_error(
|
||||
500,
|
||||
"Что-то пошло не так",
|
||||
"Во время обработки запроса произошла ошибка. Попробуйте позже."
|
||||
)
|
||||
|
||||
@app.before_request
|
||||
def scanner_navigation_guard():
|
||||
|
||||
@@ -90,6 +198,9 @@ def scanner_navigation_guard():
|
||||
if not status["running"]:
|
||||
return None
|
||||
|
||||
if request.endpoint is None:
|
||||
return None
|
||||
|
||||
if (
|
||||
request.endpoint is not None
|
||||
and request.endpoint.startswith("cracklab.")
|
||||
@@ -1680,249 +1791,13 @@ def reports_access_point(bssid):
|
||||
bssid
|
||||
)
|
||||
|
||||
@app.route("/reports/hashcat/")
|
||||
def reports_hashcat():
|
||||
@app.route("/reports/hashcat/", methods=["GET", "POST"])
|
||||
@app.route("/reports/hashcat/export", methods=["GET", "POST"])
|
||||
@app.route("/reports/hashcat/preflight", methods=["GET", "POST"])
|
||||
@app.route("/reports/hashcat/import", methods=["GET", "POST"])
|
||||
def reports_hashcat_gone():
|
||||
|
||||
return render_report(
|
||||
render_hashcat_page
|
||||
)
|
||||
|
||||
|
||||
@app.route("/reports/hashcat/export")
|
||||
def reports_hashcat_export():
|
||||
|
||||
vendor = request.args.get(
|
||||
"vendor",
|
||||
""
|
||||
).strip()
|
||||
|
||||
conn = connect_database()
|
||||
|
||||
try:
|
||||
|
||||
if vendor:
|
||||
|
||||
criteria = normalize_criteria(
|
||||
vendor=vendor
|
||||
)
|
||||
|
||||
if not criteria:
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error":
|
||||
"At least one search criterion "
|
||||
"is required."
|
||||
}
|
||||
), 400
|
||||
|
||||
content = build_hash_export(
|
||||
conn,
|
||||
criteria
|
||||
)
|
||||
|
||||
filename = build_export_filename(
|
||||
"search",
|
||||
vendor
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
content = build_all_hash_export(
|
||||
conn
|
||||
)
|
||||
|
||||
filename = build_export_filename(
|
||||
"all"
|
||||
)
|
||||
|
||||
return Response(
|
||||
content,
|
||||
mimetype="text/plain",
|
||||
headers={
|
||||
"Content-Disposition":
|
||||
f'attachment; filename="{filename}"'
|
||||
}
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error": str(error)
|
||||
}
|
||||
), 500
|
||||
|
||||
finally:
|
||||
|
||||
close_database(conn)
|
||||
|
||||
@app.route(
|
||||
"/reports/hashcat/preflight",
|
||||
methods=["POST"]
|
||||
)
|
||||
def reports_hashcat_preflight():
|
||||
|
||||
uploaded_file = request.files.get(
|
||||
"hashcat_file"
|
||||
)
|
||||
|
||||
if uploaded_file is None:
|
||||
return jsonify(
|
||||
{
|
||||
"valid": False,
|
||||
"error":
|
||||
"Hashcat result file is required."
|
||||
}
|
||||
), 400
|
||||
|
||||
try:
|
||||
content = uploaded_file.read().decode(
|
||||
"utf-8"
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
return jsonify(
|
||||
{
|
||||
"valid": False,
|
||||
"error":
|
||||
"Hashcat result file must be "
|
||||
"valid UTF-8 text."
|
||||
}
|
||||
), 400
|
||||
|
||||
from reports.hashcat import (
|
||||
validate_hashcat_show_file,
|
||||
)
|
||||
|
||||
conn = connect_database()
|
||||
|
||||
try:
|
||||
|
||||
result = validate_hashcat_show_file(
|
||||
conn,
|
||||
content.splitlines(
|
||||
keepends=True
|
||||
)
|
||||
)
|
||||
|
||||
result["valid"] = (
|
||||
result["total_lines"] > 0
|
||||
and result["matched_handshakes"] > 0
|
||||
and result["invalid_lines"] == 0
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
result
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"valid": False,
|
||||
"error": str(error)
|
||||
}
|
||||
), 500
|
||||
|
||||
finally:
|
||||
|
||||
close_database(conn)
|
||||
|
||||
@app.route(
|
||||
"/reports/hashcat/import",
|
||||
methods=["POST"]
|
||||
)
|
||||
def reports_hashcat_import():
|
||||
|
||||
uploaded_file = request.files.get(
|
||||
"hashcat_file"
|
||||
)
|
||||
|
||||
if uploaded_file is None:
|
||||
return jsonify(
|
||||
{
|
||||
"error":
|
||||
"Hashcat result file is required."
|
||||
}
|
||||
), 400
|
||||
|
||||
try:
|
||||
content = uploaded_file.read().decode(
|
||||
"utf-8"
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
return jsonify(
|
||||
{
|
||||
"error":
|
||||
"Hashcat result file must be "
|
||||
"valid UTF-8 text."
|
||||
}
|
||||
), 400
|
||||
|
||||
conn = connect_database()
|
||||
|
||||
try:
|
||||
|
||||
result = import_hashcat_show(
|
||||
conn,
|
||||
content.splitlines(
|
||||
keepends=True
|
||||
)
|
||||
)
|
||||
|
||||
if result["errors"]:
|
||||
|
||||
html = render_hashcat_page(
|
||||
conn,
|
||||
context=ReportContext(
|
||||
mode="server"
|
||||
),
|
||||
import_result=result,
|
||||
message={
|
||||
"type": "error",
|
||||
"text": (
|
||||
"Import was rejected. "
|
||||
"No credentials were committed."
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
return Response(
|
||||
html,
|
||||
mimetype="text/html",
|
||||
status=400
|
||||
)
|
||||
|
||||
html = render_hashcat_page(
|
||||
conn,
|
||||
context=ReportContext(
|
||||
mode="server"
|
||||
),
|
||||
import_result=result,
|
||||
message={
|
||||
"type": "success",
|
||||
"text": (
|
||||
"Import completed successfully."
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
return Response(
|
||||
html,
|
||||
mimetype="text/html"
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"error": str(error)
|
||||
}
|
||||
), 500
|
||||
|
||||
finally:
|
||||
|
||||
close_database(conn)
|
||||
abort(404)
|
||||
|
||||
@app.route("/reports/search/")
|
||||
def reports_search():
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>{{ status_code }} — {{ title }} | WiFi GPS Mapper</title>
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ url_for('static', filename='style.css') }}"
|
||||
>
|
||||
|
||||
<style>
|
||||
.error-page {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.error-card {
|
||||
width: min(100%, 620px);
|
||||
padding: 36px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
margin: 0 0 18px;
|
||||
color: var(--accent);
|
||||
font-size: clamp(48px, 10vw, 88px);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
margin: 0 0 12px;
|
||||
font-size: clamp(24px, 4vw, 32px);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
margin: 0 0 28px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.error-home {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 10px 18px;
|
||||
border-radius: 5px;
|
||||
background: var(--green);
|
||||
color: var(--bg);
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.error-home:hover {
|
||||
filter: brightness(1.08);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="error-page">
|
||||
<section class="error-card">
|
||||
<p class="error-code">{{ status_code }}</p>
|
||||
|
||||
<h1 class="error-title">{{ title }}</h1>
|
||||
|
||||
<p class="error-message">{{ message }}</p>
|
||||
|
||||
<a
|
||||
class="error-home"
|
||||
href="{{ url_for('index') }}"
|
||||
>Вернуться на главную</a>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
+3
-3
@@ -269,9 +269,9 @@ def navigation(
|
||||
),
|
||||
|
||||
(
|
||||
"hashcat",
|
||||
"Hashes",
|
||||
"/reports/hashcat/",
|
||||
"cracklab",
|
||||
"CrackLab",
|
||||
"/cracklab/",
|
||||
),
|
||||
|
||||
]
|
||||
|
||||
+9
-27
@@ -1,52 +1,34 @@
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
def setup_logger():
|
||||
log_dir = Path(__file__).resolve().parent.parent / "logs"
|
||||
|
||||
|
||||
Path(
|
||||
"logs"
|
||||
).mkdir(
|
||||
log_dir.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True
|
||||
)
|
||||
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
|
||||
|
||||
level=logging.INFO,
|
||||
|
||||
|
||||
format=(
|
||||
|
||||
"%(asctime)s "
|
||||
"[%(levelname)s] "
|
||||
"%(name)s: "
|
||||
"%(message)s"
|
||||
|
||||
),
|
||||
|
||||
|
||||
handlers=[
|
||||
|
||||
|
||||
logging.FileHandler(
|
||||
"logs/project.log"
|
||||
RotatingFileHandler(
|
||||
log_dir / "project.log",
|
||||
maxBytes=5 * 1024 * 1024,
|
||||
backupCount=3,
|
||||
encoding="utf-8"
|
||||
),
|
||||
|
||||
|
||||
logging.StreamHandler()
|
||||
|
||||
]
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
return logging.getLogger(
|
||||
"project-wifi"
|
||||
)
|
||||
Reference in New Issue
Block a user