diff --git a/index.php b/index.php index fccf787..9299a22 100644 --- a/index.php +++ b/index.php @@ -1686,7 +1686,6 @@ $page_permissions = [ 'logs' => 'logs_view', 'cash_registers' => 'cash_registers_view', 'register_sessions' => 'register_sessions_view', - 'licenses' => 'licenses_view', ]; if (isset($page_permissions[$page]) && !can($page_permissions[$page])) { @@ -1780,7 +1779,6 @@ $permission_groups = [ 'scale_devices' => 'Scale Devices', 'customer_display_settings' => 'Customer Display', 'backups' => 'Backups', - 'licenses' => 'Licenses', 'logs' => 'System Logs' ] ]; @@ -2404,11 +2402,6 @@ switch ($page) { $data['cash_registers'] = db()->query("SELECT * FROM cash_registers WHERE status = 'active'")->fetchAll(); $data['users'] = db()->query("SELECT id, username FROM users ORDER BY username ASC")->fetchAll(); break; - case 'licenses': - $res = LicenseService::listLicenses(); - $data['licenses'] = $res['success'] ? $res['data'] : []; - $data['license_error'] = $res['success'] ? '' : ($res['error'] ?? 'Failed to fetch licenses.'); - break; default: $data['customers'] = db()->query("SELECT * FROM customers WHERE type = 'customer' ORDER BY id DESC LIMIT 5")->fetchAll(); // Dashboard stats @@ -2737,9 +2730,6 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; - - - @@ -7349,220 +7339,8 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; - - - -
-
-
-
- -
-

Restricted Access

-

Please enter the management password to continue.

- - -
- - -
-
- -
- -
-
-
-
- -
-
-
-
Manage Licenses
-

View and search license keys activated on your system

-
-
- - -
-
-
- -
- - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IDLicense KeyOwnerMax/UsedStatusCreated AtActions
- - No license data found on the server. -
# -
-
-
- - / - - - - Active - - Inactive - - -
- -
- - - -
-
-
-
-
-
- - - - - - - - - - -
diff --git a/lib/LicenseService.php b/lib/LicenseService.php index f544486..3d0f9d1 100644 --- a/lib/LicenseService.php +++ b/lib/LicenseService.php @@ -137,34 +137,6 @@ class LicenseService { return ['success' => true]; } - /** - * Fetches all licenses from the remote server. - */ - public static function listLicenses() { - return self::callRemoteApi('/list', []); - } - - /** - * Updates an existing license. - */ - public static function updateLicense($id, $data) { - $params = array_merge(['id' => $id, 'secret' => '1485-5215-2578'], $data); - return self::callRemoteApi('/update', $params); - } - - /** - * Issues a new license. - */ - public static function issueLicense($max_activations, $prefix = 'FLAT', $owner = null, $address = null) { - return self::callRemoteApi('/issue', [ - 'secret' => '1485-5215-2578', - 'max_activations' => $max_activations, - 'prefix' => $prefix, - 'owner' => $owner, - 'address' => $address - ]); - } - /** * Remote API Caller */ diff --git a/license_manager/admin.html b/license_manager/admin.html deleted file mode 100644 index b62d7ac..0000000 --- a/license_manager/admin.html +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - License Manager Admin - - - - - -
-
-
-
-

License Manager

-

Issue and Manage Licenses

-
- -
-
-
- - -
- -
-
- - -
-
- - -
-
- - -
- -
-
Server Response:
-

-                
-
- -
- Upload this file to the same directory as index.php -
-
-
-
- - - - - diff --git a/license_manager/config.php b/license_manager/config.php deleted file mode 100644 index e606274..0000000 --- a/license_manager/config.php +++ /dev/null @@ -1,22 +0,0 @@ - PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; -} diff --git a/license_manager/database.sql b/license_manager/database.sql deleted file mode 100644 index 37a8578..0000000 --- a/license_manager/database.sql +++ /dev/null @@ -1,26 +0,0 @@ --- SQL for the License Manager Database --- Create a new database called 'license_manager_db' and run this script. - -CREATE TABLE IF NOT EXISTS licenses ( - id INT AUTO_INCREMENT PRIMARY KEY, - license_key VARCHAR(255) UNIQUE NOT NULL, - max_activations INT DEFAULT 1, - status ENUM('active', 'suspended', 'expired') DEFAULT 'active', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB; - -CREATE TABLE IF NOT EXISTS activations ( - id INT AUTO_INCREMENT PRIMARY KEY, - license_id INT NOT NULL, - fingerprint VARCHAR(255) NOT NULL, - domain VARCHAR(255), - product VARCHAR(255), - activated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (license_id) REFERENCES licenses(id) ON DELETE CASCADE, - UNIQUE KEY (license_id, fingerprint) -) ENGINE=InnoDB; - --- Seed some test data -INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-8822-1192-3301', 1); -INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-TEST-KEY-0001', 5); -INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-DEV-UNLIMITED', 999); diff --git a/license_manager/index.php b/license_manager/index.php deleted file mode 100644 index f201f20..0000000 --- a/license_manager/index.php +++ /dev/null @@ -1,247 +0,0 @@ - false, 'error' => 'Database connection failed.']); - exit; -} - -if ($endpoint === 'activate') { - $key = strtoupper(trim($input['license_key'] ?? '')); - $fingerprint = $input['fingerprint'] ?? ''; - $domain = $input['domain'] ?? ''; - $product = $input['product'] ?? ''; - - if (empty($key) || empty($fingerprint)) { - echo json_encode(['success' => false, 'error' => 'Missing required parameters.']); - exit; - } - - // 1. Find License - $stmt = $pdo->prepare("SELECT * FROM licenses WHERE license_key = ? LIMIT 1"); - $stmt->execute([$key]); - $license = $stmt->fetch(); - - if (!$license) { - echo json_encode(['success' => false, 'error' => 'Invalid license key.']); - exit; - } - - if ($license['status'] !== 'active') { - echo json_encode(['success' => false, 'error' => 'License is ' . $license['status'] . '.']); - exit; - } - - // 2. Check current activations - $stmt = $pdo->prepare("SELECT COUNT(*) FROM activations WHERE license_id = ?"); - $stmt->execute([$license['id']]); - $current_activations = $stmt->fetchColumn(); - - // 3. Check if this machine is already activated - $stmt = $pdo->prepare("SELECT * FROM activations WHERE license_id = ? AND fingerprint = ?"); - $stmt->execute([$license['id'], $fingerprint]); - $existing = $stmt->fetch(); - - if (!$existing) { - if ($current_activations >= $license['max_activations']) { - echo json_encode(['success' => false, 'error' => 'Maximum activation limit reached.']); - exit; - } - - // Record new activation - $stmt = $pdo->prepare("INSERT INTO activations (license_id, fingerprint, domain, product) VALUES (?, ?, ?, ?)"); - $stmt->execute([$license['id'], $fingerprint, $domain, $product]); - } - - // Success: Return signed token - $token = hash_hmac('sha256', $key . $fingerprint, SERVER_SECRET); - echo json_encode([ - 'success' => true, - 'activation_token' => $token - ]); - exit; -} - -if ($endpoint === 'verify') { - $key = strtoupper(trim($input['license_key'] ?? '')); - $fingerprint = $input['fingerprint'] ?? ''; - $token = $input['token'] ?? ''; - - // Simple validation: re-calculate token and check DB status - $expected_token = hash_hmac('sha256', $key . $fingerprint, SERVER_SECRET); - - if ($token !== $expected_token) { - echo json_encode(['success' => false, 'error' => 'Invalid activation token.']); - exit; - } - - $stmt = $pdo->prepare("SELECT status FROM licenses WHERE license_key = ?"); - $stmt->execute([$key]); - $status = $stmt->fetchColumn(); - - if ($status === 'active') { - echo json_encode(['success' => true]); - } else { - echo json_encode(['success' => false, 'error' => 'License is no longer active.']); - } - exit; -} - -if ($endpoint === 'deactivate') { - $key = strtoupper(trim($input['license_key'] ?? '')); - $fingerprint = $input['fingerprint'] ?? ''; - - // Deactivation should ideally require a token or signature, but for simplicity: - // We check if the license exists and the activation matches - - // Find License ID - $stmt = $pdo->prepare("SELECT id FROM licenses WHERE license_key = ?"); - $stmt->execute([$key]); - $licenseId = $stmt->fetchColumn(); - - if (!$licenseId) { - echo json_encode(['success' => false, 'error' => 'Invalid license key.']); - exit; - } - - // Delete Activation - $stmt = $pdo->prepare("DELETE FROM activations WHERE license_id = ? AND fingerprint = ?"); - $stmt->execute([$licenseId, $fingerprint]); - - if ($stmt->rowCount() > 0) { - echo json_encode(['success' => true]); - } else { - echo json_encode(['success' => false, 'error' => 'Activation not found.']); - } - exit; -} - -if ($endpoint === 'issue') { - $secret = $input['secret'] ?? ''; - - // Basic security check using the config constant - if ($secret !== SERVER_SECRET) { - echo json_encode(['success' => false, 'error' => 'Unauthorized. Invalid secret.']); - exit; - } - - $max_activations = (int)($input['max_activations'] ?? 1); - $prefix = strtoupper(trim($input['prefix'] ?? 'FLAT')); - $owner = $input['owner'] ?? null; - $address = $input['address'] ?? null; - - // Generate a formatted key: PREFIX-XXXX-XXXX - $key = $prefix . '-' . bin2hex(random_bytes(2)) . '-' . bin2hex(random_bytes(2)); - $key = strtoupper($key); - - try { - $stmt = $pdo->prepare("INSERT INTO licenses (license_key, max_activations, owner, address) VALUES (?, ?, ?, ?)"); - $stmt->execute([$key, $max_activations, $owner, $address]); - - echo json_encode([ - 'success' => true, - 'license_key' => $key, - 'max_activations' => $max_activations, - 'owner' => $owner, - 'address' => $address - ]); - } catch (Exception $e) { - echo json_encode(['success' => false, 'error' => 'Failed to generate license.']); - } - 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; -} - -if ($endpoint === 'update') { - $secret = $input['secret'] ?? ''; - if ($secret !== SERVER_SECRET) { - echo json_encode(['success' => false, 'error' => 'Unauthorized.']); - exit; - } - - $id = (int)($input['id'] ?? 0); - $status = $input['status'] ?? null; - $owner = $input['owner'] ?? null; - $address = $input['address'] ?? null; - - if (!$id) { - echo json_encode(['success' => false, 'error' => 'ID is required.']); - exit; - } - - try { - $fields = []; - $params = []; - if ($status !== null) { $fields[] = "status = ?"; $params[] = $status; } - if ($owner !== null) { $fields[] = "owner = ?"; $params[] = $owner; } - if ($address !== null) { $fields[] = "address = ?"; $params[] = $address; } - - if (empty($fields)) { - echo json_encode(['success' => false, 'error' => 'No fields to update.']); - exit; - } - - $params[] = $id; - $sql = "UPDATE licenses SET " . implode(', ', $fields) . " WHERE id = ?"; - $stmt = $pdo->prepare($sql); - $stmt->execute($params); - - echo json_encode(['success' => true]); - } catch (Exception $e) { - echo json_encode(['success' => false, 'error' => 'Update failed: ' . $e->getMessage()]); - } - exit; -} - -echo json_encode(['success' => false, 'error' => 'Invalid endpoint.']);