From 8d17622af3d24bfe120cd8a3296ac7d0908e9a3e Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 8 Jan 2025 18:22:16 +0000 Subject: [PATCH] feat: add ismygameserver.online links (#4742) --- lgsm/modules/alert_discord.sh | 97 +++------------------------ lgsm/modules/alert_gotify.sh | 34 ++++++---- lgsm/modules/alert_ifttt.sh | 34 ++++++---- lgsm/modules/alert_pushbullet.sh | 35 +++++----- lgsm/modules/alert_pushover.sh | 24 +++++-- lgsm/modules/alert_rocketchat.sh | 34 +++++++--- lgsm/modules/alert_slack.sh | 38 ++++++++--- lgsm/modules/alert_telegram.sh | 37 +++++----- lgsm/modules/check_permissions.sh | 4 +- lgsm/modules/command_dev_query_raw.sh | 4 ++ lgsm/modules/info_messages.sh | 33 +++++++++ 11 files changed, 205 insertions(+), 169 deletions(-) diff --git a/lgsm/modules/alert_discord.sh b/lgsm/modules/alert_discord.sh index 93eda8d5bd..3b489984d1 100644 --- a/lgsm/modules/alert_discord.sh +++ b/lgsm/modules/alert_discord.sh @@ -7,7 +7,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "username": "LinuxGSM", @@ -29,103 +29,32 @@ jsoninfo=$( "url": "${alerticon}" }, "fields": [ - { - "name": "Server Name", - "value": "${servername}" - }, - { - "name": "Information", - "value": "${alertmessage}" - }, { - "name": "Game", - "value": "${gamename}", - "inline": true + "name": "Server Name", + "value": "${servername}" }, { - "name": "Server IP", - "value": "\`${alertip}:${port}\`", - "inline": true - }, - { - "name": "Hostname", - "value": "${HOSTNAME}", - "inline": true + "name": "Information", + "value": "${alertmessage}" }, - { - "name": "More info", - "value": "${alerturl}", - "inline": true - }, - { - "name": "Server Time", - "value": "$(date)", - "inline": true - } - ], - "footer": { - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "text": "Sent by LinuxGSM ${version}" - } - } - ] -} -EOF -) - -jsonnoinfo=$( - cat << EOF -{ - "username": "LinuxGSM", - "avatar_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "file": "content", - "embeds": [ - { - "author": { - "name": "LinuxGSM Alert", - "url": "", - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg" - }, - "title": "${alerttitle}", - "url": "", - "description": "", - "color": "${alertcolourdec}", - "type": "content", - "thumbnail": { - "url": "${alerticon}" - }, - "fields": [ - { - "name": "Server Name", - "value": "${servername}" - }, - { - "name": "Information", - "value": "${alertmessage}" - }, { "name": "Game", "value": "${gamename}", "inline": true }, { - "name": "Server IP", - "value": "\`${alertip}:${port}\`", - "inline": true - }, - { - "name": "Hostname", - "value": "${HOSTNAME}", + "name": "Server Time", + "value": "$(date)", "inline": true }, { - "name": "Server Time", - "value": "$(date)", + "name": "Is my Game Server Online?", + "value": "https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}", "inline": true } ], "footer": { - "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", + "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", "text": "Sent by LinuxGSM ${version}" } } @@ -136,12 +65,6 @@ EOF fn_print_dots "Sending Discord alert" -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - discordsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${discordwebhook}") if [ -n "${discordsend}" ]; then diff --git a/lgsm/modules/alert_gotify.sh b/lgsm/modules/alert_gotify.sh index dcb438fb2e..2f627c774c 100644 --- a/lgsm/modules/alert_gotify.sh +++ b/lgsm/modules/alert_gotify.sh @@ -7,32 +7,38 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "title": "${alerttitle}", - "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)", - "priority": 5 -} + "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n EOF ) -jsonnoinfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF +Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF +More info\n${alerturl}\n\n +EOF + ) +fi + +json+=$( cat << EOF -{ - "title": "${alerttitle}", - "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)", +Server Time\n$(date)", "priority": 5 } EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending Gotify alert" gotifysend=$(curl --connect-timeout 3 -sSL "${gotifywebhook}/message"?token="${gotifytoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)") diff --git a/lgsm/modules/alert_ifttt.sh b/lgsm/modules/alert_ifttt.sh index ca1c005d0d..aaae3b4e8f 100644 --- a/lgsm/modules/alert_ifttt.sh +++ b/lgsm/modules/alert_ifttt.sh @@ -7,32 +7,38 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "value1": "${selfname}", "value2": "${alerttitle}", - "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)" -} + "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n EOF ) -jsonnoinfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF +Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF +More info\n${alerturl}\n\n +EOF + ) +fi + +json+=$( cat << EOF -{ - "value1": "${selfname}", - "value2": "${alerttitle}", - "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)" +Server Time\n$(date)" } EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending IFTTT alert" iftttsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://maker.ifttt.com/trigger/${iftttevent}/with/key/${ifttttoken}" | grep "Bad Request") diff --git a/lgsm/modules/alert_pushbullet.sh b/lgsm/modules/alert_pushbullet.sh index 4b96a1f9fe..abdfa0bb25 100644 --- a/lgsm/modules/alert_pushbullet.sh +++ b/lgsm/modules/alert_pushbullet.sh @@ -7,34 +7,39 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "channel_tag": "${channeltag}", "type": "note", "title": "${alerttitle}", - "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)" -} + "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n EOF ) -jsonnoinfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF +Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF +More info\n${alerturl}\n\n +EOF + ) +fi + +json+=$( cat << EOF -{ - "channel_tag": "${channeltag}", - "type": "note", - "title": "${alerttitle}", - "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)" +Server Time\n$(date)" } EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending Pushbullet alert" pushbulletsend=$(curl --connect-timeout 3 -sSL -H "Access-Token: ${pushbullettoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code") diff --git a/lgsm/modules/alert_pushover.sh b/lgsm/modules/alert_pushover.sh index dc488026af..8dc0ce2dc3 100644 --- a/lgsm/modules/alert_pushover.sh +++ b/lgsm/modules/alert_pushover.sh @@ -22,12 +22,28 @@ else alertpriority="0" fi -if [ -z "${alerturl}" ]; then - pushoversend=$(curl --connect-timeout 3 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

Server Time
$(date)" "https://api.pushover.net/1/messages.json" | grep errors) -else - pushoversend=$(curl --connect-timeout 3 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

More info
${alerturl}

Server Time
$(date)" "https://api.pushover.net/1/messages.json" | grep errors) +message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

" + +if [ -n "${querytype}" ]; then + message+="Is my Game Server Online?
Check here

" +fi + +if [ -n "${alerturl}" ]; then + message+="More info
${alerturl}

" fi +message+="Server Time
$(date)" + +pushoversend=$(curl --connect-timeout 3 -sS \ + -F token="${pushovertoken}" \ + -F user="${pushoveruserkey}" \ + -F html="1" \ + -F sound="${alertsound}" \ + -F priority="${alertpriority}" \ + -F title="${alerttitle}" \ + -F message="${message}" \ + "https://api.pushover.net/1/messages.json" | grep errors) + if [ -n "${pushoversend}" ]; then fn_print_fail_nl "Sending Pushover alert: ${pushoversend}" fn_script_log_fail "Sending Pushover alert: ${pushoversend}" diff --git a/lgsm/modules/alert_rocketchat.sh b/lgsm/modules/alert_rocketchat.sh index bff2c6a0ba..35bcf49286 100644 --- a/lgsm/modules/alert_rocketchat.sh +++ b/lgsm/modules/alert_rocketchat.sh @@ -7,7 +7,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "alias": "LinuxGSM", @@ -64,7 +64,31 @@ jsoninfo=$( EOF ) -jsonnoinfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF + { + "short": false, + "title": "Is my Game Server Online?", + "value": "" + }, +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF + { + "short": false, + "title": "More info", + "value": "${alerturl}" + }, +EOF + ) +fi + +json+=$( cat << EOF { "alias": "LinuxGSM", @@ -116,12 +140,6 @@ jsonnoinfo=$( EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending Rocketchat alert" rocketchatsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}") diff --git a/lgsm/modules/alert_slack.sh b/lgsm/modules/alert_slack.sh index 58dc547724..0a1e9015e0 100644 --- a/lgsm/modules/alert_slack.sh +++ b/lgsm/modules/alert_slack.sh @@ -7,7 +7,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsonnoinfo=$( +json=$( cat << EOF { "attachments": [ @@ -87,7 +87,35 @@ jsonnoinfo=$( EOF ) -jsoninfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Is my Game Server Online?*\n" + } + }, +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*More info*\n<${alerturl}|${alerturl}>" + } + }, +EOF + ) +fi + +json+=$( cat << EOF { "attachments": [ @@ -174,12 +202,6 @@ jsoninfo=$( EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending Slack alert" slacksend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${slackwebhook}") diff --git a/lgsm/modules/alert_telegram.sh b/lgsm/modules/alert_telegram.sh index 2e719dba77..d7c9b84472 100644 --- a/lgsm/modules/alert_telegram.sh +++ b/lgsm/modules/alert_telegram.sh @@ -7,38 +7,41 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -jsoninfo=$( +json=$( cat << EOF { "chat_id": "${telegramchatid}", "message_thread_id": "${telegramthreadid}", "parse_mode": "HTML", "disable_notification": "${telegramdisablenotification}", - "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)", - "disable_web_page_preview": "yes" -} + "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n EOF ) -jsonnoinfo=$( +if [ -n "${querytype}" ]; then + json+=$( + cat << EOF +Is my Game Server Online?\nCheck here\n\n +EOF + ) +fi + +if [ -n "${alerturl}" ]; then + json+=$( + cat << EOF +More info\n${alerturl}\n\n +EOF + ) +fi + +json+=$( cat << EOF -{ - "chat_id": "${telegramchatid}", - "message_thread_id": "${telegramthreadid}", - "parse_mode": "HTML", - "disable_notification": "${telegramdisablenotification}", - "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)", +Server Time\n$(date)", "disable_web_page_preview": "yes" } EOF ) -if [ -z "${alerturl}" ]; then - json="${jsonnoinfo}" -else - json="${jsoninfo}" -fi - fn_print_dots "Sending Telegram alert" telegramsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" ${curlcustomstring} "https://${telegramapi}/bot${telegramtoken}/sendMessage" | grep "error_code") diff --git a/lgsm/modules/check_permissions.sh b/lgsm/modules/check_permissions.sh index 9ed1bb65e9..4004732f2c 100644 --- a/lgsm/modules/check_permissions.sh +++ b/lgsm/modules/check_permissions.sh @@ -63,8 +63,8 @@ fn_check_permissions() { findnotexecutable="$(find "${modulesdir}" -type f -not -executable)" findnotexecutablewc="$(find "${modulesdir}" -type f -not -executable | wc -l)" if [ "${findnotexecutablewc}" -ne "0" ]; then - fn_print_fail_nl "Permissions issues found" - fn_script_log_fail "Permissions issues found" + fn_print_error_nl "Permissions issues found" + fn_script_log_error "Permissions issues found" fn_print_information_nl "The following files are not executable:" fn_script_log_info "The following files are not executable:" { diff --git a/lgsm/modules/command_dev_query_raw.sh b/lgsm/modules/command_dev_query_raw.sh index ebe54c40fd..a27850df88 100644 --- a/lgsm/modules/command_dev_query_raw.sh +++ b/lgsm/modules/command_dev_query_raw.sh @@ -208,6 +208,10 @@ echo -e "" echo -e "PORT: ${port}" echo -e "QUERY PORT: ${queryport}" echo -e "" +echo -e "${lightgreen}Is My Game Server Online?${default}" +fn_messages_separator +echo -e "Game server status: https://ismygameserver.online/${imgsoquerytype}/${queryip}:${queryport}" +echo -e "" echo -e "${lightgreen}Gamedig Raw Output${default}" fn_messages_separator echo -e "" diff --git a/lgsm/modules/info_messages.sh b/lgsm/modules/info_messages.sh index e47f5dd083..fd6ebc4473 100644 --- a/lgsm/modules/info_messages.sh +++ b/lgsm/modules/info_messages.sh @@ -7,6 +7,29 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" +# Converts querytype to imgsoquerytype for use with ismygameserver.online urls +if [ -n "${querytype}" ]; then + if [ "${querytype}" == "protocol-valve" ]; then + imgsoquerytype="valve" + elif [ "${querytype}" == "protocol-gamespy1" ]; then + imgsoquerytype="gamespy" + elif [ "${querytype}" == "protocol-gamespy2" ]; then + imgsoquerytype="gamespy" + elif [ "${querytype}" == "protocol-gamespy3" ]; then + imgsoquerytype="gamespy" + elif [ "${querytype}" == "protocol-quake1" ]; then + imgsoquerytype="quake" + elif [ "${querytype}" == "protocol-quake2" ]; then + imgsoquerytype="quake" + elif [ "${querytype}" == "protocol-quake3" ]; then + imgsoquerytype="quake" + elif [ "${querytype}" == "protocol-unreal2" ]; then + imgsoquerytype="unrealtournament2004" + else + imgsoquerytype="${querytype}" + fi +fi + # Removes the passwords form all but details. fn_info_messages_password_strip() { if [ "${commandname}" != "DETAILS" ]; then @@ -66,6 +89,11 @@ fn_info_messages_head() { echo -e "Hostname" echo -e "${HOSTNAME}" echo -e "" + if [ -n "${querytype}" ]; then + echo -e "Is my Game Server Online?" + echo -e "https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}" + echo -e "" + fi echo -e "Server Time" echo -e "$(date)" } @@ -503,6 +531,11 @@ fn_info_messages_gameserver() { else echo -e "${lightblue}Status:\t${green}STARTED${default}" fi + + # ismygameserver.online + if [ -n "${querytype}" ]; then + echo -e "${lightblue}Query Check:\t${default}https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}" + fi } | column -s $'\t' -t echo -e "" }