summaryrefslogtreecommitdiff
path: root/src/main/scala/com/tylerstonge/honeypot/ftp/FtpHandler.scala
blob: 8a55396cbe5d8ac4bf89ad2156f89a6ac65465d6 (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
package com.tylerstonge.honeypot.ftp

import akka.actor.Actor
import akka.event.{Logging, LoggingAdapter}
import akka.io.Tcp.{PeerClosed, Received, Write}
import akka.util.ByteString

class FtpHandler extends Actor {
  val log: LoggingAdapter = Logging(context.system, this)

  override def receive: Receive = {
    case Received(data) =>
      log.info(">> {}", data.utf8String)
      sender() ! Write(ByteString.apply(parse(data.utf8String)))
    case PeerClosed =>
      log.info("closing connection")
      context.stop(self)
  }

  def parse(msg: String): String = msg match {
    case "USER anonymous\n" => "331 Please specify password.\n"
    case "PASS password\n" => "230 Login successful.\n"
    case "PWD\n" => "257 \"/\" is the current directory\n"
    case "QUIT\n" => "221 Goodbye.\n"
    case _ => "200 sure\n"
  }
}