File tree 8 files changed +36
-3
lines changed
8 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ GITCOMMIT=`git describe --always`
2
2
VERSION =$$(git describe 2>/dev/null || echo "0.0.0-${GITCOMMIT}" )
3
3
GITDATE=`TZ =UTC git show -s --date=iso-strict-local --format=%cd HEAD`
4
4
BUILDDATE= ` date -u +"%Y-%m-%dT%H:%M:%S%:z"`
5
- PACKAGE=eth2-exporter
5
+ PACKAGE=coda-explorer
6
6
LDFLAGS=" -X ${PACKAGE} /version.Version=${VERSION} -X ${PACKAGE} /version.BuildDate=${BUILDDATE} -X ${PACKAGE} /version.GitCommit=${GITCOMMIT} -X ${PACKAGE} /version.GitDate=${GITDATE} "
7
7
8
8
all: explorer frontend statistics
@@ -19,8 +19,11 @@ statistics:
19
19
frontend:
20
20
rm -rf bin/templates
21
21
rm -rf bin/static
22
+ rm -rf bin/ip2location
22
23
mkdir -p bin/templates/
23
24
mkdir -p bin/static/
25
+ mkdir -p bin/ip2location/
24
26
cp -r templates/ bin/
25
27
cp -r static/ bin/
28
+ cp -r ip2location/ bin/
26
29
go build --ldflags=${LDFLAGS} -o bin/frontend cmd/frontend/main.go
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ require (
12
12
github.com/meatballhat/negroni-logrus v1.1.0
13
13
github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029
14
14
github.com/sirupsen/logrus v1.4.2
15
+ github.com/tankbusta/go-ip2location v0.0.0-20160330022245-abd0501f28f8
15
16
github.com/urfave/negroni v1.0.0
16
17
github.com/zesik/proxyaddr v0.0.0-20161218060608-ec32c535184d
17
18
google.golang.org/appengine v1.6.5 // indirect
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
30
30
github.com/stretchr/objx v0.1.1 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
31
31
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w =
32
32
github.com/stretchr/testify v1.2.2 /go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs =
33
+ github.com/tankbusta/go-ip2location v0.0.0-20160330022245-abd0501f28f8 h1:HVRn2tOYSvoJbzsJJdSGOw9Bj3XyERFRoLUnXypDl5I =
34
+ github.com/tankbusta/go-ip2location v0.0.0-20160330022245-abd0501f28f8 /go.mod h1:Yb7iDRJ9y0YCIZGWoLwiL6iwuiACyNK2u2o1rwy+b+o =
33
35
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc =
34
36
github.com/urfave/negroni v1.0.0 /go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4 =
35
37
github.com/zesik/proxyaddr v0.0.0-20161218060608-ec32c535184d h1:Gsw/uTjNB2vkIEhBO3NAXjKo6QRY6D5B0GzMv980ses =
Original file line number Diff line number Diff line change @@ -24,16 +24,26 @@ import (
24
24
"sync"
25
25
"sync/atomic"
26
26
"time"
27
+
28
+ "github.com/tankbusta/go-ip2location"
27
29
)
28
30
29
31
var latestHeight uint64
30
32
var indexPageData atomic.Value
31
33
var ready = sync.WaitGroup {}
34
+ var GeoIpDb ip2location.IP2Location
32
35
33
36
var logger = logrus .New ().WithField ("module" , "services" )
34
37
35
38
// Init will initialize the services
36
39
func Init () {
40
+
41
+ db , err := ip2location .NewIP2Location ("ip2location/IP2LOCATION-LITE-DB1.BIN" )
42
+ if err != nil {
43
+ logger .Fatalf ("error opening ip2location database: %v" , err )
44
+ }
45
+ GeoIpDb = db
46
+
37
47
ready .Add (2 )
38
48
go heightUpdater ()
39
49
go indexPageDataUpdater ()
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ <h4 class="alert-heading"><i class="fas fa-exclamation-triangle mr-1"></i>Block
78
78
</ div >
79
79
< div class ="row border-bottom p-3 ">
80
80
< div class ="col-md-2 "> Time:</ div >
81
- < div class ="col-md-10 "> < span aria-local-date ="{{.Ts.Unix}} "> {{.Ts}}</ span > </ div >
81
+ < div class ="col-md-10 "> < span aria-local-date ="{{.Ts.Unix}} "> {{.Ts}}</ span > ( < span aria-local-date =" {{.Ts.Unix}} " aria-local-date-format =" FROMNOW " > </ span > ) </ div >
82
82
</ div >
83
83
< div class ="row border-bottom p-3 ">
84
84
< div class ="col-md-2 "> Creator:</ div >
Original file line number Diff line number Diff line change 17
17
package templates
18
18
19
19
import (
20
+ "coda-explorer/services"
20
21
"fmt"
21
22
"github.com/lib/pq"
22
23
"html/template"
24
+ "net"
23
25
"strings"
24
26
"time"
25
27
@@ -35,6 +37,7 @@ func GetTemplateFuncs() template.FuncMap {
35
37
"formatPGIntArray" : formatPGIntArray ,
36
38
"decodeBase58" : decodeBase58 ,
37
39
"joinHtml" : joinHtml ,
40
+ "ipToCountry" : ipToCountry ,
38
41
}
39
42
40
43
gtf .ForceInject (fm )
@@ -65,3 +68,17 @@ func decodeBase58(encoded string) string {
65
68
func joinHtml (arg string , value []string ) template.HTML {
66
69
return template .HTML (strings .Join (value , arg ))
67
70
}
71
+
72
+ func ipToCountry (peer string ) string {
73
+ ip , _ , err := net .SplitHostPort (peer )
74
+ if err != nil {
75
+ return ""
76
+ }
77
+
78
+ rec , err := services .GeoIpDb .GetRecord (ip )
79
+
80
+ if err != nil {
81
+ return ""
82
+ }
83
+ return rec .CountryLong
84
+ }
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ <h1 class="h4 mb-1 mb-md-0">
61
61
< div class ="col-md-10 ">
62
62
< ul class ="list-unstyled ">
63
63
{{range $peer := .Peers}}
64
- < li class ="text-muted "> < small > {{$peer}}</ small > </ li >
64
+ < li class ="text-muted "> < small > {{$peer}} ({{ipToCountry $peer}}) </ small > </ li >
65
65
{{end}}
66
66
</ ul >
67
67
</ div >
You can’t perform that action at this time.
0 commit comments