From 7c8899df475eb34cfbbaaa2a719310725dc35cf8 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 19 Feb 2026 18:46:30 +0000 Subject: [PATCH] enable/disable license --- db/migrations/20260219_add_license_fields.sql | 3 + index.php | 150 +++++++++++++++++- lib/LicenseService.php | 21 +++ license_manager/index.php | 52 +++++- 4 files changed, 218 insertions(+), 8 deletions(-) create mode 100644 db/migrations/20260219_add_license_fields.sql diff --git a/db/migrations/20260219_add_license_fields.sql b/db/migrations/20260219_add_license_fields.sql new file mode 100644 index 0000000..20b3f5a --- /dev/null +++ b/db/migrations/20260219_add_license_fields.sql @@ -0,0 +1,3 @@ +-- SQL for the License Manager Database (u128023052_meezan_license) +ALTER TABLE licenses ADD COLUMN owner VARCHAR(255) DEFAULT NULL; +ALTER TABLE licenses ADD COLUMN address TEXT DEFAULT NULL; diff --git a/index.php b/index.php index 1e17142..4317978 100644 --- a/index.php +++ b/index.php @@ -1088,6 +1088,37 @@ if (isset($_POST['add_hr_department'])) { } } } + + if (isset($_POST['update_license'])) { + $id = (int)$_POST['id']; + $status = $_POST['status'] ?? null; + $owner = $_POST['owner'] ?? null; + $address = $_POST['address'] ?? null; + + $updateData = []; + if ($status !== null) $updateData['status'] = $status; + if ($owner !== null) $updateData['owner'] = $owner; + if ($address !== null) $updateData['address'] = $address; + + $res = LicenseService::updateLicense($id, $updateData); + if ($res['success']) { + $message = "License updated successfully!"; + } else { + $message = "Error: " . ($res['error'] ?? 'Unknown error'); + } + } + + if (isset($_POST['issue_license'])) { + $max = (int)($_POST['max_activations'] ?? 1); + $owner = $_POST['owner'] ?? null; + $address = $_POST['address'] ?? null; + $res = LicenseService::issueLicense($max, 'FLAT', $owner, $address); + if ($res['success']) { + $message = "New License Issued: " . $res['license_key']; + } else { + $message = "Error: " . ($res['error'] ?? 'Unknown error'); + } + } if (isset($_POST['pay_payroll'])) { $id = (int)$_POST['id']; if ($id) { @@ -7168,6 +7199,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';

View and search license keys activated on your system

+ @@ -7187,16 +7221,17 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; ID License Key - Max - Used + Owner + Max/Used Status Created At + Actions - + No license data found on the server. @@ -7206,8 +7241,15 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; # - - + +
+
+ + + + / + + Active @@ -7216,6 +7258,21 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; + +
+ +
+ + + +
+
+ @@ -7225,6 +7282,89 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
+ + + + + + + + +
diff --git a/lib/LicenseService.php b/lib/LicenseService.php index 8fa8b8c..72d9049 100644 --- a/lib/LicenseService.php +++ b/lib/LicenseService.php @@ -144,6 +144,27 @@ class LicenseService { 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/index.php b/license_manager/index.php index da29ae4..f201f20 100644 --- a/license_manager/index.php +++ b/license_manager/index.php @@ -18,6 +18,7 @@ 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'; +if (strpos($request_uri, '/update') !== false) $endpoint = 'update'; $input = json_decode(file_get_contents('php://input'), true); @@ -154,19 +155,23 @@ if ($endpoint === 'issue') { $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) VALUES (?, ?)"); - $stmt->execute([$key, $max_activations]); + $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 + 'max_activations' => $max_activations, + 'owner' => $owner, + 'address' => $address ]); } catch (Exception $e) { echo json_encode(['success' => false, 'error' => 'Failed to generate license.']); @@ -198,4 +203,45 @@ if ($endpoint === 'list') { 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.']);