cute anonymised NoIPs
parent
e42c8d0806
commit
dc19113fef
|
@ -684,7 +684,7 @@ object mod {
|
|||
logins.ips.sortBy(ip => (-ip.alts.score, -ip.ip.seconds)).map { ip =>
|
||||
val renderedIp = renderIp(ip.ip.value)
|
||||
tr(cls := ip.blocked option "blocked")(
|
||||
td(a(href := routes.Mod.singleIp(renderedIp))(renderedIp take 16)),
|
||||
td(a(href := routes.Mod.singleIp(renderedIp))(renderedIp)),
|
||||
td(dataSort := ip.alts.score)(altMarks(ip.alts)),
|
||||
td(ip.proxy option span(cls := "proxy")("PROXY")),
|
||||
td(dataSort := ip.ip.date.getMillis)(momentFromNowServer(ip.ip.date)),
|
||||
|
|
|
@ -40,8 +40,7 @@ final class Env(
|
|||
noteApi: lila.user.NoteApi,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
slackApi: lila.irc.SlackApi,
|
||||
msgApi: lila.msg.MsgApi,
|
||||
symmetricCipher: lila.common.SymmetricCipher
|
||||
msgApi: lila.msg.MsgApi
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
system: ActorSystem
|
||||
|
|
|
@ -2,12 +2,15 @@ package lila.mod
|
|||
|
||||
import com.github.blemale.scaffeine.Cache
|
||||
import com.github.blemale.scaffeine.LoadingCache
|
||||
import scala.concurrent.duration._
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
import lila.common.CuteNameGenerator
|
||||
import lila.common.IpAddress
|
||||
import lila.common.SymmetricCipher
|
||||
import lila.memo.CacheApi
|
||||
import lila.security.Granter
|
||||
import lila.user.Holder
|
||||
import lila.common.ThreadLocalRandom
|
||||
|
||||
object IpRender {
|
||||
|
||||
|
@ -16,7 +19,7 @@ object IpRender {
|
|||
type RenderIp = IpAddress => Rendered
|
||||
}
|
||||
|
||||
final class IpRender(cipher: SymmetricCipher) {
|
||||
final class IpRender {
|
||||
|
||||
import IpRender._
|
||||
|
||||
|
@ -24,13 +27,17 @@ final class IpRender(cipher: SymmetricCipher) {
|
|||
|
||||
val visible = (ip: IpAddress) => ip.value
|
||||
|
||||
val encrypted = (ip: IpAddress) => cache.get(ip.value)
|
||||
val encrypted = (ip: IpAddress) => cache get ip
|
||||
|
||||
def decrypt(str: String) = IpAddress from {
|
||||
cipher.base64UrlFriendly.decrypt(str) getOrElse str
|
||||
}
|
||||
def decrypt(str: String): Option[IpAddress] = IpAddress.from(str) orElse
|
||||
cache.underlying.asMap.asScala.collectFirst {
|
||||
case (ip, encrypted) if encrypted == str =>
|
||||
ip
|
||||
}
|
||||
|
||||
private val cache: LoadingCache[Raw, Rendered] = CacheApi.scaffeineNoScheduler
|
||||
.maximumSize(4096)
|
||||
.build((raw: Raw) => cipher.base64UrlFriendly.encrypt(raw).get)
|
||||
private val cache: LoadingCache[IpAddress, Rendered] = CacheApi.scaffeineNoScheduler
|
||||
.expireAfterAccess(30 minutes)
|
||||
.build((_: IpAddress) =>
|
||||
s"NoIP:${CuteNameGenerator.make(maxSize = 24) | ThreadLocalRandom.nextString(8)}"
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue