where

plot a map of users logged onto the system
git clone git://bvnf.space/where.git
Log | Files | Refs | README | LICENSE

commit a5c3b38f707ef122b7f96d9d5f227ac1b0aa91b8
parent 9490d5c9e4d382a5ca8b602a7bff164721b946ab
Author: aabacchus <ben@bvnf.space>
Date:   Tue, 11 May 2021 01:23:53 +0100

use freegeoip.app as ip location backend

Diffstat:
Mwhere.go | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/where.go b/where.go @@ -166,6 +166,7 @@ func main() { fmt.Printf("error reading ips cache: %s\n", err) os.Exit(1) } + log(fmt.Sprintf("found previous results file %s", cacheFname)) var cache []Marker err = json.Unmarshal(bytes, &cache) if err != nil { @@ -309,13 +310,20 @@ func ipLatLng(apikey, name, ip string, ch chan MarkResponse) { ch <- MarkResponse{Marker{Name: name}, errors.New("no IP provided")} return } - query := fmt.Sprintf("http://api.ipstack.com/%s?access_key=%s", ip, apikey) + query := fmt.Sprintf("https://freegeoip.app/json/%s", ip) resp, err := http.Get(query) if err != nil { ch <- MarkResponse{Marker{Name: name}, err} return } defer resp.Body.Close() + // freegeoip.app will give 403 if we've made more than 15,000 queries per hour. + // Unlikely, yes, but good to be careful. + if resp.StatusCode == 403 { + // this is logged to stderr, so it should be picked up by the cron daemon + fmt.Fprintf(os.Stderr, "The request to freegeoip.app returned %s", resp.Status) + } + bytes, err := ioutil.ReadAll(resp.Body) if err != nil { ch <- MarkResponse{Marker{Name: name}, err}