Subversion Repositories ALCASAR

Compare Revisions

Regard whitespace Rev 2137 → Rev 2138

/scripts/alcasar-activity_report.sh
1,22 → 1,22
#Create an activity report for ALCASAR every week.
# 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
 
#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"
# 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"
 
#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"
DIR_BUILD="/var/www/html/acc/manager/activity_report/"
MODEL_CHARTJS="$DIR_BUILD/models/Chart.report.js"
MODEL_TABINFO="$DIR_BUILD/models/tabinfo.html"
 
#Where the report will be created.
HTML_REPORT="/var/www/html/acc/manager/activity_report/alcasar-report-$(date +%F).html"
HTML_REPORT="$DIR_BUILD/alcasar-report-$(date +%F).html"
 
#password of MariaDB
PASSWD_FILE="/root/ALCASAR-passwords.txt"
 
#TIME VALUE
C_TS=$(date +"%s") #current timestamp
MAX_DAY_AGO=7
31,12 → 31,12
 
#Values to create new htdigest user to consult statistique of ACC
DIR_KEY="/usr/local/etc/digest"
compte="papa"
tmp_account="alcasar"
realm="ALCASAR Control Center (ACC)"
password=$(openssl rand -base64 32) #random password (length : 32)
SED="/usr/bin/sed -i "
TMP_STATS="/var/tmp/stats.html"
TMP_STATS_2="/var/tmp/stats2.html"
TMP_STATS="$DIR_TMP/stats.html"
TMP_STATS_2="$DIR_TMP/stats2.html"
 
#if empty logs, replace charts by text.
ENABLE_BL=0
43,7 → 43,6
ENABLE_BL_WEEK=0
ENABLE_AV=0
 
 
if [ -e $TMP_AV ]
then
rm $TMP_AV
170,7 → 169,6
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
178,16 → 176,13
echo "</tr>" >> $HTML_REPORT
done
else
echo "<td>Pas de RPM mis à jour cette semaine</td>" >> $HTML_REPORT
echo "</tr>" >> $HTML_REPORT
echo "<tr collspan="3"><td>Pas de RPM mis à jour cette semaine</td></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
233,7 → 228,6
done < /var/log/dnsmasq/$FILE
done
 
 
#if data exists, create this section in html document
if [ -e $TMP_BL ]
then
607,17 → 601,17
 
#create new htdigest user to consult statistique of ACC
#if user does not exist, we create him
if [ $(grep "$compte:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
then
(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
(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
chown -R root:apache $DIR_KEY
chmod 640 $DIR_KEY/key_*
fi
 
#get stats.php from ACC
wget -q -nv --user $compte --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
wget -q -nv --user $tmp_account --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>"
626,16 → 620,15
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 "$compte:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
then
$SED "/^$compte:/d" $DIR_KEY/key_only_manager
$SED "/^$compte:/d" $DIR_KEY/key_manager
$SED "/^$compte:/d" $DIR_KEY/key_all
$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
fi
 
######################FIN HTML######################
 
 
#Execute our javascript function to print charts
echo "<script>window.onload = function() {" >> $HTML_REPORT
#BL SINCE INSTALLATION
660,17 → 653,15
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 ]