updating license issuing

This commit is contained in:
Flatlogic Bot 2026-02-20 14:04:38 +00:00
parent ae4d3598c2
commit 590f247c08
2 changed files with 221 additions and 10 deletions

View File

@ -2009,7 +2009,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])) {
@ -2101,7 +2100,6 @@ $permission_groups = [
'users' => 'Users',
'cash_registers' => 'Cash Registers',
'register_sessions' => 'Register Sessions',
'licenses' => 'Licenses',
'logs' => 'System Logs'
]
];
@ -2782,11 +2780,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 ORDER BY id DESC LIMIT 5")->fetchAll();
$data['stats'] = [
@ -3119,9 +3112,6 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
<a href="index.php?page=backups" class="nav-link <?= $page === 'backups' ? 'active' : '' ?>">
<i class="fas fa-database"></i> <span><?= __('backups') ?></span>
</a>
<a href="index.php?page=licenses" class="nav-link <?= $page === 'licenses' ? 'active' : '' ?>">
<i class="fas fa-key"></i> <span><?= $lang === 'ar' ? 'إدارة التراخيص' : 'Manage Licenses' ?></span>
</a>
</div>
<?php endif; ?>

221
license_manager/manage.php Normal file
View File

@ -0,0 +1,221 @@
<?php
/**
* LICENSE MANAGER ADMIN PANEL
*
* Secure page to manage licenses and activations.
*/
session_start();
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'])) {
session_destroy();
header("Location: manage.php");
exit;
}
if (!isset($_SESSION['license_admin_auth'])) {
if (isset($_POST['password']) && $_POST['password'] === $admin_password) {
$_SESSION['license_admin_auth'] = true;
header("Location: manage.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>License Admin Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background: #f4f7f6; display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { width: 100%; max-width: 400px; padding: 2rem; border-radius: 1rem; box-shadow: 0 10px 25px rgba(0,0,0,0.05); background: white; }
</style>
</head>
<body>
<div class="login-card">
<h3 class="text-center mb-4">License Manager</h3>
<form method="POST">
<div class="mb-3">
<label class="form-label">Admin Password</label>
<input type="password" name="password" class="form-control" placeholder="Enter password" required autofocus>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
<?php if (isset($_POST['password'])): ?>
<div class="alert alert-danger mt-3 py-2 small">Invalid password</div>
<?php endif; ?>
</div>
</body>
</html>
<?php
exit;
}
$pdo = db_manager();
$message = '';
// 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);
$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, status) VALUES (?, ?, 'active')");
$stmt->execute([$key, $max_activations]);
$message = "New license issued: $key";
break;
}
}
}
// Fetch Licenses
$licenses = $pdo->query("SELECT * FROM licenses ORDER BY created_at DESC")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Licenses</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<style>
body { background: #f8f9fa; }
.navbar { background: #1e293b; }
.card { border: none; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); border-radius: 0.5rem; }
.status-active { color: #10b981; }
.status-suspended { color: #ef4444; }
.table thead th { background: #f1f5f9; border-top: none; }
</style>
</head>
<body>
<nav class="navbar navbar-dark mb-4">
<div class="container">
<span class="navbar-brand mb-0 h1"><i class="bi bi-shield-lock me-2"></i> License Manager Admin</span>
<a href="?logout=1" class="btn btn-outline-light btn-sm">Logout</a>
</div>
</nav>
<div class="container pb-5">
<?php if ($message): ?>
<div class="alert alert-info alert-dismissible fade show" role="alert">
<?= htmlspecialchars($message) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="row">
<!-- Issue License Card -->
<div class="col-lg-4 mb-4">
<div class="card p-4">
<h5 class="mb-4">Issue New License</h5>
<form method="POST">
<input type="hidden" name="action" value="issue">
<div class="mb-3">
<label class="form-label">Prefix</label>
<input type="text" name="prefix" class="form-control" value="FLAT" maxlength="10">
</div>
<div class="mb-3">
<label class="form-label">Max Activations</label>
<input type="number" name="max_activations" class="form-control" value="1" min="1">
</div>
<button type="submit" class="btn btn-primary w-100">Issue Key</button>
</form>
</div>
</div>
<!-- Licenses List -->
<div class="col-lg-8">
<div class="card overflow-hidden">
<div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0">Existing Licenses</h5>
<span class="badge bg-secondary"><?= count($licenses) ?> Total</span>
</div>
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Key</th>
<th>Activations</th>
<th>Status</th>
<th>Created</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($licenses as $l): ?>
<tr>
<td><code><?= htmlspecialchars($l['license_key']) ?></code></td>
<td>
<?php
$stmt = $pdo->prepare("SELECT COUNT(*) FROM activations WHERE license_id = ?");
$stmt->execute([$l['id']]);
$count = $stmt->fetchColumn();
?>
<span class="fw-bold"><?= $count ?></span> / <?= $l['max_activations'] ?>
</td>
<td>
<span class="status-<?= $l['status'] ?>">
<i class="bi bi-circle-fill small me-1"></i> <?= ucfirst($l['status']) ?>
</span>
</td>
<td class="small text-muted"><?= date('M d, Y', strtotime($l['created_at'])) ?></td>
<td class="text-end">
<div class="btn-group">
<form method="POST" class="d-inline" onsubmit="return confirm('Change status?');">
<input type="hidden" name="action" value="toggle_status">
<input type="hidden" name="id" value="<?= $l['id'] ?>">
<input type="hidden" name="status" value="<?= $l['status'] ?>">
<button type="submit" class="btn btn-outline-secondary btn-sm" title="Toggle Status">
<i class="bi bi-power"></i>
</button>
</form>
<form method="POST" class="d-inline" onsubmit="return confirm('Are you sure? This will also remove all activations.');">
<input type="hidden" name="action" value="delete_license">
<input type="hidden" name="id" value="<?= $l['id'] ?>">
<button type="submit" class="btn btn-outline-danger btn-sm" title="Delete">
<i class="bi bi-trash"></i>
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($licenses)): ?>
<tr><td colspan="5" class="text-center py-4 text-muted">No licenses found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>