diff --git a/cracklab/server/services/job_issuance.py b/cracklab/server/services/job_issuance.py index 9a48faa..abd9d4b 100644 --- a/cracklab/server/services/job_issuance.py +++ b/cracklab/server/services/job_issuance.py @@ -17,7 +17,6 @@ from cracklab.server.services.method_definition import ( validate_method_definition, ) from cracklab.server.services.search_context import ( - SearchContextError, SearchContextService, ) diff --git a/cracklab/server/web/routes.py b/cracklab/server/web/routes.py index 898d4ae..e37d431 100644 --- a/cracklab/server/web/routes.py +++ b/cracklab/server/web/routes.py @@ -181,28 +181,53 @@ def jobs_page(): "limited", ) - if issue_mode == "all": - limit = None - else: - limit_raw = request.form.get( - "limit", - "100", - ).strip() + if issue_mode == "search": - try: - limit = int(limit_raw) - except ValueError as exc: + if not search_context_token: raise JobIssuanceError( - "Количество handshakes должно быть целым числом." - ) from exc + "Search context is missing. Return to Search " + "and export the results again." + ) - issued_job = issuance_service.issue_job( - method_id=selected_method_id, - method_version=selected_version, - limit=limit, - ) + issued_job = ( + issuance_service.issue_job_from_search_context( + token=search_context_token, + method_id=selected_method_id, + method_version=selected_version, + ) + ) + + else: + + if issue_mode == "all": + limit = None + else: + limit_raw = request.form.get( + "limit", + "100", + ).strip() + + try: + limit = int(limit_raw) + except ValueError as exc: + raise JobIssuanceError( + "Количество handshakes должно быть целым числом." + ) from exc + + issued_job = issuance_service.issue_job( + method_id=selected_method_id, + method_version=selected_version, + limit=limit, + ) if issued_job is None: + + if issue_mode == "search": + raise JobIssuanceError( + "No handshakes from Search results are available " + "for the selected method and version." + ) + raise JobIssuanceError( "Нет handshakes, доступных для нового job." ) diff --git a/cracklab/server/web/templates/jobs.html b/cracklab/server/web/templates/jobs.html index 7926d15..33204e5 100644 --- a/cracklab/server/web/templates/jobs.html +++ b/cracklab/server/web/templates/jobs.html @@ -105,6 +105,10 @@
+

Standard issuance

+

+ Выдача доступных рукопожатий из всей базы CrackLab. +

- Found by Search + Handshakes found by Search
@@ -202,6 +206,15 @@ +
+
+ {{ search_statistics["matched_count"] - search_statistics["available_count"] }} +
+
+ Skipped +
+
+
{{ search_statistics["found_count"] }} @@ -239,6 +252,35 @@
{% endif %} + + + + + + + + + {% endif %} {% endif %} diff --git a/gui/app.py b/gui/app.py index 3aff96c..94207ce 100644 --- a/gui/app.py +++ b/gui/app.py @@ -40,11 +40,16 @@ from reports.dashboard import ( generate_dashboard, ) from cracklab.server.web import cracklab_bp +from cracklab.server.db.connection import ( + connect_database as connect_cracklab_database, +) +from cracklab.server.services.search_context import SearchContextService from reports.search import ( - build_hash_export, build_search_data, + load_handshakes, normalize_criteria, render_search_page, + search_access_points, ) from reports.hashcat import ( build_all_hash_export, @@ -1888,11 +1893,14 @@ def reports_search_data(): close_database(conn) -@app.route("/reports/search/export") -def reports_search_export(): +@app.route( + "/reports/search/cracklab", + methods=["POST"], +) +def reports_search_cracklab(): criteria = normalize_criteria( - vendor=request.args.get( + vendor=request.form.get( "vendor", "" ) @@ -1907,34 +1915,67 @@ def reports_search_export(): } ), 400 - conn = connect_database() + reports_conn = connect_database() + cracklab_conn = None try: - content = build_hash_export( - conn, + access_points = search_access_points( + reports_conn, criteria ) - filename = build_export_filename( - "search", - request.args.get( - "vendor", - "" - ) + handshakes = load_handshakes( + reports_conn, + criteria ) - return Response( - content, - mimetype="text/plain", - headers={ - "Content-Disposition": - f'attachment; filename="{filename}"' + handshake_ids = [ + int(handshake["id"]) + for items in handshakes.values() + for handshake in items + ] + + if not handshake_ids: + + return jsonify( + { + "error": + "Search results contain no handshakes or PMKID records." + } + ), 400 + + cracklab_conn = connect_cracklab_database() + + context = SearchContextService( + cracklab_conn + ).create_context( + criteria=criteria, + handshake_ids=handshake_ids, + matched_access_point_count=len(access_points), + ) + + return jsonify( + { + "redirect_url": url_for( + "cracklab.jobs_page", + search_context_token=context["token"], + ), + "matched_access_point_count": + context["matched_access_point_count"], + "handshake_count": + context["handshake_count"], + "expires_at": + context["expires_at"], } ) except Exception as error: + logger.exception( + "Failed to create CrackLab search context." + ) + return jsonify( { "error": str(error) @@ -1943,7 +1984,10 @@ def reports_search_export(): finally: - close_database(conn) + close_database(reports_conn) + + if cracklab_conn is not None: + cracklab_conn.close() @app.route("/reports/static/") diff --git a/reports/search.py b/reports/search.py index 3236b4a..17acf4b 100644 --- a/reports/search.py +++ b/reports/search.py @@ -1018,6 +1018,11 @@ def build_search_data( ) ) + handshake_count = sum( + len(items) + for items in handshakes.values() + ) + matching_vendors = ( get_matching_vendors( conn, @@ -1037,6 +1042,7 @@ def build_search_data( password_access_points, "handshake_access_points": handshake_access_points, + "handshake_count": handshake_count, "hash_count": len(hashes), "matching_vendors": matching_vendors, @@ -1231,7 +1237,7 @@ def render_search_page( class="button" disabled > - Export hashes + Экспорт в CrackLab @@ -1828,18 +1834,51 @@ def render_search_page( exportButton.addEventListener( "click", - () => { + async () => { if (!searchParams) { return; } - const url = - "/reports/search/export?" - + - searchParams.toString(); + exportButton.disabled = true; - window.location.href = url; + try { + + const response = await fetch( + "/reports/search/cracklab", + { + method: "POST", + headers: { + "Content-Type": + "application/x-www-form-urlencoded" + }, + body: searchParams.toString() + } + ); + + const data = await response.json(); + + if (!response.ok) { + throw new Error( + data.error || "CrackLab export failed." + ); + } + + if (!data.redirect_url) { + throw new Error( + "CrackLab did not return a destination URL." + ); + } + + window.location.href = data.redirect_url; + + } catch (error) { + + setStatus(error.message); + + exportButton.disabled = false; + + } } ); @@ -2041,7 +2080,7 @@ def render_search_page( } exportButton.disabled = - data.hash_count === 0; + data.handshake_count === 0; createMap( data.geojson