Subversion Repositories ALCASAR

Rev

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

Rev 2558 Rev 2600
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-sms.sh 2558 2018-06-05 21:56:34Z rexy $
2
# $Id: alcasar-sms.sh 2600 2018-08-19 23:48:55Z tom.houdayer $
3
 
3
 
4
# alcasar-sms.sh
4
# alcasar-sms.sh
5
# by Nicolas Aubry & Rexy
5
# by Nicolas Aubry & 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
 
7
 
8
# This script manages the 'gammu-smsd' service when a GSM adapter is detected
8
# This script manages the 'gammu-smsd' service when a GSM adapter is detected
9
# Ce script gère le service 'gammu-smsd' quand un adaptateur GSM est détecté
9
# Ce script gère le service 'gammu-smsd' quand un adaptateur GSM est détecté
10
 
10
 
-
 
11
CONF_FILE='/usr/local/etc/alcasar.conf'
-
 
12
 
11
#########################################
13
#########################################
12
#######	VARIABLES ########
14
#######	VARIABLES ########
13
nb_essais=3
15
nb_essais=3
14
time_account=1
16
time_account=1
15
time_ban=2
17
time_ban=2
Line 33... Line 35...
33
 
35
 
34
config="/etc/gammu_smsd_conf"
36
config="/etc/gammu_smsd_conf"
35
config2="/etc/gammurc"
37
config2="/etc/gammurc"
36
logfile="/var/log/gammu-smsd/gammu-smsd.log"
38
logfile="/var/log/gammu-smsd/gammu-smsd.log"
37
script="/usr/local/bin/alcasar-sms.sh"
39
script="/usr/local/bin/alcasar-sms.sh"
38
public_page="/var/www/html/autoregistrationinfo.php"
-
 
39
index_page="/var/www/html/index.php"
-
 
40
intercept_page="/var/www/html/intercept.php"
-
 
41
separator="########## START ##########"
40
separator="########## START ##########"
42
end="%%%%%%%%%% STOP %%%%%%%%%%"
41
end="%%%%%%%%%% STOP %%%%%%%%%%"
43
 
42
 
44
 
43
 
45
usage="Usage: alcasar-gammu.sh
44
usage="Usage: alcasar-gammu.sh
Line 64... Line 63...
64
 
63
 
65
	/usr/sbin/usb_modeswitch -I -H -v 0x$vendor -p 0x$product -V 0x$vendor -P 0x$product -W -n >> $logfile
64
	/usr/sbin/usb_modeswitch -I -H -v 0x$vendor -p 0x$product -V 0x$vendor -P 0x$product -W -n >> $logfile
66
}
65
}
67
 
66
 
68
function start_gammu() {
67
function start_gammu() {
-
 
68
	# Check phone number is set
-
 
69
	if [ -z "$(grep '^SMS_NUM=' $CONF_FILE | cut -d'=' -f2-)" ]; then
-
 
70
		echo 'The phone number is not set.'
-
 
71
		# exit 2
-
 
72
	fi
-
 
73
 
69
	#On truncate la table phones (informations signal / IMEI / batterie / sms recu et envoyé)
74
	#On truncate la table phones (informations signal / IMEI / batterie / sms recu et envoyé)
70
		sql_trunc_phones="connect gammu; TRUNCATE phones;"
-
 
71
		result=$(mysql --user=$u_db --password=$p_db -B -se "$sql_trunc_phones")
75
	mysql --user=$u_db --password=$p_db --database=gammu -Bs -e 'TRUNCATE phones;'
72
 
76
 
73
 
77
 
74
	#On verifie que le groupe sms est créé
78
	#On verifie que le groupe sms est créé
75
		sql_check_gp="connect radius; SELECT * FROM $radgp WHERE username='sms' AND groupname='sms';"
79
	if [ $(mysql --user=$u_db --password=$p_db --database=radius -Bs -e "SELECT COUNT(*) FROM $radgp WHERE username='sms' AND groupname='sms';") -eq 0 ]; then
76
		result=$(mysql --user=$u_db --password=$p_db -B -se "$sql_check_gp")
-
 
77
 
-
 
78
		if test -z "$result"
-
 
79
		then
-
 
80
			sql_add_gp="connect radius; INSERT INTO $radgp (username,groupname) VALUES ('sms','sms');"
-
 
81
			sql_add_gp_att="connect radius; INSERT INTO $radgpck (groupname,attribute,op,value) VALUES ('sms','Simultaneous-Use',':=',1);"
80
		sql_add_gp="INSERT INTO $radgp (username,groupname) VALUES ('sms','sms'); INSERT INTO $radgpck (groupname,attribute,op,value) VALUES ('sms','Simultaneous-Use',':=',1);"
82
 
-
 
83
			mysql --user=$u_db --password=$p_db -B -se "$sql_add_gp"
81
		mysql --user=$u_db --password=$p_db --database=radius -Bs -e "$sql_add_gp"
84
			mysql --user=$u_db --password=$p_db -B -se "$sql_add_gp_att"
-
 
85
		fi
82
	fi
86
 
83
 
87
	#Start gammu
84
	#Start gammu
88
		echo $separator >> $logfile
85
		echo $separator >> $logfile
89
		sudo gammu-smsd --config $config --pid /var/run/gammu-smsd.pid --daemon
86
		sudo gammu-smsd --config $config --pid /var/run/gammu-smsd.pid --daemon
90
} # end function start_gammu
87
} # end function start_gammu
Line 341... Line 338...
341
		if [ $gammu_pid != "0" ]
338
		if [ $gammu_pid != "0" ]
342
			then
339
			then
343
			echo "gammu is already started"
340
			echo "gammu is already started"
344
		else
341
		else
345
			start_gammu
342
			start_gammu
346
			sed -i "s/\$service_SMS_status = false;/\$service_SMS_status = true;/g" $index_page
-
 
347
			sed -i "s/\$service_SMS_status = false;/\$service_SMS_status = true;/g" $public_page
-
 
348
			sed -i "s/\$service_SMS_status = false;/\$service_SMS_status = true;/g" $intercept_page
-
 
349
		fi
343
		fi
-
 
344
		sed -i "s/^SMS=.*/SMS=on/" $CONF_FILE
350
		exit 0
345
		exit 0
351
		;;
346
		;;
352
	--stop)
347
	--stop)
353
		gammu_pid=`/usr/sbin/pidof gammu-smsd|wc -l`
348
		gammu_pid=`/usr/sbin/pidof gammu-smsd|wc -l`
354
		if [ $gammu_pid != "0" ]
349
		if [ $gammu_pid != "0" ]
355
			then
350
			then
356
			stop_gammu
351
			stop_gammu
357
			sed -i "s/\$service_SMS_status = true;/\$service_SMS_status = false;/g" $index_page
-
 
358
			sed -i "s/\$service_SMS_status = true;/\$service_SMS_status = false;/g" $public_page
-
 
359
			sed -i "s/\$service_SMS_status = true;/\$service_SMS_status = false;/g" $intercept_page
-
 
360
		else
352
		else
361
			echo "gammu is already stopped"
353
			echo "gammu is already stopped"
362
		fi
354
		fi
-
 
355
		sed -i "s/^SMS=.*/SMS=off/" $CONF_FILE
363
		exit 0
356
		exit 0
364
		;;
357
		;;
365
	--pidof)
358
	--pidof)
366
		/sbin/pidof gammu-smsd
359
		/sbin/pidof gammu-smsd
367
		;;
360
		;;
Line 520... Line 513...
520
		mysql --user=$u_db --password=$p_db -B -se "$sql_sms_received"
513
		mysql --user=$u_db --password=$p_db -B -se "$sql_sms_received"
521
		exit 0
514
		exit 0
522
		;;
515
		;;
523
	--numero_alcasar)
516
	--numero_alcasar)
524
		# Récupère le numero de la clé 3g (téléphone)
517
		# Récupère le numero de la clé 3g (téléphone)
525
		grep "\$current_num=" $public_page | head -n 1 | cut -d"'" -f2
518
		grep '^SMS_NUM=' $CONF_FILE | cut -d'=' -f2-
526
		exit 0
519
		exit 0
527
		;;
520
		;;
528
	--replace_numero_alcasar)
521
	--replace_numero_alcasar)
529
		# Edition du numero de la clé 3g (téléphone)
522
		# Edition du numero de la clé 3g (téléphone)
530
		sed -i "s/\$current_num=.*/\$current_num='$2';/g" $public_page
523
		sed -i "s/^SMS_NUM=.*/SMS_NUM=$2/" $CONF_FILE
531
		exit 0
524
		exit 0
532
		;;
525
		;;
533
	--mode)
526
	--mode)
534
		# Mode huawei
527
		# Mode huawei
535
		mode_huawei
528
		mode_huawei