Subversion Repositories ALCASAR

Rev

Rev 2631 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1349 richard 1
#!/bin/bash
2250 tom.houday 2
# $Id: alcasar-sms.sh 2875 2020-11-01 10:50:57Z rexy $
1502 richard 3
 
4
# alcasar-sms.sh
5
# by Nicolas Aubry & Rexy
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
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é
10
 
2600 tom.houday 11
CONF_FILE='/usr/local/etc/alcasar.conf'
12
 
1502 richard 13
#######	VARIABLES ########
1452 richard 14
nb_essais=3
1349 richard 15
time_account=1
1452 richard 16
time_ban=2
1349 richard 17
####### IDs DB ##########################
2601 tom.houday 18
PASSWD_FILE="/root/ALCASAR-passwords.txt"
19
u_db=$(grep '^db_user='     $PASSWD_FILE | cut -d'=' -f2-)
20
p_db=$(grep '^db_password=' $PASSWD_FILE | cut -d'=' -f2-)
1349 richard 21
#########################################
22
 
23
rad="radcheck"
24
radgp="radusergroup"
25
radgpck="radgroupcheck"
26
radinf="userinfo"
27
sms_p="SMS_ban_perm"
28
sms_t="SMS_ban_temp"
29
inb="inbox"
1416 richard 30
SMS_c="SMS_country"
1349 richard 31
config="/etc/gammu_smsd_conf"
2553 rexy 32
config2="/etc/gammurc"
1349 richard 33
logfile="/var/log/gammu-smsd/gammu-smsd.log"
34
script="/usr/local/bin/alcasar-sms.sh"
35
separator="########## START ##########"
36
end="%%%%%%%%%% STOP %%%%%%%%%%"
37
 
2454 tom.houday 38
usage="Usage: alcasar-gammu.sh
1349 richard 39
Start Gammu-smsd   : --start
2454 tom.houday 40
Stop Gammu-smsd    : --stop
1349 richard 41
Process on new sms : --new_sms"
42
 
43
nb_args=$#
44
args=$1
45
 
46
# Functions
1380 richard 47
function mode_huawei() {
48
	couple=$(lsusb | grep -i huawei | cut -d ' ' -f6)
49
	vendor=$(echo $couple | cut -d ':' -f1)
50
	product=$(echo $couple | cut -d ':' -f2)
2294 richard 51
	echo "******** Modeswitch *************" >> $logfile
52
	echo $vendor >> $logfile
53
	echo $product >> $logfile
54
	/usr/sbin/usb_modeswitch -I -H -v 0x$vendor -p 0x$product -V 0x$vendor -P 0x$product -W -n >> $logfile
2875 rexy 55
} # end function mode_huawei
1380 richard 56
 
1349 richard 57
function start_gammu() {
2875 rexy 58
	# Truncate phones table (informations signal/IMEI/battery/sent et reveived sms)
2600 tom.houday 59
	mysql --user=$u_db --password=$p_db --database=gammu -Bs -e 'TRUNCATE phones;'
2875 rexy 60
	# Verify the sms group is created
2600 tom.houday 61
	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
62
		sql_add_gp="INSERT INTO $radgp (username,groupname) VALUES ('sms','sms'); INSERT INTO $radgpck (groupname,attribute,op,value) VALUES ('sms','Simultaneous-Use',':=',1);"
63
		mysql --user=$u_db --password=$p_db --database=radius -Bs -e "$sql_add_gp"
64
	fi
2875 rexy 65
	# Start gammu
2601 tom.houday 66
	echo $separator >> $logfile
67
	/usr/bin/systemctl -q start gammu-smsd.service
68
	/usr/bin/systemctl -q enable gammu-smsd.service
1349 richard 69
} # end function start_gammu
70
 
71
function stop_gammu() {
2601 tom.houday 72
	/usr/bin/systemctl -q stop gammu-smsd.service
73
	/usr/bin/systemctl -q disable gammu-smsd.service
74
	echo $end >> $logfile
1349 richard 75
} # end function stop_gammu
76
 
77
function unlock() {
2875 rexy 78
	# Remove phone number in SMS_ban_perm table
1349 richard 79
		sql_remove_ban_perm="connect gammu; DELETE FROM $sms_p"
80
		mysql --user=$u_db --password=$p_db -B -se "$sql_remove_ban_perm WHERE SenderNumber=$1;"
2875 rexy 81
	# Add sms group
1349 richard 82
		sql_remove_gp="connect radius; DELETE FROM $radgp WHERE username='$1';"
83
		mysql --user=$u_db --password=$p_db -B -se "$sql_remove_gp"
2875 rexy 84
	# Remove account in Radcheck table
1349 richard 85
		sql_remove_compte="connect radius; DELETE FROM $rad WHERE username='$1';"
86
		mysql --user=$u_db --password=$p_db -B -se "$sql_remove_compte"
1387 richard 87
} # end function unlock
88
 
1416 richard 89
function change_country() {
90
		sql_status_country="connect gammu; SELECT status FROM SMS_country WHERE name='$1'"
91
		stat=$(mysql --user=$u_db --password=$p_db -B -se "$sql_status_country")
92
		if [ $stat -eq 0 ]
93
		then
94
			sql_change_country="connect gammu; UPDATE $SMS_c SET status=1 WHERE name='$1'"
95
			mysql --user=$u_db --password=$p_db -B -se "$sql_change_country"
96
		else
97
			sql_change_country="connect gammu; UPDATE $SMS_c SET status=0 WHERE name='$1'"
98
			mysql --user=$u_db --password=$p_db -B -se "$sql_change_country"
99
		fi
100
} # end change_country
101
 
1387 richard 102
function supp_acc_rad() {
2875 rexy 103
	# Remove account in Radcheck table
1387 richard 104
		sql_del_compte="connect radius; DELETE FROM $rad WHERE username='$1';"
105
		mysql --user=$u_db --password=$p_db -B -se "$sql_del_compte"
106
} # end function supp_acc_rad()
107
 
108
function add_acc_rad() {
2875 rexy 109
	# Add accoubt in RadCheck table
1387 richard 110
		sql_add_pass="connect radius; INSERT INTO $rad (username,attribute,op,value) VALUES ('$1','Crypt-Password',':=','$2');"
111
		sql_add_expe="connect radius; INSERT INTO $rad (username,attribute,op,value) VALUES ('$1','Expiration',':=','$3');"
112
		mysql --user=$u_db --password=$p_db -B -se "$sql_add_pass"
113
		mysql --user=$u_db --password=$p_db -B -se "$sql_add_expe"
2875 rexy 114
	# Add this account to sms group
1387 richard 115
		sql_add_gp="connect radius; INSERT INTO $radgp (username,groupname) VALUES ('$1','sms');"
116
		mysql --user=$u_db --password=$p_db -B -se "$sql_add_gp"
117
} # end function add_acc_rad()
2454 tom.houday 118
 
1387 richard 119
function supp_num_temp() {
2875 rexy 120
	# Remove phone number in SMS_ban_temp table
1387 richard 121
		sql_remove_ban_temp="connect gammu; DELETE FROM $sms_t"
122
		mysql --user=$u_db --password=$p_db -B -se "$sql_remove_ban_temp WHERE SenderNumber=$1;"
123
} # end function supp_num_temp()
2454 tom.houday 124
 
1387 richard 125
function add_num_perm() {
2875 rexy 126
	# Add phone number in SMS_ban_perm table
1387 richard 127
		sql_add_ban_perm="connect gammu; INSERT INTO $sms_p (SenderNumber,Perm,Expiration) VALUES ('$1',0,'$2');"
128
		mysql --user=$u_db --password=$p_db -B -se "$sql_add_ban_perm"
129
} # end function add_num_perm()
1349 richard 130
 
1387 richard 131
function supp_num_perm() {
2875 rexy 132
	# Remove phone number in SMS_ban_perm table
1387 richard 133
		sql_remove_ban_perm="connect gammu; DELETE FROM $sms_p"
134
		mysql --user=$u_db --password=$p_db -B -se "$sql_remove_ban_perm WHERE SenderNumber=$1;"
135
} # end function add_num_perm()
136
 
1349 richard 137
function new_sms() {
138
	# Check Inbox table, manage Ban temp and perm, create account
2631 rexy 139
		export salt='$5$passwd$'
1349 richard 140
		sql_select_inbox="connect gammu; SELECT ID, SenderNumber, TextDecoded FROM $inb;"
141
		sql_delete_inbox="connect gammu; DELETE FROM $inb"
142
		mysql --user=$u_db --password=$p_db -B -se "$sql_select_inbox" | while read result;
143
		do
2875 rexy 144
		# Retrieve the number of words (result)
1349 richard 145
			nb=$(echo $result | wc -w)
2875 rexy 146
		# Retrive the ID
147
			id=$(echo $result | cut -d ' ' -f1)
148
			numero=$(echo $result | cut -d ' ' -f2)
149
			if [[ $numero =~ ^\+ ]]
150
			then
151
			# Check if country is blocked
1416 richard 152
				sql_select_countries="connect gammu; SELECT id FROM $SMS_c WHERE status=1"
153
				mysql --user=$u_db --password=$p_db -B -se "$sql_select_countries" | while read result_c;
154
				do
2875 rexy 155
					if [[ $numero =~ ^"$result_c" ]]
1416 richard 156
					then
2875 rexy 157
						numero=$(echo $numero | cut -d '+' -f2)
158
				# Check if GSM number is nabbed
159
						sql_ban_perm="connect gammu; SELECT * FROM $sms_p WHERE SenderNumber=$numero"
160
						result_bp=$(mysql --user=$u_db --password=$p_db -B -se "$sql_ban_perm")
161
						if test -z "$result_bp"
1416 richard 162
						then
2875 rexy 163
						# Test the number of word (result)
164
							if [ $nb -eq 2 ] # if only 2 words : lack of password
165
							then
166
							# Add "1" in bans_temp table // NO PASSWORD
1416 richard 167
								sql_add_temp="connect gammu; INSERT INTO $sms_t(SenderNumber) VALUES ('$numero');"
168
								mysql --user=$u_db --password=$p_db -B -se "$sql_add_temp"
2875 rexy 169
							elif [ $nb -eq 3 ] # if 3 words (id + password + phone numbere)
170
							then
171
								export pass=$(echo $result | cut -d ' ' -f3)
172
								pass_salt=$(perl -e'print crypt($ARGV[0],$ARGV[1])' $pass $salt)
173
								export LC_TIME="en_US.UTF-8"
174
								expir=$(date '+%d %B %Y' -d "$time_account days")
175
								supp_acc_rad "$numero"
176
								add_acc_rad "$numero" "$pass_salt" "$expir"
177
								supp_num_temp "$numero"
178
								add_num_perm "$numero" "$expir"
179
							else # more then 3 words --> Add "1" in ban_temp table
180
								sql_add_temp="connect gammu; INSERT INTO $sms_t(SenderNumber) VALUES ('$numero');"
181
								mysql --user=$u_db --password=$p_db -B -se "$sql_add_temp"
182
							fi
183
							# manage ban perm
1416 richard 184
							sql_select_temp="connect gammu; SELECT ID FROM $sms_t WHERE SenderNumber='$numero'"
185
							r_select_temp=$(mysql --user=$u_db --password=$p_db -B -se "$sql_select_temp")
186
							nb_ban_t=$(echo $r_select_temp| wc -w)
2875 rexy 187
							if [ $nb_ban_t -ge $nb_essais ]
188
							then
189
								supp_num_temp "$numero"
1416 richard 190
								export LC_TIME="en_US.UTF-8"
191
								expir_f=$(date '+%d %B %Y' -d "$time_ban days")
2875 rexy 192
							# Add "1" in SMS_ban_perm table : flood
1416 richard 193
								sql_add_ban_perm="connect gammu; INSERT INTO $sms_p (SenderNumber,Perm,Expiration) VALUES ('$numero',1,'$expir_f');"
194
								mysql --user=$u_db --password=$p_db -B -se "$sql_add_ban_perm"
2875 rexy 195
							fi
196
						else
197
							date_expiration=$(echo $result_bp | cut -d ' ' -f2,3,4)
198
							perm=$(echo $result_bp | cut -d ' ' -f5)
199
							export LC_TIME="en_US.UTF-8"
200
							date_script=$(date '+%d %B %Y' -d "now")
201
							# convert in seconds in order to be able to compare
202
							d_exp=$(date --date "$date_expiration" +%s)
203
							d_scr=$(date --date "$date_script" +%s)
204
							if test $d_scr -ge $d_exp		# Si le ban à expiré
1416 richard 205
							then
2875 rexy 206
							# Test the number of words (result)
207
								if [ $nb -eq 2 ]	# Si 2 mots : le mot de passe est manquant
208
								then
209
								# Add "1" in ban temp table
1416 richard 210
								sql_add_temp="connect gammu; INSERT INTO $sms_t(SenderNumber) VALUES ('$numero');"
211
								mysql --user=$u_db --password=$p_db -B -se "$sql_add_temp"
2875 rexy 212
								elif [ $nb -eq 3 ]	# Si 3 mots : id + mot de passe + numero
213
									then
214
									date_expiration=$(echo $result_bp | cut -d ' ' -f2,3,4)
215
									perm=$(echo $result_bp | cut -d ' ' -f5)
216
									date_script=$(date '+%d %B %Y' -d "now")
217
									# convert in seconds in order to be able to compare
218
									d_exp=$(date --date "$date_expiration" +%s)
219
									d_scr=$(date --date "$date_script" +%s)
220
									export pass=$(echo $result | cut -d ' ' -f3)
221
									pass_salt=$(perl -e'print crypt($ARGV[0],$ARGV[1])' $pass $salt)
222
									export LC_TIME="en_US.UTF-8"
223
									expir=$(date '+%d %B %Y' -d "$time_account days")
224
									supp_acc_rad "$numero"
225
									add_acc_rad "$numero" "$pass_salt" "$expir"
226
									supp_num_temp "$numero"
227
									supp_num_perm "$numero"
228
									add_num_perm "$numero" "$expir"
229
								else
230
								# number of words to big (> 3)
231
								# Add "1" in bans temp table
1416 richard 232
									sql_add_temp="connect gammu; INSERT INTO $sms_t(SenderNumber) VALUES ('$numero');"
233
									mysql --user=$u_db --password=$p_db -B -se "$sql_add_temp"
234
									echo "Mot de passe incorrect, ajout du numero en ban temporaire"
2875 rexy 235
								fi
236
							# manage bans_temp & ban_perm
1416 richard 237
								sql_select_temp="connect gammu; SELECT ID FROM $sms_t WHERE SenderNumber='$numero'"
238
								r_select_temp=$(mysql --user=$u_db --password=$p_db -B -se "$sql_select_temp")
239
								nb_ban_t=$(echo $r_select_temp| wc -w)
2875 rexy 240
								if [ $nb_ban_t -ge $nb_essais ]
241
								then
242
									supp_num_perm "$numero"
243
									supp_num_temp "$numero"
1416 richard 244
									export LC_TIME="en_US.UTF-8"
245
									expir_f=$(date '+%d %B %Y' -d "$time_ban days")
2875 rexy 246
									# Add phne number in ban_perm : flood
247
									sql_add_ban_perm="connect gammu; INSERT INTO $sms_p (SenderNumber,Perm,Expiration) VALUES ('$numero',1,'$expir_f');"
248
									mysql --user=$u_db --password=$p_db -B -se "$sql_add_ban_perm"
249
								fi
250
							else
251
									echo "Le ban de $numero est encore valide"
1416 richard 252
							fi
2875 rexy 253
						break
2454 tom.houday 254
						fi
2875 rexy 255
					#else
256
					#echo "Pays bloqué"
1349 richard 257
					fi
2875 rexy 258
				done
259
			else
260
				echo "Numero non autorisé (ex: 36665)"
261
			fi
262
			# On supprime la ligne d'ID=$id dans inbox
263
			mysql --user=$u_db --password=$p_db -B -e "$sql_delete_inbox WHERE ID=$id;"
1349 richard 264
		done
265
} # end function new_sms
266
 
267
 
268
# CORE
269
case $args in
270
	-h | --help)
271
		echo "$usage"
272
		exit 0
273
		;;
274
	--start)
2875 rexy 275
		failed="0"
276
		comports=`ls -l /dev/ttyUSB* 2>/dev/null | wc -l`
277
		if [ $comports == "0" ]
278
		then
279
			echo "No GSM modem found."
280
			failed="1"
281
		fi	
282
		if [ -z "$(grep '^SMS_NUM=' $CONF_FILE | cut -d'=' -f2-)" ]; then
283
			echo 'The phone number is not set.'
284
			failed="1"
285
		fi
286
		if [ $failed == "1" ]
287
		then
288
			sed -i "s/^SMS=.*/SMS=off/" $CONF_FILE
289
			exit 0
290
		fi
1502 richard 291
		gammu_pid=`/usr/sbin/pidof gammu-smsd|wc -l`
1670 richard 292
		if [ $gammu_pid != "0" ]
2875 rexy 293
		then
294
			echo "Gammu is already started"
1670 richard 295
		else
296
			start_gammu
2875 rexy 297
			sleep 1
298
			is_active=`systemctl is-active gammu-smsd`
299
			if [ $is_active == "active" ]
300
			then
301
				sed -i "s/^SMS=.*/SMS=on/" $CONF_FILE
302
			else
303
				sed -i "s/^SMS=.*/SMS=off/" $CONF_FILE
304
			fi
1670 richard 305
		fi
306
		exit 0
307
		;;
308
	--stop)
309
		gammu_pid=`/usr/sbin/pidof gammu-smsd|wc -l`
310
		if [ $gammu_pid != "0" ]
2875 rexy 311
		then
1670 richard 312
			stop_gammu
313
		else
2875 rexy 314
			echo "Gammu is already stopped"
1670 richard 315
		fi
2600 tom.houday 316
		sed -i "s/^SMS=.*/SMS=off/" $CONF_FILE
2454 tom.houday 317
		exit 0
1670 richard 318
		;;
1452 richard 319
	--pidof)
320
		/sbin/pidof gammu-smsd
321
		;;
1349 richard 322
	--last_nosim)
323
		# Récupère la dernière ligne où NOSIM est présent (error)
324
		cat $logfile | grep -n "NOSIM" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 325
		exit 0
1349 richard 326
		;;
327
	--last_start)
328
		# Récupère la dernière ligne où ########## est présent (séparateur)
329
		cat $logfile | grep -n "##########" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 330
		exit 0
1349 richard 331
		;;
332
	--last_stop)
333
		# Récupère la dernière ligne où %%%%%%%%%% est présent (séparateur)
334
		cat $logfile | grep -n "%%%%%%%%%%" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 335
		exit 0
1349 richard 336
		;;
337
	--last_writeerror)
2558 rexy 338
		#Récupère la dernière ligne où DEVICEWRITEERROR est présent (error)
1349 richard 339
		cat $logfile | grep -n "DEVICEWRITEERROR" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 340
		exit 0
1349 richard 341
		;;
342
	--last_timeout)
2558 rexy 343
		# Récupère la dernière ligne où TIMEOUT est présent (error)
1349 richard 344
		cat $logfile | grep -n "TIMEOUT" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 345
		exit 0
1349 richard 346
		;;
347
	--last_secu)
348
		# Récupère la dernière ligne où SECURITYERROR est présent (error)
349
		cat $logfile | grep -n "SECURITYERROR" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 350
		exit 0
1349 richard 351
		;;
352
	--last_puk)
353
		# Récupère la dernière ligne où PUK est présent (error)
354
		cat $logfile | grep -n "UNKNOWN" | cut -d ':' -f1 | tail -n 1
2454 tom.houday 355
		exit 0
1349 richard 356
		;;
1387 richard 357
	#--log)
358
	#	# Récupère le nom du fichier de log
359
	#	cat $config | grep logfile | cut -d ' ' -f3
2454 tom.houday 360
	#	exit 0
1387 richard 361
	#	;;
2557 rexy 362
	--connect)
363
		# display the com port speed
364
		cat $config | grep connection | cut -d ' ' -f3
2454 tom.houday 365
		exit 0
1380 richard 366
		;;
2557 rexy 367
	--replace_port)
368
		# modify the com port
369
		echo $2
370
		sed -i "s?^port = .*?port = $2?g" $config
371
		sed -i "0,/^device =/ s?device =.*?device = $2?" $config2
372
		exit 0
373
		;;
2553 rexy 374
	--replace_speed)
2557 rexy 375
		# modufy the com port speed
1452 richard 376
		sed -i "s/^connection = at.*/connection = at$2/g" $config
2557 rexy 377
		sed -i "0,/^connection =/ s/connection =.*/connection = $2/" $config2
2454 tom.houday 378
		exit 0
1380 richard 379
		;;
1349 richard 380
	--pin)
381
		# Récupère le code PIN (file de conf)
2557 rexy 382
		cat $config | grep PIN | cut -d ' ' -f3
2454 tom.houday 383
		exit 0
1349 richard 384
		;;
385
	--replace_pin)
386
		# Edition du code PIN
1452 richard 387
		sed -i "s/^PIN =.*/PIN = $2/g" $config
2454 tom.houday 388
		exit 0
1349 richard 389
		;;
390
	--try_ban)
391
		# Récupère le nombre d'essais avant le ban perm
392
		grep nb_essais= $script | head -n 1 | cut -d '=' -f2
2454 tom.houday 393
		exit 0
1349 richard 394
		;;
395
	--replace_try_ban)
396
		# Edition le nombre d'essais avant le ban perm
1452 richard 397
		sed -i "s/^nb_essais=.*/nb_essais=$2/g" $script
2454 tom.houday 398
		exit 0
1349 richard 399
		;;
400
	--time_account)
401
		# Récupère la durée en jours de la session créée
402
		grep time_account= $script | head -n 1 | cut -d '=' -f2
2454 tom.houday 403
		exit 0
1349 richard 404
		;;
405
	--replace_time_account)
406
		# Edition de la durée de la session créée
1452 richard 407
		sed -i "s/^time_account=.*/time_account=$2/g" $script
2454 tom.houday 408
		exit 0
1349 richard 409
		;;
410
	--time_perm)
411
		# Récupère la durée un jours d'un ban perm (après flood par exemple)
412
		grep time_ban= $script | head -n 1 | cut -d '=' -f2
2454 tom.houday 413
		exit 0
1349 richard 414
		;;
415
	--replace_time_perm)
416
		# Edition de la durée d'un ban perm
1452 richard 417
		sed -i "s/^time_ban=.*/time_ban=$2/g" $script
2454 tom.houday 418
		exit 0
1349 richard 419
		;;
420
	--unlock_num)
421
		# Appel de la fonction unlock : deban un numero $2
422
		unlock "$2"
2454 tom.houday 423
		exit 0
1349 richard 424
		;;
1416 richard 425
	--change_country)
426
		# Permet de changer l'état de blocage d'un pays
427
		a=""
428
		for i in "$@"
2454 tom.houday 429
		do
1416 richard 430
			a=$(echo "$a $i")
431
		done
432
		a=$(echo $a | cut -d ' ' -f2-$#)
433
		change_country "$a"
434
		exit
435
		;;
436
	--change_country_ena_all)
437
		# Active l'ensemble des pays
438
		sql_change_country="connect gammu; UPDATE $SMS_c SET status=1"
439
		mysql --user=$u_db --password=$p_db -B -se "$sql_change_country"
440
		exit
441
		;;
442
	--change_country_dis_all)
443
		# Desactive l'ensemble des pays
444
		sql_change_country="connect gammu; UPDATE $SMS_c SET status=0"
445
		mysql --user=$u_db --password=$p_db -B -se "$sql_change_country"
446
		exit
447
		;;
448
	--change_country_filter)
449
		# Change la valeur du filtrage (FR, UE, all, perso)
450
		sql_change_country="connect gammu; UPDATE $SMS_c SET id='$2' WHERE name='FILTRAGE'"
451
		mysql --user=$u_db --password=$p_db -B -se "$sql_change_country"
452
		break
453
		;;
1349 richard 454
	--new_sms)
455
		# Appel de la fonction new_sms : filtrage du password, creation du compte et ban
456
		new_sms
457
		exit 0
458
		;;
459
	--imei_device)
460
		# Recuperation de l'imei du device
461
		sql_imei_phones="connect gammu; SELECT \`IMEI\` FROM phones;"
462
		mysql --user=$u_db --password=$p_db -B -se "$sql_imei_phones"
463
		exit 0
464
		;;
465
	--signal_device)
466
		# Recuperation du signal du device
467
		sql_signal_phones="connect gammu; SELECT \`Signal\` FROM phones;"
468
		mysql --user=$u_db --password=$p_db -B -se "$sql_signal_phones"
469
		exit 0
470
		;;
471
	--sms_received)
472
		# Recuperation du nombre de sms reçu. Depuis la dernière activation.
473
		sql_sms_received="connect gammu; SELECT \`Received\` FROM phones;"
474
		mysql --user=$u_db --password=$p_db -B -se "$sql_sms_received"
475
		exit 0
476
		;;
477
	--numero_alcasar)
478
		# Récupère le numero de la clé 3g (téléphone)
2600 tom.houday 479
		grep '^SMS_NUM=' $CONF_FILE | cut -d'=' -f2-
2454 tom.houday 480
		exit 0
1349 richard 481
		;;
482
	--replace_numero_alcasar)
483
		# Edition du numero de la clé 3g (téléphone)
2600 tom.houday 484
		sed -i "s/^SMS_NUM=.*/SMS_NUM=$2/" $CONF_FILE
2454 tom.houday 485
		exit 0
1349 richard 486
		;;
1380 richard 487
	--mode)
1416 richard 488
		# Mode huawei
489
		mode_huawei
490
		exit 0
491
		;;
1349 richard 492
	*)
493
		# Default
494
		echo "$usage"
495
		exit 0
496
		;;
497
esac
498
exit 0