Skip to content

Commit

Permalink
更新0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjinhub committed Sep 15, 2019
1 parent 0980a01 commit 30b3a81
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 77 deletions.
10 changes: 7 additions & 3 deletions admin/fish.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ <h6 class="modal-title" id="myModalLabel">上钩信息</h6>
_h += ' <td class="td"><span class="ipinfo">本机地址</span></td>';
} else if (data.result[i].country == "局域网") {
_h += ' <td class="td"><span class="ipinfo">局域网</span></td>';
}
else {
_h += ' <td class="td"><span class="ipinfo">' + data.result[i].country + ' ' + data.result[i].region + ' ' + data.result[i].city + '</span></td>';
} else {
if (data.result[i].country == "中国") {
_h += ' <td class="td"><span class="ipinfo">' + data.result[i].country + ' ' + data.result[i].region + ' ' + data.result[i].city + '</span></td>';
} else {
// 国外IP只能拿到国家
_h += ' <td class="td"><span class="ipinfo">' + data.result[i].country + '</span></td>';
}
}

_h += ' <td><span class="info" onclick="show(' + data.result[i].id + ')">点击查看</span></td>';
Expand Down
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = Server # 状态1 服务端 名称 状

[admin] # RPC 状态为2 集群客户端的时候 admin 可以删掉
addr = 0.0.0.0:9001 # 管理后台启动地址
account = admin # 登录账号
password = admin # 登录密码
account = admin # 登录账号,不能带 #
password = admin # 登录密码,不能带 #
db_type = sqlite # sqlite or mysql
db_max_open = 50 # 最大连接池,0 表示无限制
db_max_idle = 50 # 最大空闲数,0 表示无限制
Expand Down
11 changes: 2 additions & 9 deletions core/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"HFish/view/data"
"github.com/gin-gonic/gin"
"HFish/error"
"sync"
)

func AlertMail(model string, typex string, agent string, ipx string, country string, region string, city string, infox string, wg *sync.WaitGroup) {
func AlertMail(model string, typex string, agent string, ipx string, country string, region string, city string, infox string) {
// 判断邮件通知
try.Try(func() {
// 只有新加入才会发送邮件通知
Expand Down Expand Up @@ -56,14 +55,11 @@ func AlertMail(model string, typex string, agent string, ipx string, country str
send.SendMail(config[4:], "[HFish]提醒你,"+typex+"有鱼上钩!", text, config)
}
}

wg.Done()
}).Catch(func() {
wg.Done()
})
}

func AlertWebHook(id string, model string, typex string, projectName string, agent string, ipx string, country string, region string, city string, infox string, time string, wg *sync.WaitGroup) {
func AlertWebHook(id string, model string, typex string, projectName string, agent string, ipx string, country string, region string, city string, infox string, time string) {
// 判断 WebHook 通知
try.Try(func() {
result, err := dbUtil.DB().Table("hfish_setting").Fields("status", "info").Where("type", "=", "webHook").First()
Expand Down Expand Up @@ -110,10 +106,7 @@ func AlertWebHook(id string, model string, typex string, projectName string, age
defer resp.Body.Close()
//defer request.Body.Close()
}

wg.Done()
}).Catch(func() {
wg.Done()
})
}

Expand Down
15 changes: 2 additions & 13 deletions core/protocol/ftp/graval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"HFish/core/report"
"HFish/utils/is"
"HFish/core/rpc/client"
"sync"
"github.com/panjf2000/ants"
"HFish/core/pool"
)

Expand Down Expand Up @@ -332,19 +330,10 @@ func (cmd commandPass) RequireAuth() bool {
return false
}

// 加入线程池

var (
wg sync.WaitGroup
poolX *ants.Pool
)

func init() {
wg, poolX = pool.New(10)
func (cmd commandPass) Execute(conn *ftpConn, param string) {
wg, poolX := pool.New(10)
defer poolX.Release()
}

func (cmd commandPass) Execute(conn *ftpConn, param string) {
wg.Add(1)
poolX.Submit(func() {

Expand Down
54 changes: 13 additions & 41 deletions core/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"HFish/core/alert"
"HFish/utils/conf"
"HFish/core/pool"
"sync"
"github.com/panjf2000/ants"
)

type HFishInfo struct {
Expand All @@ -29,37 +27,16 @@ type HFishInfo struct {
time string
}

var (
wg sync.WaitGroup
poolX *ants.Pool

wgUpdate sync.WaitGroup
poolUpdateX *ants.Pool
)

func init() {
wg, poolX = pool.New(10)
defer poolX.Release()

wgUpdate, poolUpdateX = pool.New(10)
defer poolUpdateX.Release()
}

// 通知模块
func alertx(id string, model string, typex string, projectName string, agent string, ipx string, country string, region string, city string, infox string, timex string) {
wg.Add(1)
poolX.Submit(func() {
time.Sleep(time.Second * 2)

// 邮件通知
alert.AlertMail(model, typex, agent, ipx, country, region, city, infox, &wg)
// 邮件通知
alert.AlertMail(model, typex, agent, ipx, country, region, city, infox)

// WebHook
alert.AlertWebHook(id, model, typex, projectName, agent, ipx, country, region, city, infox, timex, &wg)
// WebHook
alert.AlertWebHook(id, model, typex, projectName, agent, ipx, country, region, city, infox, timex)

// 大数据展示
//alert.AlertDataWs(model, typex, projectName, agent, ipx, country, region, city, time)
})
// 大数据展示
//alert.AlertDataWs(model, typex, projectName, agent, ipx, country, region, city, time)
}

// 上报 集群 状态
Expand Down Expand Up @@ -159,8 +136,6 @@ func insertInfo(typex string, projectName string, agent string, ipx string, coun

// 更新
func updateInfoCore(id string, info string) {
time.Sleep(time.Second * 2)

try.Try(func() {
var sql string

Expand Down Expand Up @@ -188,18 +163,21 @@ func updateInfoCore(id string, info string) {
if err != nil {
log.Pr("HFish", "127.0.0.1", "更新上钩信息失败", err)
}

wgUpdate.Done()
}).Catch(func() {
wgUpdate.Done()
})
}

// 通用的更新
func updateInfo(id string, info string) {
wgUpdate, poolUpdateX := pool.New(10)

defer poolUpdateX.Release()

wgUpdate.Add(1)
poolUpdateX.Submit(func() {
updateInfoCore(id, info)
time.Sleep(time.Second * 2)
go updateInfoCore(id, info)
wgUpdate.Done()
})
}

Expand Down Expand Up @@ -253,12 +231,6 @@ func ReportSSH(ipx string, agent string, info string) int64 {

// 更新 SSH 操作
func ReportUpdateSSH(id string, info string) {
defer func() {
if err := recover(); err != nil {
log.Pr("HFish", "127.0.0.1", "执行SSH更新失败", err)
}
}()

if (id != "0") {
go updateInfo(id, info)
go alertx(id, "update", "SSH", "SSH蜜罐", "", "", "", "", "", info, time.Now().Format("2006-01-02 15:04:05"))
Expand Down
Binary file modified db/hfish.db
Binary file not shown.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func main() {
setting.Run()
args := os.Args
if args == nil || len(args) < 2 {
setting.Help()
Expand Down
9 changes: 0 additions & 9 deletions static/css/style.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
@charset "UTF-8";
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700,300");
/*!
* Bootstrap v4.0.0-alpha.2 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700,300");
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700,300");

html {
font-family: sans-serif;
Expand Down

0 comments on commit 30b3a81

Please sign in to comment.