Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
24cf41b8
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
大约 1 年 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
24cf41b8
编写于
5月 17, 2023
作者:
Z
zhaoke
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'main' of git.zcorp.cc:pangu/zentaoatf
上级
e729619a
6e2c910c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
129 addition
and
88 deletion
+129
-88
internal/pkg/helper/exec/errMsg.go
internal/pkg/helper/exec/errMsg.go
+22
-0
internal/pkg/helper/exec/file.go
internal/pkg/helper/exec/file.go
+8
-83
internal/pkg/helper/exec/interpreter.go
internal/pkg/helper/exec/interpreter.go
+99
-5
未找到文件。
internal/pkg/helper/exec/errMsg.go
0 → 100644
浏览文件 @
24cf41b8
package
execHelper
import
(
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
websocketHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
logUtils
"github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/fatih/color"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/websocket"
)
func
PrintErrMsg
(
key
string
,
err
error
,
wsMsg
*
websocket
.
Message
)
(
stdOutput
string
,
errOutput
string
)
{
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
err
.
Error
(),
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
color
.
FgRed
,
err
.
Error
())
logUtils
.
ExecFilef
(
err
.
Error
())
return
""
,
err
.
Error
()
}
internal/pkg/helper/exec/file.go
浏览文件 @
24cf41b8
...
...
@@ -3,20 +3,15 @@ package execHelper
import
(
"bufio"
"context"
"fm
t"
scriptHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/scrip
t"
"io"
"os"
"os/exec"
"strings"
"time"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
configHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/config"
langHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/lang"
scriptHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/script"
websocketHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
commonUtils
"github.com/easysoft/zentaoatf/pkg/lib/common"
i118Utils
"github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils
"github.com/easysoft/zentaoatf/pkg/lib/log"
stringUtils
"github.com/easysoft/zentaoatf/pkg/lib/string"
...
...
@@ -34,74 +29,16 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
lang
:=
langHelper
.
GetLangByFile
(
filePath
)
var
cmd
*
exec
.
Cmd
uuidString
:=
uuid
.
Must
(
uuid
.
NewV4
())
.
String
()
_
,
_
,
_
,
_
,
timeout
:=
scriptHelper
.
GetCaseInfo
(
filePath
)
if
timeout
==
0
{
timeout
=
86400
*
7
}
ctxt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
time
.
Duration
(
timeout
))
defer
cancel
()
uuidString
:=
uuid
.
Must
(
uuid
.
NewV4
())
.
String
()
if
commonUtils
.
IsWin
()
{
scriptInterpreter
:=
""
if
strings
.
ToLower
(
lang
)
!=
"bat"
{
scriptInterpreter
=
configHelper
.
GetFieldVal
(
conf
,
stringUtils
.
UcFirst
(
lang
))
}
if
scriptInterpreter
!=
""
{
if
strings
.
Index
(
strings
.
ToLower
(
scriptInterpreter
),
"autoit"
)
>
-
1
{
cmd
=
exec
.
CommandContext
(
ctxt
,
"cmd"
,
"/C"
,
scriptInterpreter
,
filePath
,
"|"
,
"more"
)
}
else
{
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
cmd
=
exec
.
CommandContext
(
ctxt
,
"cmd"
,
"/C"
,
scriptInterpreter
,
command
,
filePath
,
"-uuid"
,
uuidString
)
}
else
{
cmd
=
exec
.
CommandContext
(
ctxt
,
"cmd"
,
"/C"
,
scriptInterpreter
,
filePath
,
"-uuid"
,
uuidString
)
}
}
}
else
if
strings
.
ToLower
(
lang
)
==
"bat"
{
cmd
=
exec
.
CommandContext
(
ctxt
,
"cmd"
,
"/C"
,
filePath
,
"-uuid"
,
uuidString
)
}
else
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"no_interpreter_for_run"
,
lang
,
filePath
)
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
msg
,
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
-
1
,
msg
)
logUtils
.
ExecFilef
(
msg
)
}
}
else
{
err
:=
os
.
Chmod
(
filePath
,
0777
)
if
err
!=
nil
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"exec_cmd_fail"
,
filePath
,
err
.
Error
())
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
msg
,
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
-
1
,
msg
)
logUtils
.
ExecFilef
(
msg
)
}
//filePath = "\"" + filePath + "\""
scriptInterpreter
:=
configHelper
.
GetFieldVal
(
conf
,
stringUtils
.
UcFirst
(
lang
))
if
scriptInterpreter
!=
""
{
msg
:=
fmt
.
Sprintf
(
"use interpreter %s"
,
scriptInterpreter
)
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
//websocketHelper.SendOutputMsg(msg, "", iris.Map{"key": key}, wsMsg)
logUtils
.
ExecConsolef
(
-
1
,
msg
)
}
//logUtils.ExecFilef(msg)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
time
.
Duration
(
timeout
))
defer
cancel
()
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
cmd
=
exec
.
CommandContext
(
ctxt
,
scriptInterpreter
,
command
,
filePath
)
}
else
{
cmd
=
exec
.
CommandContext
(
ctxt
,
scriptInterpreter
,
filePath
)
}
}
else
{
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
filePath
=
fmt
.
Sprintf
(
"%s %s %s"
,
lang
,
command
,
filePath
)
}
cmd
=
exec
.
CommandContext
(
ctxt
,
"/bin/bash"
,
"-c"
,
fmt
.
Sprintf
(
"%s -uuid %s"
,
filePath
,
uuidString
))
}
}
cmd
:=
getCommand
(
filePath
,
lang
,
uuidString
,
conf
,
ctx
,
wsMsg
)
if
cmd
==
nil
{
msgStr
:=
i118Utils
.
Sprintf
(
"cmd_empty"
)
...
...
@@ -123,21 +60,9 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
stderr
,
err2
:=
cmd
.
StderrPipe
()
if
err1
!=
nil
{
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
err1
.
Error
(),
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
color
.
FgRed
,
err1
.
Error
())
logUtils
.
ExecFilef
(
err1
.
Error
())
return
""
,
err1
.
Error
()
return
PrintErrMsg
(
key
,
err1
,
wsMsg
)
}
else
if
err2
!=
nil
{
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
err2
.
Error
(),
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
color
.
FgRed
,
err2
.
Error
())
logUtils
.
ExecFilef
(
err2
.
Error
())
return
""
,
err2
.
Error
()
return
PrintErrMsg
(
key
,
err2
,
wsMsg
)
}
cmd
.
Start
()
...
...
@@ -226,7 +151,7 @@ ExitCurrCase:
errOutputArr
=
append
(
errOutputArr
,
line
)
}
}
if
ctx
t
.
Err
()
!=
nil
{
if
ctx
.
Err
()
!=
nil
{
errOutputArr
=
append
(
errOutputArr
,
i118Utils
.
Sprintf
(
"exec_cmd_timeout"
))
}
...
...
internal/pkg/helper/exec/interpreter.go
浏览文件 @
24cf41b8
...
...
@@ -2,21 +2,115 @@ package execHelper
import
(
"bytes"
"os/exec"
"path/filepath"
"regexp"
"strings"
"context"
"fmt"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
configHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/config"
websocketHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
"github.com/easysoft/zentaoatf/internal/server/core/dao"
"github.com/easysoft/zentaoatf/internal/server/modules/v1/model"
commonUtils
"github.com/easysoft/zentaoatf/pkg/lib/common"
fileUtils
"github.com/easysoft/zentaoatf/pkg/lib/file"
i118Utils
"github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils
"github.com/easysoft/zentaoatf/pkg/lib/log"
shellUtils
"github.com/easysoft/zentaoatf/pkg/lib/shell"
stringUtils
"github.com/easysoft/zentaoatf/pkg/lib/string"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/websocket"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
)
func
getCommand
(
filePath
,
lang
,
uuidString
string
,
conf
commDomain
.
WorkspaceConf
,
ctx
context
.
Context
,
wsMsg
*
websocket
.
Message
)
(
cmd
*
exec
.
Cmd
)
{
if
commonUtils
.
IsWin
()
{
cmd
=
setWinScriptInterpreter
(
filePath
,
lang
,
uuidString
,
conf
,
ctx
,
wsMsg
)
}
else
{
cmd
=
setLinuxScriptInterpreter
(
filePath
,
lang
,
uuidString
,
conf
,
ctx
,
wsMsg
)
}
return
}
func
setWinScriptInterpreter
(
filePath
,
lang
,
uuidString
string
,
conf
commDomain
.
WorkspaceConf
,
ctx
context
.
Context
,
wsMsg
*
websocket
.
Message
)
(
cmd
*
exec
.
Cmd
)
{
key
:=
stringUtils
.
Md5
(
filePath
)
scriptInterpreter
:=
""
if
strings
.
ToLower
(
lang
)
!=
"bat"
{
scriptInterpreter
=
configHelper
.
GetFieldVal
(
conf
,
stringUtils
.
UcFirst
(
lang
))
}
if
scriptInterpreter
!=
""
{
if
strings
.
Index
(
strings
.
ToLower
(
scriptInterpreter
),
"autoit"
)
>
-
1
{
cmd
=
exec
.
CommandContext
(
ctx
,
"cmd"
,
"/C"
,
scriptInterpreter
,
filePath
,
"|"
,
"more"
)
}
else
{
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
cmd
=
exec
.
CommandContext
(
ctx
,
"cmd"
,
"/C"
,
scriptInterpreter
,
command
,
filePath
,
"-uuid"
,
uuidString
)
}
else
{
cmd
=
exec
.
CommandContext
(
ctx
,
"cmd"
,
"/C"
,
scriptInterpreter
,
filePath
,
"-uuid"
,
uuidString
)
}
}
}
else
if
strings
.
ToLower
(
lang
)
==
"bat"
{
cmd
=
exec
.
CommandContext
(
ctx
,
"cmd"
,
"/C"
,
filePath
,
"-uuid"
,
uuidString
)
}
else
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"no_interpreter_for_run"
,
lang
,
filePath
)
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
msg
,
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
-
1
,
msg
)
logUtils
.
ExecFilef
(
msg
)
}
return
}
func
setLinuxScriptInterpreter
(
filePath
,
lang
,
uuidString
string
,
conf
commDomain
.
WorkspaceConf
,
ctx
context
.
Context
,
wsMsg
*
websocket
.
Message
)
(
cmd
*
exec
.
Cmd
)
{
key
:=
stringUtils
.
Md5
(
filePath
)
err
:=
os
.
Chmod
(
filePath
,
0777
)
if
err
!=
nil
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"exec_cmd_fail"
,
filePath
,
err
.
Error
())
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
websocketHelper
.
SendOutputMsg
(
msg
,
""
,
iris
.
Map
{
"key"
:
key
},
wsMsg
)
}
logUtils
.
ExecConsolef
(
-
1
,
msg
)
logUtils
.
ExecFilef
(
msg
)
}
//filePath = "\"" + filePath + "\""
scriptInterpreter
:=
configHelper
.
GetFieldVal
(
conf
,
stringUtils
.
UcFirst
(
lang
))
if
scriptInterpreter
!=
""
{
msg
:=
fmt
.
Sprintf
(
"use interpreter %s"
,
scriptInterpreter
)
if
commConsts
.
ExecFrom
==
commConsts
.
FromClient
{
//websocketHelper.SendOutputMsg(msg, "", iris.Map{"key": key}, wsMsg)
logUtils
.
ExecConsolef
(
-
1
,
msg
)
}
//logUtils.ExecFilef(msg)
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
cmd
=
exec
.
CommandContext
(
ctx
,
scriptInterpreter
,
command
,
filePath
)
}
else
{
cmd
=
exec
.
CommandContext
(
ctx
,
scriptInterpreter
,
filePath
)
}
}
else
{
if
command
,
ok
:=
commConsts
.
LangMap
[
lang
][
"CompiledCommand"
];
ok
&&
command
!=
""
{
filePath
=
fmt
.
Sprintf
(
"%s %s %s"
,
lang
,
command
,
filePath
)
}
cmd
=
exec
.
CommandContext
(
ctx
,
"/bin/bash"
,
"-c"
,
fmt
.
Sprintf
(
"%s -uuid %s"
,
filePath
,
uuidString
))
}
return
}
func
AddInterpreterIfExist
(
conf
*
commDomain
.
WorkspaceConf
,
lang
string
)
bool
{
if
commConsts
.
ExecFrom
!=
commConsts
.
FromZentao
{
return
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录