mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
🚸 release: v0.2.1
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -50,6 +51,9 @@ var (
|
||||
ctx = context.Background()
|
||||
delayWhenError = time.Second * 10
|
||||
updateCh = make(chan struct{}, 0)
|
||||
httpClient = &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}}
|
||||
)
|
||||
|
||||
func doSelfUpdate() {
|
||||
@@ -151,6 +155,7 @@ func run(cmd *cobra.Command, args []string) {
|
||||
func receiveTasks(tasks pb.NezhaService_RequestTaskClient) error {
|
||||
var err error
|
||||
var task *pb.Task
|
||||
|
||||
defer log.Printf("receiveTasks exit %v %v => %v", time.Now(), task, err)
|
||||
for {
|
||||
task, err = tasks.Recv()
|
||||
@@ -159,30 +164,31 @@ func receiveTasks(tasks pb.NezhaService_RequestTaskClient) error {
|
||||
}
|
||||
var result pb.TaskResult
|
||||
result.Id = task.GetId()
|
||||
result.Type = task.GetType()
|
||||
switch task.GetType() {
|
||||
case model.MonitorTypeHTTPGET:
|
||||
start := time.Now()
|
||||
resp, err := http.Get(task.GetData())
|
||||
resp, err := httpClient.Get(task.GetData())
|
||||
if err == nil {
|
||||
result.Delay = float32(time.Now().Sub(start).Microseconds()) / 1000.0
|
||||
if resp.StatusCode > 299 || resp.StatusCode < 200 {
|
||||
err = errors.New("\n应用错误:" + resp.Status)
|
||||
}
|
||||
}
|
||||
var certs cert.Certs
|
||||
if err == nil {
|
||||
if strings.HasPrefix(task.GetData(), "https://") {
|
||||
certs, err = cert.NewCerts([]string{task.GetData()})
|
||||
c := cert.NewCert(task.GetData()[8:])
|
||||
if c.Error != "" {
|
||||
if strings.Contains(c.Error, "expired") {
|
||||
result.Data = "SSL证书错误:证书已过期"
|
||||
} else {
|
||||
result.Data = "SSL证书错误:" + c.Error
|
||||
}
|
||||
} else {
|
||||
result.Data = c.Issuer + "|" + c.NotAfter
|
||||
result.Successful = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if len(certs) == 0 {
|
||||
err = errors.New("\n获取SSL证书错误:未获取到证书")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
result.Data = certs[0].Issuer
|
||||
result.Successful = true
|
||||
} else {
|
||||
result.Data = err.Error()
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ func ServeWeb(port uint) {
|
||||
"ts": func(s string) string {
|
||||
return strings.TrimSpace(s)
|
||||
},
|
||||
"float32f": func(f float32) string {
|
||||
return fmt.Sprintf("%.2f", f)
|
||||
},
|
||||
"divU64": func(a, b uint64) float32 {
|
||||
if b == 0 {
|
||||
if a > 0 {
|
||||
@@ -49,6 +52,10 @@ func ServeWeb(port uint) {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
if a == 0 {
|
||||
// 这是从未在线的情况
|
||||
return 1 / float32(b) * 100
|
||||
}
|
||||
return float32(a) / float32(b) * 100
|
||||
},
|
||||
"div": func(a, b int) float32 {
|
||||
@@ -58,6 +65,10 @@ func ServeWeb(port uint) {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
if a == 0 {
|
||||
// 这是从未在线的情况
|
||||
return 1 / float32(b) * 100
|
||||
}
|
||||
return float32(a) / float32(b) * 100
|
||||
},
|
||||
"addU64": func(a, b uint64) uint64 {
|
||||
|
||||
@@ -2,7 +2,6 @@ package rpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -47,9 +46,7 @@ func DispatchTask(duration time.Duration) {
|
||||
continue
|
||||
}
|
||||
hasAliveAgent = true
|
||||
log.Println("DispatchTask 确认派发 >>>>>", i, index)
|
||||
dao.SortedServerList[index].TaskStream.Send(tasks[i].PB())
|
||||
log.Println("DispatchTask 确认派发 <<<<<", i, index)
|
||||
index++
|
||||
}
|
||||
dao.ServerLock.RUnlock()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
@@ -13,11 +15,23 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 跳过 SSL 检查
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
httpClient := &http.Client{Transport: transCfg}
|
||||
_, err := httpClient.Get("https://expired-ecc-dv.ssl.com")
|
||||
fmt.Println(err)
|
||||
// SSL 证书信息获取
|
||||
c := cert.NewCert("expired-ecc-dv.ssl.com")
|
||||
fmt.Println(c.Error)
|
||||
// TCP
|
||||
conn, err := net.DialTimeout("tcp", "example.com:80", time.Second*10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(conn)
|
||||
// ICMP Ping
|
||||
pinger, err := ping.NewPinger("example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -28,11 +42,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%+v", pinger.Statistics())
|
||||
certs, err := cert.NewCerts([]string{"example.com"})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(certs)
|
||||
// 硬盘信息
|
||||
dparts, _ := disk.Partitions(false)
|
||||
for _, part := range dparts {
|
||||
u, _ := disk.Usage(part.Mountpoint)
|
||||
|
||||
Reference in New Issue
Block a user