From 4859398ccb2da95e4b4f63670d867845437b0079 Mon Sep 17 00:00:00 2001 From: dyzulk <66510723+dyzulk@users.noreply.github.com> Date: Thu, 8 Jan 2026 09:07:08 +0700 Subject: [PATCH] Feat: Add post-install telemetry ping (CORS enabled) --- app/Http/Controllers/Api/PublicCaController.php | 14 ++++++++++++++ app/Services/CaInstallerService.php | 6 ++++++ routes/api.php | 1 + 3 files changed, 21 insertions(+) diff --git a/app/Http/Controllers/Api/PublicCaController.php b/app/Http/Controllers/Api/PublicCaController.php index 26b3c1c..2e8ea88 100644 --- a/app/Http/Controllers/Api/PublicCaController.php +++ b/app/Http/Controllers/Api/PublicCaController.php @@ -162,4 +162,18 @@ class PublicCaController extends Controller 'Content-Disposition' => 'attachment; filename="' . $filename . '"', ]); } + /** + * Track download/installation count (Telemetry). + * Used by installer scripts to perform a "Ping" after successful installation. + */ + public function trackDownload($serial) + { + $cert = CaCertificate::where('serial_number', $serial)->firstOrFail(); + $cert->increment('download_count'); + $cert->update(['last_downloaded_at' => now()]); + + return response()->json(['success' => true]) + ->header('Access-Control-Allow-Origin', '*') + ->header('Access-Control-Allow-Methods', 'POST'); + } } diff --git a/app/Services/CaInstallerService.php b/app/Services/CaInstallerService.php index 9d89036..a5698a8 100644 --- a/app/Services/CaInstallerService.php +++ b/app/Services/CaInstallerService.php @@ -56,6 +56,8 @@ class CaInstallerService ")\r\n" . "call :printSuccess \"Certificate installed successfully!\"\r\n" . "\r\n" . + "powershell -Command \"Invoke-WebRequest -Uri 'https://pki.trustlab.local/api/public/ca-certificates/{$cert->serial_number}/track' -Method POST -ErrorAction SilentlyContinue\" >nul 2>&1\r\n" . + "\r\n" . "del \"%TEMP_CERT%\"\r\n" . "echo.\r\n" . "call :printInfo \"Press any key to close...\"\r\n" . @@ -202,6 +204,7 @@ class CaInstallerService "msg_info \"Updating certificate store...\"\n" . "if \$UPDATE_CMD >/dev/null 2>&1; then\n" . " msg_ok \"Store updated successfully.\"\n" . + " curl -X POST -s \"https://pki.trustlab.local/api/public/ca-certificates/{$cert->serial_number}/track\" >/dev/null 2>&1\n" . "else\n" . " msg_err \"Failed to update certificate store.\"\n" . " exit 1\n" . @@ -379,6 +382,8 @@ class CaInstallerService $shContent .= "msg_info \"Processing: {$cert->common_name}\"\n"; $shContent .= "curl -sL \"{$cdnUrl}\" -o \"\$TARGET_DIR/{$filename}\"\n"; + // Telemetry Ping (Silent) + $shContent .= "curl -X POST -s \"https://pki.trustlab.local/api/public/ca-certificates/{$cert->serial_number}/track\" >/dev/null 2>&1\n"; } $shContent .= "\nmsg_info \"Updating certificate store...\"\n" . @@ -418,6 +423,7 @@ class CaInstallerService "call :printAction \"Installing {$cert->common_name}...\"\r\n" . "powershell -Command \"Invoke-WebRequest -Uri '{$cdnUrl}' -OutFile '%TEMP_CERT%'\"\r\n" . "certutil -addstore -f \"{$store}\" \"%TEMP_CERT%\" >nul 2>&1\r\n" . + "powershell -Command \"Invoke-WebRequest -Uri 'https://pki.trustlab.local/api/public/ca-certificates/{$cert->serial_number}/track' -Method POST -ErrorAction SilentlyContinue\" >nul 2>&1\r\n" . "del \"%TEMP_CERT%\"\r\n"; } diff --git a/routes/api.php b/routes/api.php index ba79f57..e7810dd 100644 --- a/routes/api.php +++ b/routes/api.php @@ -25,6 +25,7 @@ Route::get('/public/ca-certificates/{serial}/download', [PublicCaController::cla Route::get('/public/ca-certificates/{serial}/download/windows', [PublicCaController::class, 'downloadWindows']); Route::get('/public/ca-certificates/{serial}/download/mac', [PublicCaController::class, 'downloadMac']); Route::get('/public/ca-certificates/{serial}/download/linux', [PublicCaController::class, 'downloadLinux']); +Route::post('/public/ca-certificates/{serial}/track', [PublicCaController::class, 'trackDownload']); Route::post('/public/inquiries', [\App\Http\Controllers\Api\InquiryController::class, 'store']); Route::get('/public/legal-pages', [\App\Http\Controllers\Api\LegalPageController::class, 'index']); Route::get('/public/legal-pages/{slug}', [\App\Http\Controllers\Api\LegalPageController::class, 'show']);