Update public source
This commit is contained in:
@@ -56,3 +56,83 @@ class HandshakesRepository:
|
||||
limit,
|
||||
),
|
||||
).fetchall()
|
||||
|
||||
def get_method_statistics(
|
||||
self,
|
||||
method_id: str,
|
||||
method_version: int,
|
||||
) -> sqlite3.Row:
|
||||
return self._conn.execute(
|
||||
"""
|
||||
SELECT
|
||||
COUNT(*) AS total_count,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM credentials AS c
|
||||
WHERE c.handshake_id = h.id
|
||||
)
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
) AS found_count,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM credentials AS c
|
||||
WHERE c.handshake_id = h.id
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM crack_attempts AS a
|
||||
WHERE a.handshake_id = h.id
|
||||
AND a.method_id = ?
|
||||
AND a.method_version = ?
|
||||
AND a.status = 'COMPLETED'
|
||||
)
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
) AS covered_count,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM credentials AS c
|
||||
WHERE c.handshake_id = h.id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM crack_attempts AS a
|
||||
WHERE a.handshake_id = h.id
|
||||
AND a.method_id = ?
|
||||
AND a.method_version = ?
|
||||
AND a.status = 'COMPLETED'
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM crack_reservations AS r
|
||||
WHERE r.handshake_id = h.id
|
||||
AND r.method_id = ?
|
||||
AND r.method_version = ?
|
||||
AND r.status = 'ACTIVE'
|
||||
)
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
) AS reserved_count
|
||||
FROM handshakes AS h
|
||||
WHERE h.hash22000 IS NOT NULL
|
||||
AND TRIM(h.hash22000) <> ''
|
||||
""",
|
||||
(
|
||||
method_id,
|
||||
method_version,
|
||||
method_id,
|
||||
method_version,
|
||||
method_id,
|
||||
method_version,
|
||||
),
|
||||
).fetchone()
|
||||
|
||||
@@ -48,6 +48,34 @@ class JobIssuanceService:
|
||||
self._reservations = ReservationsRepository(conn)
|
||||
self._audit = AuditRepository(conn)
|
||||
|
||||
def get_method_statistics(
|
||||
self,
|
||||
method_id: str,
|
||||
method_version: int,
|
||||
) -> dict[str, int]:
|
||||
row = self._handshakes.get_method_statistics(
|
||||
method_id,
|
||||
method_version,
|
||||
)
|
||||
|
||||
total_count = int(row["total_count"] or 0)
|
||||
found_count = int(row["found_count"] or 0)
|
||||
covered_count = int(row["covered_count"] or 0)
|
||||
reserved_count = int(row["reserved_count"] or 0)
|
||||
|
||||
return {
|
||||
"total_count": total_count,
|
||||
"found_count": found_count,
|
||||
"covered_count": covered_count,
|
||||
"reserved_count": reserved_count,
|
||||
"available_count": (
|
||||
total_count
|
||||
- found_count
|
||||
- covered_count
|
||||
- reserved_count
|
||||
),
|
||||
}
|
||||
|
||||
def issue_job(
|
||||
self,
|
||||
method_id: str,
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import json
|
||||
from collections import Counter
|
||||
|
||||
from flask import redirect, render_template, request, url_for
|
||||
from flask import after_this_request, redirect, render_template, request, send_file, url_for
|
||||
|
||||
from cracklab.server.db.connection import connect_database
|
||||
from cracklab.server.repositories.clients import ClientsRepository
|
||||
@@ -12,6 +16,12 @@ from cracklab.server.repositories.methods import MethodsRepository
|
||||
from cracklab.server.repositories.results import ResultsRepository
|
||||
from cracklab.server.services.methods import MethodService, MethodServiceError
|
||||
|
||||
from cracklab.server.services.job_export import JobExportService
|
||||
from cracklab.server.services.job_issuance import (
|
||||
JobIssuanceError,
|
||||
JobIssuanceService,
|
||||
)
|
||||
|
||||
from cracklab.server.web import cracklab_bp
|
||||
|
||||
|
||||
@@ -67,14 +77,234 @@ def dashboard():
|
||||
)
|
||||
|
||||
|
||||
@cracklab_bp.route("/jobs/")
|
||||
@cracklab_bp.route("/jobs/", methods=["GET", "POST"])
|
||||
def jobs_page():
|
||||
return _placeholder(
|
||||
"Jobs",
|
||||
"Job management will be implemented here.",
|
||||
"jobs",
|
||||
error = None
|
||||
created_job_id = request.args.get("created")
|
||||
|
||||
conn = connect_database()
|
||||
|
||||
try:
|
||||
method_service = MethodService(conn)
|
||||
issuance_service = JobIssuanceService(conn)
|
||||
jobs_repository = JobsRepository(conn)
|
||||
|
||||
methods = method_service.list_methods()
|
||||
|
||||
method_versions = {}
|
||||
|
||||
for method in methods:
|
||||
method_versions[method["id"]] = (
|
||||
method_service.list_method_versions(
|
||||
method["id"],
|
||||
)
|
||||
)
|
||||
|
||||
selected_method_id = request.values.get(
|
||||
"method_id",
|
||||
"",
|
||||
).strip()
|
||||
|
||||
selected_version_raw = request.values.get(
|
||||
"method_version",
|
||||
"",
|
||||
).strip()
|
||||
|
||||
if not selected_method_id and methods:
|
||||
selected_method_id = methods[0]["id"]
|
||||
|
||||
selected_versions = method_versions.get(
|
||||
selected_method_id,
|
||||
[],
|
||||
)
|
||||
|
||||
if not selected_version_raw and selected_versions:
|
||||
selected_version_raw = str(
|
||||
selected_versions[-1]["version"]
|
||||
)
|
||||
|
||||
selected_version = None
|
||||
|
||||
if selected_version_raw:
|
||||
try:
|
||||
selected_version = int(selected_version_raw)
|
||||
except ValueError:
|
||||
selected_version = None
|
||||
|
||||
if request.method == "POST":
|
||||
if not selected_method_id:
|
||||
raise JobIssuanceError(
|
||||
"Выберите метод."
|
||||
)
|
||||
|
||||
if selected_version is None:
|
||||
raise JobIssuanceError(
|
||||
"Выберите версию метода."
|
||||
)
|
||||
|
||||
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:
|
||||
raise JobIssuanceError(
|
||||
"Нет handshakes, доступных для нового job."
|
||||
)
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
"cracklab.jobs_page",
|
||||
method_id=selected_method_id,
|
||||
method_version=selected_version,
|
||||
created=issued_job.job_id,
|
||||
)
|
||||
)
|
||||
|
||||
statistics = None
|
||||
|
||||
if (
|
||||
selected_method_id
|
||||
and selected_version is not None
|
||||
):
|
||||
statistics = issuance_service.get_method_statistics(
|
||||
selected_method_id,
|
||||
selected_version,
|
||||
)
|
||||
|
||||
active_jobs = jobs_repository.list_jobs()
|
||||
|
||||
active_jobs = [
|
||||
job
|
||||
for job in active_jobs
|
||||
if job["status"] in {
|
||||
"CREATED",
|
||||
"QUEUED",
|
||||
"RUNNING",
|
||||
"PARTIAL",
|
||||
}
|
||||
]
|
||||
|
||||
method_names = {
|
||||
method["id"]: method["name"]
|
||||
for method in methods
|
||||
}
|
||||
|
||||
return render_template(
|
||||
"jobs.html",
|
||||
active_page="jobs",
|
||||
methods=methods,
|
||||
method_versions=method_versions,
|
||||
selected_method_id=selected_method_id,
|
||||
selected_version=selected_version,
|
||||
statistics=statistics,
|
||||
active_jobs=active_jobs,
|
||||
method_names=method_names,
|
||||
created_job_id=created_job_id,
|
||||
error=error,
|
||||
)
|
||||
|
||||
except (JobIssuanceError, ValueError) as exc:
|
||||
error = str(exc)
|
||||
|
||||
statistics = None
|
||||
|
||||
if (
|
||||
selected_method_id
|
||||
and selected_version is not None
|
||||
):
|
||||
statistics = issuance_service.get_method_statistics(
|
||||
selected_method_id,
|
||||
selected_version,
|
||||
)
|
||||
|
||||
active_jobs = jobs_repository.list_jobs()
|
||||
|
||||
active_jobs = [
|
||||
job
|
||||
for job in active_jobs
|
||||
if job["status"] in {
|
||||
"CREATED",
|
||||
"QUEUED",
|
||||
"RUNNING",
|
||||
"PARTIAL",
|
||||
}
|
||||
]
|
||||
|
||||
method_names = {
|
||||
method["id"]: method["name"]
|
||||
for method in methods
|
||||
}
|
||||
|
||||
return render_template(
|
||||
"jobs.html",
|
||||
active_page="jobs",
|
||||
methods=methods,
|
||||
method_versions=method_versions,
|
||||
selected_method_id=selected_method_id,
|
||||
selected_version=selected_version,
|
||||
statistics=statistics,
|
||||
active_jobs=active_jobs,
|
||||
method_names=method_names,
|
||||
created_job_id=created_job_id,
|
||||
error=error,
|
||||
)
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@cracklab_bp.route("/jobs/<job_id>/download/")
|
||||
def job_download(job_id: str):
|
||||
conn = connect_database()
|
||||
temporary_dir = Path(
|
||||
tempfile.mkdtemp(
|
||||
prefix="cracklab-job-",
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
export_service = JobExportService(conn)
|
||||
output_path = export_service.export_job(
|
||||
job_id,
|
||||
temporary_dir,
|
||||
)
|
||||
except Exception:
|
||||
shutil.rmtree(
|
||||
temporary_dir,
|
||||
ignore_errors=True,
|
||||
)
|
||||
conn.close()
|
||||
raise
|
||||
|
||||
conn.close()
|
||||
|
||||
@after_this_request
|
||||
def cleanup(response):
|
||||
shutil.rmtree(
|
||||
temporary_dir,
|
||||
ignore_errors=True,
|
||||
)
|
||||
return response
|
||||
|
||||
return send_file(
|
||||
output_path,
|
||||
as_attachment=True,
|
||||
download_name=output_path.name,
|
||||
mimetype="application/zip",
|
||||
)
|
||||
|
||||
@cracklab_bp.route("/methods/")
|
||||
def methods_page():
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}CrackLab — Jobs{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="jobs-page">
|
||||
|
||||
<div class="jobs-page-header">
|
||||
<div>
|
||||
<h1 class="page-title">Jobs</h1>
|
||||
<p class="page-description">
|
||||
Формирование заданий для CrackLab-клиентов.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if error %}
|
||||
<div class="jobs-message jobs-message-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if created_job_id %}
|
||||
<div class="jobs-message jobs-message-success">
|
||||
Job <strong>{{ created_job_id }}</strong> сформирован.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card">
|
||||
<h2>New Job</h2>
|
||||
|
||||
<form method="post" class="jobs-form">
|
||||
|
||||
<div class="jobs-form-row">
|
||||
<label for="method_id">Method</label>
|
||||
|
||||
<select
|
||||
id="method_id"
|
||||
name="method_id"
|
||||
onchange="this.form.submit()"
|
||||
>
|
||||
{% for method in methods %}
|
||||
{% for version in method_versions[method["id"]] %}
|
||||
<option
|
||||
value="{{ method["id"] }}"
|
||||
data-version="{{ version["version"] }}"
|
||||
{% if selected_method_id == method["id"] and selected_version == version["version"] %}selected{% endif %}
|
||||
>
|
||||
{{ method["name"] }} — v{{ version["version"] }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="hidden"
|
||||
name="method_version"
|
||||
id="method_version"
|
||||
value="{{ selected_version or '' }}"
|
||||
>
|
||||
</div>
|
||||
|
||||
{% if statistics %}
|
||||
<div class="jobs-stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">
|
||||
{{ statistics["total_count"] }}
|
||||
</div>
|
||||
<div class="stat-title">
|
||||
Handshakes
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">
|
||||
{{ statistics["found_count"] }}
|
||||
</div>
|
||||
<div class="stat-title">
|
||||
Password Found
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">
|
||||
{{ statistics["covered_count"] }}
|
||||
</div>
|
||||
<div class="stat-title">
|
||||
Covered
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">
|
||||
{{ statistics["reserved_count"] }}
|
||||
</div>
|
||||
<div class="stat-title">
|
||||
Reserved
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card jobs-stat-available">
|
||||
<div class="stat-value">
|
||||
{{ statistics["available_count"] }}
|
||||
</div>
|
||||
<div class="stat-title">
|
||||
Available
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="jobs-form-row">
|
||||
<label for="limit">Handshakes in job</label>
|
||||
|
||||
<input
|
||||
id="limit"
|
||||
name="limit"
|
||||
type="number"
|
||||
min="1"
|
||||
value="{{ request.form.get('limit', 100) }}"
|
||||
>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="methods-button"
|
||||
>
|
||||
Form Job
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Issued Jobs</h2>
|
||||
|
||||
{% if active_jobs %}
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Job</th>
|
||||
<th>Method</th>
|
||||
<th>Hashes</th>
|
||||
<th>Created</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for job in active_jobs %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ job["id"] }}</strong>
|
||||
</td>
|
||||
<td>
|
||||
{{ method_names.get(job["method_id"], job["method_id"]) }}
|
||||
v{{ job["method_version"] }}
|
||||
</td>
|
||||
<td>{{ job["hash_count"] }}</td>
|
||||
<td>{{ job["created_at"] }}</td>
|
||||
<td>
|
||||
<span class="badge badge-{{ job["status"]|lower }}">
|
||||
{{ job["status"] }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a
|
||||
class="methods-button-secondary"
|
||||
href="{{ url_for('cracklab.job_download', job_id=job['id']) }}"
|
||||
>
|
||||
Download ZIP
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
No active jobs.
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const methodSelect = document.getElementById("method_id");
|
||||
const versionInput = document.getElementById("method_version");
|
||||
|
||||
if (methodSelect && versionInput) {
|
||||
methodSelect.addEventListener("change", function () {
|
||||
const option = this.options[this.selectedIndex];
|
||||
versionInput.value = option.dataset.version || "";
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user