better-staridc-MNBT
1<?php
2/**
3 * 管理员端 - 主机管理
4 */
5if (!defined('IN_CRONLITE')) {
6 exit;
7}
8mnbt_admin_include('head');
9
10$page = max(1, (int)($_GET['page_num'] ?? 1));
11$hosts = zjmf_host_list_all($page, 30);
12$status_labels = [
13 'active' => '运行中',
14 'suspend' => '已暂停',
15 'pending' => '待开通',
16 'terminated' => '已终止',
17 'unknown' => '未知',
18];
19$status_classes = [
20 'active' => 'badge-success',
21 'suspend' => 'badge-danger',
22 'pending' => 'badge-warning',
23 'terminated' => 'badge-dark',
24 'unknown' => 'badge-secondary',
25];
26$title = $title ?? '主机管理';
27?>
28<div class="container-fluid p-t-15">
29 <div class="card">
30 <div class="card-header">
31 <h4 style="display:inline-block">主机管理</h4>
32 <button type="button" class="btn btn-primary btn-sm float-right" id="zjf-refresh-all">全部刷新状态</button>
33 </div>
34 <div class="card-body">
35 <p class="text-muted">主机映射为开通成功的上游主机。可点击「刷新状态」同步上游实时状态;
36 点「全部刷新状态」可批量修复存量未知/过期缓存(逐台上游查询)。</p>
37 <div id="zjf-refresh-all-msg" class="small mb-2" style="display:none;"></div>
38 <div class="table-responsive">
39 <table class="table table-bordered table-hover">
40 <thead>
41 <tr>
42 <th>ID</th>
43 <th>供应商</th>
44 <th>用户</th>
45 <th>主机名</th>
46 <th>上游主机ID</th>
47 <th>状态</th>
48 <th>周期</th>
49 <th>到期时间</th>
50 <th>创建时间</th>
51 <th>操作</th>
52 </tr>
53 </thead>
54 <tbody>
55 <?php if (empty($hosts['list'])): ?>
56 <tr><td colspan="10" class="text-center text-muted">暂无主机</td></tr>
57 <?php else: ?>
58 <?php foreach ($hosts['list'] as $h): ?>
59 <tr>
60 <td><?= (int)$h['id'] ?></td>
61 <td><?= htmlspecialchars($h['supplier_name'] ?: '-') ?></td>
62 <td><?= htmlspecialchars($h['user_name'] ?: ('ID ' . (int)$h['user_id'])) ?></td>
63 <td><?= htmlspecialchars($h['name'], ENT_QUOTES) ?></td>
64 <td><?= (int)$h['up_host_id'] ?></td>
65 <td>
66 <span class="badge <?= htmlspecialchars($status_classes[$h['status']] ?? 'badge-secondary') ?>">
67 <?= htmlspecialchars($status_labels[$h['status']] ?? $h['status']) ?>
68 </span>
69 </td>
70 <td><?= htmlspecialchars($h['cycle'] ?: '-') ?></td>
71 <td><?= htmlspecialchars(zjmf_normalize_date((string)$h['renew_date']) ?: '-') ?></td>
72 <td class="small"><?= htmlspecialchars($h['created_at']) ?></td>
73 <td>
74 <?php if ((int)$h['up_host_id'] > 0): ?>
75 <button type="button" class="btn btn-sm btn-outline-primary zjf-refresh"
76 data-id="<?= (int)$h['id'] ?>">刷新状态</button>
77 <?php else: ?>
78 <span class="text-muted">-</span>
79 <?php endif; ?>
80 </td>
81 </tr>
82 <?php endforeach; ?>
83 <?php endif; ?>
84 </tbody>
85 </table>
86 </div>
87
88 <?php
89 $total_pages = max(1, (int)ceil($hosts['total'] / $hosts['per_page']));
90 $current_page = (int)$hosts['page'];
91 if ($total_pages > 1):
92 $qs = http_build_query(['p' => 'zjmfmanager_reserve', 'page' => 'hosts']);
93 ?>
94 <nav>
95 <ul class="pagination pagination-sm">
96 <?php if ($current_page > 1): ?>
97 <li class="page-item"><a class="page-link"
98 href="plugin.php?<?= htmlspecialchars(
99 $qs . '&page_num=' . ($current_page - 1), ENT_QUOTES
100 ) ?>">上一页</a></li>
101 <?php endif; ?>
102 <li class="page-item disabled"><span class="page-link">
103 第 <?= $current_page ?> / <?= $total_pages ?> 页(共 <?= (int)$hosts['total'] ?> 条)
104 </span></li>
105 <?php if ($current_page < $total_pages): ?>
106 <li class="page-item"><a class="page-link"
107 href="plugin.php?<?= htmlspecialchars(
108 $qs . '&page_num=' . ($current_page + 1), ENT_QUOTES
109 ) ?>">下一页</a></li>
110 <?php endif; ?>
111 </ul>
112 </nav>
113 <?php endif; ?>
114 </div>
115 </div>
116</div>
117<script>
118document.querySelectorAll('.zjf-refresh').forEach(function (btn) {
119 btn.addEventListener('click', function () {
120 var self = this;
121 self.disabled = true;
122 self.textContent = '刷新中...';
123 $.post('ajax.php', {gn: 'p_zjmf_admin_fetch_host', id: self.getAttribute('data-id')}, function (res) {
124 var d;
125 try { d = typeof res === 'string' ? JSON.parse(res) : res; } catch (e) { d = {code: res}; }
126 var ok = d.qk == 1 || d.success;
127 if (typeof $.notify === 'function') {
128 $.notify({message: d.msg || d.code || '完成'}, {type: ok ? 'success' : 'danger'});
129 } else {
130 alert(d.msg || d.code || '完成');
131 }
132 setTimeout(function () { location.reload(); }, 600);
133 });
134 });
135});
136document.getElementById('zjf-refresh-all').addEventListener('click', function () {
137 var self = this;
138 var msgBox = document.getElementById('zjf-refresh-all-msg');
139 self.disabled = true;
140 self.textContent = '刷新中,请稍候...';
141 msgBox.style.display = 'block';
142 msgBox.className = 'small mb-2 text-muted';
143 msgBox.textContent = '正在逐台上游查询,请勿关闭页面...';
144 $.post('ajax.php', {gn: 'p_zjmf_admin_fetch_all_hosts'}, function (res) {
145 var d;
146 try { d = typeof res === 'string' ? JSON.parse(res) : res; } catch (e) { d = {code: res}; }
147 self.disabled = false;
148 self.textContent = '全部刷新状态';
149 if (d.qk != 1 && !d.success) {
150 msgBox.className = 'small mb-2 text-danger';
151 msgBox.textContent = '刷新失败:' + (d.msg || d.code || '未知错误');
152 return;
153 }
154 var s = d.data || {};
155 msgBox.className = 'small mb-2 text-success';
156 msgBox.textContent = '刷新完成:共 ' + s.total + ' 台,成功 ' + s.ok
157 + ',失败 ' + s.fail + ',缺少上游ID ' + s.no_up
158 + ',状态变更 ' + s.changed + ',仍为未知 ' + s.unknown + '。';
159 setTimeout(function () { location.reload(); }, 1500);
160 });
161});
162</script>