Lizenzserver (Backend) - Erstellt

Dieser Commit ist enthalten in:
2025-06-19 21:48:15 +02:00
Ursprung afa2b52494
Commit ae30b74e9c
23 geänderte Dateien mit 3712 neuen und 387 gelöschten Zeilen

Datei anzeigen

@@ -4,18 +4,52 @@
### Public Endpoints
#### POST /api/v1/activate
#### GET /
Root endpoint - Service status.
**Response:**
```json
{
"status": "ok",
"service": "V2 License Server",
"timestamp": "2025-06-19T10:30:00Z"
}
```
#### GET /health
Health check endpoint.
**Response:**
```json
{
"status": "healthy",
"timestamp": "2025-06-19T10:30:00Z"
}
```
#### GET /metrics
Prometheus metrics endpoint.
**Response:**
Prometheus metrics in CONTENT_TYPE_LATEST format.
### License API Endpoints
All license endpoints require API key authentication via `X-API-Key` header.
#### POST /api/license/activate
Activate a license on a new system.
**Headers:**
```
X-API-Key: your-api-key
```
**Request:**
```json
{
"license_key": "XXXX-XXXX-XXXX-XXXX",
"hardware_id": {
"mac_address": "00:1B:44:11:3A:B7",
"cpu_id": "BFEBFBFF000906EA",
"system_uuid": "4C4C4544-0052-3410-8036-B8C04F303832"
},
"hardware_hash": "unique-hardware-identifier",
"machine_name": "DESKTOP-ABC123",
"app_version": "1.0.0"
}
@@ -24,28 +58,32 @@ Activate a license on a new system.
**Response:**
```json
{
"success": true,
"activation_id": "act_123456",
"features": ["feature1", "feature2"],
"max_users": 10,
"valid_until": "2026-01-01T00:00:00Z"
"message": "License activated successfully",
"activation": {
"id": 123,
"license_key": "XXXX-XXXX-XXXX-XXXX",
"hardware_hash": "unique-hardware-identifier",
"machine_name": "DESKTOP-ABC123",
"activated_at": "2025-06-19T10:30:00Z",
"last_heartbeat": "2025-06-19T10:30:00Z",
"is_active": true
}
}
```
#### POST /api/v1/validate
Validate an active license.
#### POST /api/license/verify
Verify an active license.
**Headers:**
```
X-API-Key: your-api-key
```
**Request:**
```json
{
"license_key": "XXXX-XXXX-XXXX-XXXX",
"activation_id": "act_123456",
"hardware_id": {
"mac_address": "00:1B:44:11:3A:B7",
"cpu_id": "BFEBFBFF000906EA",
"system_uuid": "4C4C4544-0052-3410-8036-B8C04F303832"
},
"current_users": 5,
"hardware_hash": "unique-hardware-identifier",
"app_version": "1.0.0"
}
```
@@ -54,333 +92,526 @@ Validate an active license.
```json
{
"valid": true,
"features": ["feature1", "feature2"],
"max_users": 10,
"message": "License valid"
"message": "License is valid",
"license": {
"key": "XXXX-XXXX-XXXX-XXXX",
"valid_until": "2026-01-01",
"max_users": 10
},
"update_available": false,
"latest_version": "1.0.0"
}
```
#### POST /api/v1/heartbeat
Send usage heartbeat.
#### GET /api/license/info/{license_key}
Get license information.
**Headers:**
```
X-API-Key: your-api-key
```
**Response:**
```json
{
"license": {
"id": 123,
"key": "XXXX-XXXX-XXXX-XXXX",
"customer_name": "ACME Corp",
"type": "perpetual",
"valid_from": "2025-01-01",
"valid_until": "2026-01-01",
"max_activations": 5,
"max_users": 10,
"is_active": true
},
"activations": [
{
"id": 456,
"hardware_hash": "unique-hardware-identifier",
"machine_name": "DESKTOP-ABC123",
"activated_at": "2025-06-19T10:00:00Z",
"last_heartbeat": "2025-06-19T14:30:00Z",
"is_active": true
}
]
}
```
### Version API Endpoints
#### POST /api/version/check
Check for available updates.
**Headers:**
```
X-API-Key: your-api-key
```
**Request:**
```json
{
"license_key": "XXXX-XXXX-XXXX-XXXX",
"activation_id": "act_123456",
"current_users": 5,
"feature_usage": {
"feature1": 150,
"feature2": 75
"current_version": "1.0.0",
"license_key": "XXXX-XXXX-XXXX-XXXX"
}
```
**Response:**
```json
{
"update_available": true,
"latest_version": "1.1.0",
"download_url": "https://example.com/download/v1.1.0",
"release_notes": "Bug fixes and performance improvements",
"is_mandatory": false
}
```
#### GET /api/version/latest
Get latest version information.
**Headers:**
```
X-API-Key: your-api-key
```
**Response:**
```json
{
"version": "1.1.0",
"release_date": "2025-06-15",
"download_url": "https://example.com/download/v1.1.0",
"release_notes": "Bug fixes and performance improvements",
"is_mandatory": false
}
```
## Admin Panel API
### Customer API Endpoints
#### GET /api/customers
Search customers for Select2 dropdown.
**Query Parameters:**
- `q`: Search query
- `page`: Page number (default: 1)
**Response:**
```json
{
"results": [
{
"id": 123,
"text": "ACME Corp - admin@acme.com"
}
],
"pagination": {
"more": false
}
}
```
**Response:**
```json
{
"success": true,
"next_heartbeat": "2025-01-01T12:30:00Z"
}
```
#### POST /api/v1/deactivate
Deactivate a license.
**Request:**
```json
{
"license_key": "XXXX-XXXX-XXXX-XXXX",
"activation_id": "act_123456",
"reason": "System upgrade"
}
```
**Response:**
```json
{
"success": true,
"message": "License deactivated successfully"
}
```
### Admin API Endpoints
#### Authentication
All admin endpoints require JWT authentication:
```
Authorization: Bearer <jwt_token>
```
#### GET /api/v1/admin/licenses
List all licenses.
**Query Parameters:**
- `page` (default: 1)
- `per_page` (default: 50)
- `status` (active, inactive, expired)
- `customer_id`
#### GET /api/customer/{customer_id}/licenses
Get licenses for a specific customer.
**Response:**
```json
{
"licenses": [
{
"id": 1,
"id": 456,
"license_key": "XXXX-XXXX-XXXX-XXXX",
"customer_name": "ACME Corp",
"type": "subscription",
"type": "perpetual",
"status": "active",
"valid_from": "2025-01-01",
"valid_until": "2026-01-01",
"max_activations": 5,
"current_activations": 3
}
],
"total": 100,
"page": 1,
"per_page": 50
]
}
```
#### POST /api/v1/admin/licenses
Create a new license.
#### GET /api/customer/{customer_id}/quick-stats
Get quick statistics for a customer.
**Response:**
```json
{
"total_licenses": 10,
"active_licenses": 8,
"total_activations": 25,
"total_users": 150
}
```
### License Management API
#### POST /api/license/{license_id}/toggle
Toggle license active status.
**Response:**
```json
{
"success": true,
"is_active": true,
"message": "License activated successfully"
}
```
#### POST /api/licenses/bulk-activate
Activate multiple licenses.
**Request:**
```json
{
"customer_id": 123,
"type": "subscription",
"valid_from": "2025-01-01",
"valid_until": "2026-01-01",
"max_activations": 5,
"max_users": 10,
"features": ["feature1", "feature2"]
"license_ids": [1, 2, 3]
}
```
**Response:**
```json
{
"id": 456,
"license_key": "NEW1-NEW2-NEW3-NEW4",
"message": "License created successfully"
"success": true,
"count": 3,
"message": "3 licenses activated successfully"
}
```
#### GET /api/v1/admin/licenses/{id}
Get license details.
#### POST /api/licenses/bulk-deactivate
Deactivate multiple licenses.
**Request:**
```json
{
"license_ids": [1, 2, 3]
}
```
**Response:**
```json
{
"id": 1,
"license_key": "XXXX-XXXX-XXXX-XXXX",
"customer": {
"id": 123,
"name": "ACME Corp",
"email": "admin@acme.com"
},
"activations": [
{
"id": "act_123456",
"machine_name": "DESKTOP-ABC123",
"activated_at": "2025-01-01T10:00:00Z",
"last_heartbeat": "2025-06-19T14:30:00Z",
"status": "active"
}
],
"usage_stats": {
"total_users": 150,
"peak_users": 10,
"feature_usage": {
"feature1": 5000,
"feature2": 2500
}
}
"success": true,
"count": 3,
"message": "3 licenses deactivated successfully"
}
```
#### PUT /api/v1/admin/licenses/{id}
Update license.
#### POST /api/licenses/bulk-delete
Delete multiple licenses.
**Request:**
```json
{
"license_ids": [1, 2, 3]
}
```
**Response:**
```json
{
"success": true,
"deleted": 3,
"message": "3 licenses deleted successfully"
}
```
#### POST /api/license/{license_id}/quick-edit
Quick edit license properties.
**Request:**
```json
{
"valid_until": "2027-01-01",
"max_activations": 10,
"features": ["feature1", "feature2", "feature3"]
"max_users": 50
}
```
#### DELETE /api/v1/admin/licenses/{id}
Revoke a license.
#### GET /api/v1/admin/activations
List all activations.
**Query Parameters:**
- `license_id`
- `status` (active, inactive)
- `from_date`
- `to_date`
#### GET /api/v1/admin/statistics
Get usage statistics.
**Query Parameters:**
- `from_date`
- `to_date`
- `customer_id`
- `license_id`
**Response:**
```json
{
"summary": {
"total_licenses": 100,
"active_licenses": 85,
"total_activations": 250,
"active_users": 1500
},
"usage_trends": [
"success": true,
"message": "License updated successfully"
}
```
#### POST /api/generate-license-key
Generate a new license key.
**Response:**
```json
{
"license_key": "NEW1-NEW2-NEW3-NEW4"
}
```
### Device Management API
#### GET /api/license/{license_id}/devices
Get devices for a license.
**Response:**
```json
{
"devices": [
{
"date": "2025-06-01",
"active_users": 1200,
"new_activations": 5
"id": 123,
"hardware_hash": "unique-hardware-identifier",
"machine_name": "DESKTOP-ABC123",
"activated_at": "2025-01-01T10:00:00Z",
"last_heartbeat": "2025-06-19T14:30:00Z",
"is_active": true,
"app_version": "1.0.0"
}
]
}
```
#### POST /api/license/{license_id}/register-device
Register a new device.
**Request:**
```json
{
"hardware_hash": "unique-hardware-identifier",
"machine_name": "DESKTOP-XYZ789",
"app_version": "1.0.0"
}
```
**Response:**
```json
{
"success": true,
"device_id": 456,
"message": "Device registered successfully"
}
```
#### POST /api/license/{license_id}/deactivate-device/{device_id}
Deactivate a device.
**Response:**
```json
{
"success": true,
"message": "Device deactivated successfully"
}
```
### Resource Management API
#### GET /api/license/{license_id}/resources
Get resources for a license.
**Response:**
```json
{
"resources": [
{
"id": 789,
"type": "server",
"identifier": "SRV-001",
"status": "allocated",
"allocated_at": "2025-06-01T10:00:00Z"
}
]
}
```
#### POST /api/resources/allocate
Allocate resources to a license.
**Request:**
```json
{
"license_id": 123,
"resource_ids": [789, 790]
}
```
**Response:**
```json
{
"success": true,
"allocated": 2,
"message": "2 resources allocated successfully"
}
```
#### GET /api/resources/check-availability
Check resource availability.
**Query Parameters:**
- `type`: Resource type
- `count`: Number of resources needed
**Response:**
```json
{
"available": true,
"count": 5,
"resources": [
{
"id": 791,
"type": "server",
"identifier": "SRV-002"
}
]
}
```
#### GET /api/resources/stats
Get resource statistics.
**Response:**
```json
{
"total": 100,
"allocated": 75,
"available": 25,
"by_type": {
"server": {
"total": 50,
"allocated": 40,
"available": 10
},
"workstation": {
"total": 50,
"allocated": 35,
"available": 15
}
}
}
```
### Search API
#### GET /api/global-search
Global search across all entities.
**Query Parameters:**
- `q`: Search query
- `type`: Entity type filter (customer, license, device)
- `limit`: Maximum results (default: 20)
**Response:**
```json
{
"results": [
{
"type": "customer",
"id": 123,
"title": "ACME Corp",
"subtitle": "admin@acme.com",
"url": "/customer/edit/123"
},
{
"type": "license",
"id": 456,
"title": "XXXX-XXXX-XXXX-XXXX",
"subtitle": "ACME Corp - Active",
"url": "/license/edit/456"
}
],
"feature_usage": {
"feature1": 50000,
"feature2": 25000
"total": 15
}
```
### Session Management API
#### GET /api/sessions/active-count
Get count of active sessions.
**Response:**
```json
{
"count": 42
}
```
### Monitoring API
#### GET /api/monitoring/live-stats
Get live statistics for monitoring.
**Response:**
```json
{
"timestamp": "2025-06-19T14:30:00Z",
"metrics": {
"active_licenses": 850,
"total_activations": 2500,
"active_sessions": 1200,
"heartbeats_per_minute": 450
},
"alerts": [
{
"type": "warning",
"message": "High CPU usage detected",
"timestamp": "2025-06-19T14:25:00Z"
}
]
}
```
#### GET /api/monitoring/anomaly-stats
Get anomaly statistics.
**Response:**
```json
{
"total_anomalies": 15,
"unresolved": 3,
"by_type": {
"unusual_activation_pattern": 5,
"excessive_heartbeats": 3,
"license_hopping": 7
}
}
```
#### GET /api/admin/license/auth-token
Get JWT token for analytics access.
**Response:**
```json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_at": "2025-06-19T15:30:00Z"
}
```
## Lead Management API
### Institutions
### GET /leads/api/stats
Get lead statistics.
#### GET /api/institutions
List all institutions.
**Query Parameters:**
- `search`: Search term
- `tags`: Comma-separated tags
- `page`: Page number
- `per_page`: Items per page
#### POST /api/institutions
Create new institution.
**Request:**
**Response:**
```json
{
"name": "Example University",
"type": "university",
"address": "123 Main St",
"tags": ["education", "research"],
"metadata": {
"student_count": 5000
"total_institutions": 150,
"total_contacts": 450,
"recent_activities": 25,
"conversion_rate": 12.5,
"by_type": {
"university": 50,
"company": 75,
"government": 25
}
}
```
#### GET /api/institutions/{id}
Get institution details.
#### PUT /api/institutions/{id}
Update institution.
#### DELETE /api/institutions/{id}
Delete institution.
### Contact Persons
#### GET /api/institutions/{id}/contacts
List contacts for institution.
#### POST /api/institutions/{id}/contacts
Add contact to institution.
**Request:**
```json
{
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
"position": "IT Manager",
"is_primary": true
}
```
### Notes
#### GET /api/institutions/{id}/notes
Get notes for institution.
#### POST /api/institutions/{id}/notes
Add note to institution.
**Request:**
```json
{
"content": "Discussed pricing options",
"type": "meeting",
"tags": ["sales", "followup"]
}
```
## Analytics API
### GET /api/v1/analytics/usage
Get detailed usage analytics.
**Query Parameters:**
- `from_date`: Start date (ISO 8601)
- `to_date`: End date (ISO 8601)
- `license_id`: Filter by license
- `granularity`: hour, day, week, month
**Response:**
```json
{
"period": {
"from": "2025-06-01T00:00:00Z",
"to": "2025-06-19T23:59:59Z"
},
"metrics": {
"total_heartbeats": 50000,
"unique_activations": 150,
"average_users_per_activation": 8.5,
"peak_concurrent_users": 1200
},
"time_series": [
{
"timestamp": "2025-06-01T00:00:00Z",
"active_users": 800,
"heartbeat_count": 2500
}
]
}
```
### GET /api/v1/analytics/features
Get feature usage statistics.
**Response:**
```json
{
"features": [
{
"name": "feature1",
"total_usage": 150000,
"unique_users": 500,
"usage_trend": "increasing"
}
]
}
```
### Lead Routes (HTML Pages)
- `GET /leads/` - Lead overview page
- `GET /leads/create` - Create lead form
- `POST /leads/create` - Save new lead
- `GET /leads/edit/{lead_id}` - Edit lead form
- `POST /leads/update/{lead_id}` - Update lead
- `POST /leads/delete/{lead_id}` - Delete lead
- `GET /leads/export` - Export leads
- `POST /leads/import` - Import leads
## Common Response Codes