Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2600 → Rev 2601

/CHANGELOG
14,6 → 14,7
 
CHANGES
- Save SMS status and number in ALCASAR configuration file (persistent to updates)..
- Launch Gammu at startup when the SMS service is enabled and check Gammu status in alcasar-daemon.
 
 
BUGS
/alcasar.sh
1787,20 → 1787,25
#########################################################
gammu_smsd()
{
# Create 'gammu' databse
MYSQL="/usr/bin/mysql -uroot -p$mysqlpwd --execute"
$MYSQL="CREATE DATABASE IF NOT EXISTS $DB_GAMMU;GRANT ALL ON $DB_GAMMU.* TO $DB_USER@localhost IDENTIFIED BY '$radiuspwd';FLUSH PRIVILEGES"
# Create 'gammu' system user
groupadd -f gammu_smsd
useradd --system -g gammu_smsd -s /bin/false -c "system user for gammu_smsd" gammu_smsd
usermod -a -G dialout gammu_smsd
 
# Create 'gammu' database
MYSQL="/usr/bin/mysql -uroot -p$mysqlpwd --execute"
$MYSQL="CREATE DATABASE IF NOT EXISTS $DB_GAMMU; GRANT ALL ON $DB_GAMMU.* TO $DB_USER@localhost IDENTIFIED BY '$radiuspwd'; FLUSH PRIVILEGES;"
# Add a gammu database structure
mysql -u$DB_USER -p$radiuspwd $DB_GAMMU < $DIR_CONF/empty-gammu-smsd-db.sql
 
# Config file for the gammu_smsd daemon & gammu (ttyUSB0 as default com port)
cat << EOF > /etc/gammurc
cat << EOF > /etc/gammurc
[gammu]
device = /dev/ttyUSB0
connection = at115200
EOF
 
cat << EOF > /etc/gammu_smsd_conf
cat << EOF > /etc/gammu_smsd_conf
[gammu]
port = /dev/ttyUSB0
connection = at115200
1830,23 → 1835,35
CheckSignal = 1
CheckBattery = 0
EOF
chmod 755 /etc/gammu_smsd_conf /etc/gammurc
 
chmod 755 /etc/gammu_smsd_conf /etc/gammurc
# Create the systemd unit
cat << EOF > /lib/systemd/system/gammu-smsd.service
[Unit]
Description=SMS daemon for Gammu
Documentation=man:gammu-smsd(1)
After=network.target mysql.service
 
[Service]
Type=forking
ExecStart=/usr/bin/gammu-smsd --config /etc/gammu_smsd_conf --user=gammu_smsd --group=gammu_smsd --pid=/var/run/gammu-smsd.pid --daemon
ExecReload=/bin/kill -HUP $MAINPID
ExecStopPost=/bin/rm -f /var/run/gammu-smsd.pid
PIDFile=/var/run/gammu-smsd.pid
 
[Install]
WantedBy=multi-user.target
EOF
 
# Log folder for gammu-smsd
[ -e /var/log/gammu-smsd ] || mkdir /var/log/gammu-smsd
chmod 755 /var/log/gammu-smsd
[ -e /var/log/gammu-smsd ] || mkdir /var/log/gammu-smsd
chmod 755 /var/log/gammu-smsd
 
# Write radius credentials in the gammu script
$SED "s/^u_db=\".*/u_db=\"$DB_USER\"/g" $DIR_DEST_BIN/alcasar-sms.sh
$SED "s/^p_db=\".*/p_db=\"$radiuspwd\"/g" $DIR_DEST_BIN/alcasar-sms.sh
 
# Udev rule for Modeswitch (switch from "mass_storage" mode to "ttyUSB" modem) needed with some Huawei MODEM (idVendor: 12d1)
# normally not needed now since modeswitch is managed by udev (see Mageia RPM)
#cat << EOF > /lib/udev/rules.d/66-huawei.rules
#KERNEL=="ttyUSB0",ATTRS{idVendor}=="12d1",RUN+="$DIR_DEST_BIN/alcasar-sms.sh --mode"
#EOF
 
# Udev rule for fixing the enumeration of ttyUSB port on some MODEM (when they switch randomly the order of their ports at boot time)
# example : http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
 
2027,6 → 2044,7
[Install]
WantedBy=multi-user.target
EOF
/usr/bin/systemctl daemon-reload
# processes launched at boot time (Systemctl)
for i in alcasar-load_balancing mysqld lighttpd php-fpm ntpd iptables dnsmasq dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole radiusd nfsen e2guardian freshclam ulogd-ssh ulogd-traceability ulogd-ext-access chilli fail2ban havp tinyproxy vnstat sshd
do
/scripts/alcasar-daemon.sh
1,4 → 1,4
#!/bin/sh
#!/bin/bash
# $Id$
 
# alcasar-daemon.sh
14,16 → 14,15
LDAP=${LDAP:=off}
INTIF=`grep ^INTIF= $conf_file|cut -d"=" -f2` # INTIF name
EXTIF=`grep ^EXTIF= $conf_file|cut -d"=" -f2` # EXTIF name
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"
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"
nb_available_srv=`echo $SERVICES|wc -w`
 
function ServiceTest () {
CMD=`/usr/bin/systemctl is-active $s`
if [ $CMD != "active" ]
then
logger -t alcasar-daemon -i "$s is inactive. Activation attempt"
echo "the $s service is disabled! trying to start it..."
/usr/bin/systemctl start $s.service
service=$1
if [ $(/usr/bin/systemctl is-active $service) != "active" ]; then
logger -t alcasar-daemon -i "$service is inactive. Activation attempt"
echo "the $service service is disabled! trying to start it..."
/usr/bin/systemctl start $service.service
else
nb_srv=$((nb_srv+1))
fi
39,21 → 38,20
done
 
nb_srv=0
for s in $SERVICES
do
if [ $s != "sshd" ]
then
ServiceTest
else
{
if [ $SSH == "ON" ] || [ $SSH == "on" ] || [ $SSH == "On" ]
then
ServiceTest
else
for service in $SERVICES; do
if [ $service == 'sshd' ]; then
if [ $SSH != "ON" ] && [ $SSH != "on" ] && [ $SSH != "On" ]; then
nb_available_srv=$((nb_available_srv-1))
continue
fi
}
elif [ $service == 'gammu-smsd' ]; then
if [ $(grep '^SMS=' $conf_file | cut -d'=' -f2-) != 'on' ]; then
nb_available_srv=$((nb_available_srv-1))
continue
fi
fi
 
ServiceTest $service
done
 
if [ $nb_available_srv -ne $nb_srv ]
/scripts/alcasar-sms.sh
17,8 → 17,9
time_ban=2
#########################################
####### IDs DB ##########################
u_db="radius"
p_db="password"
PASSWD_FILE="/root/ALCASAR-passwords.txt"
u_db=$(grep '^db_user=' $PASSWD_FILE | cut -d'=' -f2-)
p_db=$(grep '^db_password=' $PASSWD_FILE | cut -d'=' -f2-)
#########################################
#########################################
 
82,15 → 83,17
fi
 
#Start gammu
echo $separator >> $logfile
sudo gammu-smsd --config $config --pid /var/run/gammu-smsd.pid --daemon
echo $separator >> $logfile
/usr/bin/systemctl -q start gammu-smsd.service
/usr/bin/systemctl -q enable gammu-smsd.service
} # end function start_gammu
 
function stop_gammu() {
#Stop gammu
sudo kill -9 gammu-smsd
sleep 10
echo $end >> $logfile
/usr/bin/systemctl -q stop gammu-smsd.service
/usr/bin/systemctl -q disable gammu-smsd.service
sleep 10
echo $end >> $logfile
} # end function stop_gammu
 
function unlock() {