Opened 6 years ago

Closed 6 years ago

#2099 closed enhancement (fixed)

Get location information from ip address

Reported by: Nicklas Nordborg Owned by: everyone
Priority: minor Milestone: BASE 3.12
Component: core Version:
Keywords: Cc:

Description

When we create a new login session, we register the ip address in the "Remote ID" field. With the help of a service like http://freegeoip.net we could get some information about the actual location of the ip. The service has a simple JSON-based API. For example:

http://freegeoip.net/json/130.235.5.57 ==>
{
  "ip": "130.235.5.57",
  "country_code": "SE",
  "country_name": "Sweden",
  "region_code": "M",
  "region_name": "Skåne",
  "city": "Lund",
  "zip_code": "220 02",
  "time_zone": "Europe/Stockholm",
  "latitude": 55.7,
  "longitude": 13.1833,
  "metro_code": 0
}

It is even possible to setup a local server: https://github.com/fiorix/freegeoip

The server URL should be specified by an option in base.config and if not set, the location lookup should be disabled.

Change History (5)

comment:1 by Nicklas Nordborg, 6 years ago

(In [7413]) References #2099: Get location information from ip address

Updated SessionData and UserDeviceData with fields for storing location information.

comment:2 by Nicklas Nordborg, 6 years ago

(In [7414]) References #2099: Get location information from ip address

Location information is now stored on sessions and devices when a user is logging in. The actual location lookup is not yet implemented. base.config has been prepared with a setting for the service to use for this.

List and view pages display the location and provide a link to a map. The default setting in base.config uses OpenStreetMap, but other services can be used as well as long as they accept at latitude and longitude.

comment:3 by Nicklas Nordborg, 6 years ago

(In [7415]) References #2099: Get location information from ip address

Location lookup implemented. Requires a bit of careful error handling since we do not want a failure or delay in this feature to prevent a user from loggin in.

  • Before trying to lookup the location, we check that the remote id seems like an ip address.
  • We do not allow more than 3 seconds.
  • The lookup service must return a HTTP status 200
  • It must return "application/json" content type
  • It must not return more than 1kB of data.

comment:4 by Nicklas Nordborg, 6 years ago

(In [7417]) References #2099: Get location information from ip address

Updating failed since we log in with a null 'ip'.

comment:5 by Nicklas Nordborg, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.