forked from axiom-team/astroport
504 lines
21 KiB
Bash
Executable File
504 lines
21 KiB
Bash
Executable File
#!/bin/bash -x
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
# G1SMS COMMUN FUNCTIONS
|
|
|
|
# TODO: REWRITE AND MAKE FULL IPFS get wallet value through IPNS links
|
|
# ipfs cat /ipns/QmUrUdfz5hWJ6354D3N6DT64tbs5CLEndSYYiqrj9Wa4Ax/+33647683646/+33647683646.uidna
|
|
###################################################################################################################################
|
|
|
|
###################################################################################################################################
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
|
|
|
|
## Récupère les données du profile
|
|
source /home/$YOU/.zen/secret.astroport.key
|
|
|
|
function sms_SEND () {
|
|
# sms_SEND ($1=phone, $2=message)
|
|
local dest="$1"
|
|
local mess="$2"
|
|
if [[ ${#dest} -eq 10 || ${#dest} -eq 12 ]]; then
|
|
if [[ -d /home/$YOU/.zen/g1sms_wallets/$dest ]]; then
|
|
# TEST IF $dest IS ON CURRENT NODE
|
|
sudo gammu-smsd-inject TEXT "$dest" -text "$mess" 1>&2
|
|
else
|
|
log ">>>>>>>>>> INCONNU $dest"
|
|
fi
|
|
else
|
|
log ">>>>>>>>>>SMS ERROR BAD DESTINATION $dest"
|
|
fi
|
|
log ">>>>>>>>>> SENDING SMS $mess TO $dest ($DESTNODEID)"
|
|
}
|
|
|
|
|
|
#################################################################################################################################
|
|
function sms_ERROR () {
|
|
# sms_ERROR ($1=phone, $2=message)
|
|
local dest="$1"
|
|
local mess="[ERREUR]
|
|
$2"
|
|
if [[ ${#dest} -eq 10 || ${#dest} -eq 12 ]]; then
|
|
sudo gammu-smsd-inject TEXT "$dest" -text "$mess" 1>&2
|
|
else
|
|
log ">>>>>>>>>>SMS ERROR BAD DESTINATION $dest"
|
|
fi
|
|
log ">>>>>>>>>> SENDING SMS $mess TO $dest"
|
|
# SEND ERROR COPY TO ADMINPHONE
|
|
if [[ "$CPERROR" == "YES" ]]; then sms_SEND "$ADMINPHONE" "ADMIN! ERROR ($dest): $mess"; fi
|
|
}
|
|
|
|
|
|
#################################################################################################################################
|
|
function log_history () { # TODO REMOVE
|
|
log "__SUB:log_history: history ($1, $2)"
|
|
PHONE="$1"
|
|
HISTFILE="./history.$IPFSNODEID.log.csv"
|
|
|
|
echo "$(date +%Y%m%d), $(date +%H:%M:%S), $1, $2" >> "$HISTFILE"
|
|
}
|
|
|
|
|
|
#################################################################################################################################
|
|
function security () {
|
|
|
|
if [[ "$G1SMS" == "YES" ]]; then # ONLY OF gammu is really sending SMS on that NODE
|
|
# No Reply to MySelf (or enjoy SMS LOOP of the death) Nobody neither
|
|
if [[ "$PHONE" == "$MASTERPHONE" || "$PHONE" == "" ]]; then log "__SUB:security: SMS REJECTED !! $PHONE $TEXT"; exit; fi
|
|
|
|
# ADAPT TO YOUR PHONE COMPANY / ADVERT ANNOYANCE
|
|
if [[ "$PHONE" == "Orange Info" ]]; then log "__SUB:security: SMS REJECTED !! $PHONE ADVERT $TEXT"; exit; fi
|
|
if [[ ${#PHONE} -ne 12 && ${#PHONE} -ne 46 ]]; then log "!! SMS REJECTED !! $PHONE BAD $TEXT"; exit; fi
|
|
fi
|
|
|
|
# ANTI SPAM SMS (1 mn entre chaque commande)
|
|
find /tmp -cmin +1 -type f -name "sms_received_*" -exec rm -f '{}' \;
|
|
|
|
# Do not consider SPAM, Delivered notification
|
|
if [[ "$CMD" != "DELIVERED" && "$CMD" != "PENDING" ]]; then
|
|
if [[ -f "/tmp/sms_received_$PHONE" ]]; then
|
|
# Send response SMS
|
|
if [[ ! -f "/tmp/sms_SPAM_$PHONE" ]]; then
|
|
sms_ERROR "$PHONE" "Je ne le dirai pas 2 fois... Laissez moi au moins 1 minute entre chacune de vos commandes SMS! Autrement je n'y répondrai pas. Merci!"
|
|
echo $(date) > "/tmp/sms_SPAM_$PHONE"
|
|
fi
|
|
log "__SUB:security: ################################"
|
|
log "__SUB:security: $PHONE COMMAND REJECTED: $TEXT"
|
|
exit
|
|
fi
|
|
echo "$TEXT" > "/tmp/sms_received_$PHONE"
|
|
# Remove SPAM flag older than one day
|
|
find /tmp -ctime +1 -type f -name "sms_SPAM_*" -exec rm -f '{}' \;
|
|
else
|
|
# THIS IS AN AKNOWLEGEMENT
|
|
log "__SUB:security: ################################"
|
|
log "__SUB:security: $PHONE COMMAND REJECTED: $TEXT"
|
|
exit
|
|
fi
|
|
# Remove SPAM flag older than one day
|
|
find /tmp -ctime +1 -type f -name "sms_SPAM_*" -exec rm -f '{}' \;
|
|
|
|
}
|
|
|
|
|
|
|
|
#################################################################################################################################
|
|
function ipfs_node_wallets_add (){
|
|
##########################
|
|
log "TODO ipfs_node_wallets_add"
|
|
##########################
|
|
# IWALLETS=$(su $YOU -c "ipfs add -rHq '/home/$YOU/.zen/g1sms_wallets' | tail -n 1")
|
|
|
|
# CHAIN STATE FOR $IPFSNODEID
|
|
# echo $IWALLETS > /home/$YOU/.zen/ipfs/.$IPFSNODEID.wallets.chain
|
|
# log "__SUB:ipfs_node_wallets_add: NEW '/home/$YOU/.zen/g1sms_wallets' HASH ipfs ls $IWALLETS"
|
|
|
|
# PUBLISH IPNS NODE WALLETS
|
|
# NODEWALLETS=$(su $YOU -c "ipfs name publish --quieter /ipfs/$IWALLETS")
|
|
# log "__SUB:ipfs_node_wallets_add: G1smsWallet = ipfs cat /ipns/$NODEWALLETS/$PHONE/$PHONE.g1cents Zen"
|
|
|
|
# echo $IWALLETS
|
|
}
|
|
|
|
|
|
#################################################################################################################################
|
|
function sms_uid2key (){
|
|
# sms_uid2key "$MEMBERUID" "$PHONE" "$PIN"
|
|
RIBFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidrib"
|
|
NAMEFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidname"
|
|
UIDNAFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidna"
|
|
# New related wallet asked
|
|
ASKWALLET="$1"
|
|
#For micro payement
|
|
PHONE="$2"
|
|
PIN="$3"
|
|
|
|
[[ -f $UIDNAFILE ]] && UIDNA=$(cat $UIDNAFILE) || UIDNA=""
|
|
log "__SUB:sms_uid2key: $UIDNA Try to associate $ASKWALLET with $PHONE... SEARCHING..."
|
|
|
|
if [[ $UIDNA && "$ASKWALLET" == "$UIDNA" ]]; then
|
|
log "__SUB:sms_uid2key: "$ASKWALLET" == "$UIDNA" !!"
|
|
sms_SEND "$PHONE" "[G1sms+] $UIDNA est le nom de votre porte monnaie libre pour $PHONE. Il ne peut également être compte maître!"
|
|
fi
|
|
|
|
# Test if member files exists
|
|
if [ -f "$NAMEFILE" ]; then
|
|
UIDNAME=$(cat "$NAMEFILE")
|
|
log "__SUB:sms_uid2key: ALREADY $UIDNAME related Wallet for $PHONE Wallet change to $ASKWALLET !!"
|
|
if [["$UIDNAME" != "$ASKWALLET" ]]; then
|
|
sms_SEND "$ADMINPHONE" "ADMIN! INFO: $PHONE Wallet associé à $UIDNAME change en $ASKWALLET !!"
|
|
sms_SEND "$PHONE" "[G1sms+] Votre portefeuille maitre va passer de $UIDNAME à $ASKWALLET!"
|
|
fi
|
|
fi
|
|
|
|
# Search fo duplicate
|
|
DUP=$(grep -Rwl "$ASKWALLET" /home/$YOU/.zen/g1sms_wallets/*/_uidname 2>/dev/null | cut -f 6 -d '/')
|
|
if [[ "$DUP" != "" && "$DUP" != "$PHONE" ]]; then
|
|
sms_SEND "$ADMINPHONE" "ADMIN! INFO: $PHONE prend le même $ASKWALLET, que $DUP"
|
|
sms_SEND "$DUP" "Vous devez savoir que $ASKWALLET est associé à un autre téléphone que le votre également!"
|
|
fi
|
|
|
|
###########################################################
|
|
# FIND ASKWALLET into wallets, wallest_swarm OR duniter (silkaj)
|
|
DESTMEM="$VIRDEST"
|
|
# SEARCH IN WALLETS
|
|
LOCAL=$(grep -Rwl "$ASKWALLET" /home/$YOU/.zen/g1sms_wallets/*/_uidna 2>/dev/null | cut -f 6 -d '/')
|
|
if [[ "$LOCAL" != "" ]]; then
|
|
# LOCAL G1sms account
|
|
DESTRIB=$(cat /home/$YOU/.zen/g1sms_wallets/$LOCAL/_pub)
|
|
DESTPHONE=$LOCAL
|
|
log "__SUB:sms_uid2key: FOUND LOCAL ($MASTERPHONE) G1sms+ wallet: $DESTRIB ($LOCAL)"
|
|
else
|
|
|
|
##################### REWRITE TODO
|
|
# SEARCH IN WALLETS SWARM
|
|
# INSWARM=$(grep -Rwl "$ASKWALLET" /home/$YOU/.zen/ipfs_swarm/*/_uidna | cut -f 6 -d '/' )
|
|
# MYCHAN=$( echo $INSWARM | cut -f 6 -d '/' )
|
|
# MYHASH=$( echo $MYCHAN | cut -f 1 -d '@' )
|
|
# if [[ "$INSWARM" != "" ]]; then
|
|
# REMOTENODE=$(cat /home/$YOU/.zen/ipfs_swarm/$MYIPFS/MASTERPHONE.sms)
|
|
# DESTRIB=$(cat /home/$YOU/.zen/ipfs_swarm/$MYHASH/_pub)
|
|
# DESTPHONE=$INSWARM
|
|
# log "__SUB:sms_uid2key: FOUND SWARM ($REMOTENODE) G1sms+ wallet: $DESTRIB ($INSWARM)"
|
|
# else
|
|
##################### REWRITE TODO
|
|
# SEARCH WITH SILKAJ
|
|
log "__SUB:sms_uid2key: GETTING FROM SILKAJ MEMBER ID"
|
|
DESTRIB=$(silkaj id "$ASKWALLET" | grep -w "$ASKWALLET" | awk '{print $2}' | tail -n 1)
|
|
log "__SUB:sms_uid2key: OUT OFF SWARM MEMBER wallet: $DESTRIB"
|
|
# GET CESIUM+ geoPoint DATA (TODO: cron for GCHANGE SMS Alert)
|
|
curl -s ${CESIUM}/user/profile/${DESTRIB} | jq '._source.geoPoint' > "/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidgeo.json"
|
|
log "__SUB:sms_uid2key: GET CESIUM+ geoPoint and AVATAR : $(cat /home/$YOU/.zen/g1sms_wallets/$PHONE/_uidgeo.json)"
|
|
curl -s ${CESIUM}/user/profile/${DESTRIB} | jq '._source.avatar._content' | sed 's/\"//g' | base64 -d > "/home/$YOU/.zen/g1sms_wallets/$PHONE/_avatar.png"
|
|
fi
|
|
|
|
if [ "$DESTRIB" != "" ]; then
|
|
echo "$DESTRIB" > "$RIBFILE"
|
|
echo "$ASKWALLET" > "$NAMEFILE"
|
|
log "__SUB:sms_uid2key: NEW EXTERNAL RELATED $DESTRIB / FOR MEMBER OR WALLET = $ASKWALLET - INIT 0.1 TX"
|
|
duniter_server=$(/home/$YOU/.zen/astroport/zen/tools/tools/duniter_getnode.sh)
|
|
INIT=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey tx --output $DESTRIB --amount 1 --comment "[G1sms+] Porte Monnaie $(cat $UIDNAFILE) -> $(cat $NAMEFILE)" -y)
|
|
|
|
log "__SUB:sms_uid2key: INIT = $INIT | Create Connection with related Wallet."
|
|
log_history "$PHONE" "MEMBER, $ASKWALLET"
|
|
sms_SEND "$ADMINPHONE" "ADMIN! LOG: $PHONE Nouveau compte lié $UIDNA -- $ASKWALLET ($INIT)"
|
|
else
|
|
sms_SEND "$ADMINPHONE" "ADMIN! LOG: $PHONE / $ASKWALLET ABSENT"
|
|
fi
|
|
|
|
log "__SUB:sms_uid2key: $MEMBER($DESTRIB)"
|
|
echo "$DESTRIB"
|
|
}
|
|
|
|
#################################################################################################################################
|
|
function silkaj_balance () {
|
|
pubkey="$1"
|
|
[[ ! $pubkey ]] && echo "0" && exit
|
|
silkajQuantitativeAmountPattern='Total\sQuantitative\s+=\s+(.*)\s+Ğ1'
|
|
silkajExitCode=1
|
|
myi=1
|
|
while [ $silkajExitCode -ne 0 ]
|
|
do
|
|
duniter_server=$(/home/$YOU/.zen/astroport/zen/tools/duniter_getnode.sh)
|
|
log "Running silkaj -p "${duniter_server}" balance $pubkey"
|
|
silkajOutput=$(silkaj -p "${duniter_server}" balance $pubkey 2>/dev/null)
|
|
silkajExitCode=$?
|
|
|
|
((myi++))
|
|
[ $i -gt 4 ] && continue
|
|
done
|
|
|
|
if [[ $silkajOutput =~ $silkajQuantitativeAmountPattern ]]
|
|
then
|
|
echo "${BASH_REMATCH[1]}"
|
|
else
|
|
echo "0"
|
|
fi
|
|
}
|
|
|
|
#################################################################################################################################
|
|
function sms_INIT_ACCOUNT () {
|
|
log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|
PHONE="$1"
|
|
UNKNOWN=0
|
|
# TODO Optimize GLOBAL/local variables use, use more function array output ?!
|
|
# Initiate PHONE settings files and values
|
|
IPFSNODEIDFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/MASTERPHONE.ipfsid" # Contains G1sms+ NODE IPFS id
|
|
SMSNODE="/home/$YOU/.zen/g1sms_wallets/$PHONE/MASTERPHONE.sms" # Contains G1sms+ SMS phone number
|
|
PINFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_pin" # Contains phone wallet diceware password
|
|
GPGPINFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_pin.gpg" # Contains g1smsnode cypher phone wallet diceware password
|
|
DUNIKEYFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey" # secret.dunikey
|
|
PUBKEYFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_pub" # Contains phone wallet public key (RIB)
|
|
UNITFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_unit" # Contains phone wallet prefered unit (LOVE,G1,DU)
|
|
|
|
RIBFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidrib" # Contains phone wallet related UID Pubkey
|
|
NAMEFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidname" # Contains the member UID related to wallet
|
|
MAILFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_email" # Contains the member EMAIL (Send BILLET)
|
|
GPGMAILFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_email.gpg" # Contains the member EMAIL (Send BILLET)
|
|
UIDNAFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidna" # Contains the G1sms+ UID Name for recursive VIR
|
|
GEOFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/_uidgeo.json" # Contains the member GeoPoint from member Cesium+ related to wallet
|
|
|
|
RECFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/VIREMENTS" # File showing recurrent payements are left to be done with this G1sms Wallet
|
|
GPGRECFILE="/home/$YOU/.zen/g1sms_wallets/$PHONE/VIREMENTS.gpg" # Cypher file with IPFSPrivKey (Node .Identity.PrivKey)
|
|
|
|
DABUIDF="/home/$YOU/.zen/g1sms_wallets/$PHONE/uidna.G1TAGNODE" # Contains G1Dab Name
|
|
# GET CURRENT NODE UIDNA (default DABUID)
|
|
NODEUIDNA=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna)
|
|
######################################################################
|
|
# (NO PIN) = FIRST ACCOUNT: Create wallet
|
|
if [ ! -f "$PINFILE" ]; then
|
|
# NOSMS mode?
|
|
if [[ $2 == "NOSMS" ]]; then UNKNOWN="unknown"; return; fi
|
|
mkdir -p /home/$YOU/.zen/g1sms_wallets/$PHONE/
|
|
|
|
#######################
|
|
# GIVE NAME TO WALLET
|
|
#######################
|
|
# 4 derniers chiffres du numéro de téléphone
|
|
TAIL=${PHONE:6:6}
|
|
# No UIDNA yet. Create new
|
|
UIDNA=$(/home/$YOU/.zen/astroport/zen/tools/diceware.sh 1 | xargs)
|
|
# Check if already existing among all swarm wallets
|
|
while [[ $(grep -Rwl "$UIDNA$TAIL" /home/$YOU/.zen/ipfs_swarm/.*/G1SMS/_uidna 2>/dev/null) ]]; do UIDNA=$(/home/$YOU/.zen/astroport/zen/tools/diceware.sh 1 | xargs); done
|
|
UIDNA="$UIDNA$TAIL"
|
|
echo "$UIDNA" > "$UIDNAFILE"
|
|
|
|
#######################
|
|
# Create Account Files
|
|
#######################
|
|
|
|
PIN=$(/home/$YOU/.zen/astroport/zen/tools/diceware.sh | xargs)
|
|
|
|
python3 /home/$YOU/.zen/astroport/zen/tools/key_create_dunikey.py "$UIDNA" "$PIN" ## Copy PubSec file to /tmp/secret.dunikey
|
|
mv /tmp/secret.dunikey /home/$YOU/.zen/g1sms_wallets/$PHONE/
|
|
PUBKEY=$(cat $DUNIKEYFILE | grep 'pub:' | cut -d ' ' -f 2)
|
|
log "__SUB:sms_INIT_ACCOUNT: !! G1 Wallet CREATED: $PHONE = $UIDNA $PIN : $PUBKEY"
|
|
[[ $PUBKEY == "" ]] && log "__SUB:sms_INIT_ACCOUNT: Problem making secret.dunikey" && exit 1
|
|
#######################
|
|
# ACTIVATE G1SMS WALLET
|
|
#######################
|
|
# log "$NODE_PUBSECFILE $PUBKEY THIRD_PARTY_MANAGER:$NODE_G1PUBKEY"
|
|
duniter_server=$(/home/$YOU/.zen/astroport/zen/tools/duniter_getnode.sh)
|
|
TX_IN=$(silkaj -p "$duniter_server" -af --file ~/.ssb/secret.dunikey tx --output $PUBKEY --amount 3.24 --comment "[G1sms+] $UIDNA$TAIL 3RD:$NODE_G1PUBKEY" -y)
|
|
log "__SUB:sms_INIT_ACCOUNT: G1 Wallet TX IN: $TX_IN"
|
|
sleep 2
|
|
|
|
TX_OUT=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey tx --output $NODE_G1PUBKEY --amount 0.1 --comment "[G1sms+] $UIDNA$TAIL 3RD:$NODE_G1PUBKEY:ACK" -y)
|
|
log "__SUB:sms_INIT_ACCOUNT: G1 Wallet TX OUT: $TX_OUT"
|
|
|
|
################
|
|
# GPG cypher PIN (ONLY CREATOR NODE CAN ACCESS IT !)
|
|
################
|
|
echo "$PIN" > "$PINFILE"
|
|
echo "${IPFSPrivKey}" | gpg -q --output "$GPGPINFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE"
|
|
/home/$YOU/.zen/astroport/zen/tools/natools.py encrypt -p $NODE_G1PUBKEY -i "$PINFILE" -o "${PINFILE}.crypt"
|
|
PIN=$(cat "$PINFILE" | xargs)
|
|
[[ "$PIN" != "" ]] && echo "" > "$PINFILE" || log "SYSTEM ERROR :: PIN EMPTY !!! GPG???"
|
|
|
|
echo "$PUBKEY" > "$PUBKEYFILE"
|
|
echo "$COIN" > "$UNITFILE"
|
|
echo "$MASTERPHONE" > "$SMSNODE"
|
|
log_history "$PHONE" "NEW, $PUBKEY"
|
|
|
|
# ADD WALLET TO IPFS
|
|
I=$(ipfs_node_wallets_add)
|
|
fi
|
|
|
|
|
|
#################################################
|
|
# PUBLISH G1sms+ WALLET PROPERTIES MAIN PROCESS
|
|
#################################################
|
|
######################################################################
|
|
log "__SUB:sms_INIT_ACCOUNT: Déchiffrage PGP PIN..."
|
|
# GPG decypher PIN
|
|
# TODO make decypher less stress on filesystem, use /tmp and ramdisk
|
|
echo "${IPFSPrivKey}" | gpg -d -q --output "$PINFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGPINFILE"
|
|
PIN=$(cat "$PINFILE" | xargs)
|
|
[[ "$PIN" == "" ]] && [[ -f "${PINFILE}.crypt" ]] && /home/$YOU/.zen/astroport/zen/tools/natools.py decrypt --pubsec -k "$NODE_PUBSECFILE" -i "${PINFILE}.crypt" -o "$PINFILE" && PIN=$(cat "$PINFILE");
|
|
[[ "$PIN" != "" ]] && echo "" > "$PINFILE" || log "SYSTEM ERROR :: PIN EMPTY !!! GPG???"
|
|
|
|
# TODO ./natools.py encrypt -p $NODE_G1PUBKEY -i "$DUNIKEYFILE" -o "$DUNIKEYFILE.crypt"
|
|
# ./natools.py decrypt --pubsec -k "$NODE_PUBSECFILE" -i "$DUNIKEYFILE.crypt" -o "$DUNIKEYFILE"
|
|
|
|
# EMAIL
|
|
[[ $SMSEMAIL == "" ]] && [[ -f "$GPGMAILFILE" ]] && echo "${IPFSPrivKey}" | gpg -d -q --output "$MAILFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGMAILFILE" && SMSEMAIL=$(cat $MAILFILE)
|
|
[[ $SMSEMAIL == "" ]] && [[ -f "$MAILFILE.crypt" ]] && /home/$YOU/.zen/astroport/zen/tools/natools.py decrypt --pubsec -k "$NODE_PUBSECFILE" -i "$MAILFILE.crypt" -o "$MAILFILE" && SMSEMAIL=$(cat $MAILFILE)
|
|
log "__SUB:sms_INIT_ACCOUNT: Déchiffrage EMAIL $SMSEMAIL"
|
|
# EMPTY CLEAR EMAIL FILE
|
|
[[ $SMSEMAIL != "" ]] && echo "" > "$MAILFILE"
|
|
|
|
|
|
# PUBLISH GLOBAL VARS FROM ACCOUNT FILES
|
|
echo $IPFSNODEID > $IPFSNODEIDFILE
|
|
PUBKEY=$(cat "$PUBKEYFILE" | xargs)
|
|
UNIT=$(cat "$UNITFILE" | xargs)
|
|
if [ -f "$NAMEFILE" ]; then MEMBER=$(cat "$NAMEFILE"); else MEMBER=""; fi
|
|
if [ -f "$RIBFILE" ]; then MEMRIB=$(cat "$RIBFILE"); else MEMRIB=""; fi
|
|
if [ -f "$UIDNAFILE" ]; then UIDNA=$(cat "$UIDNAFILE"); else UIDNA=""; fi
|
|
if [ -f "$DABUIDF" ]; then DABID=$(cat "$DABUIDF"); else DABID="$NODEUIDNA"; fi
|
|
|
|
AMOUNTG1=$(silkaj_balance $PUBKEY)
|
|
AMOUNTDU=$(bc <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
|
|
AMOUNTLOVE=$(bc <<< "$AMOUNTG1 * 100 / $DUFACTOR")
|
|
|
|
case "$UNIT" in
|
|
G1)
|
|
AMOUNT=$AMOUNTG1
|
|
;;
|
|
DU)
|
|
AMOUNT=$AMOUNTDU
|
|
;;
|
|
*)
|
|
AMOUNT=$AMOUNTLOVE
|
|
;;
|
|
esac
|
|
log "__SUB:sms_INIT_ACCOUNT: $AMOUNTG1 = $AMOUNT $UNIT"
|
|
|
|
# LOG # TODO SECURITY REMOVE PIN LOG!!
|
|
log "#####################"
|
|
log "PHONE: $PHONE"
|
|
log "PIN: $PIN"
|
|
log "PUBKEY: $PUBKEY"
|
|
log "G1: $AMOUNTG1"
|
|
log "AMOUNT: $AMOUNT $UNIT"
|
|
log "UIDNA: $UIDNA"
|
|
log "MEMBER: $MEMBER"
|
|
log "MEMRIB: $MEMRIB"
|
|
log "SMSEMAIL: $SMSEMAIL"
|
|
log "DABID: $DABID"
|
|
log "#####################"
|
|
|
|
|
|
log "__SUB:sms_INIT_ACCOUNT: END"
|
|
}
|
|
|
|
#################################################################################################################################
|
|
function check_account (){
|
|
|
|
AMOUNTG1=$(silkaj_balance $PUBKEY)
|
|
AMOUNTDU=$(bc <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
|
|
AMOUNTLOVE=$(bc <<< "$AMOUNTG1 * 100 / $DUFACTOR")
|
|
|
|
case "$UNIT" in
|
|
G1)
|
|
AMOUNT=$AMOUNTG1
|
|
;;
|
|
DU)
|
|
AMOUNT=$AMOUNTDU
|
|
;;
|
|
*)
|
|
AMOUNT=$AMOUNTLOVE
|
|
;;
|
|
esac
|
|
|
|
declare -a aaa
|
|
aaa=( "$AMOUNTG1" "$AMOUNT" "$UNIT" )
|
|
log "__SUB:check_account: $(declare -p aaa)"
|
|
echo ${aaa[@]}
|
|
}
|
|
|
|
|
|
#################################################################################################################################
|
|
function make_accounting (){
|
|
# CONVERT AMOUNT UNIT to VIR G1
|
|
case "$UNIT" in
|
|
G1)
|
|
VIR=$AMOUNT;
|
|
;;
|
|
DU)
|
|
VIR=$(bc -l <<< "scale=2; $AMOUNT * $DUFACTOR")
|
|
;;
|
|
LOVE)
|
|
VIR=$(bc -l <<< "scale=2; $AMOUNT * $DUFACTOR / 100")
|
|
;;
|
|
*)
|
|
VIR=$(bc -l <<< "scale=2; $AMOUNT * $DUFACTOR / 100")
|
|
;;
|
|
esac
|
|
|
|
###########################################################
|
|
# GET G1sms wallet AMOUNTG1 and CHECK for right balance
|
|
log "__SUB:make_accounting: LOCAL $VIR amount for $PHONE : $PUBKEY"
|
|
AMOUNTG1=$(silkaj_balance $PUBKEY)
|
|
if [[ "$AMOUNTG1" == "" ]]; then AMOUNTG1=0; fi
|
|
|
|
# TAX AND MINIMUM WALLET ACCOUNT CALCULATION
|
|
PERCENT=0$(bc -l <<< "scale=2; $VIR / $SWARMCOMM")
|
|
MIN=$(bc -l <<< "$AMOUNTG1 - $PERCENT - $LIMIT")
|
|
CHARGE=$(bc -l <<< "scale=2; $VIR + $PERCENT + $LIMIT")
|
|
TESTMIN=$( echo "${VIR} < ${MIN}" | bc -l )
|
|
log "__SUB:make_accounting: TEST $AMOUNT $UNIT :: $VIR + $PERCENT + $LIMIT = $CHARGE < $AMOUNTG1 ? $TESTMIN"
|
|
|
|
declare -a myarray
|
|
myarray=( "$TESTMIN" "$VIR" "$PERCENT" "$CHARGE")
|
|
log "__SUB:make_accounting: $(declare -p myarray)"
|
|
echo ${myarray[@]}
|
|
}
|
|
|
|
#################################################################################################################################
|
|
|
|
#################################################################################################################################
|
|
# Contact database management
|
|
function add_contact(){
|
|
userDB="gammu"
|
|
pwdDB=$(cat /etc/gammu-smsdrc | grep "password =" | awk '{ print $3 }' || exit 1)
|
|
local sql="mysql -N -u$userDB -p$pwdDB gammu -e"
|
|
|
|
local PHONE=$1
|
|
local MEMBERUID=$2
|
|
|
|
[[ -z $MEMBERUID ]] && MEMBERUID=$PHONE
|
|
|
|
[[ -z $($sql "SELECT * FROM pbk_groups WHERE ID='1'") ]] && $sql "INSERT INTO pbk_groups (ID, Name, id_user, is_public) VALUES ('1', '$(grep "ADRESSE" $MY_PATH/../.profile | awk -F= '{ print $2 }' | tr -d '"')', '1', 'false')"
|
|
|
|
if [[ -z $($sql "SELECT * FROM pbk WHERE Number=$PHONE") ]]; then
|
|
$sql "INSERT INTO pbk (GroupID, Name, Number, id_user, is_public) VALUES ('1', '$MEMBERUID', '$PHONE', '1', 'false')" || exit 1
|
|
local id_user=$($sql "SELECT ID FROM pbk WHERE Number=$PHONE" || exit 1)
|
|
$sql "INSERT INTO user_group (id_group, id_pbk, id_pbk_groups, id_user) VALUES ('$id_user', '$id_user', '1', '1')" || exit 1
|
|
else
|
|
log "${red}Contact already exist$c_"
|
|
fi
|
|
|
|
}
|
|
|
|
function rm_contact(){
|
|
userDB="gammu"
|
|
pwdDB=$(cat /etc/gammu-smsdrc | grep "password =" | awk '{ print $3 }' || exit 1)
|
|
local sql="mysql -N -u$userDB -p$pwdDB gammu -e"
|
|
|
|
local PHONE=$1
|
|
local MEMBERUID=$2
|
|
|
|
[[ -z $MEMBERUID ]] && MEMBERUID=$PHONE
|
|
|
|
if [[ ! -z $($sql "SELECT * FROM pbk WHERE Number=$PHONE") ]]; then
|
|
local id_user=$($sql "SELECT ID FROM pbk WHERE Number=$PHONE" || exit 1)
|
|
$sql "DELETE FROM pbk WHERE Number=$PHONE" || exit 1
|
|
$sql "DELETE FROM user_group WHERE id_group='$id_user'" || exit 1
|
|
else
|
|
log "${red}Contact doesn't exist$c_"
|
|
fi
|
|
|
|
}
|