unplugin-https-reverse-proxy 4.1.0-beta.9 → 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-3NHJSYFO.js → chunk-U6J2RMIR.js} +186 -96
- package/dist/esbuild.cjs +198 -108
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +198 -108
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +196 -108
- package/dist/nuxt.js +1 -1
- package/dist/privileged-helper.cjs +140 -53
- package/dist/privileged-helper.js +130 -43
- package/dist/rollup.cjs +198 -108
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +198 -108
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +198 -108
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +198 -108
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/caddyfile.ts +2 -0
- package/src/caddy/config.ts +26 -18
- package/src/caddy/constants.ts +30 -1
- package/src/caddy/index.ts +19 -43
- 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 +12 -4
- package/src/privileged/session.ts +3 -0
- package/src/privileged/windows-elevation.ts +91 -33
- package/src/privileged-helper.ts +32 -0
package/dist/nuxt.cjs
CHANGED
|
@@ -44,10 +44,10 @@ var import_unplugin = require("unplugin");
|
|
|
44
44
|
|
|
45
45
|
// src/caddy/index.ts
|
|
46
46
|
var import_node_child_process3 = require("child_process");
|
|
47
|
-
var
|
|
47
|
+
var import_node_fs5 = require("fs");
|
|
48
48
|
var import_promises2 = require("fs/promises");
|
|
49
49
|
var import_node_os5 = require("os");
|
|
50
|
-
var
|
|
50
|
+
var import_node_path6 = require("path");
|
|
51
51
|
var import_node_process8 = __toESM(require("process"), 1);
|
|
52
52
|
var import_got_cjs = require("got-cjs");
|
|
53
53
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
@@ -12940,6 +12940,7 @@ var ProxyType = type({
|
|
|
12940
12940
|
});
|
|
12941
12941
|
var CaddyContext = type({
|
|
12942
12942
|
caddy_root: "string",
|
|
12943
|
+
admin_socket: "string",
|
|
12943
12944
|
proxies: ProxyType.array()
|
|
12944
12945
|
});
|
|
12945
12946
|
function validateTemplateContext(ctx) {
|
|
@@ -12952,6 +12953,7 @@ var caddyTemplate = `{
|
|
|
12952
12953
|
debug
|
|
12953
12954
|
auto_https disable_redirects ignore_loaded_certs
|
|
12954
12955
|
skip_install_trust
|
|
12956
|
+
admin unix/{{ admin_socket }}
|
|
12955
12957
|
}
|
|
12956
12958
|
|
|
12957
12959
|
:7601 {
|
|
@@ -13049,11 +13051,20 @@ function resolvePath(path) {
|
|
|
13049
13051
|
return (0, import_node_path.join)(import_node_os2.default.homedir() || "", path.slice(1));
|
|
13050
13052
|
return path;
|
|
13051
13053
|
}
|
|
13052
|
-
|
|
13054
|
+
function defaultTempDir() {
|
|
13055
|
+
const fromEnv = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR;
|
|
13056
|
+
if (fromEnv)
|
|
13057
|
+
return resolvePath(fromEnv);
|
|
13058
|
+
if (import_node_process.default.platform === "linux")
|
|
13059
|
+
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");
|
|
13060
|
+
return "/tmp";
|
|
13061
|
+
}
|
|
13062
|
+
var TEMP_DIR = resolvePath(import_node_process.default.env.UHRP_CADDY_PATH || defaultTempDir());
|
|
13053
13063
|
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
13054
13064
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
13055
13065
|
var caddyConfigPath = (0, import_node_path.join)(TEMP_DIR, ".CADDYFILE.config.json");
|
|
13056
13066
|
var caddyLockFilePath = (0, import_node_path.join)(TEMP_DIR, "caddylock");
|
|
13067
|
+
var caddyAdminSocketPath = (0, import_node_path.join)(TEMP_DIR, "caddy-admin.sock");
|
|
13057
13068
|
var supportList = [
|
|
13058
13069
|
{
|
|
13059
13070
|
platform: "dragonfly",
|
|
@@ -13176,12 +13187,12 @@ function isAlive(pid) {
|
|
|
13176
13187
|
return false;
|
|
13177
13188
|
}
|
|
13178
13189
|
}
|
|
13179
|
-
function readConfig() {
|
|
13180
|
-
if (!(0, import_node_fs.existsSync)(
|
|
13190
|
+
function readConfig(path = caddyConfigPath) {
|
|
13191
|
+
if (!(0, import_node_fs.existsSync)(path))
|
|
13181
13192
|
return {};
|
|
13182
13193
|
let parsed2;
|
|
13183
13194
|
try {
|
|
13184
|
-
parsed2 = JSON.parse((0, import_node_fs.readFileSync)(
|
|
13195
|
+
parsed2 = JSON.parse((0, import_node_fs.readFileSync)(path, "utf-8"));
|
|
13185
13196
|
} catch {
|
|
13186
13197
|
return {};
|
|
13187
13198
|
}
|
|
@@ -13192,21 +13203,22 @@ function readConfig() {
|
|
|
13192
13203
|
}
|
|
13193
13204
|
return alive;
|
|
13194
13205
|
}
|
|
13195
|
-
function writeConfig(proxies) {
|
|
13206
|
+
function writeConfig(proxies, path = caddyConfigPath) {
|
|
13196
13207
|
const content = JSON.stringify(proxies, null, 2);
|
|
13197
|
-
const temp = `${
|
|
13208
|
+
const temp = `${path}.${import_node_process2.default.pid}.tmp`;
|
|
13198
13209
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13199
|
-
(0, import_node_fs.renameSync)(temp,
|
|
13210
|
+
(0, import_node_fs.renameSync)(temp, path);
|
|
13200
13211
|
}
|
|
13201
13212
|
function useCaddyConfig(options = {}) {
|
|
13202
13213
|
const lock3 = options.lock ?? createFileLock();
|
|
13214
|
+
const configPath = options.configPath ?? caddyConfigPath;
|
|
13203
13215
|
async function mutate(apply) {
|
|
13204
13216
|
var _a4;
|
|
13205
13217
|
const release = await lock3.acquire();
|
|
13206
13218
|
try {
|
|
13207
|
-
const proxies = readConfig();
|
|
13219
|
+
const proxies = readConfig(configPath);
|
|
13208
13220
|
apply(proxies);
|
|
13209
|
-
writeConfig(proxies);
|
|
13221
|
+
writeConfig(proxies, configPath);
|
|
13210
13222
|
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13211
13223
|
return proxies;
|
|
13212
13224
|
} finally {
|
|
@@ -13214,7 +13226,7 @@ function useCaddyConfig(options = {}) {
|
|
|
13214
13226
|
}
|
|
13215
13227
|
}
|
|
13216
13228
|
return {
|
|
13217
|
-
configJsonRef: () => (0, import_node_fs.existsSync)(
|
|
13229
|
+
configJsonRef: () => (0, import_node_fs.existsSync)(configPath) ? readConfig(configPath) : void 0,
|
|
13218
13230
|
async writeCaddyConfig(_proxies, key) {
|
|
13219
13231
|
await mutate((proxies) => {
|
|
13220
13232
|
for (const p of _proxies)
|
|
@@ -13222,25 +13234,23 @@ function useCaddyConfig(options = {}) {
|
|
|
13222
13234
|
});
|
|
13223
13235
|
},
|
|
13224
13236
|
async removeProxy(key) {
|
|
13225
|
-
|
|
13237
|
+
await mutate((current) => {
|
|
13226
13238
|
for (const route of Object.keys(current)) {
|
|
13227
13239
|
if (route.endsWith(`#${key}`))
|
|
13228
13240
|
delete current[route];
|
|
13229
13241
|
}
|
|
13230
13242
|
});
|
|
13231
|
-
if (Object.keys(proxies).length === 0)
|
|
13232
|
-
removeConfigFile();
|
|
13233
13243
|
},
|
|
13234
|
-
readProxies: () => readConfig(),
|
|
13244
|
+
readProxies: () => readConfig(configPath),
|
|
13235
13245
|
async cleanUp() {
|
|
13236
|
-
removeConfigFile();
|
|
13246
|
+
removeConfigFile(configPath);
|
|
13237
13247
|
}
|
|
13238
13248
|
};
|
|
13239
13249
|
}
|
|
13240
|
-
function removeConfigFile() {
|
|
13250
|
+
function removeConfigFile(path = caddyConfigPath) {
|
|
13241
13251
|
try {
|
|
13242
|
-
if ((0, import_node_fs.existsSync)(
|
|
13243
|
-
(0, import_node_fs.unlinkSync)(
|
|
13252
|
+
if ((0, import_node_fs.existsSync)(path))
|
|
13253
|
+
(0, import_node_fs.unlinkSync)(path);
|
|
13244
13254
|
} catch {
|
|
13245
13255
|
}
|
|
13246
13256
|
}
|
|
@@ -13286,7 +13296,7 @@ function isCaddyReloadCancellation(line) {
|
|
|
13286
13296
|
// src/caddy/privileged.ts
|
|
13287
13297
|
var import_node_buffer2 = require("buffer");
|
|
13288
13298
|
var import_node_events = require("events");
|
|
13289
|
-
var
|
|
13299
|
+
var import_node_path5 = require("path");
|
|
13290
13300
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
13291
13301
|
var import_node_url = require("url");
|
|
13292
13302
|
|
|
@@ -13322,16 +13332,18 @@ function findUp(from, relative, exists2) {
|
|
|
13322
13332
|
|
|
13323
13333
|
// src/privileged/session.ts
|
|
13324
13334
|
var import_node_buffer = require("buffer");
|
|
13325
|
-
var
|
|
13335
|
+
var import_node_fs4 = require("fs");
|
|
13326
13336
|
var import_promises = require("fs/promises");
|
|
13327
13337
|
var import_node_os4 = require("os");
|
|
13328
|
-
var
|
|
13338
|
+
var import_node_path4 = require("path");
|
|
13329
13339
|
var lockfile2 = __toESM(require("proper-lockfile"), 1);
|
|
13330
13340
|
|
|
13331
13341
|
// src/privileged/launch.ts
|
|
13332
13342
|
var import_node_child_process2 = require("child_process");
|
|
13333
13343
|
var import_node_crypto = require("crypto");
|
|
13344
|
+
var import_node_fs3 = require("fs");
|
|
13334
13345
|
var import_node_os3 = require("os");
|
|
13346
|
+
var import_node_path3 = require("path");
|
|
13335
13347
|
var import_node_process6 = __toESM(require("process"), 1);
|
|
13336
13348
|
|
|
13337
13349
|
// src/privileged/client.ts
|
|
@@ -13445,7 +13457,7 @@ async function connectClient(options) {
|
|
|
13445
13457
|
} catch (error) {
|
|
13446
13458
|
lastError = error;
|
|
13447
13459
|
const code = lastError.code;
|
|
13448
|
-
if (code === "EACCES" || lastError instanceof HelperConnectionError)
|
|
13460
|
+
if (code === "EACCES" || code === "EPERM" || lastError instanceof HelperConnectionError)
|
|
13449
13461
|
throw lastError;
|
|
13450
13462
|
await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
|
|
13451
13463
|
}
|
|
@@ -13577,39 +13589,78 @@ function createClient(socket, initialBuffer, callTimeoutMs) {
|
|
|
13577
13589
|
// src/privileged/windows-elevation.ts
|
|
13578
13590
|
var import_node_child_process = require("child_process");
|
|
13579
13591
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
13592
|
+
var ERROR_CANCELLED = 1223;
|
|
13580
13593
|
function quotePowerShell(value2) {
|
|
13581
13594
|
return `'${value2.replace(/'/g, "''")}'`;
|
|
13582
13595
|
}
|
|
13596
|
+
function quoteWindowsArg(arg) {
|
|
13597
|
+
if (arg === "")
|
|
13598
|
+
return '""';
|
|
13599
|
+
if (!/[\s"]/.test(arg))
|
|
13600
|
+
return arg;
|
|
13601
|
+
let quoted = '"';
|
|
13602
|
+
let backslashes = 0;
|
|
13603
|
+
for (const char of arg) {
|
|
13604
|
+
if (char === "\\") {
|
|
13605
|
+
backslashes++;
|
|
13606
|
+
continue;
|
|
13607
|
+
}
|
|
13608
|
+
quoted += char === '"' ? `${"\\".repeat(backslashes * 2 + 1)}"` : `${"\\".repeat(backslashes)}${char}`;
|
|
13609
|
+
backslashes = 0;
|
|
13610
|
+
}
|
|
13611
|
+
return `${quoted}${"\\".repeat(backslashes * 2)}"`;
|
|
13612
|
+
}
|
|
13583
13613
|
function buildElevationCommand(options) {
|
|
13584
|
-
const
|
|
13585
|
-
|
|
13586
|
-
"
|
|
13587
|
-
"-
|
|
13588
|
-
quotePowerShell(options.file)
|
|
13614
|
+
const lines = [
|
|
13615
|
+
// The message read back on failure is localized; keep it readable as UTF-8.
|
|
13616
|
+
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
|
|
13617
|
+
"$psi = New-Object System.Diagnostics.ProcessStartInfo",
|
|
13618
|
+
`$psi.FileName = ${quotePowerShell(options.file)}`,
|
|
13619
|
+
`$psi.Arguments = ${quotePowerShell(options.args.map(quoteWindowsArg).join(" "))}`
|
|
13589
13620
|
];
|
|
13590
|
-
if (argumentList)
|
|
13591
|
-
parts.push("-ArgumentList", argumentList);
|
|
13592
13621
|
if (options.cwd)
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13622
|
+
lines.push(`$psi.WorkingDirectory = ${quotePowerShell(options.cwd)}`);
|
|
13623
|
+
lines.push(
|
|
13624
|
+
"$psi.Verb = 'runas'",
|
|
13625
|
+
"$psi.UseShellExecute = $true",
|
|
13626
|
+
"$psi.WindowStyle = 'Hidden'",
|
|
13627
|
+
"try { $p = [System.Diagnostics.Process]::Start($psi); if ($p) { [Console]::Out.Write($p.Id) } }",
|
|
13628
|
+
`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 }`
|
|
13629
|
+
);
|
|
13630
|
+
return lines.join("\n");
|
|
13597
13631
|
}
|
|
13598
13632
|
function spawnElevatedOnWindows(options) {
|
|
13599
|
-
return new Promise((resolve2
|
|
13600
|
-
const script = buildElevationCommand(options);
|
|
13633
|
+
return new Promise((resolve2) => {
|
|
13601
13634
|
const child = (0, import_node_child_process.spawn)(
|
|
13602
13635
|
"powershell.exe",
|
|
13603
|
-
["-NoProfile", "-NonInteractive", "-Command",
|
|
13604
|
-
{ stdio: "ignore", windowsHide: true }
|
|
13636
|
+
["-NoProfile", "-NonInteractive", "-Command", buildElevationCommand(options)],
|
|
13637
|
+
{ stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
|
|
13605
13638
|
);
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
));
|
|
13639
|
+
let stdout = "";
|
|
13640
|
+
let stderr = "";
|
|
13641
|
+
child.stdout.on("data", (data) => {
|
|
13642
|
+
stdout += data.toString();
|
|
13643
|
+
});
|
|
13644
|
+
child.stderr.on("data", (data) => {
|
|
13645
|
+
stderr = (stderr + data.toString()).slice(-4096);
|
|
13646
|
+
});
|
|
13647
|
+
child.once("error", (error) => resolve2({
|
|
13648
|
+
ok: false,
|
|
13649
|
+
denied: false,
|
|
13650
|
+
message: `could not start PowerShell to request administrator permission: ${error.message}`
|
|
13651
|
+
}));
|
|
13652
|
+
child.once("close", (code) => {
|
|
13653
|
+
if (code === 0) {
|
|
13654
|
+
const pid = Number(stdout.trim());
|
|
13655
|
+
return resolve2({ ok: true, pid: Number.isSafeInteger(pid) && pid > 0 ? pid : void 0 });
|
|
13656
|
+
}
|
|
13657
|
+
if (code === ERROR_CANCELLED)
|
|
13658
|
+
return resolve2({ ok: false, denied: true, message: "administrator permission was cancelled" });
|
|
13659
|
+
resolve2({
|
|
13660
|
+
ok: false,
|
|
13661
|
+
denied: false,
|
|
13662
|
+
message: `could not start the privileged helper as administrator (PowerShell exited with ${code}).${stderr.trim() ? ` ${stderr.trim()}` : ""}`
|
|
13663
|
+
});
|
|
13613
13664
|
});
|
|
13614
13665
|
});
|
|
13615
13666
|
}
|
|
@@ -13736,11 +13787,22 @@ async function startPrivilegedHelper(options) {
|
|
|
13736
13787
|
"--caddy",
|
|
13737
13788
|
options.caddyBin,
|
|
13738
13789
|
"--caddy-config",
|
|
13739
|
-
options.caddyConfigPath
|
|
13790
|
+
options.caddyConfigPath,
|
|
13791
|
+
...options.caddyAdminSocket ? ["--caddy-admin", options.caddyAdminSocket] : []
|
|
13740
13792
|
];
|
|
13741
13793
|
let child;
|
|
13794
|
+
let helperExited;
|
|
13742
13795
|
if (!direct && (0, import_node_os3.platform)() === "win32") {
|
|
13743
|
-
|
|
13796
|
+
const errorFile = (0, import_node_path3.join)((0, import_node_os3.tmpdir)(), `uhrp-helper-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.log`);
|
|
13797
|
+
const elevated = await spawnElevatedOnWindows({
|
|
13798
|
+
file: helperEntry,
|
|
13799
|
+
args: [...childArgv, "--error-file", errorFile],
|
|
13800
|
+
cwd: import_node_process6.default.cwd()
|
|
13801
|
+
});
|
|
13802
|
+
if (!elevated.ok)
|
|
13803
|
+
throw elevated.denied ? new PrivilegeDeniedError(elevated.message) : new Error(elevated.message);
|
|
13804
|
+
if (elevated.pid !== void 0)
|
|
13805
|
+
helperExited = watchWindowsHelper(elevated.pid, errorFile);
|
|
13744
13806
|
} else {
|
|
13745
13807
|
const command = direct ? helperEntry : sudoCommand;
|
|
13746
13808
|
const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
|
|
@@ -13748,20 +13810,36 @@ async function startPrivilegedHelper(options) {
|
|
|
13748
13810
|
stdio: ["ignore", "pipe", "pipe"]
|
|
13749
13811
|
});
|
|
13750
13812
|
(_a4 = child.stdout) == null ? void 0 : _a4.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
|
|
13751
|
-
|
|
13752
|
-
|
|
13813
|
+
let stderr = "";
|
|
13814
|
+
(_b3 = child.stderr) == null ? void 0 : _b3.on("data", (data) => {
|
|
13815
|
+
stderr = (stderr + data.toString()).slice(-4096);
|
|
13816
|
+
log == null ? void 0 : log(data.toString().trimEnd());
|
|
13817
|
+
});
|
|
13818
|
+
const exited = new Promise((resolve2) => {
|
|
13819
|
+
child.once("error", (error) => {
|
|
13820
|
+
stderr = error.message;
|
|
13821
|
+
});
|
|
13822
|
+
child.once("close", (code) => resolve2(code));
|
|
13823
|
+
});
|
|
13753
13824
|
const earlyExit = await Promise.race([
|
|
13754
13825
|
exited,
|
|
13755
13826
|
new Promise((resolve2) => setTimeout(() => resolve2(void 0), 500))
|
|
13756
13827
|
]);
|
|
13757
13828
|
if (earlyExit !== void 0 && earlyExit !== 0) {
|
|
13758
|
-
|
|
13759
|
-
|
|
13760
|
-
)
|
|
13829
|
+
const detail = stderr.trim();
|
|
13830
|
+
let guidance = "";
|
|
13831
|
+
if (/\b(?:EACCES|EPERM)\b/.test(detail))
|
|
13832
|
+
guidance = " Check the path named above and its parent directories. Fix ownership or access manually; do not use chmod 777.";
|
|
13833
|
+
else if (!direct && /^sudo:/m.test(detail))
|
|
13834
|
+
guidance = " Retry from a terminal where sudo can request permission, or ask an administrator to grant access.";
|
|
13835
|
+
throw new Error(`privileged helper exited with code ${earlyExit}.${detail ? ` ${detail}${guidance}` : " No diagnostic output from the helper or sudo."}`);
|
|
13761
13836
|
}
|
|
13762
13837
|
}
|
|
13763
13838
|
try {
|
|
13764
|
-
const
|
|
13839
|
+
const connecting = connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
|
|
13840
|
+
connecting.catch(() => {
|
|
13841
|
+
});
|
|
13842
|
+
const client = await (helperExited ? Promise.race([connecting, helperExited.promise]) : connecting);
|
|
13765
13843
|
return {
|
|
13766
13844
|
client,
|
|
13767
13845
|
async close() {
|
|
@@ -13776,6 +13854,42 @@ async function startPrivilegedHelper(options) {
|
|
|
13776
13854
|
} catch {
|
|
13777
13855
|
}
|
|
13778
13856
|
throw error;
|
|
13857
|
+
} finally {
|
|
13858
|
+
helperExited == null ? void 0 : helperExited.stop();
|
|
13859
|
+
}
|
|
13860
|
+
}
|
|
13861
|
+
function watchWindowsHelper(pid, errorFile) {
|
|
13862
|
+
let timer;
|
|
13863
|
+
const promise = new Promise((_, reject2) => {
|
|
13864
|
+
timer = setInterval(() => {
|
|
13865
|
+
if (isProcessRunning(pid))
|
|
13866
|
+
return;
|
|
13867
|
+
clearInterval(timer);
|
|
13868
|
+
let detail = "";
|
|
13869
|
+
try {
|
|
13870
|
+
detail = (0, import_node_fs3.readFileSync)(errorFile, "utf8").trim().slice(-4096);
|
|
13871
|
+
} catch {
|
|
13872
|
+
}
|
|
13873
|
+
reject2(new Error(`privileged helper exited before accepting connections.${detail ? ` ${detail}` : " No diagnostic output from the helper."}`));
|
|
13874
|
+
}, 250);
|
|
13875
|
+
});
|
|
13876
|
+
return {
|
|
13877
|
+
promise,
|
|
13878
|
+
stop() {
|
|
13879
|
+
clearInterval(timer);
|
|
13880
|
+
try {
|
|
13881
|
+
(0, import_node_fs3.rmSync)(errorFile, { force: true });
|
|
13882
|
+
} catch {
|
|
13883
|
+
}
|
|
13884
|
+
}
|
|
13885
|
+
};
|
|
13886
|
+
}
|
|
13887
|
+
function isProcessRunning(pid) {
|
|
13888
|
+
try {
|
|
13889
|
+
import_node_process6.default.kill(pid, 0);
|
|
13890
|
+
return true;
|
|
13891
|
+
} catch (error) {
|
|
13892
|
+
return error.code !== "ESRCH";
|
|
13779
13893
|
}
|
|
13780
13894
|
}
|
|
13781
13895
|
async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
@@ -13788,12 +13902,12 @@ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
|
13788
13902
|
|
|
13789
13903
|
// src/privileged/session.ts
|
|
13790
13904
|
function tokenPath(runtimeDir) {
|
|
13791
|
-
return (0,
|
|
13905
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.token");
|
|
13792
13906
|
}
|
|
13793
13907
|
function sessionSocketPath(runtimeDir) {
|
|
13794
13908
|
if ((0, import_node_os4.platform)() === "win32")
|
|
13795
13909
|
return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
|
|
13796
|
-
return (0,
|
|
13910
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.sock");
|
|
13797
13911
|
}
|
|
13798
13912
|
async function openHelperSession(scope2) {
|
|
13799
13913
|
const socketPath = sessionSocketPath(scope2.runtimeDir);
|
|
@@ -13808,7 +13922,7 @@ async function openHelperSession(scope2) {
|
|
|
13808
13922
|
}
|
|
13809
13923
|
}
|
|
13810
13924
|
async function tryReuse(socketPath, scope2) {
|
|
13811
|
-
if (!(0,
|
|
13925
|
+
if (!(0, import_node_fs4.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
|
|
13812
13926
|
return void 0;
|
|
13813
13927
|
const token = await readToken(scope2.runtimeDir);
|
|
13814
13928
|
if (!token)
|
|
@@ -13838,6 +13952,7 @@ async function startNew(socketPath, scope2) {
|
|
|
13838
13952
|
caddyStoragePath: scope2.caddyStoragePath,
|
|
13839
13953
|
caddyBin: scope2.caddyBin,
|
|
13840
13954
|
caddyConfigPath: scope2.caddyConfigPath,
|
|
13955
|
+
caddyAdminSocket: scope2.caddyAdminSocket,
|
|
13841
13956
|
reason: scope2.reason,
|
|
13842
13957
|
log: scope2.log
|
|
13843
13958
|
});
|
|
@@ -13851,7 +13966,7 @@ async function startNew(socketPath, scope2) {
|
|
|
13851
13966
|
};
|
|
13852
13967
|
}
|
|
13853
13968
|
async function acquireStartLock(runtimeDir) {
|
|
13854
|
-
const lockPath = (0,
|
|
13969
|
+
const lockPath = (0, import_node_path4.join)(runtimeDir, "helper.start.lock");
|
|
13855
13970
|
try {
|
|
13856
13971
|
await (0, import_promises.writeFile)(lockPath, "", { flag: "a" });
|
|
13857
13972
|
} catch {
|
|
@@ -13885,7 +14000,7 @@ async function writeToken(runtimeDir, token) {
|
|
|
13885
14000
|
// src/caddy/privileged.ts
|
|
13886
14001
|
var import_meta = {};
|
|
13887
14002
|
function resolvePrivilegedEnv() {
|
|
13888
|
-
const moduleDir = typeof __dirname === "string" ? __dirname : (0,
|
|
14003
|
+
const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
13889
14004
|
const resolved = resolveHelperEntry({ moduleDir });
|
|
13890
14005
|
return { helperEntry: resolved.entry, helperArgs: resolved.args };
|
|
13891
14006
|
}
|
|
@@ -13925,7 +14040,7 @@ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
|
|
|
13925
14040
|
}
|
|
13926
14041
|
};
|
|
13927
14042
|
function caddyStoragePath() {
|
|
13928
|
-
return import_node_process7.default.platform === "win32" ? (0,
|
|
14043
|
+
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");
|
|
13929
14044
|
}
|
|
13930
14045
|
function openPrivilegedSession(runtimeDir, options) {
|
|
13931
14046
|
const env2 = resolvePrivilegedEnv();
|
|
@@ -13941,6 +14056,7 @@ function openPrivilegedSession(runtimeDir, options) {
|
|
|
13941
14056
|
// execute a path supplied over the socket.
|
|
13942
14057
|
caddyBin: options.caddyBin,
|
|
13943
14058
|
caddyConfigPath: options.caddyConfigPath,
|
|
14059
|
+
caddyAdminSocket: options.caddyAdminSocket,
|
|
13944
14060
|
reason: options.reason,
|
|
13945
14061
|
log: options.log
|
|
13946
14062
|
});
|
|
@@ -14068,11 +14184,11 @@ async function download() {
|
|
|
14068
14184
|
if (await testCaddy())
|
|
14069
14185
|
return caddyPath;
|
|
14070
14186
|
return new Promise((resolve2, reject2) => {
|
|
14071
|
-
if (!(0,
|
|
14072
|
-
(0,
|
|
14073
|
-
(0,
|
|
14187
|
+
if (!(0, import_node_fs5.existsSync)(TEMP_DIR)) {
|
|
14188
|
+
(0, import_node_fs5.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
14189
|
+
(0, import_node_fs5.chmodSync)(TEMP_DIR, 448);
|
|
14074
14190
|
}
|
|
14075
|
-
const file = (0,
|
|
14191
|
+
const file = (0, import_node_fs5.createWriteStream)(caddyPath);
|
|
14076
14192
|
let _platform = (0, import_node_os5.platform)().toString();
|
|
14077
14193
|
_platform === "win32" && (_platform = "windows");
|
|
14078
14194
|
let _arch = import_node_process8.default.arch.toString();
|
|
@@ -14081,13 +14197,13 @@ async function download() {
|
|
|
14081
14197
|
if (!support)
|
|
14082
14198
|
return reject2(new Error("not support"));
|
|
14083
14199
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
|
|
14084
|
-
(0,
|
|
14200
|
+
(0, import_node_fs5.existsSync)(caddyPath) && (0, import_node_fs5.unlinkSync)(caddyPath);
|
|
14085
14201
|
const httpProxy = import_node_process8.default.env.HTTP_PROXY || import_node_process8.default.env.http_proxy;
|
|
14086
14202
|
const httpsProxy = import_node_process8.default.env.HTTPS_PROXY || import_node_process8.default.env.https_proxy;
|
|
14087
14203
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
14088
14204
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
14089
14205
|
const chmodCaddyOnce = once(() => {
|
|
14090
|
-
(0,
|
|
14206
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14091
14207
|
});
|
|
14092
14208
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
14093
14209
|
agent: {
|
|
@@ -14101,7 +14217,7 @@ async function download() {
|
|
|
14101
14217
|
logProgressOver();
|
|
14102
14218
|
if (import_node_process8.default.platform === "win32")
|
|
14103
14219
|
return resolve2(caddyPath);
|
|
14104
|
-
(0,
|
|
14220
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14105
14221
|
resolve2(caddyPath);
|
|
14106
14222
|
}).on("error", (err) => {
|
|
14107
14223
|
reject2(err);
|
|
@@ -14110,10 +14226,10 @@ async function download() {
|
|
|
14110
14226
|
}
|
|
14111
14227
|
function testCaddy() {
|
|
14112
14228
|
return new Promise((resolve2) => {
|
|
14113
|
-
if (!(0,
|
|
14229
|
+
if (!(0, import_node_fs5.existsSync)(caddyPath))
|
|
14114
14230
|
return resolve2(false);
|
|
14115
14231
|
try {
|
|
14116
|
-
(0,
|
|
14232
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14117
14233
|
} catch {
|
|
14118
14234
|
}
|
|
14119
14235
|
(0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
|
|
@@ -14124,7 +14240,7 @@ function testCaddy() {
|
|
|
14124
14240
|
});
|
|
14125
14241
|
}
|
|
14126
14242
|
function caddyRootPath() {
|
|
14127
|
-
return (0,
|
|
14243
|
+
return (0, import_node_path6.join)(
|
|
14128
14244
|
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14129
14245
|
"./pki/authorities/local"
|
|
14130
14246
|
);
|
|
@@ -14132,9 +14248,13 @@ function caddyRootPath() {
|
|
|
14132
14248
|
async function renderCaddyfile(proxies) {
|
|
14133
14249
|
const ctx = validateTemplateContext({
|
|
14134
14250
|
caddy_root: caddyRootPath(),
|
|
14251
|
+
admin_socket: caddyAdminSocketPath,
|
|
14135
14252
|
proxies: Object.values(proxies)
|
|
14136
14253
|
});
|
|
14137
|
-
|
|
14254
|
+
const content = await genCaddyfile(ctx);
|
|
14255
|
+
const temp = `${caddyFilePath}.${import_node_process8.default.pid}.tmp`;
|
|
14256
|
+
await (0, import_promises2.writeFile)(temp, content);
|
|
14257
|
+
await (0, import_promises2.rename)(temp, caddyFilePath);
|
|
14138
14258
|
}
|
|
14139
14259
|
var caddyConfig;
|
|
14140
14260
|
function getCaddyConfig() {
|
|
@@ -14161,6 +14281,7 @@ var defaultDependencies = {
|
|
|
14161
14281
|
// helper must never execute something named in a request.
|
|
14162
14282
|
caddyBin: caddyPath,
|
|
14163
14283
|
caddyConfigPath: caddyFilePath,
|
|
14284
|
+
caddyAdminSocket: caddyAdminSocketPath,
|
|
14164
14285
|
reason
|
|
14165
14286
|
}),
|
|
14166
14287
|
config: () => getCaddyConfig()
|
|
@@ -14182,12 +14303,14 @@ var CaddyInstant = class {
|
|
|
14182
14303
|
async session(reason) {
|
|
14183
14304
|
if (this._session && !this._session.client.connected)
|
|
14184
14305
|
this._session = void 0;
|
|
14185
|
-
if (!this._session)
|
|
14306
|
+
if (!this._session) {
|
|
14307
|
+
await this.deps.config().writeCaddyConfig([], this.proxyKey);
|
|
14186
14308
|
this._session = await this.deps.openSession(TEMP_DIR, reason);
|
|
14309
|
+
}
|
|
14187
14310
|
return this._session;
|
|
14188
14311
|
}
|
|
14189
14312
|
async getCaddyfile() {
|
|
14190
|
-
if (!(0,
|
|
14313
|
+
if (!(0, import_node_fs5.existsSync)(caddyFilePath)) {
|
|
14191
14314
|
this.caddyfile = "";
|
|
14192
14315
|
return "";
|
|
14193
14316
|
}
|
|
@@ -14239,40 +14362,6 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14239
14362
|
if (!health.healthy)
|
|
14240
14363
|
throw new Error(formatTlsHealthFailure(targetHost, health));
|
|
14241
14364
|
}
|
|
14242
|
-
/**
|
|
14243
|
-
* Regenerates the Caddyfile from the config on disk.
|
|
14244
|
-
*
|
|
14245
|
-
* Reading the file rather than a cached view matters here: another project
|
|
14246
|
-
* may have added its route since this instance last looked.
|
|
14247
|
-
*/
|
|
14248
|
-
async updateCaddyfile() {
|
|
14249
|
-
const { readProxies } = this.deps.config();
|
|
14250
|
-
const proxies = Object.values(readProxies());
|
|
14251
|
-
const ctx = validateTemplateContext({
|
|
14252
|
-
caddy_root: this.caddyRoot,
|
|
14253
|
-
proxies
|
|
14254
|
-
});
|
|
14255
|
-
this.caddyfile = await genCaddyfile(ctx);
|
|
14256
|
-
await this.writeCaddyfile();
|
|
14257
|
-
}
|
|
14258
|
-
async stopCaddy() {
|
|
14259
|
-
var _a4;
|
|
14260
|
-
try {
|
|
14261
|
-
await import_got_cjs.got.post("http://127.0.0.1:2019/stop", {
|
|
14262
|
-
headers: {
|
|
14263
|
-
Origin: "http://localhost:2019"
|
|
14264
|
-
},
|
|
14265
|
-
retry: {
|
|
14266
|
-
limit: 0
|
|
14267
|
-
},
|
|
14268
|
-
timeout: {
|
|
14269
|
-
request: 2e3
|
|
14270
|
-
}
|
|
14271
|
-
});
|
|
14272
|
-
} catch {
|
|
14273
|
-
}
|
|
14274
|
-
(_a4 = this._caddyChild) == null ? void 0 : _a4.kill();
|
|
14275
|
-
}
|
|
14276
14365
|
/**
|
|
14277
14366
|
* @param source like `127.0.0.1:8080`
|
|
14278
14367
|
* @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
|
|
@@ -14317,7 +14406,6 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14317
14406
|
];
|
|
14318
14407
|
const { writeCaddyConfig } = this.deps.config();
|
|
14319
14408
|
await writeCaddyConfig(proxies, this.proxyKey);
|
|
14320
|
-
await this.updateCaddyfile();
|
|
14321
14409
|
await session.client.call("port.free", { port: 443 });
|
|
14322
14410
|
if (import_node_process8.default.platform === "win32" || !https)
|
|
14323
14411
|
await session.client.call("port.free", { port: 80 });
|