Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timezone information to the available fields #33

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +22 to +26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The steps for handling the GeoLite2-City database are correctly implemented, ensuring secure download, verification, and extraction. To optimize the Dockerfile and reduce the number of layers, consider combining these RUN commands into a single RUN command using && to chain the commands together. This can improve the build performance and reduce the image size.

-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
+RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz && \
+    wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 && \
+    sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 && \
+    sha256sum -c GeoLite2-City.tar.gz.sha256 && \
+    tar xvf GeoLite2-City.tar.gz --strip 1

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz && \
wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 && \
sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 && \
sha256sum -c GeoLite2-City.tar.gz.sha256 && \
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/
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to the changes in the PR, we should leave it alone.


### Client side

Expand All @@ -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
Comment on lines 55 to 66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [29-29]

The description of the demo setup mentions "an reverse proxy" which should be corrected to "a reverse proxy" for grammatical accuracy.

- this demo is behind an reverse proxy with https enabled
+ this demo is behind a reverse proxy with https enabled

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [29-29]

There's a minor typographical error with "http traffic" which should be capitalized as "HTTP traffic" for consistency with standard terminology.

- http traffic will be redirected to use https
+ HTTP traffic will be redirected to use https

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [49-49]

The phrase "pass the it to the container" seems to contain an extra word. It should be corrected for clarity.

- set up an `X-Real-IP` header and pass the it to the container
+ set up an `X-Real-IP` header and pass it to the container

Expand All @@ -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:

Expand All @@ -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.

Expand Down
5 changes: 5 additions & 0 deletions nginx/conf.d/geoip2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ 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;
$ip_time_zone source=$remote_addr location time_zone;
}
5 changes: 4 additions & 1 deletion nginx/conf.d/ipinfo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^(.*)$ /;
}
Expand All @@ -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;
Expand Down