Update public source
This commit is contained in:
@@ -21,7 +21,10 @@ from cracklab.server.services.job_issuance import (
|
|||||||
JobIssuanceError,
|
JobIssuanceError,
|
||||||
JobIssuanceService,
|
JobIssuanceService,
|
||||||
)
|
)
|
||||||
|
from cracklab.server.services.job_result import (
|
||||||
|
JobResultError,
|
||||||
|
JobResultService,
|
||||||
|
)
|
||||||
from cracklab.server.web import cracklab_bp
|
from cracklab.server.web import cracklab_bp
|
||||||
|
|
||||||
|
|
||||||
@@ -726,12 +729,93 @@ def clients_page():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@cracklab_bp.route("/results/")
|
@cracklab_bp.route("/results/", methods=["GET", "POST"])
|
||||||
def results_page():
|
def results_page():
|
||||||
return _placeholder(
|
error = None
|
||||||
"Results",
|
message = None
|
||||||
"Result history will be implemented here.",
|
result_summary = None
|
||||||
"results",
|
|
||||||
|
if request.method == "POST":
|
||||||
|
uploaded_file = request.files.get("result_package")
|
||||||
|
|
||||||
|
if uploaded_file is None or not uploaded_file.filename:
|
||||||
|
error = "Select a result ZIP package."
|
||||||
|
elif not uploaded_file.filename.lower().endswith(".zip"):
|
||||||
|
error = "Only ZIP packages are accepted."
|
||||||
|
else:
|
||||||
|
temp_path = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
with tempfile.NamedTemporaryFile(
|
||||||
|
prefix="cracklab-result-",
|
||||||
|
suffix=".zip",
|
||||||
|
delete=False,
|
||||||
|
) as temp_file:
|
||||||
|
temp_path = Path(temp_file.name)
|
||||||
|
total_size = 0
|
||||||
|
max_size = 100 * 1024 * 1024
|
||||||
|
|
||||||
|
while True:
|
||||||
|
chunk = uploaded_file.stream.read(1024 * 1024)
|
||||||
|
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
|
||||||
|
total_size += len(chunk)
|
||||||
|
|
||||||
|
if total_size > max_size:
|
||||||
|
raise ValueError(
|
||||||
|
"The ZIP package exceeds the 100 MB limit."
|
||||||
|
)
|
||||||
|
|
||||||
|
temp_file.write(chunk)
|
||||||
|
|
||||||
|
conn = connect_database()
|
||||||
|
|
||||||
|
try:
|
||||||
|
result_summary = JobResultService(conn).import_result(
|
||||||
|
temp_path
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if result_summary["status"] == "ALREADY_IMPORTED":
|
||||||
|
message = (
|
||||||
|
f"Result for Job {result_summary['job_id']} "
|
||||||
|
"was already imported. No changes were made."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
message = (
|
||||||
|
f"Result for Job {result_summary['job_id']} "
|
||||||
|
"imported successfully."
|
||||||
|
)
|
||||||
|
|
||||||
|
except (JobResultError, ValueError) as exc:
|
||||||
|
error = str(exc)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
error = (
|
||||||
|
"The result package could not be imported because "
|
||||||
|
"of an internal error. Check the application logs."
|
||||||
|
)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
if temp_path is not None:
|
||||||
|
temp_path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
conn = connect_database()
|
||||||
|
|
||||||
|
try:
|
||||||
|
result_rows = ResultsRepository(conn).list_results()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"results.html",
|
||||||
|
active_page="results",
|
||||||
|
results=result_rows,
|
||||||
|
error=error,
|
||||||
|
message=message,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}CrackLab — Results{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="results-page">
|
||||||
|
|
||||||
|
<div class="jobs-page-header">
|
||||||
|
<div>
|
||||||
|
<h1 class="page-title">Results</h1>
|
||||||
|
<p class="page-description">
|
||||||
|
Import completed results from CrackLab clients and review import history.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
<div class="jobs-message jobs-message-error">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if message %}
|
||||||
|
<div class="jobs-message jobs-message-success">
|
||||||
|
{{ message }}
|
||||||
|
{% if result_summary and result_summary.status == "COMPLETED" %}
|
||||||
|
<div class="method-help">
|
||||||
|
Credentials imported: {{ result_summary.credentials_imported }}.
|
||||||
|
Already present: {{ result_summary.credentials_already_present }}.
|
||||||
|
Attempts completed: {{ result_summary.attempts_completed }}.
|
||||||
|
Reservations released: {{ result_summary.reservations_released }}.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>Import Result Package</h2>
|
||||||
|
|
||||||
|
<form method="post" enctype="multipart/form-data" class="jobs-form">
|
||||||
|
<div class="method-field">
|
||||||
|
<label for="result_package">Result ZIP package</label>
|
||||||
|
<input
|
||||||
|
id="result_package"
|
||||||
|
name="result_package"
|
||||||
|
type="file"
|
||||||
|
accept=".zip,application/zip"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<div class="method-help">
|
||||||
|
Select the ZIP package produced by a CrackLab client.
|
||||||
|
Maximum upload size: 100 MB.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="method-step-actions">
|
||||||
|
<button type="submit" class="methods-button">
|
||||||
|
Import Result
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>Import History</h2>
|
||||||
|
|
||||||
|
{% if results %}
|
||||||
|
<div class="table-container">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Job ID</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Imported At (UTC)</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for result in results %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ result["job_id"] }}</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge-completed">
|
||||||
|
{{ result["status"] }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>{{ result["imported_at"] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="empty-state">
|
||||||
|
No result packages have been imported yet.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user