Ajout du mode "unlock" + hotfix
* Ajout du mode "unlock" qui permet de ne plus a avoir à tapper l'OTP pendant 30min. * Ajout du menu HELP. * Fix des commandes a plusieurs mots
This commit is contained in:
parent
e2a8b0ac1e
commit
722ef11089
@ -3,35 +3,58 @@
|
|||||||
SECRETKEY=''
|
SECRETKEY=''
|
||||||
PHONENUM=''
|
PHONENUM=''
|
||||||
|
|
||||||
|
PATH_UNLOCK_FILE="/tmp/gammu_unlock_file"
|
||||||
|
|
||||||
DATE=`date --date="2 minute ago" +'%Y-%m-%d %H:%M:%S'`
|
DATE=`date --date="2 minute ago" +'%Y-%m-%d %H:%M:%S'`
|
||||||
OTP=`oathtool -w 4 --now="$DATE" --totp -b $SECRETKEY`
|
OTP=`oathtool -w 4 --now="$DATE" --totp -b $SECRETKEY`
|
||||||
|
|
||||||
OTPFROMCLIENT=`echo $SMS_1_TEXT | awk '{print $NF}'`
|
OTPFROMCLIENT=`echo $SMS_1_TEXT | awk '{print $NF}'`
|
||||||
CMD=`echo $SMS_1_TEXT | awk '{print tolower($1)}'`
|
CMD=`echo $SMS_1_TEXT | awk '{print tolower($1)}'``
|
||||||
TEXT=`echo $SMS_1_TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<NF; i++) print $i}'`
|
|
||||||
MATCH=`echo $OTP | grep $OTPFROMCLIENT`
|
MATCH=`echo $OTP | grep $OTPFROMCLIENT`
|
||||||
|
|
||||||
|
UNLOCKDATE=`cat $PATH_UNLOCK_FILE`
|
||||||
|
CURRENTDATE=`date +%s`
|
||||||
|
DIFFDATE=$(($CURRENTDATE-$UNLOCKDATE))
|
||||||
|
|
||||||
|
if [[ "$DIFFDATE" -lt "1800" ]];then
|
||||||
|
TEXT=`echo $SMS_1_TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<=NF; i++) print $i " "}'`
|
||||||
|
else
|
||||||
|
TEXT=`echo $SMS_1_TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<NF; i++) print $i " "}'`
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ $SMS_1_NUMBER -eq $PHONENUM ]]; then
|
if [[ $SMS_1_NUMBER -eq $PHONENUM ]]; then
|
||||||
if [[ -n $MATCH ]] ;then
|
if [ -n "$MATCH" ] || [ "$DIFFDATE" -lt "1800" ] ; then
|
||||||
case $CMD in
|
case $CMD in
|
||||||
allo)
|
allo)
|
||||||
REPLY="A l'huile"
|
REPLY="A l'huile"
|
||||||
;;
|
;;
|
||||||
|
help)
|
||||||
|
REPLY="PING \$HOST - ping un host; UNLOCK - déverrouille pendant 30 le mode OTP; LOCK - verrouille le mode unlock; REBOOT \$HOST - redémarre l'host distant; CMD \$HOST \$COMMAND - exécute une commande sur l'host distant; PXY \$NUM \$MESSAGE - Envoie un SMS avec le module"
|
||||||
|
;;
|
||||||
ping)
|
ping)
|
||||||
REPLY=`ping -n -c 2 $TEXT`
|
REPLY=`ping -n -c 2 $TEXT`
|
||||||
;;
|
;;
|
||||||
|
unlock)
|
||||||
|
date +%s > $PATH_UNLOCK_FILE
|
||||||
|
REPLY="Système débloqué pour 30 min"
|
||||||
|
;;
|
||||||
|
lock)
|
||||||
|
echo "0" > $PATH_UNLOCK_FILE
|
||||||
|
REPLY="Système re-verouillé"
|
||||||
|
;;
|
||||||
reboot)
|
reboot)
|
||||||
ssh root@"$TEXT" 'sudo reboot'
|
ssh root@"$TEXT" 'sudo reboot'
|
||||||
REPLY="Signal reboot envoyé"
|
REPLY="Signal reboot envoyé"
|
||||||
;;
|
;;
|
||||||
cmd)
|
cmd)
|
||||||
HOST=`echo $TEXT | awk '{print $1}'`
|
HOST=`echo $TEXT | awk '{print $1}'`
|
||||||
COMMAND=`echo $TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<=NF; i++) print $i}'`
|
COMMAND=`echo $TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<=NF; i++) print $i " "}'`
|
||||||
REPLY=`ssh -oStrictHostKeyChecking=no root@$HOST $COMMAND`
|
REPLY=`ssh -oStrictHostKeyChecking=no root@$HOST $COMMAND`
|
||||||
|
;;
|
||||||
pxy)
|
pxy)
|
||||||
PHONENUM=`echo $TEXT | awk '{print $1}'`
|
PHONENUM=`echo $TEXT | awk '{print $1}'`
|
||||||
REPLY=`echo $TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<=NF; i++) print $i}'`
|
REPLY=`echo $TEXT | awk 'BEGIN {ORS=" "} {for (i=2; i<=NF; i++) print $i " "}'`
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
REPLY="Commande inconnu"
|
REPLY="Commande inconnu"
|
||||||
|
Loading…
Reference in New Issue
Block a user