#!/bin/sh

#
#  Returns XMLRPC caller IP (tcosmonitor IP)
#


if [ -e /conf/tcos-run-functions ]; then
  STANDALONE=/var
  export `grep SSL /conf/tcos.conf`
else
  STANDALONE=/var/lib/tcos/standalone
  . /etc/default/tcos-standalone
fi

pidssl="$(pidof stunnel4 | sed '/^$/d')"

# SSL enabled
if [ -f $STANDALONE/log/stunnel.log -a "$pidssl" != "" -a "$1" = "1" ]; then
  if [ "$TCOS_XMLRPC_SSL" = "1" ] || [ "$TCOS_ENABLE_SSL" = "1" ]; then
    grep "tcosxmlrpc accepted connection" $STANDALONE/log/stunnel.log |tail -1 | awk '{print $NF}'| awk -F ":" '{print $1}'
    exit 0
  fi
fi

# SSL disabled (not stunnel4 logs) read XMLRPC abyss log
if [ -f $STANDALONE/log/access.log ]; then
    tail -1 $STANDALONE/log/access.log | awk '{print $1}'
    exit 0
fi  



