From 43cc3eb21a0b6c7a5a75c5d373e7709260e5aeec Mon Sep 17 00:00:00 2001 From: Pentium44 Date: Thu, 24 Dec 2020 20:07:13 -0800 Subject: [PATCH] Call this v1.0 --- README.md | 16 ++++++++++ config | 13 ++++++++ speedyparse | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 README.md create mode 100644 config create mode 100755 speedyparse diff --git a/README.md b/README.md new file mode 100644 index 0000000..b0628cb --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +--- SpeedyParse +SpeedyParse is a simple configurable bash script that parses lighttpd +access.log files and generates static HTML files in a specific location + +--- Usage +* Modify "config" do your needs. +* Run speedyparse as root (if log files are owned by root, or web server) +* View generated HTML file! + +--- Changelog +* v1.0 + * Generates HTML file after parsing access.log files within lighttpd log file + * Working as it does, will be added to after I get more time. + +--- License +SpeedyParse is released under CC-BY-SA-NC 3.0 diff --git a/config b/config new file mode 100644 index 0000000..8842711 --- /dev/null +++ b/config @@ -0,0 +1,13 @@ +# SpeedyParse configuration file +# Chris Dorman, 2020 - CC-BY-SA-NC 3.0 + +### Search parameters ### +# Domain to parse hits, and connections from +DOMAIN="hosting.cddo.cf" +# Where to put [domain name]-[date].html when generated +OUTPUTDIR="/opt/htdocs" # Where the parsed HTML log file will go +# String to search for; great for finding individual page +# hits, default searches for root hits from [domain name] +SEARCHSTRING="GET / " +# Secondary string for a more strict search, leave unset for no use +SECONDARYSEARCH="" diff --git a/speedyparse b/speedyparse new file mode 100755 index 0000000..ad104f3 --- /dev/null +++ b/speedyparse @@ -0,0 +1,88 @@ +#!/bin/sh +# +# Parse lighttpd access logs for website hits +# Chris Dorman, 2020 - CC-BY-SA-NC 3.0 +# + +# Include configuartion file +. config + +# Date string for html generation +datestring=`date +"%Y%m%d-%H%M"` + +# Project information +PROJTITLE="SpeedyParse" +PROJVERSION="1.0" + +cd /var/log/lighttpd + +if [ -f access.*.gz ]; then + echo "Extracting access.log files" + tar -xzf *.gz +fi + +# Parse latest access.log and put within log file in HTML format. + +if [ -z "$SECONDARYSEARCH" ]; then + catchcount=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | wc -l` + catchlog=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | sort` +else + catchcount=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | wc -l` + catchlog=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | sort` +fi + +catchtotal=$catchcount + +echo " + + + Lighttpd access logs ~ $date + + + +

Access.log information ~ ${datestring}

+ +Searching through lighttpd logs with these parameters: +"${SEARCHSTRING}"" > $OUTPUTDIR/$DOMAIN-${datestring}.html + +if [ ! -z "$SECONDARYSEARCH" ]; then + echo ""${SECONDARYSEARCH}"" >> $OUTPUTDIR/$DOMAIN-${datestring}.html +fi + +echo " + +access.log ~ ${catchcount} hits
+ +${catchlog} + +

+" >> $OUTPUTDIR/$DOMAIN-${datestring}.html + +# Parse old .log files and output within HTML +for file in access.log.* +do + if [ -z "$SECONDARYSEARCH" ]; then + addition=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | wc -l` + catchlog=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | sort` + else + addition=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | wc -l` + catchlog=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | sort` + fi + + doaddition=$(( $catchcount + $addition )) + + export catchcount=$doaddition + + echo "$file ~ ${addition} hits
" >> $OUTPUTDIR/$DOMAIN-${datestring}.html + echo "${catchlog}

" >> $OUTPUTDIR/$DOMAIN-${datestring}.html +done + +echo "${doaddition} hits total on ${DOMAIN} using above search parameters.

" >> $OUTPUTDIR/$DOMAIN-${datestring}.html + +echo "" >> $OUTPUTDIR/$DOMAIN-${datestring}.html