Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
# $Id: alcasar-activity_report.sh 2262 2017-05-29 20:19:03Z tom.houdayer $
|
2 |
# $Id: alcasar-activity_report.sh 2267 2017-06-04 09:28:36Z richard $
|
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 565... |
Line 565... |
565 |
###################### ALCASAR : LOG ACCESS ######################
|
565 |
###################### ALCASAR : LOG ACCESS ######################
|
566 |
echo "Get ACC log access of the week"
|
566 |
echo "Get ACC log access of the week"
|
567 |
|
567 |
|
568 |
ROWS=""
|
568 |
ROWS=""
|
569 |
while read -r access ; do
|
569 |
while read -r access ; do
|
570 |
access_datas=(${access//|||/ })
|
570 |
access_datas=(${access//|/ })
|
571 |
|
571 |
|
572 |
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
|
572 |
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
|
573 |
access_date=$(date -d "$accces_date_intl" +%s)
|
573 |
access_date=$(date -d "$accces_date_intl" +%s)
|
574 |
access_user=${access_datas[2]}
|
574 |
access_user=${access_datas[2]}
|
575 |
access_ip=${access_datas[3]}
|
575 |
access_ip=${access_datas[3]}
|
576 |
|
- |
|
- |
|
576 |
access_agent=${access_datas[4]}
|
577 |
if [ $access_date -lt $SECS_AGO ]; then
|
577 |
if [ $access_date -lt $SECS_AGO ]; then
|
578 |
break
|
578 |
break
|
579 |
fi
|
579 |
fi
|
580 |
|
580 |
|
581 |
access_date_formatted=$(date -d @$access_date +"%x %X")
|
581 |
access_date_formatted=$(date -d @$access_date +"%x %X")
|
582 |
|
582 |
|
583 |
ROWS="$ROWS<tr><td>$access_date_formatted</td><td>$access_user</td><td>$access_ip</td></tr>"
|
583 |
ROWS="$ROWS<tr><td>$access_date_formatted</td><td>$access_user</td><td>$access_ip</td><td>$access_agent</td></tr>"
|
584 |
done < <(cat /var/www/html/acc/admin_log.txt | sort -r)
|
584 |
done < <(cat /var/Save/security/acc_access.log | sort -r)
|
585 |
# TODO: Read archives if necessary
|
585 |
# TODO: Read archives if necessary
|
586 |
|
586 |
|
587 |
if [ -z "$ROWS" ]; then
|
587 |
if [ -z "$ROWS" ]; then
|
588 |
ROWS="<tr><td colspan=\"3\" style=\"text-align: center;\">Aucune connexion</td></tr>"
|
588 |
ROWS="<tr><td colspan=\"4\" style=\"text-align: center;\">Aucune connexion</td></tr>"
|
589 |
fi
|
589 |
fi
|
590 |
|
590 |
|
591 |
# Create HTML document
|
591 |
# Create HTML document
|
592 |
echo "<h2>Connexion à l'ALCASAR Control Center (ACC)</h2>" >> $HTML_REPORT
|
592 |
echo "<h2>Connexion à l'ALCASAR Control Center (ACC)</h2>" >> $HTML_REPORT
|
593 |
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
|
593 |
echo "<table class=\"table table-striped\">" >> $HTML_REPORT
|
594 |
echo "<thead><tr><th>Date</th><th>Utilisateur</th><th>Adresse IP</th></tr></thead><tbody>" >> $HTML_REPORT
|
594 |
echo "<thead><tr><th>Date</th><th>Utilisateur</th><th>Adresse IP</th><th>Agent</th></tr></thead><tbody>" >> $HTML_REPORT
|
595 |
echo $ROWS >> $HTML_REPORT
|
595 |
echo $ROWS >> $HTML_REPORT
|
596 |
echo "</tbody></table>" >> $HTML_REPORT
|
596 |
echo "</tbody></table>" >> $HTML_REPORT
|
597 |
|
597 |
|
598 |
|
598 |
|
599 |
###################### ALCASAR : GLOBAL TRAFFIC ######################
|
599 |
###################### ALCASAR : GLOBAL TRAFFIC ######################
|