4
0

command_postdetails.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. for queryip in "${queryips[@]}"
  54. do
  55. query_gamedig.sh
  56. if [ "${querystatus}" == "0" ]; then
  57. break
  58. fi
  59. done
  60. touch "${postdetailslog}" || fn_bad_postdetailslog
  61. {
  62. fn_info_message_distro
  63. fn_info_message_server_resource
  64. fn_info_message_gameserver_resource
  65. fn_info_message_gameserver
  66. fn_info_message_script
  67. fn_info_message_backup
  68. # Some game servers do not have parms.
  69. if [ "${shortname}" != "jc2" ]&&[ "${shortname}" != "jc3" ]&&[ "${shortname}" != "dst" ]&&[ "${shortname}" != "pz" ]&&[ "${engine}" != "renderware" ]; then
  70. fn_parms
  71. fn_info_message_commandlineparms
  72. fi
  73. fn_info_message_ports
  74. fn_info_message_select_engine
  75. fn_info_message_statusbottom
  76. } | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | tee -a "${postdetailslog}" > /dev/null 2>&1
  77. fi
  78. # Pastebin
  79. if [ "${posttarget}" == "http://pastebin.com" ] ; then
  80. fn_print_dots "pastbin.com for ${postexpire}"
  81. # grab the return from 'value' from an initial visit to pastebin.
  82. csrftoken=$(curl -s "${posttarget}" | sed -n 's/^.*input type="hidden" name="csrf_token_post" value="\(.*\)".*$/\1/p')
  83. #
  84. # Use the csrftoken to then post the content.
  85. #
  86. link=$(curl -s "${posttarget}/post.php" -D - -F "submit_hidden=submit_hidden" \
  87. -F "post_key=${csrftoken}" -F "paste_expire_date=${postexpire}" \
  88. -F "paste_name=${gamename} Debug Info" \
  89. -F "paste_format=8" -F "paste_private=0" \
  90. -F "paste_type=bash" -F "paste_code=<${postdetailslog}" |
  91. awk '/^location: / { print $2 }' | sed "s/\n//g")
  92. # Output the resulting link.
  93. fn_print_ok_nl "pastbin.com for ${postexpire}"
  94. fn_script_log_pass "pastbin.com for ${postexpire}"
  95. pdurl="${posttarget}${link}"
  96. # Hastebin
  97. elif [ "${posttarget}" == "https://hastebin.com" ] ; then
  98. fn_print_dots "hastebin.com"
  99. # hastebin is a bit simpler. If successful, the returned result
  100. # should look like: {"something":"key"}, putting the reference that
  101. # we need in "key". TODO - error handling. -CedarLUG
  102. link=$(curl -H "HTTP_X_REQUESTED_WITH:XMLHttpRequest" -s -d "$(<${postdetailslog})" "${posttarget}/documents" | cut -d\" -f4)
  103. fn_print_ok_nl "hastebin.com for ${postexpire}"
  104. fn_script_log_pass "hastebin.com for ${postexpire}"
  105. pdurl="${posttarget}/${link}"
  106. # Termbin
  107. elif [ "${posttarget}" == "https://termbin.com" ] ; then
  108. fn_print_dots "termbin.com"
  109. link=$(cat "${postdetailslog}" | nc termbin.com 9999 | tr -d '\n\0')
  110. fn_print_ok_nl "termbin.com for 30D"
  111. fn_script_log_pass "termbin.com for 30D"
  112. pdurl="${link}"
  113. fi
  114. echo -e ""
  115. echo -e "Please share the following url for support: "
  116. echo -e "${pdurl}"
  117. fn_script_log_info "${pdurl}"
  118. if [ -z "${exitbypass}" ]; then
  119. core_exit.sh
  120. else
  121. alerturl="${pdurl}"
  122. fi