forked from scollazo/docker-naxsi-waf-with-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·72 lines (58 loc) · 1.84 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#Check for local config files
if [ "$(find /etc/nginx/local-config -type f)" != "" ]
then
sed -i 's%include /etc/nginx/naxsi.rules;%include /etc/nginx/naxsi.rules;\n\t\tinclude /etc/nginx/local-rules/*;%g' /etc/nginx/sites-enabled/default
fi
#Check if we are asked to process old logs
if [ x${PROXY_REDIRECT_IP} = x"12.34.56.78" ]
then
echo "You need to set the PROXY_REDIRECT_IP"
echo "Run with:"
echo " docker run -e PROXY_REDIRECT_IP=<your_backend_ip> -p 80:80 -p 8081:8081 scollazo/bla"
exit 1
else
sed -i "s#proxy_redirect_ip#${PROXY_REDIRECT_IP}#" /etc/nginx/sites-enabled/default
fi
if [ x${LEARNING_MODE} != x"yes" ]
then
sed -i 's/LearningMode;//g' /etc/nginx/naxsi.rules
echo "LearningMode is disabled - Blocking requests"
else
echo "LearningMode is enabled"
fi
if [ x${ELASTICSEARCH_HOST} != x"elasticsearch" ]
then
sed -i "s/elasticsearch/${ELASTICSEARCH_HOST}/g" /usr/local/etc/nxapi.json
fi
#if [ x${KIBANA_PASSWORD} != x"popo" ]
# then
# #sed -i 's/LearningMode;//g' /etc/nginx/naxsi.rules
# PASS=
# echo "LearningMode is disabled - Blocking requests"
# else
# echo "LearningMode is enabled"
#fi
#Change owner for log files
if [ -d /var/log/nginx ]
then
chown www-data.www-data /var/log/nginx -R
fi
if [ x"$1" = x"debug" ]
then
echo "Changed config files. Not starting any daemon"
exit 0
fi
echo "Naxsi filtering requests to $PROXY_REDIRECT_IP"
nginx -c /etc/nginx/nginx.conf
## Ugly hack, but I don't know how to get live logs from nginx to nxtool
## --stdin goes crazy (infinite loop)
## --fifo goes crazy too
## --syslog didn't work for me with nginx 1.7.9 and
## nginx.conf: error_log syslog=localhost:51400 debug;
## So I used logtail, and --file
sh -c 'while $(pidof nginx > /dev/null)
do
logtail /var/log/nginx/error.log > current && nxtool.py --file=current && rm -f current
sleep 5
done'