home-hosted 0.10.0 → 0.10.1
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/AGENTS.md +78 -0
- package/README.md +39 -13
- package/dist/cli.js +1705 -245
- package/dist/cli.js.map +1 -1
- package/docs/NOTIFICATIONS.md +19 -0
- package/docs/REVERSE_PROXY.md +23 -4
- package/docs/SERVERS.md +80 -3
- package/docs/UI_CREATION.md +13 -3
- package/package.json +1 -2
- package/uis/stock/dist/assets/de-Dy66GhJ0.js +1 -0
- package/uis/stock/dist/assets/es-DV-Sq6ZE.js +1 -0
- package/uis/stock/dist/assets/fr-DgypPCaQ.js +1 -0
- package/uis/stock/dist/assets/{index-ZrOADDZx.css → index-Cok5msAO.css} +1 -1
- package/uis/stock/dist/assets/{index-aK_CRIGL.js → index-Dm3f5Ssr.js} +12 -12
- package/uis/stock/dist/assets/ja-BckgJ7ql.js +1 -0
- package/uis/stock/dist/assets/ko-B4wj7dOk.js +1 -0
- package/uis/stock/dist/assets/ru-jU0fytv4.js +1 -0
- package/uis/stock/dist/assets/vi-DG3AWtuR.js +1 -0
- package/uis/stock/dist/assets/zh-CN-Bk5kP2q-.js +1 -0
- package/uis/stock/dist/index.html +2 -2
- package/uis/stock/dist/ui.json +3 -3
- package/uis/stock/dist/assets/de-pnMS_erQ.js +0 -1
- package/uis/stock/dist/assets/es-BaIbld2Z.js +0 -1
- package/uis/stock/dist/assets/fr-B2gy4ynV.js +0 -1
- package/uis/stock/dist/assets/ja-DFH5Ol5b.js +0 -1
- package/uis/stock/dist/assets/ko-C3LcaLoa.js +0 -1
- package/uis/stock/dist/assets/ru-B7nB7X1y.js +0 -1
- package/uis/stock/dist/assets/vi-CzXGueBM.js +0 -1
- package/uis/stock/dist/assets/zh-CN-Du_sQUjJ.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -24,7 +24,6 @@ import { parseArgs, promisify } from "node:util";
|
|
|
24
24
|
import net, { isIP } from "node:net";
|
|
25
25
|
import { Hono } from "hono";
|
|
26
26
|
import { HTTPException } from "hono/http-exception";
|
|
27
|
-
import { Scalar } from "@scalar/hono-api-reference";
|
|
28
27
|
import https from "node:https";
|
|
29
28
|
import { finished } from "node:stream/promises";
|
|
30
29
|
import { BlobReader, ZipReader, ZipWriter, configure } from "@zip.js/zip.js";
|
|
@@ -292,6 +291,18 @@ function invocation() {
|
|
|
292
291
|
if (/[\\/]cli\.ts$/.test(entry)) return "pnpm exec tsx src/cli.ts";
|
|
293
292
|
return "home-hosted";
|
|
294
293
|
}
|
|
294
|
+
function isClosedReaderError(error) {
|
|
295
|
+
const code = error?.code;
|
|
296
|
+
if (typeof code === "string" && READER_GONE.test(code)) return true;
|
|
297
|
+
const message = error?.message ?? "";
|
|
298
|
+
return /^(?:closed|write after end|premature close)$/i.test(message);
|
|
299
|
+
}
|
|
300
|
+
function treatClosedReaderAsDone() {
|
|
301
|
+
process.stdout.on("error", (error) => {
|
|
302
|
+
if (isClosedReaderError(error)) process.exit(0);
|
|
303
|
+
throw error;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
295
306
|
/** One shape for every failure: a red `error <message>` on stderr and exit 1. */
|
|
296
307
|
function fail(message) {
|
|
297
308
|
process.stderr.write(`${paint("31", "error")} ${message}\n`);
|
|
@@ -341,7 +352,7 @@ async function confirm(question, fallback) {
|
|
|
341
352
|
if (answer.length === 0) return fallback;
|
|
342
353
|
return answer === "y" || answer === "yes";
|
|
343
354
|
}
|
|
344
|
-
var isTty, paint, dim, bold, cyan, green, heading, style;
|
|
355
|
+
var isTty, paint, dim, bold, cyan, green, heading, style, READER_GONE;
|
|
345
356
|
var init_io = __esmMin((() => {
|
|
346
357
|
isTty = () => process.stdout.isTTY === true;
|
|
347
358
|
paint = (code, text) => isTty() ? `\x1B[${code}m${text}\x1B[0m` : text;
|
|
@@ -355,6 +366,7 @@ var init_io = __esmMin((() => {
|
|
|
355
366
|
dim,
|
|
356
367
|
green
|
|
357
368
|
};
|
|
369
|
+
READER_GONE = /^(?:EPIPE|ERR_STREAM_DESTROYED|ERR_STREAM_WRITE_AFTER_END|ECONNRESET)$/;
|
|
358
370
|
}));
|
|
359
371
|
//#endregion
|
|
360
372
|
//#region src/helpers/runtime.ts
|
|
@@ -411,22 +423,22 @@ var version_exports = /* @__PURE__ */ __exportAll({
|
|
|
411
423
|
* import there would pull the daemon graph in before citty is even asked anything.
|
|
412
424
|
*/
|
|
413
425
|
function appVersion() {
|
|
414
|
-
if (cached !== null) return cached;
|
|
426
|
+
if (cached$1 !== null) return cached$1;
|
|
415
427
|
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
416
428
|
for (let depth = 0; depth < 4; depth++) {
|
|
417
429
|
try {
|
|
418
430
|
const manifest = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
419
431
|
if (manifest.name === "home-hosted" && typeof manifest.version === "string") {
|
|
420
|
-
cached = manifest.version;
|
|
421
|
-
return cached;
|
|
432
|
+
cached$1 = manifest.version;
|
|
433
|
+
return cached$1;
|
|
422
434
|
}
|
|
423
435
|
} catch {}
|
|
424
436
|
const parent = path.dirname(dir);
|
|
425
437
|
if (parent === dir) break;
|
|
426
438
|
dir = parent;
|
|
427
439
|
}
|
|
428
|
-
cached = "0.0.0";
|
|
429
|
-
return cached;
|
|
440
|
+
cached$1 = "0.0.0";
|
|
441
|
+
return cached$1;
|
|
430
442
|
}
|
|
431
443
|
/**
|
|
432
444
|
* The one line to add when this CLI and the panel it is talking to are not the same
|
|
@@ -437,9 +449,9 @@ function versionMismatchNote(panelVersion) {
|
|
|
437
449
|
const cli = appVersion();
|
|
438
450
|
return cli === panelVersion ? null : `note: this CLI is ${cli}, the panel is ${panelVersion}`;
|
|
439
451
|
}
|
|
440
|
-
var cached;
|
|
452
|
+
var cached$1;
|
|
441
453
|
var init_version = __esmMin((() => {
|
|
442
|
-
cached = null;
|
|
454
|
+
cached$1 = null;
|
|
443
455
|
}));
|
|
444
456
|
//#endregion
|
|
445
457
|
//#region src/helpers/daemon-log.ts
|
|
@@ -731,6 +743,153 @@ function secureCookieFor(mode, protocol) {
|
|
|
731
743
|
var init_cookies = __esmMin((() => {}));
|
|
732
744
|
//#endregion
|
|
733
745
|
//#region src/shared/contracts.ts
|
|
746
|
+
var contracts_exports = /* @__PURE__ */ __exportAll({
|
|
747
|
+
actionResultSchema: () => actionResultSchema,
|
|
748
|
+
apiErrorSchema: () => apiErrorSchema,
|
|
749
|
+
appStateSchema: () => appStateSchema,
|
|
750
|
+
authSchema: () => authSchema,
|
|
751
|
+
authStatusSchema: () => authStatusSchema,
|
|
752
|
+
backupCreateSchema: () => backupCreateSchema,
|
|
753
|
+
backupCreatedResponseSchema: () => backupCreatedResponseSchema,
|
|
754
|
+
backupEntrySchema: () => backupEntrySchema,
|
|
755
|
+
backupFileSchema: () => backupFileSchema,
|
|
756
|
+
backupFilesResponseSchema: () => backupFilesResponseSchema,
|
|
757
|
+
backupHookOrNullSchema: () => backupHookOrNullSchema,
|
|
758
|
+
backupHookSchema: () => backupHookSchema,
|
|
759
|
+
backupScheduleSchema: () => backupScheduleSchema,
|
|
760
|
+
backupScheduleViewSchema: () => backupScheduleViewSchema,
|
|
761
|
+
backupScopeSchema: () => backupScopeSchema,
|
|
762
|
+
backupsSchema: () => backupsSchema,
|
|
763
|
+
backupsViewSchema: () => backupsViewSchema,
|
|
764
|
+
bindSchema: () => bindSchema,
|
|
765
|
+
bootstrapOrNullSchema: () => bootstrapOrNullSchema,
|
|
766
|
+
bootstrapSchema: () => bootstrapSchema,
|
|
767
|
+
controlSchema: () => controlSchema,
|
|
768
|
+
controlViewSchema: () => controlViewSchema,
|
|
769
|
+
ddnsAccountSchema: () => ddnsAccountSchema,
|
|
770
|
+
ddnsConfigSchema: () => ddnsConfigSchema,
|
|
771
|
+
ddnsCredentialsSchema: () => ddnsCredentialsSchema,
|
|
772
|
+
ddnsDomainSchema: () => ddnsDomainSchema,
|
|
773
|
+
ddnsIpv4Schema: () => ddnsIpv4Schema,
|
|
774
|
+
ddnsIpv6Schema: () => ddnsIpv6Schema,
|
|
775
|
+
ddnsPatchSchema: () => ddnsPatchSchema,
|
|
776
|
+
ddnsProviderFieldSchema: () => ddnsProviderFieldSchema,
|
|
777
|
+
ddnsProviderInfoSchema: () => ddnsProviderInfoSchema,
|
|
778
|
+
ddnsRecordStateSchema: () => ddnsRecordStateSchema,
|
|
779
|
+
ddnsRecordTypeSchema: () => ddnsRecordTypeSchema,
|
|
780
|
+
ddnsRecordViewSchema: () => ddnsRecordViewSchema,
|
|
781
|
+
ddnsStatusSchema: () => ddnsStatusSchema,
|
|
782
|
+
ddnsViewSchema: () => ddnsViewSchema,
|
|
783
|
+
defaultsSchema: () => defaultsSchema,
|
|
784
|
+
deliveryResultSchema: () => deliveryResultSchema,
|
|
785
|
+
destinationIdParamSchema: () => destinationIdParamSchema,
|
|
786
|
+
destinationStatusSchema: () => destinationStatusSchema,
|
|
787
|
+
destinationTestSchema: () => destinationTestSchema,
|
|
788
|
+
duplicateWebhookIds: () => duplicateWebhookIds,
|
|
789
|
+
entryStateSchema: () => entryStateSchema,
|
|
790
|
+
freePortResultSchema: () => freePortResultSchema,
|
|
791
|
+
healthResponseSchema: () => healthResponseSchema,
|
|
792
|
+
healthSchema: () => healthSchema,
|
|
793
|
+
healthStateSchema: () => healthStateSchema,
|
|
794
|
+
historyActorSchema: () => historyActorSchema,
|
|
795
|
+
historyEventSchema: () => historyEventSchema,
|
|
796
|
+
hostDiskSchema: () => hostDiskSchema,
|
|
797
|
+
hostSchema: () => hostSchema,
|
|
798
|
+
hostViewSchema: () => hostViewSchema,
|
|
799
|
+
httpCheckSchema: () => httpCheckSchema,
|
|
800
|
+
labelOrNullSchema: () => labelOrNullSchema,
|
|
801
|
+
logBufferLinesSchema: () => logBufferLinesSchema,
|
|
802
|
+
logFileInfoSchema: () => logFileInfoSchema,
|
|
803
|
+
logHistoryQuerySchema: () => logHistoryQuerySchema,
|
|
804
|
+
logHistoryViewSchema: () => logHistoryViewSchema,
|
|
805
|
+
logLineSchema: () => logLineSchema,
|
|
806
|
+
logLinesResponseSchema: () => logLinesResponseSchema,
|
|
807
|
+
logQuerySchema: () => logQuerySchema,
|
|
808
|
+
logServerViewSchema: () => logServerViewSchema,
|
|
809
|
+
logServersViewSchema: () => logServersViewSchema,
|
|
810
|
+
logStreamSchema: () => logStreamSchema,
|
|
811
|
+
loginSchema: () => loginSchema,
|
|
812
|
+
logsSchema: () => logsSchema,
|
|
813
|
+
nannyExitSchema: () => nannyExitSchema,
|
|
814
|
+
nannySpecSchema: () => nannySpecSchema,
|
|
815
|
+
nannyStateSchema: () => nannyStateSchema,
|
|
816
|
+
notificationActionSchema: () => notificationActionSchema,
|
|
817
|
+
notificationDefaultsSchema: () => notificationDefaultsSchema,
|
|
818
|
+
notificationDefaultsViewSchema: () => notificationDefaultsViewSchema,
|
|
819
|
+
notificationTargetSchema: () => notificationTargetSchema,
|
|
820
|
+
notificationViewSchema: () => notificationViewSchema,
|
|
821
|
+
notificationsSchema: () => notificationsSchema,
|
|
822
|
+
okResponseSchema: () => okResponseSchema,
|
|
823
|
+
onPortConflictDefaultSchema: () => onPortConflictDefaultSchema,
|
|
824
|
+
onPortConflictSchema: () => onPortConflictSchema,
|
|
825
|
+
parseBind: () => parseBind,
|
|
826
|
+
passwordSchema: () => passwordSchema,
|
|
827
|
+
passwordSetResponseSchema: () => passwordSetResponseSchema,
|
|
828
|
+
passwordValueSchema: () => passwordValueSchema,
|
|
829
|
+
portSchema: () => portSchema,
|
|
830
|
+
portStateSchema: () => portStateSchema,
|
|
831
|
+
processResourcesSchema: () => processResourcesSchema,
|
|
832
|
+
proxyCertificateSchema: () => proxyCertificateSchema,
|
|
833
|
+
proxyCertificateStateSchema: () => proxyCertificateStateSchema,
|
|
834
|
+
proxyCertificateUploadSchema: () => proxyCertificateUploadSchema,
|
|
835
|
+
proxyCertificateViewSchema: () => proxyCertificateViewSchema,
|
|
836
|
+
proxyConfigSchema: () => proxyConfigSchema,
|
|
837
|
+
proxyDns01Schema: () => proxyDns01Schema,
|
|
838
|
+
proxyDnsAccountViewSchema: () => proxyDnsAccountViewSchema,
|
|
839
|
+
proxyEngineInfoSchema: () => proxyEngineInfoSchema,
|
|
840
|
+
proxyEngineInstallSchema: () => proxyEngineInstallSchema,
|
|
841
|
+
proxyEngineSchema: () => proxyEngineSchema,
|
|
842
|
+
proxyEngineSourceSchema: () => proxyEngineSourceSchema,
|
|
843
|
+
proxyEngineStatusSchema: () => proxyEngineStatusSchema,
|
|
844
|
+
proxyPatchSchema: () => proxyPatchSchema,
|
|
845
|
+
proxyRoutePatchSchema: () => proxyRoutePatchSchema,
|
|
846
|
+
proxyRouteSchema: () => proxyRouteSchema,
|
|
847
|
+
proxyRouteStatusSchema: () => proxyRouteStatusSchema,
|
|
848
|
+
proxyRouteViewSchema: () => proxyRouteViewSchema,
|
|
849
|
+
proxyRunStateSchema: () => proxyRunStateSchema,
|
|
850
|
+
proxyStatusSchema: () => proxyStatusSchema,
|
|
851
|
+
proxyTargetSchema: () => proxyTargetSchema,
|
|
852
|
+
proxyTlsModeSchema: () => proxyTlsModeSchema,
|
|
853
|
+
proxyViewSchema: () => proxyViewSchema,
|
|
854
|
+
resourcesSchema: () => resourcesSchema,
|
|
855
|
+
restartSchema: () => restartSchema,
|
|
856
|
+
restoreItemSchema: () => restoreItemSchema,
|
|
857
|
+
restorePlanSchema: () => restorePlanSchema,
|
|
858
|
+
restoreRequestSchema: () => restoreRequestSchema,
|
|
859
|
+
restoreSkipSchema: () => restoreSkipSchema,
|
|
860
|
+
serverCreateSchema: () => serverCreateSchema,
|
|
861
|
+
serverHistorySchema: () => serverHistorySchema,
|
|
862
|
+
serverOrphanSchema: () => serverOrphanSchema,
|
|
863
|
+
serverPatchSchema: () => serverPatchSchema,
|
|
864
|
+
serverSchema: () => serverSchema,
|
|
865
|
+
serverStatusSchema: () => serverStatusSchema,
|
|
866
|
+
serverViewSchema: () => serverViewSchema,
|
|
867
|
+
sessionViewSchema: () => sessionViewSchema,
|
|
868
|
+
settingsPatchSchema: () => settingsPatchSchema,
|
|
869
|
+
settingsSavedSchema: () => settingsSavedSchema,
|
|
870
|
+
settingsViewSchema: () => settingsViewSchema,
|
|
871
|
+
sseMessageSchema: () => sseMessageSchema,
|
|
872
|
+
stopSchema: () => stopSchema,
|
|
873
|
+
telegramChatsSchema: () => telegramChatsSchema,
|
|
874
|
+
telegramTokenSchema: () => telegramTokenSchema,
|
|
875
|
+
tlsReviewResponseSchema: () => tlsReviewResponseSchema,
|
|
876
|
+
tlsSchema: () => tlsSchema,
|
|
877
|
+
tlsStatusSchema: () => tlsStatusSchema,
|
|
878
|
+
tlsUploadSchema: () => tlsUploadSchema,
|
|
879
|
+
uiInstallResponseSchema: () => uiInstallResponseSchema,
|
|
880
|
+
uiMetaSchema: () => uiMetaSchema,
|
|
881
|
+
uiStatusSchema: () => uiStatusSchema,
|
|
882
|
+
webhookTargetSchema: () => webhookTargetSchema,
|
|
883
|
+
workspaceCreateSchema: () => workspaceCreateSchema,
|
|
884
|
+
workspaceIdSchema: () => workspaceIdSchema,
|
|
885
|
+
workspaceRenameSchema: () => workspaceRenameSchema,
|
|
886
|
+
workspaceSchema: () => workspaceSchema,
|
|
887
|
+
workspaceSettingsPatchSchema: () => workspaceSettingsPatchSchema,
|
|
888
|
+
workspaceSettingsSavedSchema: () => workspaceSettingsSavedSchema,
|
|
889
|
+
workspaceSettingsViewSchema: () => workspaceSettingsViewSchema,
|
|
890
|
+
workspaceViewSchema: () => workspaceViewSchema,
|
|
891
|
+
wslTemperatureSchema: () => wslTemperatureSchema
|
|
892
|
+
});
|
|
734
893
|
/** Parses a bind value (`local` | `lan` | ipv4); null when it is not one. */
|
|
735
894
|
function parseBind(value) {
|
|
736
895
|
const parsed = bindSchema(value);
|
|
@@ -751,7 +910,7 @@ function duplicateWebhookIds(targets) {
|
|
|
751
910
|
}
|
|
752
911
|
return [...duplicates];
|
|
753
912
|
}
|
|
754
|
-
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, backupHookSchema, backupHookOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, backupScopeSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, backupFileSchema, backupEntrySchema, backupScheduleViewSchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, serverOrphanSchema, workspaceViewSchema, appStateSchema, logQuerySchema, actionResultSchema, deliveryResultSchema, passwordSetResponseSchema, tlsReviewResponseSchema, okResponseSchema, backupFilesResponseSchema, uiInstallResponseSchema, backupCreatedResponseSchema, logLinesResponseSchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
913
|
+
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, backupHookSchema, backupHookOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, ddnsPatchSchema, backupScopeSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, wslTemperatureSchema, backupFileSchema, backupEntrySchema, backupScheduleViewSchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, serverOrphanSchema, workspaceViewSchema, appStateSchema, sseMessageSchema, logQuerySchema, actionResultSchema, deliveryResultSchema, passwordSetResponseSchema, tlsReviewResponseSchema, okResponseSchema, backupFilesResponseSchema, uiInstallResponseSchema, backupCreatedResponseSchema, logLinesResponseSchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, logHistoryViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
755
914
|
var init_contracts = __esmMin((() => {
|
|
756
915
|
bindSchema = type("\"local\" | \"lan\" | /^\\d{1,3}(?:\\.\\d{1,3}){3}$/");
|
|
757
916
|
workspaceIdSchema = type("/^[a-z0-9][a-z0-9_-]*$/");
|
|
@@ -970,7 +1129,18 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
970
1129
|
memoryUsedPercent: "number >= 0 = 90",
|
|
971
1130
|
swapUsedPercent: "number >= 0 = 50",
|
|
972
1131
|
loadPerCpu: "number >= 0 = 2",
|
|
973
|
-
tempCelsius: "number >= 0 = 85"
|
|
1132
|
+
tempCelsius: "number >= 0 = 85",
|
|
1133
|
+
/**
|
|
1134
|
+
* How to read the CPU temperature when the kernel exposes no sensor.
|
|
1135
|
+
*
|
|
1136
|
+
* A command whose stdout is a number in °C — the escape hatch for a machine this panel cannot read
|
|
1137
|
+
* for itself (a WSL2 guest, a VM, a board whose hwmon chip is unsupported). Empty means "use the
|
|
1138
|
+
* built-in probe". It runs on the sampling interval, so it must be cheap; `docs/SERVERS.md` carries
|
|
1139
|
+
* the WSL2 setup.
|
|
1140
|
+
*/
|
|
1141
|
+
tempCommand: "string <= 512 = \"\"",
|
|
1142
|
+
/** How long that command may run before it is killed, so a hung helper cannot stall a sample. */
|
|
1143
|
+
tempCommandTimeoutMs: "100 <= number <= 30000 = 5000"
|
|
974
1144
|
}).onUndeclaredKey("reject");
|
|
975
1145
|
ddnsRecordTypeSchema = type.enumerated("A", "AAAA");
|
|
976
1146
|
ddnsAccountSchema = type({
|
|
@@ -1062,7 +1232,7 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1062
1232
|
provider: "string >= 1",
|
|
1063
1233
|
credentials: type("Record<string, string>")
|
|
1064
1234
|
}).onUndeclaredKey("reject");
|
|
1065
|
-
type({
|
|
1235
|
+
ddnsPatchSchema = type({
|
|
1066
1236
|
enabled: "boolean?",
|
|
1067
1237
|
intervalMs: "number >= 60000?",
|
|
1068
1238
|
ipv4: type({
|
|
@@ -1210,7 +1380,9 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1210
1380
|
memoryUsedPercent: "number >= 0?",
|
|
1211
1381
|
swapUsedPercent: "number >= 0?",
|
|
1212
1382
|
loadPerCpu: "number >= 0?",
|
|
1213
|
-
tempCelsius: "number >= 0?"
|
|
1383
|
+
tempCelsius: "number >= 0?",
|
|
1384
|
+
tempCommand: "string <= 512?",
|
|
1385
|
+
tempCommandTimeoutMs: "100 <= number <= 30000?"
|
|
1214
1386
|
}).onUndeclaredKey("reject");
|
|
1215
1387
|
backupSchedulePatchSchema = type({
|
|
1216
1388
|
intervalMs: "number.integer >= 0?",
|
|
@@ -1690,6 +1862,26 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1690
1862
|
"alerts": type("string[]"),
|
|
1691
1863
|
"sampledAt": "number | null"
|
|
1692
1864
|
});
|
|
1865
|
+
wslTemperatureSchema = type({
|
|
1866
|
+
/** This process runs under WSL. */
|
|
1867
|
+
"wsl": "boolean",
|
|
1868
|
+
/** The setup can work here — the same as `wsl` today, separate so a future bridge can differ. */
|
|
1869
|
+
"supported": "boolean",
|
|
1870
|
+
/** `host.tempCommand` already names a command. */
|
|
1871
|
+
"configured": "boolean",
|
|
1872
|
+
/** The helper script exists on disk. */
|
|
1873
|
+
"scriptWritten": "boolean",
|
|
1874
|
+
/** LibreHardwareMonitor was found on the Windows side. */
|
|
1875
|
+
"libraryPresent": "boolean",
|
|
1876
|
+
/** Where the helper was written, for the sentence that tells a person what to delete. */
|
|
1877
|
+
"scriptPath": "string | null",
|
|
1878
|
+
/** The command the panel would run, absent until it is configured. */
|
|
1879
|
+
"tempCommand?": "string | null",
|
|
1880
|
+
/** The last probe's reading, so the page can say "this works" without running it again. */
|
|
1881
|
+
"lastReadingCelsius?": "number | null",
|
|
1882
|
+
/** Why the last probe failed, if it did — a missing library and no sensor read differently. */
|
|
1883
|
+
"lastError?": "string | null"
|
|
1884
|
+
});
|
|
1693
1885
|
backupFileSchema = type({
|
|
1694
1886
|
name: "string",
|
|
1695
1887
|
sizeBytes: "number",
|
|
@@ -2023,7 +2215,7 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
2023
2215
|
/** The release this panel is running. Optional: an older panel does not send one. */
|
|
2024
2216
|
"version?": "string"
|
|
2025
2217
|
});
|
|
2026
|
-
type({
|
|
2218
|
+
sseMessageSchema = type({
|
|
2027
2219
|
"type": "\"hello\" | \"state\" | \"log\" | \"server\"",
|
|
2028
2220
|
"ts": "number",
|
|
2029
2221
|
"workspaceId?": "string",
|
|
@@ -2113,7 +2305,7 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
2113
2305
|
files: logFileInfoSchema.array()
|
|
2114
2306
|
});
|
|
2115
2307
|
logServersViewSchema = type({ servers: logServerViewSchema.array() });
|
|
2116
|
-
type({
|
|
2308
|
+
logHistoryViewSchema = type({
|
|
2117
2309
|
serverId: "string",
|
|
2118
2310
|
enabled: "boolean",
|
|
2119
2311
|
sizeBytes: "number",
|
|
@@ -3177,9 +3369,29 @@ var init_auth = __esmMin((() => {
|
|
|
3177
3369
|
}));
|
|
3178
3370
|
//#endregion
|
|
3179
3371
|
//#region src/helpers/bind.ts
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3372
|
+
/**
|
|
3373
|
+
* This machine's first non-internal IPv4 address, or null when it has none.
|
|
3374
|
+
*
|
|
3375
|
+
* Cached for `LAN_ADDRESS_TTL_MS`: the call is expensive and its answer is read per server per
|
|
3376
|
+
* state frame. The cache is module state, which is acceptable here for the same reason
|
|
3377
|
+
* `appVersion()`'s is — the answer is a property of the host, not of a workspace, and nothing in
|
|
3378
|
+
* a test changes the interfaces it observes.
|
|
3379
|
+
*/
|
|
3380
|
+
function lanAddress(now = Date.now()) {
|
|
3381
|
+
if (cached !== null && now - cached.at < LAN_ADDRESS_TTL_MS) return cached.value;
|
|
3382
|
+
let value = null;
|
|
3383
|
+
for (const entries of Object.values(os.networkInterfaces())) {
|
|
3384
|
+
for (const entry of entries ?? []) if (entry.family === "IPv4" && !entry.internal) {
|
|
3385
|
+
value = entry.address;
|
|
3386
|
+
break;
|
|
3387
|
+
}
|
|
3388
|
+
if (value !== null) break;
|
|
3389
|
+
}
|
|
3390
|
+
cached = {
|
|
3391
|
+
value,
|
|
3392
|
+
at: now
|
|
3393
|
+
};
|
|
3394
|
+
return value;
|
|
3183
3395
|
}
|
|
3184
3396
|
function bindHost(bind) {
|
|
3185
3397
|
if (bind === "local") return "127.0.0.1";
|
|
@@ -3196,7 +3408,11 @@ function displayHost(bind) {
|
|
|
3196
3408
|
function isExposed(bind) {
|
|
3197
3409
|
return bindHost(bind) !== "127.0.0.1";
|
|
3198
3410
|
}
|
|
3199
|
-
var
|
|
3411
|
+
var LAN_ADDRESS_TTL_MS, cached;
|
|
3412
|
+
var init_bind = __esmMin((() => {
|
|
3413
|
+
LAN_ADDRESS_TTL_MS = 3e4;
|
|
3414
|
+
cached = null;
|
|
3415
|
+
}));
|
|
3200
3416
|
//#endregion
|
|
3201
3417
|
//#region src/services/exposure.ts
|
|
3202
3418
|
/**
|
|
@@ -3471,7 +3687,6 @@ var paths_exports = /* @__PURE__ */ __exportAll({
|
|
|
3471
3687
|
workspaceDdnsStatePath: () => workspaceDdnsStatePath,
|
|
3472
3688
|
workspaceDir: () => workspaceDir,
|
|
3473
3689
|
workspaceHistoryPath: () => workspaceHistoryPath,
|
|
3474
|
-
workspaceIdsOnDisk: () => workspaceIdsOnDisk,
|
|
3475
3690
|
workspaceLogsDir: () => workspaceLogsDir,
|
|
3476
3691
|
workspaceSecretsPath: () => workspaceSecretsPath,
|
|
3477
3692
|
workspaceServersPath: () => workspaceServersPath,
|
|
@@ -3536,14 +3751,6 @@ function workspaceStateDir(id) {
|
|
|
3536
3751
|
function workspaceDdnsStatePath(id) {
|
|
3537
3752
|
return path.join(workspaceStateDir(id), "ddns.json");
|
|
3538
3753
|
}
|
|
3539
|
-
/** Every directory a nanny state file may sit in, across all workspaces. */
|
|
3540
|
-
function workspaceIdsOnDisk() {
|
|
3541
|
-
try {
|
|
3542
|
-
return fs.readdirSync(hhDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).filter((id) => /^[a-z0-9][a-z0-9_-]*$/.test(id));
|
|
3543
|
-
} catch {
|
|
3544
|
-
return [];
|
|
3545
|
-
}
|
|
3546
|
-
}
|
|
3547
3754
|
/**
|
|
3548
3755
|
* True when a pre-workspace instance left state at the old paths **and** never
|
|
3549
3756
|
* crossed into `.hh`: `workspaces.json` means the layout is current, so a stray
|
|
@@ -4311,7 +4518,8 @@ function createControlRoute(deps) {
|
|
|
4311
4518
|
}
|
|
4312
4519
|
}), (c) => {
|
|
4313
4520
|
assertLocalCall(c, "stop the control panel");
|
|
4314
|
-
|
|
4521
|
+
const withPersistent = c.req.query("withPersistent") === "true";
|
|
4522
|
+
afterResponse(() => deps.onShutdown({ withPersistent }), (error) => logger.error("shutdown failed", error));
|
|
4315
4523
|
return c.json({ ok: true });
|
|
4316
4524
|
}).post("/servers/:id/start", describeRoute({
|
|
4317
4525
|
tags: ["panel"],
|
|
@@ -4955,6 +5163,10 @@ var init_seed = __esmMin((() => {
|
|
|
4955
5163
|
}));
|
|
4956
5164
|
//#endregion
|
|
4957
5165
|
//#region src/config/settings.ts
|
|
5166
|
+
var settings_exports = /* @__PURE__ */ __exportAll({
|
|
5167
|
+
ConfigError: () => ConfigError,
|
|
5168
|
+
GlobalSettingsStore: () => GlobalSettingsStore
|
|
5169
|
+
});
|
|
4958
5170
|
var ConfigError, GlobalSettingsStore;
|
|
4959
5171
|
var init_settings$1 = __esmMin((() => {
|
|
4960
5172
|
init_migrations();
|
|
@@ -6751,6 +6963,22 @@ function webhookPayload(event, now = Date.now()) {
|
|
|
6751
6963
|
};
|
|
6752
6964
|
}
|
|
6753
6965
|
/**
|
|
6966
|
+
* What `Headers` will refuse, decided here so the refusal names the line.
|
|
6967
|
+
*
|
|
6968
|
+
* This is not a second opinion about validity: `Headers` (and Node's own `http`) throw on a name
|
|
6969
|
+
* holding a space or a non-ASCII letter, and on a value holding a character above `0xFF` — so
|
|
6970
|
+
* `Title: 🔴 server down` fails at the request with `Cannot convert argument to a ByteString …
|
|
6971
|
+
* value of 55357`, beside a `lastResult` a person reads as the receiver's fault. HTTP header values
|
|
6972
|
+
* are bytes, not text: ntfy's own answer for an emoji title is `=?UTF-8?B?…?=`. Naming both here
|
|
6973
|
+
* means the save is refused with the line quoted, and a config that already holds one says which
|
|
6974
|
+
* header it is instead of surfacing a JS engine message.
|
|
6975
|
+
*/
|
|
6976
|
+
function headerProblem(name, value) {
|
|
6977
|
+
if (!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(name)) return `"${name}" is not a valid header name`;
|
|
6978
|
+
for (const char of value) if (char.codePointAt(0) > 255) return `the "${name}" value holds a character a header cannot carry (${char}) — headers are bytes, so encode it (ntfy reads \`=?UTF-8?B?…?=\`) or use format: json, which carries text in the body`;
|
|
6979
|
+
return null;
|
|
6980
|
+
}
|
|
6981
|
+
/**
|
|
6754
6982
|
* `Name: value` lines into a header map.
|
|
6755
6983
|
*
|
|
6756
6984
|
* The format is line-based rather than a JSON object because it is edited in a textarea, and
|
|
@@ -6777,6 +7005,13 @@ function parseHeaders(text, vars = process.env) {
|
|
|
6777
7005
|
const name = trimmed.slice(0, at).trim();
|
|
6778
7006
|
const value = expandEnv(trimmed.slice(at + 1).trim(), vars);
|
|
6779
7007
|
if (value.includes("${")) unexpanded.push(name);
|
|
7008
|
+
else {
|
|
7009
|
+
const problem = headerProblem(name, value);
|
|
7010
|
+
if (problem !== null) {
|
|
7011
|
+
errors.push(problem);
|
|
7012
|
+
continue;
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
6780
7015
|
headers[name] = value;
|
|
6781
7016
|
}
|
|
6782
7017
|
return {
|
|
@@ -6819,13 +7054,16 @@ async function sendWebhook(target, event, fetchImpl) {
|
|
|
6819
7054
|
ok: false,
|
|
6820
7055
|
error: `the URL still holds an unexpanded placeholder: ${url}`
|
|
6821
7056
|
};
|
|
7057
|
+
const sent = { "content-type": asText ? "text/plain; charset=utf-8" : "application/json" };
|
|
7058
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
7059
|
+
const key = name.toLowerCase();
|
|
7060
|
+
for (const existing of Object.keys(sent)) if (existing.toLowerCase() === key) delete sent[existing];
|
|
7061
|
+
sent[name] = value;
|
|
7062
|
+
}
|
|
6822
7063
|
try {
|
|
6823
7064
|
const response = await (fetchImpl ?? fetch)(url, {
|
|
6824
7065
|
method: target.method,
|
|
6825
|
-
headers:
|
|
6826
|
-
"content-type": asText ? "text/plain; charset=utf-8" : "application/json",
|
|
6827
|
-
...headers
|
|
6828
|
-
},
|
|
7066
|
+
headers: sent,
|
|
6829
7067
|
body,
|
|
6830
7068
|
signal: AbortSignal.timeout(1e4)
|
|
6831
7069
|
});
|
|
@@ -6850,6 +7088,10 @@ var init_webhook = __esmMin((() => {
|
|
|
6850
7088
|
}));
|
|
6851
7089
|
//#endregion
|
|
6852
7090
|
//#region src/config/store.ts
|
|
7091
|
+
var store_exports = /* @__PURE__ */ __exportAll({
|
|
7092
|
+
ConfigError: () => ConfigError,
|
|
7093
|
+
WorkspaceStore: () => WorkspaceStore
|
|
7094
|
+
});
|
|
6853
7095
|
function readFile(file) {
|
|
6854
7096
|
let text;
|
|
6855
7097
|
try {
|
|
@@ -7660,7 +7902,7 @@ function createLogsRoute(deps) {
|
|
|
7660
7902
|
200: { description: "application/x-ndjson" },
|
|
7661
7903
|
404: ERROR_RESPONSES[404]
|
|
7662
7904
|
}
|
|
7663
|
-
}), validate("query", downloadQuery), validate("param", idParam$2), (c) => {
|
|
7905
|
+
}), validate("query", downloadQuery), validate("param", idParam$2), async (c) => {
|
|
7664
7906
|
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
7665
7907
|
const { id } = c.req.valid("param");
|
|
7666
7908
|
if (!runtime.store.getServer(id)) throw unknownServerError(id);
|
|
@@ -7670,10 +7912,21 @@ function createLogsRoute(deps) {
|
|
|
7670
7912
|
code: "UNKNOWN_LOG_FILE"
|
|
7671
7913
|
});
|
|
7672
7914
|
const file = path.join(runtime.logFiles.directory, requested);
|
|
7673
|
-
|
|
7674
|
-
|
|
7915
|
+
/**
|
|
7916
|
+
* Streamed, not read into memory. This is the same class the archive download answers, and the
|
|
7917
|
+
* logs are the *bigger* case in practice: `logs.maxBytes` bounds one rotation at up to 100 MB and
|
|
7918
|
+
* `keep` keeps 10 of them, and a person downloads exactly when a log is large.
|
|
7919
|
+
*
|
|
7920
|
+
* Measured on the built panel with a real 100 MB rotation: `readFileSync` cost **+199 MB RSS**
|
|
7921
|
+
* for one download and **+402 MB** for four arriving together, `/healthz` went from 4 ms to
|
|
7922
|
+
* p95 859 ms / max 898 ms, and the headers only arrived after the whole read (TTFB 272 ms). The
|
|
7923
|
+
* archive route with the same four downloads grew **+2 MB** and answered `/healthz` in p50 17 ms.
|
|
7924
|
+
* `stat` gives the same `Content-Length` a client needs for a progress bar without the buffer.
|
|
7925
|
+
*/
|
|
7926
|
+
const stats = await fs.promises.stat(file);
|
|
7927
|
+
return c.body(Readable.toWeb(createReadStream(file)), 200, {
|
|
7675
7928
|
"Content-Type": "application/x-ndjson; charset=utf-8",
|
|
7676
|
-
"Content-Length": String(
|
|
7929
|
+
"Content-Length": String(stats.size),
|
|
7677
7930
|
"Content-Disposition": `attachment; filename="${requested}"`
|
|
7678
7931
|
});
|
|
7679
7932
|
}).delete("/logs/:id", describeRoute({
|
|
@@ -8034,7 +8287,7 @@ function parseWindowsCsv(text) {
|
|
|
8034
8287
|
async function getClockTicks() {
|
|
8035
8288
|
if (clockTicks !== null) return clockTicks;
|
|
8036
8289
|
try {
|
|
8037
|
-
const { stdout } = await execFileAsync$
|
|
8290
|
+
const { stdout } = await execFileAsync$6("getconf", ["CLK_TCK"], { timeout: 2e3 });
|
|
8038
8291
|
const parsed = Number.parseInt(stdout.trim(), 10);
|
|
8039
8292
|
clockTicks = Number.isFinite(parsed) && parsed > 0 ? parsed : 100;
|
|
8040
8293
|
} catch {
|
|
@@ -8086,7 +8339,7 @@ async function readLinux() {
|
|
|
8086
8339
|
return rows;
|
|
8087
8340
|
}
|
|
8088
8341
|
async function readPosix() {
|
|
8089
|
-
const { stdout } = await execFileAsync$
|
|
8342
|
+
const { stdout } = await execFileAsync$6("ps", ["-Ao", "pid=,ppid=,rss=,%cpu="], {
|
|
8090
8343
|
timeout: 5e3,
|
|
8091
8344
|
maxBuffer: 16777216
|
|
8092
8345
|
});
|
|
@@ -8095,7 +8348,7 @@ async function readPosix() {
|
|
|
8095
8348
|
async function readWindows() {
|
|
8096
8349
|
const script = "Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,WorkingSetSize,KernelModeTime,UserModeTime | ConvertTo-Csv -NoTypeInformation";
|
|
8097
8350
|
try {
|
|
8098
|
-
const { stdout } = await execFileAsync$
|
|
8351
|
+
const { stdout } = await execFileAsync$6("powershell.exe", [
|
|
8099
8352
|
"-NoProfile",
|
|
8100
8353
|
"-NonInteractive",
|
|
8101
8354
|
"-Command",
|
|
@@ -8107,7 +8360,7 @@ async function readWindows() {
|
|
|
8107
8360
|
return parseWindowsCsv(stdout);
|
|
8108
8361
|
} catch {
|
|
8109
8362
|
try {
|
|
8110
|
-
const { stdout } = await execFileAsync$
|
|
8363
|
+
const { stdout } = await execFileAsync$6("wmic", [
|
|
8111
8364
|
"process",
|
|
8112
8365
|
"get",
|
|
8113
8366
|
"ProcessId,ParentProcessId,WorkingSetSize,KernelModeTime,UserModeTime",
|
|
@@ -8228,7 +8481,7 @@ async function processCarriesServerId(pid, serverId) {
|
|
|
8228
8481
|
return false;
|
|
8229
8482
|
}
|
|
8230
8483
|
if (process.platform === "darwin") try {
|
|
8231
|
-
const { stdout } = await execFileAsync$
|
|
8484
|
+
const { stdout } = await execFileAsync$6("ps", [
|
|
8232
8485
|
"-p",
|
|
8233
8486
|
String(pid),
|
|
8234
8487
|
"-E",
|
|
@@ -8242,9 +8495,9 @@ async function processCarriesServerId(pid, serverId) {
|
|
|
8242
8495
|
}
|
|
8243
8496
|
return false;
|
|
8244
8497
|
}
|
|
8245
|
-
var execFileAsync$
|
|
8498
|
+
var execFileAsync$6, clockTicks, ProcessSampler;
|
|
8246
8499
|
var init_proc = __esmMin((() => {
|
|
8247
|
-
execFileAsync$
|
|
8500
|
+
execFileAsync$6 = promisify(execFile);
|
|
8248
8501
|
clockTicks = null;
|
|
8249
8502
|
ProcessSampler = class {
|
|
8250
8503
|
/**
|
|
@@ -8469,7 +8722,7 @@ async function processArgv(pid) {
|
|
|
8469
8722
|
return null;
|
|
8470
8723
|
}
|
|
8471
8724
|
try {
|
|
8472
|
-
const { stdout } = await execFileAsync$
|
|
8725
|
+
const { stdout } = await execFileAsync$5("ps", [
|
|
8473
8726
|
"-p",
|
|
8474
8727
|
String(pid),
|
|
8475
8728
|
"-ww",
|
|
@@ -8540,7 +8793,7 @@ async function windowsProcessInfo(pid) {
|
|
|
8540
8793
|
if (!windowsFilter.test(String(pid))) return null;
|
|
8541
8794
|
try {
|
|
8542
8795
|
const script = `Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" | Select-Object CommandLine,ExecutablePath | ConvertTo-Csv -NoTypeInformation`;
|
|
8543
|
-
const { stdout } = await execFileAsync$
|
|
8796
|
+
const { stdout } = await execFileAsync$5("powershell", [
|
|
8544
8797
|
"-NoProfile",
|
|
8545
8798
|
"-NonInteractive",
|
|
8546
8799
|
"-Command",
|
|
@@ -8591,10 +8844,10 @@ async function identifyHolders(serverId, spawn, pids) {
|
|
|
8591
8844
|
}
|
|
8592
8845
|
return found;
|
|
8593
8846
|
}
|
|
8594
|
-
var execFileAsync$
|
|
8847
|
+
var execFileAsync$5, windowsFilter;
|
|
8595
8848
|
var init_identity = __esmMin((() => {
|
|
8596
8849
|
init_proc();
|
|
8597
|
-
execFileAsync$
|
|
8850
|
+
execFileAsync$5 = promisify(execFile);
|
|
8598
8851
|
windowsFilter = /^\d+$/;
|
|
8599
8852
|
}));
|
|
8600
8853
|
//#endregion
|
|
@@ -8716,7 +8969,7 @@ async function processBirth(pid) {
|
|
|
8716
8969
|
}
|
|
8717
8970
|
if (process.platform === "win32") try {
|
|
8718
8971
|
const script = `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; if ($p) { $p.CreationDate.ToFileTimeUtc() }`;
|
|
8719
|
-
const { stdout } = await execFileAsync$
|
|
8972
|
+
const { stdout } = await execFileAsync$4("powershell", [
|
|
8720
8973
|
"-NoProfile",
|
|
8721
8974
|
"-NonInteractive",
|
|
8722
8975
|
"-Command",
|
|
@@ -8734,7 +8987,7 @@ async function processBirth(pid) {
|
|
|
8734
8987
|
return null;
|
|
8735
8988
|
}
|
|
8736
8989
|
try {
|
|
8737
|
-
const { stdout } = await execFileAsync$
|
|
8990
|
+
const { stdout } = await execFileAsync$4("ps", [
|
|
8738
8991
|
"-p",
|
|
8739
8992
|
String(pid),
|
|
8740
8993
|
"-o",
|
|
@@ -8816,19 +9069,20 @@ function parseNetstatListeners(output, port) {
|
|
|
8816
9069
|
}
|
|
8817
9070
|
async function findDockerPortHolder(port) {
|
|
8818
9071
|
try {
|
|
8819
|
-
const { stdout } = await execFileAsync$
|
|
9072
|
+
const { stdout } = await execFileAsync$4("docker", [
|
|
8820
9073
|
"ps",
|
|
8821
9074
|
"--filter",
|
|
8822
9075
|
`publish=${port}`,
|
|
8823
9076
|
"--format",
|
|
8824
|
-
"{{.Names}} {{.Label \"com.docker.compose.project.working_dir\"}}"
|
|
9077
|
+
"{{.Names}} {{.Label \"com.docker.compose.project\"}} {{.Label \"com.docker.compose.project.working_dir\"}}"
|
|
8825
9078
|
], { timeout: 3e3 });
|
|
8826
9079
|
const line = stdout.split("\n").find((entry) => entry.trim().length > 0);
|
|
8827
9080
|
if (line === void 0) return null;
|
|
8828
|
-
const [container = "", composeDir = ""] = line.split(" ");
|
|
9081
|
+
const [container = "", project = "", composeDir = ""] = line.split(" ");
|
|
8829
9082
|
if (container.trim().length === 0) return null;
|
|
8830
9083
|
return {
|
|
8831
9084
|
container: container.trim(),
|
|
9085
|
+
project: project.trim().length > 0 ? project.trim() : null,
|
|
8832
9086
|
composeDir: composeDir.trim().length > 0 ? composeDir.trim() : null,
|
|
8833
9087
|
port
|
|
8834
9088
|
};
|
|
@@ -8846,7 +9100,7 @@ async function findDockerPortHolder(port) {
|
|
|
8846
9100
|
*/
|
|
8847
9101
|
async function releaseDockerPort(holder, timeoutMs = 2e4) {
|
|
8848
9102
|
try {
|
|
8849
|
-
await execFileAsync$
|
|
9103
|
+
await execFileAsync$4("docker", ["stop", holder.container], { timeout: timeoutMs });
|
|
8850
9104
|
return true;
|
|
8851
9105
|
} catch {
|
|
8852
9106
|
return false;
|
|
@@ -8854,7 +9108,7 @@ async function releaseDockerPort(holder, timeoutMs = 2e4) {
|
|
|
8854
9108
|
}
|
|
8855
9109
|
async function listPortHolders(port) {
|
|
8856
9110
|
if (process.platform === "win32") try {
|
|
8857
|
-
const { stdout } = await execFileAsync$
|
|
9111
|
+
const { stdout } = await execFileAsync$4("netstat", [
|
|
8858
9112
|
"-ano",
|
|
8859
9113
|
"-p",
|
|
8860
9114
|
"tcp"
|
|
@@ -8864,7 +9118,7 @@ async function listPortHolders(port) {
|
|
|
8864
9118
|
return [];
|
|
8865
9119
|
}
|
|
8866
9120
|
try {
|
|
8867
|
-
const { stdout } = await execFileAsync$
|
|
9121
|
+
const { stdout } = await execFileAsync$4("lsof", [
|
|
8868
9122
|
"-ti",
|
|
8869
9123
|
`tcp:${port}`,
|
|
8870
9124
|
"-sTCP:LISTEN"
|
|
@@ -8872,7 +9126,7 @@ async function listPortHolders(port) {
|
|
|
8872
9126
|
return parsePids(stdout);
|
|
8873
9127
|
} catch {}
|
|
8874
9128
|
try {
|
|
8875
|
-
const { stdout } = await execFileAsync$
|
|
9129
|
+
const { stdout } = await execFileAsync$4("fuser", [`${port}/tcp`], { timeout: 3e3 });
|
|
8876
9130
|
return parsePids(stdout);
|
|
8877
9131
|
} catch {
|
|
8878
9132
|
return [];
|
|
@@ -8889,9 +9143,9 @@ async function listPortHolders(port) {
|
|
|
8889
9143
|
function parsePids(stdout) {
|
|
8890
9144
|
return [...new Set(stdout.split(/\s+/).map((entry) => Number.parseInt(entry, 10)).filter((pid) => Number.isInteger(pid) && pid > 0 && pid !== process.pid))];
|
|
8891
9145
|
}
|
|
8892
|
-
var execFileAsync$
|
|
9146
|
+
var execFileAsync$4, LINUX_HZ, FILETIME_UNIX_OFFSET_MS;
|
|
8893
9147
|
var init_port = __esmMin((() => {
|
|
8894
|
-
execFileAsync$
|
|
9148
|
+
execFileAsync$4 = promisify(execFile);
|
|
8895
9149
|
LINUX_HZ = 100;
|
|
8896
9150
|
FILETIME_UNIX_OFFSET_MS = 0xa9730b66800;
|
|
8897
9151
|
}));
|
|
@@ -8986,7 +9240,7 @@ async function terminate(child, options) {
|
|
|
8986
9240
|
*/
|
|
8987
9241
|
async function killTreeWindows(pid) {
|
|
8988
9242
|
try {
|
|
8989
|
-
await execFileAsync$
|
|
9243
|
+
await execFileAsync$3("taskkill", [
|
|
8990
9244
|
"/pid",
|
|
8991
9245
|
String(pid),
|
|
8992
9246
|
"/T",
|
|
@@ -9053,11 +9307,11 @@ function waitForExit$1(child, timeoutMs) {
|
|
|
9053
9307
|
child.once("exit", onExit);
|
|
9054
9308
|
});
|
|
9055
9309
|
}
|
|
9056
|
-
var execFileAsync$
|
|
9310
|
+
var execFileAsync$3, WINDOWS_SHIM_EXTENSIONS;
|
|
9057
9311
|
var init_process = __esmMin((() => {
|
|
9058
9312
|
init_paths();
|
|
9059
9313
|
init_port();
|
|
9060
|
-
execFileAsync$
|
|
9314
|
+
execFileAsync$3 = promisify(execFile);
|
|
9061
9315
|
WINDOWS_SHIM_EXTENSIONS = [
|
|
9062
9316
|
".exe",
|
|
9063
9317
|
".cmd",
|
|
@@ -9357,6 +9611,30 @@ var init_proxy$2 = __esmMin((() => {
|
|
|
9357
9611
|
BY_ID = new Map(PROXY_ENGINES.map((engine) => [engine.info.id, engine]));
|
|
9358
9612
|
}));
|
|
9359
9613
|
//#endregion
|
|
9614
|
+
//#region src/shared/proxy-form.ts
|
|
9615
|
+
/** A name an ACME CA could issue for; anything else gets the engine's own CA. */
|
|
9616
|
+
function isPublicHost(host) {
|
|
9617
|
+
const name = host.trim().toLowerCase();
|
|
9618
|
+
if (name.length === 0 || name === "localhost" || !name.includes(".")) return false;
|
|
9619
|
+
if (LOCAL_TLDS.some((tld) => name.endsWith(tld))) return false;
|
|
9620
|
+
return !/^\d{1,3}(?:\.\d{1,3}){3,}$/.test(name);
|
|
9621
|
+
}
|
|
9622
|
+
var LOCAL_TLDS;
|
|
9623
|
+
var init_proxy_form = __esmMin((() => {
|
|
9624
|
+
init_contracts();
|
|
9625
|
+
LOCAL_TLDS = [
|
|
9626
|
+
".localhost",
|
|
9627
|
+
".local",
|
|
9628
|
+
".internal",
|
|
9629
|
+
".home.arpa",
|
|
9630
|
+
".lan",
|
|
9631
|
+
".home",
|
|
9632
|
+
".test",
|
|
9633
|
+
".invalid",
|
|
9634
|
+
".example"
|
|
9635
|
+
];
|
|
9636
|
+
}));
|
|
9637
|
+
//#endregion
|
|
9360
9638
|
//#region src/services/proxy-config.ts
|
|
9361
9639
|
/**
|
|
9362
9640
|
* The DNS-01 challenge block, which names the panel as the one that answers it. The
|
|
@@ -9610,8 +9888,9 @@ function renderCaddyConfig(input) {
|
|
|
9610
9888
|
issuers: acmeIssuers(input.acme)
|
|
9611
9889
|
});
|
|
9612
9890
|
}
|
|
9891
|
+
const localNames = [...new Set(managed.filter((route) => route.tls === "auto" && !isPublicHost(route.host)).map((route) => route.host))];
|
|
9613
9892
|
if (managed.length > 0) policies.push({
|
|
9614
|
-
subjects: [FALLBACK_NAME],
|
|
9893
|
+
subjects: [FALLBACK_NAME, ...localNames],
|
|
9615
9894
|
issuers: [{ module: "internal" }]
|
|
9616
9895
|
});
|
|
9617
9896
|
if (policies.length > 0) tlsApp.automation = { policies };
|
|
@@ -9634,6 +9913,7 @@ function renderCaddyConfig(input) {
|
|
|
9634
9913
|
}
|
|
9635
9914
|
var ACME_STAGING, FALLBACK_NAME;
|
|
9636
9915
|
var init_proxy_config = __esmMin((() => {
|
|
9916
|
+
init_proxy_form();
|
|
9637
9917
|
ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory";
|
|
9638
9918
|
FALLBACK_NAME = "hh-fallback.invalid";
|
|
9639
9919
|
}));
|
|
@@ -9824,30 +10104,6 @@ var init_tls$1 = __esmMin((() => {
|
|
|
9824
10104
|
};
|
|
9825
10105
|
}));
|
|
9826
10106
|
//#endregion
|
|
9827
|
-
//#region src/shared/proxy-form.ts
|
|
9828
|
-
/** A name an ACME CA could issue for; anything else gets the engine's own CA. */
|
|
9829
|
-
function isPublicHost(host) {
|
|
9830
|
-
const name = host.trim().toLowerCase();
|
|
9831
|
-
if (name.length === 0 || name === "localhost" || !name.includes(".")) return false;
|
|
9832
|
-
if (LOCAL_TLDS.some((tld) => name.endsWith(tld))) return false;
|
|
9833
|
-
return !/^\d{1,3}(?:\.\d{1,3}){3,}$/.test(name);
|
|
9834
|
-
}
|
|
9835
|
-
var LOCAL_TLDS;
|
|
9836
|
-
var init_proxy_form = __esmMin((() => {
|
|
9837
|
-
init_contracts();
|
|
9838
|
-
LOCAL_TLDS = [
|
|
9839
|
-
".localhost",
|
|
9840
|
-
".local",
|
|
9841
|
-
".internal",
|
|
9842
|
-
".home.arpa",
|
|
9843
|
-
".lan",
|
|
9844
|
-
".home",
|
|
9845
|
-
".test",
|
|
9846
|
-
".invalid",
|
|
9847
|
-
".example"
|
|
9848
|
-
];
|
|
9849
|
-
}));
|
|
9850
|
-
//#endregion
|
|
9851
10107
|
//#region src/services/proxy.ts
|
|
9852
10108
|
/** The DNS names a certificate covers, from its SANs (and its subject as a fallback). */
|
|
9853
10109
|
function namesOf(x509) {
|
|
@@ -10350,10 +10606,20 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10350
10606
|
message: covering === void 0 ? `no uploaded certificate covers ${route.host}` : `${covering.error ?? "the uploaded certificate cannot be used"} — upload a valid pair for ${route.host}`
|
|
10351
10607
|
};
|
|
10352
10608
|
}
|
|
10353
|
-
if (!isPublicHost(route.host))
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10609
|
+
if (!isPublicHost(route.host)) {
|
|
10610
|
+
if (this.localCertificates().has(route.host.toLowerCase())) return {
|
|
10611
|
+
state: "local",
|
|
10612
|
+
message: "signed by the engine's own CA"
|
|
10613
|
+
};
|
|
10614
|
+
const refusal = this.obtainFailures().get(route.host.toLowerCase());
|
|
10615
|
+
return refusal === void 0 ? {
|
|
10616
|
+
state: "pending",
|
|
10617
|
+
message: "the engine is issuing its own certificate"
|
|
10618
|
+
} : {
|
|
10619
|
+
state: "failed",
|
|
10620
|
+
message: refusal
|
|
10621
|
+
};
|
|
10622
|
+
}
|
|
10357
10623
|
const issued = this.issuedCertificates().get(route.host.toLowerCase());
|
|
10358
10624
|
if (issued !== void 0) return {
|
|
10359
10625
|
state: "issued",
|
|
@@ -11938,14 +12204,14 @@ function createServersRoute(deps) {
|
|
|
11938
12204
|
return c.json({ servers: runtime.supervisor.views() });
|
|
11939
12205
|
}).post("/stop-all", describeRoute({
|
|
11940
12206
|
tags: ["servers"],
|
|
11941
|
-
summary: "Stop every server in a workspace",
|
|
12207
|
+
summary: "Stop every server in a workspace, persistent entries included if asked",
|
|
11942
12208
|
responses: { 200: {
|
|
11943
12209
|
description: "The servers",
|
|
11944
12210
|
content: jsonBody(serversResponse)
|
|
11945
12211
|
} }
|
|
11946
12212
|
}), validate("query", workspaceQuerySchema), async (c) => {
|
|
11947
12213
|
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11948
|
-
await runtime.supervisor.stopAll();
|
|
12214
|
+
await runtime.supervisor.stopAll({ withPersistent: c.req.query("withPersistent") === "true" });
|
|
11949
12215
|
return c.json({ servers: runtime.supervisor.views() });
|
|
11950
12216
|
}).get("/:id", describeRoute({
|
|
11951
12217
|
tags: ["servers"],
|
|
@@ -12410,7 +12676,10 @@ function createSettingsRoute(deps) {
|
|
|
12410
12676
|
const patch = c.req.valid("json");
|
|
12411
12677
|
try {
|
|
12412
12678
|
if (patch.defaults !== void 0) runtime.store.updateDefaults(patch.defaults);
|
|
12413
|
-
if (patch.logs !== void 0)
|
|
12679
|
+
if (patch.logs !== void 0) {
|
|
12680
|
+
runtime.store.updateLogs(patch.logs);
|
|
12681
|
+
runtime.logFiles.prune();
|
|
12682
|
+
}
|
|
12414
12683
|
if (patch.notifications !== void 0) {
|
|
12415
12684
|
const saved = runtime.store.updateNotifications(patch.notifications);
|
|
12416
12685
|
runtime.secrets.forgetTelegramTokens(saved.destinations.map((destination) => destination.id));
|
|
@@ -12713,6 +12982,274 @@ var init_$_routes = __esmMin((() => {
|
|
|
12713
12982
|
});
|
|
12714
12983
|
}));
|
|
12715
12984
|
//#endregion
|
|
12985
|
+
//#region src/providers/wsl-temperature.ts
|
|
12986
|
+
var wsl_temperature_exports = /* @__PURE__ */ __exportAll({
|
|
12987
|
+
isWsl: () => isWsl,
|
|
12988
|
+
probeWslTemperature: () => probeWslTemperature,
|
|
12989
|
+
tempCommandFor: () => tempCommandFor,
|
|
12990
|
+
windowsScriptPath: () => windowsScriptPath,
|
|
12991
|
+
writeWslTemperatureScript: () => writeWslTemperatureScript,
|
|
12992
|
+
wslScriptPath: () => wslScriptPath,
|
|
12993
|
+
wslTemperatureStatus: () => wslTemperatureStatus
|
|
12994
|
+
});
|
|
12995
|
+
/**
|
|
12996
|
+
* Whether this process is a WSL2 guest.
|
|
12997
|
+
*
|
|
12998
|
+
* `os.release()` carries `microsoft-standard-WSL2`, and `/proc/version` the same — checked on both
|
|
12999
|
+
* because a future WSL may rename the release while the version line keeps the vendor.
|
|
13000
|
+
*/
|
|
13001
|
+
function isWsl() {
|
|
13002
|
+
if (process.platform !== "linux") return false;
|
|
13003
|
+
try {
|
|
13004
|
+
return /microsoft/i.test(fs.readFileSync("/proc/version", "utf8"));
|
|
13005
|
+
} catch {
|
|
13006
|
+
return false;
|
|
13007
|
+
}
|
|
13008
|
+
}
|
|
13009
|
+
/**
|
|
13010
|
+
* Where the helper script goes: **on the Windows side**, under `%LOCALAPPDATA%`-style storage.
|
|
13011
|
+
*
|
|
13012
|
+
* This is the part that is easy to get wrong. `powershell.exe` reads a *Windows* path, so a script
|
|
13013
|
+
* written into the guest's Linux home (`/tmp`, `~/.home-hosted`) is invisible to it — the command
|
|
13014
|
+
* appears to work only while some stale copy exists, then fails with a path error that names nothing
|
|
13015
|
+
* useful. `/mnt/c` is the 9p mount of `C:`, so writing there gives both sides the same file.
|
|
13016
|
+
*/
|
|
13017
|
+
function windowsScriptPath(scriptPath) {
|
|
13018
|
+
const match = /^\/mnt\/([a-z])\/(.*)$/i.exec(scriptPath);
|
|
13019
|
+
if (match === null) return scriptPath;
|
|
13020
|
+
return `${match[1].toUpperCase()}:\\${match[2].replaceAll("/", "\\")}`;
|
|
13021
|
+
}
|
|
13022
|
+
/**
|
|
13023
|
+
* The Linux path the helper is written to: `C:\Tools\home-hosted\cpu-temp.ps1` on Windows.
|
|
13024
|
+
*
|
|
13025
|
+
* `user` is the Windows-side account, taken from the mount when it can be read. Falls back to the
|
|
13026
|
+
* user's home on the Windows drive, which is where a person can find and delete the file.
|
|
13027
|
+
*/
|
|
13028
|
+
function wslScriptPath() {
|
|
13029
|
+
if (!isWsl()) return null;
|
|
13030
|
+
return path.join("/mnt/c/Tools/home-hosted", SCRIPT_NAME);
|
|
13031
|
+
}
|
|
13032
|
+
/** The `powershell.exe` invocation that runs `scriptPath` and prints the temperature. */
|
|
13033
|
+
function tempCommandFor(scriptPath) {
|
|
13034
|
+
return `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${windowsScriptPath(scriptPath)}"`;
|
|
13035
|
+
}
|
|
13036
|
+
/** The script's body. Kept tiny: it runs on every host sample. */
|
|
13037
|
+
function scriptBody(lhmDir) {
|
|
13038
|
+
return `# CPU temperature for home-hosted, read through LibreHardwareMonitor.
|
|
13039
|
+
# Written by \`home-hosted host tempsetup\`; safe to delete, and the panel stops using it when the
|
|
13040
|
+
# Temperature command field is cleared.
|
|
13041
|
+
$dir = '${lhmDir}'
|
|
13042
|
+
if (-not (Test-Path "$dir\\LibreHardwareMonitorLib.dll")) {
|
|
13043
|
+
[Console]::Error.WriteLine("LibreHardwareMonitor not found in $dir")
|
|
13044
|
+
exit 1
|
|
13045
|
+
}
|
|
13046
|
+
[System.Reflection.Assembly]::LoadFrom("$dir\\System.Memory.dll") | Out-Null
|
|
13047
|
+
[System.Reflection.Assembly]::LoadFrom("$dir\\System.Buffers.dll") | Out-Null
|
|
13048
|
+
[System.Reflection.Assembly]::LoadFrom("$dir\\Microsoft.Bcl.AsyncInterfaces.dll") | Out-Null
|
|
13049
|
+
Add-Type -Path "$dir\\LibreHardwareMonitorLib.dll"
|
|
13050
|
+
$c = New-Object LibreHardwareMonitor.Hardware.Computer
|
|
13051
|
+
$c.IsCpuEnabled = $true
|
|
13052
|
+
$c.Open()
|
|
13053
|
+
$out = $null
|
|
13054
|
+
foreach ($hw in $c.Hardware) {
|
|
13055
|
+
$hw.Update()
|
|
13056
|
+
foreach ($s in $hw.Sensors) {
|
|
13057
|
+
if ($s.SensorType -eq 'Temperature' -and $s.Name -match 'Tctl|Package|Core') {
|
|
13058
|
+
$out = [math]::Round($s.Value, 1)
|
|
13059
|
+
break
|
|
13060
|
+
}
|
|
13061
|
+
}
|
|
13062
|
+
if ($null -ne $out) { break }
|
|
13063
|
+
}
|
|
13064
|
+
$c.Close()
|
|
13065
|
+
if ($null -eq $out) { exit 2 }
|
|
13066
|
+
$out
|
|
13067
|
+
`;
|
|
13068
|
+
}
|
|
13069
|
+
/**
|
|
13070
|
+
* Whether the setup is in place: the script exists, and the panel has been pointed at it.
|
|
13071
|
+
*
|
|
13072
|
+
* `configured` is what the panel *will do*; `ready` is whether it can work — the two are separate so
|
|
13073
|
+
* the UI can say "set up, but the library is missing" rather than only "not set up".
|
|
13074
|
+
*/
|
|
13075
|
+
function wslTemperatureStatus(scriptPath, tempCommand) {
|
|
13076
|
+
const wsl = isWsl();
|
|
13077
|
+
const scriptWritten = scriptPath !== null && fs.existsSync(scriptPath);
|
|
13078
|
+
const configured = tempCommand.trim().length > 0;
|
|
13079
|
+
let libraryPresent = false;
|
|
13080
|
+
try {
|
|
13081
|
+
libraryPresent = fs.existsSync(path.join("/mnt", "c", "Tools", "LibreHardwareMonitor", "LibreHardwareMonitorLib.dll"));
|
|
13082
|
+
} catch {
|
|
13083
|
+
libraryPresent = false;
|
|
13084
|
+
}
|
|
13085
|
+
return {
|
|
13086
|
+
wsl,
|
|
13087
|
+
supported: wsl,
|
|
13088
|
+
configured,
|
|
13089
|
+
scriptWritten,
|
|
13090
|
+
libraryPresent,
|
|
13091
|
+
scriptPath: wsl ? scriptPath : null,
|
|
13092
|
+
tempCommand: configured ? tempCommand : null
|
|
13093
|
+
};
|
|
13094
|
+
}
|
|
13095
|
+
/** Write the helper script. Idempotent: re-running overwrites it with the current version. */
|
|
13096
|
+
function writeWslTemperatureScript(scriptPath) {
|
|
13097
|
+
fs.mkdirSync(path.dirname(scriptPath), { recursive: true });
|
|
13098
|
+
fs.writeFileSync(scriptPath, scriptBody(LHM_DIR), { mode: 384 });
|
|
13099
|
+
}
|
|
13100
|
+
/**
|
|
13101
|
+
* Run the helper once, to tell the person whether the setup works before they save a broken command.
|
|
13102
|
+
*
|
|
13103
|
+
* The answer is the reading, or a reason. A missing library and a library that returned nothing are
|
|
13104
|
+
* different problems and get different sentences — the first says where to put the download, the
|
|
13105
|
+
* second that the harness ran but found no sensor (a locked-down driver, a VM in a VM).
|
|
13106
|
+
*/
|
|
13107
|
+
async function probeWslTemperature(tempCommand, timeoutMs) {
|
|
13108
|
+
try {
|
|
13109
|
+
const { stdout, stderr } = await execFileAsync$2(tempCommand, {
|
|
13110
|
+
timeout: timeoutMs,
|
|
13111
|
+
windowsHide: true,
|
|
13112
|
+
maxBuffer: 65536,
|
|
13113
|
+
shell: true
|
|
13114
|
+
});
|
|
13115
|
+
const match = /-?\d+(?:\.\d+)?/.exec(stdout);
|
|
13116
|
+
if (match === null) return {
|
|
13117
|
+
celsius: null,
|
|
13118
|
+
error: stderr.trim().length > 0 ? stderr.trim() : "the script printed no number — is LibreHardwareMonitor installed at C:\\Tools\\LibreHardwareMonitor?"
|
|
13119
|
+
};
|
|
13120
|
+
const celsius = Number.parseFloat(match[0]);
|
|
13121
|
+
if (!Number.isFinite(celsius) || celsius <= 0 || celsius >= 150) return {
|
|
13122
|
+
celsius: null,
|
|
13123
|
+
error: `the script printed ${match[0]}, which is not a temperature`
|
|
13124
|
+
};
|
|
13125
|
+
return {
|
|
13126
|
+
celsius,
|
|
13127
|
+
error: null
|
|
13128
|
+
};
|
|
13129
|
+
} catch (error) {
|
|
13130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
13131
|
+
logger.warn(`the WSL temperature probe failed: ${message}`);
|
|
13132
|
+
return {
|
|
13133
|
+
celsius: null,
|
|
13134
|
+
error: message
|
|
13135
|
+
};
|
|
13136
|
+
}
|
|
13137
|
+
}
|
|
13138
|
+
var execFileAsync$2, SCRIPT_NAME, LHM_DIR;
|
|
13139
|
+
var init_wsl_temperature$1 = __esmMin((() => {
|
|
13140
|
+
init_logger();
|
|
13141
|
+
execFileAsync$2 = promisify(execFile);
|
|
13142
|
+
SCRIPT_NAME = "cpu-temp.ps1";
|
|
13143
|
+
LHM_DIR = "C:\\Tools\\LibreHardwareMonitor";
|
|
13144
|
+
}));
|
|
13145
|
+
//#endregion
|
|
13146
|
+
//#region src/api/wsl-temperature.ts
|
|
13147
|
+
/**
|
|
13148
|
+
* The helper's location, or null when the Windows drive is not mounted.
|
|
13149
|
+
*
|
|
13150
|
+
* It lives on the *Windows* side: `powershell.exe` cannot read the guest's Linux home, so a script
|
|
13151
|
+
* written there is invisible to it.
|
|
13152
|
+
*/
|
|
13153
|
+
function scriptPath() {
|
|
13154
|
+
return wslScriptPath();
|
|
13155
|
+
}
|
|
13156
|
+
function status(deps) {
|
|
13157
|
+
return wslTemperatureStatus(scriptPath(), deps.panel.settings.host.tempCommand);
|
|
13158
|
+
}
|
|
13159
|
+
/**
|
|
13160
|
+
* The WSL2 temperature bridge, over the panel's own settings.
|
|
13161
|
+
*
|
|
13162
|
+
* Panel-wide (a temperature is the machine's, not a workspace's), and deliberately three small
|
|
13163
|
+
* routes rather than one: read the state, install it, test it. Installing writes a file and changes
|
|
13164
|
+
* a setting, so it is the one that can fail and has to say why.
|
|
13165
|
+
*/
|
|
13166
|
+
function createWslTemperatureRoute(deps) {
|
|
13167
|
+
return appFactory.createApp().get("/host/temperature", describeRoute({
|
|
13168
|
+
tags: ["panel"],
|
|
13169
|
+
summary: "Whether the WSL temperature bridge is set up, and what it last read",
|
|
13170
|
+
responses: { 200: {
|
|
13171
|
+
description: "The bridge state",
|
|
13172
|
+
content: jsonBody(wslTemperatureSchema)
|
|
13173
|
+
} }
|
|
13174
|
+
}), async (c) => {
|
|
13175
|
+
const current = status(deps);
|
|
13176
|
+
if (!current.configured) return c.json(current);
|
|
13177
|
+
const probe = await probeWslTemperature(deps.panel.settings.host.tempCommand, deps.panel.settings.host.tempCommandTimeoutMs);
|
|
13178
|
+
return c.json({
|
|
13179
|
+
...current,
|
|
13180
|
+
lastReadingCelsius: probe.celsius,
|
|
13181
|
+
lastError: probe.error
|
|
13182
|
+
});
|
|
13183
|
+
}).post("/host/temperature", describeRoute({
|
|
13184
|
+
tags: ["panel"],
|
|
13185
|
+
summary: "Write the WSL helper script and point the temperature command at it",
|
|
13186
|
+
responses: {
|
|
13187
|
+
200: {
|
|
13188
|
+
description: "Set up",
|
|
13189
|
+
content: jsonBody(wslTemperatureSchema)
|
|
13190
|
+
},
|
|
13191
|
+
400: ERROR_RESPONSES[400]
|
|
13192
|
+
}
|
|
13193
|
+
}), async (c) => {
|
|
13194
|
+
if (!status(deps).supported) throw new DetailedError("this is not a WSL2 guest, so there is no host sensor to bridge to", {
|
|
13195
|
+
statusCode: 400,
|
|
13196
|
+
code: "NOT_WSL"
|
|
13197
|
+
});
|
|
13198
|
+
const target = scriptPath();
|
|
13199
|
+
if (target === null) throw new DetailedError("the Windows drive is not mounted at /mnt/c, so the helper cannot be written where powershell.exe can read it", {
|
|
13200
|
+
statusCode: 400,
|
|
13201
|
+
code: "WINDOWS_DRIVE_MISSING"
|
|
13202
|
+
});
|
|
13203
|
+
try {
|
|
13204
|
+
writeWslTemperatureScript(target);
|
|
13205
|
+
} catch (error) {
|
|
13206
|
+
throw new DetailedError(`the helper could not be written to ${target}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
13207
|
+
statusCode: 400,
|
|
13208
|
+
code: "SCRIPT_WRITE_FAILED"
|
|
13209
|
+
});
|
|
13210
|
+
}
|
|
13211
|
+
const command = tempCommandFor(target);
|
|
13212
|
+
const probe = await probeWslTemperature(command, 5e3);
|
|
13213
|
+
if (probe.celsius === null) return c.json({
|
|
13214
|
+
...status(deps),
|
|
13215
|
+
lastReadingCelsius: null,
|
|
13216
|
+
lastError: probe.error ?? "the helper did not answer"
|
|
13217
|
+
});
|
|
13218
|
+
deps.panel.settings.updateHost({
|
|
13219
|
+
tempCommand: command,
|
|
13220
|
+
tempCommandTimeoutMs: 5e3
|
|
13221
|
+
});
|
|
13222
|
+
return c.json({
|
|
13223
|
+
...status(deps),
|
|
13224
|
+
lastReadingCelsius: probe.celsius,
|
|
13225
|
+
lastError: null
|
|
13226
|
+
});
|
|
13227
|
+
}).delete("/host/temperature", describeRoute({
|
|
13228
|
+
tags: ["panel"],
|
|
13229
|
+
summary: "Stop using the helper and delete it",
|
|
13230
|
+
responses: {
|
|
13231
|
+
200: {
|
|
13232
|
+
description: "Cleared",
|
|
13233
|
+
content: jsonBody(wslTemperatureSchema)
|
|
13234
|
+
},
|
|
13235
|
+
400: ERROR_RESPONSES[400]
|
|
13236
|
+
}
|
|
13237
|
+
}), async (c) => {
|
|
13238
|
+
const target = scriptPath();
|
|
13239
|
+
deps.panel.settings.updateHost({ tempCommand: "" });
|
|
13240
|
+
try {
|
|
13241
|
+
if (target !== null) fs.rmSync(target, { force: true });
|
|
13242
|
+
} catch {}
|
|
13243
|
+
return c.json(status(deps));
|
|
13244
|
+
});
|
|
13245
|
+
}
|
|
13246
|
+
var init_wsl_temperature = __esmMin((() => {
|
|
13247
|
+
init_factory();
|
|
13248
|
+
init_openapi$1();
|
|
13249
|
+
init_wsl_temperature$1();
|
|
13250
|
+
init_contracts();
|
|
13251
|
+
}));
|
|
13252
|
+
//#endregion
|
|
12716
13253
|
//#region src/helpers/error.ts
|
|
12717
13254
|
function toErrorBody(error) {
|
|
12718
13255
|
if (error instanceof HTTPException) return {
|
|
@@ -12753,12 +13290,139 @@ var init_error = __esmMin((() => {
|
|
|
12753
13290
|
};
|
|
12754
13291
|
}));
|
|
12755
13292
|
//#endregion
|
|
13293
|
+
//#region src/openapi-reference.ts
|
|
13294
|
+
/**
|
|
13295
|
+
* Deliberately a string, not a `.vue` or a template dependency: this route is outside `/api` and outside
|
|
13296
|
+
* both UIs, and `src/**` may not know a UI's files.
|
|
13297
|
+
*/
|
|
13298
|
+
function openApiReferencePage(specUrl) {
|
|
13299
|
+
return `<!doctype html>
|
|
13300
|
+
<html lang="en">
|
|
13301
|
+
<head>
|
|
13302
|
+
<meta charset="utf-8" />
|
|
13303
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
13304
|
+
<title>home-hosted — API reference</title>
|
|
13305
|
+
<style>
|
|
13306
|
+
:root { color-scheme: light dark; --line: #d8dee9; --ink: #14202e; --muted: #5b6b80; --page: #fbfcfe; --code: #eef2f8; }
|
|
13307
|
+
@media (prefers-color-scheme: dark) { :root { --line: #263243; --ink: #e6edf7; --muted: #9fb0c6; --page: #0d131c; --code: #16202c; } }
|
|
13308
|
+
* { box-sizing: border-box; }
|
|
13309
|
+
body { margin: 0; padding: 2rem 1.25rem 4rem; background: var(--page); color: var(--ink);
|
|
13310
|
+
font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
|
13311
|
+
main { max-width: 60rem; margin: 0 auto; }
|
|
13312
|
+
h1 { font-size: 1.35rem; margin: 0 0 .35rem; letter-spacing: -.01em; }
|
|
13313
|
+
p.lede { margin: 0 0 1.75rem; color: var(--muted); }
|
|
13314
|
+
a { color: inherit; }
|
|
13315
|
+
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
|
|
13316
|
+
margin: 2rem 0 .6rem; }
|
|
13317
|
+
ul { list-style: none; margin: 0; padding: 0; }
|
|
13318
|
+
li { display: grid; grid-template-columns: 4.6rem 1fr; gap: .75rem; align-items: baseline;
|
|
13319
|
+
padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .5rem; margin-bottom: .4rem; }
|
|
13320
|
+
.m { font: 600 .72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em;
|
|
13321
|
+
padding: .3rem .4rem; border-radius: .3rem; text-align: center; background: var(--code); }
|
|
13322
|
+
.m[data-m="GET"] { color: #0a7d52; } .m[data-m="POST"] { color: #1f5fd0; }
|
|
13323
|
+
.m[data-m="PUT"], .m[data-m="PATCH"] { color: #8a5b00; } .m[data-m="DELETE"] { color: #b32020; }
|
|
13324
|
+
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86rem; }
|
|
13325
|
+
.summary { color: var(--muted); font-size: .87rem; }
|
|
13326
|
+
.error { padding: 1rem; border: 1px solid var(--line); border-radius: .5rem; color: var(--muted); }
|
|
13327
|
+
footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line);
|
|
13328
|
+
color: var(--muted); font-size: .85rem; }
|
|
13329
|
+
@media (max-width: 30rem) { li { grid-template-columns: 4rem 1fr; } body { padding: 1.25rem 1rem 3rem; } }
|
|
13330
|
+
</style>
|
|
13331
|
+
</head>
|
|
13332
|
+
<body>
|
|
13333
|
+
<main>
|
|
13334
|
+
<h1>home-hosted API</h1>
|
|
13335
|
+
<p class="lede">Every route the panel serves, generated from the same schemas the routes validate
|
|
13336
|
+
with. Send <code>Authorization: Bearer hh_…</code> with any call; a cookie session works too.</p>
|
|
13337
|
+
<div id="app" data-fallback="index"><p class="error">Loading the route index…</p></div>
|
|
13338
|
+
<footer>
|
|
13339
|
+
<a href="${specUrl}">${specUrl}</a> — the OpenAPI document, for
|
|
13340
|
+
<code>openapi-typescript</code>, <code>openapi-generator</code> or any other client.
|
|
13341
|
+
</footer>
|
|
13342
|
+
</main>
|
|
13343
|
+
<script type="module">
|
|
13344
|
+
const specUrl = ${JSON.stringify(specUrl)}
|
|
13345
|
+
const app = document.getElementById('app')
|
|
13346
|
+
|
|
13347
|
+
/**
|
|
13348
|
+
* The index, from the spec, with nothing but \`fetch\`. This is the page's real content: it is what a
|
|
13349
|
+
* person on an air-gapped box sees, and what the browser below replaces only if the CDN answers.
|
|
13350
|
+
*/
|
|
13351
|
+
async function renderIndex() {
|
|
13352
|
+
let spec
|
|
13353
|
+
try {
|
|
13354
|
+
const response = await fetch(specUrl, { headers: { accept: 'application/json' } })
|
|
13355
|
+
if (!response.ok) throw new Error(String(response.status))
|
|
13356
|
+
spec = await response.json()
|
|
13357
|
+
} catch (error) {
|
|
13358
|
+
app.dataset.fallback = 'error'
|
|
13359
|
+
app.innerHTML = '<p class="error">The OpenAPI document could not be read (' +
|
|
13360
|
+
String(error && error.message ? error.message : error) + ').</p>'
|
|
13361
|
+
return
|
|
13362
|
+
}
|
|
13363
|
+
|
|
13364
|
+
const tags = (spec.tags || []).map(tag => tag.name)
|
|
13365
|
+
const groups = new Map(tags.map(name => [name, []]))
|
|
13366
|
+
for (const [path, operations] of Object.entries(spec.paths || {})) {
|
|
13367
|
+
for (const [method, operation] of Object.entries(operations || {})) {
|
|
13368
|
+
const name = (operation.tags && operation.tags[0]) || 'other'
|
|
13369
|
+
if (!groups.has(name)) groups.set(name, [])
|
|
13370
|
+
groups.get(name).push({ path, method: method.toUpperCase(), summary: operation.summary || '' })
|
|
13371
|
+
}
|
|
13372
|
+
}
|
|
13373
|
+
|
|
13374
|
+
let html = ''
|
|
13375
|
+
for (const [tag, rows] of groups) {
|
|
13376
|
+
if (rows.length === 0) continue
|
|
13377
|
+
html += '<h2>' + escapeHtml(tag) + '</h2><ul>'
|
|
13378
|
+
for (const row of rows.sort((a, b) => a.path.localeCompare(b.path) || a.method.localeCompare(b.method)))
|
|
13379
|
+
html += '<li><span class="m" data-m="' + row.method + '">' + row.method + '</span><span><code>' +
|
|
13380
|
+
escapeHtml(row.path) + '</code><br><span class="summary">' + escapeHtml(row.summary) + '</span></span></li>'
|
|
13381
|
+
html += '</ul>'
|
|
13382
|
+
}
|
|
13383
|
+
app.dataset.fallback = 'rendered'
|
|
13384
|
+
app.innerHTML = html || '<p class="error">The OpenAPI document lists no operations.</p>'
|
|
13385
|
+
}
|
|
13386
|
+
|
|
13387
|
+
function escapeHtml(value) {
|
|
13388
|
+
return String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
13389
|
+
.replace(/"/g, '"')
|
|
13390
|
+
}
|
|
13391
|
+
|
|
13392
|
+
await renderIndex()
|
|
13393
|
+
|
|
13394
|
+
/**
|
|
13395
|
+
* Optional enhancement: the interactive reference, which lives on a CDN. It is allowed to fail —
|
|
13396
|
+
* that is the whole point of rendering the index first — so a LAN box with no internet keeps a
|
|
13397
|
+
* usable page instead of a blank one.
|
|
13398
|
+
*
|
|
13399
|
+
* The version is pinned: this is an enhancement fetched from a third party at page load, and a
|
|
13400
|
+
* floating major would let an upstream release break or restyle the panel's page with no change
|
|
13401
|
+
* here. The index above is unaffected either way.
|
|
13402
|
+
*/
|
|
13403
|
+
try {
|
|
13404
|
+
const { createApiReference } = await import('https://cdn.jsdelivr.net/npm/@scalar/api-reference@${SCALAR_VERSION}/esm.js')
|
|
13405
|
+
app.innerHTML = ''
|
|
13406
|
+
app.dataset.fallback = 'enhanced'
|
|
13407
|
+
createApiReference('#app', { _integration: 'hono', url: specUrl, theme: 'deepSpace' })
|
|
13408
|
+
} catch {
|
|
13409
|
+
// No CDN: the index above stays, and that is a supported outcome.
|
|
13410
|
+
}
|
|
13411
|
+
<\/script>
|
|
13412
|
+
</body>
|
|
13413
|
+
</html>`;
|
|
13414
|
+
}
|
|
13415
|
+
var SCALAR_VERSION;
|
|
13416
|
+
var init_openapi_reference = __esmMin((() => {
|
|
13417
|
+
SCALAR_VERSION = "1.76.0";
|
|
13418
|
+
}));
|
|
13419
|
+
//#endregion
|
|
12756
13420
|
//#region src/openapi.ts
|
|
12757
13421
|
/**
|
|
12758
13422
|
* The machine-readable contract, generated from the same ArkType schemas the
|
|
12759
13423
|
* routes validate with — one source of truth, no second set of DTOs to drift.
|
|
12760
|
-
* `/openapi/ui` is
|
|
12761
|
-
*
|
|
13424
|
+
* `/openapi/ui` is the browsable reference and needs no session, since a UI
|
|
13425
|
+
* author has to be able to read it before they can log in.
|
|
12762
13426
|
*/
|
|
12763
13427
|
/** The version the package was built with, so the spec never drifts from it. */
|
|
12764
13428
|
function setupOpenAPI(app) {
|
|
@@ -12829,15 +13493,13 @@ function setupOpenAPI(app) {
|
|
|
12829
13493
|
url: "/",
|
|
12830
13494
|
description: "This panel"
|
|
12831
13495
|
}]
|
|
12832
|
-
} })).get(`${PREFIX}/ui`,
|
|
12833
|
-
theme: "deepSpace",
|
|
12834
|
-
url: `${PREFIX}/spec.json`
|
|
12835
|
-
}));
|
|
13496
|
+
} })).get(`${PREFIX}/ui`, (c) => c.html(openApiReferencePage(`${PREFIX}/spec.json`)));
|
|
12836
13497
|
}
|
|
12837
13498
|
var PREFIX;
|
|
12838
13499
|
var init_openapi = __esmMin((() => {
|
|
12839
13500
|
init_factory();
|
|
12840
13501
|
init_version();
|
|
13502
|
+
init_openapi_reference();
|
|
12841
13503
|
PREFIX = "/openapi";
|
|
12842
13504
|
}));
|
|
12843
13505
|
//#endregion
|
|
@@ -12854,7 +13516,7 @@ function createRootApp(deps) {
|
|
|
12854
13516
|
const started = Date.now();
|
|
12855
13517
|
await next();
|
|
12856
13518
|
logger.debug(`${c.req.method} ${new URL(c.req.url).pathname} ${c.res.status} ${Date.now() - started}ms`);
|
|
12857
|
-
}).onError(errorHandler).route("/_hh", createControlRoute(deps)).route("/_acme", createAcmeChallengeRoute(deps)).use("/api/*", createAuthGuard({ auth: deps.auth })).route("/api", createAuthRoute(deps)).route("/api", createStateRoute(deps)).route("/api", createEventsRoute(deps)).route("/api", createSettingsRoute(deps)).route("/api", createTlsRoute(deps)).route("/api", createLogsRoute(deps)).route("/api", createNotificationsRoute(deps)).route("/api", createDdnsRoute(deps)).route("/api", createProxyRoute(deps)).route("/api", createMetricsRoute(deps)).route("/api", createBackupsRoute(deps)).route("/api/workspaces", createWorkspacesRoute(deps)).route("/api/servers", createServersRoute(deps)).route("/", createHealthRoute(deps));
|
|
13519
|
+
}).onError(errorHandler).route("/_hh", createControlRoute(deps)).route("/_acme", createAcmeChallengeRoute(deps)).use("/api/*", createAuthGuard({ auth: deps.auth })).route("/api", createAuthRoute(deps)).route("/api", createStateRoute(deps)).route("/api", createEventsRoute(deps)).route("/api", createSettingsRoute(deps)).route("/api", createTlsRoute(deps)).route("/api", createWslTemperatureRoute(deps)).route("/api", createLogsRoute(deps)).route("/api", createNotificationsRoute(deps)).route("/api", createDdnsRoute(deps)).route("/api", createProxyRoute(deps)).route("/api", createMetricsRoute(deps)).route("/api", createBackupsRoute(deps)).route("/api/workspaces", createWorkspacesRoute(deps)).route("/api/servers", createServersRoute(deps)).route("/", createHealthRoute(deps));
|
|
12858
13520
|
return app.route("/", setupOpenAPI(app)).route("/", createStaticRoute({ dir: () => deps.ui.resolveDir() }));
|
|
12859
13521
|
}
|
|
12860
13522
|
var init_app = __esmMin((() => {
|
|
@@ -12875,6 +13537,7 @@ var init_app = __esmMin((() => {
|
|
|
12875
13537
|
init_static();
|
|
12876
13538
|
init_tls();
|
|
12877
13539
|
init_$_routes();
|
|
13540
|
+
init_wsl_temperature();
|
|
12878
13541
|
init_error();
|
|
12879
13542
|
init_factory();
|
|
12880
13543
|
init_logger();
|
|
@@ -12995,8 +13658,8 @@ async function probeRuntime(runtime, timeoutMs = 2500) {
|
|
|
12995
13658
|
* Asks the daemon to stop through its own endpoint, so supervised servers are
|
|
12996
13659
|
* shut down cleanly on every platform (a bare signal is not graceful on Windows).
|
|
12997
13660
|
*/
|
|
12998
|
-
async function requestShutdown(runtime, timeoutMs = 4e3) {
|
|
12999
|
-
const answer = await localCall(runtime,
|
|
13661
|
+
async function requestShutdown(runtime, timeoutMs = 4e3, options = {}) {
|
|
13662
|
+
const answer = await localCall(runtime, `/_hh/shutdown${options.withPersistent === true ? "?withPersistent=true" : ""}`, "POST", runtime.token, timeoutMs);
|
|
13000
13663
|
return answer !== null && answer.status >= 200 && answer.status < 300;
|
|
13001
13664
|
}
|
|
13002
13665
|
/**
|
|
@@ -13414,7 +14077,8 @@ async function listZip(file) {
|
|
|
13414
14077
|
directory: entry.directory === true,
|
|
13415
14078
|
encrypted: entry.encrypted === true,
|
|
13416
14079
|
symlink: entry.symlink === true,
|
|
13417
|
-
size: entry.uncompressedSize ?? 0
|
|
14080
|
+
size: entry.uncompressedSize ?? 0,
|
|
14081
|
+
...entry.unixMode === void 0 ? {} : { mode: entry.unixMode }
|
|
13418
14082
|
}));
|
|
13419
14083
|
} finally {
|
|
13420
14084
|
await reader.close();
|
|
@@ -13434,10 +14098,14 @@ function isInvalidPassword(error) {
|
|
|
13434
14098
|
return error instanceof Error && /invalid password/i.test(error.message);
|
|
13435
14099
|
}
|
|
13436
14100
|
/**
|
|
13437
|
-
* Writes the contents of `sourceDir` into `destination`, preserving the tree
|
|
13438
|
-
*
|
|
13439
|
-
*
|
|
13440
|
-
*
|
|
14101
|
+
* Writes the contents of `sourceDir` into `destination`, preserving the tree and each
|
|
14102
|
+
* entry's permission bits.
|
|
14103
|
+
*
|
|
14104
|
+
* The mode is captured because the tree is somebody's data directory: a `0600` key, a `0700`
|
|
14105
|
+
* directory and a `0755` script are all routine there, and a backup that restores them as `0644`
|
|
14106
|
+
* changes who can read the data it was taken to protect. What a symlink may bring in is bounded by
|
|
14107
|
+
* the tree itself (`walk`): the target has to be inside it, so a declared path cannot capture bytes
|
|
14108
|
+
* from outside itself. Streams from disk to disk: nothing is buffered whole.
|
|
13441
14109
|
*/
|
|
13442
14110
|
async function createZip(sourceDir, destination, options = {}) {
|
|
13443
14111
|
const output = fs.createWriteStream(destination, { mode: 384 });
|
|
@@ -13452,9 +14120,18 @@ async function createZip(sourceDir, destination, options = {}) {
|
|
|
13452
14120
|
keepOrder: true
|
|
13453
14121
|
});
|
|
13454
14122
|
try {
|
|
13455
|
-
for (const item of walk(sourceDir))
|
|
13456
|
-
|
|
13457
|
-
|
|
14123
|
+
for (const item of walk(sourceDir)) {
|
|
14124
|
+
const mode = item.mode === null ? {} : { unixMode: item.mode };
|
|
14125
|
+
if (item.directory) await zip.add(item.name, null, {
|
|
14126
|
+
directory: true,
|
|
14127
|
+
...mode
|
|
14128
|
+
});
|
|
14129
|
+
else if (item.size === 0) await zip.add(item.name, null, {
|
|
14130
|
+
directory: false,
|
|
14131
|
+
...mode
|
|
14132
|
+
});
|
|
14133
|
+
else await zip.add(item.name, Readable.toWeb(fs.createReadStream(item.absolute)), mode);
|
|
14134
|
+
}
|
|
13458
14135
|
await zip.close();
|
|
13459
14136
|
await flushed;
|
|
13460
14137
|
} catch (error) {
|
|
@@ -13467,10 +14144,16 @@ async function createZip(sourceDir, destination, options = {}) {
|
|
|
13467
14144
|
* Extracts the given entries (already validated by the caller) into
|
|
13468
14145
|
* `destination`. Symbolic links are never recreated — an archive is not allowed
|
|
13469
14146
|
* to make the filesystem point somewhere else.
|
|
14147
|
+
*
|
|
14148
|
+
* An entry's permission bits are applied after it lands. The file is created under a restrictive
|
|
14149
|
+
* mode first, so a `0600` secret never exists world-readable between two calls, and a mode the
|
|
14150
|
+
* current umask would widen is set with an explicit `chmod` rather than left to the create.
|
|
13470
14151
|
*/
|
|
13471
14152
|
async function extractZip(file, destination, options) {
|
|
13472
14153
|
const reader = await open(file, options.password);
|
|
13473
14154
|
const skipped = [];
|
|
14155
|
+
/** Directory modes, applied after their contents: a `0700` dir cannot be written into. */
|
|
14156
|
+
const pendingDirModes = [];
|
|
13474
14157
|
try {
|
|
13475
14158
|
const entries = new Map((await reader.getEntries()).map((entry) => [entry.filename, entry]));
|
|
13476
14159
|
for (const name of options.names) {
|
|
@@ -13482,6 +14165,11 @@ async function extractZip(file, destination, options) {
|
|
|
13482
14165
|
const target = path.join(destination, name);
|
|
13483
14166
|
if (entry.directory) {
|
|
13484
14167
|
fs.mkdirSync(target, { recursive: true });
|
|
14168
|
+
const mode = permissionBits(entry.unixMode);
|
|
14169
|
+
if (mode !== null) pendingDirModes.push({
|
|
14170
|
+
target,
|
|
14171
|
+
mode
|
|
14172
|
+
});
|
|
13485
14173
|
continue;
|
|
13486
14174
|
}
|
|
13487
14175
|
if (entry.symlink) {
|
|
@@ -13489,10 +14177,18 @@ async function extractZip(file, destination, options) {
|
|
|
13489
14177
|
continue;
|
|
13490
14178
|
}
|
|
13491
14179
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
13492
|
-
await entry.getData(Writable.toWeb(fs.createWriteStream(target)), writeOptions(entry, options.password));
|
|
14180
|
+
await entry.getData(Writable.toWeb(fs.createWriteStream(target, { mode: 384 })), writeOptions(entry, options.password));
|
|
14181
|
+
const mode = permissionBits(entry.unixMode);
|
|
14182
|
+
if (mode !== null) try {
|
|
14183
|
+
fs.chmodSync(target, mode);
|
|
14184
|
+
} catch {}
|
|
13493
14185
|
}
|
|
13494
14186
|
} finally {
|
|
13495
14187
|
await reader.close();
|
|
14188
|
+
for (const { target, mode } of pendingDirModes.sort((left, right) => right.target.length - left.target.length)) try {
|
|
14189
|
+
fs.chmodSync(target, mode);
|
|
14190
|
+
} catch {}
|
|
14191
|
+
pendingDirModes.length = 0;
|
|
13496
14192
|
}
|
|
13497
14193
|
return { skipped };
|
|
13498
14194
|
}
|
|
@@ -13504,15 +14200,58 @@ async function open(file, password) {
|
|
|
13504
14200
|
return password === void 0 ? new ZipReader(new BlobReader(blob)) : new ZipReader(new BlobReader(blob), { password });
|
|
13505
14201
|
}
|
|
13506
14202
|
/**
|
|
13507
|
-
*
|
|
14203
|
+
* The `st_mode` an entry should carry, or `null` where the platform does not report one.
|
|
14204
|
+
*
|
|
14205
|
+
* Only the permission bits and the file type are kept: the archive records a mode, not an owner,
|
|
14206
|
+
* because a restore runs as whoever restores it and a foreign uid would be a worse lie than the
|
|
14207
|
+
* restoring user's own.
|
|
14208
|
+
*/
|
|
14209
|
+
function archiveMode(stats) {
|
|
14210
|
+
const bits = stats.mode & 511;
|
|
14211
|
+
if (process.platform === "win32" || bits === 0) return null;
|
|
14212
|
+
return (stats.isDirectory() ? 16384 : 32768) | bits;
|
|
14213
|
+
}
|
|
14214
|
+
/**
|
|
14215
|
+
* The permission bits an extracted entry should be given, or `null` when the archive carries none.
|
|
14216
|
+
*
|
|
14217
|
+
* Zip stores the type in the same field, so the file type is dropped: the entry is written as the
|
|
14218
|
+
* ordinary file or directory this call is creating, never as a fifo or a device node an archive
|
|
14219
|
+
* could name. The setuid/setgid/sticky bits are dropped too — an archive from another host does not
|
|
14220
|
+
* get to install a privileged binary here.
|
|
14221
|
+
*/
|
|
14222
|
+
function permissionBits(unixMode) {
|
|
14223
|
+
if (unixMode === void 0 || unixMode === 0) return null;
|
|
14224
|
+
const bits = unixMode & 511;
|
|
14225
|
+
return bits === 0 ? null : bits;
|
|
14226
|
+
}
|
|
14227
|
+
/** True when `child` is `parent` itself or lives underneath it, after resolving both. */
|
|
14228
|
+
function isUnderResolved(parent, child) {
|
|
14229
|
+
const relative = path.relative(parent, child);
|
|
14230
|
+
return relative === "" || !path.isAbsolute(relative) && !relative.startsWith("..");
|
|
14231
|
+
}
|
|
14232
|
+
/**
|
|
14233
|
+
* Sorted, deterministic walk with directory loops broken and the declared tree respected.
|
|
13508
14234
|
*
|
|
13509
14235
|
* Every read is best-effort: a directory that vanishes mid-walk (a rotated log, a
|
|
13510
14236
|
* build directory being cleaned, a container being torn down) must leave it out of
|
|
13511
14237
|
* the archive rather than reject `createZip` and turn a backup into a failure.
|
|
14238
|
+
*
|
|
14239
|
+
* A link that resolves **outside** `root` is left out rather than followed. `root` is a copy of the
|
|
14240
|
+
* declared path, so a link inside it points back at the live tree — following one captured bytes
|
|
14241
|
+
* from outside the path the person declared (a `media -> /mnt/nas` symlink pulled the whole share
|
|
14242
|
+
* into the archive), and it captured the *live* copy of anything the copy had already frozen. A
|
|
14243
|
+
* restore never recreates links anyway, so the link itself has nothing to restore; its content, if
|
|
14244
|
+
* it is wanted, is declared as its own path.
|
|
13512
14245
|
*/
|
|
13513
14246
|
function walk(root) {
|
|
13514
14247
|
const files = [];
|
|
13515
14248
|
const seen = /* @__PURE__ */ new Set();
|
|
14249
|
+
let realRoot;
|
|
14250
|
+
try {
|
|
14251
|
+
realRoot = fs.realpathSync(root);
|
|
14252
|
+
} catch {
|
|
14253
|
+
return files;
|
|
14254
|
+
}
|
|
13516
14255
|
const readDir = (absolute) => {
|
|
13517
14256
|
try {
|
|
13518
14257
|
return fs.readdirSync(absolute).sort();
|
|
@@ -13527,20 +14266,22 @@ function walk(root) {
|
|
|
13527
14266
|
} catch {
|
|
13528
14267
|
return;
|
|
13529
14268
|
}
|
|
14269
|
+
let real;
|
|
14270
|
+
try {
|
|
14271
|
+
real = fs.realpathSync(absolute);
|
|
14272
|
+
} catch {
|
|
14273
|
+
return;
|
|
14274
|
+
}
|
|
14275
|
+
if (!isUnderResolved(realRoot, real)) return;
|
|
13530
14276
|
if (stats.isDirectory()) {
|
|
13531
|
-
let real;
|
|
13532
|
-
try {
|
|
13533
|
-
real = fs.realpathSync(absolute);
|
|
13534
|
-
} catch {
|
|
13535
|
-
return;
|
|
13536
|
-
}
|
|
13537
14277
|
if (seen.has(real)) return;
|
|
13538
14278
|
seen.add(real);
|
|
13539
14279
|
files.push({
|
|
13540
14280
|
name: `${name}/`,
|
|
13541
14281
|
absolute,
|
|
13542
14282
|
directory: true,
|
|
13543
|
-
size: 0
|
|
14283
|
+
size: 0,
|
|
14284
|
+
mode: archiveMode(stats)
|
|
13544
14285
|
});
|
|
13545
14286
|
for (const child of readDir(absolute)) visit(path.join(absolute, child), `${name}/${child}`);
|
|
13546
14287
|
return;
|
|
@@ -13549,7 +14290,8 @@ function walk(root) {
|
|
|
13549
14290
|
name,
|
|
13550
14291
|
absolute,
|
|
13551
14292
|
directory: false,
|
|
13552
|
-
size: stats.size
|
|
14293
|
+
size: stats.size,
|
|
14294
|
+
mode: archiveMode(stats)
|
|
13553
14295
|
});
|
|
13554
14296
|
};
|
|
13555
14297
|
for (const child of readDir(root)) visit(path.join(root, child), child);
|
|
@@ -13745,6 +14487,10 @@ function findComposeFile(from) {
|
|
|
13745
14487
|
dir = parent;
|
|
13746
14488
|
}
|
|
13747
14489
|
}
|
|
14490
|
+
/** Whether this argv runs a compose stack, without resolving anything — a cheap pre-check. */
|
|
14491
|
+
function isComposeCommand(command, args) {
|
|
14492
|
+
return composeArgv(command, args) !== null;
|
|
14493
|
+
}
|
|
13748
14494
|
/**
|
|
13749
14495
|
* The compose project an entry runs, from evidence in its own config: the command it spawns, its
|
|
13750
14496
|
* argv, its cwd and its environment. `null` means "sample the process tree", which is the right
|
|
@@ -13801,6 +14547,58 @@ function sumContainers(rows, readings) {
|
|
|
13801
14547
|
containers: rows.length
|
|
13802
14548
|
};
|
|
13803
14549
|
}
|
|
14550
|
+
/** Whether a container publishing a port belongs to the stack this entry itself declares. */
|
|
14551
|
+
function isOwnStack(holder, target) {
|
|
14552
|
+
if (target === null) return false;
|
|
14553
|
+
if (holder.project !== null && target.project !== null) return holder.project === target.project;
|
|
14554
|
+
if (holder.composeDir === null) return false;
|
|
14555
|
+
return target.configFiles.some((file) => samePath(path.dirname(file), holder.composeDir));
|
|
14556
|
+
}
|
|
14557
|
+
/** One target's running containers from a fresh `docker ps`, or `null` when docker cannot answer. */
|
|
14558
|
+
async function composeContainers(target) {
|
|
14559
|
+
try {
|
|
14560
|
+
return attributeContainers(target, parseDockerPs((await execFileAsync$1("docker", [
|
|
14561
|
+
"ps",
|
|
14562
|
+
"--filter",
|
|
14563
|
+
"label=com.docker.compose.project",
|
|
14564
|
+
"--format",
|
|
14565
|
+
PS_FORMAT
|
|
14566
|
+
], {
|
|
14567
|
+
timeout: 5e3,
|
|
14568
|
+
maxBuffer: 4194304
|
|
14569
|
+
})).stdout));
|
|
14570
|
+
} catch {
|
|
14571
|
+
return null;
|
|
14572
|
+
}
|
|
14573
|
+
}
|
|
14574
|
+
/**
|
|
14575
|
+
* Stops every container of one target and reports what is still running afterwards.
|
|
14576
|
+
*
|
|
14577
|
+
* The answer comes from a **fresh listing**, not from `docker stop`'s exit code: a stop that
|
|
14578
|
+
* printed success for a container still listed is the empty success this exists to refuse.
|
|
14579
|
+
* `null` means docker could not be asked, which is not the same as "it stopped".
|
|
14580
|
+
*/
|
|
14581
|
+
async function stopComposeContainers(target) {
|
|
14582
|
+
const before = await composeContainers(target);
|
|
14583
|
+
if (before === null) return null;
|
|
14584
|
+
if (before.length === 0) return {
|
|
14585
|
+
stopped: [],
|
|
14586
|
+
survivors: []
|
|
14587
|
+
};
|
|
14588
|
+
try {
|
|
14589
|
+
await execFileAsync$1("docker", ["stop", ...before.map((row) => row.name)], {
|
|
14590
|
+
timeout: 12e4,
|
|
14591
|
+
maxBuffer: 4194304
|
|
14592
|
+
});
|
|
14593
|
+
} catch {}
|
|
14594
|
+
const after = await composeContainers(target);
|
|
14595
|
+
if (after === null) return null;
|
|
14596
|
+
const remaining = new Set(after.map((row) => row.name));
|
|
14597
|
+
return {
|
|
14598
|
+
stopped: before.map((row) => row.name).filter((name) => !remaining.has(name)),
|
|
14599
|
+
survivors: after.map((row) => row.name)
|
|
14600
|
+
};
|
|
14601
|
+
}
|
|
13804
14602
|
var execFileAsync$1, DOCKER_CACHE_MS, COMPOSE_FILES, COMPOSE_VALUE_FLAGS, COMPOSE_VALUELESS_FLAGS, DOCKER_VALUE_FLAGS, PS_FORMAT, EMPTY, statsLineSchema, BYTE_SCALES, DockerMetrics;
|
|
13805
14603
|
var init_docker = __esmMin((() => {
|
|
13806
14604
|
execFileAsync$1 = promisify(execFile);
|
|
@@ -14702,15 +15500,15 @@ var init_supervisor = __esmMin((() => {
|
|
|
14702
15500
|
for (const config of orderByDependencies(targets)) await this.start(config.id, { actor: "boot" });
|
|
14703
15501
|
}
|
|
14704
15502
|
/**
|
|
14705
|
-
* Stops every entry this command owns. A persistent entry is deliberately not among
|
|
14706
|
-
*
|
|
15503
|
+
* Stops every entry this command owns. A persistent entry is deliberately not among them
|
|
15504
|
+
* unless asked: that is the whole point of the flag, and it is said out loud rather than
|
|
14707
15505
|
* silently skipped, so "stopped everything" is never claimed about a running server.
|
|
14708
15506
|
*/
|
|
14709
|
-
async stopAll() {
|
|
15507
|
+
async stopAll(options = {}) {
|
|
14710
15508
|
const targets = orderByDependencies([...this.entries.values()].map((entry) => entry.config)).reverse();
|
|
14711
15509
|
for (const config of targets) {
|
|
14712
15510
|
const entry = this.entries.get(config.id);
|
|
14713
|
-
if (entry !== void 0 && entry.config.persistent) {
|
|
15511
|
+
if (entry !== void 0 && entry.config.persistent && options.withPersistent !== true) {
|
|
14714
15512
|
if (this.isActive(entry)) this.log(entry, "system", "persistent: left running (stop it explicitly to end it)");
|
|
14715
15513
|
continue;
|
|
14716
15514
|
}
|
|
@@ -15015,12 +15813,17 @@ var init_supervisor = __esmMin((() => {
|
|
|
15015
15813
|
entry.logs.clear();
|
|
15016
15814
|
this.publishServer(entry);
|
|
15017
15815
|
}
|
|
15018
|
-
|
|
15816
|
+
/**
|
|
15817
|
+
* Ends this supervisor's work. Persistent entries outlive the process by design, so they
|
|
15818
|
+
* are left running unless `withPersistent` says otherwise — `down --with-persistent` is
|
|
15819
|
+
* what asks, and it needs the stop recorded here, while the panel is still alive to do it.
|
|
15820
|
+
*/
|
|
15821
|
+
async dispose(options = {}) {
|
|
15019
15822
|
this.disposed = true;
|
|
15020
15823
|
clearInterval(this.tickTimer);
|
|
15021
15824
|
this.storeUnsubscribe();
|
|
15022
15825
|
for (const entry of this.entries.values()) this.clearRetry(entry);
|
|
15023
|
-
await Promise.all([...this.entries.values()].filter((entry) => !entry.config.persistent).map((entry) => this.stopEntry(entry)));
|
|
15826
|
+
await Promise.all([...this.entries.values()].filter((entry) => options.withPersistent === true || !entry.config.persistent).map((entry) => this.stopEntry(entry)));
|
|
15024
15827
|
this.relay.dispose();
|
|
15025
15828
|
}
|
|
15026
15829
|
/**
|
|
@@ -15088,6 +15891,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
15088
15891
|
});
|
|
15089
15892
|
if (entry.child === null && entry.pid === null) {
|
|
15090
15893
|
entry.stopping = false;
|
|
15894
|
+
const stack = await this.stopComposeStack(entry);
|
|
15895
|
+
entry.stopping = false;
|
|
15896
|
+
if (this.refuseLingeringStack(entry, stack)) return {
|
|
15897
|
+
ok: false,
|
|
15898
|
+
error: entry.lastError
|
|
15899
|
+
};
|
|
15091
15900
|
entry.status = "stopped";
|
|
15092
15901
|
this.publishServer(entry);
|
|
15093
15902
|
return { ok: true };
|
|
@@ -15120,6 +15929,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15120
15929
|
}
|
|
15121
15930
|
entry.stopping = false;
|
|
15122
15931
|
entry.child = null;
|
|
15932
|
+
const stack = await this.stopComposeStack(entry);
|
|
15123
15933
|
this.endProcessReadings(entry);
|
|
15124
15934
|
entry.nannyExit = null;
|
|
15125
15935
|
this.endHealthStreak(entry);
|
|
@@ -15128,11 +15938,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
15128
15938
|
entry.lastChild = null;
|
|
15129
15939
|
this.persistEntryState(entry);
|
|
15130
15940
|
}
|
|
15131
|
-
|
|
15941
|
+
const lingering = this.refuseLingeringStack(entry, stack);
|
|
15132
15942
|
if (survivor !== null) entry.lastError = `pid ${survivor} survived the stop`;
|
|
15133
|
-
|
|
15943
|
+
entry.status = survivor === null && !lingering ? "stopped" : "conflict";
|
|
15944
|
+
this.log(entry, "system", entry.status === "stopped" ? "stopped" : entry.lastError);
|
|
15134
15945
|
this.publishServer(entry);
|
|
15135
|
-
return
|
|
15946
|
+
return entry.status === "stopped" ? { ok: true } : {
|
|
15136
15947
|
ok: false,
|
|
15137
15948
|
error: entry.lastError
|
|
15138
15949
|
};
|
|
@@ -15364,7 +16175,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
15364
16175
|
this.log(entry, "system", `port ${port} is held by pid ${own}, a detached restart of this entry — replacing it with a supervised process`);
|
|
15365
16176
|
return await this.stopPortHolders(entry, [own], port, "replacing", freeOnAll);
|
|
15366
16177
|
}
|
|
15367
|
-
const hint =
|
|
16178
|
+
const hint = isOwnStack(docker ?? {
|
|
16179
|
+
project: null,
|
|
16180
|
+
composeDir: null
|
|
16181
|
+
}, entry.compose) ? ` — this is this entry's own stack, already up: set onPortConflict to "warn" to attach to it` : own !== null ? ` — pid ${own} is a detached restart of this entry: set onPortConflict to "follow" to adopt it, "reclaim" to replace it with a supervised process, or "kill" to stop whatever holds the port` : docker === null ? "" : ` — it is published by a docker container, which \`kill\` stops through docker; \`block\` and \`warn\` leave it alone`;
|
|
15368
16182
|
const blockedError = ours.length > 0 ? this.heldByOurs(port, ours, siblings) : `port ${port} is already in use${suffix}${hint}`;
|
|
15369
16183
|
if (entry.config.onPortConflict !== "warn") {
|
|
15370
16184
|
entry.status = "conflict";
|
|
@@ -15555,6 +16369,46 @@ var init_supervisor = __esmMin((() => {
|
|
|
15555
16369
|
else if (code !== null) this.log(entry, "system", `bootstrap exited with code ${code} — continuing anyway`);
|
|
15556
16370
|
}
|
|
15557
16371
|
/**
|
|
16372
|
+
* Marks a stop that did not take because a container outlived it, and reports whether it happened.
|
|
16373
|
+
*
|
|
16374
|
+
* Both stop paths can end with the wrapper gone and the stack up — with no child to signal at all
|
|
16375
|
+
* (a reboot, `compose up -d` from a shell, a panel crash), or with one this process signalled that
|
|
16376
|
+
* did not take its containers down. One sentence for the one condition, so the card answers the
|
|
16377
|
+
* same whether the person pressed Stop on a conflict or on a running entry.
|
|
16378
|
+
*/
|
|
16379
|
+
refuseLingeringStack(entry, stack) {
|
|
16380
|
+
const survivors = stack?.survivors ?? [];
|
|
16381
|
+
if (survivors.length === 0) return false;
|
|
16382
|
+
entry.status = "conflict";
|
|
16383
|
+
entry.lastError = `the stack "${entry.config.id}" is still running: container${survivors.length === 1 ? "" : "s"} ${survivors.join(", ")} — docker was asked to stop them and they stayed up`;
|
|
16384
|
+
this.log(entry, "system", entry.lastError);
|
|
16385
|
+
return true;
|
|
16386
|
+
}
|
|
16387
|
+
/**
|
|
16388
|
+
* Stops the running containers of a compose entry whose wrapper this panel is not holding.
|
|
16389
|
+
*
|
|
16390
|
+
* A compose entry's server is its containers, and they are not descendants of the wrapper: a
|
|
16391
|
+
* reboot, a `docker compose up -d` from a shell, or a panel crash leaves them running with no
|
|
16392
|
+
* child to signal. The stop path answered "stopped" for exactly that state (measured: the stack
|
|
16393
|
+
* kept serving HTTP 200 through `stop`, `stop-all` and `down`, all exiting 0), so the containers
|
|
16394
|
+
* have to be ended by the thing that knows which stack this entry declares.
|
|
16395
|
+
*
|
|
16396
|
+
* `null` means "this entry has no compose stack, or docker could not be asked" — the caller then
|
|
16397
|
+
* reports what it can actually see, never a stack it did not confirm is gone.
|
|
16398
|
+
*/
|
|
16399
|
+
async stopComposeStack(entry) {
|
|
16400
|
+
if (entry.compose === null && !isComposeCommand(entry.config.command, entry.config.args)) return null;
|
|
16401
|
+
if (entry.compose === null) this.detectCompose(entry, this.resolveSpawn(entry));
|
|
16402
|
+
if (entry.compose === null) return null;
|
|
16403
|
+
const outcome = await stopComposeContainers(entry.compose);
|
|
16404
|
+
if (outcome === null) {
|
|
16405
|
+
this.log(entry, "system", "docker could not be asked to stop this stack — its containers were not confirmed stopped");
|
|
16406
|
+
return null;
|
|
16407
|
+
}
|
|
16408
|
+
if (outcome.stopped.length > 0) this.log(entry, "system", `stopped the container${outcome.stopped.length === 1 ? "" : "s"} ${outcome.stopped.join(", ")}`);
|
|
16409
|
+
return outcome;
|
|
16410
|
+
}
|
|
16411
|
+
/**
|
|
15558
16412
|
* Whether this entry runs a compose stack, from what it would actually spawn.
|
|
15559
16413
|
*
|
|
15560
16414
|
* `command`/`args` are read through the same `resolveSpawn` the spawn itself uses, so the
|
|
@@ -16443,6 +17297,21 @@ function readArchivedServers(staging, workspaceId, defaults = {}) {
|
|
|
16443
17297
|
return [];
|
|
16444
17298
|
}
|
|
16445
17299
|
}
|
|
17300
|
+
/**
|
|
17301
|
+
* Whether one archive path segment is a name a filesystem will accept as-is.
|
|
17302
|
+
*
|
|
17303
|
+
* A separator moves the path, and `\` is a separator on Windows while an archive crosses platforms;
|
|
17304
|
+
* `:` re-roots or opens a stream there. A control character is never a real filename and is how an
|
|
17305
|
+
* extractor is confused. Everything else — spaces, non-ASCII, `&`, `$`, `#`, `@` — is what a data
|
|
17306
|
+
* directory actually contains.
|
|
17307
|
+
*/
|
|
17308
|
+
function isPortableSegment(segment) {
|
|
17309
|
+
for (const character of segment) {
|
|
17310
|
+
const code = character.codePointAt(0) ?? 0;
|
|
17311
|
+
if (character === "\\" || character === ":" || code < 32 || code === 127) return false;
|
|
17312
|
+
}
|
|
17313
|
+
return true;
|
|
17314
|
+
}
|
|
16446
17315
|
function isSafeArchiveEntry(entry) {
|
|
16447
17316
|
if (entry.startsWith("/") || entry.includes("\0")) return false;
|
|
16448
17317
|
const cleaned = entry.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -16451,7 +17320,7 @@ function isSafeArchiveEntry(entry) {
|
|
|
16451
17320
|
const segments = cleaned.split("/");
|
|
16452
17321
|
if (segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) return false;
|
|
16453
17322
|
if (!ALLOWED_ROOTS.has(segments[0])) return false;
|
|
16454
|
-
return segments.every(
|
|
17323
|
+
return segments.every(isPortableSegment);
|
|
16455
17324
|
}
|
|
16456
17325
|
async function admitArchive(archivePath) {
|
|
16457
17326
|
if (!isZipArchive(archivePath)) return {
|
|
@@ -16602,16 +17471,53 @@ function buildBackupSources(input) {
|
|
|
16602
17471
|
};
|
|
16603
17472
|
}
|
|
16604
17473
|
/**
|
|
17474
|
+
* An archived config, lifted to the schema this release reads.
|
|
17475
|
+
*
|
|
17476
|
+
* An archive is a snapshot, so the release that wrote it is often **older** than the one restoring
|
|
17477
|
+
* it — the backup someone takes before an upgrade is the one they reach for afterwards. Its files
|
|
17478
|
+
* carry the schema they were written with, and the parsers refuse an older stamp by design, so a
|
|
17479
|
+
* plain readability gate discarded every config an older archive carried: measured on a real
|
|
17480
|
+
* 0.7.21 archive applied to a blank 0.10.0 home, it reported "restored 4 items" and every one of
|
|
17481
|
+
* them was a secrets leaf, while both workspaces and the global settings were dropped as "not
|
|
17482
|
+
* valid" — a half-restored setup that reads as a success.
|
|
17483
|
+
*
|
|
17484
|
+
* So run the same chain `migrate` runs, on the contents rather than on a file: an archive that
|
|
17485
|
+
* needs lifting is lifted, and one this release cannot lift is still refused. A newer archive is
|
|
17486
|
+
* never rewritten here — that direction is refused earlier, from the manifest's own schema.
|
|
17487
|
+
*
|
|
17488
|
+
* **Lifting needs an explicit older stamp.** A file carrying no `meta.schema` is not evidence of an
|
|
17489
|
+
* older release — it is a seed (written in the current shape) or a damaged file, and lifting an
|
|
17490
|
+
* unparseable one let `{"not": "a servers file"}` be stamped as a valid empty `servers.config.json`,
|
|
17491
|
+
* which would restore a workspace with every entry deleted. Only a numeric stamp this release can
|
|
17492
|
+
* lift qualifies; anything else is left to its own parser, which refuses it.
|
|
17493
|
+
*
|
|
17494
|
+
* `null` means "this release cannot read it", which stays distinguishable from "it was fine".
|
|
17495
|
+
*/
|
|
17496
|
+
function liftArchived(raw) {
|
|
17497
|
+
if (!isRecord(raw)) return null;
|
|
17498
|
+
const meta = isRecord(raw.meta) ? raw.meta : {};
|
|
17499
|
+
if (typeof meta.schema !== "number") return raw;
|
|
17500
|
+
const plan = planConfigMigrations(meta.schema);
|
|
17501
|
+
if (plan.tooNew || plan.reached !== plan.to) return null;
|
|
17502
|
+
if (plan.steps.length === 0) return raw;
|
|
17503
|
+
const lifted = applyConfigMigrations(raw, meta.schema).config;
|
|
17504
|
+
return isRecord(lifted) ? stampConfig(lifted) : null;
|
|
17505
|
+
}
|
|
17506
|
+
/**
|
|
16605
17507
|
* A restored settings file is accepted when this release can read it — through
|
|
16606
17508
|
* the same tolerant parser the stores use, so an archive from a newer release
|
|
16607
17509
|
* keeps only the keys this one understands instead of being refused outright.
|
|
17510
|
+
*
|
|
17511
|
+
* An older one is lifted first (`liftArchived`), and the **lifted** value is returned so the
|
|
17512
|
+
* caller writes a config this release can load rather than the stamp it could not.
|
|
16608
17513
|
*/
|
|
16609
17514
|
function readableGlobalSettings(text) {
|
|
16610
|
-
if (text === null) return
|
|
17515
|
+
if (text === null) return null;
|
|
16611
17516
|
try {
|
|
16612
|
-
|
|
17517
|
+
const lifted = liftArchived(JSON.parse(text));
|
|
17518
|
+
return lifted !== null && parseGlobalSettings(lifted).config !== null ? lifted : null;
|
|
16613
17519
|
} catch {
|
|
16614
|
-
return
|
|
17520
|
+
return null;
|
|
16615
17521
|
}
|
|
16616
17522
|
}
|
|
16617
17523
|
/**
|
|
@@ -16706,21 +17612,27 @@ function manifestInfo(manifest) {
|
|
|
16706
17612
|
* `servers.config.json` is only a readability gate here: the store applies the
|
|
16707
17613
|
* workspace's own defaults on the next load, and an archive from another machine
|
|
16708
17614
|
* need not match this one's default shapes exactly.
|
|
17615
|
+
*
|
|
17616
|
+
* An older archive is lifted to this release's schema first, so its entries are adopted rather
|
|
17617
|
+
* than dropped; `null` means this release cannot read it at all.
|
|
16709
17618
|
*/
|
|
16710
17619
|
function readableServersFile(text) {
|
|
16711
17620
|
try {
|
|
16712
|
-
const
|
|
17621
|
+
const lifted = liftArchived(JSON.parse(text));
|
|
17622
|
+
if (lifted === null) return null;
|
|
17623
|
+
const result = parseServersFile(lifted, {});
|
|
16713
17624
|
return result.errors.length === 0 ? result.servers : null;
|
|
16714
17625
|
} catch {
|
|
16715
17626
|
return null;
|
|
16716
17627
|
}
|
|
16717
17628
|
}
|
|
16718
|
-
/** A workspace settings file is adopted only when this release can read it. */
|
|
17629
|
+
/** A workspace settings file is adopted only when this release can read it, lifted when older. */
|
|
16719
17630
|
function readableWorkspaceSettings(text) {
|
|
16720
17631
|
try {
|
|
16721
|
-
|
|
17632
|
+
const lifted = liftArchived(JSON.parse(text));
|
|
17633
|
+
return lifted !== null && parseWorkspaceSettings(lifted).config !== null ? lifted : null;
|
|
16722
17634
|
} catch {
|
|
16723
|
-
return
|
|
17635
|
+
return null;
|
|
16724
17636
|
}
|
|
16725
17637
|
}
|
|
16726
17638
|
var MANIFEST, REGISTRY, ALLOWED_ROOTS, SUFFIX, PENDING_LOAD, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
@@ -17134,7 +18046,8 @@ var init_backups = __esmMin((() => {
|
|
|
17134
18046
|
}
|
|
17135
18047
|
};
|
|
17136
18048
|
const settingsText = readText(path.join(staging, "global", "settings.json"));
|
|
17137
|
-
const
|
|
18049
|
+
const liftedGlobal = readableGlobalSettings(settingsText);
|
|
18050
|
+
const parsedGlobal = liftedGlobal === null ? null : parseGlobalSettings(liftedGlobal).config;
|
|
17138
18051
|
if (settingsText !== null && parsedGlobal === null) {
|
|
17139
18052
|
plan.skipped.push("Global settings (the archive's settings are not valid)");
|
|
17140
18053
|
plan.skippedItems.push({
|
|
@@ -17143,16 +18056,19 @@ var init_backups = __esmMin((() => {
|
|
|
17143
18056
|
reasonKey: "settings.restore.reasonInvalidSettings"
|
|
17144
18057
|
});
|
|
17145
18058
|
}
|
|
17146
|
-
if (parsedGlobal !== null &&
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
18059
|
+
if (parsedGlobal !== null && liftedGlobal !== null) {
|
|
18060
|
+
const globalText = `${JSON.stringify(liftedGlobal, null, 2)}\n`;
|
|
18061
|
+
addItem({
|
|
18062
|
+
id: "global:settings",
|
|
18063
|
+
label: "Global settings",
|
|
18064
|
+
labelKey: "settings.backup.entryGlobalSettings",
|
|
18065
|
+
kind: "settings",
|
|
18066
|
+
restorable: true,
|
|
18067
|
+
note: null
|
|
18068
|
+
}, () => {
|
|
18069
|
+
writeFileAtomic(sources.globalSettingsPath, globalText);
|
|
18070
|
+
}, ["config"]);
|
|
18071
|
+
}
|
|
17156
18072
|
const globalSecrets = readText(path.join(staging, "global", "secrets.json"));
|
|
17157
18073
|
if (globalSecrets !== null) {
|
|
17158
18074
|
const globalSecretKeys = presentSecretKeys(parseSecrets(globalSecrets));
|
|
@@ -17242,23 +18158,26 @@ var init_backups = __esmMin((() => {
|
|
|
17242
18158
|
}
|
|
17243
18159
|
if (!sources.workspaces.some((candidate) => candidate.id === id)) createdWorkspaces.set(id, workspace);
|
|
17244
18160
|
if (settings !== null) {
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
|
|
17248
|
-
|
|
17249
|
-
|
|
17250
|
-
|
|
17251
|
-
|
|
17252
|
-
|
|
17253
|
-
|
|
17254
|
-
|
|
17255
|
-
|
|
17256
|
-
|
|
17257
|
-
|
|
17258
|
-
|
|
17259
|
-
|
|
17260
|
-
|
|
17261
|
-
|
|
18161
|
+
const liftedSettings = readableWorkspaceSettings(settings);
|
|
18162
|
+
if (liftedSettings !== null) {
|
|
18163
|
+
const settingsText = `${JSON.stringify(liftedSettings, null, 2)}\n`;
|
|
18164
|
+
addItem({
|
|
18165
|
+
id: `workspace:${id}:settings`,
|
|
18166
|
+
label: `${workspace.label}: Settings`,
|
|
18167
|
+
labelKey: "settings.backup.restoreItemLabel",
|
|
18168
|
+
labelParams: {
|
|
18169
|
+
workspace: workspace.label,
|
|
18170
|
+
item: "settings"
|
|
18171
|
+
},
|
|
18172
|
+
kind: "settings",
|
|
18173
|
+
workspaceId: id,
|
|
18174
|
+
restorable: true,
|
|
18175
|
+
note: null
|
|
18176
|
+
}, () => {
|
|
18177
|
+
fs.mkdirSync(path.dirname(workspace.settingsPath), { recursive: true });
|
|
18178
|
+
writeFileAtomic(workspace.settingsPath, settingsText);
|
|
18179
|
+
});
|
|
18180
|
+
} else {
|
|
17262
18181
|
plan.skipped.push(`${workspace.label}: Settings (the archive's settings are not valid)`);
|
|
17263
18182
|
plan.skippedItems.push({
|
|
17264
18183
|
label: `${workspace.label}: Settings`,
|
|
@@ -17273,7 +18192,9 @@ var init_backups = __esmMin((() => {
|
|
|
17273
18192
|
}
|
|
17274
18193
|
if (servers !== null) {
|
|
17275
18194
|
const parsed = readableServersFile(servers);
|
|
17276
|
-
|
|
18195
|
+
const liftedServers = parsed === null ? null : liftArchived(JSON.parse(servers));
|
|
18196
|
+
if (parsed !== null && liftedServers !== null) {
|
|
18197
|
+
const serversText = `${JSON.stringify(liftedServers, null, 2)}\n`;
|
|
17277
18198
|
archivedServers.set(id, parsed);
|
|
17278
18199
|
addItem({
|
|
17279
18200
|
id: `workspace:${id}:servers`,
|
|
@@ -17289,7 +18210,7 @@ var init_backups = __esmMin((() => {
|
|
|
17289
18210
|
note: null
|
|
17290
18211
|
}, () => {
|
|
17291
18212
|
fs.mkdirSync(path.dirname(workspace.serversPath), { recursive: true });
|
|
17292
|
-
writeFileAtomic(workspace.serversPath,
|
|
18213
|
+
writeFileAtomic(workspace.serversPath, serversText);
|
|
17293
18214
|
});
|
|
17294
18215
|
} else {
|
|
17295
18216
|
plan.skipped.push(`${workspace.label}: Servers (the archive's servers are not valid)`);
|
|
@@ -17462,9 +18383,8 @@ var init_backups = __esmMin((() => {
|
|
|
17462
18383
|
}, aliases);
|
|
17463
18384
|
}
|
|
17464
18385
|
if (parsedGlobal !== null && actions.has("global:settings") && settingsText !== null) {
|
|
17465
|
-
const
|
|
17466
|
-
|
|
17467
|
-
plan.restartRequired = JSON.stringify(parsedGlobal.control) !== JSON.stringify(current?.control ?? null);
|
|
18386
|
+
const current = readableGlobalSettings(readText(sources.globalSettingsPath));
|
|
18387
|
+
plan.restartRequired = JSON.stringify(parsedGlobal.control) !== JSON.stringify(current === null ? null : parseGlobalSettings(current).config?.control ?? null);
|
|
17468
18388
|
}
|
|
17469
18389
|
if (!options.confirm) {
|
|
17470
18390
|
plan.applied = [...actions.keys()].map((id) => labelOf(plan, id));
|
|
@@ -18236,30 +19156,60 @@ function getPageSize() {
|
|
|
18236
19156
|
}
|
|
18237
19157
|
}
|
|
18238
19158
|
/**
|
|
18239
|
-
*
|
|
18240
|
-
*
|
|
18241
|
-
*
|
|
19159
|
+
* The CPU temperature, or null when this machine names no CPU sensor.
|
|
19160
|
+
*
|
|
19161
|
+
* One tier is chosen and the maximum is taken only *within* it — a CPU package reports several
|
|
19162
|
+
* dies, so the hottest die is the reading, but a disk's temperature is not a second opinion.
|
|
19163
|
+
*/
|
|
19164
|
+
function pickCpuTemperature(sensors) {
|
|
19165
|
+
for (const pattern of [CPU_SENSOR, ACPI_SENSOR]) {
|
|
19166
|
+
const tier = sensors.filter((sensor) => pattern.test(sensor.name)).map((sensor) => sensor.celsius);
|
|
19167
|
+
if (tier.length > 0) return Math.max(...tier);
|
|
19168
|
+
}
|
|
19169
|
+
return null;
|
|
19170
|
+
}
|
|
19171
|
+
/**
|
|
19172
|
+
* Best-effort CPU temperature from Linux thermal zones / hwmon. macOS and Windows expose no
|
|
19173
|
+
* unprivileged sensor, so those platforms report null and both UIs read "n/a" — a WSL2 guest has
|
|
19174
|
+
* none either, and the Windows host's `MSAcpi_ThermalZoneTemperature` answers a constant 20 °C
|
|
19175
|
+
* regardless of load, so reaching across for it would be a fabricated number rather than a reading.
|
|
18242
19176
|
*/
|
|
18243
19177
|
function cpuTemperature() {
|
|
18244
|
-
const
|
|
18245
|
-
|
|
19178
|
+
const sensors = [];
|
|
19179
|
+
/** `name` is the sensor's own label; absent means the file could not be read, so skip it. */
|
|
19180
|
+
const inspect = (file, name) => {
|
|
18246
19181
|
try {
|
|
18247
19182
|
const raw = Number.parseInt(fs.readFileSync(file, "utf8").trim(), 10);
|
|
18248
19183
|
if (!Number.isFinite(raw)) return;
|
|
18249
19184
|
const celsius = raw / 1e3;
|
|
18250
|
-
if (celsius > 0 && celsius < 150)
|
|
19185
|
+
if (celsius > 0 && celsius < 150) sensors.push({
|
|
19186
|
+
name,
|
|
19187
|
+
celsius
|
|
19188
|
+
});
|
|
18251
19189
|
} catch {}
|
|
18252
19190
|
};
|
|
18253
19191
|
try {
|
|
18254
|
-
for (const zone of fs.readdirSync("/sys/class/thermal"))
|
|
19192
|
+
for (const zone of fs.readdirSync("/sys/class/thermal")) {
|
|
19193
|
+
if (!zone.startsWith("thermal_zone")) continue;
|
|
19194
|
+
const dir = path.join("/sys/class/thermal", zone);
|
|
19195
|
+
let type = "";
|
|
19196
|
+
try {
|
|
19197
|
+
type = fs.readFileSync(path.join(dir, "type"), "utf8").trim();
|
|
19198
|
+
} catch {}
|
|
19199
|
+
inspect(path.join(dir, "temp"), type);
|
|
19200
|
+
}
|
|
18255
19201
|
} catch {}
|
|
18256
19202
|
try {
|
|
18257
19203
|
for (const hwmon of fs.readdirSync("/sys/class/hwmon")) {
|
|
18258
19204
|
const dir = path.join("/sys/class/hwmon", hwmon);
|
|
18259
|
-
|
|
19205
|
+
let chip = "";
|
|
19206
|
+
try {
|
|
19207
|
+
chip = fs.readFileSync(path.join(dir, "name"), "utf8").trim();
|
|
19208
|
+
} catch {}
|
|
19209
|
+
for (const entry of fs.readdirSync(dir)) if (/^temp\d+_input$/.test(entry)) inspect(path.join(dir, entry), chip);
|
|
18260
19210
|
}
|
|
18261
19211
|
} catch {}
|
|
18262
|
-
return
|
|
19212
|
+
return pickCpuTemperature(sensors);
|
|
18263
19213
|
}
|
|
18264
19214
|
async function diskUsage(target) {
|
|
18265
19215
|
try {
|
|
@@ -18277,6 +19227,51 @@ async function diskUsage(target) {
|
|
|
18277
19227
|
}
|
|
18278
19228
|
}
|
|
18279
19229
|
/**
|
|
19230
|
+
* Run the configured temperature command and parse one number out of its stdout.
|
|
19231
|
+
*
|
|
19232
|
+
* This is the escape hatch for a machine whose kernel exposes no sensor — a WSL2 guest above all,
|
|
19233
|
+
* where `/sys/class/hwmon` is empty and the Windows ACPI zone answers a constant 20 °C. The user
|
|
19234
|
+
* supplies the command, so it is spawned without a shell and given a timeout: a hung helper must
|
|
19235
|
+
* not stall a sample that the whole panel's tick waits on.
|
|
19236
|
+
*
|
|
19237
|
+
* Only a whole-number or decimal reading in a plausible range is accepted. Anything else answers
|
|
19238
|
+
* null, which the UI reads as `n/a` — never a guess, for the same reason a missing sensor is not
|
|
19239
|
+
* published as 0.
|
|
19240
|
+
*/
|
|
19241
|
+
async function temperatureFromCommand(command, timeoutMs) {
|
|
19242
|
+
const trimmed = command.trim();
|
|
19243
|
+
if (trimmed.length === 0) return null;
|
|
19244
|
+
try {
|
|
19245
|
+
const { stdout } = await execFileAsync(trimmed, {
|
|
19246
|
+
timeout: timeoutMs,
|
|
19247
|
+
windowsHide: true,
|
|
19248
|
+
maxBuffer: 65536,
|
|
19249
|
+
shell: true
|
|
19250
|
+
});
|
|
19251
|
+
return parseTemperature(stdout);
|
|
19252
|
+
} catch {
|
|
19253
|
+
return null;
|
|
19254
|
+
}
|
|
19255
|
+
}
|
|
19256
|
+
/** The first plausible °C reading in a command's output, or null. Exported for its own tests. */
|
|
19257
|
+
function parseTemperature(output) {
|
|
19258
|
+
const match = /-?\d+(?:\.\d+)?/.exec(output);
|
|
19259
|
+
if (match === null) return null;
|
|
19260
|
+
const celsius = Number.parseFloat(match[0]);
|
|
19261
|
+
if (!Number.isFinite(celsius) || celsius <= 0 || celsius >= 150) return null;
|
|
19262
|
+
return celsius;
|
|
19263
|
+
}
|
|
19264
|
+
/**
|
|
19265
|
+
* The temperature to report: the configured command when there is one, else the built-in probe.
|
|
19266
|
+
*
|
|
19267
|
+
* The command wins even on a platform whose probe works, because a person who set it did so to
|
|
19268
|
+
* override what the panel found.
|
|
19269
|
+
*/
|
|
19270
|
+
async function readTemperature(config) {
|
|
19271
|
+
if (config.tempCommand.trim().length > 0) return temperatureFromCommand(config.tempCommand, config.tempCommandTimeoutMs);
|
|
19272
|
+
return cpuTemperature();
|
|
19273
|
+
}
|
|
19274
|
+
/**
|
|
18280
19275
|
* Samples the machine itself: the failures a home server actually dies from are
|
|
18281
19276
|
* a full disk, exhausted memory or a runaway load — none of which a port probe
|
|
18282
19277
|
* can see.
|
|
@@ -18290,7 +19285,7 @@ async function sampleHost(config, resolvePath) {
|
|
|
18290
19285
|
previousCpuTimes = cpuTimes;
|
|
18291
19286
|
if (process.platform === "win32") loadAvg.fill(0);
|
|
18292
19287
|
if (memory.swapUsedPercent === 0 && process.platform !== "linux") memory.swapUsedPercent = await swapUsedPercent();
|
|
18293
|
-
const tempCelsius =
|
|
19288
|
+
const tempCelsius = await readTemperature(config);
|
|
18294
19289
|
const disks = (await Promise.all(config.diskPaths.map((entry) => diskUsage(resolvePath(entry))))).filter((disk) => disk !== null);
|
|
18295
19290
|
const alerts = [];
|
|
18296
19291
|
for (const disk of disks) if (config.diskUsedPercent > 0 && disk.usedPercent >= config.diskUsedPercent) alerts.push(`disk ${disk.path} is ${disk.usedPercent.toFixed(1)}% full`);
|
|
@@ -18332,12 +19327,14 @@ function emptyHostView(config) {
|
|
|
18332
19327
|
sampledAt: null
|
|
18333
19328
|
};
|
|
18334
19329
|
}
|
|
18335
|
-
var execFileAsync, SWAP_CACHE_MS, swapCache, previousCpuTimes;
|
|
19330
|
+
var execFileAsync, SWAP_CACHE_MS, swapCache, previousCpuTimes, CPU_SENSOR, ACPI_SENSOR;
|
|
18336
19331
|
var init_host = __esmMin((() => {
|
|
18337
19332
|
execFileAsync = promisify(execFile);
|
|
18338
19333
|
SWAP_CACHE_MS = 6e4;
|
|
18339
19334
|
swapCache = null;
|
|
18340
19335
|
previousCpuTimes = null;
|
|
19336
|
+
CPU_SENSOR = /coretemp|k10temp|zenpower|cpu_thermal|cpu-thermal|x86_pkg_temp|soc_thermal|package/i;
|
|
19337
|
+
ACPI_SENSOR = /acpitz|acpi/i;
|
|
18341
19338
|
}));
|
|
18342
19339
|
//#endregion
|
|
18343
19340
|
//#region src/services/host-monitor.ts
|
|
@@ -18980,13 +19977,13 @@ var init_log_files = __esmMin((() => {
|
|
|
18980
19977
|
sizeBytes,
|
|
18981
19978
|
files
|
|
18982
19979
|
};
|
|
18983
|
-
for (const file of this.
|
|
19980
|
+
for (const file of this.retained(serverId)) try {
|
|
18984
19981
|
const stats = fs.statSync(file);
|
|
18985
19982
|
files.push({
|
|
18986
19983
|
name: path.basename(file),
|
|
18987
19984
|
sizeBytes: stats.size
|
|
18988
19985
|
});
|
|
18989
|
-
|
|
19986
|
+
sizeBytes += stats.size;
|
|
18990
19987
|
} catch {}
|
|
18991
19988
|
return {
|
|
18992
19989
|
enabled: config.persist,
|
|
@@ -18995,15 +19992,21 @@ var init_log_files = __esmMin((() => {
|
|
|
18995
19992
|
};
|
|
18996
19993
|
}
|
|
18997
19994
|
/**
|
|
18998
|
-
* Reads the last `tail` lines, newest file first, padding from
|
|
19995
|
+
* Reads the last `tail` lines, newest file first, padding from the rotations behind it.
|
|
18999
19996
|
*
|
|
19000
19997
|
* With `persist` off there is nothing this panel is willing to serve, even though a
|
|
19001
19998
|
* persistent entry's nanny still writes its file: that file is the log's transport —
|
|
19002
19999
|
* there is no pipe to carry it — and `persist` decides what counts as history.
|
|
20000
|
+
*
|
|
20001
|
+
* Every *retained* file is a source, not just `.1`: `keep` is the number of rotations the
|
|
20002
|
+
* person asked to keep, so a 5000-line window over a 10 MB rotation could not be filled by
|
|
20003
|
+
* the current file and `.1` alone. It read two of eleven files and returned "no matches" for
|
|
20004
|
+
* a line that was on disk — a search that answers "nothing found" while the log holds the
|
|
20005
|
+
* match is worse than a shorter window.
|
|
19003
20006
|
*/
|
|
19004
20007
|
readTail(serverId, tail) {
|
|
19005
20008
|
if (!this.getConfig().persist) return [];
|
|
19006
|
-
const sources =
|
|
20009
|
+
const sources = this.retained(serverId);
|
|
19007
20010
|
const lines = [];
|
|
19008
20011
|
for (const file of sources) {
|
|
19009
20012
|
if (lines.length >= tail) break;
|
|
@@ -19014,10 +20017,32 @@ var init_log_files = __esmMin((() => {
|
|
|
19014
20017
|
}
|
|
19015
20018
|
clear(serverId) {
|
|
19016
20019
|
this.pending.delete(serverId);
|
|
19017
|
-
for (const file of this.
|
|
20020
|
+
for (const file of this.ownedFiles(serverId)) try {
|
|
19018
20021
|
fs.rmSync(file, { force: true });
|
|
19019
20022
|
} catch {}
|
|
19020
20023
|
}
|
|
20024
|
+
/**
|
|
20025
|
+
* Drops rotations above the current `keep`, for every server, now.
|
|
20026
|
+
*
|
|
20027
|
+
* `rotate` prunes too, but it only runs when a file fills — which on a quiet entry can be days
|
|
20028
|
+
* after the person lowered the ceiling. A retention setting that takes effect "eventually, once
|
|
20029
|
+
* the server is chatty enough" is not the promise the page makes, so the settings save calls
|
|
20030
|
+
* this directly.
|
|
20031
|
+
*/
|
|
20032
|
+
prune() {
|
|
20033
|
+
let names;
|
|
20034
|
+
try {
|
|
20035
|
+
names = fs.readdirSync(this.dir);
|
|
20036
|
+
} catch {
|
|
20037
|
+
return;
|
|
20038
|
+
}
|
|
20039
|
+
const ids = /* @__PURE__ */ new Set();
|
|
20040
|
+
for (const name of names) {
|
|
20041
|
+
const dot = name.indexOf(".log");
|
|
20042
|
+
if (dot > 0 && (name.length === dot + 4 || name.startsWith(".log.", dot))) ids.add(name.slice(0, dot));
|
|
20043
|
+
}
|
|
20044
|
+
for (const id of ids) this.pruneServer(id);
|
|
20045
|
+
}
|
|
19021
20046
|
dispose() {
|
|
19022
20047
|
this.closed = true;
|
|
19023
20048
|
if (this.timer !== null) clearTimeout(this.timer);
|
|
@@ -19047,8 +20072,28 @@ var init_log_files = __esmMin((() => {
|
|
|
19047
20072
|
}
|
|
19048
20073
|
commit();
|
|
19049
20074
|
}
|
|
20075
|
+
/**
|
|
20076
|
+
* Drops this id's rotations numbered above `keep`.
|
|
20077
|
+
*
|
|
20078
|
+
* They are left over from a higher ceiling (or an older release). Renaming up only ever shifts
|
|
20079
|
+
* them further out of reach, so they have to be removed outright: a retention setting is a
|
|
20080
|
+
* promise about the directory, not about a rename loop.
|
|
20081
|
+
*/
|
|
20082
|
+
pruneServer(serverId) {
|
|
20083
|
+
const { keep } = this.getConfig();
|
|
20084
|
+
const current = this.currentPath(serverId);
|
|
20085
|
+
for (const file of this.ownedFiles(serverId)) {
|
|
20086
|
+
if (file === current) continue;
|
|
20087
|
+
const index = Number(file.slice(current.length + 1));
|
|
20088
|
+
if (!Number.isInteger(index) || index <= keep) continue;
|
|
20089
|
+
try {
|
|
20090
|
+
fs.rmSync(file, { force: true });
|
|
20091
|
+
} catch {}
|
|
20092
|
+
}
|
|
20093
|
+
}
|
|
19050
20094
|
rotate(serverId) {
|
|
19051
20095
|
const { keep } = this.getConfig();
|
|
20096
|
+
this.pruneServer(serverId);
|
|
19052
20097
|
for (let index = keep - 1; index >= 1; index--) {
|
|
19053
20098
|
const from = this.rotatedPath(serverId, index);
|
|
19054
20099
|
if (!fs.existsSync(from)) continue;
|
|
@@ -19102,11 +20147,43 @@ var init_log_files = __esmMin((() => {
|
|
|
19102
20147
|
rotatedPath(serverId, index) {
|
|
19103
20148
|
return path.join(this.dir, `${serverId}.log.${index}`);
|
|
19104
20149
|
}
|
|
19105
|
-
|
|
20150
|
+
/**
|
|
20151
|
+
* Every file this id owns on disk, newest first, found by reading the directory.
|
|
20152
|
+
*
|
|
20153
|
+
* The count comes from the directory rather than from `keep` because the two disagree the
|
|
20154
|
+
* moment a person lowers it: `rotate` only renames *up* to the new ceiling, so it never removes
|
|
20155
|
+
* the rotations numbered above it. Those files stayed, were invisible to `info()`, were served
|
|
20156
|
+
* by no reader, and survived a `clear` — growth the retention setting promised to bound, in
|
|
20157
|
+
* files nothing would ever show. Reading the directory is also what makes them prunable.
|
|
20158
|
+
*/
|
|
20159
|
+
ownedFiles(serverId) {
|
|
20160
|
+
const current = this.currentPath(serverId);
|
|
20161
|
+
const prefix = `${serverId}.log.`;
|
|
20162
|
+
let names;
|
|
20163
|
+
try {
|
|
20164
|
+
names = fs.readdirSync(this.dir);
|
|
20165
|
+
} catch {
|
|
20166
|
+
return fs.existsSync(current) ? [current] : [];
|
|
20167
|
+
}
|
|
20168
|
+
const rotated = names.filter((name) => name.startsWith(prefix)).map((name) => ({
|
|
20169
|
+
name,
|
|
20170
|
+
index: Number(name.slice(prefix.length))
|
|
20171
|
+
})).filter((entry) => Number.isInteger(entry.index) && entry.index >= 1).sort((a, b) => a.index - b.index).map((entry) => path.join(this.dir, entry.name));
|
|
20172
|
+
return fs.existsSync(current) ? [current, ...rotated] : rotated;
|
|
20173
|
+
}
|
|
20174
|
+
/**
|
|
20175
|
+
* The files `keep` still covers, newest first — what `info` lists and what a tail may read.
|
|
20176
|
+
*
|
|
20177
|
+
* The current file is always first and never counted against `keep`, which is what the UI
|
|
20178
|
+
* promises ("before rolling to .1, .2, …").
|
|
20179
|
+
*/
|
|
20180
|
+
retained(serverId) {
|
|
19106
20181
|
const { keep } = this.getConfig();
|
|
19107
|
-
const
|
|
19108
|
-
|
|
19109
|
-
|
|
20182
|
+
const owned = this.ownedFiles(serverId);
|
|
20183
|
+
if (owned.length === 0) return [];
|
|
20184
|
+
const [current, ...rotated] = owned;
|
|
20185
|
+
const covered = rotated.slice(0, keep);
|
|
20186
|
+
return current === void 0 ? covered : [current, ...covered];
|
|
19110
20187
|
}
|
|
19111
20188
|
};
|
|
19112
20189
|
}));
|
|
@@ -19250,7 +20327,28 @@ var init_notifications = __esmMin((() => {
|
|
|
19250
20327
|
}
|
|
19251
20328
|
/** Starts the cooldown window for every destination about to be asked to send. */
|
|
19252
20329
|
markSent(event, now = Date.now()) {
|
|
19253
|
-
for (const target of this.targetsFor(event, now)) this.
|
|
20330
|
+
for (const target of this.targetsFor(event, now)) this.armCooldown(target, event, now);
|
|
20331
|
+
}
|
|
20332
|
+
/** One destination's window, returning the deadline it set so a failed send can undo it. */
|
|
20333
|
+
armCooldown(target, event, now = Date.now()) {
|
|
20334
|
+
const until = now + this.effectivePolicy(target).cooldownMs;
|
|
20335
|
+
this.cooldowns.set(this.cooldownKey(target, event), until);
|
|
20336
|
+
return until;
|
|
20337
|
+
}
|
|
20338
|
+
/**
|
|
20339
|
+
* Gives back the window a **failed** send took.
|
|
20340
|
+
*
|
|
20341
|
+
* The window exists to collapse a flapping server into one message, so it is armed before the
|
|
20342
|
+
* send rather than after: two events already in flight must not both go out. But a send that
|
|
20343
|
+
* never arrived has told nobody anything — measured on the built panel, a crash alert sent while
|
|
20344
|
+
* the receiver was down recorded `fetch failed`, and the next two crashes inside the 5-minute
|
|
20345
|
+
* window were silenced by it, so the one alert that would have reached a working receiver was
|
|
20346
|
+
* the one the outage took. Undo only the deadline this send set: a concurrent dispatch may have
|
|
20347
|
+
* armed a later one, and clearing that would reopen the flood the window is for.
|
|
20348
|
+
*/
|
|
20349
|
+
releaseCooldown(target, event, armed) {
|
|
20350
|
+
const key = this.cooldownKey(target, event);
|
|
20351
|
+
if (this.cooldowns.get(key) === armed) this.cooldowns.delete(key);
|
|
19254
20352
|
}
|
|
19255
20353
|
/** Fire-and-forget by design: supervision must never wait on a chat or webhook API. */
|
|
19256
20354
|
notify(event) {
|
|
@@ -19261,13 +20359,13 @@ var init_notifications = __esmMin((() => {
|
|
|
19261
20359
|
async dispatch(event) {
|
|
19262
20360
|
const targets = this.targetsFor(event);
|
|
19263
20361
|
if (targets.length === 0) return false;
|
|
19264
|
-
this.
|
|
20362
|
+
const armed = new Map(targets.map((target) => [target.id, this.armCooldown(target, event)]));
|
|
19265
20363
|
const title = TITLE[event.reason];
|
|
19266
20364
|
const message = `${event.label} (${event.serverId}) ${REASON_LABEL[event.reason]}\n${event.detail}`;
|
|
19267
|
-
return (await Promise.all(targets.map((target) => this.deliver(target, title, message, event)))).includes(true);
|
|
20365
|
+
return (await Promise.all(targets.map((target) => this.deliver(target, title, message, event, armed.get(target.id) ?? 0)))).includes(true);
|
|
19268
20366
|
}
|
|
19269
20367
|
/** One destination, one event. A throw is recorded against it and nothing else. */
|
|
19270
|
-
async deliver(target, title, message, event) {
|
|
20368
|
+
async deliver(target, title, message, event, armed) {
|
|
19271
20369
|
try {
|
|
19272
20370
|
const result = target.kind === "telegram" ? await this.sendTelegram(target, title, message) : await sendWebhook(target, {
|
|
19273
20371
|
title,
|
|
@@ -19277,9 +20375,11 @@ var init_notifications = __esmMin((() => {
|
|
|
19277
20375
|
label: event.label
|
|
19278
20376
|
});
|
|
19279
20377
|
this.remember(target.id, result.ok ? "sent" : result.error ?? "send failed");
|
|
20378
|
+
if (!result.ok) this.releaseCooldown(target, event, armed);
|
|
19280
20379
|
return result.ok;
|
|
19281
20380
|
} catch (error) {
|
|
19282
20381
|
this.remember(target.id, errorMessage(error));
|
|
20382
|
+
this.releaseCooldown(target, event, armed);
|
|
19283
20383
|
return false;
|
|
19284
20384
|
}
|
|
19285
20385
|
}
|
|
@@ -19736,11 +20836,12 @@ var init_panel = __esmMin((() => {
|
|
|
19736
20836
|
}
|
|
19737
20837
|
}
|
|
19738
20838
|
}
|
|
19739
|
-
|
|
20839
|
+
/** `withPersistent` reaches every workspace's supervisor: a `down` is host-wide. */
|
|
20840
|
+
async dispose(options = {}) {
|
|
19740
20841
|
this.disposed = true;
|
|
19741
20842
|
clearInterval(this.timer);
|
|
19742
20843
|
this.options.backups.dispose();
|
|
19743
|
-
await Promise.all(this.workspaces().map((runtime) => runtime.supervisor.dispose()));
|
|
20844
|
+
await Promise.all(this.workspaces().map((runtime) => runtime.supervisor.dispose(options)));
|
|
19744
20845
|
for (const runtime of this.workspaces()) this.disposeRuntime(runtime);
|
|
19745
20846
|
}
|
|
19746
20847
|
createRuntime(workspace) {
|
|
@@ -20809,7 +21910,7 @@ async function runControlPlane(options) {
|
|
|
20809
21910
|
}
|
|
20810
21911
|
}
|
|
20811
21912
|
let shuttingDown = false;
|
|
20812
|
-
const shutdown = async (reason) => {
|
|
21913
|
+
const shutdown = async (reason, options = {}) => {
|
|
20813
21914
|
if (shuttingDown) return;
|
|
20814
21915
|
shuttingDown = true;
|
|
20815
21916
|
logger.info(`${reason} — stopping ${panel.serverViews().length} server(s) across ${panel.workspaces().length} workspace(s)`);
|
|
@@ -20817,7 +21918,7 @@ async function runControlPlane(options) {
|
|
|
20817
21918
|
clearRuntime();
|
|
20818
21919
|
auth.dispose();
|
|
20819
21920
|
proxy.dispose();
|
|
20820
|
-
await panel.dispose();
|
|
21921
|
+
await panel.dispose(options);
|
|
20821
21922
|
await controlServer.close(true);
|
|
20822
21923
|
process.exit(0);
|
|
20823
21924
|
};
|
|
@@ -20839,7 +21940,7 @@ async function runControlPlane(options) {
|
|
|
20839
21940
|
}
|
|
20840
21941
|
}),
|
|
20841
21942
|
runtimeToken: token,
|
|
20842
|
-
onShutdown: () => shutdown("shutdown requested locally")
|
|
21943
|
+
onShutdown: (options) => shutdown("shutdown requested locally", options)
|
|
20843
21944
|
});
|
|
20844
21945
|
await controlServer.start();
|
|
20845
21946
|
await backups.warm();
|
|
@@ -21029,6 +22130,26 @@ async function runUp(flags, entry) {
|
|
|
21029
22130
|
process.stdout.write(` ${dim(`project ${runtime.projectDir}`)}\n`);
|
|
21030
22131
|
process.stdout.write(` ${dim(`state ${runtime.dataRoot}`)}\n`);
|
|
21031
22132
|
process.stdout.write(` ${dim(`log ${runtime.logFile}`)}\n`);
|
|
22133
|
+
await warnIfWslTemperatureMissing();
|
|
22134
|
+
}
|
|
22135
|
+
/**
|
|
22136
|
+
* Say once, on `up`, that this box cannot read its own temperature and that it can be fixed.
|
|
22137
|
+
*
|
|
22138
|
+
* A WSL2 guest has no sensor the kernel exposes, so the Host vitals tile reads `n/a` and looks
|
|
22139
|
+
* broken. Nothing tells a person why — the settings page has the button, but only if they go
|
|
22140
|
+
* looking. This is the one line that turns "the panel is broken" into "run one command".
|
|
22141
|
+
*
|
|
22142
|
+
* Silent when a command is already configured, and on any platform that is not WSL.
|
|
22143
|
+
*/
|
|
22144
|
+
async function warnIfWslTemperatureMissing() {
|
|
22145
|
+
const { isWsl } = await Promise.resolve().then(() => (init_wsl_temperature$1(), wsl_temperature_exports));
|
|
22146
|
+
if (!isWsl()) return;
|
|
22147
|
+
const { GlobalSettingsStore } = await Promise.resolve().then(() => (init_settings$1(), settings_exports));
|
|
22148
|
+
const { globalSettingsPath } = await Promise.resolve().then(() => (init_paths(), paths_exports));
|
|
22149
|
+
const store = new GlobalSettingsStore(globalSettingsPath);
|
|
22150
|
+
store.load();
|
|
22151
|
+
if (store.host.tempCommand.trim().length > 0) return;
|
|
22152
|
+
process.stdout.write(`${paint("33", "note")} WSL2 detected: the guest exposes no CPU temperature, so Host vitals shows n/a\n ${dim(`set it up with ${invocation()} setup-temp --wsl`)}\n`);
|
|
21032
22153
|
}
|
|
21033
22154
|
async function waitForStartup(child, timeoutMs = 2e4) {
|
|
21034
22155
|
const { readRuntime } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
|
|
@@ -21088,24 +22209,142 @@ var init_up = __esmMin((() => {
|
|
|
21088
22209
|
};
|
|
21089
22210
|
}));
|
|
21090
22211
|
//#endregion
|
|
22212
|
+
//#region src/providers/nanny-sweep.ts
|
|
22213
|
+
var nanny_sweep_exports = /* @__PURE__ */ __exportAll({
|
|
22214
|
+
livePersistentEntries: () => livePersistentEntries,
|
|
22215
|
+
stopPersistentEntries: () => stopPersistentEntries
|
|
22216
|
+
});
|
|
22217
|
+
/**
|
|
22218
|
+
* Every workspace's state directory.
|
|
22219
|
+
*
|
|
22220
|
+
* Read here rather than through `workspaceStateDir()`, which resolves from *this* process's
|
|
22221
|
+
* `HHOSTED_HOME`: a caller passing `--home` elsewhere would otherwise sweep another host's
|
|
22222
|
+
* state — the mistake `backup-offline` already paid for.
|
|
22223
|
+
*/
|
|
22224
|
+
function stateDirs(hhDir) {
|
|
22225
|
+
try {
|
|
22226
|
+
return fs.readdirSync(hhDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).filter((id) => /^[a-z0-9][a-z0-9_-]*$/.test(id)).map((workspaceId) => ({
|
|
22227
|
+
workspaceId,
|
|
22228
|
+
dir: path.join(hhDir, workspaceId, ".state")
|
|
22229
|
+
}));
|
|
22230
|
+
} catch {
|
|
22231
|
+
return [];
|
|
22232
|
+
}
|
|
22233
|
+
}
|
|
22234
|
+
/**
|
|
22235
|
+
* The persistent entries whose nanny is running right now.
|
|
22236
|
+
*
|
|
22237
|
+
* A `<id>.run.json` file is a *non-persistent* child's own record and carries no nanny, so it
|
|
22238
|
+
* is skipped by suffix — the same distinction `backup-offline` relies on. `nannyIsAlive` is
|
|
22239
|
+
* the identity check: a live pid alone proves nothing, since pids are reused.
|
|
22240
|
+
*/
|
|
22241
|
+
async function livePersistentEntries(hhDir) {
|
|
22242
|
+
const found = [];
|
|
22243
|
+
for (const { workspaceId, dir } of stateDirs(hhDir)) {
|
|
22244
|
+
let names;
|
|
22245
|
+
try {
|
|
22246
|
+
names = fs.readdirSync(dir);
|
|
22247
|
+
} catch {
|
|
22248
|
+
continue;
|
|
22249
|
+
}
|
|
22250
|
+
for (const name of names) {
|
|
22251
|
+
if (!name.endsWith(".json") || name.endsWith(".spec.json")) continue;
|
|
22252
|
+
const serverId = name.slice(0, -5);
|
|
22253
|
+
const state = readNannyState(path.join(dir, name));
|
|
22254
|
+
if (state === null || state.serverId !== serverId) continue;
|
|
22255
|
+
if (await nannyIsAlive(state, serverId)) found.push({
|
|
22256
|
+
workspaceId,
|
|
22257
|
+
serverId,
|
|
22258
|
+
state,
|
|
22259
|
+
dir
|
|
22260
|
+
});
|
|
22261
|
+
}
|
|
22262
|
+
}
|
|
22263
|
+
return found;
|
|
22264
|
+
}
|
|
22265
|
+
/**
|
|
22266
|
+
* Stops these entries and consumes the record of each one that ended.
|
|
22267
|
+
*
|
|
22268
|
+
* `stopFor` is the entry's own `stop` config, read by the caller from the workspace that
|
|
22269
|
+
* declares it: the grace period here has to be the one the entry asked for, or a stop that
|
|
22270
|
+
* was still finishing its shutdown reads as a failure and escalates to `SIGKILL`.
|
|
22271
|
+
*/
|
|
22272
|
+
async function stopPersistentEntries(handles, options = {}) {
|
|
22273
|
+
const results = [];
|
|
22274
|
+
const terminate = options.terminate ?? terminatePid;
|
|
22275
|
+
const defaultStop = stopSchema.assert({});
|
|
22276
|
+
for (const handle of handles) {
|
|
22277
|
+
const stop = options.stopFor?.(handle) ?? defaultStop;
|
|
22278
|
+
const { state, dir, serverId } = handle;
|
|
22279
|
+
const nanny = await terminate(state.nannyPid, {
|
|
22280
|
+
signal: stop.signal,
|
|
22281
|
+
killGroup: stop.killGroup,
|
|
22282
|
+
graceMs: stop.graceMs
|
|
22283
|
+
});
|
|
22284
|
+
if (isProcessAlive(state.nannyPid)) {
|
|
22285
|
+
results.push({
|
|
22286
|
+
handle,
|
|
22287
|
+
stopped: false,
|
|
22288
|
+
error: `pid ${state.nannyPid} survived the stop — its record is kept, so the next \`up\` can still find it`
|
|
22289
|
+
});
|
|
22290
|
+
continue;
|
|
22291
|
+
}
|
|
22292
|
+
if (!stop.killGroup && nanny === "force-killed" && state.childPid !== null && state.childPid > 0) await terminate(state.childPid, {
|
|
22293
|
+
signal: "SIGKILL",
|
|
22294
|
+
killGroup: false,
|
|
22295
|
+
graceMs: 0
|
|
22296
|
+
});
|
|
22297
|
+
consumeRecord(dir, serverId);
|
|
22298
|
+
results.push({
|
|
22299
|
+
handle,
|
|
22300
|
+
stopped: true,
|
|
22301
|
+
error: null
|
|
22302
|
+
});
|
|
22303
|
+
}
|
|
22304
|
+
return results;
|
|
22305
|
+
}
|
|
22306
|
+
/**
|
|
22307
|
+
* The record goes only once the process it names is gone: a state file kept past its process
|
|
22308
|
+
* is a false reattach waiting, which is what `resumePersistent` exists to prevent.
|
|
22309
|
+
*/
|
|
22310
|
+
function consumeRecord(dir, serverId) {
|
|
22311
|
+
for (const file of [nannyStatePath(dir, serverId), nannySpecPath(dir, serverId)]) try {
|
|
22312
|
+
fs.rmSync(file, { force: true });
|
|
22313
|
+
} catch {}
|
|
22314
|
+
}
|
|
22315
|
+
var init_nanny_sweep = __esmMin((() => {
|
|
22316
|
+
init_nanny$2();
|
|
22317
|
+
init_port();
|
|
22318
|
+
init_process();
|
|
22319
|
+
init_contracts();
|
|
22320
|
+
}));
|
|
22321
|
+
//#endregion
|
|
21091
22322
|
//#region src/cli/down.ts
|
|
21092
22323
|
var down_exports = /* @__PURE__ */ __exportAll({
|
|
21093
22324
|
downCommand: () => downCommand,
|
|
22325
|
+
exitCodeForStops: () => exitCodeForStops,
|
|
22326
|
+
livePersistents: () => livePersistents,
|
|
22327
|
+
persistentLabel: () => persistentLabel,
|
|
21094
22328
|
runDown: () => runDown
|
|
21095
22329
|
});
|
|
21096
|
-
|
|
21097
|
-
async function runDown() {
|
|
22330
|
+
async function runDown(options = {}) {
|
|
21098
22331
|
const { clearRuntime, isLiveLiveness, readRuntime, requestShutdown, runtimeLiveness } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
|
|
22332
|
+
const result = { stoppedPersistent: [] };
|
|
22333
|
+
const before = options.withPersistent === true ? await livePersistents() : [];
|
|
22334
|
+
const finish = async () => {
|
|
22335
|
+
result.stoppedPersistent.push(...await reportPersistent(options, before));
|
|
22336
|
+
return result;
|
|
22337
|
+
};
|
|
21099
22338
|
const runtime = readRuntime();
|
|
21100
22339
|
if (runtime === null) {
|
|
21101
22340
|
process.stdout.write("home-hosted is not running\n");
|
|
21102
|
-
return;
|
|
22341
|
+
return finish();
|
|
21103
22342
|
}
|
|
21104
22343
|
const liveness = await runtimeLiveness(runtime);
|
|
21105
22344
|
if (liveness === "gone") {
|
|
21106
22345
|
clearRuntime();
|
|
21107
22346
|
process.stdout.write(`home-hosted is not running (removed a stale run.json from home-hosted ${runtime.version})\n`);
|
|
21108
|
-
return;
|
|
22347
|
+
return finish();
|
|
21109
22348
|
}
|
|
21110
22349
|
/** What was stopped, and whether this CLI is a different release than it was. */
|
|
21111
22350
|
const reportStopped = (forced) => {
|
|
@@ -21116,59 +22355,141 @@ async function runDown() {
|
|
|
21116
22355
|
let answered = false;
|
|
21117
22356
|
if (isLiveLiveness(liveness)) {
|
|
21118
22357
|
process.stdout.write(`stopping pid ${runtime.pid}…\n`);
|
|
21119
|
-
answered = await requestShutdown(runtime);
|
|
22358
|
+
answered = await requestShutdown(runtime, 4e3, { withPersistent: options.withPersistent === true });
|
|
21120
22359
|
if (!answered) signal(runtime.pid, "SIGTERM");
|
|
21121
22360
|
} else {
|
|
21122
|
-
if (!await requestShutdown(runtime)) {
|
|
22361
|
+
if (!await requestShutdown(runtime, 4e3, { withPersistent: options.withPersistent === true })) {
|
|
21123
22362
|
process.stdout.write(`home-hosted is not running (the pid in run.json, ${runtime.pid}, belongs to another process — it was not signalled)\n`);
|
|
21124
|
-
return;
|
|
22363
|
+
return finish();
|
|
21125
22364
|
}
|
|
21126
22365
|
process.stdout.write(`stopped the panel on ${runtime.url} (its pid in run.json, ${runtime.pid}, was another process and was left alone)\n`);
|
|
21127
22366
|
clearRuntime();
|
|
21128
|
-
|
|
21129
|
-
return;
|
|
22367
|
+
return finish();
|
|
21130
22368
|
}
|
|
21131
22369
|
if (await waitForExit(runtime.pid, 2e4)) {
|
|
21132
22370
|
clearRuntime();
|
|
21133
22371
|
reportStopped(false);
|
|
21134
|
-
|
|
21135
|
-
return;
|
|
22372
|
+
return finish();
|
|
21136
22373
|
}
|
|
21137
22374
|
process.stdout.write(`${dim("it did not stop in time — forcing")}\n`);
|
|
21138
22375
|
forceStop(runtime.pid);
|
|
21139
22376
|
await waitForExit(runtime.pid, 5e3);
|
|
21140
22377
|
clearRuntime();
|
|
21141
22378
|
reportStopped(true);
|
|
21142
|
-
|
|
22379
|
+
return finish();
|
|
21143
22380
|
}
|
|
21144
22381
|
/**
|
|
21145
|
-
*
|
|
21146
|
-
*
|
|
21147
|
-
*
|
|
21148
|
-
*
|
|
22382
|
+
* The persistent entries this host has running, as their state files describe them.
|
|
22383
|
+
*
|
|
22384
|
+
* Every workspace keeps its own `.state`, and only the panel normally sees all of them, so
|
|
22385
|
+
* `down` reads them itself — after a crash there is nobody left to ask.
|
|
21149
22386
|
*/
|
|
21150
|
-
async function
|
|
21151
|
-
const {
|
|
21152
|
-
const {
|
|
21153
|
-
|
|
21154
|
-
|
|
21155
|
-
|
|
21156
|
-
|
|
21157
|
-
|
|
21158
|
-
|
|
21159
|
-
|
|
21160
|
-
|
|
21161
|
-
|
|
22387
|
+
async function livePersistents() {
|
|
22388
|
+
const { livePersistentEntries } = await Promise.resolve().then(() => (init_nanny_sweep(), nanny_sweep_exports));
|
|
22389
|
+
const { hhDir } = await Promise.resolve().then(() => (init_paths(), paths_exports));
|
|
22390
|
+
return livePersistentEntries(hhDir);
|
|
22391
|
+
}
|
|
22392
|
+
/** `workspace/id`, because a server id is only unique inside its workspace. */
|
|
22393
|
+
function persistentLabel(handle) {
|
|
22394
|
+
return `${handle.workspaceId}/${handle.serverId}`;
|
|
22395
|
+
}
|
|
22396
|
+
/**
|
|
22397
|
+
* Stops what is left of the snapshot: with the panel gone each nanny is signalled directly, and
|
|
22398
|
+
* its state file consumed once it is really gone. Returns which were ended here and which
|
|
22399
|
+
* survived, so the caller can account for the rest as the panel's work.
|
|
22400
|
+
*/
|
|
22401
|
+
async function stopPersistents(before) {
|
|
22402
|
+
const done = /* @__PURE__ */ new Set();
|
|
22403
|
+
const survived = /* @__PURE__ */ new Set();
|
|
22404
|
+
const live = new Set((await livePersistents()).map(persistentLabel));
|
|
22405
|
+
const handles = before.filter((handle) => live.has(persistentLabel(handle)));
|
|
22406
|
+
if (handles.length === 0) return {
|
|
22407
|
+
done,
|
|
22408
|
+
survived
|
|
22409
|
+
};
|
|
22410
|
+
const { stopPersistentEntries } = await Promise.resolve().then(() => (init_nanny_sweep(), nanny_sweep_exports));
|
|
22411
|
+
const results = await stopPersistentEntries(handles, { stopFor: await stopPolicyLookup() });
|
|
22412
|
+
for (const result of results) {
|
|
22413
|
+
const label = persistentLabel(result.handle);
|
|
22414
|
+
if (result.stopped) {
|
|
22415
|
+
done.add(label);
|
|
22416
|
+
process.stdout.write(`${green("stopped")} persistent ${label}\n`);
|
|
21162
22417
|
continue;
|
|
21163
22418
|
}
|
|
21164
|
-
|
|
21165
|
-
|
|
21166
|
-
|
|
22419
|
+
survived.add(label);
|
|
22420
|
+
process.stderr.write(`${paint("31", "error")} persistent ${label}: ${result.error}\n`);
|
|
22421
|
+
}
|
|
22422
|
+
const code = exitCodeForStops(results);
|
|
22423
|
+
if (code !== 0) process.exitCode = code;
|
|
22424
|
+
return {
|
|
22425
|
+
done,
|
|
22426
|
+
survived
|
|
22427
|
+
};
|
|
22428
|
+
}
|
|
22429
|
+
/**
|
|
22430
|
+
* The exit code these stops earn: any survivor is a failure, because the command was asked to
|
|
22431
|
+
* stop them and the host is still running one. Separated from the printing so the rule is
|
|
22432
|
+
* pinned where it can be read, not inferred from a process's status.
|
|
22433
|
+
*/
|
|
22434
|
+
function exitCodeForStops(results) {
|
|
22435
|
+
return results.some((result) => !result.stopped) ? 1 : 0;
|
|
22436
|
+
}
|
|
22437
|
+
/**
|
|
22438
|
+
* Each entry's own `stop` policy, read from the workspace that declares it.
|
|
22439
|
+
*
|
|
22440
|
+
* The grace period is the entry's, not a constant: the nanny forwards it to the child it
|
|
22441
|
+
* owns, so a shorter one here would escalate to `SIGKILL` while a shutdown the config asked
|
|
22442
|
+
* to allow more time for was still running. A workspace whose config cannot be read falls
|
|
22443
|
+
* back to the defaults — the host is being brought down either way.
|
|
22444
|
+
*/
|
|
22445
|
+
async function stopPolicyLookup() {
|
|
22446
|
+
const { WorkspaceStore } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
22447
|
+
const { workspaceServersPath, workspaceSettingsPath } = await Promise.resolve().then(() => (init_paths(), paths_exports));
|
|
22448
|
+
const { stopSchema } = await Promise.resolve().then(() => (init_contracts(), contracts_exports));
|
|
22449
|
+
const policies = /* @__PURE__ */ new Map();
|
|
22450
|
+
return (handle) => {
|
|
22451
|
+
let byId = policies.get(handle.workspaceId);
|
|
22452
|
+
if (byId === void 0) {
|
|
22453
|
+
byId = /* @__PURE__ */ new Map();
|
|
22454
|
+
try {
|
|
22455
|
+
const store = new WorkspaceStore(handle.workspaceId, workspaceSettingsPath(handle.workspaceId), workspaceServersPath(handle.workspaceId));
|
|
22456
|
+
store.load();
|
|
22457
|
+
for (const server of store.servers) byId.set(server.id, server.stop);
|
|
22458
|
+
} catch {}
|
|
22459
|
+
policies.set(handle.workspaceId, byId);
|
|
21167
22460
|
}
|
|
22461
|
+
return byId.get(handle.serverId) ?? stopSchema.assert({});
|
|
22462
|
+
};
|
|
22463
|
+
}
|
|
22464
|
+
/**
|
|
22465
|
+
* The last step: name what the flag left running, or stop what the panel could not and account
|
|
22466
|
+
* for every entry that was running when this command started.
|
|
22467
|
+
*
|
|
22468
|
+
* The panel does the stopping whenever it is reachable — it is the only process that can record
|
|
22469
|
+
* it — so what is left of the snapshot is what still needs a signal here. Anything else in the
|
|
22470
|
+
* snapshot was ended by the panel, and is reported as stopped; a survivor is never reported as
|
|
22471
|
+
* stopped, or `restart` would treat a failed stop as a successful one.
|
|
22472
|
+
*/
|
|
22473
|
+
async function reportPersistent(options, before = []) {
|
|
22474
|
+
if (options.withPersistent !== true) {
|
|
22475
|
+
const running = await livePersistents();
|
|
22476
|
+
if (running.length === 0) return [];
|
|
22477
|
+
process.stdout.write(`${dim(`${running.length} persistent server(s) left running: ${running.map(persistentLabel).join(", ")}\n`)}`);
|
|
22478
|
+
process.stdout.write(`${dim("stop one from the panel, or pass --with-persistent")}\n`);
|
|
22479
|
+
return [];
|
|
22480
|
+
}
|
|
22481
|
+
const ended = await stopPersistents(before);
|
|
22482
|
+
const stopped = [];
|
|
22483
|
+
for (const handle of before) {
|
|
22484
|
+
const label = persistentLabel(handle);
|
|
22485
|
+
if (ended.survived.has(label)) continue;
|
|
22486
|
+
if (!ended.done.has(label)) process.stdout.write(`${green("stopped")} persistent ${label}\n`);
|
|
22487
|
+
stopped.push({
|
|
22488
|
+
workspaceId: handle.workspaceId,
|
|
22489
|
+
serverId: handle.serverId
|
|
22490
|
+
});
|
|
21168
22491
|
}
|
|
21169
|
-
|
|
21170
|
-
process.stdout.write(`${dim(`${running.length} persistent server(s) left running: ${running.join(", ")}`)}\n`);
|
|
21171
|
-
process.stdout.write(`${dim("stop one from the panel, or restart it here to reattach")}\n`);
|
|
22492
|
+
return stopped;
|
|
21172
22493
|
}
|
|
21173
22494
|
async function waitForExit(pid, timeoutMs) {
|
|
21174
22495
|
const { isProcessAlive } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
|
|
@@ -21203,8 +22524,12 @@ var init_down = __esmMin((() => {
|
|
|
21203
22524
|
init_version();
|
|
21204
22525
|
downCommand = defineCommand({
|
|
21205
22526
|
meta: { name: "down" },
|
|
21206
|
-
|
|
21207
|
-
|
|
22527
|
+
args: { withPersistent: {
|
|
22528
|
+
type: "boolean",
|
|
22529
|
+
description: "also stop every persistent entry, in every workspace"
|
|
22530
|
+
} },
|
|
22531
|
+
run: async ({ args }) => {
|
|
22532
|
+
await runDown({ withPersistent: args.withPersistent === true });
|
|
21208
22533
|
}
|
|
21209
22534
|
});
|
|
21210
22535
|
}));
|
|
@@ -21366,6 +22691,10 @@ function restartCommand(entry) {
|
|
|
21366
22691
|
meta: { name: "restart" },
|
|
21367
22692
|
args: {
|
|
21368
22693
|
...upArgs,
|
|
22694
|
+
withPersistent: {
|
|
22695
|
+
type: "boolean",
|
|
22696
|
+
description: "stop the persistent entries too, instead of leaving them running"
|
|
22697
|
+
},
|
|
21369
22698
|
id: {
|
|
21370
22699
|
type: "positional",
|
|
21371
22700
|
required: false,
|
|
@@ -21380,15 +22709,35 @@ function restartCommand(entry) {
|
|
|
21380
22709
|
run: async ({ args }) => {
|
|
21381
22710
|
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
21382
22711
|
if (id.length > 0) {
|
|
22712
|
+
if (args.withPersistent === true) fail("restart <id> restarts one server — drop --with-persistent, or use it on a bare `restart`");
|
|
21383
22713
|
await runServerAction("restart", id, typeof args.workspace === "string" ? args.workspace.trim() : void 0);
|
|
21384
22714
|
return;
|
|
21385
22715
|
}
|
|
21386
22716
|
if (args.workspace !== void 0) fail("restart --workspace needs a server id — `home-hosted restart <id> --workspace <id>`");
|
|
21387
|
-
await runDown();
|
|
22717
|
+
const stopped = (await runDown({ withPersistent: args.withPersistent === true })).stoppedPersistent;
|
|
21388
22718
|
await runUp(toUpFlags(args), entry);
|
|
22719
|
+
if (stopped.length > 0) await startPersistentBack(stopped);
|
|
21389
22720
|
}
|
|
21390
22721
|
});
|
|
21391
22722
|
}
|
|
22723
|
+
/**
|
|
22724
|
+
* Starts the entries this restart stopped, through the panel that just came back.
|
|
22725
|
+
*
|
|
22726
|
+
* Only the ones `up` did not already start: its autostart pass runs asynchronously and a second
|
|
22727
|
+
* start of a running entry is a plain `{ ok: true }`, so re-asking is harmless — but the
|
|
22728
|
+
* entries with `autostart: false`, the reason this exists, would never come back otherwise.
|
|
22729
|
+
*/
|
|
22730
|
+
async function startPersistentBack(stopped) {
|
|
22731
|
+
const { readRuntime, requestControl } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
|
|
22732
|
+
const runtime = readRuntime();
|
|
22733
|
+
if (runtime === null) return;
|
|
22734
|
+
for (const { workspaceId, serverId } of stopped) {
|
|
22735
|
+
const workspace = `?workspace=${encodeURIComponent(workspaceId)}`;
|
|
22736
|
+
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(serverId)}/start${workspace}`);
|
|
22737
|
+
const body = answer?.body ?? {};
|
|
22738
|
+
if (body.ok !== true) process.stderr.write(`${paint("31", "error")} ${workspaceId}/${serverId} did not come back: ${body.error ?? `the panel answered ${answer?.status}`}\n`);
|
|
22739
|
+
}
|
|
22740
|
+
}
|
|
21392
22741
|
var init_restart = __esmMin((() => {
|
|
21393
22742
|
init_down();
|
|
21394
22743
|
init_io();
|
|
@@ -21744,6 +23093,101 @@ var init_set_token = __esmMin((() => {
|
|
|
21744
23093
|
});
|
|
21745
23094
|
}));
|
|
21746
23095
|
//#endregion
|
|
23096
|
+
//#region src/cli/setup-temp.ts
|
|
23097
|
+
var setup_temp_exports = /* @__PURE__ */ __exportAll({
|
|
23098
|
+
runSetupTemp: () => runSetupTemp,
|
|
23099
|
+
setupTempArgs: () => setupTempArgs,
|
|
23100
|
+
setupTempCommand: () => setupTempCommand,
|
|
23101
|
+
sourceFromFlags: () => sourceFromFlags
|
|
23102
|
+
});
|
|
23103
|
+
/** Which source a flag names, or null when the invocation asks for no change. */
|
|
23104
|
+
function sourceFromFlags(flags) {
|
|
23105
|
+
if (flags.clear === true) return null;
|
|
23106
|
+
if (flags.wsl === true) return "wsl";
|
|
23107
|
+
return null;
|
|
23108
|
+
}
|
|
23109
|
+
async function runSetupTemp(flags) {
|
|
23110
|
+
const store = new GlobalSettingsStore(globalSettingsPath);
|
|
23111
|
+
store.load();
|
|
23112
|
+
const host = store.host;
|
|
23113
|
+
const configured = host.tempCommand.trim().length > 0;
|
|
23114
|
+
if (flags.clear === true) {
|
|
23115
|
+
if (!configured) {
|
|
23116
|
+
process.stdout.write("no temperature command is set — nothing to clear\n");
|
|
23117
|
+
return;
|
|
23118
|
+
}
|
|
23119
|
+
store.updateHost({ tempCommand: "" });
|
|
23120
|
+
process.stdout.write(`${green("temperature command cleared")} — the tile uses the built-in probe again\n`);
|
|
23121
|
+
return;
|
|
23122
|
+
}
|
|
23123
|
+
const source = sourceFromFlags(flags);
|
|
23124
|
+
if (source === null) {
|
|
23125
|
+
if (configured) {
|
|
23126
|
+
process.stdout.write(`${green("a temperature command is set")}: ${bold(host.tempCommand)}\n`);
|
|
23127
|
+
const probe = await probeWslTemperature(host.tempCommand, host.tempCommandTimeoutMs);
|
|
23128
|
+
process.stdout.write(probe.celsius === null ? ` ${dim(`it did not answer: ${probe.error ?? "unknown reason"}`)}\n` : ` last reading: ${green(`${probe.celsius}°C`)}\n`);
|
|
23129
|
+
return;
|
|
23130
|
+
}
|
|
23131
|
+
process.stdout.write("the panel reads the temperature from the kernel when the machine exposes a sensor.\n");
|
|
23132
|
+
process.stdout.write(`this machine: ${host.tempCelsius > 0 ? `threshold ${host.tempCelsius}°C` : "no temperature alert"}\n`);
|
|
23133
|
+
process.stdout.write(`\n${dim("if the Host vitals tile says n/a, set a source up:")}\n`);
|
|
23134
|
+
process.stdout.write(` ${bold("setup-temp --wsl")} read it through the Windows host (WSL2)\n`);
|
|
23135
|
+
return;
|
|
23136
|
+
}
|
|
23137
|
+
if (source === "wsl") {
|
|
23138
|
+
const { isWsl } = await Promise.resolve().then(() => (init_wsl_temperature$1(), wsl_temperature_exports));
|
|
23139
|
+
if (!isWsl()) fail("--wsl is for a WSL2 guest, and this is not one. Run `setup-temp` with no flag to see the options");
|
|
23140
|
+
const scriptPath = wslScriptPath();
|
|
23141
|
+
if (scriptPath === null) fail("the Windows drive is not mounted, so the helper cannot be written where powershell.exe can read it");
|
|
23142
|
+
writeWslTemperatureScript(scriptPath);
|
|
23143
|
+
const command = tempCommandFor(scriptPath);
|
|
23144
|
+
process.stdout.write(` helper ${dim(`${scriptPath} (${windowsScriptPath(scriptPath)} on Windows)`)}\n`);
|
|
23145
|
+
const probe = await probeWslTemperature(command, 5e3);
|
|
23146
|
+
if (probe.celsius === null) {
|
|
23147
|
+
process.stdout.write(`${fail("not set up")} — the helper did not answer: ${probe.error ?? "unknown reason"}\n`);
|
|
23148
|
+
process.stdout.write(`${dim("install LibreHardwareMonitor in C:\\Tools\\LibreHardwareMonitor on Windows, then re-run this command")}\n`);
|
|
23149
|
+
process.stdout.write(`${dim(`the script is at ${scriptPath}; the config was left unchanged`)}\n`);
|
|
23150
|
+
return;
|
|
23151
|
+
}
|
|
23152
|
+
store.updateHost({
|
|
23153
|
+
tempCommand: command,
|
|
23154
|
+
tempCommandTimeoutMs: 5e3
|
|
23155
|
+
});
|
|
23156
|
+
process.stdout.write(`${green("WSL temperature bridge set up")}\n`);
|
|
23157
|
+
process.stdout.write(` command ${bold(command)}\n`);
|
|
23158
|
+
process.stdout.write(` reading ${green(`${probe.celsius}°C`)}\n`);
|
|
23159
|
+
}
|
|
23160
|
+
}
|
|
23161
|
+
var setupTempArgs, setupTempCommand;
|
|
23162
|
+
var init_setup_temp = __esmMin((() => {
|
|
23163
|
+
init_io();
|
|
23164
|
+
init_settings$1();
|
|
23165
|
+
init_paths();
|
|
23166
|
+
init_wsl_temperature$1();
|
|
23167
|
+
setupTempArgs = {
|
|
23168
|
+
wsl: {
|
|
23169
|
+
type: "boolean",
|
|
23170
|
+
description: "read the temperature through the Windows host (WSL2)",
|
|
23171
|
+
default: false
|
|
23172
|
+
},
|
|
23173
|
+
clear: {
|
|
23174
|
+
type: "boolean",
|
|
23175
|
+
description: "stop using a configured command and delete its helper",
|
|
23176
|
+
default: false
|
|
23177
|
+
}
|
|
23178
|
+
};
|
|
23179
|
+
setupTempCommand = defineCommand({
|
|
23180
|
+
meta: { name: "setup-temp" },
|
|
23181
|
+
args: setupTempArgs,
|
|
23182
|
+
async run({ args }) {
|
|
23183
|
+
await runSetupTemp({
|
|
23184
|
+
wsl: args.wsl === true,
|
|
23185
|
+
clear: args.clear === true
|
|
23186
|
+
});
|
|
23187
|
+
}
|
|
23188
|
+
});
|
|
23189
|
+
}));
|
|
23190
|
+
//#endregion
|
|
21747
23191
|
//#region src/cli/migrate.ts
|
|
21748
23192
|
var migrate_exports = /* @__PURE__ */ __exportAll({
|
|
21749
23193
|
migrateArgs: () => migrateArgs,
|
|
@@ -21788,6 +23232,7 @@ async function runMigrate(dryRun, yes) {
|
|
|
21788
23232
|
if (existing.length === 0) fail(`no home-hosted state to migrate — nothing at ${globalSettingsPath} or any workspace`);
|
|
21789
23233
|
const consented = yes || (process.env.HHOSTED_MIGRATE ?? "").toLowerCase() === "allow";
|
|
21790
23234
|
let stampOnly = 0;
|
|
23235
|
+
let lifted = 0;
|
|
21791
23236
|
for (const target of existing) {
|
|
21792
23237
|
let raw;
|
|
21793
23238
|
try {
|
|
@@ -21835,6 +23280,7 @@ async function runMigrate(dryRun, yes) {
|
|
|
21835
23280
|
if (migratedProblem !== null) fail(`the migration produced a config this release cannot read:\n ${migratedProblem}`);
|
|
21836
23281
|
fs.copyFileSync(target.file, `${target.file}.bak`);
|
|
21837
23282
|
writeFileAtomic(target.file, `${JSON.stringify(stampConfig(migrated), null, 2)}\n`);
|
|
23283
|
+
lifted += 1;
|
|
21838
23284
|
process.stdout.write(`${green(`migrated ${target.label} to schema ${plan.to}`)} in ${target.file}\n`);
|
|
21839
23285
|
process.stdout.write(` ${dim(`previous file kept at ${target.file}.bak`)}\n`);
|
|
21840
23286
|
}
|
|
@@ -21842,8 +23288,11 @@ async function runMigrate(dryRun, yes) {
|
|
|
21842
23288
|
process.stdout.write(`${dim("nothing was written (--dry-run)")}\n`);
|
|
21843
23289
|
return;
|
|
21844
23290
|
}
|
|
21845
|
-
|
|
21846
|
-
|
|
23291
|
+
const done = [];
|
|
23292
|
+
if (lifted > 0) done.push(green(`${lifted} file(s) migrated`));
|
|
23293
|
+
if (stampOnly > 0) done.push(green(`${stampOnly} file(s) stamped`));
|
|
23294
|
+
if (done.length === 0) process.stdout.write(`every file is already what home-hosted ${appVersion()} understands — nothing to migrate\n`);
|
|
23295
|
+
else process.stdout.write(`${done.join(", ")} to what home-hosted ${appVersion()} understands\n`);
|
|
21847
23296
|
}
|
|
21848
23297
|
var migrateArgs, migrateCommand;
|
|
21849
23298
|
var init_migrate = __esmMin((() => {
|
|
@@ -22722,7 +24171,7 @@ var backup_exports = /* @__PURE__ */ __exportAll({
|
|
|
22722
24171
|
* Both directions print through this, and so does the "what could I act on" list, so the three read
|
|
22723
24172
|
* alike. A row's note is the panel's own wording, passed through untouched.
|
|
22724
24173
|
*/
|
|
22725
|
-
function printPlanTree(rows) {
|
|
24174
|
+
function printPlanTree(rows, out = (text) => process.stdout.write(text)) {
|
|
22726
24175
|
const known = new Set(rows.map((row) => row.id));
|
|
22727
24176
|
const nodes = /* @__PURE__ */ new Map();
|
|
22728
24177
|
const ensure = (id) => {
|
|
@@ -22748,8 +24197,7 @@ function printPlanTree(rows) {
|
|
|
22748
24197
|
const write = (id, depth) => {
|
|
22749
24198
|
const node = nodes.get(id);
|
|
22750
24199
|
if (node === void 0) return;
|
|
22751
|
-
|
|
22752
|
-
process.stdout.write(`${padding}${depth === 1 ? "" : "- "}${id}${node.note === null ? "" : ` ${dim(`(${node.note})`)}`}\n`);
|
|
24200
|
+
out(`${" ".repeat(depth)}${depth === 1 ? "" : "- "}${id}${node.note === null ? "" : ` ${dim(`(${node.note})`)}`}\n`);
|
|
22753
24201
|
for (const child of node.children) write(child, depth + 1);
|
|
22754
24202
|
};
|
|
22755
24203
|
for (const root of roots) write(root, 1);
|
|
@@ -22877,7 +24325,7 @@ async function refuseWithoutScope(action, suffix) {
|
|
|
22877
24325
|
if (rows.length === 0) fail("name what to act on — pass --include <ids> or --all");
|
|
22878
24326
|
process.stderr.write(`${paint("31", "error")} name what to act on — pass --include <ids> or --all\n\n`);
|
|
22879
24327
|
process.stderr.write("available (or narrow it):\n");
|
|
22880
|
-
printPlanTree(flattenRows(rows));
|
|
24328
|
+
printPlanTree(flattenRows(rows), (text) => process.stderr.write(text));
|
|
22881
24329
|
process.stderr.write("\n--exclude <ids> leaves those out: --all --exclude global:secrets\n");
|
|
22882
24330
|
process.exit(1);
|
|
22883
24331
|
}
|
|
@@ -23544,7 +24992,7 @@ var HEADER = "home-hosted — a control panel for the processes on your home ser
|
|
|
23544
24992
|
/** The one line the full reference lists for a command. */
|
|
23545
24993
|
var SYNOPSIS = {
|
|
23546
24994
|
"up": "home-hosted up [options]",
|
|
23547
|
-
"down": "home-hosted down",
|
|
24995
|
+
"down": "home-hosted down [--with-persistent]",
|
|
23548
24996
|
"restart": "home-hosted restart [<id>] [options]",
|
|
23549
24997
|
"status": "home-hosted status [--json]",
|
|
23550
24998
|
"logs": "home-hosted logs [--lines <n>] [--follow] [--json]",
|
|
@@ -23572,6 +25020,7 @@ var SUMMARIES = {
|
|
|
23572
25020
|
"free-port": "free the port a server needs, so it can start",
|
|
23573
25021
|
"set-password": "set the panel password without the API",
|
|
23574
25022
|
"set-token": "set the API token that scripts and agents use",
|
|
25023
|
+
"setup-temp": "teach the panel how to read this machine's CPU temperature",
|
|
23575
25024
|
"migrate": "bring the config up to this release's schema",
|
|
23576
25025
|
"init": "scaffold a project that keeps its state in the repo",
|
|
23577
25026
|
"ui-switch": "install a UI from a release asset, a zip file or a URL",
|
|
@@ -23629,11 +25078,17 @@ var START_SECTION = {
|
|
|
23629
25078
|
["--free-port", "free the port first, then start — the panel's Free port button"]
|
|
23630
25079
|
]
|
|
23631
25080
|
};
|
|
25081
|
+
var PERSISTENT_LINE = ["--with-persistent", "stop the persistent entries too (default: leave them running)"];
|
|
25082
|
+
var DOWN_SECTION = {
|
|
25083
|
+
heading: "Options for down",
|
|
25084
|
+
lines: [PERSISTENT_LINE]
|
|
25085
|
+
};
|
|
23632
25086
|
var RESTART_SECTION = {
|
|
23633
25087
|
heading: "Options for restart",
|
|
23634
25088
|
lines: [
|
|
23635
25089
|
["<id>", "restart just this server, leaving the panel up (optional)"],
|
|
23636
25090
|
["-w, --workspace <id>", "the workspace to act in, with an id"],
|
|
25091
|
+
PERSISTENT_LINE,
|
|
23637
25092
|
...UP_SECTION.lines
|
|
23638
25093
|
]
|
|
23639
25094
|
};
|
|
@@ -23754,6 +25209,8 @@ var USAGE = [
|
|
|
23754
25209
|
"",
|
|
23755
25210
|
renderSection(UI_SWITCH_SECTION),
|
|
23756
25211
|
"",
|
|
25212
|
+
renderSection(DOWN_SECTION),
|
|
25213
|
+
"",
|
|
23757
25214
|
renderSection(STATUS_SECTION),
|
|
23758
25215
|
"",
|
|
23759
25216
|
renderSection(SERVER_SECTION),
|
|
@@ -23762,6 +25219,7 @@ var USAGE = [
|
|
|
23762
25219
|
].join("\n");
|
|
23763
25220
|
var UP_COMMANDS = /* @__PURE__ */ new Set(["up", "restart"]);
|
|
23764
25221
|
var SECTIONS = {
|
|
25222
|
+
"down": DOWN_SECTION,
|
|
23765
25223
|
"status": STATUS_SECTION,
|
|
23766
25224
|
"logs": LOGS_SECTION,
|
|
23767
25225
|
"backup": BACKUP_SECTION,
|
|
@@ -23814,6 +25272,7 @@ var COMMANDS = {
|
|
|
23814
25272
|
"free-port": () => Promise.resolve().then(() => (init_server(), server_exports)).then((module) => module.freePortCommand),
|
|
23815
25273
|
"set-password": () => Promise.resolve().then(() => (init_set_password(), set_password_exports)).then((module) => module.setPasswordCommand),
|
|
23816
25274
|
"set-token": () => Promise.resolve().then(() => (init_set_token(), set_token_exports)).then((module) => module.setTokenCommand),
|
|
25275
|
+
"setup-temp": () => Promise.resolve().then(() => (init_setup_temp(), setup_temp_exports)).then((module) => module.setupTempCommand),
|
|
23817
25276
|
"migrate": () => Promise.resolve().then(() => (init_migrate(), migrate_exports)).then((module) => module.migrateCommand),
|
|
23818
25277
|
"init": () => Promise.resolve().then(() => (init_init(), init_exports)).then((module) => module.initCommand),
|
|
23819
25278
|
"ui-switch": () => Promise.resolve().then(() => (init_ui_switch(), ui_switch_exports)).then((module) => module.uiSwitchCommand),
|
|
@@ -23831,6 +25290,7 @@ var rootCommand = defineCommand({
|
|
|
23831
25290
|
});
|
|
23832
25291
|
var commandNames = Object.keys(COMMANDS);
|
|
23833
25292
|
async function main() {
|
|
25293
|
+
treatClosedReaderAsDone();
|
|
23834
25294
|
const dirFlags = extractDirFlags(process.argv.slice(2));
|
|
23835
25295
|
if (dirFlags.error !== void 0) fail(dirFlags.error);
|
|
23836
25296
|
applyDirFlags(dirFlags);
|