Skip to content

Commit

Permalink
FEATURE: exclude all access by IP
Browse files Browse the repository at this point in the history
- under configuration in blacklist.txt : if contains line with noAccessByIP
- TESTED with http://127.0.0.1:9000/ (= localhost )
- TODO update web admin doc.
  • Loading branch information
jmvanel committed Feb 5, 2021
1 parent 6eb93a7 commit 916e5ce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scala/core/src/main/scala/deductions/runtime/core/IPFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,22 @@ trait IPFilter extends HTTPFilter {
ipsFromFile getOrElse List()
}

private lazy val noAccessByIP =
( blacklistedIPs contains "noAccessByIP" ) ||
( blacklistedIPs contains "no access by IP" )

val responseToBlackListed = Some(
"Black listed, please respect robots.txt, see https://en.wikipedia.org/wiki/Robots_exclusion_standard")

private val regexIP = """\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b""".r
/** @return a message for HTTP output or None */
override def filter(request: HTTPrequest): Option[String] = {
val blacklistCriterium = blacklistedIPs contains request.remoteAddress
val blacklistCriterium =
( blacklistedIPs contains request.remoteAddress ) ||
// this excludes all access by IP : should be under configuration
( noAccessByIP &&
regexIP.findAllIn(request.host).size == 1 )

if( blacklistCriterium ) {
responseToBlackListed
} else {
Expand Down

0 comments on commit 916e5ce

Please sign in to comment.