├── pygopherstats.sh └── README.md /pygopherstats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ -z $1 ]]; then 4 | echo "Please provide logfile to scan: " 5 | echo "./$0 /var/log/syslog" 6 | exit 1 7 | fi 8 | 9 | mkdir -p /var/log/gopherlog/ 10 | GOPHERLOG=/var/log/gopherlog/analyze.$(date +%s) 11 | 12 | grep pygopherd $@ | awk '{print $6" "$7" "$8" "$9" "$10}' | grep -e GopherProtocol -e HTTPProtocol > ${GOPHERLOG} 13 | 14 | LOGSTART=$(grep pygopherd /var/log/syslog | awk '{print $1" "$2" "$3}' | head -n 1) 15 | LOGEND=$(grep pygopherd /var/log/syslog | awk '{print $1" "$2" "$3}' | tail -n 1) 16 | 17 | TOTALHITS=$(wc -l $GOPHERLOG | awk '{print $1}') 18 | TOTALIPS=$(awk '{print $1}' ${GOPHERLOG} | sort -u | wc -l) 19 | TOPTENIPS="$(awk '{print $1}' ${GOPHERLOG} | uniq -c | sort -r | head)" 20 | PROTOCOLS="$(awk '{print $2}' ${GOPHERLOG} | sort | uniq -c | sort -r)" 21 | TOPTENFILES="$(awk '{$1=$2=""; print $0}' ${GOPHERLOG} | grep -v "EXCEPTION" | sort | uniq -c | sort -r | head)" 22 | TOPTENERRORS="$(awk '{$1=$2=""; print $0}' ${GOPHERLOG} | grep "EXCEPTION" | sort | uniq -c | sort -r | head)" 23 | TOPTENFILESPERIP="$(grep FileHandler ${GOPHERLOG} | awk '{$2=""; print $0}' | grep -v "EXCEPTION" | sort | uniq -c | sort -r | head)" 24 | TOPTENGOPHERMAPSPERIP="$(grep BuckGophermapHandler ${GOPHERLOG} | awk '{$2=""; print $0}' | grep -v "EXCEPTION" | sort | uniq -c | sort -r | head)" 25 | TOPTENDIRSPERIP="$(grep UMNDirHandler ${GOPHERLOG} | awk '{$2=""; print $0}' | grep -v "EXCEPTION" | sort | uniq -c | sort -r | head)" 26 | 27 | if [[ -z ${LOGSTART} || -z ${LOGEND} ]]; then 28 | echo "No gopher messages found in logfile $1" 29 | exit 1 30 | fi 31 | 32 | echo "# pyGopherd log analyzer" 33 | echo "From file: $@" 34 | echo "Hostname: $(hostname -f || hostname)" 35 | echo "Start: ${LOGSTART}" 36 | echo "End: ${LOGEND}" 37 | echo "----------------------------------" 38 | echo "# Totals " 39 | echo "- Hits: ${TOTALHITS}" 40 | echo "- IP's: ${TOTALIPS}" 41 | echo "" 42 | echo "# Top Tens" 43 | echo "## Most Popular " 44 | echo "${TOPTENFILES}" 45 | echo "" 46 | echo "## Files per IP" 47 | echo "${TOPTENFILESPERIP}" 48 | echo "" 49 | echo "## Gophermaps per IP" 50 | echo "${TOPTENGOPHERMAPSPERIP}" 51 | echo "" 52 | echo "## Folders per IP" 53 | echo "${TOPTENDIRSPERIP}" 54 | echo "" 55 | echo "## Errors: " 56 | echo "${TOPTENERRORS}" 57 | echo 58 | echo "# Protocols " 59 | echo "${PROTOCOLS}" 60 | echo "" 61 | echo "" 62 | echo "----------------------------------" 63 | echo "Simple pygopherlog analyzer by raymii.org" 64 | echo "License: GNU GPLv3" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pygopherd log analyzer 2 | 3 | Simple log analyzer for pygopherd. Fun if you have a gopherhole and want statistics. 4 | If you ever used [Logwatch](https://wiki.archlinux.org/index.php/Logwatch) you'll 5 | feel at home. 6 | 7 | ## Requirements 8 | 9 | - pygopherd (tested with 2.0.18) 10 | - syslog of some kind 11 | - bash 4+ 12 | 13 | ## Installation 14 | 15 | - Clone the git repository or save the shell script somewhere 16 | - Make the script executable (`chmod +x ./pygopherstats.sh`) 17 | - Run it providing one or more logfiles to analyze: 18 | 19 | ./pygopherstats.sh /var/log/syslog 20 | ./pygopherstats.sh /var/log/syslog /var/log/syslog.1 21 | ./pygopherstats.sh /var/log/syslog.* 22 | 23 | If you don't have a central syslog server, use poor man's ssh to get all the 24 | log files from all the servers: 25 | 26 | for host in $(dig +short a example.org); do 27 | ssh -l root $host "zgrep pygopherd /var/log/syslog.*"; 28 | done 2>/dev/null > gopherlog 29 | 30 | 31 | ## Example report 32 | 33 | # pyGopherd log analyzer 34 | From file: /var/log/syslog 35 | Hostname: example.org 36 | Start: Mar 18 06:29:50 37 | End: Mar 18 12:18:23 38 | ---------------------------------- 39 | 40 | # Totals 41 | - Hits: 800 42 | - IP's: 60 43 | 44 | # Top Tens 45 | ## Most Popular 46 | 165 / 47 | 32 /Site_updates_raymii.org_now_on_gopher.txt 48 | 14 /links 49 | 14 /About.txt 50 | 10 /Viewing_PDF_docx_and_odt_files_in_Mutt.txt 51 | 10 /SpaceCat_Launchpad_v2_an_awesome_little_macropad.txt 52 | 6 /Get_json_value_with_sed.txt 53 | 5 /Split_keyboards_a_five_year_review_including_the_ErgoDox_EZ_Matias_Ergo_Pro_and_Kinesis_Freestyle_2.txt 54 | 4 /Sparkling_Network.txt 55 | 3 /Three_New_Nitrokeys_Pro_2_Storage_2_and_Fido_u2f.txt 56 | 57 | ## Files per IP 58 | 10 66.166.122.163 /Site_updates_raymii.org_now_on_gopher.txt 59 | 3 66.166.122.163 /About.txt 60 | 3 182.259.43.98 /Viewing_PDF_docx_and_odt_files_in_Mutt.txt 61 | 2 79.131.39.102 /SpaceCat_Launchpad_v2_an_awesome_little_macropad.txt 62 | 2 66.166.122.163 /SpaceCat_Launchpad_v2_an_awesome_little_macropad.txt 63 | 2 182.259.43.98 /Split_keyboards_a_five_year_review_including_the_ErgoDox_EZ_Matias_Ergo_Pro_and_Kinesis_Freestyl 64 | e_2.txt 65 | 2 182.259.43.98 /Site_updates_raymii.org_now_on_gopher.txt 66 | 2 47.72.77.216 /About.txt 67 | 2 185.94.189.189 /Site_updates_raymii.org_now_on_gopher.txt 68 | 2 18.197.227.29 /Site_updates_raymii.org_now_on_gopher.txt 69 | 70 | ## Gophermaps per IP 71 | 52 182.259.43.98 / 72 | 32 66.166.122.163 / 73 | 8 60.191.38.77 / 74 | 7 182.259.43.98 /links 75 | 5 143.179.52.12 /links 76 | 4 143.179.52.12 / 77 | 3 88.75.179.155 / 78 | 3 84.75.205.142 / 79 | 3 82.68.156.30 / 80 | 3 79.131.39.102 / 81 | 82 | ## Folders per IP 83 | 1 182.259.43.98 /links 84 | 85 | ## Errors: 86 | 54 EXCEPTION FileNotFound: '/caps.txt' 87 | 25 EXCEPTION TypeError'>: stat() 88 | 24 EXCEPTION error'>: [Errno 89 | 17 EXCEPTION IndexError'>: string 90 | 12 EXCEPTION FileNotFound: '/bout.txt' 91 | 2 EXCEPTION FileNotFound: '/mahua/v/20190212/8dfcb2192a5052e5a152b9d8115201af_24f3fa0cbc00474fab1610181191b09c_0. 92 | m3u8' 93 | 2 EXCEPTION FileNotFound: '/Hello 94 | 1 EXCEPTION FileNotFound: '/links' 95 | 1 EXCEPTION FileNotFound: '/ite_updates_raymii.org_now_on_gopher.txt' 96 | 1 EXCEPTION FileNotFound: '/favicon.ico' 97 | 98 | # Protocols 99 | 480 [GopherProtocol/FileHandler]: 100 | 162 [GopherProtocol/BuckGophermapHandler]: 101 | 128 [GopherProtocol/None] 102 | 16 [HTTPProtocol/BuckGophermapHandler]: 103 | 13 [HTTPProtocol/None] 104 | 1 [GopherProtocol/UMNDirHandler]: 105 | 106 | 107 | ---------------------------------- 108 | Simple pygopherlog analyzer by raymii.org 109 | License: GNU GPLv3 110 | --------------------------------------------------------------------------------