mirror of
https://github.com/louislam/dockge.git
synced 2026-05-21 14:02:17 +00:00
Console Improvements (#767)
This commit is contained in:
@@ -38,6 +38,11 @@ export class TerminalSocketHandler extends AgentSocketHandler {
|
||||
try {
|
||||
checkLogin(socket);
|
||||
|
||||
// Throw an error if console is not enabled
|
||||
if (!server.config.enableConsole) {
|
||||
throw new ValidationError("Console is not enabled.");
|
||||
}
|
||||
|
||||
// TODO: Reset the name here, force one main terminal for now
|
||||
terminalName = "console";
|
||||
|
||||
@@ -66,6 +71,18 @@ export class TerminalSocketHandler extends AgentSocketHandler {
|
||||
}
|
||||
});
|
||||
|
||||
// Check if MainTerminal is enabled
|
||||
agentSocket.on("checkMainTerminal", async (callback) => {
|
||||
try {
|
||||
checkLogin(socket);
|
||||
callbackResult({
|
||||
ok: server.config.enableConsole,
|
||||
}, callback);
|
||||
} catch (e) {
|
||||
callbackError(e, callback);
|
||||
}
|
||||
});
|
||||
|
||||
// Interactive Terminal for containers
|
||||
agentSocket.on("interactiveTerminal", async (stackName : unknown, serviceName : unknown, shell : unknown, callback) => {
|
||||
try {
|
||||
|
||||
@@ -136,6 +136,11 @@ export class DockgeServer {
|
||||
stacksDir: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
enableConsole: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
defaultValue: false,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -149,6 +154,7 @@ export class DockgeServer {
|
||||
this.config.hostname = args.hostname || process.env.DOCKGE_HOSTNAME || undefined;
|
||||
this.config.dataDir = args.dataDir || process.env.DOCKGE_DATA_DIR || "./data/";
|
||||
this.config.stacksDir = args.stacksDir || process.env.DOCKGE_STACKS_DIR || defaultStacksDir;
|
||||
this.config.enableConsole = args.enableConsole || process.env.DOCKGE_ENABLE_CONSOLE === "true" || false;
|
||||
this.stacksDir = this.config.stacksDir;
|
||||
|
||||
log.debug("server", this.config);
|
||||
|
||||
@@ -4,7 +4,6 @@ import * as pty from "@homebridge/node-pty-prebuilt-multiarch";
|
||||
import { LimitQueue } from "./utils/limit-queue";
|
||||
import { DockgeSocket } from "./util-server";
|
||||
import {
|
||||
allowedCommandList, allowedRawKeys,
|
||||
PROGRESS_TERMINAL_ROWS,
|
||||
TERMINAL_COLS,
|
||||
TERMINAL_ROWS
|
||||
@@ -16,7 +15,6 @@ import { log } from "./log";
|
||||
* Terminal for running commands, no user interaction
|
||||
*/
|
||||
export class Terminal {
|
||||
|
||||
protected static terminalMap : Map<string, Terminal> = new Map();
|
||||
|
||||
protected _ptyProcess? : pty.IPty;
|
||||
@@ -272,6 +270,11 @@ export class MainTerminal extends InteractiveTerminal {
|
||||
constructor(server : DockgeServer, name : string) {
|
||||
let shell;
|
||||
|
||||
// Throw an error if console is not enabled
|
||||
if (!server.config.enableConsole) {
|
||||
throw new Error("Console is not enabled.");
|
||||
}
|
||||
|
||||
if (os.platform() === "win32") {
|
||||
if (commandExistsSync("pwsh.exe")) {
|
||||
shell = "pwsh.exe";
|
||||
@@ -285,21 +288,6 @@ export class MainTerminal extends InteractiveTerminal {
|
||||
}
|
||||
|
||||
public write(input : string) {
|
||||
// For like Ctrl + C
|
||||
if (allowedRawKeys.includes(input)) {
|
||||
super.write(input);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the command is allowed
|
||||
const cmdParts = input.split(" ");
|
||||
const executable = cmdParts[0].trim();
|
||||
log.debug("console", "Executable: " + executable);
|
||||
log.debug("console", "Executable length: " + executable.length);
|
||||
|
||||
if (!allowedCommandList.includes(executable)) {
|
||||
throw new Error("Command not allowed.");
|
||||
}
|
||||
super.write(input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface Arguments {
|
||||
hostname? : string;
|
||||
dataDir? : string;
|
||||
stacksDir? : string;
|
||||
enableConsole? : boolean;
|
||||
}
|
||||
|
||||
// Some config values are required
|
||||
|
||||
Reference in New Issue
Block a user