From 6bc4ca3136b1bcd71cdef285689288d59b1534a4 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 20 Feb 2026 15:25:41 +0000 Subject: [PATCH] editin serila semi final --- license_manager/manage.php | 524 ++++++++++++++++++++++--------------- 1 file changed, 308 insertions(+), 216 deletions(-) diff --git a/license_manager/manage.php b/license_manager/manage.php index 8e90636..d151c63 100644 --- a/license_manager/manage.php +++ b/license_manager/manage.php @@ -5,10 +5,12 @@ * Secure page to manage licenses and activations. */ session_start(); +error_reporting(E_ALL); +ini_set('display_errors', 1); + require_once __DIR__ . '/config.php'; // SIMPLE PASSWORD PROTECTION -// Change this to a secure password or use a more robust auth system $admin_password = "Meezan@2026"; if (isset($_GET['logout'])) { @@ -31,23 +33,36 @@ if (!isset($_SESSION['license_admin_auth'])) { License Admin Login + -
-

License Manager

-
-
- - + @@ -56,254 +71,331 @@ if (!isset($_SESSION['license_admin_auth'])) { exit; } -$pdo = db_manager(); +try { + $pdo = db_manager(); +} catch (Exception $e) { + die("Database connection failed: " . $e->getMessage()); +} + $message = ''; +$error = ''; // Handle Actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'toggle_status': - $id = (int)$_POST['id']; - $new_status = $_POST['status'] === 'active' ? 'suspended' : 'active'; - $stmt = $pdo->prepare("UPDATE licenses SET status = ? WHERE id = ?"); - $stmt->execute([$new_status, $id]); - $message = "License status updated to $new_status."; - break; - - case 'delete_license': - $id = (int)$_POST['id']; - $stmt = $pdo->prepare("DELETE FROM licenses WHERE id = ?"); - $stmt->execute([$id]); - $message = "License deleted successfully."; - break; - - case 'issue': - $prefix = strtoupper(trim($_POST['prefix'] ?? 'FLAT')); - $max_activations = (int)($_POST['max_activations'] ?? 1); - $max_counters = (int)($_POST['max_counters'] ?? 1); - $owner = trim($_POST['owner'] ?? ''); - $address = trim($_POST['address'] ?? ''); - $key = $prefix . '-' . strtoupper(bin2hex(random_bytes(2))) . '-' . strtoupper(bin2hex(random_bytes(2))) . '-' . strtoupper(bin2hex(random_bytes(2))); + try { + if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'toggle_status': + $id = (int)$_POST['id']; + $new_status = $_POST['status'] === 'active' ? 'suspended' : 'active'; + $stmt = $pdo->prepare("UPDATE licenses SET status = ? WHERE id = ?"); + $stmt->execute([$new_status, $id]); + $message = "License status updated to $new_status."; + break; - $stmt = $pdo->prepare("INSERT INTO licenses (license_key, max_activations, max_counters, owner, address, status) VALUES (?, ?, ?, ?, ?, 'active')"); - $stmt->execute([$key, $max_activations, $max_counters, $owner, $address]); - $message = "New license issued: $key"; - break; + case 'delete_license': + $id = (int)$_POST['id']; + $stmt = $pdo->prepare("DELETE FROM licenses WHERE id = ?"); + $stmt->execute([$id]); + $message = "License deleted successfully."; + break; + + case 'issue': + $prefix = strtoupper(trim($_POST['prefix'] ?? 'FLAT')); + $max_activations = (int)($_POST['max_activations'] ?? 1); + $max_counters = (int)($_POST['max_counters'] ?? 1); + $owner = trim($_POST['owner'] ?? ''); + $address = trim($_POST['address'] ?? ''); + + // Generate key + $key = $prefix . '-' . strtoupper(bin2hex(random_bytes(2))) . '-' . strtoupper(bin2hex(random_bytes(2))) . '-' . strtoupper(bin2hex(random_bytes(2))); + + $stmt = $pdo->prepare("INSERT INTO licenses (license_key, max_activations, max_counters, owner, address, status) VALUES (?, ?, ?, ?, ?, 'active')"); + $stmt->execute([$key, $max_activations, $max_counters, $owner, $address]); + $message = "New license issued successfully: $key"; + break; + } } + } catch (Exception $e) { + $error = "Operation failed: " . $e->getMessage(); } } // Fetch Licenses -$licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC")->fetchAll(); +try { + $licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC")->fetchAll(); +} catch (Exception $e) { + $licenses = []; + $error = "Failed to fetch licenses: " . $e->getMessage(); +} ?> - Manage Licenses + Manage Licenses | Admin Panel - + + -