quck
This commit is contained in:
@@ -25,7 +25,13 @@ if ($path === '') {
|
|||||||
switch ($path) {
|
switch ($path) {
|
||||||
case '/quickcheck':
|
case '/quickcheck':
|
||||||
require __DIR__ . '/target/quickcheck.php';
|
require __DIR__ . '/target/quickcheck.php';
|
||||||
$result = quickcheck_handle_request(); // Funktion in quickcheck.php
|
$result = quickcheck_handle_request();
|
||||||
|
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '/browser.quick.test':
|
||||||
|
require __DIR__ . '/target/browser.quick.test.php';
|
||||||
|
$result = browser_quick_test_handle_request();
|
||||||
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ declare(strict_types=1);
|
|||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// DB einbinden – bitte Pfad an DEINE Struktur anpassen!
|
// DB einbinden – bitte Pfad an DEINE Struktur anpassen!
|
||||||
require $_SERVER['DOCUMENT_ROOT']. '/../config/db.php'; // z.B. stellt $pdo (PDO) bereit
|
require $_SERVER['DOCUMENT_ROOT']. '/../config/fileload.php'; // z.B. stellt $pdo (PDO) bereit
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
|||||||
155
api/target/browser.quick.test.php
Normal file
155
api/target/browser.quick.test.php
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
// /api/target/browser.quick.test.php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
function browser_quick_test_handle_request(): array
|
||||||
|
{
|
||||||
|
// 1. JSON einlesen
|
||||||
|
$raw = file_get_contents('php://input');
|
||||||
|
$data = json_decode($raw, true);
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
http_response_code(400);
|
||||||
|
return [
|
||||||
|
'ok' => false,
|
||||||
|
'error' => 'Invalid JSON payload',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Session / User
|
||||||
|
// (falls index.php evtl. schon session_start() macht, ist das idempotent)
|
||||||
|
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
$userId = $_SESSION['user_id'] ?? null;
|
||||||
|
$isLoggedIn = $userId ? 1 : 0;
|
||||||
|
$sessionId = session_id() ?: null;
|
||||||
|
|
||||||
|
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? null;
|
||||||
|
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
|
||||||
|
|
||||||
|
// 3. DB-Verbindung
|
||||||
|
// Dokumentroot der API-Subdomain zeigt auf /api,
|
||||||
|
// config liegt ein Level darüber: /config/db.php
|
||||||
|
require $_SERVER['DOCUMENT_ROOT'] . '/../config/db.php'; // $pdo
|
||||||
|
|
||||||
|
if ($pdo instanceof PDO) {
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Werte aus dem Report aggregieren (minimal)
|
||||||
|
$measuredBytes = 0;
|
||||||
|
|
||||||
|
if (!empty($data['quick']) && is_array($data['quick'])) {
|
||||||
|
$measuredBytes += (int)($data['quick']['size_bytes'] ?? 0);
|
||||||
|
}
|
||||||
|
if (!empty($data['benchmark']) && is_array($data['benchmark'])) {
|
||||||
|
$measuredBytes += (int)($data['benchmark']['size_bytes'] ?? 0);
|
||||||
|
}
|
||||||
|
if (!empty($data['writeverify']) && is_array($data['writeverify'])) {
|
||||||
|
$measuredBytes += (int)($data['writeverify']['total_bytes'] ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Browser/OS & Stick-Infos – erstmal noch leer, später aus meta/parsing füllen
|
||||||
|
$browserName = null;
|
||||||
|
$browserVersion = null;
|
||||||
|
$osName = null;
|
||||||
|
$osVersion = null;
|
||||||
|
|
||||||
|
$volumeLabel = null;
|
||||||
|
$manufacturer = null;
|
||||||
|
$modelName = null;
|
||||||
|
$usbType = null;
|
||||||
|
$filesystem = null;
|
||||||
|
|
||||||
|
$advCapacityBytes = null;
|
||||||
|
$capacityStatus = 'unknown';
|
||||||
|
|
||||||
|
// Kompletten Report als JSON-String speichern
|
||||||
|
$testReportJson = $raw;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$sql = "
|
||||||
|
INSERT INTO web_quicktests (
|
||||||
|
user_id,
|
||||||
|
is_logged_in,
|
||||||
|
usb_device_id,
|
||||||
|
browser_name,
|
||||||
|
browser_version,
|
||||||
|
os_name,
|
||||||
|
os_version,
|
||||||
|
volume_label,
|
||||||
|
manufacturer,
|
||||||
|
model_name,
|
||||||
|
usb_type,
|
||||||
|
advertised_capacity_bytes,
|
||||||
|
measured_capacity_bytes,
|
||||||
|
capacity_status,
|
||||||
|
filesystem,
|
||||||
|
test_report_json,
|
||||||
|
ip_address,
|
||||||
|
session_id
|
||||||
|
) VALUES (
|
||||||
|
:user_id,
|
||||||
|
:is_logged_in,
|
||||||
|
:usb_device_id,
|
||||||
|
:browser_name,
|
||||||
|
:browser_version,
|
||||||
|
:os_name,
|
||||||
|
:os_version,
|
||||||
|
:volume_label,
|
||||||
|
:manufacturer,
|
||||||
|
:model_name,
|
||||||
|
:usb_type,
|
||||||
|
:adv_capacity,
|
||||||
|
:measured_capacity,
|
||||||
|
:capacity_status,
|
||||||
|
:filesystem,
|
||||||
|
:test_report_json,
|
||||||
|
:ip_address,
|
||||||
|
:session_id
|
||||||
|
)
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
|
||||||
|
$ok = $stmt->execute([
|
||||||
|
'user_id' => $userId,
|
||||||
|
'is_logged_in' => $isLoggedIn,
|
||||||
|
'usb_device_id' => null,
|
||||||
|
'browser_name' => $browserName,
|
||||||
|
'browser_version' => $browserVersion,
|
||||||
|
'os_name' => $osName,
|
||||||
|
'os_version' => $osVersion,
|
||||||
|
'volume_label' => $volumeLabel,
|
||||||
|
'manufacturer' => $manufacturer,
|
||||||
|
'model_name' => $modelName,
|
||||||
|
'usb_type' => $usbType,
|
||||||
|
'adv_capacity' => $advCapacityBytes,
|
||||||
|
'measured_capacity' => $measuredBytes ?: null,
|
||||||
|
'capacity_status' => $capacityStatus,
|
||||||
|
'filesystem' => $filesystem,
|
||||||
|
'test_report_json' => $testReportJson,
|
||||||
|
'ip_address' => $ipAddress,
|
||||||
|
'session_id' => $sessionId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$ok) {
|
||||||
|
$info = $stmt->errorInfo();
|
||||||
|
throw new RuntimeException($info[2] ?? 'Unknown DB error during insert');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ok' => true,
|
||||||
|
'id' => (int)$pdo->lastInsertId(),
|
||||||
|
];
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
return [
|
||||||
|
'ok' => false,
|
||||||
|
'error' => 'DB error: ' . $e->getMessage(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -885,7 +885,12 @@
|
|||||||
// --- Backend-Speicherung ------------------------------------------------
|
// --- Backend-Speicherung ------------------------------------------------
|
||||||
|
|
||||||
async function saveReportToBackend(report) {
|
async function saveReportToBackend(report) {
|
||||||
const url = "/api/result/browser-quick-test.php";
|
// apiBase kommt aus fakecheck.core.js (detectApiBase)
|
||||||
|
const apiBase = (cfg && cfg.apiBase) ? cfg.apiBase : "";
|
||||||
|
const base = apiBase.replace(/\/+$/, "");
|
||||||
|
// Fallback: falls apiBase aus irgendeinem Grund leer ist, lokal auf /api routen
|
||||||
|
const url = base ? (base + "/browser.quick.test") : "/api/browser.quick.test";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -913,6 +918,24 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json().catch(() => null);
|
const data = await response.json().catch(() => null);
|
||||||
|
|
||||||
|
if (!data || data.ok !== true) {
|
||||||
|
logLine(
|
||||||
|
tFmt(
|
||||||
|
"fake_ui.log_backend_save_error_payload",
|
||||||
|
"Backend: Testergebnis wurde nicht bestätigt{suffix}.",
|
||||||
|
{
|
||||||
|
suffix: data && data.error
|
||||||
|
? ` (${data.error})`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"warn"
|
||||||
|
);
|
||||||
|
if (saveError) saveError.style.display = "block";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logLine(
|
logLine(
|
||||||
tFmt(
|
tFmt(
|
||||||
"fake_ui.log_backend_save_ok",
|
"fake_ui.log_backend_save_ok",
|
||||||
|
|||||||
Reference in New Issue
Block a user