diff --git a/license_manager/index.php b/license_manager/index.php index 0966cd6..da29ae4 100644 --- a/license_manager/index.php +++ b/license_manager/index.php @@ -17,6 +17,7 @@ if (strpos($request_uri, '/activate') !== false) $endpoint = 'activate'; if (strpos($request_uri, '/verify') !== false) $endpoint = 'verify'; if (strpos($request_uri, '/deactivate') !== false) $endpoint = 'deactivate'; if (strpos($request_uri, '/issue') !== false) $endpoint = 'issue'; +if (strpos($request_uri, '/list') !== false) $endpoint = 'list'; $input = json_decode(file_get_contents('php://input'), true); @@ -173,4 +174,28 @@ if ($endpoint === 'issue') { exit; } +if ($endpoint === 'list') { + // Basic security check (Optional: You can use the secret here too) + // For now, it fetches all licenses with their activation counts + try { + $stmt = $pdo->prepare(" + SELECT l.*, + (SELECT COUNT(*) FROM activations a WHERE a.license_id = l.id) as activations_count, + (l.status = 'active') as is_active + FROM licenses l + ORDER BY l.created_at DESC + "); + $stmt->execute(); + $licenses = $stmt->fetchAll(); + + echo json_encode([ + 'success' => true, + 'data' => $licenses + ]); + } catch (Exception $e) { + echo json_encode(['success' => false, 'error' => 'Failed to fetch licenses: ' . $e->getMessage()]); + } + exit; +} + echo json_encode(['success' => false, 'error' => 'Invalid endpoint.']);