Files
wevads-platform/scripts/huawei-accounts.php
2026-02-26 04:53:11 +01:00

145 lines
8.2 KiB
PHP
Executable File

<?php
session_start();
$base_url = 'http://89.167.40.150:5821';
try {
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die("Database connection failed: " . $e->getMessage());
}
// Suppression
if (isset($_GET['delete']) && is_numeric($_GET['delete'])) {
$stmt = $pdo->prepare("DELETE FROM admin.huawei_accounts WHERE id = ?");
$stmt->execute([$_GET['delete']]);
header("Location: huawei-accounts.php?deleted=1");
exit;
}
// Toggle status
if (isset($_GET['toggle']) && is_numeric($_GET['toggle'])) {
$stmt = $pdo->prepare("UPDATE admin.huawei_accounts SET status = CASE WHEN status = 'Activated' THEN 'Disabled' ELSE 'Activated' END, last_updated_date = CURRENT_DATE WHERE id = ?");
$stmt->execute([$_GET['toggle']]);
header("Location: huawei-accounts.php");
exit;
}
$accounts = $pdo->query("SELECT * FROM admin.huawei_accounts ORDER BY id DESC")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WEVAL APP | Huawei Cloud Accounts</title>
<meta content="width=device-width, initial-scale=1" name="viewport" />
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js"></script>
<script>WebFont.load({google: {"families":["Poppins:300,400,500,600,700"]}});</script>
<link href="<?php echo $base_url; ?>/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<link href="<?php echo $base_url; ?>/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link rel="shortcut icon" href="<?php echo $base_url; ?>/images/logos/favicon.ico" />
<style>
body { background: #f1f5f9 !important; font-family: 'Poppins', sans-serif; }
.page-container { max-width: 1400px; margin: 0 auto; padding: 20px; }
.back-link { color: #00e5ff; text-decoration: none; display: inline-flex; align-items: center; margin-bottom: 20px; }
.back-link:hover { color: #1e3a5f; }
.back-link i { margin-right: 8px; }
.page-header { background: #ffffff; border-radius: 8px; padding: 25px; margin-bottom: 25px; border: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
.page-header h1 { color: #e53935; margin: 0; font-size: 24px; }
.page-header p { color: #64748b; margin: 5px 0 0 0; }
.btn-add { background: linear-gradient(135deg, #e53935 0%, #c62828 100%); color: #fff; border: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; text-decoration: none; }
.btn-add:hover { background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); color: #fff; text-decoration: none; }
.card-light { background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; }
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: #f8fafc; color: #1e293b; font-weight: 600; padding: 12px 15px; text-align: left; border-bottom: 2px solid #e2e8f0; font-size: 13px; }
td { padding: 12px 15px; border-bottom: 1px solid #e2e8f0; color: #475569; font-size: 13px; }
tr:hover { background: #f8fafc; }
.badge-active { background: #d1fae5; color: #065f46; padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-disabled { background: #fee2e2; color: #991b1b; padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.btn-action { padding: 6px 10px; border-radius: 4px; font-size: 12px; margin-right: 5px; text-decoration: none; display: inline-block; }
.btn-edit { background: #e0f2fe; color: #0369a1; }
.btn-edit:hover { background: #0ea5e9; color: #fff; }
.btn-toggle { background: #fef3c7; color: #92400e; }
.btn-toggle:hover { background: #f59e0b; color: #fff; }
.btn-delete { background: #fee2e2; color: #991b1b; }
.btn-delete:hover { background: #ef4444; color: #fff; }
.btn-test { background: #e0f2fe; color: #0369a1; }
.btn-test:hover { background: #0ea5e9; color: #fff; }
.empty-state { text-align: center; padding: 60px 20px; color: #64748b; }
.empty-state i { font-size: 48px; color: #e53935; margin-bottom: 15px; }
.alert-success { background: #d1fae5; border: 1px solid #10b981; color: #065f46; padding: 12px 15px; border-radius: 6px; margin-bottom: 20px; }
.key-masked { font-family: monospace; color: #64748b; }
.region-badge { background: #e0f2fe; color: #0369a1; padding: 3px 8px; border-radius: 4px; font-size: 11px; }
</style>
</head>
<body>
<div class="page-container">
<a href="<?php echo $base_url; ?>/dashboard.html" class="back-link"><i class="fa fa-arrow-left"></i> Back to Dashboard</a>
<?php if (isset($_GET['deleted'])): ?>
<div class="alert-success"><i class="fa fa-check-circle"></i> Account deleted successfully!</div>
<?php endif; ?>
<?php if (isset($_GET['saved'])): ?>
<div class="alert-success"><i class="fa fa-check-circle"></i> Account saved successfully!</div>
<?php endif; ?>
<div class="page-header">
<div>
<h1><i class="fa fa-cloud"></i> Huawei Cloud Accounts</h1>
<p>Manage your Huawei Cloud API accounts for server deployment</p>
</div>
<a href="huawei-accounts-add.php" class="btn-add"><i class="fa fa-plus"></i> Add Account</a>
</div>
<div class="card-light">
<div class="table-container">
<?php if (count($accounts) > 0): ?>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Region</th>
<th>Application Key</th>
<th>Status</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($accounts as $acc): ?>
<tr>
<td><?php echo $acc['id']; ?></td>
<td><strong><?php echo htmlspecialchars($acc['name']); ?></strong></td>
<td><span class="region-badge"><?php echo htmlspecialchars($acc['region']); ?></span></td>
<td><span class="key-masked"><?php echo substr($acc['application_key'], 0, 12); ?>...</span></td>
<td><span class="badge-<?php echo $acc['status'] == 'Activated' ? 'active' : 'disabled'; ?>"><?php echo $acc['status']; ?></span></td>
<td><?php echo $acc['created_date']; ?></td>
<td>
<a href="huawei-accounts-add.php?id=<?php echo $acc['id']; ?>" class="btn-action btn-edit" title="Edit"><i class="fa fa-edit"></i></a>
<a href="huawei-test.php?id=<?php echo $acc['id']; ?>" class="btn-action btn-test" title="Test Connection"><i class="fa fa-plug"></i></a>
<a href="?toggle=<?php echo $acc['id']; ?>" class="btn-action btn-toggle" title="Toggle Status"><i class="fa fa-power-off"></i></a>
<a href="?delete=<?php echo $acc['id']; ?>" class="btn-action btn-delete" onclick="return confirm('Delete this account?');" title="Delete"><i class="fa fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-state">
<i class="fa fa-cloud"></i>
<h4>No Huawei Cloud Accounts</h4>
<p>Add your first Huawei Cloud account to deploy servers automatically</p>
<a href="huawei-accounts-add.php" class="btn-add" style="margin-top: 15px; display: inline-block;"><i class="fa fa-plus"></i> Add Account</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php include("includes/chatbot-widget.php"); ?>
</body>
</html>