增加恢复模式

This commit is contained in:
GoEdgeLab
2021-07-20 17:15:17 +08:00
parent 320b325496
commit 064bf2016b
34 changed files with 948 additions and 285 deletions

View File

@@ -3,8 +3,7 @@ package setup
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"net"
"regexp"
"sort"
"strings"
)
type IndexAction struct {
@@ -16,31 +15,18 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
// 当前服务器的IP
serverIPs := []string{}
addrs, _ := net.InterfaceAddrs()
for _, addr := range addrs {
netAddr, ok := addr.(*net.IPNet)
if !ok {
continue
var currentHost = this.Request.Host
if strings.Contains(this.Request.Host, ":") {
host, _, err := net.SplitHostPort(this.Request.Host)
if err == nil {
currentHost = host
}
serverIPs = append(serverIPs, netAddr.IP.String())
}
// 对IP进行排序我们希望IPv4排在前面而且希望127.0.0.1排在IPv4里的最后
sort.Slice(serverIPs, func(i, j int) bool {
ip1 := serverIPs[i]
if ip1 == "127.0.0.1" {
return false
}
if regexp.MustCompile(`^\d+\.\d+\.\d+.\d+$`).MatchString(ip1) {
return true
}
return false
})
this.Data["serverIPs"] = serverIPs
if net.ParseIP(currentHost) != nil {
this.Data["currentHost"] = currentHost
} else {
this.Data["currentHost"] = ""
}
this.Show()
}