Subversion Repositories ALCASAR

Rev

Rev 2601 | Rev 2764 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2601 Rev 2620
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-daemon.sh 2601 2018-08-19 23:58:27Z tom.houdayer $
2
# $Id: alcasar-daemon.sh 2620 2018-08-23 22:35:52Z rexy $
3
 
3
 
4
# alcasar-daemon.sh
4
# alcasar-daemon.sh
5
# by Franck BOUIJOUX & Rexy
5
# by Franck BOUIJOUX & 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
# Watchdog of Services
7
# Watchdog of Services
8
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
8
# See /etc/cron.d/alcasar-daemon-watchdog for config the time
9
 
9
 
10
conf_file="/usr/local/etc/alcasar.conf"
10
conf_file="/usr/local/etc/alcasar.conf"
11
SSH=`grep ^SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
11
SSH=`grep ^SSH= $conf_file|cut -d"=" -f2`				# sshd active (on/off)
12
SSH=${SSH:=off}
12
SSH=${SSH:=off}
-
 
13
SMS=`grep ^SMS= $conf_file|cut -d"=" -f2`				# SMS active (on/off)
-
 
14
SMS=${SMS:=off}
13
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
15
LDAP=`grep ^LDAP= $conf_file|cut -d"=" -f2`				# ldap active (on/off)
14
LDAP=${LDAP:=off}
16
LDAP=${LDAP:=off}
15
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
17
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2`				# INTIF name
16
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
18
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2`				# EXTIF name
17
SERVICES="mysqld lighttpd php-fpm ntpd havp dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd tinyproxy nfsen e2guardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
19
SERVICES="mysqld lighttpd php-fpm ntpd havp dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd tinyproxy nfsen e2guardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban sshd vnstat gammu-smsd"
18
nb_available_srv=`echo $SERVICES|wc -w`
20
nb_available_srv=`echo $SERVICES|wc -w`
19
 
21
 
20
function ServiceTest () {
22
function ServiceTest () {
21
	service=$1
23
	service=$1
22
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
24
	if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
23
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
25
		logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
24
		echo "the $service service is disabled! trying to start it..."
26
		echo "the $service service is disabled! trying to start it..."
25
		/usr/bin/systemctl start $service.service
27
		/usr/bin/systemctl start $service.service
26
	else
28
	else
27
		nb_srv=$((nb_srv+1))
29
		nb_srv=$((nb_srv+1))
28
	fi
30
	fi
29
}
31
}
30
 
32
 
31
for NIC in $EXTIF $INTIF
33
for NIC in $EXTIF $INTIF
32
do
34
do
33
	if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]
35
	if [ `/usr/sbin/ip a show $NIC|grep DOWN|wc -l` -eq "1" ]
34
	then
36
	then
35
		echo "The network interface card '$NIC' is down! Try to enable it"
37
		echo "The network interface card '$NIC' is down! Try to enable it"
36
		/usr/sbin/ifup $NIC
38
		/usr/sbin/ifup $NIC
37
	fi
39
	fi
38
done
40
done
39
 
41
 
40
nb_srv=0
42
nb_srv=0
41
for service in $SERVICES; do
43
for service in $SERVICES; do
42
	if [ $service == 'sshd' ]; then
44
	if [ $service == 'sshd' ]; then
43
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
45
		if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
44
			nb_available_srv=$((nb_available_srv-1))
46
			nb_available_srv=$((nb_available_srv-1))
45
			continue
47
			continue
46
		fi
48
		fi
47
	elif [ $service == 'gammu-smsd' ]; then
49
	elif [ $service == 'gammu-smsd' ]; then
48
		if [ $(grep '^SMS=' $conf_file | cut -d'=' -f2-) != 'on' ]; then
50
		if [ $SMS != "ON" ] && [ $SMS != "on" ] && [ $SMS != "On" ]; then
49
			nb_available_srv=$((nb_available_srv-1))
51
			nb_available_srv=$((nb_available_srv-1))
50
			continue
52
			continue
51
		fi
53
		fi
52
	fi
54
	fi
53
 
-
 
54
	ServiceTest $service
55
	ServiceTest $service
55
done
56
done
56
 
57
 
57
if [ $nb_available_srv -ne $nb_srv ]
58
if [ $nb_available_srv -ne $nb_srv ]
58
then
59
then
59
	echo "Restart this script to know if all is ok"
60
	echo "Restart this script to know if all is ok"
60
else
61
else
61
	echo "$nb_srv services needed by ALCASAR are started."
62
	echo "$nb_srv services needed by ALCASAR are started."
62
fi
63
fi
63
 
64
 
64
if [ `lsmod|grep ipt_NETFLOW|wc -l` == 0 ]
65
if [ `lsmod|grep ipt_NETFLOW|wc -l` == 0 ]
65
then
66
then
66
	logger -t alcasar-daemon -i "ipt_netflow is inactive."
67
	logger -t alcasar-daemon -i "ipt_netflow is inactive."
67
	echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
68
	echo "The Log system is disabled! try to know why (modprobe ipt_NETFLOW)"
68
else
69
else
69
	echo "The Log system is active"
70
	echo "The Log system is active"
70
fi
71
fi
71
if [ ! -e /etc/raddb/mods-enabled/ldap ]
72
if [ ! -e /etc/raddb/mods-enabled/ldap ]
72
then
73
then
73
	if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]
74
	if [ $LDAP == "ON" ] || [ $LDAP == "on" ] || [ $LDAP == "On" ]
74
	then
75
	then
75
	echo "Enable LDAP..."
76
	echo "Enable LDAP..."
76
	/usr/local/bin/alcasar-ldap.sh -on
77
	/usr/local/bin/alcasar-ldap.sh -on
77
	fi
78
	fi
78
fi
79
fi
79
 
80
 
80
 
81