reporting 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. tmpdir="/tmp"
  3. force_email_flag=$1
  4. checkInternet() {
  5. ping -c1 -W3 -q 8.8.8.8 &> /dev/null && {
  6. echo "1"
  7. } || {
  8. echo "0"
  9. }
  10. }
  11. checkSDCard() {
  12. [[ $(mount | grep /sd) == "" ]] && {
  13. echo "1"
  14. } || {
  15. echo "0"
  16. }
  17. }
  18. sendEmail() {
  19. tar_gz=$1
  20. to=$(uci get reporting.@ssmtp[0].to)
  21. from=$(uci get reporting.@ssmtp[0].from)
  22. email_body="To:$to\nFrom:$from\nSubject:WiFi Pineapple Report: $(date)\n\nPlease see the attached file."
  23. date=$(date +%Y-%m-%d-%H:%M)
  24. echo -e $email_body | (cat - && cat $tar_gz | uuencode "WiFi_Pineapple_Report_$(date +%Y-%m-%d-%H-%M).tar.gz") | ssmtp $to &> /dev/null && {
  25. echo "$date: Successfully sent email to $to" >> /tmp/reporting.log
  26. } || {
  27. echo "$date: Failed to send email to $to" >> /tmp/reporting.log
  28. }
  29. }
  30. getPineAPReport() {
  31. [[ "$(uci get reporting.@settings[0].log)" == "1" ]] && {
  32. /pineapple/modules/Reporting/files/getlog.php > $tmpdir/report/pineap.log
  33. }
  34. }
  35. getClientReport() {
  36. [[ "$(uci get reporting.@settings[0].client)" == "1" ]] && {
  37. /pineapple/modules/Reporting/files/getlog.php --probes > $tmpdir/report/probing_clients.csv
  38. }
  39. }
  40. getSiteReport() {
  41. [[ "$(uci get reporting.@settings[0].survey)" == "1" ]] && {
  42. /etc/init.d/pineapd start
  43. sleep 3
  44. duration=$(uci get reporting.@settings[0].duration)
  45. scan_type=0
  46. cat /proc/cpuinfo | grep TETRA && scan_type=2
  47. echo -e "\tRunning scan type $scan_type for 15 seconds"
  48. (/usr/bin/pineap /tmp/pineap.conf run_scan $duration $scan_type 2>&1) >> /tmp/reporting.log
  49. sleep 2
  50. scan_id="$(/usr/bin/pineap /tmp/pineap.conf get_status | grep scanID | awk '{print $2}' | sed 's/,//')"
  51. echo -e "\tNew scan id: $scan_id"
  52. echo -e "\tWaiting for scan to finish"
  53. while [ "$(/usr/bin/pineap /tmp/pineap.conf get_status | grep 'scanRunning' | awk '{print $2}' | sed 's/,//')" == "true" ]; do sleep 1; done
  54. echo -e "\tRetrieving scan results, appending to debug log"
  55. chmod a+x /pineapple/modules/Help/files/dumpscan.php
  56. /pineapple/modules/Help/files/dumpscan.php $scan_id > $tmpdir/report/site_survey
  57. }
  58. }
  59. getTrackedClients() {
  60. [[ "$(uci get reporting.@settings[0].tracking)" == "1" ]] && {
  61. cp /tmp/tracking.report $tmpdir/report/tracked_clients &> /dev/null
  62. echo "" > /tmp/tracking.report
  63. }
  64. }
  65. generateReport() {
  66. rm -rf $tmpdir/report &> /dev/null
  67. mkdir -p $tmpdir/report &> /dev/null
  68. archive_name="WiFi_Pineapple_Report_$(date +%Y-%m-%d-%H-%M).tar.gz"
  69. echo getPineAPReport
  70. getPineAPReport
  71. echo getClientReport
  72. getClientReport
  73. echo getTrackedclients
  74. getTrackedClients
  75. echo getSiteReport
  76. getSiteReport
  77. echo tar
  78. tar -C $tmpdir -pczhf $tmpdir/$archive_name report
  79. [[ "$(uci get reporting.@settings[0].send_email)" == "1" ]] || [[ "$force_email_flag" == "force_email" ]] && {
  80. [[ "$(checkInternet)" == "1" ]] && {
  81. sendEmail $tmpdir/$archive_name
  82. } || {
  83. echo "$(date +%Y-%m-%d-%H:%M): Failed to email report - no internet connection available" >> /tmp/reporting.log
  84. }
  85. }
  86. [[ $(checkSDCard) == "1" ]] && {
  87. [[ "$(uci get reporting.@settings[0].save_report)" != "1" ]] && {
  88. rm -rf $tmpdir/$archive_name
  89. } || {
  90. mkdir -p /sd/wifipineapple_reports &> /dev/null
  91. mv $tmpdir/$archive_name /sd/wifipineapple_reports/$archive_name
  92. echo "$(date +%Y-%m-%d-%H:%M): Report saved to SD card" >> /tmp/reporting.log
  93. }
  94. } || {
  95. echo "$(date +%Y-%m-%d-%H:%M): Failed to save to SD card - no SD card found" >> /tmp/reporting.log
  96. }
  97. rm -rf $tmpdir/report &> /dev/null
  98. }
  99. tmpdir="/tmp"
  100. [[ $(checkSDCard) == "1" ]] && {
  101. tmpdir="/sd/tmp"
  102. }
  103. generateReport