astroport/g1sms/sms_ASTROPORT.sh

106 lines
3.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# AJAX REQUEST TRACKER : ASTROPORT ON BOARDING
# GETTING : PHONE + PARRAIN + NAISSANCE
#
# DataFlow : index.html + ajaxform.js + zen_loveland_entrance.php
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
[[ ! $(which gammu-smsd-inject) ]] && exit 0 ## TODO: ONLY SMS equiped NODE run that part of code !! DO IT BETTER MAY BE
source $MY_PATH/init.sh
source $MY_PATH/functions.sh
export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er+=" ipfs daemon not running"
export IPFSNODEID=$(ipfs id -f='<id>\n') || er+=" ipfs id problem"
export WHOAMI=$(sbotc whoami | jq -r .id) || er+=" sbotc whoami problem"
[[ "$YOU" == "" || "$IPFSNODEID" == "" || "$WHOAMI" == "" ]] && echo "ERROR : $er " && exit 1
TODAY=$(date '+%Y%m%d')
timestamp=$(date -u +%s%N | cut -b1-13)
#
# ___ __ __
# / | _____/ /__________ ____ ____ _____/ /_
# / /| | / ___/ __/ ___/ __ \/ __ \/ __ \/ ___/ __/
# / ___ |(__ ) /_/ / / /_/ / /_/ / /_/ / / / /_
#/_/ |_/____/\__/_/ \____/ .___/\____/_/ \__/
# /_/
#Love Land ENTRANCE CHECKING
#
[[ ! $(which gammu-smsd) ]] && echo "I am NOT a G1SMS Node... Can't do nothing... EXIT" && exit 1
# /home/$YOU/.zen/astroport/zen/ipfs_SWARM_refresh.sh
# CHECK FOR request from loveland home page
for hashfile in /tmp/loveland_entrance/*; do
[[ ! -f $hashfile ]] && continue
PP=$(cat $hashfile)
PHONE=$(echo $PP | cut -d '|' -f 1)
# CHECK FOR PHONE NUMBER COHERENCE
[[ ! ${#PHONE} -eq 12 ]] && exit 1
[[ ! ${PHONE:3:1} == "6" && ! ${PHONE:3:1} == "7" ]] && exit 1
PARRAIN=$(echo $PP | cut -d '|' -f 2)
NAISSANCE=$(echo $PP | cut -d '|' -f 3)
HPHONE=$(basename -- "$hashfile")
echo "Astroport Ajax Request received $PP"
# TODO SEARCH IN SWARM (* = G1PUB) : /home/$YOU/.zen/ipfs_swarm/*/g1sms/Qm*/$HPHONE/_pub
if [[ ! -f /home/$YOU/.zen/g1sms/$PHONE/_pub ]]; then
# PHONE IS UNKNOWN !
sms_SEND "$PHONE" "JEU_0: Creer votre compte et 2 annonces sur Cesium+ et https://gchange.fr avec votre clef."
## TODO ADD DOUBLE AUTH....?
log "$(date): $PHONE : $PARRAIN : $NAISSANCE"
# CHECK for Associated PARRAIN. GET PubKey?
PARRAIN=$(echo "$PARRAIN" | grep -E "([A-Za-z0-9\-\_]+$)")
#[[ $PARRAIN ]] && MEMRIB=$(sms_uid2key "$PARRAIN" "$PHONE" "$PIN") && echo "RIB PARRAIN: $MEMRIB"
# CREATE G1 WALLET
$MY_PATH/sms_NEW.sh "$PHONE" "$PARRAIN"
else
# ACCOUNT ALREADY EXISTING
# Get AMOUNTG1, AMOUNTLOVE, AMOUNTDU
PUBKEY=$(cat /home/$YOU/.zen/g1sms/$PHONE/_pub)
AMOUNTG1=$(silkaj_balance $PUBKEY)
AMOUNTDU=$(bc -l <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
AMOUNTLOVE=$(bc -l <<< "scale=0; $AMOUNTG1 * 100 / $DUFACTOR")
AMOUNTZEN=$(bc -l <<< "scale=0; $AMOUNTG1 * 100")
mess="Vous avez $AMOUNTZEN ZEN sur votre compte. Installez https://cesium.app"
# Send response SMS
sms_SEND "$PHONE" "$mess"
fi
### REMOVE SMS COMMAND from LOVELAND entrance
[[ -f $hashfile ]] && rm -f $hashfile
done
## CHECK FOR DOUBLE AUTH REQUEST
if [[ -f /tmp/sms.auth.commands ]]; then
for phone_auth in $(cat /tmp/sms.auth.commands); do
$MY_PATH/sms_AUTH.sh $phone_auth
done
fi
[[ -d /home/$YOU/.zen/g1sms/$PHONE ]] && [[ $(whoami) == "root" ]] && chown -R $YOU /home/$YOU/.zen/g1sms/$PHONE
exit 0