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