Subversion Repositories ALCASAR

Rev

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

Rev 1215 Rev 1219
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
#  $Id: alcasar.sh 1215 2013-09-18 22:08:14Z richard $ 
2
#  $Id: alcasar.sh 1219 2013-09-20 13:41:29Z crox53 $ 
3
 
3
 
4
# alcasar.sh
4
# alcasar.sh
5
 
5
 
6
# ALCASAR Install script -  CopyLeft ALCASAR Team [Rexy + 3abtux + Steweb + Crox + ...] 
6
# ALCASAR Install script -  CopyLeft ALCASAR Team [Rexy + 3abtux + Steweb + Crox + ...] 
7
# Ce programme est un logiciel libre ; This software is free and open source
7
# Ce programme est un logiciel libre ; This software is free and open source
Line 18... Line 18...
18
# Script d'installation d'ALCASAR (Application Libre pour le Contrôle d'Accès Sécurisé et Authentifié au Réseau)
18
# Script d'installation d'ALCASAR (Application Libre pour le Contrôle d'Accès Sécurisé et Authentifié au Réseau)
19
# ALCASAR est architecturé autour d'une distribution Linux Mageia minimaliste et les logiciels libres suivants :
19
# ALCASAR est architecturé autour d'une distribution Linux Mageia minimaliste et les logiciels libres suivants :
20
# Install script for ALCASAR (a secured and authenticated Internet access control captive portal)
20
# Install script for ALCASAR (a secured and authenticated Internet access control captive portal)
21
# ALCASAR is based on a stripped Mageia (LSB) with the following open source softwares :
21
# ALCASAR is based on a stripped Mageia (LSB) with the following open source softwares :
22
#
22
#
23
# Coovachilli (a fork of chillispot), freeradius, mysql, apache, netfilter, squid, dansguardian, ntpd, openssl, dnsmasq, havp, libclamav  and firewalleyes
23
# Coovachilli (a fork of chillispot), freeradius, mysql, apache, netfilter, squid, dansguardian, ntpd, openssl, dnsmasq, havp, libclamav
24
 
24
 
25
# Options :
25
# Options :
26
#       -i or --install
26
#       -i or --install
27
#       -u or --uninstall
27
#       -u or --uninstall
28
 
28
 
Line 1189... Line 1189...
1189
##              Fonction param_nfsen			##
1189
##              Fonction param_nfsen			##
1190
##########################################################
1190
##########################################################
1191
param_nfsen()
1191
param_nfsen()
1192
{
1192
{
1193
#Decompression tarball
1193
#Decompression tarball
1194
	tar xvzf ./conf/nfsen/nfsen-1.3.6p1.tar.gz -C /tmp/
1194
tar xvzf ./conf/nfsen/nfsen-1.3.6p1.tar.gz -C /tmp/
1195
#Création groupe et utilisteur
1195
#Création groupe et utilisteur
1196
	if grep "^www-data:" /etc/group > /dev/null; then
1196
if grep "^www-data:" /etc/group > /dev/null; then
1197
		echo "Group already exists !"
1197
	echo "Group already exists !"
1198
	else
1198
else
1199
		groupadd www-data
1199
	groupadd www-data
1200
		echo "Group 'www-data' created !"
1200
	echo "Group 'www-data' created !"
1201
	fi
1201
fi
1202
	if grep "^nfsen:" /etc/passwd > /dev/null; then
1202
if grep "^nfsen:" /etc/passwd > /dev/null; then
1203
		echo "User already exists !"
1203
	echo "User already exists !"
1204
	else
1204
else
1205
		useradd -m nfsen
1205
	useradd -m nfsen
1206
		echo "User 'nfsen' created !"
1206
	echo "User 'nfsen' created !"
1207
	fi
1207
fi
1208
	usermod -G www-data nfsen
1208
usermod -G www-data nfsen
1209
#Ajout du plugin nfsen : PortTracker
1209
#Ajout du plugin nfsen : PortTracker
1210
	mkdir -p /var/www/nfsen/plugins
1210
mkdir -p /var/www/nfsen/plugins
1211
	chown -R nfsen:www-data /var/www/nfsen
1211
chown -R nfsen:www-data /var/www/nfsen
1212
#Ajout du plugin PortTracker
1212
#Ajout du plugin PortTracker
1213
	mkdir -p /var/log/netflow/porttracker /usr/share/nfsen/plugins 
1213
mkdir -p /var/log/netflow/porttracker 
-
 
1214
mkdir -p /usr/share/nfsen/plugins
1214
	chown -R apache:apache /var/log/netflow/porttracker /usr/share/nfsen
1215
chown -R apache:apache /usr/share/nfsen
1215
	cp -f $DIR_CONF/nfsen/PortTracker.pm /tmp/nfsen-1.3.6p1/contrib/PortTracker/ 
1216
cp -f $DIR_CONF/nfsen/PortTracker.pm /tmp/nfsen-1.3.6p1/contrib/PortTracker/
-
 
1217
chown apache /var/log/netflow/porttracker
1216
#Copie du fichier de conf modifié de nfsen
1218
#Copie du fichier de conf modifié de nfsen
1217
	cp $DIR_CONF/nfsen/nfsen.conf /tmp/nfsen-1.3.6p1/etc/
1219
cp $DIR_CONF/nfsen/nfsen.conf /tmp/nfsen-1.3.6p1/etc/
1218
#Copie du script d'initialisation de nfsen
1220
#Copie du script d'initialisation de nfsen
1219
	cp $DIR_CONF/nfsen/nfsen.service /lib/systemd/system/
1221
cp $DIR_CONF/nfsen/nfsen.service /lib/systemd/system/
-
 
1222
systemctl enable nfsen.service
1220
#Installation de nfsen via le scrip Perl
1223
#Installation de nfsen via le scrip Perl
1221
	DirTmp=$(pwd)
1224
DirTmp=$(pwd)
1222
	cd /tmp/nfsen-1.3.6p1/
1225
cd /tmp/nfsen-1.3.6p1/
1223
	/usr/bin/perl5 install.pl etc/nfsen.conf #script lancé deux fois pour corriger,
1226
/usr/bin/perl5 install.pl etc/nfsen.conf #script lancé deux fois pour corriger,
1224
	/usr/bin/perl5 install.pl etc/nfsen.conf #un problème Perl : "Semaphore introuvable"
1227
/usr/bin/perl5 install.pl etc/nfsen.conf #un problème Perl : "Semaphore introuvable"
1225
#Création de la DB pour rrdtool
1228
#Création de la DB pour rrdtool
1226
	cp /tmp/nfsen-1.3.6p1/contrib/PortTracker/PortTracker.pm /usr/share/nfsen/plugins/
1229
cp /tmp/nfsen-1.3.6p1/contrib/PortTracker/PortTracker.pm /usr/share/nfsen/plugins/
1227
	cp /tmp/nfsen-1.3.6p1/contrib/PortTracker/PortTracker.php /var/www/nfsen/plugins/
1230
cp /tmp/nfsen-1.3.6p1/contrib/PortTracker/PortTracker.php /var/www/nfsen/plugins/
1228
	sudo -u apache nftrack -I -d /var/log/netflow/porttracker
1231
sudo -u apache nftrack -I -d /var/log/netflow/porttracker
1229
	chown -R apache:www-data /var/log/netflow/porttracker/
1232
chown -R apache:www-data /var/log/netflow/porttracker/
1230
	chmod -R 775 /var/log/netflow/porttracker
1233
chmod -R 775 /var/log/netflow/porttracker
1231
#Configuration du fichier de conf d'apache
1234
#Configuration du fichier de conf d'apache
1232
	if [ -f /etc/httpd/conf.d/nfsen.conf ];then
1235
if [ -f /etc/httpd/conf.d/nfsen.conf ];then
1233
		rm -f /etc/httpd/conf.d/nfsen.conf
1236
	rm -f /etc/httpd/conf.d/nfsen.conf
1234
	fi
1237
fi
1235
	cat <<EOF >> /etc/httpd/conf.d/nfsen.conf
1238
cat <<EOF >> /etc/httpd/conf.d/nfsen.conf
1236
Alias /nfsen /var/www/nfsen 
1239
Alias /nfsen /var/www/nfsen 
1237
<Directory /var/www/nfsen/> 
1240
<Directory /var/www/nfsen/> 
1238
DirectoryIndex nfsen.php 
1241
DirectoryIndex nfsen.php 
1239
Options -Indexes 
1242
Options -Indexes 
1240
AllowOverride all 
1243
AllowOverride all 
Line 1244... Line 1247...
1244
php_flag magic_quotes_gpc on 
1247
php_flag magic_quotes_gpc on 
1245
php_flag track_vars on 
1248
php_flag track_vars on 
1246
</Directory>
1249
</Directory>
1247
EOF
1250
EOF
1248
#Configuration du délais d'expiration des captures du profile "live"
1251
#Configuration du délais d'expiration des captures du profile "live"
1249
	nfsen -m live -e 62d
1252
nfsen -m live -e 62d
1250
#Suppression des sources de nfsen
1253
#Suppression des sources de nfsen
1251
	cd $DirTmp
1254
cd $DirTmp
1252
	rm -rf /tmp/nfsen-1.3.6p1/
1255
rm -rf /tmp/nfsen-1.3.6p1/
1253
} # End of param_nfsen
1256
} # End of param_nfsen
1254
 
1257
 
1255
##########################################################
1258
##########################################################
1256
##		Fonction param_dnsmasq			##
1259
##		Fonction param_dnsmasq			##
1257
##########################################################
1260
##########################################################
Line 1303... Line 1306...
1303
server=$DNS1
1306
server=$DNS1
1304
server=$DNS2
1307
server=$DNS2
1305
EOF
1308
EOF
1306
 
1309
 
1307
# Init file modification
1310
# Init file modification
1308
	[ -e /etc/init.d/dnsmasq.default ] || cp /etc/init.d/dnsmasq /etc/init.d/dnsmasq.default
1311
[ -e /etc/init.d/dnsmasq.default ] || cp /etc/init.d/dnsmasq /etc/init.d/dnsmasq.default
1309
# Start and stop a 2nd process for the "DNS blackhole"
1312
# Start and stop a 2nd process for the "DNS blackhole"
1310
	cp -f $DIR_CONF/dnsmasq /etc/init.d/dnsmasq			
1313
cp -f $DIR_CONF/dnsmasq /etc/init.d/dnsmasq			
1311
# Start after chilli (65) which create tun0
1314
# Start after chilli (65) which create tun0
1312
	$SED "s?^# chkconfig:.*?# chkconfig: 2345 99 40?g" /etc/init.d/dnsmasq
1315
$SED "s?^# chkconfig:.*?# chkconfig: 2345 99 40?g" /etc/init.d/dnsmasq
1313
# Optionnellement on pré-active les logs DNS des clients
1316
# Optionnellement on pré-active les logs DNS des clients
1314
	[ -e /etc/sysconfig/dnsmasq.default ] || cp /etc/sysconfig/dnsmasq /etc/sysconfig/dnsmasq.default
1317
[ -e /etc/sysconfig/dnsmasq.default ] || cp /etc/sysconfig/dnsmasq /etc/sysconfig/dnsmasq.default
1315
	$SED "s?log-facility?#OPTIONS=\"-q --log-facility=/var/log/dnsmasq/queries.log\"?g"  /etc/sysconfig/dnsmasq
1318
$SED "s?log-facility?#OPTIONS=\"-q --log-facility=/var/log/dnsmasq/queries.log\"?g"  /etc/sysconfig/dnsmasq
1316
# Optionnellement, exemple de paramètre supplémentaire pour le cache memoire
1319
# Optionnellement, exemple de paramètre supplémentaire pour le cache memoire
1317
	echo '#OPTIONS="$OPTIONS --cache-size=250"' >> /etc/sysconfig/dnsmasq
1320
echo '#OPTIONS="$OPTIONS --cache-size=250"' >> /etc/sysconfig/dnsmasq
1318
# Optionnellement, exemple de configuration avec un A.D.
1321
# Optionnellement, exemple de configuration avec un A.D.
1319
	echo '#OPTIONS="$OPTIONS --server=/your.domain/192.168.182.3"' >> /etc/sysconfig/dnsmasq
1322
echo '#OPTIONS="$OPTIONS --server=/your.domain/192.168.182.3"' >> /etc/sysconfig/dnsmasq
1320
} # End dnsmasq
1323
} # End dnsmasq
1321
 
1324
 
1322
##########################################################
1325
##########################################################
1323
##		Fonction BL (BlackList)			##
1326
##		Fonction BL (BlackList)			##
1324
##########################################################
1327
##########################################################
Line 1421... Line 1424...
1421
# mise à jour automatique de la distribution tous les jours 3h30
1424
# mise à jour automatique de la distribution tous les jours 3h30
1422
30 3 * * *  root /usr/sbin/urpmi --auto-update --auto 2>&1
1425
30 3 * * *  root /usr/sbin/urpmi --auto-update --auto 2>&1
1423
EOF
1426
EOF
1424
	cat << EOF > /etc/cron.d/alcasar-netflow
1427
	cat << EOF > /etc/cron.d/alcasar-netflow
1425
# mise à jour automatique du délais d'expiration des log Nertflow (tous les vendredi à 0h05)
1428
# mise à jour automatique du délais d'expiration des log Nertflow (tous les vendredi à 0h05)
1426
05 0 * * 5  root $DIR_DEST_BIN/alcasar-netflow.sh
1429
15 0 * * 1  root $DIR_DEST_BIN/alcasar-netflow.sh
1427
EOF
1430
EOF
1428
 
1431
 
1429
# mise à jour des stats de connexion (accounting). Scripts provenant de "dialupadmin" (rpm freeradius-web) (cf. wiki.freeradius.org/Dialup_admin).
1432
# mise à jour des stats de connexion (accounting). Scripts provenant de "dialupadmin" (rpm freeradius-web) (cf. wiki.freeradius.org/Dialup_admin).
1430
# on écrase le crontab d'origine installé par le RPM "freeradius-web" (bug remonté à qa.mandriva.com : 46739).
1433
# on écrase le crontab d'origine installé par le RPM "freeradius-web" (bug remonté à qa.mandriva.com : 46739).
1431
# 'tot_stats' (tout les jours à 01h01) : aggrégat des connexions journalières par usager (renseigne la table 'totacct') 
1434
# 'tot_stats' (tout les jours à 01h01) : aggrégat des connexions journalières par usager (renseigne la table 'totacct') 
Line 1531... Line 1534...
1531
	do
1534
	do
1532
	      find /var/log/$dir -type f -name *.log-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] -exec gzip {} \;
1535
	      find /var/log/$dir -type f -name *.log-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] -exec gzip {} \;
1533
	done
1536
	done
1534
# export des logs en 'retard' dans /var/Save/logs
1537
# export des logs en 'retard' dans /var/Save/logs
1535
	/usr/local/bin/alcasar-log.sh --export
1538
	/usr/local/bin/alcasar-log.sh --export
1536
# creation of the unit of alcasar-load_balancing
1539
# processus lancés par défaut au démarrage
-
 
1540
	for i in ntpd iptables ulogd dnsmasq squid chilli httpd radiusd netfs mysqld dansguardian havp freshclam nfsen
-
 
1541
	do
-
 
1542
		/sbin/chkconfig --add $i
-
 
1543
	done
-
 
1544
 
1537
	cat << EOF > /lib/systemd/system/alcasar-load_balancing.service
1545
cat << EOF > /lib/systemd/system/alcasar-load_balancing.service
1538
#  This file is part of systemd.
1546
#  This file is part of systemd.
1539
#
1547
#
1540
#  systemd is free software; you can redistribute it and/or modify it
1548
#  systemd is free software; you can redistribute it and/or modify it
1541
#  under the terms of the GNU General Public License as published by
1549
#  under the terms of the GNU General Public License as published by
1542
#  the Free Software Foundation; either version 2 of the License, or
1550
#  the Free Software Foundation; either version 2 of the License, or
Line 1556... Line 1564...
1556
SysVStartPriority=99
1564
SysVStartPriority=99
1557
 
1565
 
1558
[Install]
1566
[Install]
1559
WantedBy=multi-user.target
1567
WantedBy=multi-user.target
1560
EOF
1568
EOF
1561
	
-
 
1562
# process launch at boot time
-
 
1563
	for service in ntpd iptables ulogd dnsmasq squid chilli httpd radiusd netfs mysqld dansguardian havp freshclam
-
 
1564
	do
-
 
1565
		/sbin/chkconfig --add $service
-
 
1566
	done
-
 
1567
	for service in alcasar-load_balancing.service nfsen.service
1569
systemctl enable alcasar-load_balancing.service
1568
 
-
 
1569
	do
-
 
1570
		 /bin/systemctl enable $service
-
 
1571
	done
-
 
1572
 
1570
 
1573
# On applique les préconisations ANSSI
1571
# On applique les préconisations ANSSI
1574
# Apply French Security Agency rules
1572
# Apply French Security Agency rules
1575
# ignorer les broadcast ICMP. (attaque smurf) 
1573
# ignorer les broadcast ICMP. (attaque smurf) 
1576
	sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
1574
sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
1577
# ignorer les erreurs ICMP bogus
1575
# ignorer les erreurs ICMP bogus
1578
	sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
1576
sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
1579
# désactiver l'envoi et la réponse aux ICMP redirects
1577
# désactiver l'envoi et la réponse aux ICMP redirects
1580
	sysctl -w net.ipv4.conf.all.accept_redirects=0
1578
sysctl -w net.ipv4.conf.all.accept_redirects=0
1581
	accept_redirect=`grep accept_redirect /etc/sysctl.conf|wc -l`
1579
accept_redirect=`grep accept_redirect /etc/sysctl.conf|wc -l`
1582
	if [ "$accept_redirect" == "0" ]
1580
	if [ "$accept_redirect" == "0" ]
1583
	then
1581
	then
1584
		echo "net.ipv4.conf.all.accept_redirects = 0" >> /etc/sysctl.conf
1582
		echo "net.ipv4.conf.all.accept_redirects = 0" >> /etc/sysctl.conf
1585
	else
1583
	else
1586
		$SED "s?accept_redirects.*?accept_redirects = 0?g" /etc/sysctl.conf
1584
		$SED "s?accept_redirects.*?accept_redirects = 0?g" /etc/sysctl.conf
Line 1835... Line 1833...
1835
			mode="install"
1833
			mode="install"
1836
		fi
1834
		fi
1837
		for func in init network gestion AC init_db param_radius param_web_radius param_chilli param_squid param_dansguardian antivirus param_ulogd param_nfsen param_dnsmasq BL cron fail2ban post_install
1835
		for func in init network gestion AC init_db param_radius param_web_radius param_chilli param_squid param_dansguardian antivirus param_ulogd param_nfsen param_dnsmasq BL cron fail2ban post_install
1838
		do
1836
		do
1839
			$func
1837
			$func
1840
# echo "*** 'debug' : end of function $func ***"; read a
1838
 echo "*** 'debug' : end of function $func ***"; read a
1841
		done
1839
		done
1842
		;;
1840
		;;
1843
	-u | --uninstall)
1841
	-u | --uninstall)
1844
		if [ ! -e $DIR_DEST_SBIN/alcasar-uninstall.sh ]
1842
		if [ ! -e $DIR_DEST_SBIN/alcasar-uninstall.sh ]
1845
		then
1843
		then