#!/bin/bash
cd `dirname $0`
VISUREIP=`host www.visureinrete.it | cut -d' ' -f4`
MYIP=`ifconfig | sed 's/addr://' | awk '/inet 10\.1\./ { print $2; }'`
BRPORT=44443

echo DEBUG=./portbridge $BRPORT $VISUREIP 443
./portbridge $BRPORT $VISUREIP 443 >/dev/null 2>&1 &
BRPID=$!

RESULT=0
#curl -s  -H HOST:www.spintec.it http://10.1.0.1:8880/piva_to_addr/ -d key=1234567890 -d piva="$1" -d bridge=$MYIP:$BRPORT
#echo CURL=curl -s  http://10.1.0.1/e3g_services/piva_to_addr/index.php -d key=1234567890 -d piva="$1" -d bridge=$MYIP:$BRPORT
curl --max-time 6 --connect-timeout 4 -s  http://10.1.0.1/e3g_services/piva_to_addr/index.php -d key=1234567890 -d piva="$1" -d bridge=$MYIP:$BRPORT
if [ $? -gt 0 ]; then
  echo STATUS=ERROR_NETWORK
  RESULT=1
fi
kill $BRPID 2>/dev/null 
wait $BRPID 2>/dev/null
#exit $RESULT
exit 0
