false, 'msg' => ''];
$traffic = $traffic ?? ['ok' => false, 'data' => []];
$dcim = $dcim ?? ['ok' => false, 'data' => []];
$config_options = $config_options ?? [];
$custom_fields = $custom_fields ?? [];
$os_list = $os_list ?? [];
$os_groups = $os_groups ?? [];
$os_error = $os_error ?? '';
// 密码默认掩码展示,点击"显示"后经 /reserve/api/host_password 按需解密
// (服务端记日志),页面不再无条件渲染明文密码
$hasUpId = (int)$host['up_host_id'] > 0;
// 上游详情字段(label => [显示名, 分组])。价格 / 付款相关字段一律不展示。
$up_fields = [
'productname' => ['产品名', '产品信息'],
'groupname' => ['产品组名', '产品信息'],
'os' => ['操作系统', '产品信息'],
'domain' => ['主机名', '产品信息'],
'dedicatedip' => ['独立 IP', '网络信息'],
'assignedips' => ['附加 IP', '网络信息'],
'ip_num' => ['IP 数量', '网络信息'],
'port' => ['端口', '网络信息'],
'username' => ['服务器用户名', '账号信息'],
// 上游密码不在详情面板展示(脱敏收敛,仅在"显示密码"后经 AJAX 获取)
'regdate' => ['开通时间', '生命周期'],
'nextduedate' => ['到期时间', '生命周期'],
'domainstatus' => ['产品状态', '生命周期'],
'suspendreason' => ['暂停原因', '其他'],
'auto_terminate_end_cycle' => ['到期自动取消', '其他'],
'auto_terminate_reason' => ['取消原因', '其他'],
'bwusage' => ['当前使用流量', '其他'],
'bwlimit' => ['流量上限', '其他'],
'remark' => ['备注', '其他'],
'allow_upgrade_config' => ['支持升级配置', '其他'],
'allow_upgrade_product' => ['支持升级产品', '其他'],
'show_traffic_usage' => ['显示用量图', '其他'],
'productid' => ['产品 ID', '其他'],
'serverid' => ['服务器 ID', '其他'],
'ordernum' => ['上游订单号', '其他'],
];
$up_group_order = ['产品信息', '网络信息', '账号信息', '生命周期', '其他'];
$up_groups = [];
if (is_array($info['data']) && $info['data'] !== []) {
foreach ($up_fields as $k => $cfg) {
[$label, $group] = $cfg;
if (!array_key_exists($k, $info['data'])) {
continue;
}
$v = $info['data'][$k];
if ($v === null || $v === '' || $v === []) {
continue;
}
// 时间戳 → 本地日期时间
if (in_array($k, ['regdate', 'nextduedate'], true) && is_numeric($v)) {
$v = zjmf_normalize_date((string)$v);
}
// 布尔开关
if (in_array($k, ['auto_terminate_end_cycle', 'allow_upgrade_config', 'allow_upgrade_product', 'show_traffic_usage'], true)) {
$v = (string)$v === '1' ? '是' : ((string)$v === '0' ? '否' : $v);
}
// 流量上限 0 表示不限
if ($k === 'bwlimit' && (string)$v === '0') {
$v = '不限';
}
// 状态转中文
if ($k === 'domainstatus') {
$v = zjmf_host_status_label(zjmf_map_upstream_status((string)$v));
}
if (is_array($v)) {
$v = json_encode($v, JSON_UNESCAPED_UNICODE);
}
if ((string)$v === '') {
continue;
}
$up_groups[$group][] = ['label' => $label, 'value' => (string)$v];
}
}
// 端口:host/product 的 host_data.port 是真实端口,优先使用;
// 为空 / 0 时再依次从配置选项、自定义字段中识别(名称含“端口/port”),同样排除无效值
$displayPort = '';
$rawPort = trim((string)($info['data']['port'] ?? ''));
if ($rawPort !== '' && $rawPort !== '0') {
$displayPort = $rawPort;
}
if ($displayPort === '') {
foreach (($config_options ?: []) as $opt) {
$optName = strtolower((string)($opt['name'] ?? ''));
if ($optName !== '' && (strpos($optName, '端口') !== false || strpos($optName, 'port') !== false)) {
$pv = trim((string)($opt['sub_name'] ?? ''));
if ($pv !== '' && $pv !== '0') {
$displayPort = $pv;
break;
}
}
}
}
if ($displayPort === '') {
foreach (($custom_fields ?: []) as $cf) {
$cfName = strtolower((string)($cf['fieldname'] ?? $cf['name'] ?? ''));
if ($cfName !== '' && (strpos($cfName, '端口') !== false || strpos($cfName, 'port') !== false)) {
$cfv = trim((string)($cf['value'] ?? ''));
if ($cfv !== '' && $cfv !== '0') {
$displayPort = $cfv;
break;
}
}
}
}
// DCIM 交换机端口名兜底(dcim/detail 的 switch[].name)
if ($displayPort === '') {
$switchList = $dcim['data']['detail']['switch'] ?? [];
if (is_array($switchList) && isset($switchList[0]['name'])) {
$displayPort = trim((string)$switchList[0]['name']);
}
}
if ($displayPort === '0') {
$displayPort = '';
}
// 端口行统一用正确端口,无效(空 / 0)则不展示
if ($displayPort !== '' && isset($up_groups['网络信息'])) {
foreach ($up_groups['网络信息'] as $i => $r) {
if ($r['label'] === '端口') {
$up_groups['网络信息'][$i]['value'] = $displayPort;
break;
}
}
}
// 配置选项:剔除已单独展示的端口项,避免重复
if (is_array($config_options)) {
$config_options = array_values(array_filter($config_options, function ($opt) {
$name = strtolower((string)($opt['name'] ?? ''));
return !($name !== '' && (strpos($name, '端口') !== false || strpos($name, 'port') !== false));
}));
}
$liveIp = (string)($info['data']['dedicatedip'] ?? $info['data']['ip'] ?? '');
function zjmf_view_show_traffic($data)
{
if (!is_array($data) || $data === []) {
return '暂无流量数据';
}
// 常见标量字段直接展示
$rows = [];
foreach (['total', 'used', 'free', 'percent', 'current', 'monthly_used'] as $k) {
if (isset($data[$k]) && $data[$k] !== '' && $data[$k] !== null) {
$rows[] = $k . ':' . htmlspecialchars((string)$data[$k]);
}
}
if ($rows) {
return implode('
', $rows);
}
return htmlspecialchars(json_encode($data, JSON_UNESCAPED_UNICODE));
}
ob_start();
?>
重启 / 重装 / 救援 / 重置密码为高危操作,请谨慎执行。