Subversion Repositories ALCASAR

Rev

Rev 2841 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2841 Rev 3099
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-activity_report.sh 2841 2020-06-28 21:49:00Z rexy $
2
# $Id: alcasar-activity_report.sh 3099 2022-12-28 11:30:30Z rexy $
3
#
3
#
4
# Create an activity report for ALCASAR every week (sunday at 5.35 pm --> see cron.d).
4
# Create an activity report for ALCASAR every week (sunday at 5.35 pm --> see cron.d).
5
# We read configuration files and logs to create cool charts.
5
# We read configuration files and logs to create cool charts.
6
# Written by Raphaël PION, Rexy & Tom HOUDAYER
6
# Written by Raphaël PION, Rexy & Tom HOUDAYER
7
 
7
 
8
CONF_FILE='/usr/local/etc/alcasar.conf'
8
CONF_FILE='/usr/local/etc/alcasar.conf'
9
# files
9
# files
10
DIR_TMP="/var/tmp"
10
DIR_TMP="/var/tmp"
11
TMP_AV="$DIR_TMP/av_count.txt"
11
TMP_AV="$DIR_TMP/av_count.txt"
12
TMP_BL="$DIR_TMP/bl_count.txt"
12
TMP_BL="$DIR_TMP/bl_count.txt"
13
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt"
13
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt"
14
TMP_BL_WEEK_CAT="$DIR_TMP/bl_count_week_cat.txt"
14
TMP_BL_WEEK_CAT="$DIR_TMP/bl_count_week_cat.txt"
15
 
15
 
16
# Model loaded to create charts
16
# Model loaded to create charts
17
DIR_BUILD="/var/www/html/acc/manager/activity_report/"
17
DIR_BUILD="/var/www/html/acc/manager/activity_report/"
18
MODEL_CHARTJS="$DIR_BUILD/models/Chart.report.js"
18
MODEL_CHARTJS="$DIR_BUILD/models/Chart.report.js"
19
MODEL_TABINFO="$DIR_BUILD/models/tabinfo.html"
19
MODEL_TABINFO="$DIR_BUILD/models/tabinfo.html"
20
 
20
 
21
# Where the report will be created.
21
# Where the report will be created.
22
HTML_REPORT="$DIR_BUILD/alcasar-report-$(date +%F).html"
22
HTML_REPORT="$DIR_BUILD/alcasar-report-$(date +%F).html"
23
 
23
 
24
# TIME VALUE
24
# TIME VALUE
25
C_TS=$(date +"%s") #current timestamp
25
C_TS=$(date +"%s") #current timestamp
26
MAX_DAY_AGO=7
26
MAX_DAY_AGO=7
27
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
27
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
28
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
28
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
29
 
29
 
30
# PRIVATE IP OF ALCASAR
30
# PRIVATE IP OF ALCASAR
31
PRIVATE_IP=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2 | cut -d'/' -f1)
31
PRIVATE_IP=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2 | cut -d'/' -f1)
32
 
32
 
33
# COLOR for charts
33
# COLOR for charts
34
COLOR="'#ff0000','#3333cc','#009933','#993300','#1720EE','#D30229','#8D726D','#41C4E4','#8574F4','#A0BC1A','#BFDC1F','#5ADDC3','#B05744','#CD9319','#8CA39B','#D4AA1C','#A76752','#B03088','#445E87','#70424D','#D118C3','#46ABEF','#E9F197','#AEC0D4','#755C79','#94BBD7','#E2E9DC','#8B68D0','#F7EC7C','#1F16B8','#F4DA0A','#2EC17A','#E06483','#48B342','#F510CD','#9B2662','#180E98','#988FC1','#209E4E','#034240','#FDB142','#36B445','#CDD5C9','#6FA0DE','#EE2206','#204E19','#15FC93','#161ECE','#83D33B','#11A44A','#B7BF6C','#87274C','#B52C4F','#AD2805','#427E6C','#91341A','#191315','#FCB290','#13D3CD','#90F0E6','#C870C9','#AD2C14','#201D2A','#E4DB79','#90A919','#FE17FE','#09B35C','#88D950','#3440FC','#A9D42F','#E2DFAC','#DA69EC','#67430A','#43E94E','#5F7349','#22CF16','#CF038F','#0F6427','#F7AD0F','#C5E382','#DB49B6','#F760BF','#0BE701','#EF88D8','#79E6D7','#8A2D3D','#435A30','#A3C8AC','#99B118','#A929FF','#08A36D','#0A1654','#6F8283','#E1CA3E','#3E8577','#580FB6','#DB0E16','#386CBE','#FA0C43','#B713C9'"
34
COLOR="'#ff0000','#3333cc','#009933','#993300','#1720EE','#D30229','#8D726D','#41C4E4','#8574F4','#A0BC1A','#BFDC1F','#5ADDC3','#B05744','#CD9319','#8CA39B','#D4AA1C','#A76752','#B03088','#445E87','#70424D','#D118C3','#46ABEF','#E9F197','#AEC0D4','#755C79','#94BBD7','#E2E9DC','#8B68D0','#F7EC7C','#1F16B8','#F4DA0A','#2EC17A','#E06483','#48B342','#F510CD','#9B2662','#180E98','#988FC1','#209E4E','#034240','#FDB142','#36B445','#CDD5C9','#6FA0DE','#EE2206','#204E19','#15FC93','#161ECE','#83D33B','#11A44A','#B7BF6C','#87274C','#B52C4F','#AD2805','#427E6C','#91341A','#191315','#FCB290','#13D3CD','#90F0E6','#C870C9','#AD2C14','#201D2A','#E4DB79','#90A919','#FE17FE','#09B35C','#88D950','#3440FC','#A9D42F','#E2DFAC','#DA69EC','#67430A','#43E94E','#5F7349','#22CF16','#CF038F','#0F6427','#F7AD0F','#C5E382','#DB49B6','#F760BF','#0BE701','#EF88D8','#79E6D7','#8A2D3D','#435A30','#A3C8AC','#99B118','#A929FF','#08A36D','#0A1654','#6F8283','#E1CA3E','#3E8577','#580FB6','#DB0E16','#386CBE','#FA0C43','#B713C9'"
35
 
35
 
36
# Values to create new htdigest user to consult statistique of ACC
36
# Values to create new htdigest user to consult statistique of ACC
37
DIR_KEY="/usr/local/etc/digest"
37
DIR_KEY="/usr/local/etc/digest"
38
tmp_account="tmp_activityreport"
38
tmp_account="tmp_activityreport"
39
realm="ALCASAR Control Center (ACC)"
39
realm="ALCASAR Control Center (ACC)"
40
password=$(openssl rand -base64 32) #random password (length : 32)
40
password=$(openssl rand -base64 32) #random password (length : 32)
41
SED="/usr/bin/sed -i "
41
SED="/usr/bin/sed -i "
42
TMP_STATS="$DIR_TMP/stats.html"
42
TMP_STATS="$DIR_TMP/stats.html"
43
TMP_STATS_2="$DIR_TMP/stats2.html"
43
TMP_STATS_2="$DIR_TMP/stats2.html"
44
 
44
 
45
# if empty logs, replace charts by text.
45
# if empty logs, replace charts by text.
46
ENABLE_BL=0
46
ENABLE_BL=0
47
ENABLE_BL_WEEK=0
47
ENABLE_BL_WEEK=0
48
ENABLE_AV=0
48
ENABLE_AV=0
49
 
49
 
50
if [ -e $TMP_AV ]
50
if [ -e $TMP_AV ]
51
then
51
then
52
	rm $TMP_AV
52
	rm $TMP_AV
53
fi
53
fi
54
 
54
 
55
if [ -e $TMP_BL ]
55
if [ -e $TMP_BL ]
56
then
56
then
57
	rm $TMP_BL
57
	rm $TMP_BL
58
fi
58
fi
59
 
59
 
60
if [ -e $TMP_BL_WEEK ]
60
if [ -e $TMP_BL_WEEK ]
61
then
61
then
62
	rm $TMP_BL_WEEK
62
	rm $TMP_BL_WEEK
63
fi
63
fi
64
 
64
 
65
if [ -e $TMP_BL_WEEK_CAT ]
65
if [ -e $TMP_BL_WEEK_CAT ]
66
then
66
then
67
	rm $TMP_BL_WEEK_CAT
67
	rm $TMP_BL_WEEK_CAT
68
fi
68
fi
69
 
69
 
70
if [ -e $HTML_REPORT ]
70
if [ -e $HTML_REPORT ]
71
then
71
then
72
	rm $HTML_REPORT
72
	rm $HTML_REPORT
73
fi
73
fi
74
 
74
 
75
echo "<!doctype html>" >> $HTML_REPORT
75
echo "<!doctype html>" >> $HTML_REPORT
76
echo "<html>" >> $HTML_REPORT
76
echo "<html>" >> $HTML_REPORT
77
echo "<head>" >> $HTML_REPORT
77
echo "<head>" >> $HTML_REPORT
78
echo "<meta charset=\"utf-8\">" >> $HTML_REPORT
78
echo "<meta charset=\"utf-8\">" >> $HTML_REPORT
79
echo "<title>ALCASAR report</title>" >> $HTML_REPORT
79
echo "<title>ALCASAR report</title>" >> $HTML_REPORT
80
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/bootstrap.min.css\">" >> $HTML_REPORT
80
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/bootstrap.min.css\">" >> $HTML_REPORT
81
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
81
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
82
echo "<script src=\"../../../js/Chart.bundle.min.js\"></script>" >> $HTML_REPORT
82
echo "<script src=\"../../../js/Chart.bundle.min.js\"></script>" >> $HTML_REPORT
83
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
83
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
84
echo "</head>" >> $HTML_REPORT
84
echo "</head>" >> $HTML_REPORT
85
echo "<body>" >> $HTML_REPORT
85
echo "<body>" >> $HTML_REPORT
86
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)</center></h1>" >> $HTML_REPORT
86
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)</center></h1>" >> $HTML_REPORT
87
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
87
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
88
echo "<font size=\"1\">" >> $HTML_REPORT
88
echo "<font size=\"1\">" >> $HTML_REPORT
89
 
89
 
90
######################TABINFO######################
90
######################TABINFO######################
91
echo "Create information about system and ALCASAR"
91
echo "Create information about system and ALCASAR"
92
#contain every information about ALCASAR configuration, system and last update
92
#contain every information about ALCASAR configuration, system and last update
93
 
93
 
94
cat $MODEL_TABINFO | while read LINE_HTML
94
cat $MODEL_TABINFO | while read LINE_HTML
95
do
95
do
96
	if [ "$(echo $LINE_HTML | grep 'XXORGXX' | wc -l)" -eq 1 ]
96
	if [ "$(echo $LINE_HTML | grep 'XXORGXX' | wc -l)" -eq 1 ]
97
	then
97
	then
98
		VALUE=$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)
98
		VALUE=$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)
99
		echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
99
		echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
100
 
100
 
101
	elif [ "$(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l)" -eq 1 ]
101
	elif [ "$(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l)" -eq 1 ]
102
	then
102
	then
103
		VALUE=$(grep ^INSTALL_DATE= $CONF_FILE | cut -d'=' -f2)
103
		VALUE=$(grep ^INSTALL_DATE= $CONF_FILE | cut -d'=' -f2)
104
		echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
104
		echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
105
 
105
 
106
	elif [ "$(echo $LINE_HTML | grep 'XXAVERSIONXX' | wc -l)" -eq 1 ]
106
	elif [ "$(echo $LINE_HTML | grep 'XXAVERSIONXX' | wc -l)" -eq 1 ]
107
	then
107
	then
108
		VALUE=$(grep ^VERSION= $CONF_FILE | cut -d'=' -f2)
108
		VALUE=$(grep ^VERSION= $CONF_FILE | cut -d'=' -f2)
109
		echo ${LINE_HTML/XXAVERSIONXX/$VALUE} >> $HTML_REPORT
109
		echo ${LINE_HTML/XXAVERSIONXX/$VALUE} >> $HTML_REPORT
110
 
110
 
111
	elif [ "$(echo $LINE_HTML | grep 'XXIP_PUBLICXX' | wc -l)" -eq 1 ]
111
	elif [ "$(echo $LINE_HTML | grep 'XXIP_PUBLICXX' | wc -l)" -eq 1 ]
112
	then
112
	then
113
		VALUE=$(grep ^PUBLIC_IP= $CONF_FILE | cut -d'=' -f2)
113
		VALUE=$(grep ^PUBLIC_IP= $CONF_FILE | cut -d'=' -f2)
114
		echo ${LINE_HTML/XXIP_PUBLICXX/$VALUE} >> $HTML_REPORT
114
		echo ${LINE_HTML/XXIP_PUBLICXX/$VALUE} >> $HTML_REPORT
115
 
115
 
116
	elif [ "$(echo $LINE_HTML | grep 'XXIP_PRIVEXX' | wc -l)" -eq 1 ]
116
	elif [ "$(echo $LINE_HTML | grep 'XXIP_PRIVEXX' | wc -l)" -eq 1 ]
117
	then
117
	then
118
		VALUE=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2)
118
		VALUE=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2)
119
		echo ${LINE_HTML/XXIP_PRIVEXX/$VALUE} >> $HTML_REPORT
119
		echo ${LINE_HTML/XXIP_PRIVEXX/$VALUE} >> $HTML_REPORT
120
 
120
 
121
	elif [ "$(echo $LINE_HTML | grep 'XXGWXX' | wc -l)" -eq 1 ]
121
	elif [ "$(echo $LINE_HTML | grep 'XXGWXX' | wc -l)" -eq 1 ]
122
	then
122
	then
123
		VALUE=$(grep ^GW= $CONF_FILE | cut -d'=' -f2)
123
		VALUE=$(grep ^GW= $CONF_FILE | cut -d'=' -f2)
124
		echo ${LINE_HTML/XXGWXX/$VALUE} >> $HTML_REPORT
124
		echo ${LINE_HTML/XXGWXX/$VALUE} >> $HTML_REPORT
125
 
125
 
126
	elif [ "$(echo $LINE_HTML | grep 'XXDNS1XX' | wc -l)" -eq 1 ]
126
	elif [ "$(echo $LINE_HTML | grep 'XXDNS1XX' | wc -l)" -eq 1 ]
127
	then
127
	then
128
		VALUE=$(grep ^DNS1= $CONF_FILE | cut -d'=' -f2)
128
		VALUE=$(grep ^DNS1= $CONF_FILE | cut -d'=' -f2)
129
		echo ${LINE_HTML/XXDNS1XX/$VALUE} >> $HTML_REPORT
129
		echo ${LINE_HTML/XXDNS1XX/$VALUE} >> $HTML_REPORT
130
 
130
 
131
	elif [ "$(echo $LINE_HTML | grep 'XXDNS2XX' | wc -l)" -eq 1 ]
131
	elif [ "$(echo $LINE_HTML | grep 'XXDNS2XX' | wc -l)" -eq 1 ]
132
	then
132
	then
133
		VALUE=$(grep ^DNS2= $CONF_FILE | cut -d'=' -f2)
133
		VALUE=$(grep ^DNS2= $CONF_FILE | cut -d'=' -f2)
134
		echo ${LINE_HTML/XXDNS2XX/$VALUE} >> $HTML_REPORT
134
		echo ${LINE_HTML/XXDNS2XX/$VALUE} >> $HTML_REPORT
135
 
135
 
136
	elif [ "$(echo $LINE_HTML | grep 'XXHOSTXX' | wc -l)" -eq 1 ]
136
	elif [ "$(echo $LINE_HTML | grep 'XXHOSTXX' | wc -l)" -eq 1 ]
137
	then
137
	then
138
		VALUE=$(hostname)
138
		VALUE=$(hostname)
139
		echo ${LINE_HTML/XXHOSTXX/$VALUE} >> $HTML_REPORT
139
		echo ${LINE_HTML/XXHOSTXX/$VALUE} >> $HTML_REPORT
140
 
140
 
141
	elif [ "$(echo $LINE_HTML | grep 'XXOS_VERSIONXX' | wc -l)" -eq 1 ]
141
	elif [ "$(echo $LINE_HTML | grep 'XXOS_VERSIONXX' | wc -l)" -eq 1 ]
142
	then
142
	then
143
		VALUE=$(echo "$(uname -r) [ $(uname -m) ]")
143
		VALUE=$(echo "$(uname -r) [ $(uname -m) ]")
144
		echo ${LINE_HTML/XXOS_VERSIONXX/$VALUE} >> $HTML_REPORT
144
		echo ${LINE_HTML/XXOS_VERSIONXX/$VALUE} >> $HTML_REPORT
145
 
145
 
146
	elif [ "$(echo $LINE_HTML | grep 'XXREBOOTXX' | wc -l)" -eq 1 ]
146
	elif [ "$(echo $LINE_HTML | grep 'XXREBOOTXX' | wc -l)" -eq 1 ]
147
	then
147
	then
148
		VALUE=$(who -b | cut -d' ' -f12-)
148
		VALUE=$(who -b | cut -d' ' -f12-)
149
		echo ${LINE_HTML/XXREBOOTXX/$VALUE} >> $HTML_REPORT
149
		echo ${LINE_HTML/XXREBOOTXX/$VALUE} >> $HTML_REPORT
150
 
150
 
151
	elif [ "$(echo $LINE_HTML | grep 'XXMAJCLAMAVXX' | wc -l)" -eq 1 ]
151
	elif [ "$(echo $LINE_HTML | grep 'XXMAJCLAMAVXX' | wc -l)" -eq 1 ]
152
	then
152
	then
153
		VALUE=$(date -d "@$(rpm -qa --queryformat "%{installtime} %{name}\n" | grep -E "clamav-db" | cut -d' ' -f1 )" "+%Y-%m-%d %H:%M:%S")
153
		VALUE=$(date -d "@$(rpm -qa --queryformat "%{installtime} %{name}\n" | grep -E "clamav-db" | cut -d' ' -f1 )" "+%Y-%m-%d %H:%M:%S")
154
		echo ${LINE_HTML/XXMAJCLAMAVXX/$VALUE} >> $HTML_REPORT
154
		echo ${LINE_HTML/XXMAJCLAMAVXX/$VALUE} >> $HTML_REPORT
155
 
155
 
156
	elif [ "$(echo $LINE_HTML | grep 'XXMAJBLXX' | wc -l)" -eq 1 ]
156
	elif [ "$(echo $LINE_HTML | grep 'XXMAJBLXX' | wc -l)" -eq 1 ]
157
	then
157
	then
158
		VALUE=$(cat /etc/e2guardian/lists/blacklists/README | grep 'Last version' | cut -d' ' -f4-6)
158
		VALUE=$(cat /etc/e2guardian/lists/blacklists/README | grep 'Last version' | cut -d' ' -f4-6)
159
		echo ${LINE_HTML/XXMAJBLXX/$VALUE} >> $HTML_REPORT
159
		echo ${LINE_HTML/XXMAJBLXX/$VALUE} >> $HTML_REPORT
160
 
160
 
161
	elif [ "$(echo $LINE_HTML | grep 'XXRPMXX' | wc -l)" -eq 1 ]
161
	elif [ "$(echo $LINE_HTML | grep 'XXRPMXX' | wc -l)" -eq 1 ]
162
	then
162
	then
163
		#show every ALCASAR RPM updated since X day ago
163
		#show every ALCASAR RPM updated since X day ago
164
		#get timestamp of X day ago. Then we get every packets chich have been updated since this date.
164
		#get timestamp of X day ago. Then we get every packets chich have been updated since this date.
165
		if [ "$(rpm -qa --queryformat '%{installtime} %{name} %{version}\n' | awk -v seuil="$SECS_AGO" '$1 > seuil' | sort -n | grep -E "$PACKAGE" | wc -l)" -gt 1 ]
165
		if [ "$(rpm -qa --queryformat '%{installtime} %{name} %{version}\n' | awk -v seuil="$SECS_AGO" '$1 > seuil' | sort -n | grep -E "$PACKAGE" | wc -l)" -gt 1 ]
166
		then
166
		then
167
			PACKAGE='php|lighttpd|iptables|dnsmasq|unbound|radius|nfdump|e2guardian|clamav|ulogd|chilli|fail2ban|openssh|ipt-netflow|wget|mariadb|gnupg|openssl'
167
			PACKAGE='php|lighttpd|iptables|unbound|radius|nfdump|e2guardian|clamav|ulogd|chilli|fail2ban|openssh|ipt-netflow|wget|mariadb|gnupg|openssl'
168
			rpm -qa --queryformat '%{installtime} %{name} %{version}\n' | awk -v seuil="$SECS_AGO" '$1 > seuil' | sort -n | grep -E "$PACKAGE" | while read RPM_ALCASAR
168
			rpm -qa --queryformat '%{installtime} %{name} %{version}\n' | awk -v seuil="$SECS_AGO" '$1 > seuil' | sort -n | grep -E "$PACKAGE" | while read RPM_ALCASAR
169
			do
169
			do
170
				RPM_TIMESTAMP=$(echo $RPM_ALCASAR | cut -d' ' -f1)
170
				RPM_TIMESTAMP=$(echo $RPM_ALCASAR | cut -d' ' -f1)
171
				RPM_DATE=$(date -d "@$(echo $RPM_TIMESTAMP)" "+%Y-%m-%d %H:%M:%S")
171
				RPM_DATE=$(date -d "@$(echo $RPM_TIMESTAMP)" "+%Y-%m-%d %H:%M:%S")
172
				RPM_NAME=$(echo $RPM_ALCASAR | cut -d' ' -f2)
172
				RPM_NAME=$(echo $RPM_ALCASAR | cut -d' ' -f2)
173
				RPM_VERSION=$(echo $RPM_ALCASAR | cut -d' ' -f3)
173
				RPM_VERSION=$(echo $RPM_ALCASAR | cut -d' ' -f3)
174
 
174
 
175
				echo "<tr>" >> $HTML_REPORT
175
				echo "<tr>" >> $HTML_REPORT
176
				echo "<td>$RPM_NAME</td>" >> $HTML_REPORT
176
				echo "<td>$RPM_NAME</td>" >> $HTML_REPORT
177
				echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
177
				echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
178
				echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
178
				echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
179
				echo "</tr>" >> $HTML_REPORT
179
				echo "</tr>" >> $HTML_REPORT
180
			done
180
			done
181
		else
181
		else
182
			echo "<tr><td colspan=\"3\">Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT
182
			echo "<tr><td colspan=\"3\">Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT
183
		fi
183
		fi
184
	else
184
	else
185
		echo $LINE_HTML >> $HTML_REPORT
185
		echo $LINE_HTML >> $HTML_REPORT
186
	fi
186
	fi
187
done
187
done
188
 
188
 
189
######################BL WEBSITE SINCE INSTALLATION######################
189
######################BL WEBSITE SINCE INSTALLATION######################
190
echo "Create BL website since the installation of ALCASAR"
190
echo "Create BL website since the installation of ALCASAR"
191
#find data
191
#find data
192
 
192
 
193
#decompress every logs
193
#decompress every logs
194
if [ "$(ls -1 /var/log/unbound/unbound-blacklist.log.*.gz 2>/dev/null | wc -l)" -ge 1 ]
194
if [ "$(ls -1 /var/log/unbound/unbound-blacklist.log.*.gz 2>/dev/null | wc -l)" -ge 1 ]
195
then
195
then
196
	gunzip -d unbound-blacklist.log.*.gz
196
	gunzip -d unbound-blacklist.log.*.gz
197
fi
197
fi
198
 
198
 
199
#convert logs date in timestamp and find categories of blacklisted website
199
#convert logs date in timestamp and find categories of blacklisted website
200
tmp_log=$(mktemp)
200
tmp_log=$(mktemp)
201
for FILE in /var/log/unbound/unbound-blacklist.log*
201
for FILE in /var/log/unbound/unbound-blacklist.log*
202
do
202
do
203
	grep -E "info: [^ ]+ typetransparent $PRIVATE_IP" /var/log/unbound/unbound-blacklist.log > $tmp_log
203
	grep -E "info: [^ ]+ typetransparent $PRIVATE_IP" /var/log/unbound/unbound-blacklist.log > $tmp_log
204
	while read LOG_BL
204
	while read LOG_BL
205
	do
205
	do
206
		# find the current blacklisted category
206
		# find the current blacklisted category
207
		website_bl=$(echo $LOG_BL | cut -d' ' -f4)
207
		website_bl=$(echo $LOG_BL | cut -d' ' -f4)
208
		website_bl=${website_bl%?} # remove the last character
208
		website_bl=${website_bl%?} # remove the last character
209
 
209
 
210
		#we convert www.test.co.uk => test.co.uk to find the category of this website
210
		#we convert www.test.co.uk => test.co.uk to find the category of this website
211
		if [ "$(grep -o '\.' <<< "$website_bl" | wc -l)" -ge "2" ]
211
		if [ "$(grep -o '\.' <<< "$website_bl" | wc -l)" -ge "2" ]
212
		then
212
		then
213
			website_bl=$(echo $website_bl | cut -d'.' -f2-)
213
			website_bl=$(echo $website_bl | cut -d'.' -f2-)
214
		fi
214
		fi
215
 
215
 
216
		#get BL category
216
		#get BL category
217
		categorie_bl=$(grep -Rl "$website_bl" /usr/local/share/unbound-bl-enabled/ | cut -d'/' -f6 | head -1)
217
		categorie_bl=$(grep -Rl "$website_bl" /usr/local/share/unbound-bl-enabled/ | cut -d'/' -f6 | head -1)
218
 
218
 
219
		CURRENT_TS=$(echo $LOG_BL | cut -d '[' -f2 | cut -d ']' -f1)
219
		CURRENT_TS=$(echo $LOG_BL | cut -d '[' -f2 | cut -d ']' -f1)
220
		echo "$CURRENT_TS:$categorie_bl:" >> $TMP_BL
220
		echo "$CURRENT_TS:$categorie_bl:" >> $TMP_BL
221
	done < $tmp_log
221
	done < $tmp_log
222
done
222
done
223
rm $tmp_log
223
rm $tmp_log
224
 
224
 
225
#if data exists, create this section in html document
225
#if data exists, create this section in html document
226
if [ -e $TMP_BL ]
226
if [ -e $TMP_BL ]
227
then
227
then
228
	ENABLE_BL=1
228
	ENABLE_BL=1
229
	#count every BL website consulted since installation (maximum 1 year)
229
	#count every BL website consulted since installation (maximum 1 year)
230
	DATE_END=$(cat $TMP_BL | cut -d':' -f1 | sort -n | head -1 )
230
	DATE_END=$(cat $TMP_BL | cut -d':' -f1 | sort -n | head -1 )
231
 
231
 
232
 
232
 
233
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
233
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
234
	do
234
	do
235
		DATE_1=$TS
235
		DATE_1=$TS
236
		DATE_2=$((TS-$STEP_TS))
236
		DATE_2=$((TS-$STEP_TS))
237
		COUNT_BL_INSTALLATION=0
237
		COUNT_BL_INSTALLATION=0
238
 
238
 
239
		for LINE in $(cat $TMP_BL)
239
		for LINE in $(cat $TMP_BL)
240
		do
240
		do
241
			TS_FILE=$(echo $LINE | cut -d':' -f1)
241
			TS_FILE=$(echo $LINE | cut -d':' -f1)
242
 
242
 
243
			if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
243
			if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
244
			then
244
			then
245
				COUNT_BL_INSTALLATION=$((COUNT_BL_INSTALLATION+1))
245
				COUNT_BL_INSTALLATION=$((COUNT_BL_INSTALLATION+1))
246
			fi
246
			fi
247
		done
247
		done
248
 
248
 
249
		VALUE_BL_INSTALLATION_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_BL_INSTALLATION_LABEL"
249
		VALUE_BL_INSTALLATION_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_BL_INSTALLATION_LABEL"
250
		VALUE_BL_INSTALLATION_DATA="$COUNT_BL_INSTALLATION, $VALUE_BL_INSTALLATION_DATA"
250
		VALUE_BL_INSTALLATION_DATA="$COUNT_BL_INSTALLATION, $VALUE_BL_INSTALLATION_DATA"
251
	done
251
	done
252
 
252
 
253
	#create Antivirus section in html document
253
	#create Antivirus section in html document
254
	NAME_BL_INSTALLATION='chart_bl_installation'
254
	NAME_BL_INSTALLATION='chart_bl_installation'
255
	CONF_BL_INSTALLATION='config_bl_installation'
255
	CONF_BL_INSTALLATION='config_bl_installation'
256
	echo "<center>" >> $HTML_REPORT
256
	echo "<center>" >> $HTML_REPORT
257
	echo "<canvas id='$NAME_BL_INSTALLATION' width='450' height='450'></canvas>" >> $HTML_REPORT
257
	echo "<canvas id='$NAME_BL_INSTALLATION' width='450' height='450'></canvas>" >> $HTML_REPORT
258
	echo "</center>" >> $HTML_REPORT
258
	echo "</center>" >> $HTML_REPORT
259
 
259
 
260
	#create chart bar in html file with javascript (chartjs.com)
260
	#create chart bar in html file with javascript (chartjs.com)
261
	echo "<script>" >> $HTML_REPORT
261
	echo "<script>" >> $HTML_REPORT
262
	cat $MODEL_CHARTJS | while read LINE_JS
262
	cat $MODEL_CHARTJS | while read LINE_JS
263
	do
263
	do
264
		#name of variable
264
		#name of variable
265
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
265
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
266
		then
266
		then
267
			echo ${LINE_JS/XXCONFXX/$CONF_BL_INSTALLATION} >> $HTML_REPORT
267
			echo ${LINE_JS/XXCONFXX/$CONF_BL_INSTALLATION} >> $HTML_REPORT
268
		#chart type
268
		#chart type
269
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
269
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
270
		then
270
		then
271
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
271
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
272
		#chart title
272
		#chart title
273
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
273
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
274
		then
274
		then
275
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués au total"} >> $HTML_REPORT
275
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués au total"} >> $HTML_REPORT
276
		#chart data
276
		#chart data
277
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
277
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
278
		then
278
		then
279
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_INSTALLATION_DATA} >> $HTML_REPORT
279
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_INSTALLATION_DATA} >> $HTML_REPORT
280
		#color
280
		#color
281
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
281
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
282
		then
282
		then
283
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
283
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
284
		#labels
284
		#labels
285
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
285
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
286
		then
286
		then
287
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_INSTALLATION_LABEL} >> $HTML_REPORT
287
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_INSTALLATION_LABEL} >> $HTML_REPORT
288
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
288
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
289
		then
289
		then
290
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
290
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
291
		#display value of Y axis, only useful for chart bar
291
		#display value of Y axis, only useful for chart bar
292
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
292
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
293
		then
293
		then
294
			echo "" >> $HTML_REPORT
294
			echo "" >> $HTML_REPORT
295
		#display value of Y axis, only useful for chart bar
295
		#display value of Y axis, only useful for chart bar
296
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
296
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
297
		then
297
		then
298
			echo "" >> $HTML_REPORT
298
			echo "" >> $HTML_REPORT
299
		elif [ "$(echo $LINE_JS | grep 'XXYLABELXX' | wc -l)" -eq 1 ]
299
		elif [ "$(echo $LINE_JS | grep 'XXYLABELXX' | wc -l)" -eq 1 ]
300
		then
300
		then
301
			echo "\"Nombre de site bloqué par la blacklist\"" >> $HTML_REPORT
301
			echo "\"Nombre de site bloqué par la blacklist\"" >> $HTML_REPORT
302
		else
302
		else
303
			echo $LINE_JS >> $HTML_REPORT
303
			echo $LINE_JS >> $HTML_REPORT
304
		fi
304
		fi
305
	done
305
	done
306
	echo "</script>" >> $HTML_REPORT
306
	echo "</script>" >> $HTML_REPORT
307
else
307
else
308
	echo "<h2>Aucune activité de la Blacklist depuis l'installation.</h2>" >> $HTML_REPORT
308
	echo "<h2>Aucune activité de la Blacklist depuis l'installation.</h2>" >> $HTML_REPORT
309
fi
309
fi
310
 
310
 
311
 
311
 
312
 
312
 
313
######################Unbound BLACKLIST######################
313
######################Unbound BLACKLIST######################
314
echo "Create BL website since $MAX_DAY_AGO days"
314
echo "Create BL website since $MAX_DAY_AGO days"
315
 
315
 
316
#if data exists, create BL section in html document
316
#if data exists, create BL section in html document
317
if [ -e $TMP_BL ]
317
if [ -e $TMP_BL ]
318
then
318
then
319
	ENABLE_BL_WEEK=1
319
	ENABLE_BL_WEEK=1
320
	#find data
320
	#find data
321
	#count every BL website consulted since DAYS_AGO
321
	#count every BL website consulted since DAYS_AGO
322
	DATE_1=$C_TS
322
	DATE_1=$C_TS
323
	DATE_2=$((DATE_1-$STEP_TS))
323
	DATE_2=$((DATE_1-$STEP_TS))
324
 
324
 
325
	touch $TMP_BL_WEEK
325
	touch $TMP_BL_WEEK
326
 
326
 
327
	for LINE in $(cat $TMP_BL)
327
	for LINE in $(cat $TMP_BL)
328
	do
328
	do
329
		TS_FILE=$(echo $LINE | cut -d':' -f1)
329
		TS_FILE=$(echo $LINE | cut -d':' -f1)
330
		#select only elements between DATE_1 and DATE_2
330
		#select only elements between DATE_1 and DATE_2
331
		if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
331
		if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
332
		then
332
		then
333
			echo $LINE >> $TMP_BL_WEEK
333
			echo $LINE >> $TMP_BL_WEEK
334
		fi
334
		fi
335
	done
335
	done
336
 
336
 
337
	#then we count every occurence for each category in TMP_BL_WEEK
337
	#then we count every occurence for each category in TMP_BL_WEEK
338
	for CAT in $(ls /usr/local/share/unbound-bl/ -1 | cut -d'.' -f1)
338
	for CAT in $(ls /usr/local/share/unbound-bl/ -1 | cut -d'.' -f1)
339
	do
339
	do
340
		echo "$CAT:$(grep -o ":$CAT:" <<< "$(cat $TMP_BL_WEEK)" | wc -l):" >> $TMP_BL_WEEK_CAT
340
		echo "$CAT:$(grep -o ":$CAT:" <<< "$(cat $TMP_BL_WEEK)" | wc -l):" >> $TMP_BL_WEEK_CAT
341
	done
341
	done
342
 
342
 
343
	#we sort by number of occurence and we take the top 10 BL categories
343
	#we sort by number of occurence and we take the top 10 BL categories
344
	for LINE in $(sort -t':' -k2 -rn $TMP_BL_WEEK_CAT | head -n 10)
344
	for LINE in $(sort -t':' -k2 -rn $TMP_BL_WEEK_CAT | head -n 10)
345
	do
345
	do
346
 
346
 
347
		DATA=$(echo $LINE | cut -d':' -f2)
347
		DATA=$(echo $LINE | cut -d':' -f2)
348
		LABEL=$(echo $LINE | cut -d':' -f1)
348
		LABEL=$(echo $LINE | cut -d':' -f1)
349
		if [ $DATA -ne 0 ]
349
		if [ $DATA -ne 0 ]
350
		then
350
		then
351
			VALUE_BL_DATA="$VALUE_BL_DATA $DATA, "
351
			VALUE_BL_DATA="$VALUE_BL_DATA $DATA, "
352
			VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
352
			VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
353
		fi
353
		fi
354
	done
354
	done
355
 
355
 
356
	#get other categories (sum them all)
356
	#get other categories (sum them all)
357
	if [ "$(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc)" -gt 0 ]
357
	if [ "$(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc)" -gt 0 ]
358
	then
358
	then
359
		VALUE_BL_DATA="$VALUE_BL_DATA $(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc)"
359
		VALUE_BL_DATA="$VALUE_BL_DATA $(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc)"
360
		VALUE_BL_LABEL="$VALUE_BL_LABEL 'autre ($(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc))'"
360
		VALUE_BL_LABEL="$VALUE_BL_LABEL 'autre ($(cat $TMP_BL_WEEK_CAT | cut -d':' -f2 | sort -k1 -rn | tail -n+$(($(echo $VALUE_BL_DATA | wc -w)+1)) | paste -sd+ | bc))'"
361
	fi
361
	fi
362
 
362
 
363
	#create chart pie in html file with javascript (chartjs.com)
363
	#create chart pie in html file with javascript (chartjs.com)
364
	NAME_BL='chart_bl'
364
	NAME_BL='chart_bl'
365
	CONF_BL='config_bl'
365
	CONF_BL='config_bl'
366
	echo "<center>" >> $HTML_REPORT
366
	echo "<center>" >> $HTML_REPORT
367
	echo "<canvas id='$NAME_BL' width='450' height='450' ></canvas>" >> $HTML_REPORT
367
	echo "<canvas id='$NAME_BL' width='450' height='450' ></canvas>" >> $HTML_REPORT
368
	echo "</center>" >> $HTML_REPORT
368
	echo "</center>" >> $HTML_REPORT
369
	echo "<script>" >> $HTML_REPORT
369
	echo "<script>" >> $HTML_REPORT
370
 
370
 
371
	cat $MODEL_CHARTJS | while read LINE_JS
371
	cat $MODEL_CHARTJS | while read LINE_JS
372
	do
372
	do
373
		#variable name
373
		#variable name
374
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
374
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
375
		then
375
		then
376
			echo ${LINE_JS/XXCONFXX/$CONF_BL} >> $HTML_REPORT
376
			echo ${LINE_JS/XXCONFXX/$CONF_BL} >> $HTML_REPORT
377
		#chart type
377
		#chart type
378
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
378
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
379
		then
379
		then
380
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
380
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
381
		#graph title
381
		#graph title
382
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
382
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
383
		then
383
		then
384
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
384
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
385
		#chart data
385
		#chart data
386
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
386
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
387
		then
387
		then
388
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
388
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
389
		#color
389
		#color
390
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
390
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
391
		then
391
		then
392
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
392
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
393
		#labels
393
		#labels
394
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
394
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
395
		then
395
		then
396
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_LABEL} >> $HTML_REPORT
396
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_LABEL} >> $HTML_REPORT
397
		#display legend, only useful for chart pie
397
		#display legend, only useful for chart pie
398
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
398
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
399
		then
399
		then
400
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
400
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
401
		#display value of Y axis, only useful for chart bar
401
		#display value of Y axis, only useful for chart bar
402
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
402
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
403
		then
403
		then
404
			echo "/*" >> $HTML_REPORT
404
			echo "/*" >> $HTML_REPORT
405
		#display value of Y axis, only useful for chart bar
405
		#display value of Y axis, only useful for chart bar
406
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
406
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
407
		then
407
		then
408
			echo "*/" >> $HTML_REPORT
408
			echo "*/" >> $HTML_REPORT
409
		else
409
		else
410
			echo $LINE_JS >> $HTML_REPORT
410
			echo $LINE_JS >> $HTML_REPORT
411
		fi
411
		fi
412
	done
412
	done
413
	echo "</script>" >> $HTML_REPORT
413
	echo "</script>" >> $HTML_REPORT
414
else
414
else
415
	echo "<h2>Aucune activité de la Blacklist cette semaine.</h2>" >> $HTML_REPORT
415
	echo "<h2>Aucune activité de la Blacklist cette semaine.</h2>" >> $HTML_REPORT
416
fi
416
fi
417
 
417
 
418
######################VIRUS THREAT######################
418
######################VIRUS THREAT######################
419
echo "Create AV logs since the installation of ALCASAR"
419
echo "Create AV logs since the installation of ALCASAR"
420
 
420
 
421
#decompress every logs, if they exist
421
#decompress every logs, if they exist
422
if [ "$(ls -1 /var/log/clamav/clamd.log.*.gz 2>/dev/null | wc -l)" -ge 1 ]
422
if [ "$(ls -1 /var/log/clamav/clamd.log.*.gz 2>/dev/null | wc -l)" -ge 1 ]
423
then
423
then
424
	gunzip -d clamd.log.*.gz
424
	gunzip -d clamd.log.*.gz
425
fi
425
fi
426
 
426
 
427
for FILE in /var/log/clamav/clamd.log*
427
for FILE in /var/log/clamav/clamd.log*
428
do
428
do
429
	while read LINE_AV
429
	while read LINE_AV
430
	do
430
	do
431
		if [ "`echo $LINE_AV|grep -c FOUND`" == 1 ]
431
		if [ "`echo $LINE_AV|grep -c FOUND`" == 1 ]
432
		then
432
		then
433
			Y=$(echo $LINE_AV | cut -d' ' -f5)
433
			Y=$(echo $LINE_AV | cut -d' ' -f5)
434
			M=$(echo $LINE_AV | cut -d' ' -f2)
434
			M=$(echo $LINE_AV | cut -d' ' -f2)
435
			D=$(echo $LINE_AV | cut -d' ' -f3)
435
			D=$(echo $LINE_AV | cut -d' ' -f3)
436
			H=$(echo $LINE_AV | cut -d' ' -f4)
436
			H=$(echo $LINE_AV | cut -d' ' -f4)
437
			CURRENT_TS=$(date -d "$M $D $Y $H" +"%s")
437
			CURRENT_TS=$(date -d "$M $D $Y $H" +"%s")
438
			echo $CURRENT_TS >> $TMP_AV
438
			echo $CURRENT_TS >> $TMP_AV
439
		fi
439
		fi
440
	done < $FILE
440
	done < $FILE
441
done
441
done
442
 
442
 
443
if [ -e $TMP_AV ]
443
if [ -e $TMP_AV ]
444
then
444
then
445
	ENABLE_AV=1
445
	ENABLE_AV=1
446
	DATE_END=$(cat $TMP_AV | sort -n | head -1)
446
	DATE_END=$(cat $TMP_AV | sort -n | head -1)
447
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
447
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
448
	do
448
	do
449
		DATE_1=$TS
449
		DATE_1=$TS
450
		DATE_2=$((TS-$STEP_TS))
450
		DATE_2=$((TS-$STEP_TS))
451
		COUNT_AV=0
451
		COUNT_AV=0
452
 
452
 
453
		for TS_FILE in $(cat $TMP_AV)
453
		for TS_FILE in $(cat $TMP_AV)
454
		do
454
		do
455
			if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
455
			if [ "$TS_FILE" -le "$DATE_1" ] && [ "$TS_FILE" -ge "$DATE_2" ]
456
			then
456
			then
457
				COUNT_AV=$((COUNT_AV+1))
457
				COUNT_AV=$((COUNT_AV+1))
458
			fi
458
			fi
459
		done
459
		done
460
 
460
 
461
		VALUE_AV_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_AV_LABEL"
461
		VALUE_AV_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_AV_LABEL"
462
		VALUE_AV_DATA="$COUNT_AV, $VALUE_AV_DATA"
462
		VALUE_AV_DATA="$COUNT_AV, $VALUE_AV_DATA"
463
	done
463
	done
464
 
464
 
465
	#create Antivirus section in html document
465
	#create Antivirus section in html document
466
	NAME_AV='chart_av'
466
	NAME_AV='chart_av'
467
	CONF_AV='config_av'
467
	CONF_AV='config_av'
468
	echo "<center>" >> $HTML_REPORT
468
	echo "<center>" >> $HTML_REPORT
469
	echo "<canvas id='$NAME_AV' width='450' height='450' ></canvas>" >> $HTML_REPORT
469
	echo "<canvas id='$NAME_AV' width='450' height='450' ></canvas>" >> $HTML_REPORT
470
	echo "</center>" >> $HTML_REPORT
470
	echo "</center>" >> $HTML_REPORT
471
 
471
 
472
 
472
 
473
	#create chart bar in html file with javascript (chartjs.com)
473
	#create chart bar in html file with javascript (chartjs.com)
474
	echo "<script>" >> $HTML_REPORT
474
	echo "<script>" >> $HTML_REPORT
475
	cat $MODEL_CHARTJS | while read LINE_JS
475
	cat $MODEL_CHARTJS | while read LINE_JS
476
	do
476
	do
477
		#name of variable
477
		#name of variable
478
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
478
		if [ "$(echo $LINE_JS | grep 'XXCONFXX' | wc -l)" -eq 1 ]
479
		then
479
		then
480
			echo ${LINE_JS/XXCONFXX/$CONF_AV} >> $HTML_REPORT
480
			echo ${LINE_JS/XXCONFXX/$CONF_AV} >> $HTML_REPORT
481
		#chart type
481
		#chart type
482
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
482
		elif [ "$(echo $LINE_JS | grep 'XXTYPEXX' | wc -l)" -eq 1 ]
483
		then
483
		then
484
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
484
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
485
		#graph title
485
		#graph title
486
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
486
		elif [ "$(echo $LINE_JS | grep 'XXTITLEXX' | wc -l)" -eq 1 ]
487
		then
487
		then
488
			echo ${LINE_JS/XXTITLEXX/"Menaces bloqués par l\'antivirus"} >> $HTML_REPORT
488
			echo ${LINE_JS/XXTITLEXX/"Menaces bloqués par l\'antivirus"} >> $HTML_REPORT
489
		#chart data
489
		#chart data
490
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
490
		elif [ "$(echo $LINE_JS | grep 'XXDATAXX' | wc -l)" -eq 1 ]
491
		then
491
		then
492
			echo ${LINE_JS/XXDATAXX/$VALUE_AV_DATA} >> $HTML_REPORT
492
			echo ${LINE_JS/XXDATAXX/$VALUE_AV_DATA} >> $HTML_REPORT
493
		#color
493
		#color
494
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
494
		elif [ "$(echo $LINE_JS | grep 'XXCOLORXX' | wc -l)" -eq 1 ]
495
		then
495
		then
496
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
496
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
497
		#labels
497
		#labels
498
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
498
		elif [ "$(echo $LINE_JS | grep 'XXLABELSXX' | wc -l)" -eq 1 ]
499
		then
499
		then
500
			echo ${LINE_JS/XXLABELSXX/$VALUE_AV_LABEL} >> $HTML_REPORT
500
			echo ${LINE_JS/XXLABELSXX/$VALUE_AV_LABEL} >> $HTML_REPORT
501
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
501
		elif [ "$(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l)" -eq 1 ]
502
		then
502
		then
503
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
503
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
504
		#display value of Y axis, only useful for chart bar
504
		#display value of Y axis, only useful for chart bar
505
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
505
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l)" -eq 1 ]
506
		then
506
		then
507
			echo "" >> $HTML_REPORT
507
			echo "" >> $HTML_REPORT
508
		#display value of Y axis, only useful for chart bar
508
		#display value of Y axis, only useful for chart bar
509
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
509
		elif [ "$(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l)" -eq 1 ]
510
		then
510
		then
511
			echo "" >> $HTML_REPORT
511
			echo "" >> $HTML_REPORT
512
		elif [ "$(echo $LINE_JS | grep 'XXYLABELXX' | wc -l)" -eq 1 ]
512
		elif [ "$(echo $LINE_JS | grep 'XXYLABELXX' | wc -l)" -eq 1 ]
513
		then
513
		then
514
			echo "\"Nombre de menaces virales bloqués par l'antivirus\"" >> $HTML_REPORT
514
			echo "\"Nombre de menaces virales bloqués par l'antivirus\"" >> $HTML_REPORT
515
		else
515
		else
516
			echo $LINE_JS >> $HTML_REPORT
516
			echo $LINE_JS >> $HTML_REPORT
517
		fi
517
		fi
518
	done
518
	done
519
	echo "</script>" >> $HTML_REPORT
519
	echo "</script>" >> $HTML_REPORT
520
else
520
else
521
	echo "<h2>Aucune menace virale.</h2>" >> $HTML_REPORT
521
	echo "<h2>Aucune menace virale.</h2>" >> $HTML_REPORT
522
fi
522
fi
523
 
523
 
524
 
524
 
525
######################ALCASAR : DAILY USE######################
525
######################ALCASAR : DAILY USE######################
526
echo "Get daily use connection of the week"
526
echo "Get daily use connection of the week"
527
#create html document
527
#create html document
528
echo "<h2>Statistiques volumétrie connexions</h2>" >> $HTML_REPORT
528
echo "<h2>Statistiques volumétrie connexions</h2>" >> $HTML_REPORT
529
 
529
 
530
#create new htdigest user to consult statistique of ACC
530
#create new htdigest user to consult statistique of ACC
531
#if user does not exist, we create him
531
#if user does not exist, we create him
532
if [ "$(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l)" -lt 1 ]
532
if [ "$(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l)" -lt 1 ]
533
then
533
then
534
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
534
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
535
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
535
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
536
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
536
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
537
	chown -R root:apache $DIR_KEY
537
	chown -R root:apache $DIR_KEY
538
	chmod 640 $DIR_KEY/key_*
538
	chmod 640 $DIR_KEY/key_*
539
fi
539
fi
540
 
540
 
541
#get stats.php from ACC
541
#get stats.php from ACC
542
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
542
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
543
 
543
 
544
#clean this file to include it in html report.
544
#clean this file to include it in html report.
545
DELIM_1="<td colspan=10 height=20><img src=\"images\/pixel.gif\"><\/td>"
545
DELIM_1="<td colspan=10 height=20><img src=\"images\/pixel.gif\"><\/td>"
546
DELIM_2="<\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <p>"
546
DELIM_2="<\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <p>"
547
cat $TMP_STATS | sed -n "/$DELIM_1/,/$DELIM_2/p" | tail -n+3 | head -n-2 >> $TMP_STATS_2
547
cat $TMP_STATS | sed -n "/$DELIM_1/,/$DELIM_2/p" | tail -n+3 | head -n-2 >> $TMP_STATS_2
548
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
548
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
549
 
549
 
550
#we delete our user if he still exists
550
#we delete our user if he still exists
551
if [ "$(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l)" -ge 1 ]
551
if [ "$(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l)" -ge 1 ]
552
then
552
then
553
	$SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager
553
	$SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager
554
	$SED "/^$tmp_account:/d" $DIR_KEY/key_manager
554
	$SED "/^$tmp_account:/d" $DIR_KEY/key_manager
555
	$SED "/^$tmp_account:/d" $DIR_KEY/key_all
555
	$SED "/^$tmp_account:/d" $DIR_KEY/key_all
556
fi
556
fi
557
 
557
 
558
 
558
 
559
###################### ALCASAR : LOG ACCESS ######################
559
###################### ALCASAR : LOG ACCESS ######################
560
echo "Get ACC log access of the week"
560
echo "Get ACC log access of the week"
561
 
561
 
562
ROWS=""
562
ROWS=""
563
while read -r access ; do
563
while read -r access ; do
564
	access_datas=(${access//|/ })
564
	access_datas=(${access//|/ })
565
 
565
 
566
	accces_date_intl=$(echo "${access_datas[0]} ${access_datas[1]}" | sed -E 's@^([0-9]{2})+/+([0-9]{2})+/+([0-9]{4})+@\3-\2-\1@') # Convert date format DD/MM/YYYY to YYYY-MM-DD
566
	accces_date_intl=$(echo "${access_datas[0]} ${access_datas[1]}" | sed -E 's@^([0-9]{2})+/+([0-9]{2})+/+([0-9]{4})+@\3-\2-\1@') # Convert date format DD/MM/YYYY to YYYY-MM-DD
567
	access_date=$(date -d "$accces_date_intl" +%s)
567
	access_date=$(date -d "$accces_date_intl" +%s)
568
	access_user=${access_datas[2]}
568
	access_user=${access_datas[2]}
569
	access_ip=${access_datas[3]}
569
	access_ip=${access_datas[3]}
570
	access_agent=$(echo "$access" | cut -d'|' -f4)
570
	access_agent=$(echo "$access" | cut -d'|' -f4)
571
	if [ $access_date -lt $SECS_AGO ]; then
571
	if [ $access_date -lt $SECS_AGO ]; then
572
		break
572
		break
573
	fi
573
	fi
574
 
574
 
575
	access_date_formatted=$(date -d @$access_date +"%x %X")
575
	access_date_formatted=$(date -d @$access_date +"%x %X")
576
 
576
 
577
	ROWS="$ROWS<tr><td>$access_date_formatted</td><td>$access_user</td><td>$access_ip</td><td>$access_agent</td></tr>"
577
	ROWS="$ROWS<tr><td>$access_date_formatted</td><td>$access_user</td><td>$access_ip</td><td>$access_agent</td></tr>"
578
done < <(cat /var/Save/security/acc_access.log | sort -r)
578
done < <(cat /var/Save/security/acc_access.log | sort -r)
579
# TODO: Read archives if necessary
579
# TODO: Read archives if necessary
580
 
580
 
581
if [ -z "$ROWS" ]; then
581
if [ -z "$ROWS" ]; then
582
	ROWS="<tr><td colspan=\"4\" style=\"text-align: center;\">Aucune connexion</td></tr>"
582
	ROWS="<tr><td colspan=\"4\" style=\"text-align: center;\">Aucune connexion</td></tr>"
583
fi
583
fi
584
 
584
 
585
# Create HTML document
585
# Create HTML document
586
echo "<h2>Connexion à l'ALCASAR Control Center (ACC)</h2>" >> $HTML_REPORT
586
echo "<h2>Connexion à l'ALCASAR Control Center (ACC)</h2>" >> $HTML_REPORT
587
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
587
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
588
echo "<thead><tr><th>Date</th><th>Utilisateur</th><th>Adresse IP</th><th>Agent</th></tr></thead><tbody>" >> $HTML_REPORT
588
echo "<thead><tr><th>Date</th><th>Utilisateur</th><th>Adresse IP</th><th>Agent</th></tr></thead><tbody>" >> $HTML_REPORT
589
echo "$ROWS" >> $HTML_REPORT
589
echo "$ROWS" >> $HTML_REPORT
590
echo "</tbody></table>" >> $HTML_REPORT
590
echo "</tbody></table>" >> $HTML_REPORT
591
 
591
 
592
 
592
 
593
###################### ALCASAR : GLOBAL TRAFFIC ######################
593
###################### ALCASAR : GLOBAL TRAFFIC ######################
594
echo "Get Global traffic of the last 30 days"
594
echo "Get Global traffic of the last 30 days"
595
 
595
 
596
ROWS=""
596
ROWS=""
597
EXTIF=$(grep ^EXTIF= $CONF_FILE | cut -d'=' -f2)
597
EXTIF=$(grep ^EXTIF= $CONF_FILE | cut -d'=' -f2)
598
for day in $(vnstat --exportdb -i $EXTIF | grep '^d;' | sort -t";" -k3 -r); do
598
for day in $(vnstat --exportdb -i $EXTIF | grep '^d;' | sort -t";" -k3 -r); do
599
	day_datas=(${day//;/ })
599
	day_datas=(${day//;/ })
600
	day_date=${day_datas[2]}
600
	day_date=${day_datas[2]}
601
	day_rxMio=${day_datas[3]}
601
	day_rxMio=${day_datas[3]}
602
	day_txMio=${day_datas[4]}
602
	day_txMio=${day_datas[4]}
603
	day_rxKio=${day_datas[5]}
603
	day_rxKio=${day_datas[5]}
604
	day_txKio=${day_datas[6]}
604
	day_txKio=${day_datas[6]}
605
	day_act=${day_datas[7]}
605
	day_act=${day_datas[7]}
606
 
606
 
607
	if [ $day_act -ne 1 ]; then
607
	if [ $day_act -ne 1 ]; then
608
		continue
608
		continue
609
	fi
609
	fi
610
 
610
 
611
	if [ $day_date -lt $SECS_AGO ]; then
611
	if [ $day_date -lt $SECS_AGO ]; then
612
		break
612
		break
613
	fi
613
	fi
614
 
614
 
615
	day_date_formatted=$(date -d @$day_date +%x)
615
	day_date_formatted=$(date -d @$day_date +%x)
616
	day_rx=$(($day_rxMio * 1048576 + $day_rxKio * 1024))
616
	day_rx=$(($day_rxMio * 1048576 + $day_rxKio * 1024))
617
	day_tx=$(($day_txMio * 1048576 + $day_txKio * 1024))
617
	day_tx=$(($day_txMio * 1048576 + $day_txKio * 1024))
618
	day_total=$(($day_rx + $day_tx))
618
	day_total=$(($day_rx + $day_tx))
619
	day_rx_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_rx)
619
	day_rx_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_rx)
620
	day_tx_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_tx)
620
	day_tx_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_tx)
621
	day_total_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_total)
621
	day_total_formatted=$(numfmt --from=iec --to=iec --suffix=B $day_total)
622
 
622
 
623
	ROWS="$ROWS<tr><td>$day_date_formatted</td><td>$day_rx_formatted</td><td>$day_tx_formatted</td><td>$day_total_formatted</td></tr>"
623
	ROWS="$ROWS<tr><td>$day_date_formatted</td><td>$day_rx_formatted</td><td>$day_tx_formatted</td><td>$day_total_formatted</td></tr>"
624
done
624
done
625
 
625
 
626
if [ -z "$ROWS" ]; then
626
if [ -z "$ROWS" ]; then
627
	ROWS="<tr><td colspan=\"4\" style=\"text-align: center;\">Aucun jour capturé</td></tr>"
627
	ROWS="<tr><td colspan=\"4\" style=\"text-align: center;\">Aucun jour capturé</td></tr>"
628
fi
628
fi
629
 
629
 
630
# Create html document
630
# Create html document
631
echo "<h2>Trafic global</h2>" >> $HTML_REPORT
631
echo "<h2>Trafic global</h2>" >> $HTML_REPORT
632
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
632
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
633
echo "<thead><tr><th>Date</th><th>Entrant</th><th>Sortant</th><th>Total</th></tr></thead><tbody>" >> $HTML_REPORT
633
echo "<thead><tr><th>Date</th><th>Entrant</th><th>Sortant</th><th>Total</th></tr></thead><tbody>" >> $HTML_REPORT
634
echo "$ROWS" >> $HTML_REPORT
634
echo "$ROWS" >> $HTML_REPORT
635
echo "</tbody></table>" >> $HTML_REPORT
635
echo "</tbody></table>" >> $HTML_REPORT
636
 
636
 
637
 
637
 
638
###################### ALCASAR : FAIL2BAN ######################
638
###################### ALCASAR : FAIL2BAN ######################
639
echo "Get fail2ban log of the week"
639
echo "Get fail2ban log of the week"
640
 
640
 
641
ROWS=""
641
ROWS=""
642
dateDaysAgo_formatted=$(date --date="$MAX_DAY_AGO days ago" +'%Y-%m-%d %H:%M:%S,%N' | rev | cut -c 7- | rev)
642
dateDaysAgo_formatted=$(date --date="$MAX_DAY_AGO days ago" +'%Y-%m-%d %H:%M:%S,%N' | rev | cut -c 7- | rev)
643
while read -r log ; do
643
while read -r log ; do
644
	log_datas=($log)
644
	log_datas=($log)
645
	log_date="${log_datas[0]} ${log_datas[1]}"
645
	log_date="${log_datas[0]} ${log_datas[1]}"
646
	log_type=${log_datas[4]:1:-1}
646
	log_type=${log_datas[4]:1:-1}
647
	log_ip=${log_datas[6]}
647
	log_ip=${log_datas[6]}
648
	log_date_formatted=$(date -d "$log_date" +"%x %X")
648
	log_date_formatted=$(date -d "$log_date" +"%x %X")
649
 
649
 
650
	ROWS="$ROWS<tr><td>$log_date_formatted</td><td>$log_ip</td><td>$log_type</td></tr>"
650
	ROWS="$ROWS<tr><td>$log_date_formatted</td><td>$log_ip</td><td>$log_type</td></tr>"
651
done < <(grep " Ban " /var/log/fail2ban.log | sort -r | awk -v dateDaysAgo="$dateDaysAgo_formatted" '($1 " " $2) >= dateDaysAgo')
651
done < <(grep " Ban " /var/log/fail2ban.log | sort -r | awk -v dateDaysAgo="$dateDaysAgo_formatted" '($1 " " $2) >= dateDaysAgo')
652
 
652
 
653
if [ -z "$ROWS" ]; then
653
if [ -z "$ROWS" ]; then
654
	ROWS="<tr><td colspan=\"3\" style=\"text-align: center;\">Aucune adresse IP bloquée</td></tr>"
654
	ROWS="<tr><td colspan=\"3\" style=\"text-align: center;\">Aucune adresse IP bloquée</td></tr>"
655
fi
655
fi
656
 
656
 
657
# Create html document
657
# Create html document
658
echo "<h2>Adresse(s) IP bloquée(s) (Fail2Ban)</h2>" >> $HTML_REPORT
658
echo "<h2>Adresse(s) IP bloquée(s) (Fail2Ban)</h2>" >> $HTML_REPORT
659
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
659
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
660
echo "<thead><tr><th>Date</th><th>Adresse IP</th><th>Règle</th></tr></thead><tbody>" >> $HTML_REPORT
660
echo "<thead><tr><th>Date</th><th>Adresse IP</th><th>Règle</th></tr></thead><tbody>" >> $HTML_REPORT
661
echo $ROWS >> $HTML_REPORT
661
echo $ROWS >> $HTML_REPORT
662
echo "</tbody></table>" >> $HTML_REPORT
662
echo "</tbody></table>" >> $HTML_REPORT
663
 
663
 
664
 
664
 
665
######################FIN HTML######################
665
######################FIN HTML######################
666
 
666
 
667
#Execute our javascript function to print charts
667
#Execute our javascript function to print charts
668
echo "<script>window.onload = function() {" >> $HTML_REPORT
668
echo "<script>window.onload = function() {" >> $HTML_REPORT
669
#BL SINCE INSTALLATION
669
#BL SINCE INSTALLATION
670
if [ $ENABLE_BL -eq "1" ]
670
if [ $ENABLE_BL -eq "1" ]
671
then
671
then
672
	echo "var ctx_$NAME_BL_INSTALLATION = document.getElementById('$NAME_BL_INSTALLATION').getContext('2d');" >> $HTML_REPORT
672
	echo "var ctx_$NAME_BL_INSTALLATION = document.getElementById('$NAME_BL_INSTALLATION').getContext('2d');" >> $HTML_REPORT
673
	echo "var $NAME_BL_INSTALLATION = new Chart(ctx_$NAME_BL_INSTALLATION, $CONF_BL_INSTALLATION);" >> $HTML_REPORT
673
	echo "var $NAME_BL_INSTALLATION = new Chart(ctx_$NAME_BL_INSTALLATION, $CONF_BL_INSTALLATION);" >> $HTML_REPORT
674
fi
674
fi
675
#BL WEEK
675
#BL WEEK
676
if [ $ENABLE_BL_WEEK -eq "1" ]
676
if [ $ENABLE_BL_WEEK -eq "1" ]
677
then
677
then
678
	echo "var ctx_$NAME_BL = document.getElementById('$NAME_BL').getContext('2d');" >> $HTML_REPORT
678
	echo "var ctx_$NAME_BL = document.getElementById('$NAME_BL').getContext('2d');" >> $HTML_REPORT
679
	echo "var $NAME_BL = new Chart(ctx_$NAME_BL, $CONF_BL);" >> $HTML_REPORT
679
	echo "var $NAME_BL = new Chart(ctx_$NAME_BL, $CONF_BL);" >> $HTML_REPORT
680
fi
680
fi
681
#VIRUS THREAT
681
#VIRUS THREAT
682
if [ $ENABLE_AV -eq "1" ]
682
if [ $ENABLE_AV -eq "1" ]
683
then
683
then
684
	echo "var ctx_$NAME_AV = document.getElementById('$NAME_AV').getContext('2d');" >> $HTML_REPORT
684
	echo "var ctx_$NAME_AV = document.getElementById('$NAME_AV').getContext('2d');" >> $HTML_REPORT
685
	echo "var $NAME_AV = new Chart(ctx_$NAME_AV, $CONF_AV);" >> $HTML_REPORT
685
	echo "var $NAME_AV = new Chart(ctx_$NAME_AV, $CONF_AV);" >> $HTML_REPORT
686
fi
686
fi
687
echo "};</script>" >> $HTML_REPORT
687
echo "};</script>" >> $HTML_REPORT
688
echo "</body>" >> $HTML_REPORT
688
echo "</body>" >> $HTML_REPORT
689
echo "</html>" >> $HTML_REPORT
689
echo "</html>" >> $HTML_REPORT
690
 
690
 
691
#convert html document to PDF
691
#convert html document to PDF
692
/usr/bin/wkhtmltopdf $HTML_REPORT "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
692
/usr/bin/wkhtmltopdf $HTML_REPORT "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
693
chown apache:apache "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
693
chown apache:apache "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
694
chmod 644 "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
694
chmod 644 "$(echo $HTML_REPORT | cut -d'.' -f1).pdf"
695
mv "$(echo $HTML_REPORT | cut -d'.' -f1).pdf" /var/Save/activity_report/
695
mv "$(echo $HTML_REPORT | cut -d'.' -f1).pdf" /var/Save/activity_report/
696
 
696
 
697
#compress every logs, if they exist
697
#compress every logs, if they exist
698
if [ "$(ls -1 /var/log/clamav/clamd.log.* 2>/dev/null | wc -l)" -ge 1 ]
698
if [ "$(ls -1 /var/log/clamav/clamd.log.* 2>/dev/null | wc -l)" -ge 1 ]
699
then
699
then
700
	gzip /var/log/clamav/clamd.log.*
700
	gzip /var/log/clamav/clamd.log.*
701
fi
701
fi
702
 
702
 
703
#compress every logs
703
#compress every logs
704
if [ "$(ls -1 /var/log/unbound/unbound-blacklist.log.* 2>/dev/null | wc -l)" -ge 1 ]
704
if [ "$(ls -1 /var/log/unbound/unbound-blacklist.log.* 2>/dev/null | wc -l)" -ge 1 ]
705
then
705
then
706
	gzip /var/log/unbound/unbound-blacklist.log.*
706
	gzip /var/log/unbound/unbound-blacklist.log.*
707
fi
707
fi
708
 
708
 
709
#remove our files
709
#remove our files
710
rm -f $TMP_BL
710
rm -f $TMP_BL
711
rm -f $TMP_BL_WEEK
711
rm -f $TMP_BL_WEEK
712
rm -f $TMP_BL_WEEK_CAT
712
rm -f $TMP_BL_WEEK_CAT
713
rm -f $TMP_STATS
713
rm -f $TMP_STATS
714
rm -f $TMP_STATS_2
714
rm -f $TMP_STATS_2
715
rm -f $HTML_REPORT
715
rm -f $HTML_REPORT
716
 
716