HCR SUPPORT

This commit is contained in:
2026-09-13 22:31:36 -03:00
parent ede2e9eb89
commit 2b5a8c4452
13 changed files with 2393 additions and 5 deletions
+108
View File
@@ -159,8 +159,10 @@ async function loadServerConfig() {
// BHTTP + BTUN
writeBhttpConfig(c);
writeBtunConfig(c);
writeHcrConfig(c);
loadBhttpHealth();
loadBtunHealth();
loadHcrHealth();
// TLS forwarders
tlsForwardersState = c.tls_forwarders || [];
@@ -241,6 +243,7 @@ async function saveServerConfig() {
} : null,
bhttp: readBhttpConfig(),
btun: readBtunConfig(),
hcr: readHcrConfig(),
tls_forwarders: tlsArr,
xray: {
enabled: document.getElementById("cfgXrayEnabled").checked,
@@ -270,6 +273,7 @@ async function saveServerConfig() {
}
loadBhttpHealth();
loadBtunHealth();
loadHcrHealth();
} catch (e) {
if (e.message === "auth") doAuthError();
else st.textContent = "Error: " + e.message;
@@ -1011,3 +1015,107 @@ window.loadBhttpHealth = loadBhttpHealth;
window.loadBhttpLogs = loadBhttpLogs;
window.loadBtunHealth = loadBtunHealth;
window.loadBtunLogs = loadBtunLogs;
function toggleHcrFields(on) {
const el = document.getElementById("hcrFields");
if (!el) return;
el.style.opacity = on ? "1" : ".4";
el.style.pointerEvents = on ? "" : "none";
}
function writeHcrConfig(c) {
const has = !!c.hcr;
fieldCheck("cfgHcrEnabled", has);
toggleHcrFields(has);
const h = c.hcr || {};
// Sharing the panel's ports (alongside BHTTP) is the least-friction setup, so
// a config that never had an hcr block starts with it on.
fieldCheck("cfgHcrSharedPorts", has ? !!h.shared_ports : true);
fieldSet("cfgHcrListen", (h.listen || []).join("\n"));
fieldSet("cfgHcrMaxSessions", h.max_sessions || 0);
fieldSet("cfgHcrMaxConnections", h.max_connections || 0);
fieldSet("cfgHcrMaxSource", h.max_source_sessions || 0);
fieldSet("cfgHcrMaxFrame", h.max_download_frame || 0);
fieldSet("cfgHcrPollTimeout", h.download_poll_timeout || "");
fieldSet("cfgHcrIdleTimeout", h.idle_session_timeout || "");
fieldSet("cfgHcrAutoRestart", h.auto_restart_interval || "");
fieldSet("cfgHcrRestartGrace", h.auto_restart_grace || "");
fieldCheck("cfgHcrNoConsole", !!h.disable_console_log);
fieldCheck("cfgHcrLogConnections", !!h.log_connections);
}
function readHcrConfig() {
if (!fieldBool("cfgHcrEnabled")) return null;
const listen = readListenLines("cfgHcrListen");
const shared = fieldBool("cfgHcrSharedPorts");
return {
// With shared ports on, a dedicated listener is optional.
listen: listen.length ? listen : (shared ? [] : ["0.0.0.0:8181"]),
shared_ports: shared,
max_sessions: fieldInt("cfgHcrMaxSessions"),
max_connections: fieldInt("cfgHcrMaxConnections"),
max_source_sessions: fieldInt("cfgHcrMaxSource"),
max_download_frame: fieldInt("cfgHcrMaxFrame"),
download_poll_timeout: fieldText("cfgHcrPollTimeout"),
idle_session_timeout: fieldText("cfgHcrIdleTimeout"),
auto_restart_interval: fieldText("cfgHcrAutoRestart"),
auto_restart_grace: fieldText("cfgHcrRestartGrace"),
disable_console_log: fieldBool("cfgHcrNoConsole"),
log_connections: fieldBool("cfgHcrLogConnections"),
};
}
async function loadHcrHealth() {
const summary = document.getElementById("hcrStatusSummary");
if (!summary) return;
try {
const res = await api("/api/hcr");
if (!res.ok) throw new Error(await res.text());
const d = await res.json();
setServiceChip("hcrStatusChip", d);
document.getElementById("hcrActiveSessions").textContent = fmtInt(d.activeSessions);
document.getElementById("hcrActiveConns").textContent = fmtInt(d.activeConnections);
document.getElementById("hcrUploadBytes").textContent = fmtBytes(d.uploadBytes || 0);
document.getElementById("hcrDownloadBytes").textContent = fmtBytes(d.downloadBytes || 0);
renderCounterRows("hcrHealthBody", [
["Sockets accepted", d.accepted],
["Sockets rejected", d.connectionsRejected],
["Sessions created", d.sessionsCreated],
["Sessions rejected", d.sessionsRejected],
["Protocol errors", d.protocolErrors],
]);
if (d.enabled === false) {
summary.textContent = "HCR está desativado na configuração.";
} else if (!d.running) {
summary.textContent = "HCR está ativado mas não está rodando. Verifique se a porta está livre nos logs abaixo.";
} else {
const bad = Number(d.connectionsRejected || 0) + Number(d.sessionsRejected || 0) + Number(d.protocolErrors || 0);
summary.textContent = bad > 0
? `Rodando em ${d.listen || "?"} — atenção: ${fmtInt(bad)} rejeições/erros acumulados.`
: `Rodando em ${d.listen || "?"} — sem rejeições nem erros.`;
}
} catch (e) {
if (e.message === "auth") doAuthError();
else summary.textContent = "Erro ao carregar status: " + e.message;
}
}
async function loadHcrLogs() {
const box = document.getElementById("hcrLogs");
if (!box) return;
box.textContent = "Carregando…";
try {
const res = await api("/api/hcr/logs");
if (!res.ok) throw new Error(await res.text());
const lines = await res.json();
box.textContent = lines && lines.length ? lines.join("\n") : "Sem logs.";
} catch (e) {
if (e.message === "auth") doAuthError();
else box.textContent = "Erro: " + e.message;
}
}
window.toggleHcrFields = toggleHcrFields;
window.loadHcrHealth = loadHcrHealth;
window.loadHcrLogs = loadHcrLogs;
+94 -3
View File
@@ -1231,17 +1231,18 @@
<section class="page-hero" data-tone="blue"><div class="page-hero-copy"><span class="page-kicker">System studio</span><h2>Configurações</h2><p>Rede, SSH, túneis e TLS organizados em blocos visuais e aplicados ao vivo.</p></div></section>
<div class="workspace-nav-shell" data-tone="blue">
<nav class="workspace-section-nav" id="configSectionNav" aria-label="Áreas de configuração" style="--workspace-nav-columns:7">
<nav class="workspace-section-nav" id="configSectionNav" aria-label="Áreas de configuração" style="--workspace-nav-columns:8">
<button class="active" type="button" data-workspace="config" data-workspace-section="general"><span>⌁</span> Rede e SSH</button>
<button type="button" data-workspace="config" data-workspace-section="slowdns"><span>DNS</span> SlowDNS</button>
<button type="button" data-workspace="config" data-workspace-section="udp"><span>⇅</span> UDP Gateway</button>
<button type="button" data-workspace="config" data-workspace-section="bhttp"><span>BH</span> BHTTP</button>
<button type="button" data-workspace="config" data-workspace-section="btun"><span>BT</span> BTUN</button>
<button type="button" data-workspace="config" data-workspace-section="hcr"><span>HC</span> HCR</button>
<button type="button" data-workspace="config" data-workspace-section="tls"><span>◇</span> TLS</button>
<button type="button" data-workspace="config" data-workspace-section="xray"><span>◆</span> Xray</button>
</nav>
<select id="configSection" class="workspace-section-select" data-workspace-select="config" aria-label="Área de configuração">
<option value="general">Rede e SSH</option><option value="slowdns">SlowDNS</option><option value="udp">UDP Gateway</option><option value="bhttp">BHTTP</option><option value="btun">BTUN</option><option value="tls">TLS</option><option value="xray">Xray</option>
<option value="general">Rede e SSH</option><option value="slowdns">SlowDNS</option><option value="udp">UDP Gateway</option><option value="bhttp">BHTTP</option><option value="btun">BTUN</option><option value="hcr">HCR</option><option value="tls">TLS</option><option value="xray">Xray</option>
</select>
</div>
@@ -1667,8 +1668,98 @@
</div>
</section>
<section class="workspace-section" data-workspace-panel="config" data-workspace-section-panel="hcr">
<div class="workspace-section-heading"><div><span>06 · HCR</span><h3>HCR (HTTP/Custom Relay)</h3><p>Túnel de requisição/resposta do UDP-Custom. Cada sessão vai ao servidor SSH interno do painel e pode dividir as mesmas portas do BHTTP.</p></div></div>
<div class="card" style="margin-top:12px">
<div class="card-hdr">
<div class="card-title">HCR Transport</div>
<span class="chip green">live</span>
<label style="font-size:.73rem;display:flex;align-items:center;gap:5px;cursor:pointer;margin-left:auto;">
<input type="checkbox" id="cfgHcrEnabled" onchange="toggleHcrFields(this.checked)"/> Enabled
</label>
</div>
<div id="hcrFields" class="form-grid" style="opacity:.4;pointer-events:none;">
<label style="font-size:.73rem;display:flex;align-items:center;gap:5px;cursor:pointer;grid-column:1/-1">
<input type="checkbox" id="cfgHcrSharedPorts"/> Compartilhar as portas do painel <span class="hint">80/8080 (proxy) e 443 (TLS), junto com BHTTP</span>
</label>
<div class="hint" style="grid-column:1/-1;margin-top:-4px;">
Os listeners existentes distinguem HCR de BHTTP pelo cabeçalho de 62 bytes e pelo byte de versão <code>0x01</code>, então SSH, injeção HTTP e BHTTP na mesma porta continuam funcionando. Com o compartilhamento ligado o campo Listen pode ficar vazio.
</div>
<div class="field" style="grid-column:1/-1">
<label>Listen <span class="hint">um endereço por linha; opcional com portas compartilhadas</span></label>
<textarea id="cfgHcrListen" rows="2" placeholder="0.0.0.0:8181"></textarea>
</div>
<div class="field">
<label>Max Sessions <span class="hint">0 = padrão (10000), -1 = ilimitado</span></label>
<input type="number" id="cfgHcrMaxSessions" placeholder="10000"/>
</div>
<div class="field">
<label>Max Connections <span class="hint">0 = padrão (10000), -1 = ilimitado</span></label>
<input type="number" id="cfgHcrMaxConnections" placeholder="10000"/>
</div>
<div class="field">
<label>Max Sessions Per IP <span class="hint">0 = ilimitado</span></label>
<input type="number" id="cfgHcrMaxSource" min="0" placeholder="0"/>
</div>
<div class="field">
<label>Max Download Frame <span class="hint">bytes; 0 = 16384</span></label>
<input type="number" id="cfgHcrMaxFrame" min="0" placeholder="16384"/>
</div>
<div class="field">
<label>Download Poll Timeout <span class="hint">1s..1m</span></label>
<input type="text" id="cfgHcrPollTimeout" placeholder="10s"/>
</div>
<div class="field">
<label>Idle Session Timeout <span class="hint">10s..1h</span></label>
<input type="text" id="cfgHcrIdleTimeout" placeholder="5m"/>
</div>
<div class="field">
<label>Auto Restart Interval <span class="hint">0s/off desativa</span></label>
<input type="text" id="cfgHcrAutoRestart" placeholder="24h"/>
</div>
<div class="field">
<label>Restart Grace Delay</label>
<input type="text" id="cfgHcrRestartGrace" placeholder="2s"/>
</div>
<div class="hint" style="grid-column:1/-1;margin-top:-4px;">Cada sessão HCR conta como uma conexão SSH da conta: valem o limite de conexões, a banda e a cota de dados do usuário.</div>
<label style="font-size:.73rem;display:flex;align-items:center;gap:5px;cursor:pointer;grid-column:1/-1">
<input type="checkbox" id="cfgHcrNoConsole"/> Disable Console Log
</label>
<label style="font-size:.73rem;display:flex;align-items:center;gap:5px;cursor:pointer;grid-column:1/-1">
<input type="checkbox" id="cfgHcrLogConnections"/> Verbose Connection Logs
</label>
</div>
</div>
<div class="card" style="margin-top:12px">
<div class="card-hdr">
<div class="card-title">Status HCR</div>
<span class="chip" id="hcrStatusChip">—</span>
<button class="btn btn-ghost btn-sm" type="button" onclick="loadHcrHealth()">Atualizar</button>
</div>
<div class="metrics">
<div class="metric"><div class="m-label">Active Sessions</div><div class="m-val" id="hcrActiveSessions">--</div></div>
<div class="metric"><div class="m-label">Active Sockets</div><div class="m-val" id="hcrActiveConns">--</div></div>
<div class="metric"><div class="m-label">Upload</div><div class="m-val" id="hcrUploadBytes">--</div></div>
<div class="metric"><div class="m-label">Download</div><div class="m-val" id="hcrDownloadBytes">--</div></div>
</div>
<div class="tbl-wrap" style="margin-top:10px;">
<table>
<thead><tr><th>Counter</th><th>Value</th><th>Counter</th><th>Value</th></tr></thead>
<tbody id="hcrHealthBody"></tbody>
</table>
</div>
<div class="statusbar"><span id="hcrStatusSummary">Salve a configuração para iniciar o transporte.</span><span class="hint">Rejeições e erros de protocolo devem normalmente ficar em 0.</span></div>
<div class="card-hdr" style="margin-top:12px">
<div class="card-title">Logs HCR</div>
<button class="btn btn-ghost btn-sm" type="button" onclick="loadHcrLogs()">Carregar logs</button>
</div>
<pre id="hcrLogs" class="log-box">—</pre>
</div>
</section>
<section class="workspace-section" data-workspace-panel="config" data-workspace-section-panel="tls">
<div class="workspace-section-heading"><div><span>06 · Segurança</span><h3>Encaminhadores TLS</h3><p>Gerencie os certificados do servidor e crie listeners TLS com certificado automático, colado ou armazenado em arquivo.</p></div></div>
<div class="workspace-section-heading"><div><span>07 · Segurança</span><h3>Encaminhadores TLS</h3><p>Gerencie os certificados do servidor e crie listeners TLS com certificado automático, colado ou armazenado em arquivo.</p></div></div>
<!-- TLS Certificates -->
<div class="card" style="margin-top:12px">