-
Admin Password
-
+
+
+
-
Login
+
License Admin
+
Enter password to manage licenses
+
+
-
Invalid password
+
Invalid password. Please try again.
@@ -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
-
+
+
-
+
-
+
-
- = htmlspecialchars($message) ?>
+
+ = $message ?>
-
-
-
-
+
+
+ = $error ?>
+
+
-
-