Improve logging
This commit is contained in:
parent
6d261b509b
commit
06cec4b5ed
|
@ -8,24 +8,24 @@
|
|||
MY_PATH="`dirname \"$0\"`" # relative
|
||||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||
if [[ -f $MY_PATH/.profile ]]; then
|
||||
source $MY_PATH/.profile
|
||||
source $MY_PATH/.profile
|
||||
elif [[ -f $MY_PATH/../.profile ]]; then
|
||||
source $MY_PATH/../.profile
|
||||
source $MY_PATH/../.profile
|
||||
else
|
||||
echo -e "${c_red}Le .profile n'existe pas$c_"
|
||||
exit 1
|
||||
echo -e "${c_red}Le .profile n'existe pas$c_"
|
||||
exit 1
|
||||
fi
|
||||
source /home/pi/.bash_aliases
|
||||
|
||||
# Adapter les valeurs au contexte spatio-temporel du NODE G1SMS
|
||||
function log () {
|
||||
# log ($1=text)
|
||||
if [ "$DOLOG" == "YES" ]
|
||||
then
|
||||
echo "$PHONE:$1" >> /tmp/g1sms.log
|
||||
fi
|
||||
if [ "$DOLOG" == "YES" ]
|
||||
then
|
||||
echo -e "$PHONE: $1" >> $logfile
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
###################################################################################################################################
|
||||
fn_exists() {
|
||||
# appended double quote is an ugly trick to make sure we do get a string -- if $1 is not a known command, type does not output anything
|
||||
|
@ -35,13 +35,12 @@ fn_exists() {
|
|||
if ! fn_exists gammu-smsd-inject; then
|
||||
log ":p) DESACTIVATION ENVOI DE SMS .............."
|
||||
function gammu-smsd-inject () {
|
||||
log "$PHONE: >>> SENDING SMS $4 TO $2 "
|
||||
log "$PHONE: >>> SENDING SMS $4 TO $2 "
|
||||
}
|
||||
else
|
||||
export G1SMS="YES"
|
||||
fi
|
||||
|
||||
|
||||
export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
|
||||
cd $GPATH
|
||||
##################################################################
|
||||
|
|
|
@ -41,9 +41,9 @@ function sms_SEND () {
|
|||
gammu-smsd-inject TEXT "$dest" -text "$mess" 1>&2
|
||||
fi
|
||||
else
|
||||
log ">>>>>>>>>>SMS ERROR BAD DESTINATION $dest"
|
||||
log "${c_red}>>>>>>>>>>SMS ERROR BAD DESTINATION $dest$c_"
|
||||
fi
|
||||
log ">>>>>>>>>> SENDING SMS $mess TO $dest via $DESTNODEID"
|
||||
log "${c_green}>>>>>>>>>> SENDING SMS$c_ \n$mess TO $dest via $DESTNODEID"
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,9 +56,9 @@ $2"
|
|||
if [[ ${#dest} -eq 10 || ${#dest} -eq 12 ]]; then
|
||||
gammu-smsd-inject TEXT "$dest" -text "$mess" 1>&2
|
||||
else
|
||||
log ">>>>>>>>>>SMS ERROR BAD DESTINATION $dest"
|
||||
log "${c_red}>>>>>>>>>>SMS ERROR BAD DESTINATION$c_ $dest"
|
||||
fi
|
||||
log ">>>>>>>>>> SENDING SMS $mess TO $dest"
|
||||
log "${c_red}>>>>>>>>>> SENDING SMS$c_ \n$mess TO $dest"
|
||||
# SEND ERROR COPY TO ADMINPHONE
|
||||
if [[ "$CPERROR" == "YES" ]]; then sms_SEND "$ADMINPHONE" "ADMIN! ERROR ($dest): $mess"; fi
|
||||
}
|
||||
|
@ -79,11 +79,11 @@ 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
|
||||
if [[ "$PHONE" == "$MASTERPHONE" || "$PHONE" == "" ]]; then log "${c_red}__SUB:security: SMS REJECTED !!$c_ $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
|
||||
if [[ "$PHONE" == "Orange Info" ]]; then log "${c_red}__SUB:security: SMS REJECTED !! $PHONE ADVERT$c_ $TEXT"; exit; fi
|
||||
if [[ ${#PHONE} -ne 12 && ${#PHONE} -ne 46 ]]; then log "${c_red}!! SMS REJECTED !! $PHONE BAD$c_ $TEXT"; exit; fi
|
||||
fi
|
||||
|
||||
# ANTI SPAM SMS (1 mn entre chaque commande)
|
||||
|
@ -98,7 +98,7 @@ if [[ "$CMD" != "DELIVERED" && "$CMD" != "PENDING" ]]; then
|
|||
echo $(date) > "/tmp/sms_SPAM_$PHONE"
|
||||
fi
|
||||
log "__SUB:security: ################################"
|
||||
log "__SUB:security: $PHONE COMMAND REJECTED: $TEXT"
|
||||
log "${c_red}__SUB:security: $PHONE COMMAND REJECTED:$c_ $TEXT"
|
||||
exit
|
||||
fi
|
||||
echo "$TEXT" > "/tmp/sms_received_$PHONE"
|
||||
|
@ -107,7 +107,7 @@ if [[ "$CMD" != "DELIVERED" && "$CMD" != "PENDING" ]]; then
|
|||
else
|
||||
# THIS IS AN AKNOWLEGEMENT
|
||||
log "__SUB:security: ################################"
|
||||
log "__SUB:security: $PHONE COMMAND REJECTED: $TEXT"
|
||||
log "${c_red}__SUB:security: $PHONE COMMAND REJECTED:$c_ $TEXT"
|
||||
exit
|
||||
fi
|
||||
# Remove SPAM flag older than one day
|
||||
|
@ -125,24 +125,25 @@ I=$(ipfs_node_wallets_add)
|
|||
# REFRESH SWARM MEMORY
|
||||
mkdir -p "./wallets_swarm"
|
||||
chown -R $YOU "./wallets_swarm"
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: REFRESHING SWARM $PHONE shared memory..."
|
||||
if [[ $PHONE ]]; then rm -Rf ./wallets_swarm/$PHONE; fi
|
||||
|
||||
log "${yellow}__SUB:ipfs_swarm_wallets_refresh: REFRESHING SWARM $HASHLINK ($PHONE) shared memory...$c_"
|
||||
if [[ $HASHLINK ]]; then rm -Rf ./wallets_swarm/PHONE/$HASHLINK; fi
|
||||
|
||||
# GET IPNS published wallets from ALL SWARM NODES / TODO: IF NODES MISSING, check ./wallets_swarm/.QmNODES...
|
||||
#log "__SUB:ipfs_swarm_wallets_refresh: IPFS: ipfs get --output=./wallets_swarm/ /ipns/$IPFSNODEID"
|
||||
su $YOU -c "ipfs get --output=./wallets_swarm/ /ipns/$IPFSNODEID"
|
||||
count=1
|
||||
# Search for All peers Nodes. TODO: To be changed when Swarm is too bug or not expendanding
|
||||
# Search for All peers Nodes. TODO: To be changed when Swarm is too big and stable
|
||||
for id in ./wallets_swarm/.Qm*/;
|
||||
#for id in $(su $YOU -c "ipfs swarm peers" | awk -F '/' '{print $7}');
|
||||
do
|
||||
count=$((count+1))
|
||||
id=$(echo $id | cut -d '.' -f 3 | cut -d '/' -f 1)
|
||||
#log "__SUB:ipfs_swarm_wallets_refresh: IPFS: ipfs get --output=./wallets_swarm/ /ipns/$id"
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: IPFS REFRESHING ./wallets_swarm/.$id"
|
||||
rm -Rf ./wallets_swarm/.$id
|
||||
su $YOU -c "ipfs get --output=./wallets_swarm/ /ipns/$id"
|
||||
done
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: ./wallets_swarm/ RENEW from $count peers .........OK!!!"
|
||||
log "${c_green}__SUB:ipfs_swarm_wallets_refresh: ./wallets_swarm/ RENEW from $count peers .........OK!!!$c_"
|
||||
|
||||
|
||||
############################################################################"
|
||||
|
@ -159,7 +160,7 @@ do
|
|||
TDEST=$( echo $FTASK | cut -d '.' -f 3) # $DESTPHONE
|
||||
HDEST=$(echo -n $TDEST | sha256sum | cut -d ' ' -f 1)
|
||||
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) FOUND TASK $TNANO:$TTYPE:$TDEST "
|
||||
log "${c_yellow}__SUB:ipfs_swarm_wallets_refresh:$c_ .$IPFSNODEID($FTASK) FOUND TASK $TNANO:$TTYPE:$TDEST"
|
||||
# MAKE LOCAL .$IPFSNODEID directory
|
||||
mkdir -p ./wallets/.$IPFSNODEID/TASK/
|
||||
# TODO: CHECK BETTER NOT DONE YET and $NANODATE > $TNANO (=> detect NODES writing in the future!!)
|
||||
|
@ -178,26 +179,26 @@ do
|
|||
newvalue=$(bc -l <<< "$curvalue + $ZENVAL")
|
||||
echo $newvalue > ./wallets/PHONE/$HDEST/_g1cents
|
||||
echo "OK.$tdiff" > ./wallets/.$IPFSNODEID/TASK/done.$TNANO
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) DONE! OPERATION: ($curvalue + $ZENVAL) = $newvalue Zen <=> ./wallets/PHONE/$HDEST/_g1cents:: OK"
|
||||
log "${c_green}__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) DONE!$c_ OPERATION: ($curvalue + $ZENVAL) = $newvalue Zen <=> ./wallets/PHONE/$HDEST/_g1cents:: OK"
|
||||
# REFRESH ./wallets and PUBLISH
|
||||
I=$(ipfs_node_wallets_add)
|
||||
else
|
||||
echo "KO.$tdiff" > ./wallets/.$IPFSNODEID/TASK/done.$TNANO
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) ERROR! BAD: ($curvalue + $ZENVAL) = $newvalue Zen <=> ./wallets/PHONE/$HDEST/_g1cents :: KO"
|
||||
log "${red}__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) ERROR!$c_ BAD: ($curvalue + $ZENVAL) = $newvalue Zen <=> ./wallets/PHONE/$HDEST/_g1cents :: ${red}KO$c_"
|
||||
I=$(ipfs_node_wallets_add)
|
||||
sms_SEND "$ADMINPHONE" "ADMIN! TASK ERROR: .$IPFSNODEID($FTASK) ERROR! BAD: ($curvalue + $ZENVAL) = $newvalue Zen <=> ./wallets/PHONE/$HDEST/_g1cents :: KO"
|
||||
fi
|
||||
else
|
||||
# TODO: Bad NODE in the Future task !!! Make better BAD Node detection = Swarm Banish?
|
||||
echo "KO.$tdiff" > ./wallets/.$IPFSNODEID/TASK/done.$TNANO
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) ERROR! DATE PROBLEM: $NANODATE < $TNANO :: KO"
|
||||
log "${red}__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID($FTASK) ERROR!$c_ DATE PROBLEM: $NANODATE < $TNANO :: ${red}KO$c_"
|
||||
I=$(ipfs_node_wallets_add)
|
||||
sms_SEND "$ADMINPHONE" "ADMIN! .$IPFSNODEID($FTASK) ERROR! DATE PROBLEM: $NANODATE < $TNANO :: KO"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: REMOVE OLD TASK MARKED AS DONE"
|
||||
log "${c_yellow}__SUB:ipfs_swarm_wallets_refresh:$c_ REMOVE OLD TASK MARKED AS DONE"
|
||||
for scan in ./wallets_swarm/.Qm*/TASK/done.*; do
|
||||
lscan=$(echo $scan | sed s/_swarm//g )
|
||||
lid=$(echo $scan | cut -d '/' -f 3 | cut -d '.' -f 2 )
|
||||
|
@ -209,7 +210,7 @@ done
|
|||
fi
|
||||
done
|
||||
else
|
||||
log "__SUB:ipfs_swarm_wallets_refresh: .$IPFSNODEID :: NO TASK ! "
|
||||
log "${c_yellow}__SUB:ipfs_swarm_wallets_refresh:$c_ .$IPFSNODEID :: NO TASK !"
|
||||
############################################################################"
|
||||
fi
|
||||
}
|
||||
|
@ -223,7 +224,7 @@ function ipfs_node_wallets_add (){
|
|||
|
||||
# CHAIN STATE FOR $IPFSNODEID
|
||||
echo $IWALLETS > ./wallets/.$IPFSNODEID.wallets.chain
|
||||
log "__SUB:ipfs_node_wallets_add: NEW './wallets' HASH ipfs ls /ipfs/$IWALLETS"
|
||||
log "${c_yellow}__SUB:ipfs_node_wallets_add:$c_ NEW './wallets' HASH ipfs ls /ipfs/$IWALLETS"
|
||||
|
||||
# PUBLISH IPNS NODE WALLETS
|
||||
NODEWALLETS=$(su $YOU -c "ipfs name publish --quieter /ipfs/$IWALLETS")
|
||||
|
@ -284,7 +285,7 @@ function sms_uid2pubkey (){
|
|||
# LOCAL G1sms account
|
||||
DESTRIB=$(cat ./wallets/PHONE/$LOCAL/_pub)
|
||||
DESTPHONE=$LOCAL
|
||||
log "__SUB:sms_uid2pubkey: FOUND LOCAL ($MASTERPHONE) G1sms Wallet: $DESTRIB ($DESTPHONE)"
|
||||
log "${c_yellow}__SUB:sms_uid2pubkey:$c_ FOUND LOCAL ($MASTERPHONE) G1sms Wallet: $DESTRIB ($DESTPHONE)"
|
||||
else
|
||||
# SEARCH IN WALLETS SWARM
|
||||
INSWARM=$(grep -Rwl "$ASKWALLET" ./wallets_swarm/PHONE/*/_uidna | tail -n 1 | cut -f 4 -d '/')
|
||||
|
@ -293,7 +294,7 @@ function sms_uid2pubkey (){
|
|||
REMOTENODEIPFSID=$(cat ./wallets_swarm/PHONE/$INSWARM/MASTERPHONE.ipfsid)
|
||||
DESTRIB=$(cat ./wallets_swarm/PHONE/$INSWARM/_pub)
|
||||
DESTPHONE=$INSWARM
|
||||
log "__SUB:sms_uid2pubkey: FOUND SWARM ($REMOTENODE) G1sms+ wallet: $DESTRIB ($DESTPHONE)"
|
||||
log "${c_green}__SUB:sms_uid2pubkey: FOUND SWARM ($REMOTENODE) G1sms+ wallet: $DESTRIB ($DESTPHONE)$c_"
|
||||
else
|
||||
# SEARCH FOR DUNITER MEMBER WITH SILKAJ
|
||||
log "__SUB:sms_uid2pubkey: GETTING FROM SILKAJ MEMBER ID"
|
||||
|
@ -309,7 +310,7 @@ function sms_uid2pubkey (){
|
|||
if [ "$DESTRIB" != "" ]; then
|
||||
echo "$DESTRIB" > "$RIBFILE"
|
||||
echo "$ASKWALLET" > "$NAMEFILE"
|
||||
log "__SUB:sms_uid2pubkey: NEW RELATED $DESTRIB FOR G1sms WALLET = $ASKWALLET - INIT 0.1 TX"
|
||||
log "${c_yellow}__SUB:sms_uid2pubkey:$c_ NEW RELATED $DESTRIB FOR G1sms WALLET = $ASKWALLET - INIT 0.1 TX"
|
||||
INIT=$(./silkaj/silkaj transaction --auth-scrypt -salt="$UIDNA" -password="$PIN" --amount="0.1" --output=$DESTRIB --comment="[G1sms+] Porte Monnaie $(cat $UIDNAFILE) -> $(cat $NAMEFILE)" -y)
|
||||
log "__SUB:sms_uid2pubkey: INIT = $INIT | Create Connection with related Wallet."
|
||||
log_history "$PHONE" "MEMBER, $ASKWALLET"
|
||||
|
@ -325,7 +326,7 @@ function sms_uid2pubkey (){
|
|||
|
||||
#################################################################################################################################
|
||||
function sms_INIT_ACCOUNT () {
|
||||
log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
||||
log "${c_yellow}__SUB:sms_INIT_ACCOUNT:$c_ ($1=phone, $2=NOSMS)"
|
||||
PHONE="$1"
|
||||
UNKNOWN=0
|
||||
# Initiate PHONE settings files and values
|
||||
|
@ -338,12 +339,12 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|||
SMSNODE="./wallets/PHONE/$PHONE/MASTERPHONE.sms" # Contains G1sms+ SMS phone number
|
||||
PINFILE="./wallets/PHONE/$PHONE/_pin" # Contains phone wallet diceware password
|
||||
GPGPINFILE="./wallets/PHONE/$PHONE/_pin.gpg" # Contains g1smsnode cypher phone wallet diceware password
|
||||
AUTHCRYPTFILE="./wallets/PHONE/$PHONE/_authfile.crypt" # TEST!!! crypt with $PHONE wallet keypair
|
||||
AUTHCRYPTFILE="./wallets/PHONE/$PHONE/_authfile.node.crypt" # authfile backup cyphered by Node G1 Pubkey
|
||||
PUBKEYFILE="./wallets/PHONE/$PHONE/_pub" # Contains phone wallet public key (RIB)
|
||||
UNITFILE="./wallets/PHONE/$PHONE/_unit" # Contains phone wallet prefered unit (LOVE,G1,DU)
|
||||
|
||||
RIBFILE="./wallets/PHONE/$PHONE/_uidrib" # Contains phone wallet related UID Pubkey
|
||||
NAMEFILE="./wallets/PHONE/$PHONE/_uidname" # Contains the member UID related to wallet
|
||||
NAMEFILE="./wallets/PHONE/$PHONE/_uidname" # Contains Related MEMBER UID or Wallet UIDNA
|
||||
MAILFILE="./wallets/PHONE/$PHONE/_email" # Contains the member EMAIL (Send BILLET)
|
||||
GPGMAILFILE="./wallets/PHONE/$PHONE/_email.gpg" # Contains the member EMAIL (Send BILLET)
|
||||
UIDNAFILE="./wallets/PHONE/$PHONE/_uidna" # Contains the G1sms+ UID Name for recursive VIR
|
||||
|
@ -353,12 +354,16 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|||
GPGRECFILE="./wallets/PHONE/$PHONE/VIREMENTS.gpg" # Cypher file with GPGPASS (Node .Identity.PrivKey)
|
||||
G1COUNTFILE="./wallets/PHONE/$PHONE/_g1cents" # Last sms_COUNT.sh call value
|
||||
CHAINFILE="./wallets/PHONE/$PHONE/_chain" # Contains wallet last IPFS hash before ZEN value change
|
||||
NNFILE="./wallets/PHONE/$PHONE/_n" # Contains Changes Number
|
||||
|
||||
DABUIDF="./wallets/PHONE/$PHONE/uidna.G1TAGNODE" # Contains G1Dab Name
|
||||
# GET CURRENT NODE UIDNA (default DABUID)
|
||||
NODEUIDNA=$(cat "./wallets/.$IPFSNODEID/_uidna")
|
||||
######################################################################
|
||||
# (NO PIN) = FIRST ACCOUNT: Create wallet
|
||||
|
||||
######################################################################
|
||||
######################################################################
|
||||
# (NO $PINFILE) = FIRST ACCOUNT: Create wallet
|
||||
######################################################################
|
||||
if [ ! -f "$PINFILE" ]; then
|
||||
# NOSMS mode? = DO NOT CREATE
|
||||
if [[ $2 == "NOSMS" ]]; then UNKNOWN="unknown"; return; fi
|
||||
|
@ -372,118 +377,70 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|||
fi
|
||||
# LINKS ARE NOT REPLICATED INTO IPFS ;)
|
||||
|
||||
PIN=$(./shell/diceware.sh | xargs)
|
||||
PUBKEY=$(./silkaj/silkaj generate_auth_file --auth-scrypt -salt="$UIDNA" -password="$PIN")
|
||||
|
||||
# BACKUP authfile available to authfile or PIN owner (DOUBLON AVEC PIN) TEST
|
||||
log "__SUB:sms_INIT_ACCOUNT: ./shell/natools.py encrypt -p $PUBKEY -i ""./authfile"" -o ""$AUTHCRYPTFILE"""
|
||||
./shell/natools.py encrypt -p $PUBKEY -i "./authfile" -o "$AUTHCRYPTFILE"
|
||||
rm -f ./authfile
|
||||
log "__SUB:sms_INIT_ACCOUNT: !! G1 Wallet CREATED: $PHONE $PIN : $PUBKEY"
|
||||
|
||||
#######################
|
||||
# GIVE NAME TO WALLET
|
||||
#######################
|
||||
# 4 derniers chiffres du numéro de téléphone
|
||||
TAIL=${PHONE:8:4}
|
||||
# No UIDNA yet. Create new
|
||||
UIDNA=$(./shell/diceware.sh 1 | xargs)
|
||||
UID=$(./shell/diceware.sh 1 | xargs)
|
||||
# Check if already existing among all swarm wallets
|
||||
while [[ $(grep -Rwl $UIDNA$TAIL ./wallets_swarm/*/*.uidna) ]]; do UIDNA=$(./shell/diceware.sh 1 | xargs); done
|
||||
echo "$UIDNA$TAIL" > "$UIDNAFILE"
|
||||
while [[ $(grep -Rwl $UID$TAIL ./wallets_swarm/*/*.uidna) ]]; do UID=$(./shell/diceware.sh 1 | xargs); done
|
||||
UIDNA=$UIDNA$TAIL
|
||||
echo "$UIDNA" > "$UIDNAFILE"
|
||||
|
||||
PIN=$(./shell/diceware.sh | xargs)
|
||||
PUBKEY=$(./silkaj/silkaj generate_auth_file --auth-scrypt -salt="$UIDNA" -password="$PIN")
|
||||
|
||||
# BACKUP authfile available to authfile or PIN owner (DOUBLON AVEC PIN) TEST
|
||||
log "__SUB:sms_INIT_ACCOUNT: ./shell/natools.py encrypt -p $NODE_G1PUBKEY -i ""./authfile"" -o ""$AUTHCRYPTFILE"""
|
||||
./shell/natools.py encrypt -p $NODE_G1PUBKEY -i "./authfile" -o "$AUTHCRYPTFILE"
|
||||
rm -f ./authfile
|
||||
log "__SUB:sms_INIT_ACCOUNT: !! G1 Wallet CREATED: $PHONE $PIN : $PUBKEY (HASHLINK=$HASHLINK)"
|
||||
#######################
|
||||
# ACTIVATE G1SMS WALLET
|
||||
#######################
|
||||
# log "$NODE_G1AUTHFILE $PUBKEY THIRD_PARTY_MANAGER:$NODE_G1PUBKEY"
|
||||
TX_IN=$(./silkaj/silkaj transaction --auth-file -file="$NODE_G1AUTHFILE" --amount=3.24 --output=$PUBKEY --comment="[G1sms+] $UIDNA$TAIL 3RD:$NODE_G1PUBKEY " -y)
|
||||
TX_IN=$(./silkaj/silkaj transaction --auth-file -file="$NODE_G1AUTHFILE" --amount=3.24 --output=$PUBKEY --comment="[G1sms+] $UIDNA 3RD:$NODE_G1PUBKEY " -y)
|
||||
log "__SUB:sms_INIT_ACCOUNT: G1 Wallet TX IN: $TX_IN"
|
||||
sleep 2
|
||||
TX_OUT=$(./silkaj/silkaj transaction --auth-scrypt -salt="$PHONE" -password="$PIN" --amount=0.1 --output=$NODE_G1PUBKEY --comment="[G1sms+] $UIDNA$TAIL 3RD:$NODE_G1PUBKEY:ACK" -y)
|
||||
TX_OUT=$(./silkaj/silkaj transaction --auth-scrypt -salt="$UIDNA" -password="$PIN" --amount=0.1 --output=$NODE_G1PUBKEY --comment="[G1sms+] $UIDNA 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 "${GPGPASS}" | gpg -q --output "$GPGPINFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE"
|
||||
echo "${SWARMKEY}" | gpg -q --output "$GPGPINFILE.swarm" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE"
|
||||
PIN=$(cat "$PINFILE" | xargs)
|
||||
# echo "${GPGPASS}" | gpg -q --output "$GPGPINFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE"
|
||||
./shell/natools.py encrypt -p $NODE_G1PUBKEY -i "$PINFILE" -o "$PINFILE.node.crypt"
|
||||
./shell/natools.py encrypt -p $SWARM_G1PUBKEY -i "$PINFILE" -o "$PINFILE.swarm.crypt"
|
||||
# EMPTY CLEAR PIN
|
||||
echo "" > "$PINFILE"
|
||||
|
||||
# WRITE G1sms WALLET FILES
|
||||
echo "314" > "$G1COUNTFILE"
|
||||
echo "0" > "$NNFILE"
|
||||
echo "$PUBKEY" > "$PUBKEYFILE"
|
||||
echo "$COIN" > "$UNITFILE"
|
||||
echo "$MASTERPHONE" > "$SMSNODE"
|
||||
log_history "$PHONE" "NEW, $PUBKEY"
|
||||
|
||||
# ADD WALLET TO IPFS
|
||||
# PUSH WALLET TO IPFS
|
||||
I=$(ipfs_node_wallets_add)
|
||||
fi
|
||||
|
||||
|
||||
#################################################
|
||||
# PUBLISH G1sms+ WALLET PROPERTIES MAIN PROCESS
|
||||
#################################################
|
||||
######################################################################
|
||||
if [[ ! -f "$GPGPINFILE" ]]
|
||||
then
|
||||
HASH=$(echo -n $PHONE | sha256sum | cut -d ' ' -f 1)
|
||||
log "__SUB:sms_INIT_ACCOUNT: decrypting PIN..."
|
||||
# GPG decypher PIN
|
||||
# TODO make decypher less stress on filesystem, use /tmp and ramdisk
|
||||
# echo "${GPGPASS}" | gpg -d -q --output "$PINFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGPINFILE"
|
||||
[[ "$PIN" == "" ]] && ./shell/natools.py decrypt -k "$NODE_G1AUTHFILE" -i "$PINFILE.node.crypt" -o "$PINFILE" && PIN=$(cat "$PINFILE" | xargs) && echo "" > "$PINFILE";
|
||||
|
||||
# ------------8<------------------
|
||||
# WALLET MIGRATION -> CRYPT PIN (For Old G1sms clear PIN WALLETs...)
|
||||
if [[ ! -s "$UIDNAFILE" ]]; then
|
||||
# ADD NEW PARAMS TO WALLET
|
||||
#######################
|
||||
# 4 derniers chiffres du numéro de téléphone
|
||||
TAIL=${PHONE:8:4}
|
||||
# No UIDNA yet. Create new
|
||||
UIDNA=$(./shell/diceware.sh 1 | xargs)
|
||||
# Check if already existing among all swarm wallets
|
||||
while [[ $(grep -Rwl $UIDNA$TAIL ./wallets_swarm/*/*.uidna) ]]; do UIDNA=$(./shell/diceware.sh 1 | xargs); done
|
||||
echo "$UIDNA$TAIL" > "$UIDNAFILE"
|
||||
fi
|
||||
|
||||
echo "$MASTERPHONE" > "$SMSNODE"
|
||||
PIN=$(cat "$PINFILE" | xargs)
|
||||
log "__SUB:sms_INIT_ACCOUNT: Old G1sms wallet ;) SECURITY HOLE... Chiffrage PGP du PIN !!!"
|
||||
echo "${GPGPASS}" | gpg -q --output "$GPGPINFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE";
|
||||
echo "${SWARMKEY}" | gpg -q --output "$GPGPINFILE.swarm" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE";
|
||||
else
|
||||
# ------------>8------------------
|
||||
log "__SUB:sms_INIT_ACCOUNT: Déchiffrage PGP PIN..."
|
||||
# GPG decypher PIN
|
||||
# TODO make decypher less stress on filesystem, use /tmp and ramdisk
|
||||
echo "${GPGPASS}" | gpg -d -q --output "$PINFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGPINFILE"
|
||||
[[ ! -f $PINFILE ]] && echo "${SWARMKEY}" | gpg -d -q --output "$PINFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGPINFILE.swarm"
|
||||
PIN=$(cat "$PINFILE" | xargs)
|
||||
echo "" > "$PINFILE";
|
||||
fi
|
||||
|
||||
# CYPHER EMAIL FILE
|
||||
if [[ ! -f "$GPGMAILFILE.swarm" ]]; then
|
||||
# ------------8<------------------
|
||||
# NO .gpg file, CREATING it (OLD G1sms accounts)
|
||||
if [ -f "$MAILFILE" ]; then
|
||||
MAIL=$(cat "$MAILFILE");
|
||||
echo "${GPGPASS}" | gpg -q --output "$GPGMAILFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$MAILFILE";
|
||||
echo "${SWARMKEY}" | gpg -q --output "$GPGMAILFILE.swarm" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$MAILFILE";
|
||||
else
|
||||
MAIL="";
|
||||
fi
|
||||
# ------------>8------------------
|
||||
else
|
||||
# Already existing gpg DECODING IT
|
||||
echo "${GPGPASS}" | gpg -d -q --output "$MAILFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGMAILFILE"
|
||||
[[ -f "$GPGMAILFILE.swarm" ]] && echo "${SWARMKEY}" | gpg -d -q --output "$MAILFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGMAILFILE.swarm"
|
||||
MAIL=$(cat "$MAILFILE");
|
||||
echo "" > "$MAILFILE";
|
||||
fi
|
||||
|
||||
# ------------8<------------------
|
||||
# REMOVE OLD HISTORY FILES
|
||||
rm -f ./wallets/$PHONE/$PHONE.hist
|
||||
# ------------>8------------------
|
||||
# DECYPHER MAIL
|
||||
[[ -f "$MAILFILE.node.crypt" ]] && ./shell/natools.py decrypt -k "$NODE_G1AUTHFILE" -i "$MAILFILE.node.crypt" -o "$MAILFILE" && MAIL=$(cat "$MAILFILE") && echo "" > "$MAILFILE";
|
||||
|
||||
# PUBLISH GLOBAL VARS FROM ACCOUNT FILES
|
||||
echo $IPFSNODEID > $IPFSNODEIDFILE
|
||||
|
@ -513,9 +470,9 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|||
log "__SUB:sms_INIT_ACCOUNT: $AMOUNTG1 = $AMOUNT $UNIT"
|
||||
|
||||
# LOG # TODO REMOVE PIN LOG!!
|
||||
log "#####################"
|
||||
log "${c_yellow}#####################$c_"
|
||||
log "PHONE: $PHONE"
|
||||
log "PIN: $PIN"
|
||||
# log "PIN: $PIN"
|
||||
log "PUBKEY: $PUBKEY"
|
||||
log "G1: $AMOUNTG1"
|
||||
log "AMOUNT: $AMOUNT $UNIT"
|
||||
|
@ -524,10 +481,10 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
|
|||
log "MEMRIB: $MEMRIB"
|
||||
log "MAIL: $MAIL"
|
||||
log "DABID: $DABID"
|
||||
log "#####################"
|
||||
log "${c_yellow}#####################$c_"
|
||||
|
||||
|
||||
log "__SUB:sms_INIT_ACCOUNT: END"
|
||||
log "${c_green}__SUB:sms_INIT_ACCOUNT: END$c_"
|
||||
}
|
||||
|
||||
|
||||
|
@ -554,30 +511,31 @@ G1cents=$(echo "$AMOUNTG1*100" | bc -l | awk '{print int($0)}')
|
|||
log "__SUB:check_account: $PHONE: $AMOUNTG1 = $AMOUNT $UNIT ($G1cents) - $PUBKEY"
|
||||
|
||||
if [[ "$G1cents" != "" ]]; then
|
||||
NN=$(cat "./wallets/$PHONE/$PHONE.n")
|
||||
NN=$(cat "./wallets/PHONE/$PHONE/_n") || NN=0
|
||||
((NN++))
|
||||
echo "$NN" > "./wallets/$PHONE/$PHONE.n"
|
||||
echo $G1cents > "./wallets/$PHONE/$PHONE.g1cents"
|
||||
echo "$NN" > "./wallets/PHONE/$PHONE/_n"
|
||||
echo $G1cents > "./wallets/PHONE/$PHONE/_g1cents"
|
||||
echo "$NANODATE" > "./wallets/PHONE/$PHONE/_nanodate"
|
||||
# REFRESH NODE IPFS wallets & PUBLISH
|
||||
I=$(ipfs_node_wallets_add)
|
||||
# Register modification
|
||||
echo "$I" > "./wallets/$PHONE/$PHONE.chain"
|
||||
echo "$I" > "./wallets/PHONE/$PHONE/_chain"
|
||||
else
|
||||
# BAN actual Duniter Node in case of silkaj timeout.
|
||||
export NEWDUNITER=$(./shell/checknodes.sh 'BAN')
|
||||
log "__SUB:check_account: !!! SILKAJ IS TOO SLOW !!! => NEW DUNITER SERVER: $NEWDUNITER"
|
||||
log "${c_red}__SUB:check_account: !!! SILKAJ IS TOO SLOW !!!$c_ => NEW DUNITER SERVER: $NEWDUNITER"
|
||||
fi
|
||||
|
||||
declare -a aaa
|
||||
aaa=( "$AMOUNTG1" "$AMOUNT" "$UNIT" )
|
||||
log "__SUB:check_account: $(declare -p aaa)"
|
||||
echo ${aaa[@]}
|
||||
declare -a walletvalues
|
||||
walletvalues=( "$AMOUNTG1" "$AMOUNT" "$UNIT" )
|
||||
log "__SUB:check_account: $(declare -p walletvalues)"
|
||||
echo ${walletvalues[@]}
|
||||
}
|
||||
|
||||
|
||||
#################################################################################################################################
|
||||
function make_accounting (){
|
||||
# CONVERT AMOUNT UNIT to VIR G1
|
||||
# CONVERT $AMOUNT $UNIT to $VIR G1
|
||||
case "$UNIT" in
|
||||
G1)
|
||||
VIR=$AMOUNT;
|
||||
|
@ -589,22 +547,25 @@ LOVE)
|
|||
VIR=$(bc -l <<< "scale=2; $AMOUNT * $DUFACTOR / 100")
|
||||
;;
|
||||
*)
|
||||
VIR=$(bc -l <<< "scale=2; $AMOUNT * $DUFACTOR / 100")
|
||||
VIR=$AMOUNT;
|
||||
;;
|
||||
esac
|
||||
|
||||
log "${c_yellow}__SUB:make_accounting:$c_ $VIR G1 CHECKING FOR $PHONE / PUBKEY = $PUBKEY"
|
||||
|
||||
###########################################################
|
||||
# GET G1sms wallet AMOUNTG1 and CHECK for right balance
|
||||
log "__SUB:make_accounting: LOCAL $VIR amount for $PHONE : $PUBKEY"
|
||||
# Try to ask silkaj. If timeout, use SWARM last known $PHONE.g1cents value
|
||||
# Ask silkaj. If timeout, use last known $PHONE _g1cents value
|
||||
AMOUNTG1=$(./shell/timeout.sh -t 20 ./silkaj/silkaj amount "$PUBKEY")
|
||||
if [[ ! $AMOUNTG1 ]]; then AMOUNTG1=$(bc -l <<< "scale=2; $(cat ./wallets_swarm/$PHONE/_g1cents) / 100"); fi
|
||||
if [[ "$AMOUNTG1" == "" ]]; then AMOUNTG1=0; fi
|
||||
[[ ! $AMOUNTG1 ]] && AMOUNTG1=$(bc -l <<< "scale=2; $(cat ./wallets/PHONE/$PHONE/_g1cents) / 100")
|
||||
[[ "$AMOUNTG1" == "" ]] && AMOUNTG1=0
|
||||
|
||||
# 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
|
||||
|
@ -621,7 +582,7 @@ function move_g1cents (){
|
|||
phonesrc=$1
|
||||
pubkeydest=$2
|
||||
zenvalue=$3
|
||||
log "__SUB:move_g1cents: $phonesrc ($zenvalue) -> $pubkeydest :: $G1COUNTFILE ::"
|
||||
log "${c_yellow}__SUB:move_g1cents:$c_ $phonesrc ($zenvalue) -> $pubkeydest :: $G1COUNTFILE ::"
|
||||
|
||||
### CHANGE INPUT VALUE ####
|
||||
curvalue=$(cat ./wallets/$phonesrc/$phonesrc.g1cents | cut -d '.' -f 1)
|
||||
|
@ -655,7 +616,7 @@ function move_g1cents (){
|
|||
rm -f /tmp/move_g1cents.$winnerphone
|
||||
fi
|
||||
else
|
||||
log "__SUB:move_g1cents: ERROR: NO $pubkeydest WALLET FOUND"
|
||||
log "${c_red}__SUB:move_g1cents: ERROR: NO $pubkeydest WALLET FOUND$c_"
|
||||
fi
|
||||
# UPDATE MY new ./wallet STATUS to SWARM
|
||||
I=$(ipfs_node_wallets_add)
|
||||
|
@ -665,6 +626,7 @@ function move_g1cents (){
|
|||
#################################################################################################################################
|
||||
# Contact database management
|
||||
function add_contact(){
|
||||
log "${c_yellow}Add user contact$c_"
|
||||
userDB="gammu"
|
||||
pwdDB=$(cat /etc/gammu-smsdrc | grep "password =" | awk '{ print $3 }' || exit 1)
|
||||
local sql="mysql -N -u$userDB -p$pwdDB gammu -e"
|
||||
|
@ -680,6 +642,7 @@ function add_contact(){
|
|||
$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
|
||||
log "${c_green}Done$c_"
|
||||
else
|
||||
log "${red}Contact already exist$c_"
|
||||
fi
|
||||
|
@ -687,6 +650,7 @@ function add_contact(){
|
|||
}
|
||||
|
||||
function rm_contact(){
|
||||
log "${c_yellow}Remove user contact$c_"
|
||||
userDB="gammu"
|
||||
pwdDB=$(cat /etc/gammu-smsdrc | grep "password =" | awk '{ print $3 }' || exit 1)
|
||||
local sql="mysql -N -u$userDB -p$pwdDB gammu -e"
|
||||
|
@ -700,6 +664,7 @@ function rm_contact(){
|
|||
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
|
||||
log "${c_green}Done$c_"
|
||||
else
|
||||
log "${red}Contact doesn't exist$c_"
|
||||
fi
|
||||
|
|
|
@ -37,6 +37,7 @@ export YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
|
|||
cd $MY_PATH
|
||||
source $MY_PATH/shell/init.sh
|
||||
source $MY_PATH/shell/functions.sh
|
||||
date=$(date '+%D à %H:%M')
|
||||
|
||||
##################################################################
|
||||
# Get global variables from gammu-smsd
|
||||
|
@ -46,13 +47,12 @@ TEXT="$SMS_1_TEXT"
|
|||
CMD=$(echo "$TEXT" | awk '{print toupper($1)}')
|
||||
|
||||
log "##########################################################################################"
|
||||
log "#################################### ${c_yellow}$date$c_ ####################################"
|
||||
log "##########################################################################################"
|
||||
log "${c_green}SMS received $PHONE $TEXT$c_"
|
||||
log "#############################################"
|
||||
log "#############################################"
|
||||
log "$(date)"
|
||||
log "SMS received $PHONE $TEXT"
|
||||
log "#############################################"
|
||||
log "NODE: ALL WALLETS: ipfs ls /ipns/$IPFSNODEID"
|
||||
log "NODE: G1wallet: cat ./wallets/.$IPFSNODEID/NODE.pub"
|
||||
log "${$c_yellow}NODE: ALL WALLETS: ipfs ls /ipns/$IPFSNODEID$c_"
|
||||
log "${$c_yellow}NODE: G1wallet: cat ./wallets/.$IPFSNODEID/NODE.pub$c_"
|
||||
log "#############################################"
|
||||
|
||||
##################################################################
|
||||
|
@ -73,7 +73,7 @@ then
|
|||
NODEPHONE=$(cat "./wallets_swarm/$PHONE/MASTERPHONE.sms")
|
||||
if [[ "$NODEPHONE" != "$MASTERPHONE" && "$NODEPHONE" != "" ]]; then
|
||||
sms_SEND "$PHONE" "[G1sms+] Vous avez déjà un compte portefeuille sur $NODEPHONE (Envoyez lui RAZ si vous voulez fermer votre compte)"
|
||||
log "ALERT!! $PHONE compte existant sur le NODE G1sms+ ($NODEPHONE)"
|
||||
log "${c_red}ALERT!! $PHONE compte existant sur le NODE G1sms+ ($NODEPHONE)$c_"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
|
@ -203,7 +203,7 @@ case "$CMD" in
|
|||
;;
|
||||
*)
|
||||
#./shell/sms_ERROR.sh "$PHONE" "$TEXT" &
|
||||
log "SMS forward to $ADMINPHONE"
|
||||
log "${$c_yellow}SMS forward to $ADMINPHONE$c_"
|
||||
sms_SEND "$ADMINPHONE" "ADMIN! BAD SMS FROM $PHONE
|
||||
$TEXT"
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue