| #!/bin/sh |
| |
| # Copyright 2015-2025 Rivoreo |
| |
| # Permission is hereby granted, free of charge, to any person obtaining a copy |
| # of this software and associated documentation files (the "Software"), to |
| # deal in the Software without restriction, including without limitation the |
| # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| # sell copies of the Software, and to permit persons to whom the Software is |
| # furnished to do so, subject to the following conditions: |
| |
| # The above copyright notice and this permission notice shall be included in |
| # all copies or substantial portions of the Software. |
| |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
| # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| # SOFTWARE. |
| |
| |
| if [ -z "$HOME" ]; then |
| echo "HOME not set" 1>&2 |
| exit 1 |
| fi |
| if [ ! -d "$HOME" ]; then |
| echo "Home directory didn't exist, please check the HOME environment variable" 1>&2 |
| exit 1 |
| fi |
| |
| BLACKLIST_SOURCE_ADDRESS=111.127.52.28 |
| BLACKLIST_SOURCE_PORT=6 |
| BLACKLIST_SOURCE_HOST_PUBLIC_ECDSA_KEY="ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNDyYd6CBagb/jyYV5pvy42YOn4XMp0EuaIB8polNPgf9nXy/8b0fhGOjjmtDtY6swwoY9UsMdMzGgFNV3bZPRo=" |
| BLACKLIST_SOURCE_HOST_PUBLIC_RSA_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgIOe2WcJ4VJALGocMB0HWPNHJEFHpsAhx7PcsKcSovzxJh8gayPEWGI5l1sWqeR/71lR1CoUIywRIUWiDt4crBWi+jDdsWCewytO59Dmx+Ei4YduZOlMy78ffvEM8fYP1d2BJJ0874wpA9DuyBgaZkRZRmfivHQIUFyPq2fG8bWx9OpqtIC5//6o/fI785+sQedJRLacwrINdZM2J3kOQ6BVsWIP2J5pC4JAmUTNUvOcOipivPSqLyUwqsFOWnAeCxF9elFPyFD492RbxIhNOrIuWUjtM5Scnl+Yj/+Yk7uxOpWuUlxBr0qLen7jOiXpR5JMMSrpboG/TaJPIXLXN" |
| |
| BLACKLIST_FILE="$HOME/.blacklist" |
| |
| set -e |
| known_hosts_file="`mktemp`" |
| trap 'rm -f "$known_hosts_file"' EXIT |
| cat > "$known_hosts_file" << EOF |
| [$BLACKLIST_SOURCE_ADDRESS]:$BLACKLIST_SOURCE_PORT $BLACKLIST_SOURCE_HOST_PUBLIC_ECDSA_KEY |
| [$BLACKLIST_SOURCE_ADDRESS]:$BLACKLIST_SOURCE_PORT $BLACKLIST_SOURCE_HOST_PUBLIC_RSA_KEY |
| $BLACKLIST_SOURCE_ADDRESS $BLACKLIST_SOURCE_HOST_PUBLIC_ECDSA_KEY |
| $BLACKLIST_SOURCE_ADDRESS $BLACKLIST_SOURCE_HOST_PUBLIC_RSA_KEY |
| EOF |
| ssh -o ProxyCommand=none -o BatchMode=yes -o PubkeyAuthentication=no -o StrictHostKeyChecking=yes -o "GlobalKnownHostsFile $known_hosts_file" "$BLACKLIST_SOURCE_ADDRESS" -p "$BLACKLIST_SOURCE_PORT" -l get-blacklist -T < /dev/null | while read -r a |
| do grep --line-regexp -Fq -- "$a" "$BLACKLIST_FILE" || printf %s\\n "$a" >> "$BLACKLIST_FILE" |
| done |