pub / goaccess_dashboard

Tiny tool for privacy-preserving web-analytics
git clone https://src.jayvii.de/pub/goaccess_dashboard.git
Home | Log | Files | Exports | Refs | Submodules | README | RSS

create_logs_report.sh (3248B)


      1 #!/usr/bin/env bash
      2 
      3 # configuration ----------------------------------------------------------------
      4 
      5 DB_PATH="$HOME/goaccess/${1}"
      6 HTML_PATH="/var/www/traffic.${1}"
      7 LOG_PATH="/var/log/apache2/${1}_access.log"
      8 
      9 # define functions -------------------------------------------------------------
     10 
     11 # HACK: enable automatic dark mode (default is bright)
     12 function autoTheme() {
     13   echo "
     14     <script>
     15       // Define autoTheme function
     16       function autoTheme() {
     17         // If browser/client prefers dark color-scheme
     18         if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
     19           // unwind sidebar to load theme-toggles
     20           document.querySelector('.nav-gears').click();
     21           // Enable theme: dark-gray
     22           document.querySelector('.theme-dark-gray').click();
     23         }
     24       };
     25       // run autoTheme function after 1ms delay
     26       setTimeout(autoTheme, 1);
     27   </script>
     28   " | tee --append "${1}" > /dev/null
     29 }
     30 
     31 # set dates --------------------------------------------------------------------
     32 TODAY=$(date +%Y-%m-%d)
     33 THIS_WEEK=$(date +%V --date "${TODAY}")
     34 THIS_MONTH=$(date +%m --date "${TODAY}")
     35 THIS_YEAR=$(date +%Y --date "${TODAY}")
     36 TODAY=$(date +%d\\/%b\\/%Y --date "${TODAY}")
     37 
     38 # create db-paths --------------------------------------------------------------
     39 mkdir -p "${DB_PATH}/all"
     40 mkdir -p "${DB_PATH}/${THIS_YEAR}"
     41 mkdir -p "${DB_PATH}/${THIS_YEAR}/${THIS_MONTH}"
     42 mkdir -p "${DB_PATH}/${THIS_YEAR}/week-${THIS_WEEK}"
     43 
     44 # create output paths ----------------------------------------------------------
     45 mkdir -p "${HTML_PATH}/all"
     46 mkdir -p "${HTML_PATH}/${THIS_YEAR}"
     47 mkdir -p "${HTML_PATH}/${THIS_YEAR}/${THIS_MONTH}"
     48 mkdir -p "${HTML_PATH}/${THIS_YEAR}/week-${THIS_WEEK}"
     49 
     50 # create logs ------------------------------------------------------------------
     51 
     52 # create weekly log
     53 echo "Create this Week's log"
     54 sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | \
     55   grep -v -E "$(cat ./spammers.txt)" | \
     56   goaccess \
     57     --db-path="${DB_PATH}/${THIS_YEAR}/week-${THIS_WEEK}" \
     58     --output-format="${HTML_PATH}/${THIS_YEAR}/week-${THIS_WEEK}/index.html" \
     59     -
     60 
     61 # auto automatic theme to weekly log
     62 autoTheme "${HTML_PATH}/${THIS_YEAR}/week-${THIS_WEEK}/index.html"
     63 
     64 # create monthly log
     65 echo "Create this Month's log"
     66 sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | \
     67   grep -v -E "$(cat ./spammers.txt)" | \
     68   goaccess \
     69     --db-path="${DB_PATH}/${THIS_YEAR}/${THIS_MONTH}" \
     70     --output-format="${HTML_PATH}/${THIS_YEAR}/${THIS_MONTH}/index.html" \
     71     -
     72 
     73 # auto automatic theme to monthly log
     74 autoTheme "${HTML_PATH}/${THIS_YEAR}/${THIS_MONTH}/index.html"
     75 
     76 # create yearly log
     77 echo "Create this Year's log"
     78 sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | \
     79   grep -v -E "$(cat ./spammers.txt)" | \
     80   goaccess \
     81     --db-path="${DB_PATH}/${THIS_YEAR}" \
     82     --output-format="${HTML_PATH}/${THIS_YEAR}/index.html" \
     83     -
     84 
     85 # auto automatic theme to yearly log
     86 autoTheme "${HTML_PATH}/${THIS_YEAR}/index.html"
     87 
     88 # create global log
     89 echo "Create global log"
     90 sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | \
     91   grep -v -E "$(cat ./spammers.txt)" | \
     92   goaccess \
     93     --db-path="${DB_PATH}/all" \
     94     --output-format="${HTML_PATH}/all/index.html" \
     95     -
     96 
     97 # auto automatic theme to global log
     98 autoTheme "${HTML_PATH}/all/index.html"
     99 
    100 echo "Done!"