Subversion Repositories ALCASAR

Rev

Rev 2600 | Rev 2615 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 2600 Rev 2601
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
#  $Id: alcasar.sh 2600 2018-08-19 23:48:55Z tom.houdayer $
2
#  $Id: alcasar.sh 2601 2018-08-19 23:58:27Z tom.houdayer $
3
 
3
 
4
# alcasar.sh
4
# alcasar.sh
5
# ALCASAR is a Free and open source NAC created by Franck BOUIJOUX (3abtux), Pascal LEVANT and Richard REY (Rexy)
5
# ALCASAR is a Free and open source NAC created by Franck BOUIJOUX (3abtux), Pascal LEVANT and Richard REY (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
#  team@alcasar.net
7
#  team@alcasar.net
Line 1785... Line 1785...
1785
## - Creating of SMS management database               ##
1785
## - Creating of SMS management database               ##
1786
## - Write the gammu a gammu_smsd conf files           ##
1786
## - Write the gammu a gammu_smsd conf files           ##
1787
#########################################################
1787
#########################################################
1788
gammu_smsd()
1788
gammu_smsd()
1789
{
1789
{
-
 
1790
# Create 'gammu' system user
-
 
1791
	groupadd -f gammu_smsd
-
 
1792
	useradd --system -g gammu_smsd -s /bin/false -c "system user for gammu_smsd" gammu_smsd
-
 
1793
	usermod -a -G dialout gammu_smsd
-
 
1794
 
1790
# Create 'gammu' databse
1795
# Create 'gammu' database
1791
MYSQL="/usr/bin/mysql -uroot -p$mysqlpwd --execute"
1796
	MYSQL="/usr/bin/mysql -uroot -p$mysqlpwd --execute"
1792
	$MYSQL="CREATE DATABASE IF NOT EXISTS $DB_GAMMU;GRANT ALL ON $DB_GAMMU.* TO $DB_USER@localhost IDENTIFIED BY '$radiuspwd';FLUSH PRIVILEGES"
1797
	$MYSQL="CREATE DATABASE IF NOT EXISTS $DB_GAMMU; GRANT ALL ON $DB_GAMMU.* TO $DB_USER@localhost IDENTIFIED BY '$radiuspwd'; FLUSH PRIVILEGES;"
1793
# Add a gammu database structure
1798
# Add a gammu database structure
1794
	mysql -u$DB_USER -p$radiuspwd $DB_GAMMU < $DIR_CONF/empty-gammu-smsd-db.sql
1799
	mysql -u$DB_USER -p$radiuspwd $DB_GAMMU < $DIR_CONF/empty-gammu-smsd-db.sql
1795
 
1800
 
1796
# Config file for the gammu_smsd daemon & gammu (ttyUSB0 as default com port)
1801
# Config file for the gammu_smsd daemon & gammu (ttyUSB0 as default com port)
1797
cat << EOF > /etc/gammurc
1802
	cat << EOF > /etc/gammurc
Line 1828... Line 1833...
1828
 
1833
 
1829
CheckSecurity = 1
1834
CheckSecurity = 1
1830
CheckSignal = 1
1835
CheckSignal = 1
1831
CheckBattery = 0
1836
CheckBattery = 0
1832
EOF
1837
EOF
1833
 
-
 
1834
chmod 755 /etc/gammu_smsd_conf /etc/gammurc
1838
	chmod 755 /etc/gammu_smsd_conf /etc/gammurc
1835
 
1839
 
-
 
1840
# Create the systemd unit
-
 
1841
	cat << EOF > /lib/systemd/system/gammu-smsd.service
-
 
1842
[Unit]
-
 
1843
Description=SMS daemon for Gammu
-
 
1844
Documentation=man:gammu-smsd(1)
-
 
1845
After=network.target mysql.service
-
 
1846
 
-
 
1847
[Service]
-
 
1848
Type=forking
-
 
1849
ExecStart=/usr/bin/gammu-smsd --config /etc/gammu_smsd_conf --user=gammu_smsd --group=gammu_smsd --pid=/var/run/gammu-smsd.pid --daemon
-
 
1850
ExecReload=/bin/kill -HUP $MAINPID
-
 
1851
ExecStopPost=/bin/rm -f /var/run/gammu-smsd.pid
-
 
1852
PIDFile=/var/run/gammu-smsd.pid
-
 
1853
 
-
 
1854
[Install]
-
 
1855
WantedBy=multi-user.target
-
 
1856
EOF
-
 
1857
 
1836
# Log folder for gammu-smsd
1858
# Log folder for gammu-smsd
1837
[ -e /var/log/gammu-smsd ] || mkdir /var/log/gammu-smsd
1859
	[ -e /var/log/gammu-smsd ] || mkdir /var/log/gammu-smsd
1838
chmod 755 /var/log/gammu-smsd
1860
	chmod 755 /var/log/gammu-smsd
1839
 
1861
 
1840
# Write radius credentials in the gammu script
-
 
1841
$SED "s/^u_db=\".*/u_db=\"$DB_USER\"/g" $DIR_DEST_BIN/alcasar-sms.sh
-
 
1842
$SED "s/^p_db=\".*/p_db=\"$radiuspwd\"/g" $DIR_DEST_BIN/alcasar-sms.sh
-
 
1843
 
-
 
1844
# Udev rule for Modeswitch (switch from "mass_storage" mode to "ttyUSB" modem) needed with some Huawei MODEM (idVendor: 12d1)
1862
# Udev rule for Modeswitch (switch from "mass_storage" mode to "ttyUSB" modem) needed with some Huawei MODEM (idVendor: 12d1)
1845
# normally not needed now since modeswitch is managed by udev (see Mageia RPM)
1863
# normally not needed now since modeswitch is managed by udev (see Mageia RPM)
1846
#cat << EOF > /lib/udev/rules.d/66-huawei.rules
1864
#cat << EOF > /lib/udev/rules.d/66-huawei.rules
1847
#KERNEL=="ttyUSB0",ATTRS{idVendor}=="12d1",RUN+="$DIR_DEST_BIN/alcasar-sms.sh --mode"
1865
#KERNEL=="ttyUSB0",ATTRS{idVendor}=="12d1",RUN+="$DIR_DEST_BIN/alcasar-sms.sh --mode"
1848
#EOF
1866
#EOF
1849
 
-
 
1850
# Udev rule for fixing the enumeration of ttyUSB port on some MODEM (when they switch randomly the order of their ports at boot time)
1867
# Udev rule for fixing the enumeration of ttyUSB port on some MODEM (when they switch randomly the order of their ports at boot time)
1851
# example : http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
1868
# example : http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
1852
 
1869
 
1853
} # End gammu_smsd()
1870
} # End gammu_smsd()
1854
 
1871
 
Line 2025... Line 2042...
2025
SysVStartPriority=99
2042
SysVStartPriority=99
2026
 
2043
 
2027
[Install]
2044
[Install]
2028
WantedBy=multi-user.target
2045
WantedBy=multi-user.target
2029
EOF
2046
EOF
-
 
2047
	/usr/bin/systemctl daemon-reload
2030
# processes launched at boot time (Systemctl)
2048
# processes launched at boot time (Systemctl)
2031
	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
2049
	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
2032
	do
2050
	do
2033
		/usr/bin/systemctl -q enable $i.service
2051
		/usr/bin/systemctl -q enable $i.service
2034
	done
2052
	done