Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert public ip to json #4332

Merged
merged 7 commits into from
Oct 8, 2023
Merged
32 changes: 18 additions & 14 deletions lgsm/modules/info_game.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2400,25 +2400,29 @@ elif [ "${engine}" == "unreal2" ]; then
fn_info_game_unreal2
fi

# External IP address
# Cache external IP address for 24 hours
if [ -f "${tmpdir}/publicip.txt" ]; then
if [ "$(find "${tmpdir}/publicip.txt" -mmin +1440)" ]; then
rm -f "${tmpdir:?}/publicip.txt"
fi
fi

if [ ! -f "${tmpdir}/publicip.txt" ]; then
publicip="$(curl --connect-timeout 10 -s https://api.ipify.org 2> /dev/null)"
# Public IP address
# Cache public IP address for 24 hours
if [ ! -f "${tmpdir}/publicip.json" ] || [ "$(find "${tmpdir}/publicip.json" -mmin +1440)" ]; then
apiurl="http://ip-api.com/json"
publicipresponse=$(curl -s "${apiurl}")
exitcode=$?
# if curl passes add publicip to externalip.txt
# if curl passes add publicip to publicip.json
if [ "${exitcode}" == "0" ]; then
echo "${publicip}" > "${tmpdir}/publicip.txt"
fn_script_log_pass "Getting public IP address"
echo "${publicipresponse}" > "${tmpdir}/publicip.json"
publicip="$(jq -r '.query' "${tmpdir}/publicip.json")"
country="$(jq -r '.country' "${tmpdir}/publicip.json")"
countrycode="$(jq -r '.countryCode' "${tmpdir}/publicip.json")"
else
echo "Unable to get external IP address"
fn_script_log_warn "Unable to get public IP address"
publicip="NOT SET"
country="NOT SET"
countrycode="NOT SET"
fi
else
publicip="$(cat "${tmpdir}/publicip.txt")"
publicip="$(jq -r '.query' "${tmpdir}/publicip.json")"
country="$(jq -r '.country' "${tmpdir}/publicip.json")"
countrycode="$(jq -r '.countryCode' "${tmpdir}/publicip.json")"
fi

# Alert IP address
Expand Down
3 changes: 0 additions & 3 deletions lgsm/modules/info_messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ fn_info_message_script() {
# Email alert: off
# Gotify alert: off
# IFTTT alert: off
# Mailgun (email) alert: off
# Pushbullet alert: off
# Pushover alert: off
# Rocketchat alert: off
Expand Down Expand Up @@ -550,8 +549,6 @@ fn_info_message_script() {
echo -e "${lightblue}Gotify alert:\t${default}${gotifyalert}"
# IFTTT alert
echo -e "${lightblue}IFTTT alert:\t${default}${iftttalert}"
# Mailgun alert
echo -e "${lightblue}Mailgun (email) alert:\t${default}${mailgunalert}"
# Pushbullet alert
echo -e "${lightblue}Pushbullet alert:\t${default}${pushbulletalert}"
# Pushover alert
Expand Down
Loading