Skip to content

Commit

Permalink
支持 Mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjinhub committed Sep 2, 2019
1 parent fbd9922 commit 16d08e8
Show file tree
Hide file tree
Showing 21 changed files with 961 additions and 876 deletions.
18 changes: 9 additions & 9 deletions admin/colony.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,55 +131,55 @@ <h4 class="page-title">分布式集群</h4>
_h += ' <td class="td agent_name"><span class="openx"></span>' + data[i].agent_name + '</td>';
_h += ' <td class="td"><span>' + data[i].agent_ip + '</span></td>';

if (data[i].plug_status == "1") {
if (data[i].plug_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>';
}

if (data[i].web_status == "1") {
if (data[i].web_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>';
}

if (data[i].dart_status == "1") {
if (data[i].dart_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>';
}

if (data[i].ssh_status == "1" || data[i].ssh_status == "2") {
if (data[i].ssh_status == 1 || data[i].ssh_status == 2) {
_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>';
}

if (data[i].redis_status == "1") {
if (data[i].redis_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>';
}

if (data[i].mysql_status == "1") {
if (data[i].mysql_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>';
}

if (data[i].telnet_status == "1") {
if (data[i].telnet_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>';
}

if (data[i].ftp_status == "1") {
if (data[i].ftp_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>';
}

if (data[i].mem_cache_status == "1") {
if (data[i].mem_cache_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/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ <h2 class="m-b-10"><span data-plugin="counterup">{{.deepSum}}</span></h2>
url: "/get/dashboard/pie_data",
dataType: "json",
success: function (e) {
var d = e;
var d = e.data;

console.log(d);

Expand Down
7 changes: 3 additions & 4 deletions admin/fish.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ <h6 class="modal-title" id="myModalLabel">上钩信息</h6>
url: "/get/fish/typeList",
dataType: "json",
success: function (e) {
var data = e.resultInfoType;
var data = e.data.resultInfoType;
var _h = '<option value="all">请选择类型</option>';

for (var i = 0; i < data.length; i++) {
Expand All @@ -287,12 +287,11 @@ <h6 class="modal-title" id="myModalLabel">上钩信息</h6>

$("#selectType").html(_h);

var data1 = e.resultColonyName;
var data1 = e.data.resultColonyName;
var _h1 = '<option value="all">请选择集群</option>';
_h1 += '<option value="本机">本机</option>';

for (var i = 0; i < data1.length; i++) {
_h1 += '<option value="' + data1[i].agent_name + '">' + data1[i].agent_name + '</option>';
_h1 += '<option value="' + data1[i].agent + '">' + data1[i].agent + '</option>';
}
$("#selectColony").html(_h1);
},
Expand Down
1 change: 1 addition & 0 deletions admin/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
color: #ff5d48 !important;
margin-right: 5px;
}

.yes_config {
border: 1px solid #0f8ce6;
padding: 2px 5px;
Expand Down
10 changes: 9 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ name = Server # 状态1 服务端 名称 状态2
addr = 127.0.0.1:9001 # 管理后台启动地址
account = admin # 登录账号
password = admin # 登录密码
db_type = mysql # 1 sqlite 2 mysql
db_max_open = 5 # 最大连接池,0 表示无限制

# sqlite or mysql 连接字符串
# sqlite : ./db/hfish.db?cache=shared&mode=rwc
# mysql : 账号:密码@tcp(地址:端口)/数据库名?charset=utf8&parseTime=true
db_str = xxxx


[api]
status = 1 # 是否启动 API 0 关闭 1 启动
Expand Down Expand Up @@ -49,7 +57,7 @@ addr = 0.0.0.0:3306 # Mysql 服务端地址 注意端
files = /etc/passwd,/etc/group # Mysql 服务端读取客户端任意文件; 多写逗号分隔,会随机取

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

[ftp]
Expand Down
108 changes: 108 additions & 0 deletions core/alert/alert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package alert

import (
"HFish/utils/try"
"HFish/core/dbUtil"
"strconv"
"strings"
"HFish/utils/send"
"bytes"
"net/http"
"HFish/utils/log"
"encoding/json"
)

func AlertMail(model string, typex string, agent string, ipx string, country string, region string, city string, infox string) {
// 判断邮件通知
try.Try(func() {
// 只有新加入才会发送邮件通知
if (model == "new") {
result, err := dbUtil.DB().Table("hfish_setting").Fields("status", "info").Where("type", "=", "alertMail").First()

if err != nil {
log.Pr("HFish", "127.0.0.1", "获取邮件告警配置失败", err)
}

status := strconv.FormatInt(result["status"].(int64), 10)

// 判断是否启用通知
if status == "1" {
info := result["info"]
config := strings.Split(info.(string), "&&")

if (country == "本地地址") {
region = ""
city = ""
} else if (country == "局域网") {
region = ""
city = ""
}

text := `
<div><b>Hi,上钩了!</b></div>
<div><b><br /></b></div>
<div><b>集群名称:</b>` + agent + `</div>
<div><b>攻击IP:</b>` + ipx + `</div>
<div><b>地理信息:</b>` + country + ` ` + region + ` ` + city + `</div>
<div><b>上钩内容:</b>` + infox + `</div>
<div><br /></div>
<div><span style="color: rgb(128, 128, 128); font-size: 10px;">(HFish 自动发送)</span></div>
`

send.SendMail(config[4:], "[HFish]提醒你,"+typex+"有鱼上钩!", text, config)
}
}
}).Catch(func() {
})
}

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()

if err != nil {
log.Pr("HFish", "127.0.0.1", "获取WebHook配置失败", err)
}

status := strconv.FormatInt(result["status"].(int64), 10)

// 判断是否启用通知
if status == "1" {
info := result["info"]

song := make(map[string]interface{})
song["id"] = id
song["model"] = model
song["project"] = projectName
song["type"] = typex
song["agent"] = agent
song["ip"] = ipx
song["country"] = country
song["region"] = region
song["city"] = city
song["info"] = infox
song["time"] = time

bytesData, _ := json.Marshal(song)

reader := bytes.NewReader(bytesData)

request, _ := http.NewRequest("POST", info.(string), reader)
request.Header.Set("Content-Type", "application/json;charset=UTF-8")

client := http.Client{}
resp, err := client.Do(request)

if err != nil {
log.Pr("HFish", "127.0.0.1", "WebHook 调用失败", err)
} else {
log.Pr("HFish", "127.0.0.1", "WebHook 调用成功")
}

defer resp.Body.Close()
//defer request.Body.Close()
}
}).Catch(func() {
})
}
Loading

0 comments on commit 16d08e8

Please sign in to comment.