From 985ecc7c65af4ee1eb978bb4fca6c6f2d74530be Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 10 Aug 2021 20:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Linux=20=E4=B8=80=E9=94=AE=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/member_api.go | 2 + cmd/dashboard/main.go | 4 -- resource/static/main.js | 2 - resource/template/common/footer.html | 2 +- resource/template/component/server.html | 15 +++--- resource/template/dashboard/server.html | 23 +++++++- resource/template/dashboard/setting.html | 53 +++++++++--------- script/install.sh | 2 +- util/myip.go | 69 ------------------------ 9 files changed, 62 insertions(+), 110 deletions(-) delete mode 100644 util/myip.go diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 86f6470..23added 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -452,6 +452,7 @@ type settingForm struct { EnableIPChangeNotification string IgnoredIPNotification string Oauth2Type string + GRPCHost string Cover uint8 } @@ -466,6 +467,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) { } dao.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on" dao.Conf.Cover = sf.Cover + dao.Conf.GRPCHost = sf.GRPCHost dao.Conf.IgnoredIPNotification = sf.IgnoredIPNotification dao.Conf.Site.Brand = sf.Title dao.Conf.Site.Theme = sf.Theme diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 3b6026b..16982f0 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "github.com/naiba/nezha/util" "log" "time" @@ -47,9 +46,6 @@ func init() { if dao.Conf.GRPCPort == 0 { dao.Conf.GRPCPort = 5555 } - if dao.Conf.GRPCHost == "" { - dao.Conf.GRPCHost = util.FetchGeoIP(false).IP - } dao.Cache = cache.New(5*time.Minute, 10*time.Minute) initSystem() diff --git a/resource/static/main.js b/resource/static/main.js index f1e2162..f0f81cc 100644 --- a/resource/static/main.js +++ b/resource/static/main.js @@ -174,8 +174,6 @@ function addOrEditServer(server, conf) { modal.find(".secret.field").attr("style", ""); modal.find(".command.field").attr("style", ""); modal.find(".command.hostSecret").text(server.Secret); - modal.find(".command.GRPCHost").text(conf.GRPCHost); - modal.find(".command.GRPCPort").text(conf.GRPCPort); modal.find("input[name=secret]").val(server.Secret); } else { modal.find(".secret.field").attr("style", "display:none"); diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html index 6face13..758e24c 100644 --- a/resource/template/common/footer.html +++ b/resource/template/common/footer.html @@ -9,7 +9,7 @@ - + diff --git a/resource/template/component/server.html b/resource/template/component/server.html index 3748c44..db5ef5e 100644 --- a/resource/template/component/server.html +++ b/resource/template/component/server.html @@ -26,14 +26,15 @@
- +
-
- systemd -
-
- curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh install_agent -
+ {{if .Conf.GRPCHost}} + curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod + +x nezha.sh && sudo ./nezha.sh install_agent {{.Conf.GRPCHost}} {{.Conf.GRPCPort}} + {{else}} + 请先在设置页面配置 未接入CDN的面板服务器域名/IP + {{end}}
diff --git a/resource/template/dashboard/server.html b/resource/template/dashboard/server.html index 902f2e8..ccc88aa 100644 --- a/resource/template/dashboard/server.html +++ b/resource/template/dashboard/server.html @@ -19,6 +19,7 @@ IP 版本号 密钥 + 一键安装 备注 管理 @@ -32,10 +33,24 @@ {{$server.Host.IP}} {{$server.Host.Version}} {{$server.Secret}} + + + + + {{$server.Note}}
-
-{{template "component/server"}} +{{template "component/server" .}} {{template "common/footer" .}} + + {{end}} \ No newline at end of file diff --git a/resource/template/dashboard/setting.html b/resource/template/dashboard/setting.html index f4f99a0..4846f68 100644 --- a/resource/template/dashboard/setting.html +++ b/resource/template/dashboard/setting.html @@ -40,6 +40,10 @@ +
+ + +
@@ -70,40 +74,41 @@ {{template "common/footer" .}} -{{end}} +{{end}} \ No newline at end of file diff --git a/script/install.sh b/script/install.sh index 3788a4c..99ef5ce 100755 --- a/script/install.sh +++ b/script/install.sh @@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha" NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard" NZ_AGENT_PATH="${NZ_BASE_PATH}/agent" NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service" -NZ_VERSION="v0.6.5" +NZ_VERSION="v0.6.6" red='\033[0;31m' green='\033[0;32m' diff --git a/util/myip.go b/util/myip.go deleted file mode 100644 index 6653735..0000000 --- a/util/myip.go +++ /dev/null @@ -1,69 +0,0 @@ -package util - -import ( - "encoding/json" - "io/ioutil" - "net/http" - "strings" - "time" - - "github.com/naiba/nezha/pkg/utils" -) - -type geoIP struct { - CountryCode string `json:"country_code,omitempty"` - IP string `json:"ip,omitempty"` - Query string `json:"query,omitempty"` -} - -var ( - geoIPApiList = []string{ - "https://api.ip.sb/geoip", - "https://ip.seeip.org/geoip", - "https://ipapi.co/json", - "https://freegeoip.app/json/", - "http://ip-api.com/json/", - "https://extreme-ip-lookup.com/json/", - } - cachedIP, cachedCountry string - httpClientV4 = utils.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false) - httpClientV6 = utils.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true) -) - -func FetchGeoIP(isV6 bool) geoIP { - servers := geoIPApiList - var ip geoIP - var resp *http.Response - var err error - for i := 0; i < len(servers); i++ { - if isV6 { - resp, err = httpClientV6.Get(servers[i]) - } else { - resp, err = httpClientV4.Get(servers[i]) - } - if err == nil { - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - continue - } - resp.Body.Close() - err = json.Unmarshal(body, &ip) - if err != nil { - continue - } - if ip.IP == "" && ip.Query != "" { - ip.IP = ip.Query - } - // 没取到 v6 IP - if isV6 && !strings.Contains(ip.IP, ":") { - continue - } - // 没取到 v4 IP - if !isV6 && !strings.Contains(ip.IP, ".") { - continue - } - return ip - } - } - return ip -}