From 756b51e6da1dde92e34bd76d224f1636949660f9 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Sun, 21 Jul 2024 21:10:56 +0800 Subject: [PATCH 1/7] update readme --- README.md | 2 +- README_zh_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01aac49..9b282f3 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Please note, there are exceptions to this synchronization. If a version of NTrac * Scoop-extra is maintained by soenggam - Please note, the repositories for all of the above installation methods are maintained by open source enthusiasts. Availability and timely updates are not guaranteed. If you encounter problems, please contact the repository maintainer to solve them, or use the binary packages provided by the official build of this project. +Please note, the repositories for all of the above installation methods are maintained by open source enthusiasts. Availability and timely updates are not guaranteed. If you encounter problems, please contact the repository maintainer to solve them, or use the binary packages provided by the official build of this project. ### Manual Install * Download the precompiled executable diff --git a/README_zh_CN.md b/README_zh_CN.md index 3598ffa..6b27769 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -120,7 +120,7 @@ Document Language: [English](README.md) | 简体中文 * scoop-extra 由 soenggam 维护 - 请注意,以上多种安装方式的仓库均由开源爱好者自行维护,不保证可用性和及时更新,如遇到问题请联系仓库维护者解决,或使用本项目官方编译提供的二进制包。 +请注意,以上多种安装方式的仓库均由开源爱好者自行维护,不保证可用性和及时更新,如遇到问题请联系仓库维护者解决,或使用本项目官方编译提供的二进制包。 ### Manual Install * 下载预编译的可执行程序 From 636974585913452c412f9c394496e6ad087d2a24 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:38:45 +0000 Subject: [PATCH 2/7] chore(deps): bump golang.org/x/sync from 0.7.0 to 0.8.0 Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.7.0 to 0.8.0. - [Commits](https://github.com/golang/sync/compare/v0.7.0...v0.8.0) --- updated-dependencies: - dependency-name: golang.org/x/sync dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1418874..9612eba 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 github.com/tsosunchia/powclient v0.1.5 golang.org/x/net v0.27.0 - golang.org/x/sync v0.7.0 + golang.org/x/sync v0.8.0 ) require ( diff --git a/go.sum b/go.sum index 3033fc4..c3964e0 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 913a4f99b34e4a0fde9d2c967806153b448e568e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:38:48 +0000 Subject: [PATCH 3/7] chore(deps): bump github.com/rodaine/table from 1.2.0 to 1.3.0 Bumps [github.com/rodaine/table](https://github.com/rodaine/table) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/rodaine/table/releases) - [Commits](https://github.com/rodaine/table/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/rodaine/table dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1418874..44304e8 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/fatih/color v1.17.0 github.com/gorilla/websocket v1.5.2 github.com/lionsoul2014/ip2region v2.11.2+incompatible - github.com/rodaine/table v1.2.0 + github.com/rodaine/table v1.3.0 github.com/tidwall/gjson v1.17.1 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect diff --git a/go.sum b/go.sum index 3033fc4..f2bf043 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE= @@ -44,8 +44,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rodaine/table v1.2.0 h1:38HEnwK4mKSHQJIkavVj+bst1TEY7j9zhLMWu4QJrMA= -github.com/rodaine/table v1.2.0/go.mod h1:wejb/q/Yd4T/SVmBSRMr7GCq3KlcZp3gyNYdLSBhkaE= +github.com/rodaine/table v1.3.0 h1:4/3S3SVkHnVZX91EHFvAMV7K42AnJ0XuymRR2C5HlGE= +github.com/rodaine/table v1.3.0/go.mod h1:47zRsHar4zw0jgxGxL9YtFfs7EGN6B/TaS+/Dmk4WxU= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk= From b70db0883c859f452eceddc736a2dc35699a4e00 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:38:50 +0000 Subject: [PATCH 4/7] chore(deps): bump github.com/tidwall/gjson from 1.17.1 to 1.17.3 Bumps [github.com/tidwall/gjson](https://github.com/tidwall/gjson) from 1.17.1 to 1.17.3. - [Commits](https://github.com/tidwall/gjson/compare/v1.17.1...v1.17.3) --- updated-dependencies: - dependency-name: github.com/tidwall/gjson dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1418874..d8df590 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/gorilla/websocket v1.5.2 github.com/lionsoul2014/ip2region v2.11.2+incompatible github.com/rodaine/table v1.2.0 - github.com/tidwall/gjson v1.17.1 + github.com/tidwall/gjson v1.17.3 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect golang.org/x/sys v0.22.0 // indirect diff --git a/go.sum b/go.sum index 3033fc4..6cac297 100644 --- a/go.sum +++ b/go.sum @@ -75,8 +75,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= -github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94= +github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= From 7fa5181062ebd5ca7019b4fd65041f89c8ea5b5f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:38:23 +0000 Subject: [PATCH 5/7] chore(deps): bump golang.org/x/net from 0.27.0 to 0.28.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.27.0 to 0.28.0. - [Commits](https://github.com/golang/net/compare/v0.27.0...v0.28.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b9ea32c..f1b42ac 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.9.0 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 github.com/tsosunchia/powclient v0.1.5 - golang.org/x/net v0.27.0 + golang.org/x/net v0.28.0 golang.org/x/sync v0.8.0 ) @@ -33,7 +33,7 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/text v0.17.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) @@ -45,6 +45,6 @@ require ( github.com/tidwall/gjson v1.17.1 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/sys v0.23.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index cc81c5d..9ffd7de 100644 --- a/go.sum +++ b/go.sum @@ -94,8 +94,8 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= @@ -103,11 +103,11 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From eea77b1f0d2e273aff774b75fc0c6edf8082d25e Mon Sep 17 00:00:00 2001 From: breakertt Date: Thu, 15 Aug 2024 14:26:57 +0100 Subject: [PATCH 6/7] Enhance ipinfoLocal.mmdb file lookup (#66) * Enhance ipinfoLocal.mmdb file lookup * Refactor get NEXTTRACE_IPINFOLOCALPATH env variable into util --- README.md | 6 ++++- README_zh_CN.md | 8 +++++-- ipgeo/ipinfoLocal.go | 55 ++++++++++++++++++++++++++++++++++++++++---- util/util.go | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b282f3..28b0ca0 100644 --- a/README.md +++ b/README.md @@ -269,9 +269,13 @@ export NO_COLOR=1 nexttrace --data-provider ip-api.com ## Note There are frequency limits for free queries of the ipinfo and IPInsight APIs. You can purchase services from these providers to remove the limits ## If necessary, you can clone this project, add the token provided by ipinfo or IPInsight and compile it yourself +## Fill the token to: ipgeo/tokens.go + ## Note For the offline database IPInfoLocal, please download it manually and rename it to ipinfoLocal.mmdb. (You can download it from here: https://ipinfo.io/signup?ref=free-database-downloads) +## Current directory, nexttrace binary directory and FHS directories (Unix-like) will be searched. +## To customize it, please use environment variables, +export NEXTTRACE_IPINFOLOCALPATH=/xxx/yyy.mmdb ## For the offline database Ip2region, you can download it manually and rename it to ip2region.db, or let NextTrace download it automatically -## Fill the token to: ipgeo/tokens.go ## Please be aware: Due to the serious abuse of IP.SB, you will often be not able to query IP data from this source ## IP-API.com has a stricter restiction on API calls, if you can't query IP data from this source, please try again in a few minutes diff --git a/README_zh_CN.md b/README_zh_CN.md index 6b27769..e4f098e 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -282,11 +282,15 @@ export NO_COLOR=1 nexttrace --data-provider ip-api.com ## 特别的: 其中 ipinfo 和 IPInsight API 对于免费版查询有频率限制,可从这些服务商自行购买服务以解除限制,如有需要可以 clone 本项目添加其提供的 token 自行编译 ## TOKEN填写路径:ipgeo/tokens.go -## 特别的: 对于离线库 IPInfoLocal,请自行下载并命名为 ipinfoLocal.mmdb (可以从这里下载:https://ipinfo.io/signup?ref=free-database-downloads) + +## 特别的: 对于离线库 IPInfoLocal,请自行下载并命名为 ipinfoLocal.mmdb +## (可以从这里下载:https://ipinfo.io/signup?ref=free-database-downloads), +## 默认搜索用户当前路径、程序所在路径、和 FHS 路径(Unix-like) +## 如果需要自定义路径,请设置环境变量 +export NEXTTRACE_IPINFOLOCALPATH=/xxx/yyy.mmdb ## 对于离线库 Ip2region 可NextTrace自动下载,也可自行下载并命名为 ip2region.db ## 另外:由于IP.SB被滥用比较严重,会经常出现无法查询的问题,请知悉。 ## IP-API.com限制调用较为严格,如有查询不到的情况,请几分钟后再试。 - # 纯真IP数据库默认使用 http://127.0.0.1:2060 作为查询接口,如需自定义请使用环境变量 export NEXTTRACE_CHUNZHENURL=http://127.0.0.1:2060 ## 可使用 https://github.com/freshcn/qqwry 自行搭建纯真IP数据库服务 diff --git a/ipgeo/ipinfoLocal.go b/ipgeo/ipinfoLocal.go index cb2ed1f..65f415f 100644 --- a/ipgeo/ipinfoLocal.go +++ b/ipgeo/ipinfoLocal.go @@ -2,24 +2,71 @@ package ipgeo import ( "errors" - "github.com/oschwald/maxminddb-golang" "net" "os" + "path/filepath" + "runtime" "strings" "time" + + "github.com/nxtrace/NTrace-core/util" + "github.com/oschwald/maxminddb-golang" ) const ( - ipinfoDataBasePath = "./ipinfoLocal.mmdb" + ipinfoDataBaseFilename = "ipinfoLocal.mmdb" ) +// Cache the path of the ipinfoLocal.mmdb file +var ipinfoDataBasePath = "" + +// We will try to get the path of the ipinfoLocal.mmdb file in the following order: +// 1. Use the value of the environment variable NEXTTRACE_IPINFOLOCALPATH +// 2. Search in the current folder and the executable folder +// 3. Search in /usr/local/share/nexttrace/ and /usr/share/nexttrace/ (for Unix/Linux) +// If the file is found, the path will be stored in the ipinfoDataBasePath variable +func getIPInfoLocalPath() (error) { + if ipinfoDataBasePath != "" { + return nil + } + // NEXTTRACE_IPINFOLOCALPATH + if util.EnvIPInfoLocalPath != "" { + if _, err := os.Stat(util.EnvIPInfoLocalPath); err == nil { + ipinfoDataBasePath = util.EnvIPInfoLocalPath + return nil + } else { + return errors.New("NEXTTRACE_IPINFOLOCALPATH is set but the file does not exist") + } + } + folders := []string{} + // current folder + if cur, err := os.Getwd(); err == nil { + folders = append(folders, cur + string(filepath.Separator)) + } + // exeutable folder + if exe, err := os.Executable(); err == nil { + folders = append(folders, filepath.Dir(exe) + string(filepath.Separator)) + } + if runtime.GOOS != "windows" { + folders = append(folders, "/usr/local/share/nexttrace/") + folders = append(folders, "/usr/share/nexttrace/") + } + for _, folder := range folders { + if _, err := os.Stat(folder + ipinfoDataBaseFilename); err == nil { + ipinfoDataBasePath = folder + ipinfoDataBaseFilename + return nil + } + } + return errors.New("no ipinfoLocal.mmdb found") +} + func IPInfoLocal(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, error) { - if _, err := os.Stat(ipinfoDataBasePath); os.IsNotExist(err) { + if err := getIPInfoLocalPath(); err != nil { panic("Cannot find ipinfoLocal.mmdb") } region, err := maxminddb.Open(ipinfoDataBasePath) if err != nil { - panic("Cannot find ipinfoLocal.mmdb") + panic("Cannot open ipinfoLocal.mmdb at " + ipinfoDataBasePath) } defer func(region *maxminddb.Reader) { err := region.Close() diff --git a/util/util.go b/util/util.go index 8a1623d..476de68 100644 --- a/util/util.go +++ b/util/util.go @@ -18,6 +18,7 @@ import ( var Uninterrupted = GetenvDefault("NEXTTRACE_UNINTERRUPTED", "") var EnvToken = GetenvDefault("NEXTTRACE_TOKEN", "") +var EnvIPInfoLocalPath = GetenvDefault("NEXTTRACE_IPINFOLOCALPATH", "") var UserAgent = fmt.Sprintf("NextTrace %s/%s/%s", config.Version, runtime.GOOS, runtime.GOARCH) var RdnsCache sync.Map var PowProviderParam = "" From a5641b5530865621feac98027406be6860296a61 Mon Sep 17 00:00:00 2001 From: kernelcrashdump <154682737+kernelcrashdump@users.noreply.github.com> Date: Sat, 31 Aug 2024 12:48:03 +0800 Subject: [PATCH 7/7] Update nt_install.sh --- nt_install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nt_install.sh b/nt_install.sh index 20da5d4..9cb26f1 100644 --- a/nt_install.sh +++ b/nt_install.sh @@ -60,7 +60,7 @@ checkSystemDistribution() { downloadBinrayFile() { echo -e "${Info} 获取最新版的 NextTrace 发行版文件信息" for i in {1..3}; do - downloadUrls=$(curl -sL ${protocol}://www.nxtrace.org/api/dist/core/nexttrace_${osDistribution}_${archParam} --connect-timeout 1.5) + downloadUrls=$(curl -sLf ${protocol}://www.nxtrace.org/api/dist/core/nexttrace_${osDistribution}_${archParam} --connect-timeout 1.5) if [ $? -eq 0 ]; then break fi @@ -70,7 +70,7 @@ downloadBinrayFile() { backupUrl=$(echo ${downloadUrls} | awk -F '|' '{print $2}') echo -e "${Info} 正在尝试从 Primary 节点下载 NextTrace" for i in {1..3}; do - curl -sL ${primaryUrl} -o ${Temp_path} --connect-timeout 1.5 + curl -sLf ${primaryUrl} -o ${Temp_path} --connect-timeout 1.5 if [ $? -eq 0 ]; then changeMode mv ${Temp_path} ${downPath} @@ -84,7 +84,7 @@ downloadBinrayFile() { fi echo -e "${Error} 从 Primary 节点下载失败,正在尝试从 Backup 节点下载 NextTrace" for i in {1..3}; do - curl -sL ${backupUrl} -o ${Temp_path} --connect-timeout 1.5 + curl -sLf ${backupUrl} -o ${Temp_path} --connect-timeout 1.5 if [ $? -eq 0 ]; then changeMode mv ${Temp_path} ${downPath}