mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 17:45:42 +00:00
03e0e99675
Updated the documentation for RustDesk mass-deployment, including the correct `--config` deploy string format and the addition of editable client server address fields. Enhanced the dashboard with features like **Copy deploy string** and **Intune script** snippets. Introduced a new environment variable `PANEL_PUBLIC_HOST` for better configuration management. Added UI elements for improved user experience in client configuration.
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
/**
|
|
* Resolve the hostname/IP shown in RustDesk client configuration.
|
|
* Clients must reach the server on a public or LAN-routable address, which may
|
|
* differ from the Host header when operators open the panel on localhost.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const conn = require('./agentBundleConnection');
|
|
|
|
function stripRequestHost(rawHost) {
|
|
const raw = String(rawHost || 'localhost');
|
|
const firstHost = raw.split(',')[0].trim();
|
|
|
|
if (firstHost.startsWith('[')) {
|
|
const end = firstHost.indexOf(']');
|
|
return end > 0 ? firstHost.slice(1, end) : firstHost;
|
|
}
|
|
|
|
const colonCount = (firstHost.match(/:/g) || []).length;
|
|
if (colonCount === 1) {
|
|
return firstHost.split(':')[0];
|
|
}
|
|
|
|
return firstHost;
|
|
}
|
|
|
|
/**
|
|
* @param {import('express').Request} [req]
|
|
* @param {string} [queryHost] - optional ?host= override from API caller
|
|
*/
|
|
function resolveClientFacingHost(req, queryHost) {
|
|
if (queryHost) {
|
|
const normalized = conn.normalizeServerHost(queryHost);
|
|
if (normalized.valid) {
|
|
return normalized.host;
|
|
}
|
|
}
|
|
|
|
const panelHost = process.env.PANEL_PUBLIC_HOST;
|
|
if (panelHost) {
|
|
const normalized = conn.normalizeServerHost(panelHost);
|
|
if (normalized.valid) {
|
|
return normalized.host;
|
|
}
|
|
}
|
|
|
|
const fromApi = conn.defaultServerHost();
|
|
if (fromApi) {
|
|
return fromApi;
|
|
}
|
|
|
|
if (req) {
|
|
const rawHost = req.headers['x-forwarded-host'] || req.headers.host || req.hostname || 'localhost';
|
|
return stripRequestHost(rawHost);
|
|
}
|
|
|
|
return 'localhost';
|
|
}
|
|
|
|
module.exports = {
|
|
resolveClientFacingHost,
|
|
stripRequestHost,
|
|
};
|