Subversion Repositories ALCASAR

Rev

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

Rev 2013 Rev 2138
Line 1... Line 1...
1
#Create an activity report for ALCASAR every week.
1
# 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.
2
# We read configuration files and logs to create cool charts.
-
 
3
# Written by Raphaël PION & Rexy
-
 
4
 
-
 
5
# files
-
 
6
DIR_TMP="/var/tmp"
-
 
7
TMP_AV="$DIR_TMP/av_count.txt"
-
 
8
TMP_BL="$DIR_TMP/bl_count.txt"
-
 
9
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt"
-
 
10
TMP_BL_WEEK_CAT="$DIR_TMP/bl_count_week_cat.txt"
-
 
11
 
-
 
12
# Model loaded to create charts
-
 
13
DIR_BUILD="/var/www/html/acc/manager/activity_report/"
-
 
14
MODEL_CHARTJS="$DIR_BUILD/models/Chart.report.js"
-
 
15
MODEL_TABINFO="$DIR_BUILD/models/tabinfo.html"
3
 
16
 
4
#file
-
 
5
TMP_AV="/var/tmp/av_count.txt"
-
 
6
TMP_BL="/var/tmp/bl_count.txt"
-
 
7
TMP_BL_WEEK="/var/tmp/bl_count_week.txt"
-
 
8
TMP_BL_WEEK_CAT="/var/tmp/bl_count_week_cat.txt"
-
 
9
 
-
 
10
#Model loaded to create charts
17
# Where the report will be created.
11
MODEL_CHARTJS="/var/www/html/acc/manager/activity_report/models/Chart.report.js"
-
 
12
MODEL_TABINFO="/var/www/html/acc/manager/activity_report/models/tabinfo.html"
18
HTML_REPORT="$DIR_BUILD/alcasar-report-$(date +%F).html"
13
 
19
 
14
#Where the report will be created.
-
 
15
HTML_REPORT="/var/www/html/acc/manager/activity_report/alcasar-report-$(date +%F).html"
-
 
16
 
-
 
17
#password of MariaDB
-
 
18
PASSWD_FILE="/root/ALCASAR-passwords.txt"
-
 
19
 
-
 
20
#TIME VALUE
20
# TIME VALUE
21
C_TS=$(date +"%s") #current timestamp
21
C_TS=$(date +"%s") #current timestamp
22
MAX_DAY_AGO=7
22
MAX_DAY_AGO=7
23
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
23
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
24
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
24
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
25
 
25
 
26
#PRIVATE IP OF ALCASAR
26
# PRIVATE IP OF ALCASAR
27
PRIVATE_IP=$(cat /usr/local/etc/alcasar.conf | grep PRIVATE_IP | cut -d'=' -f2 | cut -d'/' -f1)
27
PRIVATE_IP=$(cat /usr/local/etc/alcasar.conf | grep PRIVATE_IP | cut -d'=' -f2 | cut -d'/' -f1)
28
 
28
 
29
#COLOR for charts
29
# COLOR for charts
30
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'"
30
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'"
31
 
31
 
32
#Values to create new htdigest user to consult statistique of ACC
32
# Values to create new htdigest user to consult statistique of ACC
33
DIR_KEY="/usr/local/etc/digest"
33
DIR_KEY="/usr/local/etc/digest"
34
compte="papa"
34
tmp_account="alcasar"
35
realm="ALCASAR Control Center (ACC)"
35
realm="ALCASAR Control Center (ACC)"
36
password=$(openssl rand -base64 32) #random password (length : 32)
36
password=$(openssl rand -base64 32) #random password (length : 32)
37
SED="/usr/bin/sed -i "
37
SED="/usr/bin/sed -i "
38
TMP_STATS="/var/tmp/stats.html"
38
TMP_STATS="$DIR_TMP/stats.html"
39
TMP_STATS_2="/var/tmp/stats2.html"
39
TMP_STATS_2="$DIR_TMP/stats2.html"
40
 
40
 
41
#if empty logs, replace charts by text.
41
# if empty logs, replace charts by text.
42
ENABLE_BL=0
42
ENABLE_BL=0
43
ENABLE_BL_WEEK=0
43
ENABLE_BL_WEEK=0
44
ENABLE_AV=0
44
ENABLE_AV=0
45
 
45
 
46
 
-
 
47
if [ -e $TMP_AV ]
46
if [ -e $TMP_AV ]
48
then
47
then
49
	rm $TMP_AV
48
	rm $TMP_AV
50
fi
49
fi
51
 
50
 
Line 168... Line 167...
168
			RPM_TIMESTAMP=$(echo $RPM_ALCASAR | cut -d' ' -f1)
167
			RPM_TIMESTAMP=$(echo $RPM_ALCASAR | cut -d' ' -f1)
169
			RPM_DATE=$(date -d @$(echo $RPM_TIMESTAMP) "+%Y-%m-%d %H:%M:%S")
168
			RPM_DATE=$(date -d @$(echo $RPM_TIMESTAMP) "+%Y-%m-%d %H:%M:%S")
170
			RPM_NAME=$(echo $RPM_ALCASAR | cut -d' ' -f2)
169
			RPM_NAME=$(echo $RPM_ALCASAR | cut -d' ' -f2)
171
			RPM_VERSION=$(echo $RPM_ALCASAR | cut -d' ' -f3)
170
			RPM_VERSION=$(echo $RPM_ALCASAR | cut -d' ' -f3)
172
 
171
 
173
 
-
 
174
			echo "<tr>" >> $HTML_REPORT
172
			echo "<tr>" >> $HTML_REPORT
175
			echo "<td>$RPM_NAME</td>" >> $HTML_REPORT
173
			echo "<td>$RPM_NAME</td>" >> $HTML_REPORT
176
			echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
174
			echo "<td>$RPM_DATE</td>" >> $HTML_REPORT
177
			echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
175
			echo "<td>$RPM_VERSION</td>" >> $HTML_REPORT
178
			echo "</tr>" >> $HTML_REPORT
176
			echo "</tr>" >> $HTML_REPORT
179
		done
177
		done
180
	else
178
	else
181
		echo "<td>Pas de RPM mis à jour cette semaine</td>" >> $HTML_REPORT
179
		echo "<tr collspan="3"><td>Pas de RPM mis à jour cette semaine</td></tr>" >> $HTML_REPORT
182
		echo "</tr>" >> $HTML_REPORT
-
 
183
	fi
180
	fi
184
else
181
else
185
	echo $LINE_HTML >> $HTML_REPORT
182
	echo $LINE_HTML >> $HTML_REPORT
186
fi
183
fi
187
 
-
 
188
done
184
done
189
 
185
 
190
 
-
 
191
######################BL WEBSITE SINCE INSTALLATION######################
186
######################BL WEBSITE SINCE INSTALLATION######################
192
echo "Create BL website since the installation of ALCASAR"
187
echo "Create BL website since the installation of ALCASAR"
193
#find data
188
#find data
194
 
189
 
195
#decompress every logs
190
#decompress every logs
Line 231... Line 226...
231
		fi
226
		fi
232
		
227
		
233
	done < /var/log/dnsmasq/$FILE
228
	done < /var/log/dnsmasq/$FILE
234
done
229
done
235
 
230
 
236
 
-
 
237
#if data exists, create this section in html document
231
#if data exists, create this section in html document
238
if [ -e $TMP_BL ]
232
if [ -e $TMP_BL ]
239
then
233
then
240
	ENABLE_BL=1
234
	ENABLE_BL=1
241
	#count every BL website consulted since installation (maximum 1 year)
235
	#count every BL website consulted since installation (maximum 1 year)
Line 605... Line 599...
605
#create html document
599
#create html document
606
echo "<h3>Statistiques volumétrie connexions</h3>" >> $HTML_REPORT
600
echo "<h3>Statistiques volumétrie connexions</h3>" >> $HTML_REPORT
607
 
601
 
608
#create new htdigest user to consult statistique of ACC
602
#create new htdigest user to consult statistique of ACC
609
#if user does not exist, we create him
603
#if user does not exist, we create him
610
if [ $(grep "$compte:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
604
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -lt 1 ]
611
then
605
then
612
        (echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
606
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_only_manager
613
        (echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
607
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_manager
614
        (echo -n "$compte:$realm:" && echo -n "$compte:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
608
        (echo -n "$tmp_account:$realm:" && echo -n "$tmp_account:$realm:$password" | md5sum | awk '{print $1}' ) >> $DIR_KEY/key_all
615
        chown -R root:apache $DIR_KEY
609
        chown -R root:apache $DIR_KEY
616
        chmod 640 $DIR_KEY/key_*
610
        chmod 640 $DIR_KEY/key_*
617
fi
611
fi
618
 
612
 
619
#get stats.php from ACC
613
#get stats.php from ACC
620
wget -q -nv --user $compte --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
614
wget -q -nv --user $tmp_account --password $password https://alcasar/acc/manager/htdocs/stats.php -O $TMP_STATS --no-check-certificate
621
 
615
 
622
#clean this file to include it in html report.
616
#clean this file to include it in html report.
623
DELIM_1="<td colspan=10 height=20><img src=\"images\/pixel.gif\"><\/td>"
617
DELIM_1="<td colspan=10 height=20><img src=\"images\/pixel.gif\"><\/td>"
624
DELIM_2="<\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <p>"
618
DELIM_2="<\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <\/td><\/tr> <\/table> <p>"
625
cat $TMP_STATS | sed -n "/$DELIM_1/,/$DELIM_2/p" | tail -n+3 | head -n-2 >> $TMP_STATS_2
619
cat $TMP_STATS | sed -n "/$DELIM_1/,/$DELIM_2/p" | tail -n+3 | head -n-2 >> $TMP_STATS_2
626
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
620
cat $TMP_STATS_2 | sed -e 's:images/pixel.gif:../../manager/htdocs/images/pixel.gif:g' >> $HTML_REPORT
627
 
621
 
628
#we delete our user if he still exists
622
#we delete our user if he still exists
629
if [ $(grep "$compte:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
623
if [ $(grep "$tmp_account:" $DIR_KEY/key_only_manager | wc -l) -ge 1 ]
630
then
624
then
631
        $SED "/^$compte:/d" $DIR_KEY/key_only_manager
625
        $SED "/^$tmp_account:/d" $DIR_KEY/key_only_manager
632
        $SED "/^$compte:/d" $DIR_KEY/key_manager
626
        $SED "/^$tmp_account:/d" $DIR_KEY/key_manager
633
       	$SED "/^$compte:/d" $DIR_KEY/key_all
627
       	$SED "/^$tmp_account:/d" $DIR_KEY/key_all
634
fi
628
fi
635
 
629
 
636
######################FIN HTML######################
630
######################FIN HTML######################
637
 
631
 
638
 
-
 
639
#Execute our javascript function to print charts
632
#Execute our javascript function to print charts
640
echo "<script>window.onload = function() {" >> $HTML_REPORT
633
echo "<script>window.onload = function() {" >> $HTML_REPORT
641
#BL SINCE INSTALLATION
634
#BL SINCE INSTALLATION
642
if [ $ENABLE_BL -eq "1" ]
635
if [ $ENABLE_BL -eq "1" ]
643
then
636
then
Line 658... Line 651...
658
fi
651
fi
659
#CONNEXIONS AUTHORIZED
652
#CONNEXIONS AUTHORIZED
660
echo "var ctx_$NAME_AUTH = document.getElementById('$NAME_AUTH').getContext('2d');" >> $HTML_REPORT
653
echo "var ctx_$NAME_AUTH = document.getElementById('$NAME_AUTH').getContext('2d');" >> $HTML_REPORT
661
echo "var $NAME_AUTH = new Chart(ctx_$NAME_AUTH, $CONF_AUTH);" >> $HTML_REPORT
654
echo "var $NAME_AUTH = new Chart(ctx_$NAME_AUTH, $CONF_AUTH);" >> $HTML_REPORT
662
echo "};</script>" >> $HTML_REPORT
655
echo "};</script>" >> $HTML_REPORT
663
 
-
 
664
 
-
 
665
 
-
 
666
echo "</body>" >> $HTML_REPORT
656
echo "</body>" >> $HTML_REPORT
667
echo "</html>" >> $HTML_REPORT
657
echo "</html>" >> $HTML_REPORT
668
 
658
 
669
 
-
 
670
#convert html document to PDF
659
#convert html document to PDF
-
 
660
cp $HTML_REPORT $DIR_BUILD/rapport.html
671
/usr/bin/wkhtmltopdf $HTML_REPORT $(echo $HTML_REPORT | cut -d'.' -f1).pdf
661
/usr/bin/wkhtmltopdf $HTML_REPORT $(echo $HTML_REPORT | cut -d'.' -f1).pdf
672
chown apache:apache $(echo $HTML_REPORT | cut -d'.' -f1).pdf
662
chown apache:apache $(echo $HTML_REPORT | cut -d'.' -f1).pdf
673
chmod 644 $(echo $HTML_REPORT | cut -d'.' -f1).pdf
663
chmod 644 $(echo $HTML_REPORT | cut -d'.' -f1).pdf
-
 
664
mv $(echo $HTML_REPORT | cut -d'.' -f1).pdf /var/Save/
674
 
665
 
675
#compress every logs, if they exist
666
#compress every logs, if they exist
676
if [ $(ls -1 /var/log/havp/access.log.* 2>/dev/null | wc -l) -ge 1 ]
667
if [ $(ls -1 /var/log/havp/access.log.* 2>/dev/null | wc -l) -ge 1 ]
677
then
668
then
678
	gzip /var/log/havp/access.log.*
669
	gzip /var/log/havp/access.log.*