1,48 → 1,49 |
# 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 |
#Create an activity report for ALCASAR every week. |
#We read configuration files and logs to create cool charts. |
|
# files |
DIR_TMP="/var/tmp" |
TMP_AV="$DIR_TMP/av_count.txt" |
TMP_BL="$DIR_TMP/bl_count.txt" |
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt" |
TMP_BL_WEEK_CAT="$DIR_TMP/bl_count_week_cat.txt" |
#file |
TMP_AV="/var/tmp/av_count.txt" |
TMP_BL="/var/tmp/bl_count.txt" |
TMP_BL_WEEK="/var/tmp/bl_count_week.txt" |
TMP_BL_WEEK_CAT="/var/tmp/bl_count_week_cat.txt" |
|
# Model loaded to create charts |
DIR_BUILD="/var/www/html/acc/manager/activity_report/" |
MODEL_CHARTJS="$DIR_BUILD/models/Chart.report.js" |
MODEL_TABINFO="$DIR_BUILD/models/tabinfo.html" |
#Model loaded to create charts |
MODEL_CHARTJS="/var/www/html/acc/manager/activity_report/models/Chart.report.js" |
MODEL_TABINFO="/var/www/html/acc/manager/activity_report/models/tabinfo.html" |
|
# Where the report will be created. |
HTML_REPORT="$DIR_BUILD/alcasar-report-$(date +%F).html" |
#Where the report will be created. |
HTML_REPORT="/var/www/html/acc/manager/activity_report/alcasar-report-$(date +%F).html" |
|
# TIME VALUE |
#password of MariaDB |
PASSWD_FILE="/root/ALCASAR-passwords.txt" |
|
#TIME VALUE |
C_TS=$(date +"%s") #current timestamp |
MAX_DAY_AGO=7 |
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago |
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO |
|
# PRIVATE IP OF ALCASAR |
#PRIVATE IP OF ALCASAR |
PRIVATE_IP=$(cat /usr/local/etc/alcasar.conf | grep PRIVATE_IP | cut -d'=' -f2 | cut -d'/' -f1) |
|
# COLOR for charts |
#COLOR for charts |
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'" |
|
# Values to create new htdigest user to consult statistique of ACC |
#Values to create new htdigest user to consult statistique of ACC |
DIR_KEY="/usr/local/etc/digest" |
tmp_account="alcasar" |
compte="papa" |
realm="ALCASAR Control Center (ACC)" |
password=$(openssl rand -base64 32) #random password (length : 32) |
SED="/usr/bin/sed -i " |
TMP_STATS="$DIR_TMP/stats.html" |
TMP_STATS_2="$DIR_TMP/stats2.html" |
TMP_STATS="/var/tmp/stats.html" |
TMP_STATS_2="/var/tmp/stats2.html" |
|
# if empty logs, replace charts by text. |
#if empty logs, replace charts by text. |
ENABLE_BL=0 |
ENABLE_BL_WEEK=0 |
ENABLE_AV=0 |
|
|
if [ -e $TMP_AV ] |
then |
rm $TMP_AV |
169,6 → 170,7 |
RPM_NAME=$(echo $RPM_ALCASAR | cut -d' ' -f2) |
RPM_VERSION=$(echo $RPM_ALCASAR | cut -d' ' -f3) |
|
|
echo "<tr>" >> $HTML_REPORT |
echo "<td>$RPM_NAME</td>" >> $HTML_REPORT |
echo "<td>$RPM_DATE</td>" >> $HTML_REPORT |
176,13 → 178,16 |
echo "</tr>" >> $HTML_REPORT |
done |
else |
echo "<tr collspan="3"><td>Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT |
echo "<td>Pas de RPM mis à jour cette semaine</td>" >> $HTML_REPORT |
echo "</tr>" >> $HTML_REPORT |
fi |
else |
echo $LINE_HTML >> $HTML_REPORT |
fi |
|
done |
|
|
######################BL WEBSITE SINCE INSTALLATION###################### |
echo "Create BL website since the installation of ALCASAR" |
#find data |
228,6 → 233,7 |
done < /var/log/dnsmasq/$FILE |
done |
|
|
#if data exists, create this section in html document |
if [ -e $TMP_BL ] |
then |
601,17 → 607,17 |
|
#create new htdigest user to consult statistique of ACC |
#if user does not exist, we create him |
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ] |
if [ $(grep "$compte:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ] |
then |
(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager |
(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager |
(echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all |
(echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager |
(echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager |
(echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all |
chown -R root:apache $DIR_KEY |
chmod 640 $DIR_KEY/key_* |
fi |
|
#get stats.php from ACC |
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate |
wget -q -nv --user $compte --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate |
|
#clean this file to include it in html report. |
DELIM_1="<td colspan=10 height=20><img src=\"images\/pixel.gif\"><\/td>" |
620,15 → 626,16 |
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT |
|
#we delete our user if he still exists |
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ] |
if [ $(grep "$compte:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ] |
then |
$SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager |
$SED "/^$tmp_account:/d" $DIR_KEY/key_manager |
$SED "/^$tmp_account:/d" $DIR_KEY/key_all |
$SED "/^$compte:/d" $DIR_KEY/key_only_manager |
$SED "/^$compte:/d" $DIR_KEY/key_manager |
$SED "/^$compte:/d" $DIR_KEY/key_all |
fi |
|
######################FIN HTML###################### |
|
|
#Execute our javascript function to print charts |
echo "<script>window.onload = function() {" >> $HTML_REPORT |
#BL SINCE INSTALLATION |
653,15 → 660,17 |
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 |
|
|
#convert html document to PDF |
cp $HTML_REPORT $DIR_BUILD/rapport.html |
/usr/bin/wkhtmltopdf $HTML_REPORT $(echo $HTML_REPORT | cut -d'.' -f1).pdf |
chown apache:apache $(echo $HTML_REPORT | cut -d'.' -f1).pdf |
chmod 644 $(echo $HTML_REPORT | cut -d'.' -f1).pdf |
mv $(echo $HTML_REPORT | cut -d'.' -f1).pdf /var/Save/ |
|
#compress every logs, if they exist |
if [ $(ls -1 /var/log/havp/access.log.* 2>/dev/null | wc -l) -ge 1 ] |