command_postdetails.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/bash -x
  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. The present
  14. # option is only pastebin, but hastebin is on the todo list (and should be
  15. # a lot easier than pastebin.
  16. #
  17. # Another reason for an alternative here is that pastebin limits guest
  18. # posts to 10 per day, which might be a tight limit for some debugging situations.
  19. #POSTTARGET="http://pastebin.com"
  20. POSTTARGET="http://hastebin.com"
  21. # POSTEXPIRE is only relevant to pastebin. If you are using
  22. # hastebin, the post expires 30 days after the last view.
  23. POSTEXPIRE="1W" # use 1 week as the default, other options are '24h' for a day, etc.
  24. # This file sources the command_details.sh file to leverage all
  25. # of the already-defined functions. To keep the command_details.sh
  26. # from actually producing output, the main executable statements have
  27. # been wrapped in the equivalent of an ifdef clause, that looks
  28. # for the variable "postdetails" to be defined. -CedarLUG
  29. # source all of the functions defined in the details command
  30. . ${functionsdir}/command_details.sh
  31. fn_bad_tmpfile() {
  32. echo "There was a problem creating a temporary file ${tmpfile}."
  33. core_exit.sh
  34. }
  35. fn_gen_rand() {
  36. # This is just a simple random generator to generate a random
  37. # name for storing the output. Named pipes would (possibly) be
  38. # better. -CedarLUG
  39. #
  40. # len holds the number of digits in our random string
  41. local len=$1
  42. # If not specified, default to 10.
  43. : {len:=10}
  44. # Quick generator for a random filename, pulled from /dev/urandom
  45. tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${len} | xargs
  46. }
  47. # Rather than a one-pass sed parser, default to using a temporary directory
  48. filedir="${lgsmdir}/tmp"
  49. # Not all game servers possess a tmp directory. So create it if
  50. # it doesn't already exist
  51. mkdir -p ${filedir} 2>&1 >/dev/null
  52. tmpfile=${filedir}/$(fn_gen_rand 10).tmp
  53. touch ${tmpfile} || fn_bad_tmpfile
  54. # fn_display_details is found in the command_details.sh file (which
  55. # was sourced above. The output is parsed for passwords and other
  56. # confidential information. -CedarLUG
  57. # The numerous sed lines could certainly be condensed quite a bit,
  58. # but they are separated out to provide examples for how to add
  59. # additional criteria in a straight-forward manner.
  60. # (This was originally a sed one-liner.) -CedarLUG
  61. fn_display_details | sed -e 's/password="[^"]*/password="--stripped--/' |
  62. sed -e 's/password "[^"]*/password "--stripped--/' |
  63. sed -e 's/password: .*/password: --stripped--/' |
  64. sed -e 's/gslt="[^"]*/gslt="--stripped--/' |
  65. sed -e 's/gslt "[^"]*/gslt "--stripped--/' |
  66. sed -e 's/pushbullettoken="[^"]*/pushbullettoken="--stripped--/' |
  67. sed -e 's/pushbullettoken "[^"]*/pushbullettoken "--stripped--/' |
  68. sed -e 's/authkey="[^"]*/authkey="--stripped--/' |
  69. sed -e 's/authkey "[^"]*/authkey "--stripped--/' |
  70. sed -e 's/authkey [A-Za-z0-9]\+/authkey --stripped--/' |
  71. sed -e 's/rcts_strAdminPassword="[^"]*/rcts_strAdminPassword="--stripped--/' |
  72. sed -e 's/rcts_strAdminPassword "[^"]*/rcts_strAdminPassword "--stripped--/' |
  73. sed -e 's/sv_setsteamaccount [A-Za-z0-9]\+/sv_setsteamaccount --stripped--/' |
  74. sed -e 's/sv_password="[^"]*/sv_password="--stripped--/' |
  75. sed -e 's/sv_password "[^"]*/sv_password "--stripped--/' |
  76. sed -e 's/zmq_stats_password="[^"]*/zmq_stats_password="--stripped--/' |
  77. sed -e 's/zmq_stats_password "[^"]*/zmq_stats_password "--stripped--/' |
  78. sed -e 's/zmq_rcon_password="[^"]*/zmq_rcon_password="--stripped--/' |
  79. sed -e 's/zmq_rcon_password "[^"]*/zmq_rcon_password "--stripped--/' |
  80. sed -e 's/pass="[^"]*/pass="--stripped--/' |
  81. sed -e 's/pass "[^"]*/pass "--stripped--/' |
  82. sed -e 's/rconServerPassword="[^"]*/rconServerPassword="--stripped--/' |
  83. sed -e 's/rconServerPassword "[^"]*/rconServerPassword "--stripped--/' > ${tmpfile}
  84. # strip off all console escape codes (colorization)
  85. sed -i -r "s/[\x1B,\x0B]\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ${tmpfile}
  86. # If the gameserver uses anonymous steam credentials, leave them displayed
  87. # in the output. Otherwise, strip these out as well.
  88. if ! grep -q "^steampass[= ]\"\"" ${tmpfile} ; then
  89. sed -i -e 's/steampass[= ]"[^"]*/steampass "--stripped--/' ${tmpfile}
  90. fi
  91. if ! grep -q "^steamuser[= ]\"anonymous\"" ${tmpfile} ; then
  92. sed -i -e 's/steamuser[= ]"[^"]*/steamuser "--stripped--/' ${tmpfile}
  93. fi
  94. if [ "$POSTTARGET" == "http://pastebin.com" ] ; then
  95. # grab the return from 'value' from an initial visit to pastebin.
  96. TOKEN=$(curl -s $POSTTARGET |
  97. sed -n 's/^.*input type="hidden" name="csrf_token_post" value="\(.*\)".*$/\1/p')
  98. #
  99. # Use the TOKEN to then post the content.
  100. #
  101. link=$(curl -s "$POSTTARGET/post.php" -D - -F "submit_hidden=submit_hidden" \
  102. -F "post_key=$TOKEN" -F "paste_expire_date=${POSTEXPIRE}" \
  103. -F "paste_name=${gamename} Debug Info" \
  104. -F "paste_format=8" -F "paste_private=0" \
  105. -F "paste_type=bash" -F "paste_code=<${tmpfile}" |
  106. awk '/^location: / { print $2 }' | sed "s/\n//g")
  107. # Output the resulting link.
  108. fn_print_warn_nl "You now need to visit (and verify) the content posted at ${POSTTARGET}${link}"
  109. elif [ "$POSTTARGET" == "http://hastebin.com" ] ; then
  110. # hastebin is a bit simpler. If successful, the returned result
  111. # should look like: {"something":"key"}, putting the reference that
  112. # we need in "key". TODO - error handling. -CedarLUG
  113. link=$(curl -s -d "$(<${tmpfile}) | cut -d\" -f4)
  114. fn_print_warn_nl "You now need to visit (and verify) the content posted at ${POSTTARGET}${link}"
  115. fi
  116. # cleanup
  117. rm ${tmpfile} || /bin/true
  118. core_exit.sh