From ec894c42a8e89199f7410e577dbf295f99e38c85 Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Mon, 1 Apr 2024 15:41:02 +0200 Subject: [PATCH 1/5] feat: add timezone information to the available fields --- Dockerfile | 6 ++++++ nginx/conf.d/geoip2.conf | 6 ++++++ nginx/conf.d/ipinfo.conf | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 193c40d..9a71bbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,12 @@ RUN sed 's/GeoLite2-Country_[0-9]*.tar.gz/GeoLite2-Country.tar.gz/g' -i GeoLite2 RUN sha256sum -c GeoLite2-Country.tar.gz.sha256 RUN tar xvf GeoLite2-Country.tar.gz --strip 1 +RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz +RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 +RUN sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 +RUN sha256sum -c GeoLite2-City.tar.gz.sha256 +RUN tar xvf GeoLite2-City.tar.gz --strip 1 + FROM alpine:3.19 as release LABEL name="ipinfo.tw" RUN mkdir -p /run/nginx/ /usr/share/GeoIP/ diff --git a/nginx/conf.d/geoip2.conf b/nginx/conf.d/geoip2.conf index 50051de..3dc5584 100644 --- a/nginx/conf.d/geoip2.conf +++ b/nginx/conf.d/geoip2.conf @@ -11,3 +11,9 @@ geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb { $ip_aso source=$remote_addr autonomous_system_organization; $ip_as_build_epoch metadata build_epoch; } + +geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb { + auto_reload 1d; # Automatically reload the database daily + $ip_time_zone source=$remote_addr location time_zone; # Retrieve the time zone +} + diff --git a/nginx/conf.d/ipinfo.conf b/nginx/conf.d/ipinfo.conf index a21c46e..7eee71d 100644 --- a/nginx/conf.d/ipinfo.conf +++ b/nginx/conf.d/ipinfo.conf @@ -50,6 +50,9 @@ server { location = /user_agent { return 200 "$http_user_agent\n"; } + location = /timezone { + return 200 "$ip_time_zone\n"; + } location ~* ^/index.htm(l)?$ { rewrite ^(.*)$ /; } @@ -58,7 +61,7 @@ server { } location = /json { default_type application/json; - return 200 "{\"ip\":\"$remote_addr\",\"country_code\":\"$ip_country_code\",\"country_name\":\"$ip_country_name\",\"asn\":\"$ip_asn\",\"as_desc\":\"$ip_aso\",\"user_agent\":\"$http_user_agent\"}\n"; + return 200 "{\"ip\":\"$remote_addr\",\"country_code\":\"$ip_country_code\",\"country_name\":\"$ip_country_name\",\"timezone\":\"$ip_time_zone\",\"asn\":\"$ip_asn\",\"as_desc\":\"$ip_aso\",\"user_agent\":\"$http_user_agent\"}\n"; } location = /build_epoch { default_type application/json; From 219b67474c33306d3c9432dd2913bc3f27a50f38 Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Tue, 2 Apr 2024 15:43:16 +0200 Subject: [PATCH 2/5] chore: style updates --- nginx/conf.d/geoip2.conf | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nginx/conf.d/geoip2.conf b/nginx/conf.d/geoip2.conf index 3dc5584..630fbd8 100644 --- a/nginx/conf.d/geoip2.conf +++ b/nginx/conf.d/geoip2.conf @@ -13,7 +13,6 @@ geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb { } geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb { - auto_reload 1d; # Automatically reload the database daily - $ip_time_zone source=$remote_addr location time_zone; # Retrieve the time zone + auto_reload 1d; + $ip_time_zone source=$remote_addr location time_zone; } - From 6ebdb16ad1b5e24d0d60bd978288584bacbedee7 Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Tue, 2 Apr 2024 15:46:44 +0200 Subject: [PATCH 3/5] chore: added docs regarding the timezone field --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5858d61..bd7b3e4 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,12 @@ Use any http(s) client to explore the server, e.g. https://ipinfo.tw, - `wget -qO- https://ipinfo.tw` - `curl https://ipinfo.tw` -Without any specified URI, the server will return IP address, country, AS, and user agent. +Without any specified URI, the server will return IP address, country, timezone, AS, and user agent. If you prefer to receive a machine-readable result, use path `/json` (without trailing slash), e.g. `https://ipinfo.tw/json`, the result will look like: ```json -{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"} +{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","timezone":"Asia/Tokyo","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"} ``` #### Endpoints @@ -75,6 +75,7 @@ You can also specify the following URI to retrieve certain info: - `asn`: AS number - `as_desc`: AS description - `user_agent`: User agent string +- `timezone`: Timezone based on the city (e.g Europe/Amsterdam) Examples: @@ -97,6 +98,9 @@ HK $ curl https://ipinfo.tw/country_name South Korea +$ curl https://ipinfo.tw/timezone +Europe/Amsterdam + $ curl https://ipinfo.tw/as AS16509 / Amazon.com, Inc. From 8ca2ec0781527b83305cbad0b26a81e57187550e Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Tue, 2 Apr 2024 15:50:24 +0200 Subject: [PATCH 4/5] fixed the coderabbit spelling suggestions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd7b3e4..541388b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ A self-hosted, non-tracking, and ad-free solution to reveal client-side IP info This project is also hosted publicly on https://ipinfo.tw, feel free to give it a try! -Please note that for response integrity and privacy concerns, this demo is behind an reverse proxy with https enabled, which is not part of this project. http traffic will be redirected to use https to establish the connection, in case the plaintext data being sniffed/intercepted. +Please note that for response integrity and privacy concerns, this demo is behind a reverse proxy with https enabled, which is not part of this project. HTTP traffic will be redirected to use https to establish the connection, in case the plaintext data being sniffed/intercepted. ## Usage @@ -46,7 +46,7 @@ Run the server daemon via docker: docker run -d --name ipinfo.tw -p 80:8080 peterdavehello/ipinfo.tw:latest ``` -If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass the it to the container, so that it can use the header as the IP of the client. +If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass it to the container, so that it can use the header as the IP of the client. ### Client side From ca436fcaeefaa46a1437ea93c8ebd8b00899054d Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Wed, 3 Apr 2024 09:09:58 +0200 Subject: [PATCH 5/5] Revert "fixed the coderabbit spelling suggestions" This reverts commit 8ca2ec0781527b83305cbad0b26a81e57187550e. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 541388b..bd7b3e4 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ A self-hosted, non-tracking, and ad-free solution to reveal client-side IP info This project is also hosted publicly on https://ipinfo.tw, feel free to give it a try! -Please note that for response integrity and privacy concerns, this demo is behind a reverse proxy with https enabled, which is not part of this project. HTTP traffic will be redirected to use https to establish the connection, in case the plaintext data being sniffed/intercepted. +Please note that for response integrity and privacy concerns, this demo is behind an reverse proxy with https enabled, which is not part of this project. http traffic will be redirected to use https to establish the connection, in case the plaintext data being sniffed/intercepted. ## Usage @@ -46,7 +46,7 @@ Run the server daemon via docker: docker run -d --name ipinfo.tw -p 80:8080 peterdavehello/ipinfo.tw:latest ``` -If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass it to the container, so that it can use the header as the IP of the client. +If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass the it to the container, so that it can use the header as the IP of the client. ### Client side