Former-commit-id: 5cccf59c08
v0.1.0-xjlab-alpha1
| @@ -565,14 +565,25 @@ type NodeAsset { | |||||
| ParticipantId int64 `json:"ParticipantId"` // 集群动态信息id | 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 { | 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"` // 开始时间 | Started string `json:"started,optional"` // 开始时间 | ||||
| Stopped string `json:"stopped,optional"` // 结束时间 | Stopped string `json:"stopped,optional"` // 结束时间 | ||||
| KernelFeature string `json:"kernelFeature"` | KernelFeature string `json:"kernelFeature"` | ||||
| @@ -117,6 +117,10 @@ service pcm { | |||||
| @handler tasksNumHandler | @handler tasksNumHandler | ||||
| get /core/tasks/num (tasksNumReq) returns (tasksNumResp) | get /core/tasks/num (tasksNumReq) returns (tasksNumResp) | ||||
| @doc "Hashcat Crack Progress" | |||||
| @handler crackProgressHandler | |||||
| get /core/crack/progress (crackProgressReq) returns (crackProgressResp) | |||||
| @doc "Resource Center Information" | @doc "Resource Center Information" | ||||
| @handler resourceCenterInfoHandler | @handler resourceCenterInfoHandler | ||||
| get /core/center/resource/:participantId (resourceCenterInfoReq) returns (resourceCenterInfoResp) | 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", | Path: "/core/tasks/num", | ||||
| Handler: core.TasksNumHandler(serverCtx), | Handler: core.TasksNumHandler(serverCtx), | ||||
| }, | }, | ||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/core/crack/progress", | |||||
| Handler: core.CrackProgressHandler(serverCtx), | |||||
| }, | |||||
| { | { | ||||
| Method: http.MethodGet, | Method: http.MethodGet, | ||||
| Path: "/core/center/resource/:participantId", | 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 | 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 { | type SaveHashcatReq struct { | ||||
| CrackTaskId string `json:"crackTaskId"` // 任务id | CrackTaskId string `json:"crackTaskId"` // 任务id | ||||
| CrackContainerId string `json:"crackContainerId"` // 容器id | CrackContainerId string `json:"crackContainerId"` // 容器id | ||||