cloudflare: validate new ip before saving

This commit is contained in:
Vasily Davydov 2024-07-13 21:55:54 +03:00
parent dce18d1911
commit 953a356724

View File

@ -33,6 +33,16 @@ function check_internet_access() {
function check_new_ip() {
local new_ip
new_ip="$(curl -s ${IP_URL})"
if [[ "$new_ip" =~ ^([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})$ ]]
then
for (( i=1; i<${#BASH_REMATCH[@]}; ++i ))
do
(( ${BASH_REMATCH[$i]} <= 255 )) || { "${SEND_TELEGRAM}" "Bad IP from curl. ${new_ip}" >&2; exit 1; }
done
else
"${SEND_TELEGRAM}" "Bad IP from curl. ${new_ip}" >&2
exit 1;
fi
if [[ "${new_ip}" == "${CACHED_PUBLIC_IP}" ]]; then
info "Public IP has not changed from ${new_ip}. Exiting..."
exit 0;