summaryrefslogtreecommitdiff
path: root/src/main/scala/com/tylerstonge/honeypot/ftp/FtpListener.scala
blob: 9e98a398377acc2327f415a16cdb1a03ae263d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.tylerstonge.honeypot.ftp

import java.net.InetSocketAddress

import akka.actor.{Actor, Props}
import akka.event.{Logging, LoggingAdapter}
import akka.io.Tcp._
import akka.io.{IO, Tcp}
import akka.util.ByteString
import com.tylerstonge.honeypot.messages.MNewConnection

object FtpListener {
  def props(port: Int): Props = Props(new FtpListener(port))
}

class FtpListener(port: Int) extends Actor {

  val log: LoggingAdapter = Logging(context.system, this)
  IO(Tcp)(context.system) ! Bind(self, new InetSocketAddress("0.0.0.0", port))

  override def receive: Receive = {
    case Bound(localAddress) =>
      log.info("listening on {}", localAddress)
    case CommandFailed(_: Bind) => context.stop(self)
    case Connected(remote, _) =>
      val connection = sender()
      val handler = context.actorOf(FtpHandler.props(connection))
      context.system.eventStream.publish(MNewConnection(remote.getHostString))
      connection ! Register(handler)
      connection ! Write(ByteString.apply("220 (vulnFTPd 2.0.1)\n"))
  }
}