Basic functionality of remote npm

This commit is contained in:
Cooldude2606 committed 2025-04-29 01:40:22 +01:00
1 parent 47c5e0fabd
commit ff35b5c378
13 files changed
+496

No files matched your search

+48
View File
@@ -28,6 +28,9 @@ export interface ControllerConfigFields {
"controller.autosave_interval": number;
"controller.mod_portal_cache_duration_minutes": number;
"controller.mod_portal_page_size": number;
"controller.allow_remote_updates": boolean;
"controller.allow_plugin_updates": boolean;
"controller.allow_plugin_install": boolean;
}
/**
@@ -211,6 +214,27 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
type: "number",
initialValue: 1000,
},
"controller.allow_remote_updates": {
description: "When true, allows a remote event to trigger a clusterio update via npm",
type: "boolean",
initialValue: true,
readonly: ["controller"],
hidden: true,
},
"controller.allow_plugin_updates": {
description: "When true, allows a remote event to trigger a plugin update via npm",
type: "boolean",
initialValue: true,
readonly: ["controller"],
hidden: true,
},
"controller.allow_plugin_install": {
description: "When true, allows a remote event to trigger a plugin install via npm",
type: "boolean",
initialValue: false,
readonly: ["controller"],
hidden: true,
},
};
}
@@ -228,6 +252,9 @@ export interface HostConfigFields {
"host.factorio_username": string | null,
"host.factorio_token": string | null,
"host.max_reconnect_delay": number;
"host.allow_remote_updates": boolean;
"host.allow_plugin_updates": boolean;
"host.allow_plugin_install": boolean;
}
/**
@@ -323,6 +350,27 @@ export class HostConfig extends classes.Config<HostConfigFields> {
type: "number",
initialValue: 60,
},
"host.allow_remote_updates": {
description: "When true, allows a remote event to trigger a clusterio update via npm",
type: "boolean",
initialValue: true,
readonly: ["host"],
hidden: true,
},
"host.allow_plugin_updates": {
description: "When true, allows a remote event to trigger a plugin update via npm",
type: "boolean",
initialValue: true,
readonly: ["host"],
hidden: true,
},
"host.allow_plugin_install": {
description: "When true, allows a remote event to trigger a plugin install via npm",
type: "boolean",
initialValue: false,
readonly: ["host"],
hidden: true,
},
};
}
@@ -352,6 +352,58 @@ export class SystemInfoUpdateEvent {
}
}
export class RemoteUpdateRequest {
declare ["constructor"]: typeof RemoteUpdateRequest;
static type = "request" as const;
static src = "control" as const;
static dst = ["controller", "host"] as const;
static permission = "core.rce.remote_update";
}
export class PluginUpdateRequest {
declare ["constructor"]: typeof PluginUpdateRequest;
static type = "request" as const;
static src = "control" as const;
static dst = ["controller", "host"] as const;
static permission = "core.rce.plugin_update";
constructor(
public pluginPackage: string,
) {}
static jsonSchema = Type.String();
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json);
}
toJSON() {
return this.pluginPackage;
}
}
export class PluginInstallRequest {
declare ["constructor"]: typeof PluginInstallRequest;
static type = "request" as const;
static src = "control" as const;
static dst = ["controller", "host"] as const;
static permission = "core.rce.plugin_install";
constructor(
public pluginPackage: string,
) {}
static jsonSchema = Type.String();
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json);
}
toJSON() {
return this.pluginPackage;
}
}
export class DebugDumpWsRequest {
declare ["constructor"]: typeof DebugDumpWsRequest;
static type = "request" as const;
+3
View File
@@ -30,6 +30,9 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
controller.LogMessageEvent,
controller.SystemInfoRequest,
controller.SystemInfoUpdateEvent,
controller.RemoteUpdateRequest,
controller.PluginUpdateRequest,
controller.PluginInstallRequest,
controller.DebugDumpWsRequest,
controller.DebugWsMessageEvent,
+16
View File
@@ -525,6 +525,22 @@ definePermission({
description: "Query past entries in the cluster log. Required to see past entries in instance console.",
});
definePermission({
name: "core.rce.remote_update",
title: "Clusterio remote update",
description: "Start a remote update of the clusterio packages",
});
definePermission({
name: "core.rce.plugin_update",
title: "Plugin remote update",
description: "Start a remote update of a third party plugin package",
});
definePermission({
name: "core.rce.plugin_install",
title: "Plugin remote install",
description: "Start a remote install of a third party plugin package",
});
definePermission({
name: "core.debug.dump_ws",
title: "Dump WebSocket",
+26
View File
@@ -0,0 +1,26 @@
import util from "util";
import path from "path";
import { exec } from "child_process";
import { logger } from "./logging";
const execAsync = util.promisify(exec);
async function isDev() {
// dev: <devRoot>/packages/lib/dist/src/rce_ops.js
// prod: <prodRoot>/node_modules/@clusterio/lib/dist/src/rce_ops.js
return __dirname.split(path.sep).at(-5) === "packages"; // opposed to "@clusterio"
}
async function logExec(cmd: string) {
logger.audit(`RCE | ${cmd}`);
if (!isDev()) {
await execAsync(cmd);
}
}
export async function updatePackage(name: string) {
return logExec(`npm update --save ${name}`);
}
export async function installPackage(name: string) {
return logExec(`npm install --save ${name}`);
}