command_postdetails.sh 4.2 KB

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