Skip to content

Commit

Permalink
Merge branch 'play26'
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-lange committed Sep 2, 2017
2 parents 8b0b111 + 7eb3bfc commit dc7d458
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 28 deletions.
5 changes: 3 additions & 2 deletions app/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import com.google.inject.AbstractModule
import org.pcap4j.core.{PcapNativeException, Pcaps}
import play.api.Logger

import scala.collection.JavaConverters._

class Module extends AbstractModule {

private val logger: Logger = Logger(this.getClass)

def configure() = {
// Print out all network interfaces so users know which names they have
try {
import scala.collection.JavaConversions._
for (nif <- Pcaps.findAllDevs) {
for (nif <- Pcaps.findAllDevs.asScala) {
Logger.info("NIF: " + nif.toString)
}
} catch {
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/ExtAssets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import javax.inject.Inject

import play.Environment
import play.api.Logger
import play.api.mvc.{Action, Controller}
import play.api.mvc.{AbstractController, ControllerComponents}
import scala.concurrent.ExecutionContext.Implicits.global

/**
* Controller for loading of external files (outside of jar)
*
* Created by Kristian Lange in 2017.
*
*/
class ExtAssets @Inject()(environment: Environment) extends Controller {
class ExtAssets @Inject()(environment: Environment,
controllerComponents: ControllerComponents)
extends AbstractController(controllerComponents) {

private val logger: Logger = Logger(this.getClass)

Expand Down
10 changes: 6 additions & 4 deletions app/controllers/Home.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import javax.inject._

import akka.actor.ActorSystem
import akka.stream.Materializer
import play.Configuration
import play.api.Configuration
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._
Expand All @@ -17,20 +17,22 @@ import services.{PcapInitializer, WebSocketActor}
class Home @Inject()(implicit actorSystem: ActorSystem,
materializer: Materializer,
configuration: Configuration,
pcapInitializer: PcapInitializer) extends Controller {
pcapInitializer: PcapInitializer,
controllerComponents: ControllerComponents)
extends AbstractController(controllerComponents) {

/**
* Default network interface (specified in application.conf)
*/
private val defaultNifName = configuration.getString("nif", "empty")
private val defaultNifName = configuration.get[String]("nif")

/**
* This endpoint serves WebSockets that stream network header data
*
* @param nif Network interface name of the interface to be intercepted
* @return WebSocket that streams network header data
*/
def netdata(nif: String = defaultNifName) = WebSocket.accept[JsValue, JsValue] {
def netdata(nif: String = defaultNifName): WebSocket = WebSocket.accept[JsValue, JsValue] {
_ => {
val nifDispatcher =
if (nif != null && nif.nonEmpty) pcapInitializer.getNifDispatcher(nif)
Expand Down
4 changes: 2 additions & 2 deletions app/services/PacketToJsonTransfer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package services
import java.sql.Timestamp

import org.pcap4j.packet._
import play.api.libs.json.{JsString, Json}
import play.api.libs.json.{JsString, JsValue, Json}

/**
* Utility class that extracts data from network packets and puts them into JSON
Expand All @@ -12,7 +12,7 @@ import play.api.libs.json.{JsString, Json}
*/
object PacketToJsonTransfer {

def packageToJson(packet: Packet, timestamp: Timestamp) = {
def packageToJson(packet: Packet, timestamp: Timestamp): JsValue = {
var json = Json.obj()
json += ("timestamp", JsString(timestamp.toString))
if (packet.contains(classOf[EthernetPacket]))
Expand Down
10 changes: 5 additions & 5 deletions app/services/PcapInitializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.inject.{Inject, Singleton}
import akka.actor.{ActorRef, ActorSystem}
import org.pcap4j.core._
import org.pcap4j.packet.{IpPacket, Packet, TcpPacket}
import play.Configuration
import play.api.Configuration
import play.api.Logger
import play.api.inject.ApplicationLifecycle

Expand All @@ -32,23 +32,23 @@ class PcapInitializer @Inject()(implicit actorSystem: ActorSystem,
* If false net-glimpse filters out its own traffic
* (specified in application.conf)
*/
private val skipOwnTraffic = configuration.getBoolean("skipOwnTraffic", true)
private val skipOwnTraffic = configuration.get[Boolean]("skipOwnTraffic")

/**
* IP / host the Play framework is bound to (default 0.0.0.0)
*/
private val httpAddress = configuration.getString("play.server.http.address")
private val httpAddress = configuration.get[String]("play.server.http.address")

/**
* Port the Play framework is bound to (default 9000)
*/
private val httpPort = configuration.getInt("play.server.http.port")
private val httpPort = configuration.get[Int]("play.server.http.port")

/**
* Specifies the portion of the network packet to capture
* https://serverfault.com/questions/253613
*/
private val snaplen = configuration.getInt("snaplen", 65536)
private val snaplen = configuration.get[Int]("snaplen")

/**
* Map: network interface name -> actor reference to [[NifDispatcherActor]]
Expand Down
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name := """net-glimpse"""

version := "1.6"
version := "1.7"

lazy val root = (project in file(".")).enablePlugins(PlayJava)
lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.11"
scalaVersion := "2.12.2"

libraryDependencies ++= Seq(
guice,
"com.typesafe.play" %% "play-json" % "2.6.0",
"org.pcap4j" % "pcap4j-core" % "1.7.1",
"org.pcap4j" % "pcap4j-packetfactory-static" % "1.7.1"
)
Expand Down
12 changes: 11 additions & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Defines which network interface to listen to in case there is none specified
# in the URL query string.
# It uses the run parameter '-Dnif' (e.g. -Dnif=wlp3s0).
nif="empty"
nif=${?nif}

# If true net-glimpse filters out its own traffic.
Expand All @@ -14,7 +15,16 @@ skipOwnTraffic=${?skipOwnTraffic}
snaplen=128
snaplen=${?snaplen}

# Where to find asset files
# https://www.playframework.com/documentation/2.6.x/AssetsOverview
play.assets.path="/public"
play.assets.urlPrefix="/assets"

# https://www.playframework.com/documentation/2.6.x/SecurityHeaders
play.filters.headers.contentTypeOptions=null
play.filters.headers.contentSecurityPolicy=null

# It's not necessary to change Play's secret since net-glimpse doesn't use
# session cookies or encryption
# https://www.playframework.com/documentation/2.6.x/ApplicationSecret
play.crypto.secret="zj97lcqp896relv8dsZdAsGeTivm72pq3p52nLfdoa5DCfuKjGoc4Rj"
play.http.secret.key="zj97lcqp896relv8dsZdAsGeTivm72pq3p52nLfdoa5DCfuKjGoc4Rj"
10 changes: 5 additions & 5 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# This file defines all application routes (Higher priority routes first)
# ~~~~

GET / controllers.Assets.at(path="/public", file="index.html")
GET /glimpse controllers.Assets.at(path="/public", file="glimpse.html")
GET /ipglimpse controllers.Assets.at(path="/public", file="ipglimpse.html")
GET /etherglimpse controllers.Assets.at(path="/public", file="etherglimpse.html")
GET / controllers.Assets.at(file="index.html")
GET /glimpse controllers.Assets.at(file="glimpse.html")
GET /ipglimpse controllers.Assets.at(file="ipglimpse.html")
GET /etherglimpse controllers.Assets.at(file="etherglimpse.html")
GET /netdata controllers.Home.netdata(nif ?= null)

GET /assets/glimpse.conf controllers.ExtAssets.at(filePath="/conf/glimpse.conf")

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /assets/*file controllers.Assets.at(file)
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.3")
3 changes: 0 additions & 3 deletions project/scaffold.sbt

This file was deleted.

0 comments on commit dc7d458

Please sign in to comment.