| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #!/bin/bash
- tmpdir="/tmp"
- force_email_flag=$1
- checkInternet() {
- ping -c1 -W3 -q 8.8.8.8 &> /dev/null && {
- echo "1"
- } || {
- echo "0"
- }
- }
- checkSDCard() {
- [[ $(mount | grep /sd) == "" ]] && {
- echo "1"
- } || {
- echo "0"
- }
- }
- sendEmail() {
- tar_gz=$1
- to=$(uci get reporting.@ssmtp[0].to)
- from=$(uci get reporting.@ssmtp[0].from)
- email_body="To:$to\nFrom:$from\nSubject:WiFi Pineapple Report: $(date)\n\nPlease see the attached file."
- date=$(date +%Y-%m-%d-%H:%M)
- echo -e $email_body | (cat - && cat $tar_gz | uuencode "WiFi_Pineapple_Report_$(date +%Y-%m-%d-%H-%M).tar.gz") | ssmtp $to &> /dev/null && {
- echo "$date: Successfully sent email to $to" >> /tmp/reporting.log
- } || {
- echo "$date: Failed to send email to $to" >> /tmp/reporting.log
- }
- }
- getPineAPReport() {
- [[ "$(uci get reporting.@settings[0].log)" == "1" ]] && {
- /pineapple/modules/Reporting/files/getlog.php > $tmpdir/report/pineap.log
- }
- }
- getClientReport() {
- [[ "$(uci get reporting.@settings[0].client)" == "1" ]] && {
- /pineapple/modules/Reporting/files/getlog.php --probes > $tmpdir/report/probing_clients.csv
- }
- }
- getSiteReport() {
- [[ "$(uci get reporting.@settings[0].survey)" == "1" ]] && {
- /etc/init.d/pineapd start
- sleep 3
- duration=$(uci get reporting.@settings[0].duration)
- scan_type=0
- cat /proc/cpuinfo | grep TETRA && scan_type=2
- echo -e "\tRunning scan type $scan_type for 15 seconds"
- (/usr/bin/pineap /tmp/pineap.conf run_scan $duration $scan_type 2>&1) >> /tmp/reporting.log
- sleep 2
- scan_id="$(/usr/bin/pineap /tmp/pineap.conf get_status | grep scanID | awk '{print $2}' | sed 's/,//')"
- echo -e "\tNew scan id: $scan_id"
- echo -e "\tWaiting for scan to finish"
- while [ "$(/usr/bin/pineap /tmp/pineap.conf get_status | grep 'scanRunning' | awk '{print $2}' | sed 's/,//')" == "true" ]; do sleep 1; done
- echo -e "\tRetrieving scan results, appending to debug log"
- chmod a+x /pineapple/modules/Help/files/dumpscan.php
- /pineapple/modules/Help/files/dumpscan.php $scan_id > $tmpdir/report/site_survey
- }
- }
- getTrackedClients() {
- [[ "$(uci get reporting.@settings[0].tracking)" == "1" ]] && {
- cp /tmp/tracking.report $tmpdir/report/tracked_clients &> /dev/null
- echo "" > /tmp/tracking.report
- }
- }
- generateReport() {
- rm -rf $tmpdir/report &> /dev/null
- mkdir -p $tmpdir/report &> /dev/null
- archive_name="WiFi_Pineapple_Report_$(date +%Y-%m-%d-%H-%M).tar.gz"
- echo getPineAPReport
- getPineAPReport
- echo getClientReport
- getClientReport
- echo getTrackedclients
- getTrackedClients
- echo getSiteReport
- getSiteReport
- echo tar
- tar -C $tmpdir -pczhf $tmpdir/$archive_name report
- [[ "$(uci get reporting.@settings[0].send_email)" == "1" ]] || [[ "$force_email_flag" == "force_email" ]] && {
- [[ "$(checkInternet)" == "1" ]] && {
- sendEmail $tmpdir/$archive_name
- } || {
- echo "$(date +%Y-%m-%d-%H:%M): Failed to email report - no internet connection available" >> /tmp/reporting.log
- }
- }
- [[ $(checkSDCard) == "1" ]] && {
- [[ "$(uci get reporting.@settings[0].save_report)" != "1" ]] && {
- rm -rf $tmpdir/$archive_name
- } || {
- mkdir -p /sd/wifipineapple_reports &> /dev/null
- mv $tmpdir/$archive_name /sd/wifipineapple_reports/$archive_name
- echo "$(date +%Y-%m-%d-%H:%M): Report saved to SD card" >> /tmp/reporting.log
- }
- } || {
- echo "$(date +%Y-%m-%d-%H:%M): Failed to save to SD card - no SD card found" >> /tmp/reporting.log
- }
- rm -rf $tmpdir/report &> /dev/null
- }
- tmpdir="/tmp"
- [[ $(checkSDCard) == "1" ]] && {
- tmpdir="/sd/tmp"
- }
- generateReport
|