Subversion Repositories ALCASAR

Rev

Rev 2317 | Rev 2474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2317 Rev 2454
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-activity_report.sh 2317 2017-06-30 11:42:44Z tom.houdayer $
2
# $Id: alcasar-activity_report.sh 2454 2017-12-09 18:59:31Z tom.houdayer $
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
 
Line 148... Line 148...
148
	VALUE=$(echo $(who -b | cut -d' ' -f12-))
148
	VALUE=$(echo $(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/dansguardian/lists/blacklists/README | grep 'Last version' | cut -d' ' -f4-6)
158
	VALUE=$(cat /etc/dansguardian/lists/blacklists/README | grep 'Last version' | cut -d' ' -f4-6)
Line 200... Line 200...
200
for FILE in $(ls -1 /var/log/dnsmasq/ | grep 'dnsmasq-blacklist.log')
200
for FILE in $(ls -1 /var/log/dnsmasq/ | grep 'dnsmasq-blacklist.log')
201
do
201
do
202
	while read LOG_BL
202
	while read LOG_BL
203
	do
203
	do
204
		if [ $(echo $LOG_BL | grep config | grep $PRIVATE_IP | wc -c) -ge 1 ]
204
		if [ $(echo $LOG_BL | grep config | grep $PRIVATE_IP | wc -c) -ge 1 ]
205
		then 
205
		then
206
			#find the current blacklisted category
206
			#find the current blacklisted category
207
			website_bl=$(echo $LOG_BL | cut -d' ' -f6)
207
			website_bl=$(echo $LOG_BL | cut -d' ' -f6)
208
			
208
			
209
			#we convert www.test.co.uk => test.co.uk to find the category of this website
209
			#we convert www.test.co.uk => test.co.uk to find the category of this website
210
			if [ $(grep -o '\.' <<< "$website_bl" | wc -l) -ge "2" ]
210
			if [ $(grep -o '\.' <<< "$website_bl" | wc -l) -ge "2" ]
Line 248... Line 248...
248
		for LINE in $(cat $TMP_BL)
248
		for LINE in $(cat $TMP_BL)
249
		do
249
		do
250
			TS_FILE=$(echo $LINE | cut -d':' -f1)
250
			TS_FILE=$(echo $LINE | cut -d':' -f1)
251
		
251
		
252
			if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
252
			if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
253
			then 
253
			then
254
				COUNT_BL_INSTALLATION=$((COUNT_BL_INSTALLATION+1))
254
				COUNT_BL_INSTALLATION=$((COUNT_BL_INSTALLATION+1))
255
 
255
 
256
			fi
256
			fi
257
		done
257
		done
258
	
258
	
Line 270... Line 270...
270
	#create chart bar in html file with javascript (chartjs.com)
270
	#create chart bar in html file with javascript (chartjs.com)
271
	echo "<script>" >> $HTML_REPORT
271
	echo "<script>" >> $HTML_REPORT
272
	cat $MODEL_CHARTJS | while read LINE_JS
272
	cat $MODEL_CHARTJS | while read LINE_JS
273
	do
273
	do
274
		#name of variable
274
		#name of variable
275
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
275
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ]
276
		then
276
		then
277
			echo ${LINE_JS/XXCONFXX/$CONF_BL_INSTALLATION} >> $HTML_REPORT
277
			echo ${LINE_JS/XXCONFXX/$CONF_BL_INSTALLATION} >> $HTML_REPORT
278
		#chart type
278
		#chart type
279
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ] 
279
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ]
280
		then
280
		then
281
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
281
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
282
		#chart title
282
		#chart title
283
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
283
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
284
		        then
284
		then
285
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués au total"} >> $HTML_REPORT
285
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués au total"} >> $HTML_REPORT
286
		#chart data
286
		#chart data
287
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
287
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ]
288
		then
288
		then
289
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_INSTALLATION_DATA} >> $HTML_REPORT
289
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_INSTALLATION_DATA} >> $HTML_REPORT
290
		#color
290
		#color
291
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ] 
291
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ]
292
		then
292
		then
293
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
293
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
294
		#labels
294
		#labels
295
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ] 
295
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ]
296
		then
296
		then
297
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_INSTALLATION_LABEL} >> $HTML_REPORT
297
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_INSTALLATION_LABEL} >> $HTML_REPORT
298
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
298
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ]
299
		then
299
		then
300
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
300
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
301
		#display value of Y axis, only useful for chart bar
301
		#display value of Y axis, only useful for chart bar
302
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ] 
302
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
303
		then
303
		then
304
			echo "" >> $HTML_REPORT
304
			echo "" >> $HTML_REPORT
305
		#display value of Y axis, only useful for chart bar
305
		#display value of Y axis, only useful for chart bar
306
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ] 
306
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ]
307
		then
307
		then
308
			echo "" >> $HTML_REPORT
308
			echo "" >> $HTML_REPORT
309
		elif [ $(echo $LINE_JS | grep 'XXYLABELXX' | wc -l) -eq 1 ] 
309
		elif [ $(echo $LINE_JS | grep 'XXYLABELXX' | wc -l) -eq 1 ]
310
		then
310
		then
311
			echo "\"Nombre de site bloqué par la blacklist\"" >> $HTML_REPORT
311
			echo "\"Nombre de site bloqué par la blacklist\"" >> $HTML_REPORT
312
		else
312
		else
313
			echo $LINE_JS >> $HTML_REPORT
313
			echo $LINE_JS >> $HTML_REPORT
314
		fi
314
		fi
Line 337... Line 337...
337
	for LINE in $(cat $TMP_BL)
337
	for LINE in $(cat $TMP_BL)
338
	do
338
	do
339
		TS_FILE=$(echo $LINE | cut -d':' -f1)
339
		TS_FILE=$(echo $LINE | cut -d':' -f1)
340
		#select only elements between DATE_1 and DATE_2
340
		#select only elements between DATE_1 and DATE_2
341
		if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
341
		if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
342
		then 
342
		then
343
			echo $LINE >> $TMP_BL_WEEK
343
			echo $LINE >> $TMP_BL_WEEK
344
		fi
344
		fi
345
	done
345
	done
346
 
346
 
347
	#then we count every occurence for each category in TMP_BL_WEEK
347
	#then we count every occurence for each category in TMP_BL_WEEK
Line 362... Line 362...
362
			VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
362
			VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
363
		fi
363
		fi
364
	done
364
	done
365
 
365
 
366
	#get other categories (sum them all)
366
	#get other categories (sum them all)
367
	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 ]
367
	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 ]
368
	then
368
	then
369
		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)"
369
		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)"
370
		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))'"
370
		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))'"
371
	fi
371
	fi
372
 
372
 
373
	#create chart pie in html file with javascript (chartjs.com)
373
	#create chart pie in html file with javascript (chartjs.com)
374
	NAME_BL='chart_bl'
374
	NAME_BL='chart_bl'
375
	CONF_BL='config_bl'
375
	CONF_BL='config_bl'
Line 379... Line 379...
379
	echo "<script>" >> $HTML_REPORT
379
	echo "<script>" >> $HTML_REPORT
380
 
380
 
381
	cat $MODEL_CHARTJS | while read LINE_JS
381
	cat $MODEL_CHARTJS | while read LINE_JS
382
	do
382
	do
383
		#variable name
383
		#variable name
384
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
384
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ]
385
		then
385
		then
386
			echo ${LINE_JS/XXCONFXX/$CONF_BL} >> $HTML_REPORT
386
			echo ${LINE_JS/XXCONFXX/$CONF_BL} >> $HTML_REPORT
387
		#chart type
387
		#chart type
388
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ] 
388
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ]
389
		then
389
		then
390
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
390
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
391
		#graph title
391
		#graph title
392
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
392
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
393
		then
393
		then
394
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
394
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
395
		#chart data
395
		#chart data
396
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
396
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ]
397
		then
397
		then
398
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
398
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
399
		#color
399
		#color
400
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ] 
400
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ]
401
		then
401
		then
402
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
402
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
403
		#labels
403
		#labels
404
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ] 
404
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ]
405
		then
405
		then
406
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_LABEL} >> $HTML_REPORT
406
			echo ${LINE_JS/XXLABELSXX/$VALUE_BL_LABEL} >> $HTML_REPORT
407
		#display legend, only useful for chart pie
407
		#display legend, only useful for chart pie
408
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
408
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ]
409
		then
409
		then
410
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
410
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
411
		#display value of Y axis, only useful for chart bar
411
		#display value of Y axis, only useful for chart bar
412
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
412
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
413
		then
413
		then