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