Fix license system - tier-aware key generation and activation

- generateLicenseKey() now accepts tier parameter and prefixes keys:
  T=Trial, B=Basic, P=Professional, E=Enterprise
- Added detectLicenseTier() to extract tier from key prefix
- Updated isValidLicenseFormat() regex to accept tier prefixes
- Simplified activateLicense() to use detectLicenseTier()
- Added license_generate API endpoint for generating sample keys
- Added "Generate Sample License Key" UI section with tier selector
- Added copy/use buttons for generated keys

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Purple
2026-02-10 17:45:23 +00:00
parent 336121d758
commit ebfbf27b9c
3 changed files with 181 additions and 45 deletions

View File

@@ -289,6 +289,10 @@ try {
handleLicenseUsage($db);
break;
case 'license_generate':
handleLicenseGenerate($db);
break;
default:
jsonResponse(['error' => 'Invalid action'], 400);
}
@@ -3717,6 +3721,49 @@ function handleLicenseUsage($db) {
]);
}
/**
* Generate sample license keys (admin only, for testing)
*/
function handleLicenseGenerate($db) {
require_once __DIR__ . '/includes/auth.php';
if (!isAdmin()) {
jsonResponse(['error' => 'Admin access required'], 403);
return;
}
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
jsonResponse(['error' => 'GET method required'], 405);
return;
}
$tier = $_GET['tier'] ?? 'trial';
// Map tier name to constant
$tierMap = [
'trial' => LICENSE_TRIAL,
'basic' => LICENSE_BASIC,
'professional' => LICENSE_PROFESSIONAL,
'enterprise' => LICENSE_ENTERPRISE
];
$tierConst = $tierMap[$tier] ?? LICENSE_TRIAL;
$key = generateLicenseKey($tierConst);
global $LICENSE_LIMITS;
$limits = $LICENSE_LIMITS[$tierConst];
jsonResponse([
'success' => true,
'license_key' => $key,
'tier' => $tier,
'tier_name' => $limits['name'],
'max_entries' => $limits['max_entries'],
'max_users' => $limits['max_users'],
'features' => $limits['features']
]);
}
/**
* Export full database backup as JSON
*/