Merge pull request 'hashcat' (#32) from zhangweiii/pcm-coordinator:v0.1.0-xjlab-alpha1 into v0.1.0-xjlab-alpha1
Former-commit-id: 5cccf59c08402261b863dc65c005d0065df02579
This commit is contained in:
commit
01fca333d9
|
@ -565,14 +565,25 @@ type NodeAsset {
|
|||
ParticipantId int64 `json:"ParticipantId"` // 集群动态信息id
|
||||
}
|
||||
|
||||
type crackProgressReq {
|
||||
CrackTaskId string `form:"crackTaskId"`
|
||||
}
|
||||
|
||||
type crackProgressResp {
|
||||
Progress string `json:"progress"`
|
||||
Current string `json:"current"`
|
||||
Total string `json:"total"`
|
||||
Speed string `json:"speed"`
|
||||
}
|
||||
|
||||
type SaveHashcatReq {
|
||||
CrackTaskId string `json:"crackTaskId"` // 任务id
|
||||
CrackContainerId string `json:"crackContainerId"` // 容器id
|
||||
CrackStatus string `json:"crackStatus"` // 状态
|
||||
CrackStartTime string `json:"crackStartTime"` //开始时间
|
||||
CrackEstimatedTime string `json:"crackEstimatedTime"` // 预计时间
|
||||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
CrackTaskId string `json:"crackTaskId"` // 任务id
|
||||
CrackContainerId string `json:"crackContainerId"` // 容器id
|
||||
CrackStatus string `json:"crackStatus"` // 状态
|
||||
CrackStartTime string `json:"crackStartTime"` //开始时间
|
||||
CrackEstimatedTime string `json:"crackEstimatedTime"` // 预计时间
|
||||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
Started string `json:"started,optional"` // 开始时间
|
||||
Stopped string `json:"stopped,optional"` // 结束时间
|
||||
KernelFeature string `json:"kernelFeature"`
|
||||
|
|
|
@ -117,6 +117,10 @@ service pcm {
|
|||
@handler tasksNumHandler
|
||||
get /core/tasks/num (tasksNumReq) returns (tasksNumResp)
|
||||
|
||||
@doc "Hashcat Crack Progress"
|
||||
@handler crackProgressHandler
|
||||
get /core/crack/progress (crackProgressReq) returns (crackProgressResp)
|
||||
|
||||
@doc "Resource Center Information"
|
||||
@handler resourceCenterInfoHandler
|
||||
get /core/center/resource/:participantId (resourceCenterInfoReq) returns (resourceCenterInfoResp)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
)
|
||||
|
||||
func CrackProgressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CrackProgressReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := core.NewCrackProgressLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CrackProgress(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -130,6 +130,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/core/tasks/num",
|
||||
Handler: core.TasksNumHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/crack/progress",
|
||||
Handler: core.CrackProgressHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/center/resource/:participantId",
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||
"strings"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CrackProgressLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCrackProgressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CrackProgressLogic {
|
||||
return &CrackProgressLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CrackProgressLogic) CrackProgress(req *types.CrackProgressReq) (resp *types.CrackProgressResp, err error) {
|
||||
result := types.CrackProgressResp{}
|
||||
var hashcat *models.THashcat
|
||||
tx := l.svcCtx.DbEngin.Where("crack_task_id = ?", req.CrackTaskId).Order("id desc").Limit(1).Find(&hashcat)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
if len(hashcat.Speed) != 0 {
|
||||
str1 := strings.Split(hashcat.Speed, "@")
|
||||
result.Speed = str1[0]
|
||||
}
|
||||
if len(hashcat.CrackProgress) != 0 {
|
||||
str1 := strings.Split(hashcat.CrackProgress, "/")
|
||||
result.Current = str1[0]
|
||||
str2 := strings.Split(str1[1], " (")
|
||||
result.Total = str2[0]
|
||||
str3 := strings.Split(str2[1], "%")
|
||||
result.Progress = str3[0]
|
||||
}
|
||||
return &result, nil
|
||||
}
|
|
@ -517,6 +517,17 @@ type NodeAsset struct {
|
|||
ParticipantId int64 `json:"ParticipantId"` // 集群动态信息id
|
||||
}
|
||||
|
||||
type CrackProgressReq struct {
|
||||
CrackTaskId string `form:"crackTaskId"`
|
||||
}
|
||||
|
||||
type CrackProgressResp struct {
|
||||
Progress string `json:"progress"`
|
||||
Current string `json:"current"`
|
||||
Total string `json:"total"`
|
||||
Speed string `json:"speed"`
|
||||
}
|
||||
|
||||
type SaveHashcatReq struct {
|
||||
CrackTaskId string `json:"crackTaskId"` // 任务id
|
||||
CrackContainerId string `json:"crackContainerId"` // 容器id
|
||||
|
|
Loading…
Reference in New Issue