@scalio-cloud/ui 0.92.0 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/nginx/access-limit.sh +24 -2
- package/nginx/geoip-attribution.txt +1 -0
- package/nginx/geoip-db.sh +61 -0
- package/nginx/geoip-module.sh +68 -0
- package/package.json +1 -1
- package/react/access_limit.js +66 -0
- package/react/index.js +1 -1
- package/react/labels.js +37 -0
package/README.md
CHANGED
|
@@ -80,6 +80,7 @@ server {
|
|
|
80
80
|
| `TRUSTED_PROXIES` | Proxies whose `X-Forwarded-For` counts (Caddy, Azure front end); the last entry is used |
|
|
81
81
|
| `SCALIO_APP` | App name (`nexus`, …) for the app-specific machine paths |
|
|
82
82
|
| `SCALIO_GEOIP_DB` | Country database, default `/etc/nginx/geoip/dbip-country.mmdb` |
|
|
83
|
+
| `SCALIO_ACCESS_STATUS` | Public status file, default `/usr/share/nginx/html/access-status.json` (from 0.93.0) |
|
|
83
84
|
|
|
84
85
|
Both lists empty: no limit (both files stay empty). An address passes if it is in the IP list or its country is
|
|
85
86
|
allowed. An invalid entry closes the instance for everyone except the machine paths and names the entry in the log
|
|
@@ -88,6 +89,54 @@ allowed. An invalid entry closes the instance for everyone except the machine pa
|
|
|
88
89
|
`ngx_http_geoip2_module` and the free DB-IP «IP to Country Lite» database (CC BY 4.0: show «IP Geolocation by DB-IP»
|
|
89
90
|
on the about page). Tests (`test/access.test.js`) run with real nginx when it is installed.
|
|
90
91
|
|
|
92
|
+
### Country limit: geoip2 module and DB-IP database in the image (from 0.94.0)
|
|
93
|
+
|
|
94
|
+
The official nginx image has neither the geoip2 module nor a country database. Two scripts close that gap at
|
|
95
|
+
image build time; add this to the app's frontend Dockerfile (same nginx version in both stages):
|
|
96
|
+
|
|
97
|
+
```dockerfile
|
|
98
|
+
FROM nginx:1.27-alpine AS geoip
|
|
99
|
+
COPY --from=build /app/node_modules/@scalio-cloud/ui/nginx/geoip-*.sh /usr/local/bin/
|
|
100
|
+
RUN geoip-module.sh build /geoip && geoip-db.sh /geoip/dbip-country.mmdb
|
|
101
|
+
# ... in the final nginx stage, after the access-limit lines above:
|
|
102
|
+
COPY --from=build /app/node_modules/@scalio-cloud/ui/nginx/geoip-module.sh /usr/local/bin/
|
|
103
|
+
COPY --from=geoip /geoip /tmp/geoip
|
|
104
|
+
RUN geoip-module.sh install /tmp/geoip && rm -rf /tmp/geoip
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- `geoip-module.sh build` compiles `ngx_http_geoip2_module` (pinned, `SCALIO_GEOIP2_VERSION`) for the nginx of that
|
|
108
|
+
stage. `install` copies it, adds `load_module` to `nginx.conf`, installs libmaxminddb and the database. A module that
|
|
109
|
+
cannot be built breaks the build (a silent image without the module would be worse).
|
|
110
|
+
- `geoip-db.sh` loads this month's «IP to Country Lite» file from download.db-ip.com (last month's while the new one is
|
|
111
|
+
not out yet) and checks gzip, size, MaxMind marker and, if `SCALIO_GEOIP_SHA256` is set, a pinned checksum
|
|
112
|
+
(db-ip.com publishes none). **It never breaks the build:** on any error the log says
|
|
113
|
+
`scalio-geoip: no country database (...) without countries`, the image has no database and `access-limit.sh` only
|
|
114
|
+
uses the IP list (and says so at start, `countries_unavailable` in `access-status.json`).
|
|
115
|
+
- Attribution (CC BY 4.0): show the text in `nginx/geoip-attribution.txt`, «IP Geolocation by DB-IP» linked to
|
|
116
|
+
https://db-ip.com, on the app's about page.
|
|
117
|
+
- Monthly update: the database is part of the image, so every image build loads the current month. «Dev neu bauen» and a
|
|
118
|
+
release therefore renew it; a running instance only gets the new month with a new image. For customers who stay on
|
|
119
|
+
one image for months a scheduled monthly rebuild is needed (open decision, see the PR of Nr. 154).
|
|
120
|
+
- Tests: `test/geoip_db.test.js` (local directory instead of db-ip.com), `test/geoip_module.test.js` (install step; the
|
|
121
|
+
module build needs Docker and is checked by building the image).
|
|
122
|
+
|
|
123
|
+
### Show the limit in the settings: `AccessLimitStatus` (React, from 0.93.0)
|
|
124
|
+
|
|
125
|
+
At start the script also writes `access-status.json` into the web root (nginx serves it like any static file):
|
|
126
|
+
`{ "active": true, "ip_ranges": 3, "countries": ["CH", "DE"], "countries_unavailable": false, "invalid": false }`.
|
|
127
|
+
Only numbers and country codes, never an IP address. `countries_unavailable`: countries set but no database or geoip2
|
|
128
|
+
module (only the IP list counts); `invalid`: a wrong entry closed the instance. A file that cannot be written only
|
|
129
|
+
logs a line; the settings then show «Status nicht verfügbar». The component reads it (read only, changing happens in
|
|
130
|
+
Scalio Compass) and belongs in Einstellungen -> Sicherheit:
|
|
131
|
+
|
|
132
|
+
```jsx
|
|
133
|
+
import { AccessLimitStatus } from "@scalio-cloud/ui/react";
|
|
134
|
+
<AccessLimitStatus lang={lang} /> // props: status (skips the request), url, fetcher, labels
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Test ids: `access-limit`, `access-limit-state`, `access-limit-ips`, `access-limit-countries`, `access-limit-warn`.
|
|
138
|
+
`accessLimitState(data)` returns `off`, `on`, `partial`, `invalid` or `null`. Texts: `LABELS.<lang>.accessLimit`.
|
|
139
|
+
|
|
91
140
|
## Sign-in state (React, from 0.37.0)
|
|
92
141
|
|
|
93
142
|
`createAuth({ api, formatError, signInWithPasskey, passkeyCancelled, legacyTokenKey })` gives `{ AuthProvider,
|
package/nginx/access-limit.sh
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# loaded in nginx.conf (load_module, or modules/*.conf as in the Alpine package)
|
|
9
9
|
# TRUSTED_PROXIES CIDR list of the proxy in front (Caddy network, Azure ingress); its X-Forwarded-For counts
|
|
10
10
|
# SCALIO_APP nexus, citadel, … : picks the app's machine paths (machine-paths.txt)
|
|
11
|
+
# SCALIO_ACCESS_STATUS public status file for the settings page, default /usr/share/nginx/html/access-status.json
|
|
12
|
+
# (active yes/no, number of IP ranges, countries; never an address); cannot be written: only a log line
|
|
11
13
|
# SCALIO_GEOIP_DB country database (DB-IP «IP to Country Lite», mmdb); default /etc/nginx/geoip/dbip-country.mmdb
|
|
12
14
|
#
|
|
13
15
|
# Allowed is who is in the IP list OR in an allowed country; machine paths stay open. Everyone else gets 403 with a
|
|
@@ -25,6 +27,7 @@ PATHS_FILE="${SCALIO_MACHINE_PATHS_FILE:-$(dirname "$0")/machine-paths.txt}"
|
|
|
25
27
|
GEOIP_DB="${SCALIO_GEOIP_DB:-$DIR/geoip/dbip-country.mmdb}"
|
|
26
28
|
NGINX_CONF="${SCALIO_NGINX_CONF:-$DIR/nginx.conf}"
|
|
27
29
|
APP="${SCALIO_APP:-}"
|
|
30
|
+
STATUS_FILE="${SCALIO_ACCESS_STATUS:-/usr/share/nginx/html/access-status.json}"
|
|
28
31
|
|
|
29
32
|
log() { echo "scalio-access: $*" >&2; }
|
|
30
33
|
|
|
@@ -50,6 +53,18 @@ valid_cidr() {
|
|
|
50
53
|
return 0
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
# Public status for the settings (AccessLimitStatus): numbers and country codes only, never an IP address.
|
|
57
|
+
# $1 active (true|false), $2 ip ranges, $3 countries (space separated), $4 countries unavailable, $5 invalid entries
|
|
58
|
+
write_status() {
|
|
59
|
+
cl=""
|
|
60
|
+
for c in $3; do cl="${cl:+$cl, }\"$c\""; done
|
|
61
|
+
if ! { mkdir -p "$(dirname "$STATUS_FILE")" &&
|
|
62
|
+
printf '{"active": %s, "ip_ranges": %s, "countries": [%s], "countries_unavailable": %s, "invalid": %s}\n' \
|
|
63
|
+
"$1" "$2" "$cl" "$4" "$5" > "$STATUS_FILE.tmp" && mv "$STATUS_FILE.tmp" "$STATUS_FILE"; } 2>/dev/null; then
|
|
64
|
+
log "cannot write the status file $STATUS_FILE (the settings page shows no status)"
|
|
65
|
+
fi
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
IPS=$(words "${ALLOWED_CLIENT_IPS:-}")
|
|
54
69
|
COUNTRIES=$(words "${ALLOWED_COUNTRIES:-}" | tr 'a-z' 'A-Z')
|
|
55
70
|
PROXIES=$(words "${TRUSTED_PROXIES:-}")
|
|
@@ -58,27 +73,34 @@ mkdir -p "$(dirname "$HTTP_CONF")" "$(dirname "$SERVER_CONF")"
|
|
|
58
73
|
if [ -z "$IPS" ] && [ -z "$COUNTRIES" ]; then
|
|
59
74
|
: > "$HTTP_CONF"
|
|
60
75
|
: > "$SERVER_CONF"
|
|
76
|
+
write_status false 0 "" false false
|
|
61
77
|
log "no access limit (ALLOWED_CLIENT_IPS and ALLOWED_COUNTRIES empty)"
|
|
62
78
|
exit 0
|
|
63
79
|
fi
|
|
64
80
|
|
|
65
81
|
broken=""
|
|
82
|
+
invalid=false
|
|
66
83
|
for c in $IPS $PROXIES; do valid_cidr "$c" || broken="$broken $c"; done
|
|
67
84
|
for c in $COUNTRIES; do echo "$c" | grep -Eq '^[A-Z]{2}$' || broken="$broken $c"; done
|
|
68
85
|
geo_ok=1
|
|
86
|
+
geo_missing=false
|
|
69
87
|
if [ -n "$COUNTRIES" ] && [ ! -r "$GEOIP_DB" ]; then
|
|
70
|
-
geo_ok=0
|
|
88
|
+
geo_ok=0; geo_missing=true
|
|
71
89
|
log "ALLOWED_COUNTRIES set, but no country database at $GEOIP_DB: only the IP list counts"
|
|
72
90
|
elif [ -n "$COUNTRIES" ] && ! cat "$NGINX_CONF" "$DIR"/modules/*.conf "$DIR"/modules-enabled/*.conf 2>/dev/null \
|
|
73
91
|
| grep -v '^[[:space:]]*#' | grep -q 'ngx_http_geoip2_module'; then
|
|
74
92
|
# Without load_module nginx would refuse the geoip2 block and not start at all.
|
|
75
|
-
geo_ok=0
|
|
93
|
+
geo_ok=0; geo_missing=true
|
|
76
94
|
log "ALLOWED_COUNTRIES set, but the geoip2 module is not loaded ($NGINX_CONF): only the IP list counts"
|
|
77
95
|
fi
|
|
78
96
|
if [ -n "$broken" ]; then
|
|
79
97
|
log "invalid entries:$broken -> access closed for everyone except the machine paths"
|
|
80
98
|
IPS=""; COUNTRIES=""
|
|
99
|
+
invalid=true
|
|
81
100
|
fi
|
|
101
|
+
COUNTRIES_SHOWN="$COUNTRIES"
|
|
102
|
+
[ "$geo_ok" = 1 ] || COUNTRIES_SHOWN=""
|
|
103
|
+
write_status true "$(echo "$IPS" | wc -w | tr -d ' ')" "$COUNTRIES_SHOWN" "$geo_missing" "$invalid"
|
|
82
104
|
|
|
83
105
|
{
|
|
84
106
|
echo "# Written by scalio-access (@scalio-cloud/ui nginx/access-limit.sh) at container start. Do not edit."
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
IP Geolocation by DB-IP (https://db-ip.com), IP to Country Lite database, licensed under CC BY 4.0.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Loads the DB-IP «IP to Country Lite» database (CC BY 4.0, https://db-ip.com) for the country limit of the frontend
|
|
3
|
+
# images (scalio-docs ADR 0085, Nr. 154). Run it in a build stage of the app's Dockerfile, see README.
|
|
4
|
+
#
|
|
5
|
+
# geoip-db.sh [TARGET] TARGET default $SCALIO_GEOIP_DB or /etc/nginx/geoip/dbip-country.mmdb
|
|
6
|
+
#
|
|
7
|
+
# Takes this month's file, or last month's while db-ip.com has not published the new one yet. Checks before it
|
|
8
|
+
# replaces TARGET: gzip, size (SCALIO_GEOIP_MIN_BYTES / SCALIO_GEOIP_MAX_BYTES), MaxMind DB marker and, when
|
|
9
|
+
# SCALIO_GEOIP_SHA256 is set, the SHA-256 of the unpacked file (db-ip.com publishes no checksum file, so it is a pin).
|
|
10
|
+
# Never breaks the build: on any error it says why in the log, leaves TARGET as it was and exits 0. The image then
|
|
11
|
+
# has no database and access-limit.sh falls back to the IP list at start (and logs it).
|
|
12
|
+
#
|
|
13
|
+
# SCALIO_GEOIP_URL base URL, default https://download.db-ip.com/free (tests use file://)
|
|
14
|
+
# SCALIO_GEOIP_MONTH fixed month YYYY-MM instead of the current and the previous one
|
|
15
|
+
set -u
|
|
16
|
+
|
|
17
|
+
TARGET="${1:-${SCALIO_GEOIP_DB:-/etc/nginx/geoip/dbip-country.mmdb}}"
|
|
18
|
+
BASE="${SCALIO_GEOIP_URL:-https://download.db-ip.com/free}"
|
|
19
|
+
MIN="${SCALIO_GEOIP_MIN_BYTES:-1000000}"
|
|
20
|
+
MAX="${SCALIO_GEOIP_MAX_BYTES:-200000000}"
|
|
21
|
+
SHA="${SCALIO_GEOIP_SHA256:-}"
|
|
22
|
+
|
|
23
|
+
log() { echo "scalio-geoip: $*" >&2; }
|
|
24
|
+
giveup() { log "no country database ($1): the image continues without countries, ALLOWED_COUNTRIES will not work until the next build"; exit 0; }
|
|
25
|
+
|
|
26
|
+
if [ -n "${SCALIO_GEOIP_MONTH:-}" ]; then
|
|
27
|
+
MONTHS="$SCALIO_GEOIP_MONTH"
|
|
28
|
+
else
|
|
29
|
+
y=$(date -u +%Y); m=$(date -u +%m | sed 's/^0//')
|
|
30
|
+
if [ "$m" -le 1 ]; then py=$((y - 1)); pm=12; else py=$y; pm=$((m - 1)); fi
|
|
31
|
+
MONTHS=$(printf '%04d-%02d %04d-%02d' "$y" "$m" "$py" "$pm")
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
command -v curl >/dev/null 2>&1 || giveup "curl missing"
|
|
35
|
+
DIR=$(dirname "$TARGET")
|
|
36
|
+
mkdir -p "$DIR" 2>/dev/null || giveup "cannot create $DIR"
|
|
37
|
+
TMP=$(mktemp -d 2>/dev/null) || giveup "no temporary directory"
|
|
38
|
+
trap 'rm -rf "$TMP"' EXIT
|
|
39
|
+
|
|
40
|
+
REASON="nothing tried"
|
|
41
|
+
for month in $MONTHS; do
|
|
42
|
+
NAME="dbip-country-lite-$month"
|
|
43
|
+
if ! curl -fsSL --retry 2 --connect-timeout 15 --max-time 300 -o "$TMP/db.gz" "$BASE/$NAME.mmdb.gz" 2>"$TMP/err"; then
|
|
44
|
+
REASON="$NAME not downloadable: $(tr '\n' ' ' < "$TMP/err")"; log "$REASON"; continue
|
|
45
|
+
fi
|
|
46
|
+
if ! gzip -t "$TMP/db.gz" 2>/dev/null; then REASON="$NAME is not a gzip file"; log "$REASON"; continue; fi
|
|
47
|
+
gzip -dc "$TMP/db.gz" > "$TMP/db.mmdb" 2>/dev/null || { REASON="$NAME cannot be unpacked"; log "$REASON"; continue; }
|
|
48
|
+
size=$(wc -c < "$TMP/db.mmdb" | tr -d ' ')
|
|
49
|
+
if [ "$size" -lt "$MIN" ]; then REASON="$NAME too small ($size bytes, minimum $MIN)"; log "$REASON"; continue; fi
|
|
50
|
+
if [ "$size" -gt "$MAX" ]; then REASON="$NAME too large ($size bytes, maximum $MAX)"; log "$REASON"; continue; fi
|
|
51
|
+
if ! grep -aq 'MaxMind.com' "$TMP/db.mmdb"; then REASON="$NAME is not a MaxMind DB file"; log "$REASON"; continue; fi
|
|
52
|
+
if [ -n "$SHA" ]; then
|
|
53
|
+
got=$(sha256sum "$TMP/db.mmdb" | cut -d' ' -f1)
|
|
54
|
+
if [ "$got" != "$SHA" ]; then REASON="$NAME checksum differs (SCALIO_GEOIP_SHA256)"; log "$REASON"; continue; fi
|
|
55
|
+
fi
|
|
56
|
+
mv "$TMP/db.mmdb" "$TARGET.new" && mv "$TARGET.new" "$TARGET" || giveup "cannot write $TARGET"
|
|
57
|
+
chmod 644 "$TARGET" 2>/dev/null
|
|
58
|
+
log "loaded $NAME ($size bytes) into $TARGET. IP Geolocation by DB-IP (https://db-ip.com), CC BY 4.0"
|
|
59
|
+
exit 0
|
|
60
|
+
done
|
|
61
|
+
giveup "$REASON"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# ngx_http_geoip2_module for the official nginx image (scalio-docs ADR 0085, Nr. 154). The official image has no
|
|
3
|
+
# geoip2 module, and a module only loads into the exact nginx version it was built for, so the build stage uses the
|
|
4
|
+
# same base image as the final stage. Usage, see README:
|
|
5
|
+
#
|
|
6
|
+
# geoip-module.sh build DIR build stage (nginx:<version>-alpine or -debian, as root): compiles
|
|
7
|
+
# DIR/ngx_http_geoip2_module.so for the nginx that is installed there
|
|
8
|
+
# geoip-module.sh install DIR final stage: libmaxminddb, DIR/*.so into the modules directory, `load_module` first
|
|
9
|
+
# in nginx.conf, DIR/dbip-country.mmdb (from geoip-db.sh) to /etc/nginx/geoip/
|
|
10
|
+
#
|
|
11
|
+
# SCALIO_GEOIP2_VERSION version of leev/ngx_http_geoip2_module, default below
|
|
12
|
+
# SCALIO_NGINX_DIR, SCALIO_MODULES_DIR, SCALIO_SKIP_PACKAGES for tests (other paths, no apk/apt)
|
|
13
|
+
set -eu
|
|
14
|
+
|
|
15
|
+
CMD="${1:-}"; DIR="${2:-}"
|
|
16
|
+
[ -n "$CMD" ] && [ -n "$DIR" ] || { echo "usage: geoip-module.sh build|install DIR" >&2; exit 2; }
|
|
17
|
+
MODVER="${SCALIO_GEOIP2_VERSION:-3.4}"
|
|
18
|
+
NGINX_DIR="${SCALIO_NGINX_DIR:-/etc/nginx}"
|
|
19
|
+
MODULES_DIR="${SCALIO_MODULES_DIR:-/usr/lib/nginx/modules}"
|
|
20
|
+
SO=ngx_http_geoip2_module.so
|
|
21
|
+
|
|
22
|
+
log() { echo "scalio-geoip: $*" >&2; }
|
|
23
|
+
|
|
24
|
+
pkg_install() {
|
|
25
|
+
[ -z "${SCALIO_SKIP_PACKAGES:-}" ] || return 0
|
|
26
|
+
if command -v apk >/dev/null 2>&1; then apk add --no-cache "$@"
|
|
27
|
+
else apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends "$@" && rm -rf /var/lib/apt/lists/*
|
|
28
|
+
fi
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
case "$CMD" in
|
|
32
|
+
build)
|
|
33
|
+
if command -v apk >/dev/null 2>&1; then
|
|
34
|
+
pkg_install build-base linux-headers pcre2-dev zlib-dev openssl-dev libmaxminddb-dev curl
|
|
35
|
+
else
|
|
36
|
+
pkg_install build-essential libpcre2-dev zlib1g-dev libssl-dev libmaxminddb-dev curl ca-certificates
|
|
37
|
+
fi
|
|
38
|
+
NGXVER=$(nginx -v 2>&1 | sed 's|.*nginx/||; s| .*||')
|
|
39
|
+
[ -n "$NGXVER" ] || { log "cannot read the nginx version (nginx -v)"; exit 1; }
|
|
40
|
+
log "building ngx_http_geoip2_module $MODVER for nginx $NGXVER"
|
|
41
|
+
W=$(mktemp -d); trap 'rm -rf "$W"' EXIT
|
|
42
|
+
curl -fsSL "https://nginx.org/download/nginx-$NGXVER.tar.gz" | tar xz -C "$W"
|
|
43
|
+
curl -fsSL "https://github.com/leev/ngx_http_geoip2_module/archive/refs/tags/$MODVER.tar.gz" | tar xz -C "$W"
|
|
44
|
+
# The module must be compiled with the flags of the installed nginx, --with-compat keeps the binary interface.
|
|
45
|
+
( cd "$W/nginx-$NGXVER" && ./configure --with-compat --add-dynamic-module="$W/ngx_http_geoip2_module-$MODVER" >/dev/null && make modules >/dev/null )
|
|
46
|
+
mkdir -p "$DIR"
|
|
47
|
+
cp "$W/nginx-$NGXVER/objs/$SO" "$DIR/$SO"
|
|
48
|
+
log "built $DIR/$SO"
|
|
49
|
+
;;
|
|
50
|
+
install)
|
|
51
|
+
[ -f "$DIR/$SO" ] || { log "$DIR/$SO is missing: run 'geoip-module.sh build' in the build stage first"; exit 1; }
|
|
52
|
+
if command -v apk >/dev/null 2>&1; then pkg_install libmaxminddb-libs; else pkg_install libmaxminddb0; fi
|
|
53
|
+
mkdir -p "$MODULES_DIR"
|
|
54
|
+
cp "$DIR/$SO" "$MODULES_DIR/$SO"
|
|
55
|
+
CONF="$NGINX_DIR/nginx.conf"
|
|
56
|
+
if ! grep -q 'ngx_http_geoip2_module' "$CONF"; then
|
|
57
|
+
{ echo "load_module modules/$SO;"; cat "$CONF"; } > "$CONF.new" && mv "$CONF.new" "$CONF"
|
|
58
|
+
fi
|
|
59
|
+
if [ -f "$DIR/dbip-country.mmdb" ]; then
|
|
60
|
+
mkdir -p "$NGINX_DIR/geoip"
|
|
61
|
+
cp "$DIR/dbip-country.mmdb" "$NGINX_DIR/geoip/dbip-country.mmdb"
|
|
62
|
+
log "installed the module and the country database"
|
|
63
|
+
else
|
|
64
|
+
log "module installed, but no country database (geoip-db.sh failed or was not run): ALLOWED_COUNTRIES will not work"
|
|
65
|
+
fi
|
|
66
|
+
;;
|
|
67
|
+
*) echo "usage: geoip-module.sh build|install DIR" >&2; exit 2 ;;
|
|
68
|
+
esac
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.94.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Einstellungen -> Sicherheit: shows the IP and country limit of the instance (scalio-docs ADR 0085, zugang/Z1).
|
|
3
|
+
// nginx/access-limit.sh writes /access-status.json at container start:
|
|
4
|
+
// { active, ip_ranges, countries: ["CH"], countries_unavailable?, invalid? } (numbers and codes, never an address)
|
|
5
|
+
// Read only: the limit is set in Scalio Compass (ALLOWED_CLIENT_IPS / ALLOWED_COUNTRIES), not here.
|
|
6
|
+
const React = require("react");
|
|
7
|
+
const h = React.createElement;
|
|
8
|
+
const { labelsFor } = require("./labels");
|
|
9
|
+
const { StatusBadge, Notice } = require("./blocks");
|
|
10
|
+
const { SettingsSection, SettingsRow } = require("./settings");
|
|
11
|
+
|
|
12
|
+
// -> null (unknown) | { kind: "off" | "on" | "partial" | "invalid", ipRanges, countries }
|
|
13
|
+
function accessLimitState(data) {
|
|
14
|
+
if (!data || typeof data.active !== "boolean") return null;
|
|
15
|
+
const countries = (Array.isArray(data.countries) ? data.countries : [])
|
|
16
|
+
.filter((c) => typeof c === "string" && c).map((c) => c.toUpperCase());
|
|
17
|
+
const n = Number(data.ip_ranges);
|
|
18
|
+
const ipRanges = Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
|
19
|
+
if (!data.active) return { kind: "off", ipRanges: 0, countries: [] };
|
|
20
|
+
const kind = data.invalid ? "invalid" : data.countries_unavailable ? "partial" : "on";
|
|
21
|
+
return { kind, ipRanges, countries };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Props: status (the parsed file; skips the request), url (default /access-status.json), fetcher (tests), lang, labels.
|
|
25
|
+
function AccessLimitStatus(props) {
|
|
26
|
+
const L = labelsFor(props.lang, props.labels).accessLimit;
|
|
27
|
+
const [data, setData] = React.useState(props.status || null);
|
|
28
|
+
const [loaded, setLoaded] = React.useState(!!props.status);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
if (props.status) { setData(props.status); setLoaded(true); return undefined; }
|
|
31
|
+
let alive = true;
|
|
32
|
+
const get = props.fetcher || (typeof fetch === "function" ? fetch : null);
|
|
33
|
+
const done = (d) => { if (alive) { setData(d); setLoaded(true); } };
|
|
34
|
+
if (!get) { done(null); return undefined; }
|
|
35
|
+
Promise.resolve()
|
|
36
|
+
.then(() => get(props.url || "/access-status.json", { cache: "no-store", headers: { Accept: "application/json" } }))
|
|
37
|
+
.then((r) => (r && r.ok ? r.json() : null))
|
|
38
|
+
.then(done, () => done(null));
|
|
39
|
+
return () => { alive = false; };
|
|
40
|
+
}, [props.status, props.url, props.fetcher]);
|
|
41
|
+
|
|
42
|
+
const s = accessLimitState(data);
|
|
43
|
+
const text = !loaded ? L.loading : !s ? L.unknown : s.kind === "off" ? L.off : L.on;
|
|
44
|
+
const tone = !s ? "neutral" : s.kind === "off" ? "neutral" : s.kind === "on" ? "ok" : "warn";
|
|
45
|
+
const ips = s && s.ipRanges === 1 ? L.ipOne : (L.ipMany || "").replace("{n}", s ? s.ipRanges : 0);
|
|
46
|
+
return h(
|
|
47
|
+
SettingsSection,
|
|
48
|
+
{ id: "access-limit", title: L.title, description: L.hint, testId: "access-limit" },
|
|
49
|
+
h(SettingsRow, { title: L.state }, h(StatusBadge, { tone, testId: "access-limit-state" }, text)),
|
|
50
|
+
s && s.kind !== "off"
|
|
51
|
+
? h(
|
|
52
|
+
"div",
|
|
53
|
+
{ className: "scalio-settings-form" },
|
|
54
|
+
h(SettingsRow, { title: L.ips }, h("span", { "data-testid": "access-limit-ips" }, ips)),
|
|
55
|
+
h(SettingsRow, { title: L.countries },
|
|
56
|
+
h("span", { "data-testid": "access-limit-countries" }, s.countries.length ? s.countries.join(", ") : L.none)),
|
|
57
|
+
h("p", { className: "scalio-settings-help", "data-testid": "access-limit-machine" }, L.machine),
|
|
58
|
+
s.kind === "invalid" ? h(Notice, { kind: "error", testId: "access-limit-warn", lang: props.lang, labels: props.labels }, L.invalid) : null,
|
|
59
|
+
s.kind === "partial" ? h(Notice, { kind: "warn", testId: "access-limit-warn", lang: props.lang, labels: props.labels }, L.noCountryDb) : null
|
|
60
|
+
)
|
|
61
|
+
: null,
|
|
62
|
+
h("p", { className: "scalio-settings-help", "data-testid": "access-limit-where" }, L.where)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { AccessLimitStatus, accessLimitState };
|
package/react/index.js
CHANGED
|
@@ -386,6 +386,6 @@ module.exports = {
|
|
|
386
386
|
TEST_IDS,
|
|
387
387
|
initials,
|
|
388
388
|
};
|
|
389
|
-
Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./limited_mode"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"), require("./fields"), require("./dialog"), require("./keyboard"), require("./agents"), require("./agent_scripts"), require("./ai"), require("./markdown"), require("./tenancy"), require("./legal"));
|
|
389
|
+
Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./limited_mode"), require("./access_limit"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"), require("./fields"), require("./dialog"), require("./keyboard"), require("./agents"), require("./agent_scripts"), require("./ai"), require("./markdown"), require("./tenancy"), require("./legal"));
|
|
390
390
|
// After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
|
|
391
391
|
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
|
package/react/labels.js
CHANGED
|
@@ -503,6 +503,24 @@ const LABELS = {
|
|
|
503
503
|
setUpFactor: "Zum Profil",
|
|
504
504
|
run: "Auf Werkseinstellungen zurücksetzen",
|
|
505
505
|
},
|
|
506
|
+
accessLimit: {
|
|
507
|
+
title: "Zugriff eingrenzen",
|
|
508
|
+
hint: "Wer diese Instanz öffnen darf: nach IP-Adresse oder Land.",
|
|
509
|
+
state: "Stand",
|
|
510
|
+
loading: "Wird geladen …",
|
|
511
|
+
unknown: "Status nicht verfügbar",
|
|
512
|
+
off: "Keine Eingrenzung: jede Adresse darf zugreifen",
|
|
513
|
+
on: "Eingegrenzt",
|
|
514
|
+
ips: "Erlaubte IP-Bereiche",
|
|
515
|
+
ipOne: "1 IP-Bereich",
|
|
516
|
+
ipMany: "{n} IP-Bereiche",
|
|
517
|
+
countries: "Erlaubte Länder",
|
|
518
|
+
none: "Keine",
|
|
519
|
+
machine: "Maschinen-Pfade (Health, Version, Provisionierung) bleiben immer offen. Wer weder in einem IP-Bereich noch in einem erlaubten Land ist, sieht eine Seite «Zugriff nicht freigegeben».",
|
|
520
|
+
invalid: "Ein Eintrag der Eingrenzung ist ungültig. Aus Sicherheitsgründen ist der Zugriff für alle gesperrt, bis der Eintrag in Scalio Compass korrigiert ist.",
|
|
521
|
+
noCountryDb: "Die Länderdatenbank ist in dieser Instanz nicht verfügbar. Es gelten nur die IP-Bereiche; die Länder sind noch nicht wirksam.",
|
|
522
|
+
where: "Die Eingrenzung ändern Sie in Scalio Compass unter «Zugriff eingrenzen». Die Änderung gilt nach dem nächsten Start der Instanz. Die IP-Adressen selbst werden hier nicht angezeigt.",
|
|
523
|
+
},
|
|
506
524
|
limitedMode: {
|
|
507
525
|
license: "Lizenz",
|
|
508
526
|
limitedTitle: "Eingeschränkter Modus: nur lesen",
|
|
@@ -1088,6 +1106,24 @@ const LABELS = {
|
|
|
1088
1106
|
setUpFactor: "Go to profile",
|
|
1089
1107
|
run: "Reset to factory settings",
|
|
1090
1108
|
},
|
|
1109
|
+
accessLimit: {
|
|
1110
|
+
title: "Restrict access",
|
|
1111
|
+
hint: "Who may open this instance: by IP address or country.",
|
|
1112
|
+
state: "Status",
|
|
1113
|
+
loading: "Loading …",
|
|
1114
|
+
unknown: "Status not available",
|
|
1115
|
+
off: "No restriction: every address may connect",
|
|
1116
|
+
on: "Restricted",
|
|
1117
|
+
ips: "Allowed IP ranges",
|
|
1118
|
+
ipOne: "1 IP range",
|
|
1119
|
+
ipMany: "{n} IP ranges",
|
|
1120
|
+
countries: "Allowed countries",
|
|
1121
|
+
none: "None",
|
|
1122
|
+
machine: "Machine paths (health, version, provisioning) always stay open. Anyone outside the IP ranges and the allowed countries sees an «Access not allowed» page.",
|
|
1123
|
+
invalid: "An entry of the restriction is invalid. For safety access is closed for everyone until the entry is corrected in Scalio Compass.",
|
|
1124
|
+
noCountryDb: "The country database is not available in this instance. Only the IP ranges apply; the countries are not effective yet.",
|
|
1125
|
+
where: "Change the restriction in Scalio Compass under «Restrict access». It applies after the next start of the instance. The IP addresses themselves are not shown here.",
|
|
1126
|
+
},
|
|
1091
1127
|
limitedMode: {
|
|
1092
1128
|
license: "License",
|
|
1093
1129
|
limitedTitle: "Limited mode: read-only",
|
|
@@ -1190,6 +1226,7 @@ function labelsFor(lang, overrides) {
|
|
|
1190
1226
|
mfa: Object.assign({}, base.mfa, o.mfa),
|
|
1191
1227
|
users: Object.assign({}, base.users, o.users),
|
|
1192
1228
|
license: Object.assign({}, base.license, o.license),
|
|
1229
|
+
accessLimit: Object.assign({}, base.accessLimit, o.accessLimit),
|
|
1193
1230
|
limitedMode: Object.assign({}, base.limitedMode, o.limitedMode, { units: Object.assign({}, base.limitedMode.units, (o.limitedMode || {}).units) }),
|
|
1194
1231
|
edition: Object.assign({}, base.edition, o.edition),
|
|
1195
1232
|
accountTabs: Object.assign({}, base.accountTabs, o.accountTabs),
|