Skip to content

Commit 08a8da2

Browse files
dgibbs64AI Assistant
andauthored
feat: convert public ip to json (#4332)
* refactor: improve retrieval and handling of public IP address The code in `info_game.sh` has been refactored to enhance the process of retrieving and handling the public IP address. The changes include: - Using the API endpoint `http://ip-api.com/json/` instead of `https://api.ipify.org` - Storing the retrieved data in `publicip.txt` - Extracting additional information such as country and country code using `jq` These improvements aim to provide more accurate and detailed information about the public IP address. * refactor: update API URL and set default values for public IP, country, and country code The commit refactors the code by updating the API URL to remove a trailing slash. Additionally, it sets default values for the variables `publicip`, `country`, and `countrycode` when the file `${tmpdir}/publicip.txt` is not found. * feat: cache and retrieve public IP address This commit adds functionality to cache the public IP address for 24 hours. If the cached IP address is older than 24 hours or doesn't exist, a new request is made to retrieve the public IP address. The retrieved IP address is then stored in a file for future use. Additionally, if there are any errors during the retrieval process, appropriate warning messages are logged and default values are set for the IP address, country, and country code. Co-authored-by: AI Assistant <[email protected]> * feat: cache and retrieve public IP address This commit adds functionality to cache the public IP address for 24 hours. If the cached IP address is older than 24 hours or doesn't exist, a new request is made to retrieve the public IP address. The retrieved IP address is then stored in a file for future use. Additionally, if there are any errors during the retrieval process, appropriate warning messages are logged and default values are set for the IP address, country, and country code. * refactor: improve caching and logging of public IP address The code has been refactored to use a JSON file instead of a text file for caching the public IP address. The log messages have also been updated to provide more informative output. * refactor(info_messages): Remove Mailgun alert This commit refactors the `info_messages.sh` module by removing the Mailgun (email) alert functionality. The code changes remove the corresponding section that displays the Mailgun alert status in the info message script. This change simplifies and streamlines the code by eliminating unused functionality. --------- Co-authored-by: AI Assistant <[email protected]>
1 parent e0b7739 commit 08a8da2

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lgsm/modules/info_game.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,25 +2400,29 @@ elif [ "${engine}" == "unreal2" ]; then
24002400
fn_info_game_unreal2
24012401
fi
24022402

2403-
# External IP address
2404-
# Cache external IP address for 24 hours
2405-
if [ -f "${tmpdir}/publicip.txt" ]; then
2406-
if [ "$(find "${tmpdir}/publicip.txt" -mmin +1440)" ]; then
2407-
rm -f "${tmpdir:?}/publicip.txt"
2408-
fi
2409-
fi
2410-
2411-
if [ ! -f "${tmpdir}/publicip.txt" ]; then
2412-
publicip="$(curl --connect-timeout 10 -s https://api.ipify.org 2> /dev/null)"
2403+
# Public IP address
2404+
# Cache public IP address for 24 hours
2405+
if [ ! -f "${tmpdir}/publicip.json" ] || [ "$(find "${tmpdir}/publicip.json" -mmin +1440)" ]; then
2406+
apiurl="http://ip-api.com/json"
2407+
publicipresponse=$(curl -s "${apiurl}")
24132408
exitcode=$?
2414-
# if curl passes add publicip to externalip.txt
2409+
# if curl passes add publicip to publicip.json
24152410
if [ "${exitcode}" == "0" ]; then
2416-
echo "${publicip}" > "${tmpdir}/publicip.txt"
2411+
fn_script_log_pass "Getting public IP address"
2412+
echo "${publicipresponse}" > "${tmpdir}/publicip.json"
2413+
publicip="$(jq -r '.query' "${tmpdir}/publicip.json")"
2414+
country="$(jq -r '.country' "${tmpdir}/publicip.json")"
2415+
countrycode="$(jq -r '.countryCode' "${tmpdir}/publicip.json")"
24172416
else
2418-
echo "Unable to get external IP address"
2417+
fn_script_log_warn "Unable to get public IP address"
2418+
publicip="NOT SET"
2419+
country="NOT SET"
2420+
countrycode="NOT SET"
24192421
fi
24202422
else
2421-
publicip="$(cat "${tmpdir}/publicip.txt")"
2423+
publicip="$(jq -r '.query' "${tmpdir}/publicip.json")"
2424+
country="$(jq -r '.country' "${tmpdir}/publicip.json")"
2425+
countrycode="$(jq -r '.countryCode' "${tmpdir}/publicip.json")"
24222426
fi
24232427

24242428
# Alert IP address

lgsm/modules/info_messages.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ fn_info_message_script() {
506506
# Email alert: off
507507
# Gotify alert: off
508508
# IFTTT alert: off
509-
# Mailgun (email) alert: off
510509
# Pushbullet alert: off
511510
# Pushover alert: off
512511
# Rocketchat alert: off
@@ -550,8 +549,6 @@ fn_info_message_script() {
550549
echo -e "${lightblue}Gotify alert:\t${default}${gotifyalert}"
551550
# IFTTT alert
552551
echo -e "${lightblue}IFTTT alert:\t${default}${iftttalert}"
553-
# Mailgun alert
554-
echo -e "${lightblue}Mailgun (email) alert:\t${default}${mailgunalert}"
555552
# Pushbullet alert
556553
echo -e "${lightblue}Pushbullet alert:\t${default}${pushbulletalert}"
557554
# Pushover alert

0 commit comments

Comments
 (0)