Subversion Repositories ALCASAR

Rev

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

Rev 2141 Rev 2189
Line -... Line 1...
-
 
1
#!/bin/bash
-
 
2
# $Id: alcasar-activity_report.sh 2189 2017-04-28 21:34:19Z tom.houdayer $
-
 
3
#
1
# 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).
2
# We read configuration files and logs to create cool charts.
5
# We read configuration files and logs to create cool charts.
3
# Written by Raphaël PION & Rexy
6
# Written by Raphaël PION & Rexy
4
 
7
 
5
# files
8
# files
Line 48... Line 51...
48
	rm $TMP_AV
51
	rm $TMP_AV
49
fi
52
fi
50
 
53
 
51
if [ -e $TMP_BL ]
54
if [ -e $TMP_BL ]
52
then
55
then
53
        rm $TMP_BL
56
	rm $TMP_BL
54
fi
57
fi
55
 
58
 
56
if [ -e $TMP_BL_WEEK ]
59
if [ -e $TMP_BL_WEEK ]
57
then
60
then
58
        rm $TMP_BL_WEEK
61
	rm $TMP_BL_WEEK
59
fi
62
fi
60
 
63
 
61
if [ -e $TMP_BL_WEEK_CAT ]
64
if [ -e $TMP_BL_WEEK_CAT ]
62
then
65
then
63
        rm $TMP_BL_WEEK_CAT
66
	rm $TMP_BL_WEEK_CAT
64
fi
67
fi
65
 
68
 
66
if [ -e $HTML_REPORT ]
69
if [ -e $HTML_REPORT ]
67
then
70
then
68
        rm $HTML_REPORT
71
	rm $HTML_REPORT
69
fi
72
fi
70
 
73
 
71
echo "<!doctype html>" >> $HTML_REPORT
74
echo "<!doctype html>" >> $HTML_REPORT
72
echo "<html>" >> $HTML_REPORT
75
echo "<html>" >> $HTML_REPORT
73
echo "<head>" >> $HTML_REPORT
76
echo "<head>" >> $HTML_REPORT
74
echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>" >> $HTML_REPORT
77
echo "<meta charset=\"utf-8\">" >> $HTML_REPORT
75
echo "<title>ALCASAR report</title>" >> $HTML_REPORT
78
echo "<title>ALCASAR report</title>" >> $HTML_REPORT
76
echo "<link rel='stylesheet' type='text/css' href='../../../css/bootstrap.min.css'>" >> $HTML_REPORT
79
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/bootstrap.min.css\">" >> $HTML_REPORT
77
echo "<link rel='stylesheet' type='text/css' href='../../../css/report.css'>" >> $HTML_REPORT
80
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
78
echo "<script src='../../../js/Chart.bundle.js'></script>" >> $HTML_REPORT
81
echo "<script src=\"../../../js/Chart.bundle.js\"></script>" >> $HTML_REPORT
79
echo "<script src='../../../js/jquery.min.js'></script>" >> $HTML_REPORT
82
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
80
echo "</head>" >> $HTML_REPORT
83
echo "</head>" >> $HTML_REPORT
81
echo "<body>" >> $HTML_REPORT
84
echo "<body>" >> $HTML_REPORT
82
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)</center></h1>" >> $HTML_REPORT
85
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)</center></h1>" >> $HTML_REPORT
83
echo "<i><p style='text-align: right;'>Date de création $(date +%F)</p></i>" >> $HTML_REPORT
86
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
84
echo "<font size='1'>" >> $HTML_REPORT
87
echo "<font size=\"1\">" >> $HTML_REPORT
85
 
88
 
86
######################TABINFO######################
89
######################TABINFO######################
87
echo "Create information about system and ALCASAR"
90
echo "Create information about system and ALCASAR"
88
#contain every information about ALCASAR configuration, system and last update
91
#contain every information about ALCASAR configuration, system and last update
89
 
92
 
Line 91... Line 94...
91
do
94
do
92
 
95
 
93
if [ $(echo $LINE_HTML | grep 'XXORGXX' | wc -l) -eq 1 ]
96
if [ $(echo $LINE_HTML | grep 'XXORGXX' | wc -l) -eq 1 ]
94
then
97
then
95
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)
98
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)
96
        echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
99
	echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
97
        
100
	
98
elif [ $(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l) -eq 1 ]
101
elif [ $(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l) -eq 1 ]
99
then
102
then
100
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep INSTALL_DATE | cut -d'=' -f2)
103
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep INSTALL_DATE | cut -d'=' -f2)
101
	echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
104
	echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
102
	
105
	
Line 174... Line 177...
174
			echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
177
			echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
175
			echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
178
			echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
176
			echo "</tr>" >> $HTML_REPORT
179
			echo "</tr>" >> $HTML_REPORT
177
		done
180
		done
178
	else
181
	else
179
		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
180
	fi
183
	fi
181
else
184
else
182
	echo $LINE_HTML >> $HTML_REPORT
185
	echo $LINE_HTML >> $HTML_REPORT
183
fi
186
fi
184
done
187
done
Line 202... Line 205...
202
		then 
205
		then 
203
			#find the current blacklisted category
206
			#find the current blacklisted category
204
			website_bl=$(echo $LOG_BL | cut -d' ' -f6)
207
			website_bl=$(echo $LOG_BL | cut -d' ' -f6)
205
			
208
			
206
			#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
207
                        if [ $(grep -o '\.' <<< "$website_bl" | wc -l) -ge "2" ]
210
			if [ $(grep -o '\.' <<< "$website_bl" | wc -l) -ge "2" ]
208
                        then
211
			then
209
                                	website_bl=$(echo $website_bl | cut -d'.' -f2-)
212
					website_bl=$(echo $website_bl | cut -d'.' -f2-)
210
                        fi
213
			fi
211
 
214
 
212
			#get BL category
215
			#get BL category
213
			categorie_bl=$(grep -R "$website_bl/" /usr/local/share/dnsmasq-bl-enabled/ | cut -d':' -f1 | cut -d'/' -f6 | cut -d' ' -f1) 
216
			categorie_bl=$(grep -R "$website_bl/" /usr/local/share/dnsmasq-bl-enabled/ | cut -d':' -f1 | cut -d'/' -f6 | cut -d' ' -f1)
214
			if [ $(echo $categorie_bl | wc -w) -gt 1 ]
217
			if [ $(echo $categorie_bl | wc -w) -gt 1 ]
215
			then
218
			then
216
				categorie_bl=$(grep -R "/$website_bl/" /usr/local/share/dnsmasq-bl-enabled/ | cut -d':' -f1 | cut -d'/' -f6 | cut -d' ' -f1 | head -1)
219
				categorie_bl=$(grep -R "/$website_bl/" /usr/local/share/dnsmasq-bl-enabled/ | cut -d':' -f1 | cut -d'/' -f6 | cut -d' ' -f1 | head -1)
217
			fi
220
			fi
218
			
221
			
219
			#Calculate its timestamp
222
			#Calculate its timestamp
220
			Y=$(date -R | cut -d' ' -f4)
223
			Y=$(date -R | cut -d' ' -f4)
221
			M=$(echo $LOG_BL | cut -d' ' -f1)
224
			M=$(echo $LOG_BL | cut -d' ' -f1)
222
			D=$(echo $LOG_BL | cut -d' ' -f2) 
225
			D=$(echo $LOG_BL | cut -d' ' -f2)
223
			H=$(echo $LOG_BL | cut -d' ' -f3)
226
			H=$(echo $LOG_BL | cut -d' ' -f3)
224
			CURRENT_TS=$(date -d "$M $D $Y $H" +"%s")
227
			CURRENT_TS=$(date -d "$M $D $Y $H" +"%s")
225
			echo "$CURRENT_TS:$categorie_bl:" >> $TMP_BL
228
			echo "$CURRENT_TS:$categorie_bl:" >> $TMP_BL
226
		fi
229
		fi
227
		
230
		
Line 340... Line 343...
340
	done
343
	done
341
 
344
 
342
	#then we count every occurence for each category in TMP_BL_WEEK
345
	#then we count every occurence for each category in TMP_BL_WEEK
343
	for CAT in $(ls /usr/local/share/dnsmasq-bl/ -1 | cut -d'.' -f1)
346
	for CAT in $(ls /usr/local/share/dnsmasq-bl/ -1 | cut -d'.' -f1)
344
	do
347
	do
345
		echo "$CAT:$(grep -o ":$CAT:" <<< "$(cat $TMP_BL_WEEK)" | wc -l):" >> $TMP_BL_WEEK_CAT  
348
		echo "$CAT:$(grep -o ":$CAT:" <<< "$(cat $TMP_BL_WEEK)" | wc -l):" >> $TMP_BL_WEEK_CAT
346
	done
349
	done
347
 
350
 
348
	#we sort by number of occurence and we take the top 10 BL categories
351
	#we sort by number of occurence and we take the top 10 BL categories
349
	for LINE in $(sort -t':' -k2 -rn $TMP_BL_WEEK_CAT | head -n 10)
352
	for LINE in $(sort -t':' -k2 -rn $TMP_BL_WEEK_CAT | head -n 10)
350
	do
353
	do
351
		
354
		
352
		DATA=$(echo $LINE | cut -d':' -f2)
355
		DATA=$(echo $LINE | cut -d':' -f2)
353
		LABEL=$(echo $LINE | cut -d':' -f1)
356
		LABEL=$(echo $LINE | cut -d':' -f1)
354
		if [ $DATA -ne 0 ]
357
		if [ $DATA -ne 0 ]
355
		then
358
		then
356
		        VALUE_BL_DATA="$VALUE_BL_DATA $DATA, "
359
			VALUE_BL_DATA="$VALUE_BL_DATA $DATA, "
357
		        VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
360
			VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
358
		  
-
 
359
		fi
361
		fi
360
	done
362
	done
361
 
363
 
362
	#get other categories (sum them all)
364
	#get other categories (sum them all)
363
        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 ]
365
	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 ]
364
        then
366
	then
365
                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)"
367
		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)"
366
                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))'"
368
		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))'"
367
        fi
369
	fi
368
 
370
 
369
	#create chart pie in html file with javascript (chartjs.com)
371
	#create chart pie in html file with javascript (chartjs.com)
370
	NAME_BL='chart_bl'
372
	NAME_BL='chart_bl'
371
	CONF_BL='config_bl'
373
	CONF_BL='config_bl'
372
	echo "<center>" >> $HTML_REPORT
374
	echo "<center>" >> $HTML_REPORT
373
	echo "<canvas id='$NAME_BL' width='450' height='450' ></canvas>" >> $HTML_REPORT
375
	echo "<canvas id='$NAME_BL' width='450' height='450' ></canvas>" >> $HTML_REPORT
374
	echo "</center>" >> $HTML_REPORT
376
	echo "</center>" >> $HTML_REPORT
375
	echo "<script>" >> $HTML_REPORT
377
	echo "<script>" >> $HTML_REPORT
376
	
378
 
377
	cat $MODEL_CHARTJS | while read LINE_JS
379
	cat $MODEL_CHARTJS | while read LINE_JS
378
	do
380
	do
379
		#variable name
381
		#variable name
380
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
382
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
381
		then
383
		then
Line 385... Line 387...
385
		then
387
		then
386
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
388
			echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
387
		#graph title
389
		#graph title
388
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
390
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
389
		then
391
		then
390
		        echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
392
			echo ${LINE_JS/XXTITLEXX/"Sites bloqués cette semaine"} >> $HTML_REPORT
391
		#chart data
393
		#chart data
392
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
394
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
393
		then
395
		then
394
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
396
			echo ${LINE_JS/XXDATAXX/$VALUE_BL_DATA} >> $HTML_REPORT
395
		#color
397
		#color
Line 403... Line 405...
403
		#display legend, only useful for chart pie
405
		#display legend, only useful for chart pie
404
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
406
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
405
		then
407
		then
406
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
408
			echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
407
		#display value of Y axis, only useful for chart bar
409
		#display value of Y axis, only useful for chart bar
408
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ] 
410
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
409
		then
411
		then
410
			echo "/*" >> $HTML_REPORT
412
			echo "/*" >> $HTML_REPORT
411
		#display value of Y axis, only useful for chart bar
413
		#display value of Y axis, only useful for chart bar
412
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ] 
414
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ]
413
		then
415
		then
414
			echo "*/" >> $HTML_REPORT
416
			echo "*/" >> $HTML_REPORT
415
		else
417
		else
416
			echo $LINE_JS >> $HTML_REPORT
418
			echo $LINE_JS >> $HTML_REPORT
417
		fi
419
		fi
Line 450... Line 452...
450
	DATE_END=$(cat $TMP_AV | sort -n | head -1)
452
	DATE_END=$(cat $TMP_AV | sort -n | head -1)
451
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
453
	for TS in $(seq $C_TS -$STEP_TS $DATE_END)
452
	do
454
	do
453
		DATE_1=$TS
455
		DATE_1=$TS
454
		DATE_2=$((TS-$STEP_TS))
456
		DATE_2=$((TS-$STEP_TS))
455
		COUNT_AV=0	
457
		COUNT_AV=0
456
	
-
 
457
 
458
 
458
		for TS_FILE in $(cat $TMP_AV)
459
		for TS_FILE in $(cat $TMP_AV)
459
		do
460
		do
460
			if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
461
			if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
461
			then 
462
			then
462
				COUNT_AV=$((COUNT_AV+1))
463
				COUNT_AV=$((COUNT_AV+1))
463
 
-
 
464
			fi
464
			fi
465
		done
465
		done
466
	
466
 
467
		VALUE_AV_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_AV_LABEL"
467
		VALUE_AV_LABEL="'$(date -d @$DATE_2 "+%Y-%m-%d" )', $VALUE_AV_LABEL"
468
		VALUE_AV_DATA="$COUNT_AV, $VALUE_AV_DATA"
468
		VALUE_AV_DATA="$COUNT_AV, $VALUE_AV_DATA"
469
	done
469
	done
470
	
470
	
471
	#create Antivirus section in html document
471
	#create Antivirus section in html document
Line 479... Line 479...
479
	#create chart bar in html file with javascript (chartjs.com)
479
	#create chart bar in html file with javascript (chartjs.com)
480
	echo "<script>" >> $HTML_REPORT
480
	echo "<script>" >> $HTML_REPORT
481
	cat $MODEL_CHARTJS | while read LINE_JS
481
	cat $MODEL_CHARTJS | while read LINE_JS
482
	do
482
	do
483
		#name of variable
483
		#name of variable
484
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
484
		if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ]
485
		then
485
		then
486
			echo ${LINE_JS/XXCONFXX/$CONF_AV} >> $HTML_REPORT
486
			echo ${LINE_JS/XXCONFXX/$CONF_AV} >> $HTML_REPORT
487
		#chart type
487
		#chart type
488
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ] 
488
		elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ]
489
		then
489
		then
490
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
490
			echo ${LINE_JS/XXTYPEXX/bar} >> $HTML_REPORT
491
		#graph title
491
		#graph title
492
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
492
		elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
493
		then
493
		then
494
		        echo ${LINE_JS/XXTITLEXX/"Menaces bloqués par l\'antivirus"} >> $HTML_REPORT
494
			echo ${LINE_JS/XXTITLEXX/"Menaces bloqués par l\'antivirus"} >> $HTML_REPORT
495
		#chart data
495
		#chart data
496
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
496
		elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ]
497
		then
497
		then
498
			echo ${LINE_JS/XXDATAXX/$VALUE_AV_DATA} >> $HTML_REPORT
498
			echo ${LINE_JS/XXDATAXX/$VALUE_AV_DATA} >> $HTML_REPORT
499
		#color
499
		#color
500
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ] 
500
		elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ]
501
		then
501
		then
502
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
502
			echo ${LINE_JS/XXCOLORXX/$COLOR} >> $HTML_REPORT
503
		#labels
503
		#labels
504
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ] 
504
		elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ]
505
		then
505
		then
506
			echo ${LINE_JS/XXLABELSXX/$VALUE_AV_LABEL} >> $HTML_REPORT
506
			echo ${LINE_JS/XXLABELSXX/$VALUE_AV_LABEL} >> $HTML_REPORT
507
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
507
		elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ]
508
		then
508
		then
509
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
509
			echo ${LINE_JS/XXLEGENDXX/false} >> $HTML_REPORT
510
		#display value of Y axis, only useful for chart bar
510
		#display value of Y axis, only useful for chart bar
511
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ] 
511
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
512
		then
512
		then
513
			echo "" >> $HTML_REPORT
513
			echo "" >> $HTML_REPORT
514
		#display value of Y axis, only useful for chart bar
514
		#display value of Y axis, only useful for chart bar
515
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ] 
515
		elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ]
516
		then
516
		then
517
			echo "" >> $HTML_REPORT
517
			echo "" >> $HTML_REPORT
518
		elif [ $(echo $LINE_JS | grep 'XXYLABELXX' | wc -l) -eq 1 ] 
518
		elif [ $(echo $LINE_JS | grep 'XXYLABELXX' | wc -l) -eq 1 ]
519
		then
519
		then
520
			echo "\"Nombre de menaces virales bloqués par l'antivirus\"" >> $HTML_REPORT
520
			echo "\"Nombre de menaces virales bloqués par l'antivirus\"" >> $HTML_REPORT
521
		else
521
		else
522
			echo $LINE_JS >> $HTML_REPORT
522
			echo $LINE_JS >> $HTML_REPORT
523
		fi
523
		fi
Line 525... Line 525...
525
	echo "</script>" >> $HTML_REPORT
525
	echo "</script>" >> $HTML_REPORT
526
else
526
else
527
	echo "<h3>Aucune menace virale.</h3>" >> $HTML_REPORT
527
	echo "<h3>Aucune menace virale.</h3>" >> $HTML_REPORT
528
fi
528
fi
529
 
529
 
530
######################AUTHORIZED CONNECTIONS######################
-
 
531
 
-
 
532
echo "Create authorized connections since the installation of ALCASAR"
-
 
533
#get number of authorized, forbidden and fail2ban connections :
-
 
534
PASSWD_FILE="/root/ALCASAR-passwords.txt"
-
 
535
QUERY="SELECT COUNT(acctterminatecause) FROM radacct WHERE acctterminatecause=\"User-Request\" ORDER BY acctstarttime"
-
 
536
AUTHORIZED=$(mysql -D radius -u root -p$(cat $PASSWD_FILE | grep "root /" | rev | cut -d' '  -f1 | rev) -e "$QUERY" | cut -d')' -f2)
-
 
537
QUERY="SELECT COUNT(acctterminatecause) FROM radacct WHERE acctterminatecause=\"Admin-Reset\" ORDER BY acctstarttime"
-
 
538
FORBIDDEN=$(mysql -D radius -u root -p$(cat $PASSWD_FILE | grep "root /" | rev | cut -d' '  -f1 | rev) -e "$QUERY" | cut -d')' -f2)
-
 
539
FAIL2BAN=$(strings /var/log/fail2ban.log | grep " Ban " | wc -l)
-
 
540
 
-
 
541
VALUE_AUTH="$AUTHORIZED, $FORBIDDEN, $FAIL2BAN"
-
 
542
LABEL_AUTH="'Autorisées ($AUTHORIZED) ', 'Interdites ($FORBIDDEN)', 'fail2ban($FAIL2BAN)'"
-
 
543
 
-
 
544
#create chart pie in html file with javascript (chartjs.com)
-
 
545
NAME_AUTH='chart_auth'
-
 
546
CONF_AUTH='config_auth'
-
 
547
echo "<center>" >> $HTML_REPORT
-
 
548
echo "<canvas id='$NAME_AUTH' width='450' height='450' ></canvas>" >> $HTML_REPORT
-
 
549
echo "</center>" >> $HTML_REPORT
-
 
550
echo "<script>" >> $HTML_REPORT
-
 
551
	
-
 
552
cat $MODEL_CHARTJS | while read LINE_JS
-
 
553
do
-
 
554
	#variable name
-
 
555
	if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ] 
-
 
556
	then
-
 
557
		echo ${LINE_JS/XXCONFXX/$CONF_AUTH} >> $HTML_REPORT
-
 
558
	#chart type
-
 
559
	elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ] 
-
 
560
	then
-
 
561
		echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
-
 
562
	#graph title
-
 
563
	elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
-
 
564
	then
-
 
565
	        echo ${LINE_JS/XXTITLEXX/"Connexions des utilisateurs"} >> $HTML_REPORT
-
 
566
	#chart data
-
 
567
	elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ] 
-
 
568
	then
-
 
569
		echo ${LINE_JS/XXDATAXX/$VALUE_AUTH} >> $HTML_REPORT
-
 
570
	#color
-
 
571
	elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ] 
-
 
572
	then
-
 
573
		echo ${LINE_JS/XXCOLORXX/"'#000099','#ff6600','#ff0000'"} >> $HTML_REPORT
-
 
574
	#labels
-
 
575
	elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ] 
-
 
576
	then
-
 
577
		echo ${LINE_JS/XXLABELSXX/$LABEL_AUTH} >> $HTML_REPORT
-
 
578
	#display legend, only useful for chart pie
-
 
579
	elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ] 
-
 
580
	then
-
 
581
		echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
-
 
582
	#display value of Y axis, only useful for chart bar
-
 
583
	elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ] 
-
 
584
	then
-
 
585
		echo "/*" >> $HTML_REPORT
-
 
586
	#display value of Y axis, only useful for chart bar
-
 
587
	elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ] 
-
 
588
	then
-
 
589
		echo "*/" >> $HTML_REPORT
-
 
590
	else
-
 
591
		echo $LINE_JS >> $HTML_REPORT
-
 
592
	fi
-
 
593
done
-
 
594
echo "</script>" >> $HTML_REPORT
-
 
595
 
-
 
596
 
530
 
597
######################ALCASAR : DAILY USE######################
531
######################ALCASAR : DAILY USE######################
598
echo "Get daily use connection of the week"
532
echo "Get daily use connection of the week"
599
#create html document
533
#create html document
600
echo "<h3>Statistiques volumétrie connexions</h3>" >> $HTML_REPORT
534
echo "<h3>Statistiques volumétrie connexions</h3>" >> $HTML_REPORT
601
 
535
 
602
#create new htdigest user to consult statistique of ACC
536
#create new htdigest user to consult statistique of ACC
603
#if user does not exist, we create him
537
#if user does not exist, we create him
604
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
538
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
605
then
539
then
606
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
540
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
607
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
541
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
608
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
542
	(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
609
        chown -R root:apache $DIR_KEY
543
	chown -R root:apache $DIR_KEY
610
        chmod 640 $DIR_KEY/key_*
544
	chmod 640 $DIR_KEY/key_*
611
fi
545
fi
612
 
546
 
613
#get stats.php from ACC
547
#get stats.php from ACC
614
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
548
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
615
 
549
 
Line 620... Line 554...
620
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
554
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
621
 
555
 
622
#we delete our user if he still exists
556
#we delete our user if he still exists
623
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
557
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
624
then
558
then
625
        $SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager
559
	$SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager
626
        $SED "/^$tmp_account:/d" $DIR_KEY/key_manager
560
	$SED "/^$tmp_account:/d" $DIR_KEY/key_manager
627
       	$SED "/^$tmp_account:/d" $DIR_KEY/key_all
561
	$SED "/^$tmp_account:/d" $DIR_KEY/key_all
628
fi
562
fi
629
 
563
 
630
######################FIN HTML######################
564
######################FIN HTML######################
631
 
565
 
632
#Execute our javascript function to print charts
566
#Execute our javascript function to print charts
Line 647... Line 581...
647
if [ $ENABLE_AV -eq "1" ]
581
if [ $ENABLE_AV -eq "1" ]
648
then
582
then
649
	echo "var ctx_$NAME_AV = document.getElementById('$NAME_AV').getContext('2d');" >> $HTML_REPORT
583
	echo "var ctx_$NAME_AV = document.getElementById('$NAME_AV').getContext('2d');" >> $HTML_REPORT
650
	echo "var $NAME_AV = new Chart(ctx_$NAME_AV, $CONF_AV);" >> $HTML_REPORT
584
	echo "var $NAME_AV = new Chart(ctx_$NAME_AV, $CONF_AV);" >> $HTML_REPORT
651
fi
585
fi
652
#CONNEXIONS AUTHORIZED
-
 
653
echo "var ctx_$NAME_AUTH = document.getElementById('$NAME_AUTH').getContext('2d');" >> $HTML_REPORT
-
 
654
echo "var $NAME_AUTH = new Chart(ctx_$NAME_AUTH, $CONF_AUTH);" >> $HTML_REPORT
-
 
655
echo "};</script>" >> $HTML_REPORT
586
echo "};</script>" >> $HTML_REPORT
656
echo "</body>" >> $HTML_REPORT
587
echo "</body>" >> $HTML_REPORT
657
echo "</html>" >> $HTML_REPORT
588
echo "</html>" >> $HTML_REPORT
658
 
589
 
659
#convert html document to PDF
590
#convert html document to PDF