Skip to content

Commit

Permalink
支持 Mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjinhub committed Sep 8, 2019
1 parent 56cc2e1 commit 5062db1
Show file tree
Hide file tree
Showing 22 changed files with 456 additions and 181 deletions.
4 changes: 2 additions & 2 deletions admin/colony.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h4 class="page-title">分布式集群</h4>
for (var i = 0; i < data.length; i++) {
_h += '<tr>';

var last_update_time = data[i].last_update_time.replace("T", " ").replace("+08:00", " ");
var last_update_time = data[i].last_update_time.replace("T", " ").replace("+08:00", "").replace("Z", "");
last_update_time = last_update_time.substring(0, 19);
last_update_time = last_update_time.replace(/-/g, '/');
var timestamp = new Date(last_update_time).getTime();
Expand All @@ -143,7 +143,7 @@ <h4 class="page-title">分布式集群</h4>
_h += ' <td class="td" style="text-align: center;"><span class="closex"></span></td>';
}

if (data[i].dart_status == 1) {
if (data[i].deep_status == 1) {
_h += ' <td class="td" style="text-align: center;"><span class="openx"></span></td>';
} else {
_h += ' <td class="td" style="text-align: center;"><span class="closex"></span></td>';
Expand Down
2 changes: 1 addition & 1 deletion admin/fish.html
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ <h6 class="modal-title" id="myModalLabel">上钩信息</h6>

_h += ' <td><span class="info" onclick="show(' + data.result[i].id + ')">点击查看</span></td>';
_h += ' <td class="td"><span class="cinfo">' + data.result[i].info.length + '</span></td>';
_h += ' <td class="td">' + data.result[i].create_time.replace("T", " ").replace("+08:00", " ") + '</td>';
_h += ' <td class="td">' + data.result[i].create_time.replace("T", " ").replace("+08:00", " ").replace("Z", "") + '</td>';
_h += '</tr>';
}

Expand Down
2 changes: 1 addition & 1 deletion admin/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h4 class="page-title">系统设置</h4>
<tr id="tr{{$e.type}}" data-id="{{$e.id}}">
<td style="font-weight: bold;">{{$e.setting_name}} </td>
<td>{{$e.setting_dis}}</td>
<td id="trx{{$e.type}}"><script>var t={{$e.update_time}}; document.getElementById("trx{{$e.type}}").innerHTML= t.replace("T", " ").replace("+08:00", " ");</script></td>
<td id="trx{{$e.type}}"><script>var t={{$e.update_time}}; document.getElementById("trx{{$e.type}}").innerHTML= t.replace("T", " ").replace("+08:00", " ").replace("Z", "");</script></td>
<td>{{if ne $e.info ""}}
<span class="yes_config">已配置</span>
{{else}}
Expand Down
9 changes: 5 additions & 4 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[rpc]
status = 1 # 模式 0关闭 1服务端 2客户端
status = 0 # 模式 0关闭 1服务端 2客户端
addr = 0.0.0.0:7879 # RPC 服务端地址 or 客户端地址
name = Server # 状态1 服务端 名称 状态2 客户端 名称

[admin] # RPC 状态为2 集群客户端的时候 admin 可以删掉
addr = 0.0.0.0:9001 # 管理后台启动地址
account = admin # 登录账号
password = admin # 登录密码
db_type = sqlite # 1 sqlite 2 mysql
db_max_open = 5 # 最大连接池,0 表示无限制
db_type = sqlite # sqlite or mysql
db_max_open = 50 # 最大连接池,0 表示无限制
db_max_idle = 50 # 最大空闲数,0 表示无限制
db_str = ./db/hfish.db?cache=shared&mode=rwc # sqlite or mysql 连接字符串
# sqlite : ./db/hfish.db?cache=shared&mode=rwc
# mysql : 账号:密码@tcp(地址:端口)/数据库名?charset=utf8&parseTime=true&loc=Local
Expand Down Expand Up @@ -54,7 +55,7 @@ addr = 0.0.0.0:3306 # Mysql 服务端地址 注意
files = /etc/passwd,/etc/group # Mysql 服务端读取客户端任意文件; 多写逗号分隔,会随机取

[telnet]
status = 0 # 是否启动 Telnet 0 关闭 1 启动
status = 1 # 是否启动 Telnet 0 关闭 1 启动
addr = 0.0.0.0:23 # Telnet 服务端地址 注意端口冲突

[ftp]
Expand Down
11 changes: 9 additions & 2 deletions core/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ 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) {
func AlertMail(model string, typex string, agent string, ipx string, country string, region string, city string, infox string, wg *sync.WaitGroup) {
// 判断邮件通知
try.Try(func() {
// 只有新加入才会发送邮件通知
Expand Down Expand Up @@ -55,11 +56,14 @@ 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) {
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) {
// 判断 WebHook 通知
try.Try(func() {
result, err := dbUtil.DB().Table("hfish_setting").Fields("status", "info").Where("type", "=", "webHook").First()
Expand Down Expand Up @@ -106,7 +110,10 @@ 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
7 changes: 4 additions & 3 deletions core/dbUtil/dbUtil.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dbUtil

import (
"github.com/gohouse/gorose"
_ "github.com/go-sql-driver/mysql"
_ "github.com/mattn/go-sqlite3"
"HFish/utils/conf"
"HFish/utils/log"
"github.com/gohouse/gorose"
)

var engin *gorose.Engin
Expand All @@ -16,15 +16,16 @@ func init() {
dbType := conf.Get("admin", "db_type")
dbStr := conf.Get("admin", "db_str")
dbMaxOpen := conf.GetInt("admin", "db_max_open")
dbMaxIdle := conf.GetInt("admin", "db_max_idle")

if dbType == "sqlite" {
engin, err = gorose.Open(&gorose.Config{Driver: "sqlite3", Dsn: dbStr, SetMaxOpenConns: dbMaxOpen})
engin, err = gorose.Open(&gorose.Config{Driver: "sqlite3", Dsn: dbStr, SetMaxOpenConns: dbMaxOpen, SetMaxIdleConns: dbMaxIdle})

if err != nil {
log.Pr("HFish", "127.0.0.1", "连接 Sqlite 数据库失败", err)
}
} else if dbType == "mysql" {
engin, err = gorose.Open(&gorose.Config{Driver: "mysql", Dsn: dbStr, SetMaxOpenConns: dbMaxOpen})
engin, err = gorose.Open(&gorose.Config{Driver: "mysql", Dsn: dbStr, SetMaxOpenConns: dbMaxOpen, SetMaxIdleConns: dbMaxIdle})

if err != nil {
log.Pr("HFish", "127.0.0.1", "连接 Mysql 数据库失败", err)
Expand Down
12 changes: 12 additions & 0 deletions core/pool/pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pool

import (
"sync"
"github.com/panjf2000/ants"
)

func New(size int) (sync.WaitGroup, *ants.Pool) {
wg := sync.WaitGroup{}
pool, _ := ants.NewPool(size)
return wg, pool
}
53 changes: 37 additions & 16 deletions core/protocol/ftp/graval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"HFish/core/report"
"HFish/utils/is"
"HFish/core/rpc/client"
"sync"
"github.com/panjf2000/ants"
"HFish/core/pool"
)

type ftpCommand interface {
Expand Down Expand Up @@ -329,24 +332,42 @@ func (cmd commandPass) RequireAuth() bool {
return false
}

func (cmd commandPass) Execute(conn *ftpConn, param string) {
info := conn.reqUser + "&&" + param
arr := strings.Split(conn.conn.RemoteAddr().String(), ":")
// 加入线程池

// 判断是否为 RPC 客户端
if is.Rpc() {
go client.ReportResult("FTP", "", arr[0], info, "0")
} else {
go report.ReportFTP(arr[0], "本机", info)
}
var (
wg sync.WaitGroup
poolX *ants.Pool
)

if conn.driver.Authenticate(conn.reqUser, param) {
conn.user = conn.reqUser
conn.reqUser = ""
conn.writeMessage(230, "Password ok, continue")
} else {
conn.writeMessage(530, "Incorrect password, not logged in")
}
func init() {
wg, poolX = pool.New(10)
defer poolX.Release()
}

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

info := conn.reqUser + "&&" + param
arr := strings.Split(conn.conn.RemoteAddr().String(), ":")

// 判断是否为 RPC 客户端
if is.Rpc() {
go client.ReportResult("FTP", "", arr[0], info, "0")
} else {
go report.ReportFTP(arr[0], "本机", info)
}

if conn.driver.Authenticate(conn.reqUser, param) {
conn.user = conn.reqUser
conn.reqUser = ""
conn.writeMessage(230, "Password ok, continue")
} else {
conn.writeMessage(530, "Incorrect password, not logged in")
}

wg.Done()
})
}

// commandPasv responds to the PASV FTP command.
Expand Down
Loading

0 comments on commit 5062db1

Please sign in to comment.