|
@@ -58,8 +58,8 @@ var (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type Result struct {
|
|
type Result struct {
|
|
|
- ProcessedString string `json:"processedString"`
|
|
|
|
|
- RawISPInfo string `json:"rawIspInfo"`
|
|
|
|
|
|
|
+ ProcessedString string `json:"processedString"`
|
|
|
|
|
+ RawISPInfo IPInfoResponse `json:"rawIspInfo"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type IPInfoResponse struct {
|
|
type IPInfoResponse struct {
|
|
@@ -129,19 +129,6 @@ func init() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (r *Result) GetISPInfo() (IPInfoResponse, error) {
|
|
|
|
|
- var ret IPInfoResponse
|
|
|
|
|
- var err error
|
|
|
|
|
-
|
|
|
|
|
- if r.RawISPInfo != "" {
|
|
|
|
|
- err = json.Unmarshal([]byte(r.RawISPInfo), &ret)
|
|
|
|
|
- } else {
|
|
|
|
|
- // if ISP info is not available (i.e. localhost testing), use ProcessedString as Organization
|
|
|
|
|
- ret.Organization = r.ProcessedString
|
|
|
|
|
- }
|
|
|
|
|
- return ret, err
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func Record(w http.ResponseWriter, r *http.Request) {
|
|
func Record(w http.ResponseWriter, r *http.Request) {
|
|
|
ipAddr, _, _ := net.SplitHostPort(r.RemoteAddr)
|
|
ipAddr, _, _ := net.SplitHostPort(r.RemoteAddr)
|
|
|
userAgent := r.UserAgent()
|
|
userAgent := r.UserAgent()
|
|
@@ -215,13 +202,6 @@ func DrawPNG(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ispInfo, err := result.GetISPInfo()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- log.Errorf("Error parsing ISP info: %s", err)
|
|
|
|
|
- w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
canvas := image.NewRGBA(image.Rectangle{
|
|
canvas := image.NewRGBA(image.Rectangle{
|
|
|
Min: image.Point{},
|
|
Min: image.Point{},
|
|
|
Max: image.Point{
|
|
Max: image.Point{
|
|
@@ -342,9 +322,9 @@ func DrawPNG(w http.ResponseWriter, r *http.Request) {
|
|
|
drawer.Src = colorISP
|
|
drawer.Src = colorISP
|
|
|
drawer.Dot = freetype.Pt(6, canvasHeight-ctx.PointToFixed(14).Round()-15)
|
|
drawer.Dot = freetype.Pt(6, canvasHeight-ctx.PointToFixed(14).Round()-15)
|
|
|
removeRegexp := regexp.MustCompile(`AS\d+\s`)
|
|
removeRegexp := regexp.MustCompile(`AS\d+\s`)
|
|
|
- org := removeRegexp.ReplaceAllString(ispInfo.Organization, "")
|
|
|
|
|
- if ispInfo.Country != "" {
|
|
|
|
|
- org += ", " + ispInfo.Country
|
|
|
|
|
|
|
+ org := removeRegexp.ReplaceAllString(result.RawISPInfo.Organization, "")
|
|
|
|
|
+ if result.RawISPInfo.Country != "" {
|
|
|
|
|
+ org += ", " + result.RawISPInfo.Country
|
|
|
}
|
|
}
|
|
|
drawer.DrawString(org)
|
|
drawer.DrawString(org)
|
|
|
|
|
|