just use andreis' disposable domains
parent
5bda5e03a3
commit
7a1bf0c64b
|
@ -244,8 +244,8 @@ security {
|
|||
refresh_delay = 1 hour
|
||||
}
|
||||
disposable_email {
|
||||
provider_url = "https://raw.githubusercontent.com/ornicar/disposable-email-domains/master/list"
|
||||
refresh_delay = 5 minutes
|
||||
provider_url = "https://raw.githack.com/andreis/disposable-email-domains/master/domains.json"
|
||||
refresh_delay = 10 minutes
|
||||
}
|
||||
recaptcha = ${recaptcha}
|
||||
whois {
|
||||
|
|
|
@ -8,36 +8,25 @@ final class DisposableEmailDomain(
|
|||
busOption: Option[lila.common.Bus]
|
||||
) {
|
||||
|
||||
private type Matcher = String => Boolean
|
||||
|
||||
private var matchers = List.empty[Matcher]
|
||||
private var domains = Set.empty[String]
|
||||
private var failed = false
|
||||
|
||||
private[security] def refresh: Unit = {
|
||||
WS.url(providerUrl).get() map { res =>
|
||||
setDomains(textToDomains(res.body))
|
||||
lila.mon.email.disposableDomain(matchers.size)
|
||||
res.json.validate[Set[String]].fold(
|
||||
err => onError(lila.base.LilaException(err.toString)),
|
||||
dat => {
|
||||
domains = dat
|
||||
failed = false
|
||||
}
|
||||
)
|
||||
lila.mon.email.disposableDomain(domains.size)
|
||||
} recover {
|
||||
case _: java.net.ConnectException => // ignore network errors
|
||||
case e: Exception => onError(e)
|
||||
}
|
||||
}
|
||||
|
||||
private[security] def setDomains(domains: List[String]): Unit = try {
|
||||
matchers = ("lichess.org" :: domains).map { d =>
|
||||
val r = d.replace("\\w", "[\\w-]").replace(".", "\\.")
|
||||
val regex = s"""(.+\\.|)$r(\\..+)?"""
|
||||
makeMatcher(regex)
|
||||
}
|
||||
failed = false
|
||||
} catch {
|
||||
case e: Exception => onError(e)
|
||||
}
|
||||
|
||||
private[security] def textToDomains(text: String): List[String] =
|
||||
text.lines.map(_.trim.toLowerCase).filter(_.nonEmpty).toList
|
||||
|
||||
private var failed = false
|
||||
|
||||
private def onError(e: Exception): Unit = {
|
||||
logger.error("Can't update disposable emails", e)
|
||||
if (!failed) {
|
||||
|
@ -51,22 +40,13 @@ final class DisposableEmailDomain(
|
|||
}
|
||||
}
|
||||
|
||||
private def makeMatcher(regex: String): Matcher = {
|
||||
val matcher = regex.r.pattern matcher _
|
||||
(s: String) => matcher(s).matches
|
||||
}
|
||||
|
||||
def isMainstream(domain: String) =
|
||||
DisposableEmailDomain.mainstreamDomains contains domain.toLowerCase
|
||||
|
||||
def apply(domain: String) =
|
||||
if (isMainstream(domain)) false
|
||||
else matchers exists { _(domain.toLowerCase) }
|
||||
!DisposableEmailDomain.mainstreamDomains(domain.toLowerCase) && domains(domain)
|
||||
}
|
||||
|
||||
object DisposableEmailDomain {
|
||||
private object DisposableEmailDomain {
|
||||
|
||||
val mainstreamDomains = Set(
|
||||
private val mainstreamDomains = Set(
|
||||
/* Default domains included */
|
||||
"aol.com", "att.net", "comcast.net", "facebook.com", "gmail.com", "gmx.com", "googlemail.com",
|
||||
"google.com", "hotmail.com", "hotmail.co.uk", "mac.com", "me.com", "mail.com", "msn.com",
|
||||
|
|
|
@ -149,7 +149,7 @@ final class Env(
|
|||
busOption = system.lilaBus.some
|
||||
)
|
||||
|
||||
scheduler.once(10 seconds)(disposableEmailDomain.refresh)
|
||||
scheduler.once(15 seconds)(disposableEmailDomain.refresh)
|
||||
scheduler.effect(DisposableEmailRefreshDelay, "Refresh disposable email domains")(disposableEmailDomain.refresh)
|
||||
|
||||
lazy val tor = new Tor(TorProviderUrl)
|
||||
|
|
Loading…
Reference in New Issue