sms_received.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/bash
  2. ################################################################################
  3. # SWARM de développement G1sms+.
  4. # PUBKEY G1 DU SWARMMASTER: 8qs69HriAdytcCLzvQGJ15XBwpjAVFx8JoVM2ahue1y7
  5. # ipfs ls /ipns/QmZHTne3bjtMgaXWRqSbdKchJbgq2NaAeVSzFUN7ceYpif
  6. #
  7. # G1sms+ est totalement décentralisé! Il peut être fait de multiples SWARM de Services dont les codes évoluent de façon décentralisé.
  8. # Puis se mettent à jour autour des $ADMINPHONE par consensus d'utilisateurs ;)
  9. #
  10. # Log => tail -f /tmp/g1sms.log -n 200
  11. # gammu => tail -f /tmp/smsd.log -n 200
  12. #
  13. # 2 commands needed to make the ramdisk if planning to run from ramdisk to gain some speed
  14. # sudo mkdir /mnt/ramdisk
  15. # sudo mount -t tmpfs -o size=50m tmpfs /mnt/ramdisk
  16. #
  17. # Utiliser la commande ./search fournie pour fouiller dans le code, mais tout est ordonnancé d'ici, donc vous êtes au bon endroit pour commencer à farfouiller.
  18. ###############################################################################
  19. # EN FAISANT PARTIE DU SWARM G1sms+ VOUS VOUS ENGAGEZ A ASSURER LA SECURITE
  20. # PHYSIQUE ET INFORMATIQUE DE VOTRE NOEUD ET NE PAS INTRODUIRE DE CODE MALVEILLANT
  21. # DANS LE GROUPE SI VOUS ETES AMENES A EN PROPOSER UNE MISE A JOUR.
  22. # UNE COMMISSION EST PERCU SUR CERTAINS TRANSFERTS.
  23. # ELLE EST PROVISION EN CAS DE FRAUDE ET SA REATRIBUTION POURRA EVOLUER...
  24. #
  25. # Author: Fred (support@qo-op.com)
  26. # Version: 0.1
  27. # License: GPL (http://www.google.com/search?q=GPL)
  28. ################################################################################
  29. MY_PATH="`dirname \"$0\"`" # relative
  30. MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
  31. # Execute Kalkun daemon
  32. [[ -f /var/www/kalkun/scripts/daemon.sh ]] && /var/www/kalkun/scripts/daemon.sh
  33. export YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
  34. cd $MY_PATH
  35. source $MY_PATH/shell/init.sh
  36. source $MY_PATH/shell/functions.sh
  37. ##################################################################
  38. # Get global variables from gammu-smsd
  39. PHONE="$SMS_1_NUMBER"
  40. TEXT="$SMS_1_TEXT"
  41. # Extract Received Command (PUBLISH OFFICIALS in file sms_AIDE.sh)
  42. CMD=$(echo "$TEXT" | awk '{print toupper($1)}')
  43. log "##########################################################################################"
  44. log "#############################################"
  45. log "#############################################"
  46. log "$(date)"
  47. log "SMS received $PHONE $TEXT"
  48. log "#############################################"
  49. log "NODE: ALL WALLETS: ipfs ls /ipns/$IPFSNODEID"
  50. log "NODE: G1wallet: cat ./wallets/.$IPFSNODEID/NODE.pub"
  51. log "#############################################"
  52. ##################################################################
  53. # BASIC SECURITY & ANTI SPAM
  54. ##################################################################
  55. security
  56. ##################################################################
  57. # Refresh All peers SWARM Wallets.
  58. ##################################################################
  59. ipfs_swarm_wallets_refresh
  60. ##################################################################
  61. # Check if PHONE is already registred in G1sms+ SWARM
  62. ##################################################################
  63. if [[ ! -f "./wallets/$PHONE/MASTERPHONE.sms" && "$CMD" != "ADMIN" ]]
  64. then
  65. NODEPHONE=$(cat "./wallets_swarm/$PHONE/MASTERPHONE.sms")
  66. if [[ "$NODEPHONE" != "$MASTERPHONE" && "$NODEPHONE" != "" ]]; then
  67. sms_SEND "$PHONE" "[G1sms+] Vous avez déjà un compte portefeuille sur $NODEPHONE (Envoyez lui RAZ si vous voulez fermer votre compte)"
  68. log "ALERT!! $PHONE compte existant sur le NODE G1sms+ ($NODEPHONE)"
  69. exit
  70. fi
  71. else
  72. # Refresh MasterPhone (usefull in case of MASTERPHONE SIM number change)
  73. echo "$MASTERPHONE" > "./wallets/$PHONE/MASTERPHONE.sms"
  74. fi
  75. ##################################################################
  76. # Handle commands CMD
  77. ##################################################################
  78. case "$CMD" in
  79. DESTROY|RAZ)
  80. # SEND DESTROY Member or DESTROY DON to empty you PHONE wallet and remove it
  81. MEMBERUID=$(echo "$TEXT" | awk '{print $2}' | grep -E "([A-Za-z0-9\-\_]+$)")
  82. ./shell/sms_DESTROY.sh "$PHONE" "$MEMBERUID"&
  83. ;;
  84. A|AIDE)
  85. ./shell/sms_AIDE.sh "$PHONE" &
  86. ;;
  87. N|D)
  88. # SEND DESTROY Member or DESTROY DON to empty you PHONE wallet and remove it
  89. MEMBERUID=$(echo "$TEXT" | awk '{print $2}' | grep -E "([A-Za-z0-9\-\_]+$)")
  90. ./shell/sms_NEW.sh "$PHONE" "$MEMBERUID" &
  91. ;;
  92. P|PAY)
  93. DEST=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
  94. MONEY=$(echo "$TEXT" | awk '{print $3}' | grep -E "^\-?[0-9]+$")
  95. if [[ ${#DEST} == 10 && "$DEST" != "" && "$MONEY" != "" ]]; then
  96. ./shell/sms_PAY.sh "$PHONE" "$DEST" "$MONEY" &
  97. else
  98. ./shell/sms_ERROR.sh "$PHONE" "ex:: P 0612345678 100 = Envoyer 100 $UNIT au portefeuille G1sms+ +33612345678" &
  99. fi
  100. ;;
  101. VIR)
  102. montant=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
  103. membre=$(echo "$TEXT" | awk '{print $3}' | grep -E "([A-Za-z0-9\-\_]+$)")
  104. if [[ "$montant" != "" && "$membre" != "" ]]; then
  105. ./shell/sms_VIR.sh "$PHONE" "$montant" "$membre" &
  106. else
  107. ./shell/sms_ERROR.sh "$PHONE" "ex:: VIR 100 mot5678 = Envoyer 100 $UNIT au portefeuille G1sms+ 'mot5678' (On peut aussi utiliser le pseudo d'un Membre)" &
  108. fi
  109. ;;
  110. REC)
  111. # ex: "REC 2000 John J 12" (Virer 2000 UNIT au G1sms+ wallet de John pour les 12 prochains jours)
  112. AMOUNT=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
  113. VIRDEST=$(echo "$TEXT" | awk '{print $3}' | grep -E "([A-Za-z0-9\-\_]+$)")
  114. PERIOD=$(echo "$TEXT" | awk '{print toupper($4)}' | grep -E "([A-Za-z0-9\-\_]+$)")
  115. TIME=$(echo "$TEXT" | awk '{print $5}' | grep -E "^\-?[0-9]+$")
  116. if [[ "$VIRDEST" != "" && "$AMOUNT" != "" && "$PERIOD" != "" && "$TIME" != "" ]]; then
  117. ./shell/sms_REC.sh "$PHONE" "$VIRDEST" "$AMOUNT" "$PERIOD" "$TIME" &
  118. else
  119. ./shell/sms_ERROR.sh "$PHONE" "ex:: REC 20 Fred M 12 => Virer 20 $UNIT au portefeuille G1sms+ de Fred pendant 12 Mois (Choisir la période: J,S,M,A)." &
  120. fi
  121. ;;
  122. C|S|SOLDE)
  123. ./shell/sms_COUNT.sh "$PHONE" &
  124. ;;
  125. EMAIL)
  126. # RECUPERE EMAIL ASSOCIE AU G1SMS WALLET
  127. MAIL=$(echo "$TEXT" | awk '{print tolower($2)}' | grep -E "[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}")
  128. if [[ "$MAIL" != "" ]]; then
  129. ./shell/sms_EMAIL.sh "$PHONE" "$MAIL" &
  130. else
  131. ./shell/sms_ERROR.sh "$PHONE" "$TEXT votre adresse est incorrecte..." &
  132. fi
  133. ;;
  134. BILL)
  135. # PREMIERS G1billets (à gratter)... COLLECTOR ;) ONLY FOR A4 PRINTER !!
  136. VAL=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
  137. if [[ "$VAL" != "" ]]; then
  138. ./shell/sms_BILLET.sh "$PHONE" "$VAL" &
  139. else
  140. ./shell/sms_ERROR.sh "$PHONE" "ex:: BILL 20 => Créer et imprimer 6 G1Billets de '20 LOVE' sur une feuille A4 (cout 120 $UNIT + $BILLCOM )" &
  141. fi
  142. ;;
  143. CHK)
  144. W1=$(echo "$TEXT" | awk '{print tolower($2)}' | grep -E "^[a-z0-9]+$")
  145. W2=$(echo "$TEXT" | awk '{print tolower($3)}' | grep -E "^[a-z0-9]+$")
  146. W3=$(echo "$TEXT" | awk '{print tolower($4)}' | grep -E "^[a-z0-9]+$")
  147. W4=$(echo "$TEXT" | awk '{print tolower($5)}' | grep -E "^[a-z0-9]+$")
  148. W5=$(echo "$TEXT" | awk '{print tolower($6)}' | grep -E "^[a-z0-9]+$")
  149. W6=$(echo "$TEXT" | awk '{print tolower($7)}' | grep -E "^[a-z0-9]+$")
  150. W7=$(echo "$TEXT" | awk '{print tolower($8)}' | grep -E "^[a-z0-9]+$")
  151. if [[ "$W1" != "" && "$W2" != "" ]]; then
  152. ./shell/sms_BILLETCHK.sh "$PHONE" "$W1" "$W2" "$W3" "$W4" "$W5" "$W6" "$W7" &
  153. else
  154. ./shell/sms_ERROR.sh "$PHONE" "Mauvais Format. Le code doit comporter 2 mots minimum pour vérifier la valeur du billet, + code secret pour l'encaisser..." &
  155. fi
  156. ;;
  157. TAG)
  158. # NOUVEAU TAG (pubkey, BI) pour terminaux DAB et TX sur IPFS.
  159. # ex: TAG 200 (Create & Print One 200 "PubKey / BI" Qrcode Notes)
  160. VAL=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
  161. NUM=$(echo "$TEXT" | awk '{print $3}' | grep -E "^\-?[0-9]+$")
  162. if [[ "$VAL" != "" ]]; then
  163. ./shell/sms_G1TAG.sh "$PHONE" "$VAL" "$NUM" &
  164. else
  165. ./shell/sms_ERROR.sh "$PHONE" "ex:: TAG 2 12 => Créer 12 G1Tag de 2 G1" &
  166. fi
  167. ;;
  168. U|UNIT)
  169. # Choisir son UNIT préférée (G1, DU, LOVE)
  170. UNIT=$(echo "$TEXT" | awk '{print toupper($2)}'| grep -E "^[A-Za-z0-9]+$")
  171. ./shell/sms_SETUNIT.sh "$PHONE" "$UNIT" &
  172. ;;
  173. OU)
  174. # CHOISIR SON DISTRIBUTEUR DE G1Tag
  175. NODEUIDNA=$(echo "$TEXT" | awk '{print $2}'| grep -E "([A-Za-z0-9\-\_]+$)")
  176. ./shell/sms_WHERE.sh "$PHONE" "$NODEUIDNA" &
  177. ;;
  178. ABO)
  179. # GERER SES ABONNEMENT CANAUX INFO SMS
  180. SERVICE=$(echo "$TEXT" | awk '{print toupper($2)}'| grep -E "([A-Za-z0-9\-\_]+$)")
  181. ./shell/sms_ABO.sh "$PHONE" "$SERVICE" &
  182. ;;
  183. DELIVERED|PENDING|FAILED)
  184. # If delivered/pending notification come back (gammu/phone config)
  185. exit
  186. ;;
  187. ADMIN)
  188. # If Phone is ADMIN
  189. if [[ "$PHONE" == "$ADMINPHONE" ]]; then
  190. CMD=$(echo "$TEXT" | awk '{print toupper($2)}')
  191. PARAM=$(echo "$TEXT" | awk '{print substr($0,index($0,$3))}')
  192. ./shell/sms_ADMIN.sh "$CMD" "$PARAM" &
  193. fi
  194. ;;
  195. *)
  196. #./shell/sms_ERROR.sh "$PHONE" "$TEXT" &
  197. log "SMS forward to $ADMINPHONE"
  198. sms_SEND "$ADMINPHONE" "ADMIN! BAD SMS FROM $PHONE
  199. $TEXT"
  200. ;;
  201. esac
  202. # MONITORING: SEND INCOMING MESSAGE COPY TO ADMINPHONE
  203. if [[ "$PHONE" != "$ADMINPHONE" && "$CPERROR" == "YES" ]]; then sms_SEND "$ADMINPHONE" "ADMIN! MONITOR: $PHONE : $TEXT"; fi
  204. echo $PUBKEY
  205. exit