木漏茶室源码下载中心
整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。
发布版本 v6.25.231
升级后自动生成独立源码包,下载中心只发送这份冻结包
已排除 config.php / 用户数据 / 上传文件 / 升级备份
COMMUNITY DEPLOYMENTS
已经跑起来的木漏茶室
从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。
实时检测
3
个站点已部署
木
木漏茶室
mlcs.xnn.lol · v6.25.231
访问 ↗
2026.11.21
在线
木
木漏茶室PHP初始化安装向导
mlcs.nbnb.mom · v6.25.225
访问 ↗
2026.11.20
在线
木
木漏茶室
csrc.954377.xyz · v6.25.211
访问 ↗
2026.11.20
离线
已展示全部 3 个站点。
admin/host.php
17.4 KB · 发布包 v6.25.231
<?php
/**
* 后台 · 主机状态
*/
$admin = current_user();
if (input('ajax') === '1') {
header('Content-Type: application/json; charset=utf-8');
$m = host_metrics(false);
echo json_encode([
'ok' => true,
'cpu' => host_cpu_percent(250),
'cpu_load' => $m['cpu_load'],
'memory_total' => $m['memory_total'],
'memory_free' => $m['memory_free'],
'memory_used' => $m['memory_used'],
'disk_total' => $m['disk_total'],
'disk_free' => $m['disk_free'],
'disk_used' => $m['disk_used'],
'time' => date('H:i:s'),
], JSON_UNESCAPED_UNICODE);
exit;
}
try {
$metrics = host_metrics();
} catch (Throwable $e) {
$metrics = [
'memory_total' => 0, 'memory_free' => 0, 'memory_used' => 0,
'disk_total' => 0, 'disk_free' => 0, 'disk_used' => 0,
'cpu_load' => null, 'cpu_cores' => 0, 'site_size' => 0,
'os' => PHP_OS_FAMILY, 'php' => PHP_VERSION, 'uptime' => '',
];
}
// 部署配置卡片(仅超级管理员可见)
$hostDriver = strtolower((string) ($CONFIG['driver'] ?? 'sqlite'));
$hostIsSqlite = $hostDriver !== 'mysql';
$hostDb = is_array($CONFIG['db'] ?? null) ? $CONFIG['db'] : [];
$hostPrefix = (string) ($CONFIG['prefix'] ?? ($hostDb['prefix'] ?? ''));
$hostSiteUrl = full_url('');
$hostDeployDir = BASE_PATH === '' ? '/' : BASE_PATH;
$hostServer = (string) ($_SERVER['SERVER_SOFTWARE'] ?? '');
$hostScheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (int) ($_SERVER['SERVER_PORT'] ?? 0) === 443 ? 'HTTPS' : 'HTTP';
$hostUploadMax = (string) ini_get('upload_max_filesize');
$hostAddress = $hostIsSqlite ? 'localhost' : (string) ($hostDb['host'] ?? 'localhost');
$hostSqlitePath = (string) ($CONFIG['sqlite_path'] ?? (APP_ROOT . '/data/komorebi.sqlite'));
$hostSqliteDisplay = $hostSqlitePath;
if (strpos($hostSqlitePath, APP_ROOT) === 0) {
$hostSqliteDisplay = ltrim(substr($hostSqlitePath, strlen(APP_ROOT)), '/');
}
$hostSqliteSize = is_file($hostSqlitePath) ? (int) @filesize($hostSqlitePath) : 0;
?>
<section class="panel">
<h2 class="section-title">主机状态</h2>
<p class="muted">实时读取本机内存、网页空间和 CPU 使用率;每 2 秒自动刷新。虚拟主机禁用系统信息读取时,对应指标会显示“不可用”。</p>
<div class="host-grid">
<div class="host-card">
<span class="host-label">内存</span>
<strong id="hostMem"><?= $metrics['memory_total'] ? format_size($metrics['memory_total']) : '不可用' ?></strong>
<small>剩余 <b id="hostMemFree"><?= $metrics['memory_total'] ? format_size($metrics['memory_free']) : '—' ?></b></small>
<div class="host-bar"><i id="hostMemBar" style="width:<?= $metrics['memory_total'] ? round($metrics['memory_used'] / max(1, $metrics['memory_total']) * 100, 1) : 0 ?>%"></i></div>
</div>
<div class="host-card">
<span class="host-label">网页空间</span>
<strong id="hostDisk"><?= $metrics['disk_total'] ? format_size($metrics['disk_total']) : '不可用' ?></strong>
<small>剩余 <b id="hostDiskFree"><?= $metrics['disk_total'] ? format_size($metrics['disk_free']) : '—' ?></b></small>
<div class="host-bar"><i id="hostDiskBar" style="width:<?= $metrics['disk_total'] ? round($metrics['disk_used'] / max(1, $metrics['disk_total']) * 100, 1) : 0 ?>%"></i></div>
</div>
<div class="host-card">
<span class="host-label">CPU 实时波动</span>
<strong id="hostCpu">采样中…</strong>
<small>负载 <b id="hostLoad"><?= $metrics['cpu_load'] !== null ? e(number_format($metrics['cpu_load'], 2)) : '—' ?></b> · <?= (int) $metrics['cpu_cores'] ?> 核</small>
<div class="host-spark"><canvas id="hostCpuChart" width="520" height="90"></canvas></div>
</div>
</div>
<div class="host-meta">
<span>系统:<?= e($metrics['os']) ?></span>
<span>PHP:<?= e($metrics['php']) ?></span>
<span>站点占用:<?= format_size($metrics['site_size']) ?></span>
<span>运行时间:<?= $metrics['uptime'] ? floor($metrics['uptime'] / 86400) . ' 天 ' . floor(($metrics['uptime'] % 86400) / 3600) . ' 小时' : '—' ?></span>
</div>
<?php if (is_superadmin()): ?>
<div class="host-info-card">
<div class="host-info-head">
<div>
<span class="host-label">主机信息</span>
<strong>部署配置</strong>
</div>
</div>
<p class="host-info-tip">以下为当前部署配置,仅超级管理员可见。点击各项中的值即可复制。</p>
<div class="host-db-center <?= $hostIsSqlite ? 'sqlite' : 'mysql' ?>">
<span class="host-db-dot"></span>
<strong><?= $hostIsSqlite ? 'SQLite 轻量版' : 'MySQL' ?></strong>
</div>
<div class="host-info-grid">
<div class="host-info-item">
<span class="host-info-label">主机地址</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostAddress) ?>"><b><?= e($hostAddress) ?></b><em>点击复制</em></button>
</div>
<?php if ($hostIsSqlite): ?>
<div class="host-info-item">
<span class="host-info-label">数据库</span>
<button type="button" class="host-info-value" data-copy-value="SQLite 轻量版"><b>SQLite 轻量版</b><em>点击复制</em></button>
</div>
<div class="host-info-item wide">
<span class="host-info-label">数据文件</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostSqliteDisplay) ?>"><b><?= e($hostSqliteDisplay) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">数据文件大小</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostSqliteSize ? format_size($hostSqliteSize) : '不可用') ?>"><b><?= $hostSqliteSize ? format_size($hostSqliteSize) : '不可用' ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">表前缀</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostPrefix !== '' ? $hostPrefix : '无') ?>"><b><?= e($hostPrefix !== '' ? $hostPrefix : '无') ?></b><em>点击复制</em></button>
</div>
<?php else: ?>
<div class="host-info-item">
<span class="host-info-label">主机端口</span>
<button type="button" class="host-info-value" data-copy-value="<?= e((string) ($hostDb['port'] ?? '3306')) ?>"><b><?= e((string) ($hostDb['port'] ?? '3306')) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">数据库名</span>
<button type="button" class="host-info-value" data-copy-value="<?= e((string) ($hostDb['database'] ?? '')) ?>"><b><?= e($hostDb['database'] ?? '未设置') ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">数据库用户名</span>
<button type="button" class="host-info-value" data-copy-value="<?= e((string) ($hostDb['username'] ?? '')) ?>"><b><?= e($hostDb['username'] ?? '未设置') ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">数据库密码</span>
<div class="host-info-secret">
<b class="host-secret-text" data-secret-b64="<?= e(base64_encode((string) ($hostDb['password'] ?? ''))) ?>" data-secret-shown="0">••••••••</b>
<button type="button" class="host-eye-btn" data-secret-toggle aria-label="显示数据库密码" title="显示密码">
<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M2.5 12s3.6-6 9.5-6 9.5 6 9.5 6-3.6 6-9.5 6-9.5-6-9.5-6Z"/><circle cx="12" cy="12" r="2.6"/></svg>
</button>
<button type="button" class="host-copy-btn" data-secret-copy>复制</button>
</div>
</div>
<div class="host-info-item">
<span class="host-info-label">表前缀</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostPrefix !== '' ? $hostPrefix : '无') ?>"><b><?= e($hostPrefix !== '' ? $hostPrefix : '无') ?></b><em>点击复制</em></button>
</div>
<?php endif; ?>
<div class="host-info-item wide">
<span class="host-info-label">站点地址</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostSiteUrl) ?>"><b><?= e($hostSiteUrl) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">部署目录</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostDeployDir) ?>"><b><?= e($hostDeployDir) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">站点协议</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostScheme) ?>"><b><?= e($hostScheme) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">上传上限</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostUploadMax !== '' ? $hostUploadMax : '未设置') ?>"><b><?= e($hostUploadMax !== '' ? $hostUploadMax : '未设置') ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item">
<span class="host-info-label">PHP 版本</span>
<button type="button" class="host-info-value" data-copy-value="<?= e(PHP_VERSION) ?>"><b><?= e(PHP_VERSION) ?></b><em>点击复制</em></button>
</div>
<div class="host-info-item wide">
<span class="host-info-label">运行环境</span>
<button type="button" class="host-info-value" data-copy-value="<?= e($hostServer !== '' ? $hostServer : $metrics['os']) ?>"><b><?= e($hostServer !== '' ? $hostServer : $metrics['os']) ?></b><em>点击复制</em></button>
</div>
</div>
</div>
<?php endif; ?>
</section>
<script>
(function () {
var cpuData = [];
var chart = document.getElementById('hostCpuChart');
var ctx = chart ? chart.getContext('2d') : null;
function fmt(bytes) {
if (!bytes) return '—';
var units = ['B','KB','MB','GB','TB'];
var i = 0, n = Number(bytes);
while (n >= 1024 && i < units.length - 1) { n /= 1024; i++; }
return n.toFixed(i >= 2 ? 1 : 0) + ' ' + units[i];
}
function pct(used, total) { return total > 0 ? Math.max(0, Math.min(100, used / total * 100)) : 0; }
function draw() {
if (!ctx) return;
var w = chart.width, h = chart.height;
ctx.clearRect(0, 0, w, h);
ctx.strokeStyle = 'rgba(127,160,185,.18)';
ctx.lineWidth = 1;
for (var y = 0; y <= 4; y++) { ctx.beginPath(); ctx.moveTo(0, h * y / 4); ctx.lineTo(w, h * y / 4); ctx.stroke(); }
if (cpuData.length < 2) return;
ctx.beginPath();
ctx.strokeStyle = '#5d9fc6';
ctx.lineWidth = 2;
cpuData.forEach(function (v, i) {
var x = i / Math.max(1, cpuData.length - 1) * w;
var yy = h - v / 100 * h;
if (i === 0) ctx.moveTo(x, yy); else ctx.lineTo(x, yy);
});
ctx.stroke();
ctx.fillStyle = 'rgba(93,159,198,.14)';
ctx.lineTo(w, h); ctx.lineTo(0, h); ctx.closePath(); ctx.fill();
}
function refresh() {
fetch(location.pathname + location.search + (location.search ? '&' : '?') + 'ajax=1', {credentials: 'same-origin'})
.then(function (r) { return r.json(); })
.then(function (d) {
if (!d || !d.ok) return;
document.getElementById('hostMem').textContent = fmt(d.memory_total) || '不可用';
document.getElementById('hostMemFree').textContent = fmt(d.memory_free);
document.getElementById('hostMemBar').style.width = pct(d.memory_used, d.memory_total).toFixed(1) + '%';
document.getElementById('hostDisk').textContent = fmt(d.disk_total) || '不可用';
document.getElementById('hostDiskFree').textContent = fmt(d.disk_free);
document.getElementById('hostDiskBar').style.width = pct(d.disk_used, d.disk_total).toFixed(1) + '%';
var cpu = d.cpu === null || d.cpu === undefined ? null : Number(d.cpu);
document.getElementById('hostCpu').textContent = cpu === null ? '不可用' : cpu.toFixed(1) + '%';
document.getElementById('hostLoad').textContent = d.cpu_load === null ? '—' : Number(d.cpu_load).toFixed(2);
if (cpu !== null) { cpuData.push(cpu); if (cpuData.length > 40) cpuData.shift(); draw(); }
}).catch(function () {});
}
refresh();
setInterval(refresh, 2000);
})();
</script>
<script>
(function () {
function decodeB64(text) {
try {
var bin = atob(text || ''), bytes = new Uint8Array(bin.length);
for (var i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
if (window.TextDecoder) return new TextDecoder('utf-8').decode(bytes);
return decodeURIComponent(escape(bin));
} catch (e) { return ''; }
}
function copyText(text) {
if (!text) return Promise.resolve(false);
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(text).then(function () { return true; }).catch(function () { return fallback(); });
}
return fallback();
function fallback() {
var ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
var ok = false;
try { ok = document.execCommand('copy'); } catch (e) {}
ta.remove();
return Promise.resolve(ok);
}
}
function flash(btn) {
if (!btn) return;
var hint = btn.querySelector('em');
if (!hint) return;
var old = hint.textContent;
hint.textContent = '已复制';
btn.classList.add('copied');
setTimeout(function () { hint.textContent = old; btn.classList.remove('copied'); }, 1200);
}
document.querySelectorAll('.host-info-value[data-copy-value]').forEach(function (btn) {
btn.addEventListener('click', function () {
copyText(btn.getAttribute('data-copy-value') || '').then(function (ok) { if (ok) flash(btn); });
});
});
var secretEl = document.querySelector('.host-secret-text');
var eyeBtn = document.querySelector('[data-secret-toggle]');
var copySecret = document.querySelector('[data-secret-copy]');
if (secretEl && eyeBtn) {
var secret = decodeB64(secretEl.getAttribute('data-secret-b64') || '');
var shown = false;
eyeBtn.addEventListener('click', function () {
shown = !shown;
secretEl.textContent = shown ? (secret || '未设置') : '••••••••';
secretEl.setAttribute('data-secret-shown', shown ? '1' : '0');
eyeBtn.setAttribute('aria-label', shown ? '隐藏数据库密码' : '显示数据库密码');
eyeBtn.setAttribute('title', shown ? '隐藏密码' : '显示密码');
eyeBtn.classList.toggle('is-open', shown);
});
if (copySecret) copySecret.addEventListener('click', function () {
copyText(secret).then(function (ok) {
if (!ok) return;
var old = copySecret.textContent;
copySecret.textContent = '已复制';
setTimeout(function () { copySecret.textContent = old; }, 1200);
});
});
}
})();
</script>
<script>
(function () {
function fallbackCopy(text) {
var ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); } catch (e) {}
document.body.removeChild(ta);
}
function copyText(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).catch(function () { fallbackCopy(text); });
} else {
fallbackCopy(text);
}
}
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-value]'), function (btn) {
btn.addEventListener('click', function () {
copyText(btn.getAttribute('data-copy-value') || '');
var em = btn.querySelector('em');
var old = em ? em.textContent : '';
btn.classList.add('copied');
if (em) em.textContent = '已复制';
setTimeout(function () { btn.classList.remove('copied'); if (em) em.textContent = old || '点击复制'; }, 1600);
});
});
function decodeB64(v) {
try { return decodeURIComponent(escape(atob(v))); } catch (e) { try { return atob(v); } catch (e2) { return ''; } }
}
Array.prototype.forEach.call(document.querySelectorAll('[data-secret-toggle]'), function (btn) {
btn.addEventListener('click', function () {
var text = btn.parentElement.querySelector('.host-secret-text');
if (!text) return;
var shown = text.getAttribute('data-secret-shown') === '1';
if (shown) {
text.textContent = '••••••••';
text.setAttribute('data-secret-shown', '0');
} else {
text.textContent = decodeB64(text.getAttribute('data-secret-b64') || '') || '未设置';
text.setAttribute('data-secret-shown', '1');
}
});
});
Array.prototype.forEach.call(document.querySelectorAll('[data-secret-copy]'), function (btn) {
btn.addEventListener('click', function () {
var text = btn.parentElement.querySelector('.host-secret-text');
if (!text) return;
copyText(decodeB64(text.getAttribute('data-secret-b64') || ''));
var old = btn.textContent;
btn.textContent = '已复制';
setTimeout(function () { btn.textContent = old || '复制'; }, 1600);
});
});
})();
</script>