Subversion Repositories ALCASAR

Rev

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

Rev 1263 Rev 1266
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-archive.sh 1263 2013-12-14 13:25:22Z richard $
2
# $Id: alcasar-archive.sh 1266 2013-12-15 21:12:46Z richard $
3
 
3
 
4
# alcasar-archive.sh
4
# alcasar-archive.sh
5
# by Franck BOUIJOUX and REXY
5
# by Franck BOUIJOUX and REXY
6
# This script is distributed under the Gnu General Public License (GPL)
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
7
 
Line 56... Line 56...
56
} # end function crypt
56
} # end function crypt
57
 
57
 
58
function archive() {
58
function archive() {
59
		mkdir -p $DIR_ARCHIVE
59
		mkdir -p $DIR_ARCHIVE
60
		mkdir -p $DIR_TMP 
60
		mkdir -p $DIR_TMP 
-
 
61
		nb_files=`ls $DIR_LOG/firewall/tracability.log*.gz 2>/dev/null | wc -w`
-
 
62
		if [ $nb_files -ne 0 ]; then
61
		mv $(echo $(ls -rt $DIR_LOG/firewall/tracability.log*.gz | tail -n 1 -)) $DIR_TMP/tracability-HTTP.log-$NOW.gz
63
			mv $(echo $(ls -rt $DIR_LOG/firewall/tracability.log*.gz | tail -n 1 -)) $DIR_TMP/tracability-HTTP.log-$NOW.gz
-
 
64
		fi
-
 
65
		nb_files=`ls $DIR_BASE/radius-*.sql 2>/dev/null | wc -w`
-
 
66
		if [ $nb_files -ne 0 ]; then
62
		mv $(echo $(ls -rt $DIR_BASE/radius-*.sql | tail -n 1 -)) $DIR_TMP/
67
			mv $(echo $(ls -rt $DIR_BASE/radius-*.sql | tail -n 1 -)) $DIR_TMP/
-
 
68
		fi
63
		cd /var/log/nfsen/profiles-data/live/ipt_netflow
69
		cd /var/log/nfsen/profiles-data/live/ipt_netflow
-
 
70
		nb_files=`find . -mtime -7 -name 'nfcapd.[0-9]*' | wc -l`
-
 
71
		if [ $nb_files -ne 0 ]; then
64
		find .  -mtime -7 -name 'nfcapd.[0-9]*' | xargs tar -cf $DIR_TMP/tracability-ALL.log-$NOW.tar;
72
			find .  -mtime -7 -name 'nfcapd.[0-9]*' | xargs tar -cf $DIR_TMP/tracability-ALL.log-$NOW.tar;
-
 
73
		fi
65
		cd /tmp/
74
		cd /tmp/
-
 
75
		nb_files=`ls archive-$NOW/* 2>/dev/null | wc -w`
-
 
76
		if [ $nb_files -ne 0 ]; then
66
		tar cvzf /tmp/$FILE archive-$NOW/*
77
			tar cvzf /tmp/$FILE archive-$NOW/*
-
 
78
		else echo "no file to archive"
-
 
79
		fi
67
} # end archive
80
} # end archive
68
 
81
 
69
#  Core script
82
#  Core script
70
case $args in
83
case $args in
71
	-\? | -h* | --h*)
84
	-\? | -h* | --h*)
Line 76... Line 89...
76
		cleanup
89
		cleanup
77
		;;
90
		;;
78
	--now | -n)
91
	--now | -n)
79
		cleanup
92
		cleanup
80
		archive
93
		archive
-
 
94
 		if [ -e /tmp/$FILE ]; then 
81
 		 if [ $CRYPT -eq "1" ]; then
95
			if [ $CRYPT -eq "1" ]; then
82
		{
96
			{
83
		 # 1 ) chiffrement/signature =1 ==> gpg --encrypt avec test de la clé présente
97
				# 1 ) chiffrement/signature =1 ==> gpg --encrypt avec test de la clé présente
84
		    gpg --output $DIR_ARCHIVE/$FILE-crypt.gpg --armor --encrypt --recipient $GPG_USER  /tmp/$FILE
98
				gpg --output $DIR_ARCHIVE/$FILE-crypt.gpg --armor --encrypt --recipient $GPG_USER  /tmp/$FILE
85
		}
99
			}
86
		elif [ $SIGN -eq "1" ]; then
100
			elif [ $SIGN -eq "1" ]; then
87
		{
101
			{
88
		  # 2) signature = 1 Chiffrement = 0 --> gpg --encrypt   idem test de la clé présente
102
				# 2) signature = 1 Chiffrement = 0 --> gpg --encrypt   idem test de la clé présente
89
		    gpg --output $DIR_ARCHIVE/$FILE-sign.gpg --sign --recipient $GPG_USER  /tmp/$FILE
103
				gpg --output $DIR_ARCHIVE/$FILE-sign.gpg --sign --recipient $GPG_USER  /tmp/$FILE
90
		    gpg --output $DIR_ARCHIVE/$FILE-sign.gpg --sign --recipient $GPG_USER --detach-sign  /tmp/$FILE
104
				gpg --output $DIR_ARCHIVE/$FILE-sign.gpg --sign --recipient $GPG_USER --detach-sign  /tmp/$FILE
91
		}
105
			}
92
		else
106
			else
93
		{
107
			{
94
		  # 3)  chiffrement/signature = 0  --> cp simple avec suppression des droits d'écriture
108
				# 3)  chiffrement/signature = 0  --> cp simple avec suppression des droits d'écriture
95
		    cp /tmp/$FILE $DIR_ARCHIVE/.
109
				cp /tmp/$FILE $DIR_ARCHIVE/.
96
		}
110
			}
-
 
111
			fi
97
		fi
112
		fi
98
		rm -rf /tmp/archive-*
113
		rm -rf /tmp/archive-*
99
		chown root:apache $DIR_ARCHIVE/*
114
		chown root:apache $DIR_ARCHIVE/*
100
		;;
115
		;;
101
	--live | -l)
116
	--live | -l)