|
| 1 | +#!/bin/bash |
| 2 | +function ncsa_combined_init(){ |
| 3 | + goan_config="/goaccess-config/goaccess.conf" |
| 4 | + nginx_html="/var/www/html/index.html" |
| 5 | + html_config="/var/www/html/goaccess_conf.html" |
| 6 | + archive_log="/goaccess-config/archive.log" |
| 7 | + active_log="/goaccess-config/active.log" |
| 8 | + |
| 9 | + if [[ -f ${goan_config} ]]; then |
| 10 | + rm ${goan_config} |
| 11 | + else |
| 12 | + mkdir -p "/goaccess-config/" |
| 13 | + cp /goaccess-config/goaccess.conf.bak ${goan_config} |
| 14 | + fi |
| 15 | + if [[ -f ${nginx_html} ]]; then |
| 16 | + rm ${nginx_html} |
| 17 | + else |
| 18 | + mkdir -p "/var/www/html/" |
| 19 | + touch ${nginx_html} |
| 20 | + fi |
| 21 | + if [[ -f ${html_config} ]]; then |
| 22 | + rm ${html_config} |
| 23 | + fi |
| 24 | + if [[ -f "$archive_log" ]]; then |
| 25 | + rm ${archive_log} |
| 26 | + else |
| 27 | + touch ${archive_log} |
| 28 | + fi |
| 29 | + if [[ -f "$active_log" ]]; then |
| 30 | + rm ${active_log} |
| 31 | + else |
| 32 | + touch ${active_log} |
| 33 | + fi |
| 34 | +} |
| 35 | + |
| 36 | +function ncsa_combined_goaccess_config(){ |
| 37 | + echo -e "\n\n\n" >> ${goan_config} |
| 38 | + echo "######################################" >> ${goan_config} |
| 39 | + echo "# ${goan_version}" >> ${goan_config} |
| 40 | + echo "# GOAN_PROXY_CONFIG" >> ${goan_config} |
| 41 | + echo "######################################" >> ${goan_config} |
| 42 | + echo "time-format %T" >> ${goan_config} |
| 43 | + echo "date-format %d/%b/%Y" >> ${goan_config} |
| 44 | + #echo "log-format [%d:%t %^] %^ %s %^ %^ %m %^ %v \"%U\" [%^ %h] [%^ %b] %^\"%u\" \"%R\"" >> ${goan_config} |
| 45 | + echo "log-format %h %^[%d:%t %^] \"%r\" %s %b \"%R\" \"%u\"" >> ${goan_config} |
| 46 | + echo "port 7890" >> ${goan_config} |
| 47 | + echo "real-time-html true" >> ${goan_config} |
| 48 | + echo "output ${nginx_html}" >> ${goan_config} |
| 49 | +} |
| 50 | + |
| 51 | +function ncsa_combined(){ |
| 52 | + ncsa_combined_init |
| 53 | + ncsa_combined_goaccess_config |
| 54 | + |
| 55 | + echo -e "\nLOADING NCSA_COMBINED LOGS" |
| 56 | + echo "-------------------------------" |
| 57 | + |
| 58 | + echo $'\n' >> ${goan_config} |
| 59 | + echo "#GOAN_DEFAULT_LOG_FILES" >> ${goan_config} |
| 60 | + echo "log-file ${archive_log}" >> ${goan_config} |
| 61 | + echo "log-file ${active_log}" >> ${goan_config} |
| 62 | + |
| 63 | + goan_log_count=0 |
| 64 | + goan_archive_log_count=0 |
| 65 | + |
| 66 | + echo -e "\n#GOAN_NCSA_COMBINED_LOG_FILES" >> ${goan_config} |
| 67 | + if [[ -d "${goan_log_path}" && -x "${goan_log_path}" ]]; then |
| 68 | + |
| 69 | + echo -e "\n\tAdding proxy logs..." |
| 70 | + IFS=$'\n' |
| 71 | + |
| 72 | + if [[ -z "${LOG_TYPE_FILE_PATTERN}" ]]; then |
| 73 | + LOG_TYPE_FILE_PATTERN="*.log" |
| 74 | + fi |
| 75 | + |
| 76 | + for file in $(find "${goan_log_path}" -name "${LOG_TYPE_FILE_PATTERN}"); |
| 77 | + do |
| 78 | + if [ -f $file ] |
| 79 | + then |
| 80 | + if [ -r $file ] && R="Read = yes" || R="Read = No" |
| 81 | + then |
| 82 | + echo "log-file ${file}" >> ${goan_config} |
| 83 | + goan_log_count=$((goan_log_count+1)) |
| 84 | + echo -ne ' \t ' |
| 85 | + echo "Filename: $file | $R" |
| 86 | + else |
| 87 | + echo -ne ' \t ' |
| 88 | + echo "Filename: $file | $R" |
| 89 | + fi |
| 90 | + else |
| 91 | + echo -ne ' \t ' |
| 92 | + echo "Filename: $file | Not a file" |
| 93 | + fi |
| 94 | + done |
| 95 | + unset IFS |
| 96 | + else |
| 97 | + echo "Problem loading directory (check directory or permissions)... ${goan_log_path}" |
| 98 | + fi |
| 99 | + |
| 100 | + if [ $goan_log_count != 0 ] |
| 101 | + then |
| 102 | + echo "Found (${goan_log_count}) proxy logs..." |
| 103 | + else |
| 104 | + echo "No access.log found. Creating an empty log file..." |
| 105 | + touch "${goan_log_path}/access.log" |
| 106 | + fi |
| 107 | + |
| 108 | + #additonal config settings |
| 109 | + exclude_ips ${goan_config} |
| 110 | + debug ${goan_config} ${html_config} |
| 111 | + set_geoip_database ${goan_config} |
| 112 | + |
| 113 | + echo -e "\nSKIP ARCHIVED LOGS" |
| 114 | + echo "-------------------------------" |
| 115 | + echo "FEATURE NOT AVAILABLE FOR NCSA_COMBINED" |
| 116 | + |
| 117 | + #write out loading page |
| 118 | + echo "<!doctype html><html><head>" > ${nginx_html} |
| 119 | + echo "<title>GOAN - ${goan_version}</title>" >> ${nginx_html} |
| 120 | + echo "<meta http-equiv=\"refresh\" content=\"1\" >" >> ${nginx_html} |
| 121 | + echo "<style>body {font-family: Arial, sans-serif;}</style>" >> ${nginx_html} |
| 122 | + echo "</head><body><p><b>${goan_version}</b><br/><br/>loading... <br/><br/>" >> ${nginx_html} |
| 123 | + echo "Logs processing: $(($goan_log_count)) (might take some time depending on the number of files to parse)" >> ${nginx_html} |
| 124 | + echo "<br/></p></body></html>" >> ${nginx_html} |
| 125 | + |
| 126 | + echo -e "\nRUN NCSA_COMBINED GOACCESS" |
| 127 | + if [[ "${DEBUG}" == "True" ]]; then |
| 128 | + /goaccess-debug/goaccess --debug-file=${goaccess_debug_file} --invalid-requests=${goaccess_invalid_file} --no-global-config --config-file=${goan_config} & |
| 129 | + else |
| 130 | + /goaccess/goaccess --no-global-config --config-file=${goan_config} & |
| 131 | + fi |
| 132 | +} |
0 commit comments