opt: check instance advanced params

This commit is contained in:
Lazy 2025-03-05 16:39:29 +08:00
parent 96ecc0ce77
commit 0dd75ac7a7
5 changed files with 38 additions and 46 deletions

View File

@ -2552,8 +2552,8 @@
"TXT_CODE_c6d3bd8": "MC Pufferfish",
"TXT_CODE_eee2a47f": "Image preview",
"TXT_CODE_66f38b2e": "Normal users can only modify part of the settings",
"TXT_CODE_a583cae4": "Allow normal users to edit the startup command",
"TXT_CODE_bfbdf579": "This feature allows normal users to edit the 'start' and 'update' commands of Docker instances",
"TXT_CODE_a583cae4": "Allow normal users to edit instance advanced configuration",
"TXT_CODE_bfbdf579": "This feature allows ordinary users to edit the configuration of Docker instances such as the \"start\" and \"update\" commands",
"TXT_CODE_36cae384": "You are using a private IP address",
"TXT_CODE_ea6e5e5e": "This node may not work properly when accessing the panel using a public IP address",
"TXT_CODE_678164d7": "You can find the node ID in the 'Node List' section of the merchant console"

View File

@ -2552,8 +2552,8 @@
"TXT_CODE_c6d3bd8": "MC Pufferfish",
"TXT_CODE_eee2a47f": "图像预览",
"TXT_CODE_66f38b2e": "普通用户仅可修改部分设置",
"TXT_CODE_a583cae4": "准许普通用户编辑启动命令",
"TXT_CODE_bfbdf579": "该功能允许普通用户编辑 Docker 实例的“启动”和“更新”命令",
"TXT_CODE_a583cae4": "准许普通用户编辑实例高级配置",
"TXT_CODE_bfbdf579": "该功能允许普通用户编辑 Docker 实例的“启动”和“更新”命令等配置",
"TXT_CODE_36cae384": "你正使用私有 IP 地址",
"TXT_CODE_ea6e5e5e": "使用公网地址访问面板时该节点可能无法正常工作",
"TXT_CODE_678164d7": "在 “商家控制台 - 节点列表” 中可以找到节点ID"

View File

@ -2552,8 +2552,8 @@
"TXT_CODE_c6d3bd8": "MC Pufferfish",
"TXT_CODE_eee2a47f": "圖片預覽",
"TXT_CODE_66f38b2e": "使用者只能修改部分設定",
"TXT_CODE_a583cae4": "允許使用者編輯啟動指令",
"TXT_CODE_bfbdf579": "該功能允許使用者編輯 Docker 伺服器的「啟動」和「更新」指令",
"TXT_CODE_a583cae4": "允許使用者編輯實例高級設定",
"TXT_CODE_bfbdf579": "該功能允許使用者編輯 Docker 伺服器的「啟動」和「更新」指令等設定",
"TXT_CODE_36cae384": "你正使用虛擬 IP 位址",
"TXT_CODE_ea6e5e5e": "使用公共 ip 存取面板時該節點可能無法正常運作",
"TXT_CODE_678164d7": "在「商家控制台 - 節點清單」中可以找到節點ID"

View File

@ -13,6 +13,7 @@ import { ROLE } from "../entity/user";
import axios from "axios";
import { systemConfig } from "../setting";
import { IQuickStartTemplate } from "common/global";
import { checkInstanceAdvancedParams } from "../service/instance_service";
const router = new Router({ prefix: "/protected_instance" });
@ -422,43 +423,11 @@ router.put(
const ie = !isEmpty(config.ie) ? toText(config?.ie) : null;
const fileCode = toText(config.fileCode);
const stopCommand = config.stopCommand ? toText(config.stopCommand) : null;
const startCommand = toText(config.startCommand);
const updateCommand = toText(config.updateCommand);
const dockerEnv =
!isEmpty(config.docker.env) && Array.isArray(config.docker.env) ? config.docker.env : [];
const remoteService = RemoteServiceSubsystem.getInstance(daemonId || "");
const isTopPermission = isTopPermissionByUuid(getUserUuid(ctx));
const instance = await new RemoteRequest(remoteService).request("instance/detail", {
instanceUuid
});
const isCmdChanged = (cmd: string | null, instanceCmd: string) => cmd !== instanceCmd;
const hasPermission = isTopPermissionByUuid(getUserUuid(ctx));
if (
dockerEnv.length &&
instance.config.processType !== "docker" &&
!systemConfig?.allowChangeCmd &&
!hasPermission
)
return verificationFailed(ctx);
if (
(startCommand || updateCommand) &&
isCmdChanged(startCommand, instance.config.startCommand) &&
isCmdChanged(updateCommand, instance.config.updateCommand)
) {
if (instance.config.processType !== "docker" && !hasPermission)
return verificationFailed(ctx);
if (
instance.config.processType === "docker" &&
!systemConfig?.allowChangeCmd &&
!hasPermission
)
return verificationFailed(ctx);
}
let advancedConfig = {};
advancedConfig = checkInstanceAdvancedParams(config, isTopPermission);
const result = await new RemoteRequest(remoteService).request("instance/update", {
instanceUuid,
@ -477,11 +446,7 @@ router.put(
enableRcon,
tag: instanceTags,
fileCode,
startCommand: startCommand ?? instance.startCommand,
updateCommand: updateCommand ?? instance.updateCommand,
docker: {
env: dockerEnv
}
...advancedConfig
}
});
ctx.body = result;

View File

@ -2,6 +2,9 @@ import userSystem from "../service/user_service";
import RemoteServiceSubsystem from "../service/remote_service";
import RemoteRequest from "../service/remote_command";
import { t } from "i18next";
import { systemConfig } from "../setting";
import { isEmpty, toText } from "common/dist";
import { IGlobalInstanceConfig } from "common/global";
export enum INSTANCE_STATUS {
BUSY = -1,
@ -136,3 +139,27 @@ export async function getInstancesByUuid(
token: ""
};
}
export function checkInstanceAdvancedParams(
config: IGlobalInstanceConfig,
isTopPermission: boolean = false
) {
const canChangeCmd = systemConfig?.allowChangeCmd;
if (!isTopPermission) {
if (!canChangeCmd) return {};
if (config.processType !== "docker") return {};
}
const startCommand = toText(config.startCommand);
const updateCommand = toText(config.updateCommand);
const dockerEnv =
!isEmpty(config.docker.env) && Array.isArray(config.docker.env) ? config.docker.env : [];
return {
startCommand,
updateCommand,
docker: {
env: dockerEnv
}
};
}