Skip to content

Commit

Permalink
Merge pull request #60 from sdr-enthusiasts/dev
Browse files Browse the repository at this point in the history
Add IPMAPS feature
  • Loading branch information
kx1t authored Feb 14, 2024
2 parents 6c360f4 + 9fe3737 commit 788fcaa
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 45 deletions.
79 changes: 51 additions & 28 deletions README.md

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions buildnow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ set -x

[[ "$1" != "" ]] && BRANCH="$1" || BRANCH=main
[[ "$BRANCH" == "main" ]] && TAG="latest" || TAG="$BRANCH"
[[ "$ARCHS" == "" ]] && ARCHS="linux/armhf,linux/arm64,linux/amd64,linux/i386"
[[ "$ARCHS" == "" ]] && ARCHS="linux/armhf,linux/arm64,linux/amd64"

BASETARGET1=ghcr.io/sdr-enthusiasts
BASETARGET2=kx1t
#BASETARGET2=kx1t

IMAGE1="$BASETARGET1/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"
IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"
IMAGE1="$BASETARGET1/docker-reversewebproxy:$TAG"
#IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG"

#shellcheck disable=SC2077,SC2015
[[ "$IMAGE1" == "$BASETARGET1/reversewebproxy:$TAG" ]] && IMAGE1="$BASETARGET1/webproxy:$TAG" || true
#shellcheck disable=SC2077,SC2015
[[ "$IMAGE2" == "$BASETARGET2/reversewebproxy:$TAG" ]] && IMAGE2="$BASETARGET2/webproxy:$TAG" || true

echo "press enter to start building $IMAGE1 and $IMAGE2 from $BRANCH"
echo "press enter to start building $IMAGE1 from $BRANCH"
read -r

starttime="$(date +%s)"
# rebuild the container
git checkout "$BRANCH" || exit 2
git pull -a
docker buildx build --compress --push "$2" --platform "$ARCHS" --tag "$IMAGE1" .
docker buildx build --compress --push "$2" --platform "$ARCHS" --tag "$IMAGE2" .
docker buildx build --compress --push --platform "$ARCHS" --tag "$IMAGE1" .
#docker buildx build --compress --push "$2" --platform "$ARCHS" --tag "$IMAGE2" .
echo "Total build time: $(( $(date +%s) - starttime )) seconds"
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/create-ipmaps/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/create-ipmaps
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/create-ipmaps/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
8 changes: 4 additions & 4 deletions rootfs/etc/s6-overlay/scripts/20-webproxy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source /scripts/common

# create run directory. This is where the locations.conf file will be located.
# Create the correct ownership and permissions for the /var/log/nginx directory:
adduser -U www-data >/dev/null 2>&1
adduser -U www-data >/dev/null 2>&1 || true
mkdir -p /var/log/nginx
mkdir -p /run/nginx/html
mkdir -p /run/nginx/.htaccess
Expand All @@ -34,11 +34,11 @@ if chk_enabled "$AUTOGENERATE"; then
[[ -f /run/nginx/locations.conf ]] && mv -f /run/nginx/locations.conf "/run/nginx/locations.conf.bkup-$(date +%y%m%d%H%M%S)"

# keep only the newest 10 backups:
org=$(shopt -p nullglob) # save current nullglob setting
org=$(shopt -p nullglob) || true # save current nullglob setting
shopt -s nullglob # set nullglob to avoid ls errors when no backups are present
# shellcheck disable=SC2010
ls -tp /run/nginx/locations.conf.bkup-* | grep -v '/$' | tail -n +11 | xargs -d '\n' -r rm -- # remove any backups older than the newest 10
$org # restore the original shopt nullglob setting
if [[ -n "$org" ]]; then $org; fi # restore the original shopt nullglob setting

# configure the locations.conf file:
# first read the REVPROXY and REDIRECT environment variables into an array:
Expand Down Expand Up @@ -160,7 +160,7 @@ fi
ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

# set logging to what VERBOSELOG says. Default is off, "ON" means to stdout, "FILE" means to access.log/error.log file in external volume
if [[ "${VERBOSELOG,,}" == "on" ]] || [[ "${VERBOSELOG,,}" == "true" ]]
if chk_enabled "${VERBOSELOG}"
then
"${s6wrap[@]}" echo "Enabled HTTP logging to container logs"
sed -i 's|\(^\s*access_log \).*|\1/dev/stdout ;|' /etc/nginx/nginx.conf
Expand Down
3 changes: 2 additions & 1 deletion rootfs/etc/s6-overlay/scripts/80-set-cors
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ for cors in "${cors_array[@]}"
do
if [[ -n "${cors}" ]]; then
printf "add_header Access-Control-Allow-Origin %s;\n" "${cors}" >> /run/nginx/cors_headers.conf
s6wrap --quiet --timestamps --prepend="${APPNAME}" --args echo "Added CORS exception for ${cors}"
# shellcheck disable=SC2154
"${s6wrap[@]}" echo "Added CORS exception for ${cors}"
fi
done
exit 0
55 changes: 55 additions & 0 deletions rootfs/etc/s6-overlay/scripts/create-ipmaps
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/command/with-contenv bash
#shellcheck shell=bash disable=SC2154,SC2089

# shellcheck disable=SC1091
source /scripts/common

# Advise to keep IPMAPS_INTERVAL < about 900 secs - this corresponds to 2920 requests
# per month, well below the maximum of 4000 requests from a single IP address for the
# free API of https://ipinfo.io/

IPMAPS_INTERVAL="${IPMAPS_INTERVAL:-900}"
IPMAPS_BASENAME="${IPMAPS_BASENAME:-ipmap-}"
HTMLDIR="/run/nginx/html"

notavail_template='<html><body><h1>Map Currently Unavailable</h1><p>This map is currently not available; please try again later. Last update: ##TIME##</body><html>'
redir_template='<html><head><meta http-equiv="refresh" content="0; URL=##REDIRURL##" /></head></html>'

if ! chk_enabled "$IPMAPS"; then
rm -f "${HTMLDIR}/${IPMAPS_BASENAME}"*.html
exec sleep infinity
fi

while :; do

ipmap_all="$(/usr/local/bin/ipmap -l 2>/dev/null| tail -1)" || true
ipmap_filtered="$(/usr/local/bin/ipmap -f 2>/dev/null| tail -1)" || true
ipmap_accepted="$(/usr/local/bin/ipmap -v 2>/dev/null| tail -1)" || true

"${s6wrap[@]}" echo "Updating ${IPMAPS_BASENAME}all.html --> $ipmap_all"
{ if [[ "${ipmap_all:0:4}" == "http" ]]; then
echo "${redir_template//##REDIRURL##/$ipmap_all}"
else
echo "${notavail_template//##TIME##/$(date)}"
fi
} > "${HTMLDIR}/${IPMAPS_BASENAME}all.html"

"${s6wrap[@]}" echo "Updating ${IPMAPS_BASENAME}filtered.html --> $ipmap_filtered"
{ if [[ "${ipmap_filtered:0:4}" == "http" ]]; then
echo "${redir_template//##REDIRURL##/$ipmap_filtered}"
else
echo "${notavail_template//##TIME##/$(date)}"
fi
} > "${HTMLDIR}/${IPMAPS_BASENAME}filtered.html"

"${s6wrap[@]}" echo "Updating ${IPMAPS_BASENAME}accepted.html --> $ipmap_accepted"
{ if [[ "${ipmap_accepted:0:4}" == "http" ]]; then
echo "${redir_template//##REDIRURL##/$ipmap_accepted}"
else
echo "${notavail_template//##TIME##/$(date)}"
fi
} > "${HTMLDIR}/${IPMAPS_BASENAME}accepted.html"

sleep "$IPMAPS_INTERVAL"

done

0 comments on commit 788fcaa

Please sign in to comment.