仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<?php
2/**
3 * 管理员端 - 资产管理
4 */
5if (!defined('IN_CRONLITE')) {
6 exit;
7}
8
9$page = max(1, (int)($_GET['page_num'] ?? 1));
10$assets = hosting_asset_list_all($page, 30);
11
12$status_labels = [
13 'active' => '正常',
14 'expired' => '已到期',
15 'cancelled' => '已取消',
16];
17$status_classes = [
18 'active' => 'badge-success',
19 'expired' => 'badge-warning',
20 'cancelled' => 'badge-secondary',
21];
22
23$title = $title ?? '资产管理';
24mnbt_admin_include('head');
25?>
26<div class="container-fluid p-t-15">
27 <div class="card">
28 <div class="card-header">
29 <h4 style="display:inline-block">资产管理</h4>
30 </div>
31 <div class="card-body">
32 <div class="table-responsive">
33 <table class="table table-bordered table-hover">
34 <thead>
35 <tr>
36 <th>ID</th>
37 <th>用户ID</th>
38 <th>套餐</th>
39 <th>主机ID</th>
40 <th>主机账号</th>
41 <th>控制面板密码</th>
42 <th>节点</th>
43 <th>宝塔站点ID</th>
44 <th>开通时间</th>
45 <th>到期时间</th>
46 <th>状态</th>
47 <th>操作</th>
48 </tr>
49 </thead>
50 <tbody>
51 <?php if (empty($assets['list'])): ?>
52 <tr><td colspan="12" class="text-center text-muted">暂无资产</td></tr>
53 <?php else: ?>
54 <?php foreach ($assets['list'] as $a): ?>
55 <?php
56 $panelUrl = '';
57 if (!empty($a['btip']) && !empty($a['btdk'])) {
58 $panelUrl = (($a['ptl'] ?? '') === 'true' ? 'https' : 'http') . '://' . $a['btip'] . ':' . $a['btdk'];
59 }
60 ?>
61 <tr>
62 <td><?= (int)$a['id'] ?></td>
63 <td><?= (int)$a['user_id'] ?></td>
64 <td><?= htmlspecialchars($a['plan_name'], ENT_QUOTES) ?></td>
65 <td><?= (int)$a['host_id'] > 0 ? (int)$a['host_id'] : '-' ?></td>
66 <td class="small"><?= htmlspecialchars($a['host_user'] ?? '-', ENT_QUOTES) ?></td>
67 <td class="small">
68 <?php if (!empty($a['host_pass'])): ?>
69 <span class="hs-pass-mask" data-pass="<?= htmlspecialchars($a['host_pass'], ENT_QUOTES) ?>">********</span>
70 <button type="button" class="btn btn-xs btn-link hs-toggle-pass" title="显示/隐藏密码">👁</button>
71 <button type="button" class="btn btn-xs btn-link hs-copy-btn" data-copy="<?= htmlspecialchars($a['host_pass'], ENT_QUOTES) ?>" title="复制密码">📋</button>
72 <?php else: ?>
73 -
74 <?php endif; ?>
75 </td>
76 <td><?= htmlspecialchars($a['ssbt'] ?? '-', ENT_QUOTES) ?></td>
77 <td class="small text-muted"><?= htmlspecialchars($a['btid'] ?? '-', ENT_QUOTES) ?></td>
78 <td class="small"><?= htmlspecialchars($a['data'] ?? $a['created_at']) ?></td>
79 <td class="small"><?= htmlspecialchars($a['expire_at']) ?></td>
80 <td>
81 <span class="badge <?= htmlspecialchars($status_classes[$a['status']] ?? 'badge-secondary', ENT_QUOTES) ?>">
82 <?= htmlspecialchars($status_labels[$a['status']] ?? $a['status']) ?>
83 </span>
84 </td>
85 <td>
86 <?php if (!empty($a['host_user']) && !empty($a['host_pass'])): ?>
87 <form method="POST" action="<?= htmlspecialchars(hosting_core_url('user/idcdl.php?gn=logine'), ENT_QUOTES) ?>" target="_blank" style="display:inline;">
88 <input type="hidden" name="username" value="<?= htmlspecialchars($a['host_user'], ENT_QUOTES) ?>">
89 <input type="hidden" name="password" value="<?= htmlspecialchars($a['host_pass'], ENT_QUOTES) ?>">
90 <button type="submit" class="btn btn-xs btn-success">一键登录</button>
91 </form>
92 <?php endif; ?>
93 <?php if ($panelUrl): ?>
94 <a href="<?= htmlspecialchars($panelUrl, ENT_QUOTES) ?>" target="_blank" class="btn btn-xs btn-outline-primary" rel="noopener noreferrer">打开面板</a>
95 <?php else: ?>
96 <span class="text-muted small">无节点信息</span>
97 <?php endif; ?>
98 </td>
99 </tr>
100 <?php endforeach; ?>
101 <?php endif; ?>
102 </tbody>
103 </table>
104 </div>
105
106 <?php
107 $total_pages = max(1, (int)ceil($assets['total'] / $assets['per_page']));
108 $current_page = (int)$assets['page'];
109 if ($total_pages > 1):
110 ?>
111 <nav>
112 <ul class="pagination pagination-sm">
113 <?php if ($current_page > 1): ?>
114 <li class="page-item"><a class="page-link" href="plugin.php?p=hosting_shop&page=assets&page_num=<?= $current_page - 1 ?>">上一页</a></li>
115 <?php endif; ?>
116 <li class="page-item disabled"><span class="page-link">第 <?= $current_page ?> / <?= $total_pages ?> 页(共 <?= (int)$assets['total'] ?> 条)</span></li>
117 <?php if ($current_page < $total_pages): ?>
118 <li class="page-item"><a class="page-link" href="plugin.php?p=hosting_shop&page=assets&page_num=<?= $current_page + 1 ?>">下一页</a></li>
119 <?php endif; ?>
120 </ul>
121 </nav>
122 <?php endif; ?>
123 </div>
124 </div>
125</div>
126<style>
127.hs-pass-mask{display:inline-block;min-width:64px;user-select:all;font-family:Consolas,Monaco,monospace;}
128.hs-pass-mask.revealed{background:#e6f4ff;padding:2px 6px;border-radius:4px;color:#1e9fff;}
129.hs-toggle-pass,.hs-copy-btn{padding:0 2px;font-size:14px;line-height:1;}
130</style>
131<script>
132(function(){
133 document.querySelectorAll('.hs-toggle-pass').forEach(function(btn){
134 btn.addEventListener('click', function(){
135 var span = this.parentNode.querySelector('.hs-pass-mask');
136 if (!span) return;
137 if (span.textContent === '********') {
138 span.textContent = span.getAttribute('data-pass');
139 span.classList.add('revealed');
140 } else {
141 span.textContent = '********';
142 span.classList.remove('revealed');
143 }
144 });
145 });
146 document.querySelectorAll('.hs-copy-btn').forEach(function(btn){
147 btn.addEventListener('click', function(){
148 var text = this.getAttribute('data-copy');
149 if (!text) return;
150 if (navigator.clipboard && navigator.clipboard.writeText) {
151 navigator.clipboard.writeText(text).then(function(){ alert('已复制:' + text); }).catch(function(){ fallbackCopy(text); });
152 } else {
153 fallbackCopy(text);
154 }
155 });
156 });
157 function fallbackCopy(text){
158 var ta = document.createElement('textarea');
159 ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
160 document.body.appendChild(ta); ta.select();
161 try { document.execCommand('copy'); alert('已复制:' + text); }
162 catch (err) { alert('复制失败,请手动复制'); }
163 document.body.removeChild(ta);
164 }
165})();
166</script>