unplugin-https-reverse-proxy 4.1.0-beta.8 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-ICH7VY4H.js → chunk-U6J2RMIR.js} +211 -109
- package/dist/esbuild.cjs +223 -121
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +223 -121
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +221 -121
- package/dist/nuxt.js +1 -1
- package/dist/privileged-helper.cjs +154 -56
- package/dist/privileged-helper.js +144 -46
- package/dist/rollup.cjs +223 -121
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +223 -121
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +223 -121
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +223 -121
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/caddyfile.ts +2 -0
- package/src/caddy/config.ts +57 -34
- package/src/caddy/constants.ts +30 -1
- package/src/caddy/index.ts +44 -49
- package/src/caddy/privileged.ts +3 -0
- package/src/index.ts +5 -0
- package/src/privileged/bootstrap.ts +27 -7
- package/src/privileged/client.ts +1 -1
- package/src/privileged/launch.ts +95 -11
- package/src/privileged/path-guard.ts +106 -0
- package/src/privileged/server.ts +36 -4
- package/src/privileged/session.ts +3 -0
- package/src/privileged/windows-elevation.ts +91 -33
- package/src/privileged-helper.ts +49 -9
package/dist/rspack.cjs
CHANGED
|
@@ -42,10 +42,10 @@ var import_unplugin = require("unplugin");
|
|
|
42
42
|
|
|
43
43
|
// src/caddy/index.ts
|
|
44
44
|
var import_node_child_process3 = require("child_process");
|
|
45
|
-
var
|
|
45
|
+
var import_node_fs5 = require("fs");
|
|
46
46
|
var import_promises2 = require("fs/promises");
|
|
47
47
|
var import_node_os5 = require("os");
|
|
48
|
-
var
|
|
48
|
+
var import_node_path6 = require("path");
|
|
49
49
|
var import_node_process8 = __toESM(require("process"), 1);
|
|
50
50
|
var import_got_cjs = require("got-cjs");
|
|
51
51
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
@@ -12938,6 +12938,7 @@ var ProxyType = type({
|
|
|
12938
12938
|
});
|
|
12939
12939
|
var CaddyContext = type({
|
|
12940
12940
|
caddy_root: "string",
|
|
12941
|
+
admin_socket: "string",
|
|
12941
12942
|
proxies: ProxyType.array()
|
|
12942
12943
|
});
|
|
12943
12944
|
function validateTemplateContext(ctx) {
|
|
@@ -12950,6 +12951,7 @@ var caddyTemplate = `{
|
|
|
12950
12951
|
debug
|
|
12951
12952
|
auto_https disable_redirects ignore_loaded_certs
|
|
12952
12953
|
skip_install_trust
|
|
12954
|
+
admin unix/{{ admin_socket }}
|
|
12953
12955
|
}
|
|
12954
12956
|
|
|
12955
12957
|
:7601 {
|
|
@@ -13047,11 +13049,20 @@ function resolvePath(path) {
|
|
|
13047
13049
|
return (0, import_node_path.join)(import_node_os2.default.homedir() || "", path.slice(1));
|
|
13048
13050
|
return path;
|
|
13049
13051
|
}
|
|
13050
|
-
|
|
13052
|
+
function defaultTempDir() {
|
|
13053
|
+
const fromEnv = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR;
|
|
13054
|
+
if (fromEnv)
|
|
13055
|
+
return resolvePath(fromEnv);
|
|
13056
|
+
if (import_node_process.default.platform === "linux")
|
|
13057
|
+
return (0, import_node_path.join)(import_node_process.default.env.XDG_CACHE_HOME || (0, import_node_path.join)(import_node_os2.default.homedir(), ".cache"), "uhrp");
|
|
13058
|
+
return "/tmp";
|
|
13059
|
+
}
|
|
13060
|
+
var TEMP_DIR = resolvePath(import_node_process.default.env.UHRP_CADDY_PATH || defaultTempDir());
|
|
13051
13061
|
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
13052
13062
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
13053
13063
|
var caddyConfigPath = (0, import_node_path.join)(TEMP_DIR, ".CADDYFILE.config.json");
|
|
13054
13064
|
var caddyLockFilePath = (0, import_node_path.join)(TEMP_DIR, "caddylock");
|
|
13065
|
+
var caddyAdminSocketPath = (0, import_node_path.join)(TEMP_DIR, "caddy-admin.sock");
|
|
13055
13066
|
var supportList = [
|
|
13056
13067
|
{
|
|
13057
13068
|
platform: "dragonfly",
|
|
@@ -13174,12 +13185,12 @@ function isAlive(pid) {
|
|
|
13174
13185
|
return false;
|
|
13175
13186
|
}
|
|
13176
13187
|
}
|
|
13177
|
-
function readConfig() {
|
|
13178
|
-
if (!(0, import_node_fs.existsSync)(
|
|
13188
|
+
function readConfig(path = caddyConfigPath) {
|
|
13189
|
+
if (!(0, import_node_fs.existsSync)(path))
|
|
13179
13190
|
return {};
|
|
13180
13191
|
let parsed2;
|
|
13181
13192
|
try {
|
|
13182
|
-
parsed2 = JSON.parse((0, import_node_fs.readFileSync)(
|
|
13193
|
+
parsed2 = JSON.parse((0, import_node_fs.readFileSync)(path, "utf-8"));
|
|
13183
13194
|
} catch {
|
|
13184
13195
|
return {};
|
|
13185
13196
|
}
|
|
@@ -13190,53 +13201,54 @@ function readConfig() {
|
|
|
13190
13201
|
}
|
|
13191
13202
|
return alive;
|
|
13192
13203
|
}
|
|
13193
|
-
function writeConfig(proxies) {
|
|
13204
|
+
function writeConfig(proxies, path = caddyConfigPath) {
|
|
13194
13205
|
const content = JSON.stringify(proxies, null, 2);
|
|
13195
|
-
const temp = `${
|
|
13206
|
+
const temp = `${path}.${import_node_process2.default.pid}.tmp`;
|
|
13196
13207
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13197
|
-
(0, import_node_fs.renameSync)(temp,
|
|
13198
|
-
}
|
|
13199
|
-
async function mutateConfig(lock3, mutate) {
|
|
13200
|
-
const release = await lock3.acquire();
|
|
13201
|
-
try {
|
|
13202
|
-
const proxies = readConfig();
|
|
13203
|
-
mutate(proxies);
|
|
13204
|
-
writeConfig(proxies);
|
|
13205
|
-
return proxies;
|
|
13206
|
-
} finally {
|
|
13207
|
-
release();
|
|
13208
|
-
}
|
|
13208
|
+
(0, import_node_fs.renameSync)(temp, path);
|
|
13209
13209
|
}
|
|
13210
13210
|
function useCaddyConfig(options = {}) {
|
|
13211
13211
|
const lock3 = options.lock ?? createFileLock();
|
|
13212
|
+
const configPath = options.configPath ?? caddyConfigPath;
|
|
13213
|
+
async function mutate(apply) {
|
|
13214
|
+
var _a4;
|
|
13215
|
+
const release = await lock3.acquire();
|
|
13216
|
+
try {
|
|
13217
|
+
const proxies = readConfig(configPath);
|
|
13218
|
+
apply(proxies);
|
|
13219
|
+
writeConfig(proxies, configPath);
|
|
13220
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13221
|
+
return proxies;
|
|
13222
|
+
} finally {
|
|
13223
|
+
release();
|
|
13224
|
+
}
|
|
13225
|
+
}
|
|
13212
13226
|
return {
|
|
13213
|
-
configJsonRef: () => (0, import_node_fs.existsSync)(
|
|
13227
|
+
configJsonRef: () => (0, import_node_fs.existsSync)(configPath) ? readConfig(configPath) : void 0,
|
|
13214
13228
|
async writeCaddyConfig(_proxies, key) {
|
|
13215
|
-
await
|
|
13229
|
+
await mutate((proxies) => {
|
|
13216
13230
|
for (const p of _proxies)
|
|
13217
13231
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13218
13232
|
});
|
|
13219
13233
|
},
|
|
13220
13234
|
async removeProxy(key) {
|
|
13221
|
-
|
|
13235
|
+
await mutate((current) => {
|
|
13222
13236
|
for (const route of Object.keys(current)) {
|
|
13223
13237
|
if (route.endsWith(`#${key}`))
|
|
13224
13238
|
delete current[route];
|
|
13225
13239
|
}
|
|
13226
13240
|
});
|
|
13227
|
-
if (Object.keys(proxies).length === 0)
|
|
13228
|
-
removeConfigFile();
|
|
13229
13241
|
},
|
|
13230
|
-
readProxies: () => readConfig(),
|
|
13242
|
+
readProxies: () => readConfig(configPath),
|
|
13231
13243
|
async cleanUp() {
|
|
13232
|
-
removeConfigFile();
|
|
13244
|
+
removeConfigFile(configPath);
|
|
13233
13245
|
}
|
|
13234
13246
|
};
|
|
13235
13247
|
}
|
|
13236
|
-
function removeConfigFile() {
|
|
13248
|
+
function removeConfigFile(path = caddyConfigPath) {
|
|
13237
13249
|
try {
|
|
13238
|
-
if ((0, import_node_fs.existsSync)(
|
|
13239
|
-
(0, import_node_fs.unlinkSync)(
|
|
13250
|
+
if ((0, import_node_fs.existsSync)(path))
|
|
13251
|
+
(0, import_node_fs.unlinkSync)(path);
|
|
13240
13252
|
} catch {
|
|
13241
13253
|
}
|
|
13242
13254
|
}
|
|
@@ -13282,7 +13294,7 @@ function isCaddyReloadCancellation(line) {
|
|
|
13282
13294
|
// src/caddy/privileged.ts
|
|
13283
13295
|
var import_node_buffer2 = require("buffer");
|
|
13284
13296
|
var import_node_events = require("events");
|
|
13285
|
-
var
|
|
13297
|
+
var import_node_path5 = require("path");
|
|
13286
13298
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
13287
13299
|
var import_node_url = require("url");
|
|
13288
13300
|
|
|
@@ -13318,16 +13330,18 @@ function findUp(from, relative, exists2) {
|
|
|
13318
13330
|
|
|
13319
13331
|
// src/privileged/session.ts
|
|
13320
13332
|
var import_node_buffer = require("buffer");
|
|
13321
|
-
var
|
|
13333
|
+
var import_node_fs4 = require("fs");
|
|
13322
13334
|
var import_promises = require("fs/promises");
|
|
13323
13335
|
var import_node_os4 = require("os");
|
|
13324
|
-
var
|
|
13336
|
+
var import_node_path4 = require("path");
|
|
13325
13337
|
var lockfile2 = __toESM(require("proper-lockfile"), 1);
|
|
13326
13338
|
|
|
13327
13339
|
// src/privileged/launch.ts
|
|
13328
13340
|
var import_node_child_process2 = require("child_process");
|
|
13329
13341
|
var import_node_crypto = require("crypto");
|
|
13342
|
+
var import_node_fs3 = require("fs");
|
|
13330
13343
|
var import_node_os3 = require("os");
|
|
13344
|
+
var import_node_path3 = require("path");
|
|
13331
13345
|
var import_node_process6 = __toESM(require("process"), 1);
|
|
13332
13346
|
|
|
13333
13347
|
// src/privileged/client.ts
|
|
@@ -13441,7 +13455,7 @@ async function connectClient(options) {
|
|
|
13441
13455
|
} catch (error) {
|
|
13442
13456
|
lastError = error;
|
|
13443
13457
|
const code = lastError.code;
|
|
13444
|
-
if (code === "EACCES" || lastError instanceof HelperConnectionError)
|
|
13458
|
+
if (code === "EACCES" || code === "EPERM" || lastError instanceof HelperConnectionError)
|
|
13445
13459
|
throw lastError;
|
|
13446
13460
|
await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
|
|
13447
13461
|
}
|
|
@@ -13573,39 +13587,78 @@ function createClient(socket, initialBuffer, callTimeoutMs) {
|
|
|
13573
13587
|
// src/privileged/windows-elevation.ts
|
|
13574
13588
|
var import_node_child_process = require("child_process");
|
|
13575
13589
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
13590
|
+
var ERROR_CANCELLED = 1223;
|
|
13576
13591
|
function quotePowerShell(value2) {
|
|
13577
13592
|
return `'${value2.replace(/'/g, "''")}'`;
|
|
13578
13593
|
}
|
|
13594
|
+
function quoteWindowsArg(arg) {
|
|
13595
|
+
if (arg === "")
|
|
13596
|
+
return '""';
|
|
13597
|
+
if (!/[\s"]/.test(arg))
|
|
13598
|
+
return arg;
|
|
13599
|
+
let quoted = '"';
|
|
13600
|
+
let backslashes = 0;
|
|
13601
|
+
for (const char of arg) {
|
|
13602
|
+
if (char === "\\") {
|
|
13603
|
+
backslashes++;
|
|
13604
|
+
continue;
|
|
13605
|
+
}
|
|
13606
|
+
quoted += char === '"' ? `${"\\".repeat(backslashes * 2 + 1)}"` : `${"\\".repeat(backslashes)}${char}`;
|
|
13607
|
+
backslashes = 0;
|
|
13608
|
+
}
|
|
13609
|
+
return `${quoted}${"\\".repeat(backslashes * 2)}"`;
|
|
13610
|
+
}
|
|
13579
13611
|
function buildElevationCommand(options) {
|
|
13580
|
-
const
|
|
13581
|
-
|
|
13582
|
-
"
|
|
13583
|
-
"-
|
|
13584
|
-
quotePowerShell(options.file)
|
|
13612
|
+
const lines = [
|
|
13613
|
+
// The message read back on failure is localized; keep it readable as UTF-8.
|
|
13614
|
+
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
|
|
13615
|
+
"$psi = New-Object System.Diagnostics.ProcessStartInfo",
|
|
13616
|
+
`$psi.FileName = ${quotePowerShell(options.file)}`,
|
|
13617
|
+
`$psi.Arguments = ${quotePowerShell(options.args.map(quoteWindowsArg).join(" "))}`
|
|
13585
13618
|
];
|
|
13586
|
-
if (argumentList)
|
|
13587
|
-
parts.push("-ArgumentList", argumentList);
|
|
13588
13619
|
if (options.cwd)
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13620
|
+
lines.push(`$psi.WorkingDirectory = ${quotePowerShell(options.cwd)}`);
|
|
13621
|
+
lines.push(
|
|
13622
|
+
"$psi.Verb = 'runas'",
|
|
13623
|
+
"$psi.UseShellExecute = $true",
|
|
13624
|
+
"$psi.WindowStyle = 'Hidden'",
|
|
13625
|
+
"try { $p = [System.Diagnostics.Process]::Start($psi); if ($p) { [Console]::Out.Write($p.Id) } }",
|
|
13626
|
+
`catch { $e = $_.Exception; while ($e.InnerException) { $e = $e.InnerException }; if ($e.NativeErrorCode -eq ${ERROR_CANCELLED}) { exit ${ERROR_CANCELLED} }; [Console]::Error.Write($e.Message); exit 1 }`
|
|
13627
|
+
);
|
|
13628
|
+
return lines.join("\n");
|
|
13593
13629
|
}
|
|
13594
13630
|
function spawnElevatedOnWindows(options) {
|
|
13595
|
-
return new Promise((resolve2
|
|
13596
|
-
const script = buildElevationCommand(options);
|
|
13631
|
+
return new Promise((resolve2) => {
|
|
13597
13632
|
const child = (0, import_node_child_process.spawn)(
|
|
13598
13633
|
"powershell.exe",
|
|
13599
|
-
["-NoProfile", "-NonInteractive", "-Command",
|
|
13600
|
-
{ stdio: "ignore", windowsHide: true }
|
|
13634
|
+
["-NoProfile", "-NonInteractive", "-Command", buildElevationCommand(options)],
|
|
13635
|
+
{ stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
|
|
13601
13636
|
);
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
));
|
|
13637
|
+
let stdout = "";
|
|
13638
|
+
let stderr = "";
|
|
13639
|
+
child.stdout.on("data", (data) => {
|
|
13640
|
+
stdout += data.toString();
|
|
13641
|
+
});
|
|
13642
|
+
child.stderr.on("data", (data) => {
|
|
13643
|
+
stderr = (stderr + data.toString()).slice(-4096);
|
|
13644
|
+
});
|
|
13645
|
+
child.once("error", (error) => resolve2({
|
|
13646
|
+
ok: false,
|
|
13647
|
+
denied: false,
|
|
13648
|
+
message: `could not start PowerShell to request administrator permission: ${error.message}`
|
|
13649
|
+
}));
|
|
13650
|
+
child.once("close", (code) => {
|
|
13651
|
+
if (code === 0) {
|
|
13652
|
+
const pid = Number(stdout.trim());
|
|
13653
|
+
return resolve2({ ok: true, pid: Number.isSafeInteger(pid) && pid > 0 ? pid : void 0 });
|
|
13654
|
+
}
|
|
13655
|
+
if (code === ERROR_CANCELLED)
|
|
13656
|
+
return resolve2({ ok: false, denied: true, message: "administrator permission was cancelled" });
|
|
13657
|
+
resolve2({
|
|
13658
|
+
ok: false,
|
|
13659
|
+
denied: false,
|
|
13660
|
+
message: `could not start the privileged helper as administrator (PowerShell exited with ${code}).${stderr.trim() ? ` ${stderr.trim()}` : ""}`
|
|
13661
|
+
});
|
|
13609
13662
|
});
|
|
13610
13663
|
});
|
|
13611
13664
|
}
|
|
@@ -13732,11 +13785,22 @@ async function startPrivilegedHelper(options) {
|
|
|
13732
13785
|
"--caddy",
|
|
13733
13786
|
options.caddyBin,
|
|
13734
13787
|
"--caddy-config",
|
|
13735
|
-
options.caddyConfigPath
|
|
13788
|
+
options.caddyConfigPath,
|
|
13789
|
+
...options.caddyAdminSocket ? ["--caddy-admin", options.caddyAdminSocket] : []
|
|
13736
13790
|
];
|
|
13737
13791
|
let child;
|
|
13792
|
+
let helperExited;
|
|
13738
13793
|
if (!direct && (0, import_node_os3.platform)() === "win32") {
|
|
13739
|
-
|
|
13794
|
+
const errorFile = (0, import_node_path3.join)((0, import_node_os3.tmpdir)(), `uhrp-helper-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.log`);
|
|
13795
|
+
const elevated = await spawnElevatedOnWindows({
|
|
13796
|
+
file: helperEntry,
|
|
13797
|
+
args: [...childArgv, "--error-file", errorFile],
|
|
13798
|
+
cwd: import_node_process6.default.cwd()
|
|
13799
|
+
});
|
|
13800
|
+
if (!elevated.ok)
|
|
13801
|
+
throw elevated.denied ? new PrivilegeDeniedError(elevated.message) : new Error(elevated.message);
|
|
13802
|
+
if (elevated.pid !== void 0)
|
|
13803
|
+
helperExited = watchWindowsHelper(elevated.pid, errorFile);
|
|
13740
13804
|
} else {
|
|
13741
13805
|
const command = direct ? helperEntry : sudoCommand;
|
|
13742
13806
|
const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
|
|
@@ -13744,20 +13808,36 @@ async function startPrivilegedHelper(options) {
|
|
|
13744
13808
|
stdio: ["ignore", "pipe", "pipe"]
|
|
13745
13809
|
});
|
|
13746
13810
|
(_a4 = child.stdout) == null ? void 0 : _a4.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
|
|
13747
|
-
|
|
13748
|
-
|
|
13811
|
+
let stderr = "";
|
|
13812
|
+
(_b3 = child.stderr) == null ? void 0 : _b3.on("data", (data) => {
|
|
13813
|
+
stderr = (stderr + data.toString()).slice(-4096);
|
|
13814
|
+
log == null ? void 0 : log(data.toString().trimEnd());
|
|
13815
|
+
});
|
|
13816
|
+
const exited = new Promise((resolve2) => {
|
|
13817
|
+
child.once("error", (error) => {
|
|
13818
|
+
stderr = error.message;
|
|
13819
|
+
});
|
|
13820
|
+
child.once("close", (code) => resolve2(code));
|
|
13821
|
+
});
|
|
13749
13822
|
const earlyExit = await Promise.race([
|
|
13750
13823
|
exited,
|
|
13751
13824
|
new Promise((resolve2) => setTimeout(() => resolve2(void 0), 500))
|
|
13752
13825
|
]);
|
|
13753
13826
|
if (earlyExit !== void 0 && earlyExit !== 0) {
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
)
|
|
13827
|
+
const detail = stderr.trim();
|
|
13828
|
+
let guidance = "";
|
|
13829
|
+
if (/\b(?:EACCES|EPERM)\b/.test(detail))
|
|
13830
|
+
guidance = " Check the path named above and its parent directories. Fix ownership or access manually; do not use chmod 777.";
|
|
13831
|
+
else if (!direct && /^sudo:/m.test(detail))
|
|
13832
|
+
guidance = " Retry from a terminal where sudo can request permission, or ask an administrator to grant access.";
|
|
13833
|
+
throw new Error(`privileged helper exited with code ${earlyExit}.${detail ? ` ${detail}${guidance}` : " No diagnostic output from the helper or sudo."}`);
|
|
13757
13834
|
}
|
|
13758
13835
|
}
|
|
13759
13836
|
try {
|
|
13760
|
-
const
|
|
13837
|
+
const connecting = connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
|
|
13838
|
+
connecting.catch(() => {
|
|
13839
|
+
});
|
|
13840
|
+
const client = await (helperExited ? Promise.race([connecting, helperExited.promise]) : connecting);
|
|
13761
13841
|
return {
|
|
13762
13842
|
client,
|
|
13763
13843
|
async close() {
|
|
@@ -13772,6 +13852,42 @@ async function startPrivilegedHelper(options) {
|
|
|
13772
13852
|
} catch {
|
|
13773
13853
|
}
|
|
13774
13854
|
throw error;
|
|
13855
|
+
} finally {
|
|
13856
|
+
helperExited == null ? void 0 : helperExited.stop();
|
|
13857
|
+
}
|
|
13858
|
+
}
|
|
13859
|
+
function watchWindowsHelper(pid, errorFile) {
|
|
13860
|
+
let timer;
|
|
13861
|
+
const promise = new Promise((_, reject2) => {
|
|
13862
|
+
timer = setInterval(() => {
|
|
13863
|
+
if (isProcessRunning(pid))
|
|
13864
|
+
return;
|
|
13865
|
+
clearInterval(timer);
|
|
13866
|
+
let detail = "";
|
|
13867
|
+
try {
|
|
13868
|
+
detail = (0, import_node_fs3.readFileSync)(errorFile, "utf8").trim().slice(-4096);
|
|
13869
|
+
} catch {
|
|
13870
|
+
}
|
|
13871
|
+
reject2(new Error(`privileged helper exited before accepting connections.${detail ? ` ${detail}` : " No diagnostic output from the helper."}`));
|
|
13872
|
+
}, 250);
|
|
13873
|
+
});
|
|
13874
|
+
return {
|
|
13875
|
+
promise,
|
|
13876
|
+
stop() {
|
|
13877
|
+
clearInterval(timer);
|
|
13878
|
+
try {
|
|
13879
|
+
(0, import_node_fs3.rmSync)(errorFile, { force: true });
|
|
13880
|
+
} catch {
|
|
13881
|
+
}
|
|
13882
|
+
}
|
|
13883
|
+
};
|
|
13884
|
+
}
|
|
13885
|
+
function isProcessRunning(pid) {
|
|
13886
|
+
try {
|
|
13887
|
+
import_node_process6.default.kill(pid, 0);
|
|
13888
|
+
return true;
|
|
13889
|
+
} catch (error) {
|
|
13890
|
+
return error.code !== "ESRCH";
|
|
13775
13891
|
}
|
|
13776
13892
|
}
|
|
13777
13893
|
async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
@@ -13784,12 +13900,12 @@ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
|
13784
13900
|
|
|
13785
13901
|
// src/privileged/session.ts
|
|
13786
13902
|
function tokenPath(runtimeDir) {
|
|
13787
|
-
return (0,
|
|
13903
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.token");
|
|
13788
13904
|
}
|
|
13789
13905
|
function sessionSocketPath(runtimeDir) {
|
|
13790
13906
|
if ((0, import_node_os4.platform)() === "win32")
|
|
13791
13907
|
return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
|
|
13792
|
-
return (0,
|
|
13908
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.sock");
|
|
13793
13909
|
}
|
|
13794
13910
|
async function openHelperSession(scope2) {
|
|
13795
13911
|
const socketPath = sessionSocketPath(scope2.runtimeDir);
|
|
@@ -13804,7 +13920,7 @@ async function openHelperSession(scope2) {
|
|
|
13804
13920
|
}
|
|
13805
13921
|
}
|
|
13806
13922
|
async function tryReuse(socketPath, scope2) {
|
|
13807
|
-
if (!(0,
|
|
13923
|
+
if (!(0, import_node_fs4.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
|
|
13808
13924
|
return void 0;
|
|
13809
13925
|
const token = await readToken(scope2.runtimeDir);
|
|
13810
13926
|
if (!token)
|
|
@@ -13834,6 +13950,7 @@ async function startNew(socketPath, scope2) {
|
|
|
13834
13950
|
caddyStoragePath: scope2.caddyStoragePath,
|
|
13835
13951
|
caddyBin: scope2.caddyBin,
|
|
13836
13952
|
caddyConfigPath: scope2.caddyConfigPath,
|
|
13953
|
+
caddyAdminSocket: scope2.caddyAdminSocket,
|
|
13837
13954
|
reason: scope2.reason,
|
|
13838
13955
|
log: scope2.log
|
|
13839
13956
|
});
|
|
@@ -13847,7 +13964,7 @@ async function startNew(socketPath, scope2) {
|
|
|
13847
13964
|
};
|
|
13848
13965
|
}
|
|
13849
13966
|
async function acquireStartLock(runtimeDir) {
|
|
13850
|
-
const lockPath = (0,
|
|
13967
|
+
const lockPath = (0, import_node_path4.join)(runtimeDir, "helper.start.lock");
|
|
13851
13968
|
try {
|
|
13852
13969
|
await (0, import_promises.writeFile)(lockPath, "", { flag: "a" });
|
|
13853
13970
|
} catch {
|
|
@@ -13881,7 +13998,7 @@ async function writeToken(runtimeDir, token) {
|
|
|
13881
13998
|
// src/caddy/privileged.ts
|
|
13882
13999
|
var import_meta = {};
|
|
13883
14000
|
function resolvePrivilegedEnv() {
|
|
13884
|
-
const moduleDir = typeof __dirname === "string" ? __dirname : (0,
|
|
14001
|
+
const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
13885
14002
|
const resolved = resolveHelperEntry({ moduleDir });
|
|
13886
14003
|
return { helperEntry: resolved.entry, helperArgs: resolved.args };
|
|
13887
14004
|
}
|
|
@@ -13921,7 +14038,7 @@ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
|
|
|
13921
14038
|
}
|
|
13922
14039
|
};
|
|
13923
14040
|
function caddyStoragePath() {
|
|
13924
|
-
return import_node_process7.default.platform === "win32" ? (0,
|
|
14041
|
+
return import_node_process7.default.platform === "win32" ? (0, import_node_path5.join)(import_node_process7.default.env.AppData ?? "", "Caddy") : (0, import_node_path5.join)(import_node_process7.default.env.HOME ?? "", "Library/Application Support/Caddy");
|
|
13925
14042
|
}
|
|
13926
14043
|
function openPrivilegedSession(runtimeDir, options) {
|
|
13927
14044
|
const env2 = resolvePrivilegedEnv();
|
|
@@ -13937,6 +14054,7 @@ function openPrivilegedSession(runtimeDir, options) {
|
|
|
13937
14054
|
// execute a path supplied over the socket.
|
|
13938
14055
|
caddyBin: options.caddyBin,
|
|
13939
14056
|
caddyConfigPath: options.caddyConfigPath,
|
|
14057
|
+
caddyAdminSocket: options.caddyAdminSocket,
|
|
13940
14058
|
reason: options.reason,
|
|
13941
14059
|
log: options.log
|
|
13942
14060
|
});
|
|
@@ -14064,11 +14182,11 @@ async function download() {
|
|
|
14064
14182
|
if (await testCaddy())
|
|
14065
14183
|
return caddyPath;
|
|
14066
14184
|
return new Promise((resolve2, reject2) => {
|
|
14067
|
-
if (!(0,
|
|
14068
|
-
(0,
|
|
14069
|
-
(0,
|
|
14185
|
+
if (!(0, import_node_fs5.existsSync)(TEMP_DIR)) {
|
|
14186
|
+
(0, import_node_fs5.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
14187
|
+
(0, import_node_fs5.chmodSync)(TEMP_DIR, 448);
|
|
14070
14188
|
}
|
|
14071
|
-
const file = (0,
|
|
14189
|
+
const file = (0, import_node_fs5.createWriteStream)(caddyPath);
|
|
14072
14190
|
let _platform = (0, import_node_os5.platform)().toString();
|
|
14073
14191
|
_platform === "win32" && (_platform = "windows");
|
|
14074
14192
|
let _arch = import_node_process8.default.arch.toString();
|
|
@@ -14077,13 +14195,13 @@ async function download() {
|
|
|
14077
14195
|
if (!support)
|
|
14078
14196
|
return reject2(new Error("not support"));
|
|
14079
14197
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
|
|
14080
|
-
(0,
|
|
14198
|
+
(0, import_node_fs5.existsSync)(caddyPath) && (0, import_node_fs5.unlinkSync)(caddyPath);
|
|
14081
14199
|
const httpProxy = import_node_process8.default.env.HTTP_PROXY || import_node_process8.default.env.http_proxy;
|
|
14082
14200
|
const httpsProxy = import_node_process8.default.env.HTTPS_PROXY || import_node_process8.default.env.https_proxy;
|
|
14083
14201
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
14084
14202
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
14085
14203
|
const chmodCaddyOnce = once(() => {
|
|
14086
|
-
(0,
|
|
14204
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14087
14205
|
});
|
|
14088
14206
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
14089
14207
|
agent: {
|
|
@@ -14097,7 +14215,7 @@ async function download() {
|
|
|
14097
14215
|
logProgressOver();
|
|
14098
14216
|
if (import_node_process8.default.platform === "win32")
|
|
14099
14217
|
return resolve2(caddyPath);
|
|
14100
|
-
(0,
|
|
14218
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14101
14219
|
resolve2(caddyPath);
|
|
14102
14220
|
}).on("error", (err) => {
|
|
14103
14221
|
reject2(err);
|
|
@@ -14106,10 +14224,10 @@ async function download() {
|
|
|
14106
14224
|
}
|
|
14107
14225
|
function testCaddy() {
|
|
14108
14226
|
return new Promise((resolve2) => {
|
|
14109
|
-
if (!(0,
|
|
14227
|
+
if (!(0, import_node_fs5.existsSync)(caddyPath))
|
|
14110
14228
|
return resolve2(false);
|
|
14111
14229
|
try {
|
|
14112
|
-
(0,
|
|
14230
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14113
14231
|
} catch {
|
|
14114
14232
|
}
|
|
14115
14233
|
(0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
|
|
@@ -14119,10 +14237,27 @@ function testCaddy() {
|
|
|
14119
14237
|
});
|
|
14120
14238
|
});
|
|
14121
14239
|
}
|
|
14240
|
+
function caddyRootPath() {
|
|
14241
|
+
return (0, import_node_path6.join)(
|
|
14242
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14243
|
+
"./pki/authorities/local"
|
|
14244
|
+
);
|
|
14245
|
+
}
|
|
14246
|
+
async function renderCaddyfile(proxies) {
|
|
14247
|
+
const ctx = validateTemplateContext({
|
|
14248
|
+
caddy_root: caddyRootPath(),
|
|
14249
|
+
admin_socket: caddyAdminSocketPath,
|
|
14250
|
+
proxies: Object.values(proxies)
|
|
14251
|
+
});
|
|
14252
|
+
const content = await genCaddyfile(ctx);
|
|
14253
|
+
const temp = `${caddyFilePath}.${import_node_process8.default.pid}.tmp`;
|
|
14254
|
+
await (0, import_promises2.writeFile)(temp, content);
|
|
14255
|
+
await (0, import_promises2.rename)(temp, caddyFilePath);
|
|
14256
|
+
}
|
|
14122
14257
|
var caddyConfig;
|
|
14123
14258
|
function getCaddyConfig() {
|
|
14124
14259
|
if (!caddyConfig) {
|
|
14125
|
-
caddyConfig = useCaddyConfig();
|
|
14260
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14126
14261
|
}
|
|
14127
14262
|
return caddyConfig;
|
|
14128
14263
|
}
|
|
@@ -14144,6 +14279,7 @@ var defaultDependencies = {
|
|
|
14144
14279
|
// helper must never execute something named in a request.
|
|
14145
14280
|
caddyBin: caddyPath,
|
|
14146
14281
|
caddyConfigPath: caddyFilePath,
|
|
14282
|
+
caddyAdminSocket: caddyAdminSocketPath,
|
|
14147
14283
|
reason
|
|
14148
14284
|
}),
|
|
14149
14285
|
config: () => getCaddyConfig()
|
|
@@ -14165,12 +14301,14 @@ var CaddyInstant = class {
|
|
|
14165
14301
|
async session(reason) {
|
|
14166
14302
|
if (this._session && !this._session.client.connected)
|
|
14167
14303
|
this._session = void 0;
|
|
14168
|
-
if (!this._session)
|
|
14304
|
+
if (!this._session) {
|
|
14305
|
+
await this.deps.config().writeCaddyConfig([], this.proxyKey);
|
|
14169
14306
|
this._session = await this.deps.openSession(TEMP_DIR, reason);
|
|
14307
|
+
}
|
|
14170
14308
|
return this._session;
|
|
14171
14309
|
}
|
|
14172
14310
|
async getCaddyfile() {
|
|
14173
|
-
if (!(0,
|
|
14311
|
+
if (!(0, import_node_fs5.existsSync)(caddyFilePath)) {
|
|
14174
14312
|
this.caddyfile = "";
|
|
14175
14313
|
return "";
|
|
14176
14314
|
}
|
|
@@ -14178,10 +14316,7 @@ var CaddyInstant = class {
|
|
|
14178
14316
|
return this.caddyfile;
|
|
14179
14317
|
}
|
|
14180
14318
|
get caddyRoot() {
|
|
14181
|
-
return (
|
|
14182
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14183
|
-
"./pki/authorities/local"
|
|
14184
|
-
);
|
|
14319
|
+
return caddyRootPath();
|
|
14185
14320
|
}
|
|
14186
14321
|
async writeCaddyfile() {
|
|
14187
14322
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
|
@@ -14225,40 +14360,6 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14225
14360
|
if (!health.healthy)
|
|
14226
14361
|
throw new Error(formatTlsHealthFailure(targetHost, health));
|
|
14227
14362
|
}
|
|
14228
|
-
/**
|
|
14229
|
-
* Regenerates the Caddyfile from the config on disk.
|
|
14230
|
-
*
|
|
14231
|
-
* Reading the file rather than a cached view matters here: another project
|
|
14232
|
-
* may have added its route since this instance last looked.
|
|
14233
|
-
*/
|
|
14234
|
-
async updateCaddyfile() {
|
|
14235
|
-
const { readProxies } = this.deps.config();
|
|
14236
|
-
const proxies = Object.values(readProxies());
|
|
14237
|
-
const ctx = validateTemplateContext({
|
|
14238
|
-
caddy_root: this.caddyRoot,
|
|
14239
|
-
proxies
|
|
14240
|
-
});
|
|
14241
|
-
this.caddyfile = await genCaddyfile(ctx);
|
|
14242
|
-
await this.writeCaddyfile();
|
|
14243
|
-
}
|
|
14244
|
-
async stopCaddy() {
|
|
14245
|
-
var _a4;
|
|
14246
|
-
try {
|
|
14247
|
-
await import_got_cjs.got.post("http://127.0.0.1:2019/stop", {
|
|
14248
|
-
headers: {
|
|
14249
|
-
Origin: "http://localhost:2019"
|
|
14250
|
-
},
|
|
14251
|
-
retry: {
|
|
14252
|
-
limit: 0
|
|
14253
|
-
},
|
|
14254
|
-
timeout: {
|
|
14255
|
-
request: 2e3
|
|
14256
|
-
}
|
|
14257
|
-
});
|
|
14258
|
-
} catch {
|
|
14259
|
-
}
|
|
14260
|
-
(_a4 = this._caddyChild) == null ? void 0 : _a4.kill();
|
|
14261
|
-
}
|
|
14262
14363
|
/**
|
|
14263
14364
|
* @param source like `127.0.0.1:8080`
|
|
14264
14365
|
* @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
|
|
@@ -14303,7 +14404,6 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14303
14404
|
];
|
|
14304
14405
|
const { writeCaddyConfig } = this.deps.config();
|
|
14305
14406
|
await writeCaddyConfig(proxies, this.proxyKey);
|
|
14306
|
-
await this.updateCaddyfile();
|
|
14307
14407
|
await session.client.call("port.free", { port: 443 });
|
|
14308
14408
|
if (import_node_process8.default.platform === "win32" || !https)
|
|
14309
14409
|
await session.client.call("port.free", { port: 80 });
|
|
@@ -14773,6 +14873,8 @@ var unpluginFactory = (options) => ({
|
|
|
14773
14873
|
return;
|
|
14774
14874
|
}
|
|
14775
14875
|
const _printUrls = server.printUrls.bind(server);
|
|
14876
|
+
if (server.config.server.middlewareMode)
|
|
14877
|
+
consola.warn("Vite runs in middleware mode, so the reverse proxy cannot start from the Vite plugin. In Nuxt, add `unplugin-https-reverse-proxy/nuxt` to `modules` instead.");
|
|
14776
14878
|
let source = `localhost:${config.server.port || 5173}`;
|
|
14777
14879
|
const url2 = (_a4 = server.resolvedUrls) == null ? void 0 : _a4.local[0];
|
|
14778
14880
|
if (url2) {
|