Skip to content

Commit 5f9a40a

Browse files
authored
Merge pull request #1065 from linuxserver/swag-ipinfo-initial
ipinfo mod for swag
2 parents 6360fcf + 304d9cb commit 5f9a40a

File tree

24 files changed

+137
-103
lines changed

24 files changed

+137
-103
lines changed

.github/workflows/BuildImage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
env:
1313
GITHUB_REPO: "linuxserver/docker-mods" #don't modify
1414
ENDPOINT: "linuxserver/mods" #don't modify
15-
BASEIMAGE: "replace_baseimage" #replace
16-
MODNAME: "replace_modname" #replace
15+
BASEIMAGE: "swag" #replace
16+
MODNAME: "ipinfo" #replace
1717
MOD_VERSION: ${{ inputs.mod_version }} #don't modify
18-
MULTI_ARCH: "true" #set to false if not needed
18+
MULTI_ARCH: "false" #set to false if not needed
1919

2020
jobs:
2121
set-vars:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
FROM scratch
44

5-
LABEL maintainer="username"
5+
LABEL maintainer="quietsy"
66

77
# copy local files
88
COPY root/ /

Dockerfile.complex

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,65 @@
1-
# Rsync - Docker mod for openssh-server
1+
# IPINFO Docker mod for Nginx based images
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
3+
This mod downloads the `ipinfo_lite.mmdb` database under `/config/geoip2db`, the database is updated daily.
44

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
5+
**This mod should not be enabled together with swag-maxmind or swag-dbip mods.**
66

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
7+
Follow these steps to enable the ipinfo mod:
88

9-
# Mod creation instructions
9+
1. Sign up and aquire an ipinfo token here: https://ipinfo.io/signup
10+
2. In the container's docker arguments, set the following environment variables:
11+
- `IPINFO_TOKEN=<token>` with your token.
12+
3. In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-ipinfo`
13+
14+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-ipinfo|linuxserver/mods:swag-mod2`
15+
4. Recreate the container to apply the changes.
16+
5. Add the following line to `/config/nginx/nginx.conf` under the `http` section:
17+
18+
```nginx
19+
include /config/nginx/ipinfo.conf;
20+
```
21+
6. Edit `/config/nginx/ipinfo.conf` and add countries to the blocklist / whitelist according to the comments, for example:
22+
23+
```nginx
24+
map $geoip2_data_country_iso_code $geo-whitelist {
25+
default no;
26+
UK yes;
27+
}
1028
11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* After all init scripts and services are created, run `find ./ -path "./.git" -prune -o \( -name "run" -o -name "finish" -o -name "check" \) -not -perm -u=x,g=x,o=x -print -exec chmod +x {} +` to fix permissions.
15-
* Edit this readme with pertinent info, delete these instructions.
16-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the vars for `BASEIMAGE` and `MODNAME`. Set the versioning logic and `MULTI_ARCH` if needed.
17-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
18-
* Submit PR against the branch created by the team.
29+
map $geoip2_data_country_iso_code $geo-blacklist {
30+
default yes;
31+
US no;
32+
}
33+
```
34+
7. Use the definitions in the following way:
35+
```nginx
36+
server {
37+
listen 443 ssl;
38+
listen [::]:443 ssl;
1939
40+
server_name some-app.*;
41+
include /config/nginx/ssl.conf;
42+
client_max_body_size 0;
2043
21-
## Tips and tricks
44+
if ($lan-ip = yes) { set $geo-whitelist yes; }
45+
if ($geo-whitelist = no) { return 404; }
2246
23-
* Some images have helpers built in, these images are currently:
24-
* [Openvscode-server](https://github.com/linuxserver/docker-openvscode-server/pull/10/files)
25-
* [Code-server](https://github.com/linuxserver/docker-code-server/pull/95)
47+
location / {
48+
```
49+
Or for blacklist with both some countries and continents:
50+
```nginx
51+
server {
52+
listen 443 ssl;
53+
listen [::]:443 ssl;
54+
55+
server_name some-app.*;
56+
include /config/nginx/ssl.conf;
57+
client_max_body_size 0;
58+
59+
if ($lan-ip = yes) { set $geo-blacklist yes; }
60+
if ($geo-blacklist = no) { return 404; }
61+
if ($continent-blacklist = no) { return 404; }
62+
63+
location / {
64+
```
65+
8. Restart the container to apply the changes.

root/defaults/ipinfo.conf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
geoip2 /config/geoip2db/ipinfo_lite.mmdb {
2+
auto_reload 1d;
3+
$geoip2_data_network network;
4+
$geoip2_data_country country;
5+
$geoip2_data_country_iso_code country_code;
6+
$geoip2_data_continent continent;
7+
$geoip2_data_continent_code continent_code;
8+
$geoip2_data_asn asn;
9+
$geoip2_data_as_name as_name;
10+
$geoip2_data_as_domain as_domain;
11+
}
12+
13+
# Country Codes: https://en.wikipedia.org/wiki/ISO_3166-2
14+
15+
map $geoip2_data_country_iso_code $geo-whitelist {
16+
default yes;
17+
# Example for whitelisting a country, comment out 'default yes;' above and uncomment 'default no;' and the whitelisted country below
18+
# default no;
19+
# GB yes;
20+
}
21+
22+
map $geoip2_data_country_iso_code $geo-blacklist {
23+
default yes;
24+
# Example for blacklisting a country, uncomment the blacklisted country below
25+
# GB no;
26+
}
27+
28+
# Continents:
29+
# Options: AF, AS, EU, NA, OC, SA, AN
30+
31+
map $geoip2_data_continent_code $continent-blacklist {
32+
default yes;
33+
# Example blacklisting a continent, uncomment the blacklisted continent bellow
34+
# SA no; # South America
35+
}
36+
37+
geo $lan-ip {
38+
default no;
39+
10.0.0.0/8 yes;
40+
172.16.0.0/12 yes;
41+
192.168.0.0/16 yes;
42+
127.0.0.1 yes;
43+
}

root/etc/periodic/daily/ipinfo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
if [[ ! -n "${IPINFO_TOKEN}" ]]; then
4+
echo "IPINFO_TOKEN env var is missing."
5+
exit 1
6+
fi
7+
8+
FILE="https://ipinfo.io/data/ipinfo_lite.mmdb?token=${IPINFO_TOKEN}"
9+
10+
wget -O /tmp/ipinfo_lite.mmdb $FILE
11+
mv -f /tmp/ipinfo_lite.mmdb /config/geoip2db/ipinfo_lite.mmdb
12+
lsiown -R abc:abc /config/geoip2db/ipinfo_lite.mmdb
13+
exit 0

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/run

Lines changed: 0 additions & 30 deletions
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/up

Lines changed: 0 additions & 1 deletion
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-install/run

Lines changed: 0 additions & 8 deletions
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-install/type

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)