command_postdetails.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # LinuxGSM command_postdetails.sh function
  3. # Author: CedarLUG
  4. # Contributor: CedarLUG
  5. # Website: https://linuxgsm.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. # Set posttarget to the appropriately-defined post destination.
  11. # The options for posttarget are:
  12. # The default destination - hastebin
  13. # posttarget="https://hastebin.com"
  14. #
  15. # Secondary destination - pastebin
  16. # posttarget="http://pastebin.com
  17. #
  18. # Third option - leave on the filesystem
  19. # posttarget=
  20. #
  21. # All of these options can be specified/overridden from the top-level
  22. # invocation, as in:
  23. # rustserver@gamerig:~$ posttarget="http://pastebin.com" ./rustserver pd
  24. # to post to pastebin, or
  25. # rustserver@gamerig:~$ posttarget= ./rustserver pd
  26. # to leave the output on the filesystem.
  27. posttarget=${posttarget="https://hastebin.com"}
  28. # For pastebin, you can set the expiration period.
  29. # use 1 week as the default, other options are '24h' for a day, etc.
  30. # This, too, may be overridden from the command line at the top-level.
  31. postexpire="${postexpire="30D"}"
  32. # source all of the functions defined in the details command.
  33. info_messages.sh
  34. fn_bad_postdetailslog() {
  35. fn_print_fail_nl "Unable to create temporary file ${postdetailslog}."
  36. core_exit.sh
  37. }
  38. # Remove any existing postdetails.log file.
  39. if [ -f "${postdetailslog}" ]; then
  40. rm -f "${postdetailslog}"
  41. fi
  42. # Rather than a one-pass sed parser, default to using a temporary directory.
  43. if [ -n "${alertflag}" ]; then
  44. postdetailslog="${alertlog}"
  45. else
  46. # Run checks and gathers details to display.
  47. check.sh
  48. info_config.sh
  49. info_parms.sh
  50. info_distro.sh
  51. info_messages.sh
  52. query_gamedig.sh
  53. touch "${postdetailslog}" || fn_bad_postdetailslog
  54. {
  55. fn_info_message_distro
  56. fn_info_message_server_resource
  57. fn_info_message_gameserver_resource
  58. fn_info_message_gameserver
  59. fn_info_message_script
  60. fn_info_message_backup
  61. # Some game servers do not have parms.
  62. if [ "${shortname}" != "ts3" ]&&[ "${shortname}" != "jc2" ]&&[ "${shortname}" != "jc3" ]&&[ "${shortname}" != "dst" ]&&[ "${shortname}" != "pz" ]&&[ "${engine}" != "renderware" ]; then
  63. fn_parms
  64. fn_info_message_commandlineparms
  65. fi
  66. fn_info_message_ports
  67. fn_info_message_select_engine
  68. fn_info_message_statusbottom
  69. } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee -a "${postdetailslog}" > /dev/null 2>&1
  70. fi
  71. if [ "${posttarget}" == "http://pastebin.com" ] ; then
  72. fn_print_dots "Posting details to pastbin.com for ${postexpire}"
  73. # grab the return from 'value' from an initial visit to pastebin.
  74. csrftoken=$(${curlpath} -s "${posttarget}" |
  75. sed -n 's/^.*input type="hidden" name="csrf_token_post" value="\(.*\)".*$/\1/p')
  76. #
  77. # Use the csrftoken to then post the content.
  78. #
  79. link=$(${curlpath} -s "${posttarget}/post.php" -D - -F "submit_hidden=submit_hidden" \
  80. -F "post_key=${csrftoken}" -F "paste_expire_date=${postexpire}" \
  81. -F "paste_name=${gamename} Debug Info" \
  82. -F "paste_format=8" -F "paste_private=0" \
  83. -F "paste_type=bash" -F "paste_code=<${postdetailslog}" |
  84. awk '/^location: / { print $2 }' | sed "s/\n//g")
  85. # Output the resulting link.
  86. fn_print_ok_nl "Posting details to pastbin.com for ${postexpire}"
  87. pdurl="${posttarget}${link}"
  88. echo " Please share the following url for support: ${pdurl}"
  89. elif [ "${posttarget}" == "https://hastebin.com" ] ; then
  90. fn_print_dots "Posting details to hastebin.com"
  91. # hastebin is a bit simpler. If successful, the returned result
  92. # should look like: {"something":"key"}, putting the reference that
  93. # we need in "key". TODO - error handling. -CedarLUG
  94. link=$(${curlpath} -H "HTTP_X_REQUESTED_WITH:XMLHttpRequest" -s -d "$(<${postdetailslog})" "${posttarget}/documents" | cut -d\" -f4)
  95. fn_print_ok_nl "Posting details to hastebin.com for ${postexpire}"
  96. pdurl="${posttarget}/${link}"
  97. echo " Please share the following url for support: ${pdurl}"
  98. elif [ "${posttarget}" == "https://termbin.com" ] ; then
  99. fn_print_dots "Posting details to termbin.com"
  100. link=$(cat "${postdetailslog}" | nc termbin.com 9999 | tr -d '\n\0')
  101. fn_print_ok_nl "Posting details to termbin.com"
  102. pdurl="${link}"
  103. echo " Please share the following url for support: ${pdurl}"
  104. else
  105. fn_print_warn_nl "Review output in: ${postdetailslog}"
  106. core_exit.sh
  107. fi
  108. if [ -z "${alertflag}" ]; then
  109. core_exit.sh
  110. else
  111. alerturl="${pdurl}"
  112. fi