From 907490d8fea00a22f9f88abab33b0d72f9b78765 Mon Sep 17 00:00:00 2001 From: CedarLUG Date: Wed, 24 Aug 2016 20:24:16 -0500 Subject: [PATCH 1/5] First-pass at post-details functionality. --- lgsm/functions/command_details.sh | 131 ++++++++++++++------------ lgsm/functions/command_postdetails.sh | 47 +++++++++ lgsm/functions/core_functions.sh | 9 ++ lgsm/functions/core_getopt.sh | 5 + 4 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 lgsm/functions/command_postdetails.sh diff --git a/lgsm/functions/command_details.sh b/lgsm/functions/command_details.sh index fb3531cc3..dfa2aeff9 100644 --- a/lgsm/functions/command_details.sh +++ b/lgsm/functions/command_details.sh @@ -580,66 +580,73 @@ fn_details_ark(){ # Run checks and gathers details to display. -check.sh -info_config.sh -info_distro.sh -info_glibc.sh -info_parms.sh -fn_details_os -fn_details_performance -fn_details_disk -fn_details_gameserver -fn_details_script -fn_details_backup -# Some game servers do not have parms. -if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${engine}" != "avalanche" ]&&[ "${engine}" != "dontstarve" ]&&[ "${engine}" != "projectzomboid" ]; then - fn_parms - fn_details_commandlineparms -fi -fn_details_ports - -# Display details depending on game or engine. -if [ "${engine}" == "avalanche" ]; then - fn_details_avalanche -elif [ "${engine}" == "dontstarve" ]; then - fn_details_dontstarve -elif [ "${engine}" == "lwjgl2" ]; then - fn_details_minecraft -elif [ "${engine}" == "projectzomboid" ]; then - fn_details_projectzomboid -elif [ "${engine}" == "idtech3" ]; then - fn_details_idtech3 -elif [ "${engine}" == "realvirtuality" ]; then - fn_details_realvirtuality -elif [ "${engine}" == "seriousengine35" ]; then - fn_details_seriousengine35 -elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then - fn_details_source -elif [ "${engine}" == "spark" ]; then - fn_details_spark -elif [ "${engine}" == "starbound" ]; then - fn_details_starbound -elif [ "${engine}" == "teeworlds" ]; then - fn_details_teeworlds -elif [ "${engine}" == "terraria" ]; then - fn_details_terraria -elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then - fn_details_unreal -elif [ "${gamename}" == "ARK: Survivial Evolved" ]; then - fn_details_ark -elif [ "${gamename}" == "Hurtworld" ]; then - fn_details_hurtworld -elif [ "${gamename}" == "7 Days To Die" ]; then - fn_details_sdtd -elif [ "${gamename}" == "TeamSpeak 3" ]; then - fn_details_teamspeak3 -elif [ "${gamename}" == "Mumble" ]; then - fn_details_mumble -elif [ "${gamename}" == "Rust" ]; then - fn_details_rust -else - fn_print_error_nl "Unable to detect server engine." -fi -fn_details_statusbottom -core_exit.sh +fn_display_details() { + check.sh + info_config.sh + info_distro.sh + info_glibc.sh + info_parms.sh + fn_details_os + fn_details_performance + fn_details_disk + fn_details_gameserver + fn_details_script + fn_details_backup + # Some game servers do not have parms. + if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${engine}" != "avalanche" ]&&[ "${engine}" != "dontstarve" ]&&[ "${engine}" != "projectzomboid" ]; then + fn_parms + fn_details_commandlineparms + fi + fn_details_ports + # Display details depending on game or engine. + if [ "${engine}" == "avalanche" ]; then + fn_details_avalanche + elif [ "${engine}" == "dontstarve" ]; then + fn_details_dontstarve + elif [ "${engine}" == "lwjgl2" ]; then + fn_details_minecraft + elif [ "${engine}" == "projectzomboid" ]; then + fn_details_projectzomboid + elif [ "${engine}" == "idtech3" ]; then + fn_details_idtech3 + elif [ "${engine}" == "realvirtuality" ]; then + fn_details_realvirtuality + elif [ "${engine}" == "seriousengine35" ]; then + fn_details_seriousengine35 + elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then + fn_details_source + elif [ "${engine}" == "spark" ]; then + fn_details_spark + elif [ "${engine}" == "starbound" ]; then + fn_details_starbound + elif [ "${engine}" == "teeworlds" ]; then + fn_details_teeworlds + elif [ "${engine}" == "terraria" ]; then + fn_details_terraria + elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then + fn_details_unreal + elif [ "${gamename}" == "ARK: Survivial Evolved" ]; then + fn_details_ark + elif [ "${gamename}" == "Hurtworld" ]; then + fn_details_hurtworld + elif [ "${gamename}" == "7 Days To Die" ]; then + fn_details_sdtd + elif [ "${gamename}" == "TeamSpeak 3" ]; then + fn_details_teamspeak3 + elif [ "${gamename}" == "Mumble" ]; then + fn_details_mumble + elif [ "${gamename}" == "Rust" ]; then + fn_details_rust + else + fn_print_error_nl "Unable to detect server engine." + fi + + fn_details_statusbottom +} + +if [ -z $postdetails ] ; +then + fn_display_details + core_exit.sh +fi diff --git a/lgsm/functions/command_postdetails.sh b/lgsm/functions/command_postdetails.sh new file mode 100644 index 000000000..c5b852a52 --- /dev/null +++ b/lgsm/functions/command_postdetails.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# LGSM command_details.sh function +# Author: Daniel Gibbs +# Contributor: UltimateByte +# Website: https://gameservermanagers.com +# Description: Displays server information. + +local commandname="POSTDETAILS" +local commandaction="Postdetails" +local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" + +postdetails=yes + +# source all of the functions defined in the details command +. ${functionsdir}/command_details.sh + +#INPUT="$( Date: Sun, 28 Aug 2016 15:16:16 -0500 Subject: [PATCH 2/5] Rolling in pastebin post functionality. Removing escape sequences from the output Leveraging tmp space for multi-pass processing. --- lgsm/functions/command_details.sh | 2 +- lgsm/functions/command_postdetails.sh | 92 ++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/lgsm/functions/command_details.sh b/lgsm/functions/command_details.sh index dfa2aeff9..95b174b31 100644 --- a/lgsm/functions/command_details.sh +++ b/lgsm/functions/command_details.sh @@ -645,7 +645,7 @@ fn_display_details() { fn_details_statusbottom } -if [ -z $postdetails ] ; +if [ -z ${POSTDETAILS} ] ; then fn_display_details core_exit.sh diff --git a/lgsm/functions/command_postdetails.sh b/lgsm/functions/command_postdetails.sh index c5b852a52..80c9af1ec 100644 --- a/lgsm/functions/command_postdetails.sh +++ b/lgsm/functions/command_postdetails.sh @@ -1,30 +1,64 @@ -#!/bin/bash -# LGSM command_details.sh function -# Author: Daniel Gibbs -# Contributor: UltimateByte +#!/bin/bash -x +# LGSM command_postdetails.sh function +# Author: CedarLUG +# Contributor: CedarLUG # Website: https://gameservermanagers.com -# Description: Displays server information. +# Description: Strips sensitive information out of Details output local commandname="POSTDETAILS" local commandaction="Postdetails" local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" -postdetails=yes +fn_bad_tmpfile() { + echo "There was a problem creating a temporary file ${tmpfile}." + core_exit.sh +} + +fn_gen_rand() { + # This is just a simple random generator to generate a random + # name for storing the output. Named pipes would (possibly) be + # better. -CedarLUG + # + # l holds the number of digits in our random string + local len=$1 + # If not specified, default to 10. + : {len:=10} + # Quick generator for a random filename, pulled from /dev/urandom + tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${len} | xargs +} + +# This file sources the command_details.sh file to leverage all +# of the already-defined functions. To keep the command_details.sh +# from actually producing output, the main executable statements have +# been wrapped in the equivalent of an ifdef clause, that looks +# for the variable "postdetails" to be defined. -CedarLUG + +POSTDETAILS=yes +POSTTARGET=http://pastebin.com +POSTEXPIRE="1W" # use 1 week as the default, other options are '24h' for a day, etc. # source all of the functions defined in the details command . ${functionsdir}/command_details.sh -#INPUT="$(&1 >/dev/null +tmpfile=${filedir}/$(fn_gen_rand 10).tmp + +touch ${tmpfile} || fn_bad_tmpfile + +# fn_display_details is found in the command_details.sh file (which +# was sourced above. The output is parsed for passwords and other +# confidential information. -CedarLUG fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' | sed -e 's/password "[^"]*/password "--stripped--/' | sed -e 's/password: .*/password: --stripped--/' | sed -e 's/gslt="[^"]*/gslt="--stripped--/' | sed -e 's/gslt "[^"]*/gslt "--stripped--/' | - sed -e 's/steamuser="[^"]*/steamuser="--stripped--/' | - sed -e 's/steamuser "[^"]*/steamuser "--stripped--/' | - sed -e 's/steampass="[^"]*/steampass="--stripped--/' | - sed -e 's/steampass "[^"]*/steampass "--stripped--/' | sed -e 's/pushbullettoken="[^"]*/pushbullettoken="--stripped--/' | sed -e 's/pushbullettoken "[^"]*/pushbullettoken "--stripped--/' | sed -e 's/authkey="[^"]*/authkey="--stripped--/' | @@ -40,8 +74,36 @@ fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' | sed -e 's/pass="[^"]*/pass="--stripped--/' | sed -e 's/pass "[^"]*/pass "--stripped--/' | sed -e 's/rconServerPassword="[^"]*/rconServerPassword="--stripped--/' | - sed -e 's/rconServerPassword "[^"]*/rconServerPassword "--stripped--/' - -#querystring="paste_private=0&paste_name=${NAME}&paste_code=${INPUT}" -#curl -d "${querystring}" http://pastebin.com/api_public.php + sed -e 's/rconServerPassword "[^"]*/rconServerPassword "--stripped--/' > ${tmpfile} + + +# strip off all console escape codes (colorization) + +sed -i -r "s/[\x1B,\x0B]\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ${tmpfile} + +if ! grep -q "^steampass[= ]\"\"" ${tmpfile} ; then + sed -i -e 's/steampass[= ]"[^"]*/steampass "--stripped--/' ${tmpfile} +fi + +if ! grep -q "^steamuser[= ]\"anonymous\"" ${tmpfile} ; then + sed -i -e 's/steamuser[= ]"[^"]*/steamuser "--stripped--/' ${tmpfile} +fi + +if [ "$POSTTARGET" == "http://pastebin.com" ] ; then + # grab the return from 'value' from an initial visit to pastebin. + TOKEN=$(curl -s $POSTTARGET | sed -n 's/^.*input type="hidden" name="csrf_token_post" value="\(.*\)".*$/\1/p') + # + # Use the TOKEN to then post the content. + # + link=$(curl -s "$POSTTARGET/post.php" -D - -F "submit_hidden=submit_hidden" \ + -F "post_key=$TOKEN" -F "paste_expire_date=${POSTEXPIRE}" \ + -F "paste_name=LGSM Debug post" \ + -F "paste_format=8" -F "paste_private=0" \ + -F "paste_type=bash" -F "paste_code=<${tmpfile}" | + awk '/^location: / { print $2 }' | sed "s/\n//g") + fn_print_warn_nl "You now need to visit (and verify) the content posted at ${POSTTARGET}${link}" +fi + +rm ${tmpfile} || /bin/true + core_exit.sh From 316ea7ab16c0a5f2fcc8de3dd3c3d254cb0193ba Mon Sep 17 00:00:00 2001 From: CedarLUG Date: Sun, 28 Aug 2016 15:22:14 -0500 Subject: [PATCH 3/5] Adding postdetails to wherever details is an option. --- lgsm/functions/core_getopt.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index d27d41e99..30df7d778 100644 --- a/lgsm/functions/core_getopt.sh +++ b/lgsm/functions/core_getopt.sh @@ -131,6 +131,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}change-password\t${default}pw |Changes TS3 serveradmin password." echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}install\t${default}i |Install the server." @@ -192,6 +193,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful infomation about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server." echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal." @@ -248,6 +250,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}install\t${default}i |Install the server." } | column -s $'\t' -t @@ -316,6 +319,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server." echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal." @@ -378,6 +382,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server." echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal." @@ -451,6 +456,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server." echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal." @@ -516,6 +522,7 @@ case "${getopt}" in echo -e "${blue}monitor\t${default}m |Checks that the server is running." echo -e "${blue}test-alert\t${default}ta |Sends test alert." echo -e "${blue}details\t${default}dt |Displays useful information about the server." + echo -e "${blue}postdetails\t${default}pd | Post stripped details to pastebin (for support)" echo -e "${blue}backup\t${default}b |Create archive of the server." echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server." echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal." From 377eafdafb4f1fd41834529b08e3f6aabba9b073 Mon Sep 17 00:00:00 2001 From: CedarLUG Date: Sun, 28 Aug 2016 15:57:38 -0500 Subject: [PATCH 4/5] Tweaking sv_setsteamaccount --- lgsm/functions/command_postdetails.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lgsm/functions/command_postdetails.sh b/lgsm/functions/command_postdetails.sh index 80c9af1ec..ff7a1d146 100644 --- a/lgsm/functions/command_postdetails.sh +++ b/lgsm/functions/command_postdetails.sh @@ -65,6 +65,7 @@ fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' | sed -e 's/authkey "[^"]*/authkey "--stripped--/' | sed -e 's/rcts_strAdminPassword="[^"]*/rcts_strAdminPassword="--stripped--/' | sed -e 's/rcts_strAdminPassword "[^"]*/rcts_strAdminPassword "--stripped--/' | + sed -e 's/sv_setsteamaccount [A-Za-z0-9]\+/sv_setsteamaccount --stripped--/' | sed -e 's/sv_password="[^"]*/sv_password="--stripped--/' | sed -e 's/sv_password "[^"]*/sv_password "--stripped--/' | sed -e 's/zmq_stats_password="[^"]*/zmq_stats_password="--stripped--/' | From e28e38c418d4b7c9513cbbdd700db1034beacd23 Mon Sep 17 00:00:00 2001 From: CedarLUG Date: Sun, 28 Aug 2016 19:09:49 -0500 Subject: [PATCH 5/5] Moving things around a bit in the postdetails script, and adding an additional set for authkey (where it doesn't have quotes) --- lgsm/functions/command_postdetails.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lgsm/functions/command_postdetails.sh b/lgsm/functions/command_postdetails.sh index ff7a1d146..839aa1626 100644 --- a/lgsm/functions/command_postdetails.sh +++ b/lgsm/functions/command_postdetails.sh @@ -9,6 +9,19 @@ local commandname="POSTDETAILS" local commandaction="Postdetails" local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" +POSTDETAILS=yes +POSTTARGET=http://pastebin.com +POSTEXPIRE="1W" # use 1 week as the default, other options are '24h' for a day, etc. + +# This file sources the command_details.sh file to leverage all +# of the already-defined functions. To keep the command_details.sh +# from actually producing output, the main executable statements have +# been wrapped in the equivalent of an ifdef clause, that looks +# for the variable "postdetails" to be defined. -CedarLUG + +# source all of the functions defined in the details command +. ${functionsdir}/command_details.sh + fn_bad_tmpfile() { echo "There was a problem creating a temporary file ${tmpfile}." core_exit.sh @@ -27,19 +40,6 @@ fn_gen_rand() { tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${len} | xargs } -# This file sources the command_details.sh file to leverage all -# of the already-defined functions. To keep the command_details.sh -# from actually producing output, the main executable statements have -# been wrapped in the equivalent of an ifdef clause, that looks -# for the variable "postdetails" to be defined. -CedarLUG - -POSTDETAILS=yes -POSTTARGET=http://pastebin.com -POSTEXPIRE="1W" # use 1 week as the default, other options are '24h' for a day, etc. - -# source all of the functions defined in the details command -. ${functionsdir}/command_details.sh - # Rather than a one-pass sed parser, default to using a temporary directory filedir="${lgsmdir}/tmp" @@ -63,6 +63,7 @@ fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' | sed -e 's/pushbullettoken "[^"]*/pushbullettoken "--stripped--/' | sed -e 's/authkey="[^"]*/authkey="--stripped--/' | sed -e 's/authkey "[^"]*/authkey "--stripped--/' | + sed -e 's/authkey [A-Za-z0-9]\+/authkey --stripped--/' | sed -e 's/rcts_strAdminPassword="[^"]*/rcts_strAdminPassword="--stripped--/' | sed -e 's/rcts_strAdminPassword "[^"]*/rcts_strAdminPassword "--stripped--/' | sed -e 's/sv_setsteamaccount [A-Za-z0-9]\+/sv_setsteamaccount --stripped--/' |