fix: Fix the problem of abnormal script execution (#8496)

This commit is contained in:
ssongliu 2025-04-28 14:05:48 +08:00 committed by GitHub
parent 39502b355f
commit 937ab76183
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -4,7 +4,6 @@ import (
"fmt"
"path"
"strconv"
"strings"
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
"github.com/1Panel-dev/1Panel/core/app/dto"
@ -14,6 +13,7 @@ import (
"github.com/1Panel-dev/1Panel/core/utils/terminal"
"github.com/1Panel-dev/1Panel/core/utils/xpack"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/pkg/errors"
)
@ -159,7 +159,6 @@ func (b *BaseApi) RunScript(c *gin.Context) {
return
}
fileName := strings.ReplaceAll(scriptItem.Name, " ", "_")
quitChan := make(chan bool, 3)
if currentNode == "local" {
slave, err := terminal.NewCommand(scriptItem.Script)
@ -181,8 +180,10 @@ func (b *BaseApi) RunScript(c *gin.Context) {
if wshandleError(wsConn, errors.WithMessage(err, "invalid param rows in request")) {
return
}
tmpFile := path.Join(installDir, "1panel/tmp/script")
initCmd := fmt.Sprintf("d=%s && mkdir -p $d && echo %s > $d/%s && clear && bash $d/%s", tmpFile, scriptItem.Script, fileName, fileName)
fileDir := path.Join(installDir, "1panel/tmp/script")
fileName := path.Join(fileDir, uuid.NewString())
initCmd := fmt.Sprintf("mkdir -p %s && cat > %s <<'EOF'\n%s\nEOF\n bash %s", fileDir, fileName, scriptItem.Script, fileName)
client, err := ssh.NewClient(*connInfo)
if wshandleError(wsConn, errors.WithMessage(err, "failed to set up the connection. Please check the host information")) {
return

View file

@ -87,7 +87,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
formEl.validate(async (valid) => {
if (!valid) return;
loading.value = true;
if (dialogData.value.rowData.groupList.length !== 0) {
if (dialogData.value.rowData.groupList?.length !== 0) {
dialogData.value.rowData.groups = dialogData.value.rowData.groupList?.join(',');
}
if (dialogData.value.title === 'create' || dialogData.value.title === 'clone') {