#!/bin/sh
#

# new header not using prereqs
if [ "$1" = "prereqs" ]; then
  echo ""
  exit 0
fi


quiet=n

. /scripts/functions
. /conf/tcos.conf
. /conf/tcos-run-functions

nosslxmlrpc=$(read_cmdline_var "nosslxmlrpc" "0") 
if [ "${nosslxmlrpc}" = "1" ]; then 
  _log "SSL XMLRPC disabled from cmdline" 
  exit 0 
fi

  [ -e /etc/stunnel/tcos.pem ] && rm -f /etc/stunnel/tcos.pem 2>/dev/null
  openssl req -new -x509 -nodes -days 365 -out /etc/stunnel/tcos.pem -keyout /etc/stunnel/tcos.pem -subj "/C=/ST=/L=/CN=localhost/emailAddress=root@localhost" 2>/dev/null
  dd if=/dev/urandom of=/tmp/temp_file_ssl count=2 2>/dev/null
  openssl dhparam -rand /tmp/temp_file_ssl 256 >> /etc/stunnel/tcos.pem 2>/dev/null
  chmod 600 /etc/stunnel/tcos.pem 2>/dev/null
  rm -f /tmp/temp_file_ssl 2>/dev/null

  stunnel4 >/dev/null 2>&1 &
exit 0

