add -w option for LAN situation, but WAN access through NAT + never output empty
This commit is contained in:
parent
f538db2835
commit
c0f074de19
|
@ -21,9 +21,8 @@ PARRAIN=$2
|
|||
TODAY=$(date '+%Y%m%d')
|
||||
log "__SUB:sms_AUTH.sh ($PHONE, $PARRAIN) $TODAY"
|
||||
|
||||
## INITIALIZE RESULT FILE
|
||||
# [[ $PHONE != "" ]] && sms_INIT_ACCOUNT "$PHONE" "NOSMS" || exit 1 # VERIFICATION ALREADY DONE BY CALLING bash
|
||||
#[[ $UNKNOWN == "unknown" ]] && echo "G1sms Wallet $PHONE inconnu! Envoyer N au $MASTERPHONE" && exit 1
|
||||
[[ $PHONE != "" ]] && sms_INIT_ACCOUNT "$PHONE" "NOSMS" || exit 1 # VERIFICATION ALREADY DONE BY CALLING bash ?
|
||||
[[ $UNKNOWN == "unknown" ]] && echo "G1sms Wallet $PHONE inconnu! Envoyer N au $MASTERPHONE" && exit 1
|
||||
|
||||
# Get AMOUNTG1, AMOUNTLOVE, AMOUNTDU
|
||||
AMOUNTG1=$(silkaj_balance $PUBKEY)
|
||||
|
@ -36,7 +35,7 @@ VIR=$(bc -l <<< "scale=2; $PARRAIN * $DUFACTOR / 100")
|
|||
# Need at least $MIN G1 available!
|
||||
MIN=$(bc -l <<< "$AMOUNTG1 - $LIMIT")
|
||||
testmin=$( echo "${VIR} < ${MIN}" | bc -l )
|
||||
SMSPIN=$((1000 + RANDOM % 9999))
|
||||
|
||||
|
||||
log "__SUB:sms_AUTH.sh: CODE $SMSPIN : $VIR < $MIN ? $testmin"
|
||||
if [[ "$testmin" -eq "1" ]]
|
||||
|
|
|
@ -19,20 +19,33 @@ MY_PATH="`dirname \"$0\"`" # relative
|
|||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||
ME="${0##*/}"
|
||||
|
||||
# check if -w is specified:
|
||||
# Will look for the public IP of my gateway
|
||||
# if my node is a Demilitarized Zone (DMZ)
|
||||
WAN=$1
|
||||
|
||||
# GNU DEBIAN Core install extension
|
||||
[[ ! $(which nslookup) ]] && sudo apt-get update && sudo apt-get install dnsutils -y
|
||||
|
||||
# What I am doing:
|
||||
# What is myIP?
|
||||
export myIP=$(hostname -I | awk '{print $1}')
|
||||
# Check if IP is from reserved LAN addresses
|
||||
export isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
|
||||
# Find 1st route gateway
|
||||
# Find default route gateway
|
||||
export myRouter=$(sudo route -n | head -n 3 | tail -n 1 | awk '{print $2}')
|
||||
# Ask to the router its name (BOX DNS or system defined)
|
||||
|
||||
# Ask to the router my name (BOX DNS or system defined)
|
||||
[[ $isLAN ]] && export NODENAME=$(sudo nslookup $myIP $myRouter | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//') \
|
||||
|| export NODENAME=$(sudo nslookup $myIP | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//')
|
||||
|
||||
if [[ -z "$NODENAME" && "$WAN" == "-w" ]]; then
|
||||
IP=`wget --quiet http://brouits.free.fr/ip.php -O- | sed 's/\r//'`
|
||||
NODENAME=`nslookup $IP | head -1 | cut -d'=' -f 2 | sed -E 's/^ *(.*)\.$/\1/'`
|
||||
fi
|
||||
|
||||
# We must have that nodename, perhaps BOX DNS doesn't exist...
|
||||
[[ $NODENAME == "" ]] && [[ $isLAN ]] && export NODENAME=$(sudo nslookup $myIP | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//')
|
||||
# OK no DNS is answering, let's be /etc/hostname
|
||||
[[ $NODENAME == "" ]] && NODENAME=$(cat /etc/hostname)
|
||||
|
||||
# I can tell
|
||||
|
|
Loading…
Reference in New Issue