command_postdetails.sh 4.3 KB

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