Subversion Repositories ALCASAR

Rev

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

Rev 1317 Rev 1336
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
#  $Id: alcasar.sh 1317 2014-03-17 20:26:51Z richard $ 
2
#  $Id: alcasar.sh 1336 2014-04-28 17:07:37Z richard $ 
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 67... Line 67...
67
DB_RADIUS="radius"				# database name used by FreeRadius server
67
DB_RADIUS="radius"				# database name used by FreeRadius server
68
DB_USER="radius"				# user name allows to request the users database
68
DB_USER="radius"				# user name allows to request the users database
69
# ******* Network parameters - paramètres réseau *******
69
# ******* Network parameters - paramètres réseau *******
70
HOSTNAME="alcasar"				# 
70
HOSTNAME="alcasar"				# 
71
DOMAIN="localdomain"				# default local domain
71
DOMAIN="localdomain"				# default local domain
72
EXTIF="eth0"					# ETH0 is connected to the ISP broadband modem/router (In France : Box-FAI )
72
EXTIF=`/sbin/ip route|grep default|cut -d" " -f5`	# EXTIF is connected to the ISP broadband modem/router (In France : Box-FAI)
-
 
73
INTIF=`/sbin/ip	link|grep '^[[:digit:]]:'|grep -v "lo\|$EXTIF"|cut -d" " -f2|tr -d ":"`		# INTIF is connected to the consultation network
73
MTU="1500"
74
MTU="1500"
74
ETHTOOL_OPTS='"autoneg off speed 100 duplex full"'
75
ETHTOOL_OPTS='"autoneg off speed 100 duplex full"'
75
INTIF="eth1"					# ETH1 is connected to the consultation network
-
 
76
DEFAULT_PRIVATE_IP_MASK="192.168.182.1/24"	# Default ALCASAR IP address
76
DEFAULT_PRIVATE_IP_MASK="192.168.182.1/24"	# Default ALCASAR IP address
77
# ****** Paths - chemin des commandes *******
77
# ****** Paths - chemin des commandes *******
78
SED="/bin/sed -i"
78
SED="/bin/sed -i"
79
# ****************** End of global parameters *********************
79
# ****************** End of global parameters *********************
80
 
80
 
Line 96... Line 96...
96
	echo "                     ALCASAR V$VERSION Installation"
96
	echo "                     ALCASAR V$VERSION Installation"
97
	echo "Application Libre pour le Contrôle d'Accès Sécurisé et Authentifié au Réseau"
97
	echo "Application Libre pour le Contrôle d'Accès Sécurisé et Authentifié au Réseau"
98
	echo "-----------------------------------------------------------------------------"
98
	echo "-----------------------------------------------------------------------------"
99
} # End of header_install ()
99
} # End of header_install ()
100
 
100
 
101
#Launch network service (useful only when Mageia is running in SafeFail mode)
-
 
102
service network start
-
 
103
 
101
 
104
##################################################################
102
##################################################################
105
##			Function "testing"			##
103
##			Function "testing"			##
106
## - Test of Internet access					##
104
## - Test of Internet access					##
107
##################################################################
105
##################################################################
Line 109... Line 107...
109
{
107
{
110
	if [ $Lang == "fr" ]
108
	if [ $Lang == "fr" ]
111
		then echo -n "Tests des paramètres réseau : "
109
		then echo -n "Tests des paramètres réseau : "
112
		else echo -n "Network parameters tests : "
110
		else echo -n "Network parameters tests : "
113
	fi
111
	fi
114
# We test eth0 config files
112
# We test EXTIF config files
-
 
113
 
115
	PUBLIC_IP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2`
114
	PUBLIC_IP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2`
116
	PUBLIC_GATEWAY=`grep GATEWAY /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2`
115
	PUBLIC_GATEWAY=`grep GATEWAY /etc/sysconfig/network-scripts/ifcfg-$EXTIF|cut -d"=" -f2`
117
	if [ `echo $PUBLIC_IP|wc -c` -lt 7 ] || [ `echo $PUBLIC_GATEWAY|wc -c` -lt 7 ]
116
	if [ `echo $PUBLIC_IP|wc -c` -lt 7 ] || [ `echo $PUBLIC_GATEWAY|wc -c` -lt 7 ]
118
		then
117
		then
119
		if [ $Lang == "fr" ]
118
		if [ $Lang == "fr" ]
Line 174... Line 173...
174
			echo "Resolv this problem, then restart this script."
173
			echo "Resolv this problem, then restart this script."
175
		fi
174
		fi
176
		exit 0
175
		exit 0
177
	fi
176
	fi
178
	echo -n "."
177
	echo -n "."
179
# On traite le cas où l'interface configurée lors de l'installation est "eth1" au lieu de "eth0" (mystère sur certaines versions de BIOS et de VirtualBox)
-
 
180
	if [ `ip route list|grep ^default|grep -c eth1` -eq "1" ] ; then
-
 
181
		if [ $Lang == "fr" ]
-
 
182
			then echo "La configuration des cartes réseau va être corrigée."
-
 
183
			else echo "The Ethernet card configuration will be corrected."
-
 
184
		fi
-
 
185
		/etc/init.d/network stop
-
 
186
		mv -f /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth0
-
 
187
		$SED "s?eth1?eth0?g" /etc/sysconfig/network-scripts/ifcfg-eth0
-
 
188
		/etc/init.d/network start
-
 
189
		echo 0 > /proc/sys/net/ipv4/conf/all/log_martians
-
 
190
		sleep 2
-
 
191
		if [ $Lang == "fr" ]
-
 
192
			then echo "Configuration corrigée"
-
 
193
			else echo "Configuration updated"
-
 
194
		fi
-
 
195
		sleep 2
-
 
196
		if [ $Lang == "fr" ]
-
 
197
			then echo "Vous pouvez relancer ce script."
-
 
198
			else echo "You can restart this script."
-
 
199
		fi
-
 
200
		exit 0
-
 
201
	fi
-
 
202
	echo -n "."
-
 
203
# On teste le lien vers le routeur par defaut
178
# On teste le lien vers le routeur par defaut
204
	IP_GW=`ip route list|grep ^default|cut -d" " -f3`
179
	IP_GW=`ip route list|grep ^default|cut -d" " -f3`
205
	arp_reply=`/usr/sbin/arping -b -I$EXTIF -c1 -w2 $IP_GW|grep response|cut -d" " -f2`
180
	arp_reply=`/usr/sbin/arping -b -I$EXTIF -c1 -w2 $IP_GW|grep response|cut -d" " -f2`
206
	if [ $(expr $arp_reply) -eq 0 ]
181
	if [ $(expr $arp_reply) -eq 0 ]
207
	       	then
182
	       	then
Line 315... Line 290...
315
 
290
 
316
##################################################################
291
##################################################################
317
##			Function "network"			##
292
##			Function "network"			##
318
## - Définition du plan d'adressage du réseau de consultation	##
293
## - Définition du plan d'adressage du réseau de consultation	##
319
## - Nommage DNS du système 					##
294
## - Nommage DNS du système 					##
320
## - Configuration de l'interface eth1 (réseau de consultation)	##
295
## - Configuration de l'interface INTIF (réseau de consultation)##
321
## - Modification du fichier /etc/hosts				##
296
## - Modification du fichier /etc/hosts				##
322
## - Configuration du serveur de temps (NTP)			##
297
## - Configuration du serveur de temps (NTP)			##
323
## - Renseignement des fichiers hosts.allow et hosts.deny	##
298
## - Renseignement des fichiers hosts.allow et hosts.deny	##
324
##################################################################
299
##################################################################
325
network ()
300
network ()
Line 374... Line 349...
374
	private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup`			# last octet of LAN address
349
	private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup`			# last octet of LAN address
375
	private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`			# last octet of LAN broadcast
350
	private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup`			# last octet of LAN broadcast
376
	PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1`		# First network address (ex.: 192.168.182.1)
351
	PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1`		# First network address (ex.: 192.168.182.1)
377
	PRIVATE_SECOND_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 2`	# second network address (ex.: 192.168.182.2)
352
	PRIVATE_SECOND_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 2`	# second network address (ex.: 192.168.182.2)
378
	PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1`	# last network address (ex.: 192.168.182.254)
353
	PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1`	# last network address (ex.: 192.168.182.254)
379
	PRIVATE_MAC=`/sbin/ip link show $INTIF | grep ether | cut -d" " -f6`				# MAC address of INTIF (eth1)
354
	PRIVATE_MAC=`/sbin/ip link show $INTIF | grep ether | cut -d" " -f6`				# MAC address of INTIF
380
# Define Internet parameters
355
# Define Internet parameters
381
	[ -e /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF ] || cp /etc/sysconfig/network-scripts/ifcfg-$EXTIF /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF
356
	[ -e /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF ] || cp /etc/sysconfig/network-scripts/ifcfg-$EXTIF /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF
382
	DNS1=`grep DNS1 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 1er DNS
357
	DNS1=`grep DNS1 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 1er DNS
383
	DNS2=`grep DNS2 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 2ème DNS
358
	DNS2=`grep DNS2 /etc/sysconfig/network-scripts/default-ifcfg-$EXTIF|cut -d"=" -f2` 	# @ip 2ème DNS
384
	DNS1=${DNS1:=208.67.220.220}
359
	DNS1=${DNS1:=208.67.220.220}
Line 409... Line 384...
409
	[ -e /etc/hosts.default ] || cp /etc/hosts /etc/hosts.default
384
	[ -e /etc/hosts.default ] || cp /etc/hosts /etc/hosts.default
410
	cat <<EOF > /etc/hosts
385
	cat <<EOF > /etc/hosts
411
127.0.0.1	localhost
386
127.0.0.1	localhost
412
$PRIVATE_IP	$HOSTNAME.$DOMAIN
387
$PRIVATE_IP	$HOSTNAME.$DOMAIN
413
EOF
388
EOF
414
# Config eth0 (Internet)
389
# Config EXTIF (Internet)
415
	cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
390
	cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
416
DEVICE=$EXTIF
391
DEVICE=$EXTIF
417
BOOTPROTO=static
392
BOOTPROTO=static
418
IPADDR=$PUBLIC_IP
393
IPADDR=$PUBLIC_IP
419
NETMASK=$PUBLIC_NETMASK
394
NETMASK=$PUBLIC_NETMASK
Line 427... Line 402...
427
IPV6TO4INIT=no
402
IPV6TO4INIT=no
428
ACCOUNTING=no
403
ACCOUNTING=no
429
USERCTL=no
404
USERCTL=no
430
MTU=$MTU
405
MTU=$MTU
431
EOF
406
EOF
432
# Config eth1 (consultation LAN) in normal mode
407
# Config INTIF (consultation LAN) in normal mode
433
	cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$INTIF
408
	cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$INTIF
434
DEVICE=$INTIF
409
DEVICE=$INTIF
435
BOOTPROTO=static
410
BOOTPROTO=static
436
ONBOOT=yes
411
ONBOOT=yes
437
NOZEROCONF=yes
412
NOZEROCONF=yes
Line 440... Line 415...
440
IPV6TO4INIT=no
415
IPV6TO4INIT=no
441
ACCOUNTING=no
416
ACCOUNTING=no
442
USERCTL=no
417
USERCTL=no
443
ETHTOOL_OPTS=$ETHTOOL_OPTS
418
ETHTOOL_OPTS=$ETHTOOL_OPTS
444
EOF
419
EOF
445
# Config of eth1 in bypass mode (see "alcasar-bypass.sh")
420
# Config of INTIF in bypass mode (see "alcasar-bypass.sh")
446
	cat <<EOF > /etc/sysconfig/network-scripts/default-ifcfg-$INTIF
421
	cat <<EOF > /etc/sysconfig/network-scripts/default-ifcfg-$INTIF
447
DEVICE=$INTIF
422
DEVICE=$INTIF
448
BOOTPROTO=static
423
BOOTPROTO=static
449
IPADDR=$PRIVATE_IP
424
IPADDR=$PRIVATE_IP
450
NETMASK=$PRIVATE_NETMASK
425
NETMASK=$PRIVATE_NETMASK
Line 903... Line 878...
903
	    	(cd /dev; 
878
	    	(cd /dev; 
904
			mkdir net; 
879
			mkdir net; 
905
			cd net; 
880
			cd net; 
906
			mknod tun c 10 200)
881
			mknod tun c 10 200)
907
		}
882
		}
908
		ifconfig eth1 0.0.0.0
883
		ifconfig $INTIF 0.0.0.0
909
		daemon /usr/sbin/chilli -c \$CONFIG --pidfile=\$pidfile &
884
		daemon /usr/sbin/chilli -c \$CONFIG --pidfile=\$pidfile &
910
        	RETVAL=$?
885
        	RETVAL=$?
911
	fi
886
	fi
912
	;;
887
	;;
913
 
888
 
Line 947... Line 922...
947
# conf file creation
922
# conf file creation
948
	[ -e /etc/chilli.conf.default ] || cp /etc/chilli.conf /etc/chilli.conf.default
923
	[ -e /etc/chilli.conf.default ] || cp /etc/chilli.conf /etc/chilli.conf.default
949
	cat <<EOF > /etc/chilli.conf
924
	cat <<EOF > /etc/chilli.conf
950
# coova config for ALCASAR
925
# coova config for ALCASAR
951
cmdsocket	/var/run/chilli.sock
926
cmdsocket	/var/run/chilli.sock
952
unixipc		chilli.eth1.ipc
927
unixipc		chilli.$INTIF.ipc
953
pidfile		/var/run/chilli.eth1.pid
928
pidfile		/var/run/chilli.$INTIF.pid
954
net		$PRIVATE_NETWORK_MASK
929
net		$PRIVATE_NETWORK_MASK
955
dhcpif		$INTIF
930
dhcpif		$INTIF
956
ethers		$DIR_DEST_ETC/alcasar-ethers
931
ethers		$DIR_DEST_ETC/alcasar-ethers
957
#nodynip
932
#nodynip
958
#statip
933
#statip
Line 981... Line 956...
981
include		$DIR_DEST_ETC/alcasar-uamdomain
956
include		$DIR_DEST_ETC/alcasar-uamdomain
982
#dhcpgateway
957
#dhcpgateway
983
#dhcprelayagent
958
#dhcprelayagent
984
#dhcpgatewayport
959
#dhcpgatewayport
985
EOF
960
EOF
986
# create file for DHCP static ip. Reserve the second IP address for eth1 (the first one is for tun0)
961
# create file for DHCP static ip. Reserve the second IP address for INTIF (the first one is for tun0)
987
	echo "$PRIVATE_MAC $PRIVATE_SECOND_IP" > $DIR_DEST_ETC/alcasar-ethers
962
	echo "$PRIVATE_MAC $PRIVATE_SECOND_IP" > $DIR_DEST_ETC/alcasar-ethers
988
# create files for trusted domains and urls
963
# create files for trusted domains and urls
989
	touch $DIR_DEST_ETC/alcasar-uamallowed $DIR_DEST_ETC/alcasar-uamdomain
964
	touch $DIR_DEST_ETC/alcasar-uamallowed $DIR_DEST_ETC/alcasar-uamdomain
990
	chown root:apache $DIR_DEST_ETC/alcasar-*
965
	chown root:apache $DIR_DEST_ETC/alcasar-*
991
	chmod 660 $DIR_DEST_ETC/alcasar-*
966
	chmod 660 $DIR_DEST_ETC/alcasar-*
Line 1484... Line 1459...
1484
	echo "DNS_FILTERING=off" >> $CONF_FILE
1459
	echo "DNS_FILTERING=off" >> $CONF_FILE
1485
	echo "YOUTUBE_ID=ABCD1234567890abcdef" >> $CONF_FILE
1460
	echo "YOUTUBE_ID=ABCD1234567890abcdef" >> $CONF_FILE
1486
	echo "MULTIWAN=off" >> $CONF_FILE
1461
	echo "MULTIWAN=off" >> $CONF_FILE
1487
	echo "FAILOVER=30" >> $CONF_FILE
1462
	echo "FAILOVER=30" >> $CONF_FILE
1488
	echo "## WANx=active,@IPx/mask,GWx,Weight,MTUx" >> $CONF_FILE
1463
	echo "## WANx=active,@IPx/mask,GWx,Weight,MTUx" >> $CONF_FILE
1489
	echo "#WAN1=\"1,eth0:1,192.168.2.20/24,192.168.2.6,1,1500\"" >> $CONF_FILE
1464
	echo "#WAN1=\"1,$EXTIF:1,192.168.2.20/24,192.168.2.6,1,1500\"" >> $CONF_FILE
1490
	echo "#WAN2=\"1,eth0:2,192.168.3.20/24,192.168.3.1,2,1500\"" >> $CONF_FILE
1465
	echo "#WAN2=\"1,$EXTIF:2,192.168.3.20/24,192.168.3.1,2,1500\"" >> $CONF_FILE
1491
# Coloration des prompts
1466
# Coloration des prompts
1492
	[ -e /etc/bashrc.default ]  || cp /etc/bashrc /etc/bashrc.default
1467
	[ -e /etc/bashrc.default ]  || cp /etc/bashrc /etc/bashrc.default
1493
	cp -f $DIR_CONF/bashrc /etc/. ; chmod 644 /etc/bashrc ; chown root:root /etc/bashrc
1468
	cp -f $DIR_CONF/bashrc /etc/. ; chmod 644 /etc/bashrc ; chown root:root /etc/bashrc
1494
	$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
1469
	$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
1495
# Droits d'exécution pour utilisateur apache et sysadmin
1470
# Droits d'exécution pour utilisateur apache et sysadmin
Line 1739... Line 1714...
1739
		;;
1714
		;;
1740
	-i | --install)
1715
	-i | --install)
1741
		license
1716
		license
1742
		header_install
1717
		header_install
1743
		testing
1718
		testing
1744
# Test if ALCASAR is already installed (before v2.2, the conf file doesn't exist --> can't update)
1719
# Test if ALCASAR is already installed
1745
		if [ -e $CONF_FILE ]
1720
		if [ -e $CONF_FILE ]
1746
		then
1721
		then
1747
			current_version=`cat $CONF_FILE | grep VERSION | cut -d"=" -f2`
1722
			current_version=`cat $CONF_FILE | grep VERSION | cut -d"=" -f2`
1748
			if [ $Lang == "fr" ]
1723
			if [ $Lang == "fr" ]
1749
				then echo -n "La version "; echo -n $current_version ; echo " d'ALCASAR est déjà installée";
1724
				then echo -n "La version "; echo -n $current_version ; echo " d'ALCASAR est déjà installée";
Line 1767... Line 1742...
1767
				$DIR_SCRIPTS/alcasar-conf.sh --create
1742
				$DIR_SCRIPTS/alcasar-conf.sh --create
1768
				mode="update"
1743
				mode="update"
1769
			fi
1744
			fi
1770
		fi
1745
		fi
1771
# RPMs install
1746
# RPMs install
-
 
1747
echo "STOP" ; read a
1772
		$DIR_SCRIPTS/alcasar-urpmi.sh
1748
		$DIR_SCRIPTS/alcasar-urpmi.sh
1773
		if [ "$?" != "0" ]
1749
		if [ "$?" != "0" ]
1774
		then
1750
		then
1775
			exit 0
1751
			exit 0
1776
		fi
1752
		fi