Subversion Repositories ALCASAR

Rev

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

Rev 3110 Rev 3112
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
#  $Id: alcasar.sh 3110 2023-01-11 12:57:01Z rexy $
2
#  $Id: alcasar.sh 3112 2023-01-13 17:13:15Z rexy $
3
 
3
 
4
# ALCASAR is a Free and open source NAC (Network Access Controler) created by Franck BOUIJOUX (3abtux), Pascal LEVANT and Richard REY (Rexy)
4
# ALCASAR is a Free and open source NAC (Network Access Controler) created by Franck BOUIJOUX (3abtux), Pascal LEVANT and Richard REY (Rexy)
5
# ALCASAR is based on a stripped Mageia (LSB) with the following open source softwares Coovachilli, freeradius, mariaDB, lighttpd, php, netfilter, e2guardian, ntpd, openssl, unbound, gammu, clamav, Ulog, fail2ban, vnstat, wkhtml2pdf, ipt_NETFLOW, NFsen and NFdump
5
# ALCASAR is based on a stripped Mageia (LSB) with the following open source softwares Coovachilli, freeradius, mariaDB, lighttpd, php, netfilter, e2guardian, ntpd, openssl, unbound, gammu, clamav, Ulog, fail2ban, vnstat, wkhtml2pdf, ipt_NETFLOW, NFsen and NFdump
6
# contact : info@alcasar.net
6
# contact : info@alcasar.net
7
 
7
 
Line 231... Line 231...
231
########################################################
231
########################################################
232
network_testing()
232
network_testing()
233
{
233
{
234
# Detect external/internal interfaces
234
# Detect external/internal interfaces
235
	if [ -z "$EXTIF" ]; then
235
	if [ -z "$EXTIF" ]; then
236
		EXTIF=$(/usr/sbin/ip route list | awk '/ via / {print $5}' | uniq)
236
		GwListSorted=$(/usr/sbin/ip r list | grep default | cut -d" " -f5 | uniq )
-
 
237
		nb_gw=$(echo $GwListSorted | wc -w)
237
		if [ -z "$EXTIF" ]; then
238
		if [ $nb_gw -eq 0 ]; then
238
			if [ "$Lang" == 'fr' ]
239
			if [ "$Lang" == 'fr' ]
239
				then echo "Aucune passerelle par défaut configurée"
240
				then echo "Aucune passerelle par défaut configurée"
240
				else echo "No default gateway configured"
241
				else echo "No default gateway configured"
241
			fi
242
			fi
242
			exit 1
243
			exit 1
-
 
244
		elif [ $nb_gw -eq 1 ]; then
-
 
245
			EXTIF="$GwListSorted"
-
 
246
		else
-
 
247
			if [ "$Lang" == 'fr' ]
-
 
248
				then echo -n "Erreur : Plusieurs interfaces ont une passerelle par défaut ( "
-
 
249
				else echo -n "Error : Several interfaces have a default gateway ( "
-
 
250
			fi
-
 
251
				echo "$GwListSorted" | tr "\n" " "
-
 
252
				echo ")"
-
 
253
			exit 1
243
		fi
254
		fi
244
	fi
255
	fi
245
	if [ "$Lang" == 'fr' ]
256
	if [ "$Lang" == 'fr' ]
246
		then echo "Interface externe (Internet) utilisée : $EXTIF"
257
		then echo "Interface externe (Internet) utilisée : $EXTIF"
247
		else echo "External interface (Internet) used: $EXTIF"
258
		else echo "External interface (Internet) used: $EXTIF"
248
	fi
259
	fi
249
 
260
 
250
	if [ -z "$INTIF" ]; then
261
	if [ -z "$INTIF" ]; then
251
		interfacesList=$(/usr/sbin/ip -br link show | cut -d' ' -f1 | grep -v "^\(lo\|tun0\|$EXTIF\)\$")
262
		IntifListSorted=$(/usr/sbin/ip -br link show | cut -d' ' -f1 | grep -v "^\(lo\|tun0\|$EXTIF\)\$" | uniq | sort)
252
		interfacesCount=$(echo "$interfacesList" | wc -w)
263
		IntifCount=$(echo "$IntifListSorted" | wc -w)
253
		if [ $interfacesCount -eq 0 ]; then
264
		if [ $IntifCount -eq 0 ]; then
254
			if [ "$Lang" == 'fr' ]
265
			if [ "$Lang" == 'fr' ]
255
				then echo "Aucune interface de disponible pour le réseau interne"
266
				then echo "Aucune interface de disponible pour le réseau interne"
256
				else echo "No interface available for the internal network"
267
				else echo "No interface available for the internal network"
257
			fi
268
			fi
258
			exit 1
269
			exit 1
259
		elif [ $interfacesCount -eq 1 ]; then
270
		elif [ $IntifCount -eq 1 ]; then
260
			INTIF="$interfacesList"
271
			INTIF="$IntifListSorted"
261
		else
272
		else
262
			interfacesSorted=$(/usr/sbin/ip -br addr | grep -v "^\(lo\|tun0\|$EXTIF\) " | sort -b -k3n -k2r -k1)
-
 
263
			interfacePreferred=$(echo "$interfacesSorted" | head -1 | cut -d' ' -f1)
273
			IntifPreferred=$(echo "$IntifListSorted" | head -1 | cut -d' ' -f1)
264
			if [ "$Lang" == 'fr' ]
274
			if [ "$Lang" == 'fr' ]
265
				then echo 'Liste des interfaces disponible :'
275
				then echo 'Liste des interfaces disponibles pour le réseau interne :'
266
				else echo 'List of available interfaces:'
276
				else echo 'List of available interfaces for internal network:'
267
			fi
277
			fi
268
			echo "$interfacesSorted"
278
			echo "$IntifListSorted"
269
			response=''
279
			response=''
270
			while true; do
280
			while true; do
271
				if [ "$Lang" == 'fr' ]
281
				if [ "$Lang" == 'fr' ]
272
					then echo -n "Choix de l'interface interne ? [$interfacePreferred] "
282
					then echo -n "Choix de l'interface interne ? [$IntifPreferred] "
273
					else echo -n "Choice of internal interface ? [$interfacePreferred] "
283
					else echo -n "Choice of internal interface ? [$IntifPreferred] "
274
				fi
284
				fi
275
				read response
285
				read response
276
 
-
 
277
				[ -z "$response" ] && response="$interfacePreferred"
286
				[ -z "$response" ] && response="$IntifPreferred"
278
 
287
 
279
				# Check if interface exist
288
				# Check if interface exist
280
				if [ "$(echo "$interfacesList" | grep -c "^$response\$")" -eq 1 ]; then
289
				if [ "$(echo "$IntifListSorted" | grep -c "^$response\$")" -eq 1 ]; then
281
					INTIF="$response"
290
					INTIF="$response"
282
					break
291
					break
283
				else
292
				else
284
					if [ "$Lang" == 'fr' ]
293
					if [ "$Lang" == 'fr' ]
285
						then echo "Interface \"$response\" introuvable"
294
						then echo "Interface \"$response\" introuvable"