########################################################
# T-Pot                                                #
# Dionaea upstart script                               #
#                                                      #
# v16.03.6 by mo, DTAG, 2016-03-03                     #
########################################################

description "Dionaea"
author "mo"
start on started docker and filesystem
stop on runlevel [!2345]
respawn
pre-start script
  # Remove any existing dionaea containers
  myCID=$(docker ps -a | grep dionaea | awk '{ print $1 }')
  if [ "$myCID" != "" ];
    then docker rm -v $myCID;
  fi
  # Remove any data from previous container if persistence is not enabled 
  if ! [ -f /data/persistence.on ];
    then
      rm -rf /data/dionaea/* || true
      rm /data/ews/dionaea/ews.json || true
      mkdir -p /data/dionaea/log /data/dionaea/bistreams /data/dionaea/binaries /data/dionaea/rtp /data/dionaea/wwwroot
      chmod 760 /data/dionaea -R
      chown tpot:tpot /data/dionaea -R
  fi
end script
script
  /usr/bin/docker run --name dionaea --cap-add=NET_BIND_SERVICE --rm=true -p 21:21 -p 42:42 -p 8081:80 -p 135:135 -p 443:443 -p 445:445 -p 1433:1433 -p 3306:3306 -p 5060:5060 -p 5061:5061 -p 69:69/udp -p 5060:5060/udp -v /data/dionaea:/data/dionaea -v /data/ews:/data/ews dtagdevsec/dionaea:latest1603
end script
post-start script
  # Delay next start to avoid rapid respawning
  sleep 2
end script
