From 036a817086f8c9986107ff61eee385bb4268b73f Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Sun, 22 Jan 2017 15:52:40 -0500 Subject: [PATCH 1/7] first pass at generatign and posting a debug log file --- setup/system.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/system.sh b/setup/system.sh index c0af3215..95410bae 100755 --- a/setup/system.sh +++ b/setup/system.sh @@ -117,7 +117,7 @@ echo Installing system packages... apt_install python3 python3-dev python3-pip \ netcat-openbsd wget curl git sudo coreutils bc \ haveged pollinate unzip \ - unattended-upgrades cron ntp fail2ban + unattended-upgrades cron ntp fail2ban gist # ### Suppress Upgrade Prompts # Since Mail-in-a-Box might jump straight to 18.04 LTS, there's no need From 21709a9c454d0c9aaaf8dd020318bcba0754a95c Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Sun, 22 Jan 2017 15:56:02 -0500 Subject: [PATCH 2/7] the shell script to collect and generate the debug log --- tools/collect_debug_info.sh | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tools/collect_debug_info.sh diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh new file mode 100644 index 00000000..20255823 --- /dev/null +++ b/tools/collect_debug_info.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# This script will save debug info to either a gist or /tmp/ + +# Are we running as root? +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root. Please re-run like this:" + echo + echo "sudo $0" + echo + exit +fi + +echo "This script produces a diagnostic log to help the maintainers" +echo "figure out why your Mail-in-a-Box installation isn't working the" +echo "way you expected it to." + +echo +echo "This log will contain sensitive information about your installation" +echo "including, but not limited to:" +echo "email addresses" +echo "domain names" +echo "IP addresses" +echo "server security configuration" +echo "etc." +echo +echo "=====================================================================" +echo "Please do not post this file to the internet if you are not comfortable" +echo "exposing this information publicly to the world forever." +echo "=====================================================================" +echo +echo "Once the log has been collected, you will be given the option to post" +echo "the log to https://gist.github.com/ so that others can help you diagnose" +echo "the issues with your Mail-in-a-Box installation" +echo +echo "You are solely responsible for the data you choose to publish" + +source /etc/mailinabox.conf # load global vars +TMP_FILE=/tmp/MIAB_debug_$(date -d "today" +"%Y%m%d%H%M%S").log + +touch $TMP_FILE; + +# MIAB status checks +/root/mailinabox/management/status_checks.py >> $TMP_FILE; +echo >> $TMP_FILE; # newline after status_checks + +# all of the commands we want to run. +declare -a commands=("uptime" + "lsb_release -a" + "free -m" + "df -h" + "ps auxf" + "pip3 list" + "dpkg --list" + "ufw status verbose" + "ifconfig" + "lsof -i" + "cat /etc/hosts" + "cat /etc/resolv.conf" + "cat /var/log/syslog" + "cat /var/log/mail.log" + "cat /var/log/boot.log" + "cat /var/log/roundcubemail/errors" + ) + +function name_and_delineator () { + CMD_LENGTH=${#1} + DELINEATOR=""; + for (( c=1; c<=$CMD_LENGTH; c++ )) + do + DELINEATOR+="="; + done + echo $1 >> $TMP_FILE + echo $DELINEATOR >> $TMP_FILE; +} + +# iterate through each command, announce it, execute it and log it. +for i in "${commands[@]}" +do + echo "executing: $i and saving output to $TMP_FILE" + name_and_delineator "$i" # pretty printing + eval `echo $i` >> $TMP_FILE # execute string as a command, including spaces + echo >> $TMP_FILE; # newline +done + + +# double check that the user wants to post to github. default +echo "Do You want to post your debug log on github publicly?" +echo "Please type 'YES' below, anything else will cancel." +echo -n "Type YES to publish:" +read answer +if echo "$answer" | grep -q "^YES" ;then + echo "Posting the debug log to gist.github.com at this url:" + echo $(gist-paste -p `echo $TMP_FILE`) + echo "Please provide this url to help diagnose your issue." +else + echo "Your debug log file is here: $TMP_FILE" +fi + From 92db3c984271ed615f89c507a60d8c8c05da72fb Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Sun, 22 Jan 2017 16:18:08 -0500 Subject: [PATCH 3/7] adding ability to log into github, so users can delete the secret gist --- tools/collect_debug_info.sh | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh index 20255823..252b08ea 100644 --- a/tools/collect_debug_info.sh +++ b/tools/collect_debug_info.sh @@ -83,17 +83,37 @@ do echo >> $TMP_FILE; # newline done +function post_gist () { + echo "Posting the debug log to https://gist.github.com at this url:" + echo $(gist-paste -p -s `echo $TMP_FILE`) + echo "Please provide this url to help diagnose your issue." +} -# double check that the user wants to post to github. default -echo "Do You want to post your debug log on github publicly?" +# double check that the user wants to post to github. +echo "Do You want to post your debug log on https://gist.github.com publicly?" echo "Please type 'YES' below, anything else will cancel." echo -n "Type YES to publish:" read answer if echo "$answer" | grep -q "^YES" ;then - echo "Posting the debug log to gist.github.com at this url:" - echo $(gist-paste -p `echo $TMP_FILE`) - echo "Please provide this url to help diagnose your issue." -else - echo "Your debug log file is here: $TMP_FILE" + if [ ! -f /root/.gist ]; then + echo "You will need to log into Github first." + echo "You can skip this step by pressing , but you will not" + echo "be able to delete the debug log if you do not log in." + gist-paste --login + # ask again, just to be sure. + echo "Are you sure you want to post your debug log on https://gist.github.com publicly?" + echo "Please type 'YES' below, anything else will cancel." + echo -n "Type YES to publish:" + read answer + if echo "$answer" | grep -q "^YES" ;then + post_gist + else + # logged in to github, but said no on the second request + echo "Your debug log file is here: $TMP_FILE" + fi + else + post_gist + fi +else # said no to initial request to post to gist.github.com + echo "Your debug log file is here: $TMP_FILE" fi - From 5483df804c018fdced2608e9a039b3ddf3e18a87 Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Sun, 22 Jan 2017 17:20:51 -0500 Subject: [PATCH 4/7] adding git status for /root/mailinabox --- tools/collect_debug_info.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh index 252b08ea..b0cda1c8 100644 --- a/tools/collect_debug_info.sh +++ b/tools/collect_debug_info.sh @@ -45,7 +45,8 @@ touch $TMP_FILE; echo >> $TMP_FILE; # newline after status_checks # all of the commands we want to run. -declare -a commands=("uptime" +declare -a commands=("git -C /root/mailinabox status" + "uptime" "lsb_release -a" "free -m" "df -h" @@ -60,8 +61,7 @@ declare -a commands=("uptime" "cat /var/log/syslog" "cat /var/log/mail.log" "cat /var/log/boot.log" - "cat /var/log/roundcubemail/errors" - ) + "cat /var/log/roundcubemail/errors") function name_and_delineator () { CMD_LENGTH=${#1} From 4abab9bbc4ec4bc02499280beb23b58b768108d0 Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Wed, 25 Jan 2017 14:36:40 -0500 Subject: [PATCH 5/7] using lsb_release -d instead of -a. cleaner, simpler output --- tools/collect_debug_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh index b0cda1c8..dcc38ae2 100644 --- a/tools/collect_debug_info.sh +++ b/tools/collect_debug_info.sh @@ -47,7 +47,7 @@ echo >> $TMP_FILE; # newline after status_checks # all of the commands we want to run. declare -a commands=("git -C /root/mailinabox status" "uptime" - "lsb_release -a" + "lsb_release -d" "free -m" "df -h" "ps auxf" From ee2ef9978f3ba74652ec6e01fb021b66479642a3 Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Sun, 26 Mar 2017 15:58:18 -0400 Subject: [PATCH 6/7] making the language a bit clearer, adding the 'dmesg' command, and making the script executable --- tools/collect_debug_info.sh | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) mode change 100644 => 100755 tools/collect_debug_info.sh diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh old mode 100644 new mode 100755 index dcc38ae2..139d0c05 --- a/tools/collect_debug_info.sh +++ b/tools/collect_debug_info.sh @@ -14,7 +14,11 @@ fi echo "This script produces a diagnostic log to help the maintainers" echo "figure out why your Mail-in-a-Box installation isn't working the" echo "way you expected it to." - +echo +echo "It gives you the option to post this log to a *Secret* github gist" +echo "and only those you send the link to will be able to view it." +echo "If you have a github account, and you log in with your github account" +echo "you will be able to delete the secret gist." echo echo "This log will contain sensitive information about your installation" echo "including, but not limited to:" @@ -25,7 +29,7 @@ echo "server security configuration" echo "etc." echo echo "=====================================================================" -echo "Please do not post this file to the internet if you are not comfortable" +echo "Do not post this file to the internet if you are not comfortable" echo "exposing this information publicly to the world forever." echo "=====================================================================" echo @@ -33,6 +37,9 @@ echo "Once the log has been collected, you will be given the option to post" echo "the log to https://gist.github.com/ so that others can help you diagnose" echo "the issues with your Mail-in-a-Box installation" echo +echo "Should you decide not to post the log to a gist, it will be saved" +echo "to disk and you can scrub it before sharing it." +echo echo "You are solely responsible for the data you choose to publish" source /etc/mailinabox.conf # load global vars @@ -56,6 +63,7 @@ declare -a commands=("git -C /root/mailinabox status" "ufw status verbose" "ifconfig" "lsof -i" + "dmesg" "cat /etc/hosts" "cat /etc/resolv.conf" "cat /var/log/syslog" @@ -90,7 +98,10 @@ function post_gist () { } # double check that the user wants to post to github. -echo "Do You want to post your debug log on https://gist.github.com publicly?" +echo "Do You want to post your debug log on https://gist.github.com?" +echo +echo "It will create a *secret* gist that you can delete later" +echo echo "Please type 'YES' below, anything else will cancel." echo -n "Type YES to publish:" read answer @@ -101,7 +112,7 @@ if echo "$answer" | grep -q "^YES" ;then echo "be able to delete the debug log if you do not log in." gist-paste --login # ask again, just to be sure. - echo "Are you sure you want to post your debug log on https://gist.github.com publicly?" + echo "Are you sure you want to post your debug log on https://gist.github.com?" echo "Please type 'YES' below, anything else will cancel." echo -n "Type YES to publish:" read answer @@ -109,11 +120,21 @@ if echo "$answer" | grep -q "^YES" ;then post_gist else # logged in to github, but said no on the second request - echo "Your debug log file is here: $TMP_FILE" + echo "Nothing has been posted to gist.github.com" + echo "Your debug log file is here:" + echo "$TMP_FILE" + echo + echo "You can review and edit the file to remove private information and" + echo "manually post it to gist.github.com." fi else post_gist fi else # said no to initial request to post to gist.github.com - echo "Your debug log file is here: $TMP_FILE" + echo "Nothing has been posted to gist.github.com" + echo "Your debug log file is here:" + echo "$TMP_FILE" + echo + echo "You can review and edit the file to remove private information and" + echo "manually post it to gist.github.com." fi From 8536c47a734df87b274e6f3e40632a4225e7c2fe Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Mon, 3 Apr 2017 10:36:20 -0400 Subject: [PATCH 7/7] explicitly setting pip format --- tools/collect_debug_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/collect_debug_info.sh b/tools/collect_debug_info.sh index 139d0c05..1c9eb88a 100755 --- a/tools/collect_debug_info.sh +++ b/tools/collect_debug_info.sh @@ -58,7 +58,7 @@ declare -a commands=("git -C /root/mailinabox status" "free -m" "df -h" "ps auxf" - "pip3 list" + "pip3 list --format=columns" "dpkg --list" "ufw status verbose" "ifconfig"