新增任务类型
This commit is contained in:
parent
7a1c117b59
commit
3a3667649c
@ -6,6 +6,7 @@ import (
|
||||
"go_dreamfactory/cmd/v2/service"
|
||||
"go_dreamfactory/cmd/v2/service/observer"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -14,13 +15,18 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/go-ping/ping"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type portStatus struct {
|
||||
port int
|
||||
err string
|
||||
}
|
||||
type appPing struct {
|
||||
appAdapter
|
||||
resultCh chan int
|
||||
resultCh chan portStatus
|
||||
}
|
||||
|
||||
func (this *appPing) LazyInit(ptService service.PttService, obs observer.Observer) error {
|
||||
@ -33,36 +39,59 @@ func (this *appPing) LazyInit(ptService service.PttService, obs observer.Observe
|
||||
targetHost.PlaceHolder = "目标主机Ip"
|
||||
|
||||
portEntry := widget.NewMultiLineEntry()
|
||||
portEntry.Text = "80,3306,6379"
|
||||
portEntry.Text = "20,21,22,80,1521,2379,2380,3306,6379,8080,8020,8500,9000,9090,13306,50070,27019,10013,8300,8301,8600,10012,10011"
|
||||
form := widget.NewForm(
|
||||
widget.NewFormItem("主机", targetHost),
|
||||
widget.NewFormItem("端口", portEntry),
|
||||
)
|
||||
// result
|
||||
result := widget.NewMultiLineEntry()
|
||||
result.Disable()
|
||||
|
||||
form.OnSubmit = func() {
|
||||
result.Text = ""
|
||||
if portEntry.Text == "" {
|
||||
return
|
||||
}
|
||||
this.resultCh = make(chan int)
|
||||
this.resultCh = make(chan portStatus)
|
||||
ports := strings.Split(portEntry.Text, ",")
|
||||
this.ping(targetHost.Text, ports)
|
||||
|
||||
pinger, err := ping.NewPinger(targetHost.Text)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pinger.Count = 3
|
||||
if runtime.GOOS == "windows" {
|
||||
pinger.SetPrivileged(true)
|
||||
}
|
||||
var msgs []string
|
||||
pinger.OnRecv = func(p *ping.Packet) {
|
||||
msgs = append(msgs, fmt.Sprintf("来自:%s 的回复 字节=%d 时间=%dms TTL=%d",
|
||||
p.IPAddr.String(),
|
||||
p.Nbytes,
|
||||
p.Rtt.Milliseconds(),
|
||||
p.Ttl))
|
||||
result.Text = strings.Join(msgs, "\n")
|
||||
result.Refresh()
|
||||
}
|
||||
|
||||
if err := pinger.Run(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
ip, err := net.ResolveIPAddr("ip", targetHost.Text)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return
|
||||
}
|
||||
this.ping(ip.String(), ports)
|
||||
|
||||
for p := range this.resultCh {
|
||||
for _, v := range ports {
|
||||
if cast.ToInt(v) == p {
|
||||
msgs = append(msgs, fmt.Sprintf("端口:%d OK", p))
|
||||
} else {
|
||||
msgs = append(msgs, fmt.Sprintf("端口:%s ERR", v))
|
||||
}
|
||||
result.Text = strings.Join(msgs, "\n")
|
||||
result.Refresh()
|
||||
}
|
||||
msgs = append(msgs, fmt.Sprintf("端口:%d %s", p.port, p.err))
|
||||
result.Text = strings.Join(msgs, "\n")
|
||||
result.Refresh()
|
||||
}
|
||||
|
||||
}
|
||||
form.Items[1].HintText = "多个端口使用英文,号分隔"
|
||||
|
||||
@ -81,11 +110,14 @@ func (this *appPing) ping(targetHost string, ports []string) {
|
||||
go func(p int) {
|
||||
defer wg.Done()
|
||||
_, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", targetHost, p), time.Millisecond*500)
|
||||
var errStr string
|
||||
if err == nil {
|
||||
this.resultCh <- p
|
||||
errStr = "OK"
|
||||
} else {
|
||||
errStr = "ERR"
|
||||
logrus.Error(err)
|
||||
}
|
||||
this.resultCh <- portStatus{port: p, err: errStr}
|
||||
}(cast.ToInt(port))
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,8 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
|
||||
comm.Rtype54, comm.Rtype57, comm.Rtype58, comm.Rtype60,
|
||||
comm.Rtype62, comm.Rtype64, comm.Rtype69, comm.Rtype72, comm.Rtype88, comm.Rtype104,
|
||||
comm.Rtype96, comm.Rtype105, comm.Rtype128, comm.Rtype130, comm.Rtype131,
|
||||
comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146:
|
||||
comm.Rtype141, comm.Rtype142, comm.Rtype143, comm.Rtype144, comm.Rtype145, comm.Rtype146,
|
||||
comm.Rtype147, comm.Rtype149, comm.Rtype153, comm.Rtype154, comm.Rtype155, comm.Rtype156:
|
||||
this.registerVerifyHandle(v.Id, &rtaskCondi{
|
||||
find: this.modelRtaskRecord.lessEqualFirstParam,
|
||||
verify: this.modelRtaskRecord.verifyFirstGreatEqualParam,
|
||||
@ -343,6 +344,11 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
||||
log.Field{Key: "err", Value: err2.Error()},
|
||||
)
|
||||
}
|
||||
if module, err := this.service.GetModule(comm.ModuleRtask); err == nil {
|
||||
if iRtask,ok:=module.(comm.IRtask);ok{
|
||||
iRtask.SendToRtask(session, comm.Rtype156, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error {
|
||||
globalConf := this.moduleSociaty.globalConf
|
||||
// 大于4条配置
|
||||
if len(taskListConf) > int(globalConf.GuildTaskNum) {
|
||||
// 按照权重
|
||||
//随机4条任务
|
||||
randInts := utils.RandomNumbers(0, len(taskListConf)-1, int(globalConf.GuildTaskNum))
|
||||
for _, v := range randInts {
|
||||
|
Loading…
Reference in New Issue
Block a user