command_postdetails.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # LGSM command_postdetails.sh function
  3. # Author: CedarLUG
  4. # Contributor: CedarLUG
  5. # Website: https://gameservermanagers.com
  6. # Description: Strips sensitive information out of Details output
  7. local commandname="POSTDETAILS"
  8. local commandaction="Postdetails"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. # POSTDETAILS variable affects the output of command_details.sh. Setting
  11. # it here silences the output from sourcing command_details.sh.
  12. POSTDETAILS=yes
  13. # Set POSTTARGET to the appropriately-defined post destination.
  14. # The only options for POSTTARGET are
  15. #POSTTARGET="http://pastebin.com"
  16. POSTTARGET=${POSTTARGET="http://hastebin.com"}
  17. # For pastebin, you can set the expiration period.
  18. POSTEXPIRE="1W" # use 1 week as the default, other options are '24h' for a day, etc.
  19. # This file sources the command_details.sh file to leverage all
  20. # of the already-defined functions. To keep the command_details.sh
  21. # from actually producing output, the main executable statements have
  22. # been wrapped in the equivalent of an ifdef clause, that looks
  23. # for the variable "postdetails" to be defined. -CedarLUG
  24. # source all of the functions defined in the details command
  25. . ${functionsdir}/command_details.sh
  26. fn_bad_tmpfile() {
  27. echo "There was a problem creating a temporary file ${tmpfile}."
  28. core_exit.sh
  29. }
  30. # Rather than a one-pass sed parser, default to using a temporary directory
  31. posttmpdir="${lgsmdir}/tmp"
  32. # Not all game servers possess a tmp directory. So create it if
  33. # it doesn't already exist
  34. mkdir -p ${posttmpdir} 2>&1 >/dev/null
  35. tmpfile=${posttmpdir}/postdetails-$(date +"%Y-%d-%m_%H-%M-%S").tmp
  36. touch ${tmpfile} || fn_bad_tmpfile
  37. # fn_display_details is found in the command_details.sh file (which
  38. # was sourced above). The output is parsed for passwords and other
  39. # confidential information. -CedarLUG
  40. # The numerous sed lines could certainly be condensed quite a bit,
  41. # but they are separated out to provide examples for how to add
  42. # additional criteria in a straight-forward manner.
  43. # (This was originally a sed one-liner.) -CedarLUG
  44. fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' |
  45. sed -e 's/password "[^"]*/password "--stripped--/' |
  46. sed -e 's/password: .*/password: --stripped--/' |
  47. sed -e 's/gslt="[^"]*/gslt="--stripped--/' |
  48. sed -e 's/gslt "[^"]*/gslt "--stripped--/' |
  49. sed -e 's/pushbullettoken="[^"]*/pushbullettoken="--stripped--/' |
  50. sed -e 's/pushbullettoken "[^"]*/pushbullettoken "--stripped--/' |
  51. sed -e 's/authkey="[^"]*/authkey="--stripped--/' |
  52. sed -e 's/authkey "[^"]*/authkey "--stripped--/' |
  53. sed -e 's/authkey [A-Za-z0-9]\+/authkey --stripped--/' |
  54. sed -e 's/rcts_strAdminPassword="[^"]*/rcts_strAdminPassword="--stripped--/' |
  55. sed -e 's/rcts_strAdminPassword "[^"]*/rcts_strAdminPassword "--stripped--/' |
  56. sed -e 's/sv_setsteamaccount [A-Za-z0-9]\+/sv_setsteamaccount --stripped--/' |
  57. sed -e 's/sv_password="[^"]*/sv_password="--stripped--/' |
  58. sed -e 's/sv_password "[^"]*/sv_password "--stripped--/' |
  59. sed -e 's/zmq_stats_password="[^"]*/zmq_stats_password="--stripped--/' |
  60. sed -e 's/zmq_stats_password "[^"]*/zmq_stats_password "--stripped--/' |
  61. sed -e 's/zmq_rcon_password="[^"]*/zmq_rcon_password="--stripped--/' |
  62. sed -e 's/zmq_rcon_password "[^"]*/zmq_rcon_password "--stripped--/' |
  63. sed -e 's/pass="[^"]*/pass="--stripped--/' |
  64. sed -e 's/pass "[^"]*/pass "--stripped--/' |
  65. sed -e 's/rconServerPassword="[^"]*/rconServerPassword="--stripped--/' |
  66. sed -e 's/rconServerPassword "[^"]*/rconServerPassword "--stripped--/' > ${tmpfile}
  67. # strip off all console escape codes (colorization)
  68. sed -i -r "s/[\x1B,\x0B]\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ${tmpfile}
  69. # If the gameserver uses anonymous steam credentials, leave them displayed
  70. # in the output. Otherwise, strip these out as well.
  71. if ! grep -q "^steampass[= ]\"\"" ${tmpfile} ; then
  72. sed -i -e 's/steampass[= ]"[^"]*/steampass "--stripped--/' ${tmpfile}
  73. fi
  74. if ! grep -q "^steamuser[= ]\"anonymous\"" ${tmpfile} ; then
  75. sed -i -e 's/steamuser[= ]"[^"]*/steamuser "--stripped--/' ${tmpfile}
  76. fi
  77. if [ "$POSTTARGET" == "http://pastebin.com" ] ; then
  78. # grab the return from 'value' from an initial visit to pastebin.
  79. TOKEN=$(curl -s $POSTTARGET |
  80. sed -n 's/^.*input type="hidden" name="csrf_token_post" value="\(.*\)".*$/\1/p')
  81. #
  82. # Use the TOKEN to then post the content.
  83. #
  84. link=$(curl -s "$POSTTARGET/post.php" -D - -F "submit_hidden=submit_hidden" \
  85. -F "post_key=$TOKEN" -F "paste_expire_date=${POSTEXPIRE}" \
  86. -F "paste_name=${gamename} Debug Info" \
  87. -F "paste_format=8" -F "paste_private=0" \
  88. -F "paste_type=bash" -F "paste_code=<${tmpfile}" |
  89. awk '/^location: / { print $2 }' | sed "s/\n//g")
  90. # Output the resulting link.
  91. fn_print_warn_nl "Visit (and verify) the content posted at ${POSTTARGET}${link}"
  92. elif [ "$POSTTARGET" == "http://hastebin.com" ] ; then
  93. # hastebin is a bit simpler. If successful, the returned result
  94. # should look like: {"something":"key"}, putting the reference that
  95. # we need in "key". TODO - error handling. -CedarLUG
  96. link=$(curl -s -d "$(<${tmpfile})" ${POSTTARGET}/documents| cut -d\" -f4)
  97. fn_print_warn_nl "Visit (and verify) the content posted at ${POSTTARGET}/${link}"
  98. else
  99. fn_print_warn_nl "Review the output in ${tmpfile}"
  100. core_exit.sh
  101. fi
  102. # cleanup
  103. rm ${tmpfile} || /bin/true
  104. core_exit.sh