Subversion Repositories ALCASAR

Compare Revisions

No changes between revisions

Regard whitespace Rev 2188 → Rev 2189

/scripts/alcasar-activity_report.sh
1,3 → 1,6
#!/bin/bash
# $Id$
#
# Create an activity report for ALCASAR every week (sunday at 5.35 pm --> see cron.d).
# We read configuration files and logs to create cool charts.
# Written by Raphaël PION & Rexy
71,17 → 74,17
echo "<!doctype html>" >> $HTML_REPORT
echo "<html>" >> $HTML_REPORT
echo "<head>" >> $HTML_REPORT
echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>" >> $HTML_REPORT
echo "<meta charset=\"utf-8\">" >> $HTML_REPORT
echo "<title>ALCASAR report</title>" >> $HTML_REPORT
echo "<link rel='stylesheet' type='text/css' href='../../../css/bootstrap.min.css'>" >> $HTML_REPORT
echo "<link rel='stylesheet' type='text/css' href='../../../css/report.css'>" >> $HTML_REPORT
echo "<script src='../../../js/Chart.bundle.js'></script>" >> $HTML_REPORT
echo "<script src='../../../js/jquery.min.js'></script>" >> $HTML_REPORT
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/bootstrap.min.css\">" >> $HTML_REPORT
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
echo "<script src=\"../../../js/Chart.bundle.js\"></script>" >> $HTML_REPORT
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
echo "</head>" >> $HTML_REPORT
echo "<body>" >> $HTML_REPORT
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)</center></h1>" >> $HTML_REPORT
echo "<i><p style='text-align: right;'>Date de création $(date +%F)</p></i>" >> $HTML_REPORT
echo "<font size='1'>" >> $HTML_REPORT
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
echo "<font size=\"1\">" >> $HTML_REPORT
 
######################TABINFO######################
echo "Create information about system and ALCASAR"
176,7 → 179,7
echo "</tr>" >> $HTML_REPORT
done
else
echo "<tr><td colspan=3>Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT
echo "<tr><td colspan=\"3\">Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT
fi
else
echo $LINE_HTML >> $HTML_REPORT
355,7 → 358,6
then
VALUE_BL_DATA="$VALUE_BL_DATA $DATA, "
VALUE_BL_LABEL="$VALUE_BL_LABEL '$LABEL ($DATA)',"
fi
done
 
454,13 → 456,11
DATE_2=$((TS-$STEP_TS))
COUNT_AV=0
 
for TS_FILE in $(cat $TMP_AV)
do
if [ "$TS_FILE" -le "$DATE_1" -a "$TS_FILE" -ge "$DATE_2" ]
then
COUNT_AV=$((COUNT_AV+1))
 
fi
done
527,73 → 527,7
echo "<h3>Aucune menace virale.</h3>" >> $HTML_REPORT
fi
 
######################AUTHORIZED CONNECTIONS######################
 
echo "Create authorized connections since the installation of ALCASAR"
#get number of authorized, forbidden and fail2ban connections :
PASSWD_FILE="/root/ALCASAR-passwords.txt"
QUERY="SELECT COUNT(acctterminatecause) FROM radacct WHERE acctterminatecause=\"User-Request\" ORDER BY acctstarttime"
AUTHORIZED=$(mysql -D radius -u root -p$(cat $PASSWD_FILE | grep "root /" | rev | cut -d' ' -f1 | rev) -e "$QUERY" | cut -d')' -f2)
QUERY="SELECT COUNT(acctterminatecause) FROM radacct WHERE acctterminatecause=\"Admin-Reset\" ORDER BY acctstarttime"
FORBIDDEN=$(mysql -D radius -u root -p$(cat $PASSWD_FILE | grep "root /" | rev | cut -d' ' -f1 | rev) -e "$QUERY" | cut -d')' -f2)
FAIL2BAN=$(strings /var/log/fail2ban.log | grep " Ban " | wc -l)
 
VALUE_AUTH="$AUTHORIZED, $FORBIDDEN, $FAIL2BAN"
LABEL_AUTH="'Autorisées ($AUTHORIZED) ', 'Interdites ($FORBIDDEN)', 'fail2ban($FAIL2BAN)'"
 
#create chart pie in html file with javascript (chartjs.com)
NAME_AUTH='chart_auth'
CONF_AUTH='config_auth'
echo "<center>" >> $HTML_REPORT
echo "<canvas id='$NAME_AUTH' width='450' height='450' ></canvas>" >> $HTML_REPORT
echo "</center>" >> $HTML_REPORT
echo "<script>" >> $HTML_REPORT
cat $MODEL_CHARTJS | while read LINE_JS
do
#variable name
if [ $(echo $LINE_JS | grep 'XXCONFXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXCONFXX/$CONF_AUTH} >> $HTML_REPORT
#chart type
elif [ $(echo $LINE_JS | grep 'XXTYPEXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXTYPEXX/pie} >> $HTML_REPORT
#graph title
elif [ $(echo $LINE_JS | grep 'XXTITLEXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXTITLEXX/"Connexions des utilisateurs"} >> $HTML_REPORT
#chart data
elif [ $(echo $LINE_JS | grep 'XXDATAXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXDATAXX/$VALUE_AUTH} >> $HTML_REPORT
#color
elif [ $(echo $LINE_JS | grep 'XXCOLORXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXCOLORXX/"'#000099','#ff6600','#ff0000'"} >> $HTML_REPORT
#labels
elif [ $(echo $LINE_JS | grep 'XXLABELSXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXLABELSXX/$LABEL_AUTH} >> $HTML_REPORT
#display legend, only useful for chart pie
elif [ $(echo $LINE_JS | grep 'XXLEGENDXX' | wc -l) -eq 1 ]
then
echo ${LINE_JS/XXLEGENDXX/true} >> $HTML_REPORT
#display value of Y axis, only useful for chart bar
elif [ $(echo $LINE_JS | grep 'XXCOMMENT-BEGINXX' | wc -l) -eq 1 ]
then
echo "/*" >> $HTML_REPORT
#display value of Y axis, only useful for chart bar
elif [ $(echo $LINE_JS | grep 'XXCOMMENT-ENDXX' | wc -l) -eq 1 ]
then
echo "*/" >> $HTML_REPORT
else
echo $LINE_JS >> $HTML_REPORT
fi
done
echo "</script>" >> $HTML_REPORT
 
 
######################ALCASAR : DAILY USE######################
echo "Get daily use connection of the week"
#create html document
649,9 → 583,6
echo "var ctx_$NAME_AV = document.getElementById('$NAME_AV').getContext('2d');" >> $HTML_REPORT
echo "var $NAME_AV = new Chart(ctx_$NAME_AV, $CONF_AV);" >> $HTML_REPORT
fi
#CONNEXIONS AUTHORIZED
echo "var ctx_$NAME_AUTH = document.getElementById('$NAME_AUTH').getContext('2d');" >> $HTML_REPORT
echo "var $NAME_AUTH = new Chart(ctx_$NAME_AUTH, $CONF_AUTH);" >> $HTML_REPORT
echo "};</script>" >> $HTML_REPORT
echo "</body>" >> $HTML_REPORT
echo "</html>" >> $HTML_REPORT
Property changes:
Added: svn:keywords
+Id
\ No newline at end of property