Skip to content

Commit 518c1cd

Browse files
Merge pull request #36 from xavier-hernandez/develop
v1.0.4
2 parents 5a6cb70 + b900770 commit 518c1cd

File tree

7 files changed

+151
-79
lines changed

7 files changed

+151
-79
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ COPY /resources/nginx/index.html /var/www/html/index.html
3737
COPY /resources/nginx/nginx.conf /etc/nginx/nginx.conf
3838
ADD /resources/nginx/.htpasswd /opt/auth/.htpasswd
3939

40-
COPY /resources/scripts/start.sh /start.sh
40+
WORKDIR /goan
41+
ADD /resources/scripts/funcs funcs
42+
COPY /resources/scripts/start.sh start.sh
43+
4144
VOLUME ["/opt/log"]
4245
EXPOSE 7880
43-
CMD ["sh", "/start.sh"]
46+
CMD ["sh", "/goan/start.sh"]

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
Still in development... You might need to wait a bit if you have a large amount of logs for it to parse.
44

5-
Docker image: https://hub.docker.com/r/xavierh/goaccess-for-nginxproxymanager
6-
7-
Docker tags: https://hub.docker.com/r/xavierh/goaccess-for-nginxproxymanager/tags
8-
9-
Github Repo: https://github.com/xavier-hernandez/goaccess-for-nginxproxymanager
10-
115
<br>
126

137
![Alt text](https://i.ibb.co/fNj9Dcy/goaccess1.jpg "GoAccess Dashboard")
@@ -16,7 +10,10 @@ New to creating docker images so bear with me. I did this more for me then for p
1610

1711
This docker container should work out of the box with Nginx Proxy Manager to parse proxy logs. The goaccess.conf has been configured to only access proxy logs and archived proxy logs.
1812

19-
The docker image scans and includes files matching the following criteria: proxy-host-*_access.log.gz proxy-host-*_access.log
13+
The docker image scans and includes files matching the following criteria:
14+
* proxy-host-*_access.log.gz
15+
* proxy-host-*_access.log
16+
* proxy-host-*.log
2017

2118
Currently using GoAccess version: 1.5.5
2219

@@ -33,6 +30,16 @@ Thanks to Just5KY you can find the arm version here: [justsky/goaccess-for-nginx
3330

3431
---
3532

33+
Docker image: https://hub.docker.com/r/xavierh/goaccess-for-nginxproxymanager
34+
35+
Docker tags: https://hub.docker.com/r/xavierh/goaccess-for-nginxproxymanager/tags
36+
37+
Github Repo: https://github.com/xavier-hernandez/goaccess-for-nginxproxymanager
38+
39+
---
40+
41+
42+
3643
<br>
3744

3845
```yml
-2.53 MB
Binary file not shown.

resources/nginx/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<title>GoAccess for Nginx Proxy Manager Logs</title>
4+
<title>GoAccess for Nginx Proxy Manager Logs - (#goan_version)</title>
55
<meta http-equiv="refresh" content="1" >
66
<style>
77
body {
@@ -11,8 +11,11 @@
1111
</head>
1212
<body>
1313
<p>
14-
loading... <br/>
15-
(might take some time depending on the number of files to parse)
16-
</p>
14+
<b>#goan_version</b>
15+
<br/><br/>
16+
loading... <br/><br/>
17+
Logs processing: #goan_processing_count (might take some time depending on the number of files to parse)
18+
<br/>
19+
</p>
1720
</body>
1821
</html>

resources/scripts/funcs/logs.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
#Find active logs and check for read access
4+
function logs_load_active() {
5+
echo "Checking active logs..."
6+
if [[ -d "${1}" && -x "${1}" ]];
7+
then
8+
IFS=$'\n'
9+
for file in $(find "${1}" -name 'proxy-host-*.log' ! -name "*_error.log");
10+
do
11+
if [ -f $file ]
12+
then
13+
if [ -r $file ] && R="Read = yes" || R="Read = No"
14+
then
15+
if [ -z "$goan_proxy_host" ]
16+
then
17+
goan_proxy_host="${goan_proxy_host}${file}"
18+
goan_proxy_log_count=$((goan_proxy_log_count+1))
19+
else
20+
goan_proxy_host="${goan_proxy_host} ${file}"
21+
goan_proxy_log_count=$((goan_proxy_log_count+1))
22+
fi
23+
echo -ne ' \t '
24+
echo "Filename: $file | $R"
25+
else
26+
echo -ne ' \t '
27+
echo "Filename: $file | $R"
28+
fi
29+
else
30+
echo -ne ' \t '
31+
echo "Filename: $file | Not a file"
32+
fi
33+
done
34+
unset IFS
35+
else
36+
echo "Problem loading directory (check directory or permissions)... ${1}"
37+
fi
38+
39+
if [ -z "$goan_proxy_host" ]
40+
then
41+
touch ${goan_container_active_log}
42+
goan_proxy_host=${goan_container_active_log}
43+
else
44+
echo "Found (${goan_proxy_log_count}) proxy logs...."
45+
fi
46+
}
47+
48+
#Find active logs and check for read access
49+
function logs_load_archive() {
50+
if [[ "${SKIP_ARCHIVED_LOGS}" == "True" ]]
51+
then
52+
echo "Skipping archived logs as requested..."
53+
touch ${goan_container_archive_log}
54+
else
55+
if [[ -d "${1}" && -x "${1}" ]];
56+
then
57+
count=`ls -1 ${1}/proxy-host-*_access.log*.gz 2>/dev/null | wc -l`
58+
if [ $count != 0 ]
59+
then
60+
echo "Loading (${count}) archived logs from ${1}..."
61+
zcat -f ${1}/proxy-host-*_access.log*.gz > ${goan_container_archive_log}
62+
else
63+
echo "No archived logs found at ${1}..."
64+
touch ${goan_container_archive_log}
65+
fi
66+
goan_proxy_archive_log_count=$((count))
67+
else
68+
echo "Problem loading directory (check directory or permissions)... ${1}"
69+
fi
70+
fi
71+
}

resources/scripts/funcs/nginx.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
#Set NGINX basic authentication
4+
function nginx_basic_auth() {
5+
if [[ "${BASIC_AUTH}" == "True" ]]
6+
then
7+
echo "Setting up basic auth in NGINX..."
8+
if [[ -z "$BASIC_AUTH_USERNAME" || -z "$BASIC_AUTH_PASSWORD" ]]
9+
then
10+
echo "Username or password is blank or not set."
11+
else
12+
nginx_auth_basic_s="#goan_authbasic"
13+
nginx_auth_basic_r="auth_basic \"GoAccess WebUI\";\n auth_basic_user_file \/opt\/auth\/.htpasswd; \n"
14+
sed -i "s/$nginx_auth_basic_s/$nginx_auth_basic_r/" /etc/nginx/nginx.conf
15+
16+
htpasswd -b /opt/auth/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
17+
fi
18+
fi
19+
}
20+
21+
#Set app image version
22+
function nginx_image_version() {
23+
src="#goan_version"
24+
rpl=${goan_version}
25+
sed -i "s/$src/$rpl/" /var/www/html/index.html
26+
}
27+
28+
function nginx_processing_count() {
29+
src="#goan_processing_count"
30+
rpl=$((goan_proxy_log_count+goan_proxy_archive_log_count))
31+
sed -i "s/$src/$rpl/" /var/www/html/index.html
32+
}

resources/scripts/start.sh

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,34 @@
11
#!/bin/bash
2+
source $(dirname "$0")/funcs/nginx.sh
3+
source $(dirname "$0")/funcs/logs.sh
24

3-
#BEGIN - Set NGINX basic authentication
4-
if [[ "${BASIC_AUTH}" == "True" ]]
5-
then
6-
echo "Setting up basic auth in NGINX..."
7-
if [[ -z "$BASIC_AUTH_USERNAME" || -z "$BASIC_AUTH_PASSWORD" ]]
8-
then
9-
echo "Username or password is blank or not set."
10-
else
11-
nginx_auth_basic_s="#goan_authbasic"
12-
nginx_auth_basic_r="auth_basic \"GoAccess WebUI\";\n auth_basic_user_file \/opt\/auth\/.htpasswd; \n"
13-
sed -i "s/$nginx_auth_basic_s/$nginx_auth_basic_r/" /etc/nginx/nginx.conf
5+
goan_version="GOAN v1.0.4"
6+
goan_log_path="/opt/log"
7+
goan_dir_valid=0 #false
8+
goan_proxy_host=""
9+
goan_container_archive_log="/goaccess/access_archive.log"
10+
goan_container_active_log="/goaccess/access.log"
11+
goan_proxy_log_count=0
12+
goan_proxy_archive_log_count=0
1413

15-
htpasswd -b /opt/auth/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
16-
fi
17-
fi
18-
#END - Set NGINX basic authentication
14+
echo -e "\n${goan_version}\n"
1915

20-
#BEGIN - Load archived logs
21-
if [[ "${SKIP_ARCHIVED_LOGS}" == "True" ]]
22-
then
23-
echo "Skipping archived logs as requested..."
24-
touch /goaccess/access_archive.log
25-
else
26-
count=`ls -1 /opt/log/proxy-host-*_access.log*.gz 2>/dev/null | wc -l`
27-
if [ $count != 0 ]
28-
then
29-
echo "Loading (${count}) archived logs..."
30-
zcat -f /opt/log/proxy-host-*_access.log*.gz > /goaccess/access_archive.log
31-
else
32-
echo "No archived logs found..."
33-
touch /goaccess/access_archive.log
34-
fi
35-
fi
36-
#END - Load archived logs
16+
#Set NGINX basic authentication
17+
nginx_basic_auth
3718

38-
#BEGIN - Find active logs and check for read access
39-
proxy_host=""
19+
#Load archived logs
20+
logs_load_archive ${goan_log_path}
4021

41-
echo "Checking active logs..."
42-
IFS=$'\n'
43-
for file in $(find /opt/log -name 'proxy-host-*_access.log');
44-
do
45-
if [ -f $file ]
46-
then
47-
if [ -r $file ] && R="Read = yes" || R="Read = No"
48-
then
49-
if [ -z "$proxy_host" ]
50-
then
51-
proxy_host="${proxy_host}${file}"
52-
else
53-
proxy_host="${proxy_host} ${file}"
54-
fi
55-
echo "Filename: $file | $R"
56-
else
57-
echo "Filename: $file | $R"
58-
fi
59-
else
60-
echo "Filename: $file | Not a file"
61-
fi
62-
done
63-
unset IFS
22+
#Find active logs and check for read access
23+
logs_load_active ${goan_log_path}
6424

65-
if [ -z "$proxy_host" ]
66-
then
67-
touch /goaccess/access.log
68-
proxy_host="/goaccess/access.log"
69-
else
70-
echo "Loading proxy-host logs..."
71-
fi
72-
#END - Find active logs and check for read access
25+
#Mods to index.html
26+
nginx_image_version
27+
nginx_processing_count
7328

7429
#RUN NGINX
7530
tini -s -- nginx
7631

7732
#RUN GOACCESS
78-
tini -s -- /goaccess/goaccess /goaccess/access_archive.log ${proxy_host} --no-global-config --config-file=/goaccess-config/goaccess.conf
33+
echo -e "\nProcessing ($((goan_proxy_log_count+goan_proxy_archive_log_count))) total log(s)...\n"
34+
tini -s -- /goaccess/goaccess ${goan_container_archive_log} ${goan_proxy_host} --no-global-config --config-file=/goaccess-config/goaccess.conf

0 commit comments

Comments
 (0)