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:
Beu 2018-01-29 15:31:33 +01:00
parent e2a8b0ac1e
commit 722ef11089

View File

@ -3,35 +3,58 @@
SECRETKEY=''
PHONENUM=''
PATH_UNLOCK_FILE="/tmp/gammu_unlock_file"
DATE=`date --date="2 minute ago" +'%Y-%m-%d %H:%M:%S'`
OTP=`oathtool -w 4 --now="$DATE" --totp -b $SECRETKEY`
OTPFROMCLIENT=`echo $SMS_1_TEXT | awk '{print $NF}'`
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}'`
CMD=`echo $SMS_1_TEXT | awk '{print tolower($1)}'``
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 [[ -n $MATCH ]] ;then
if [ -n "$MATCH" ] || [ "$DIFFDATE" -lt "1800" ] ; then
case $CMD in
allo)
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)
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)
ssh root@"$TEXT" 'sudo reboot'
REPLY="Signal reboot envoyé"
;;
cmd)
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`
;;
pxy)
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"