mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
Remove access methods
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
6c4a3d0152
commit
070b862f25
@ -8,13 +8,13 @@ import lc.core.Config
|
||||
object LCFramework {
|
||||
def main(args: scala.Array[String]): Unit = {
|
||||
val captcha = new Captcha()
|
||||
val server = new Server(port = Config.getPort, captcha = captcha)
|
||||
val server = new Server(port = Config.port, captcha = captcha)
|
||||
val backgroundTask = new BackgroundTask(
|
||||
captcha = captcha,
|
||||
throttle = Config.getThrottle,
|
||||
timeLimit = Config.getCaptchaExpiryTimeLimit
|
||||
throttle = Config.throttle,
|
||||
timeLimit = Config.captchaExpiryTimeLimit
|
||||
)
|
||||
backgroundTask.beginThread(delay = Config.getThreadDelay)
|
||||
backgroundTask.beginThread(delay = Config.threadDelay)
|
||||
server.start()
|
||||
}
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ class Captcha {
|
||||
token.asInstanceOf[Int]
|
||||
}
|
||||
|
||||
val supportedinputType = Config.getSupportedinputType
|
||||
val supportedLevels = Config.getSupportedLevels
|
||||
val supportedMedia = Config.getSupportedMedia
|
||||
val supportedinputType = Config.supportedinputType
|
||||
val supportedLevels = Config.supportedLevels
|
||||
val supportedMedia = Config.supportedMedia
|
||||
|
||||
private def validateParam(param: Parameters): Boolean = {
|
||||
if (
|
||||
@ -115,7 +115,7 @@ class Captcha {
|
||||
|
||||
def checkAnswer(answer: Answer): Result = {
|
||||
val selectPstmt = Statements.tlStmts.get.selectPstmt
|
||||
selectPstmt.setInt(1, Config.getCaptchaExpiryTimeLimit)
|
||||
selectPstmt.setInt(1, Config.captchaExpiryTimeLimit)
|
||||
selectPstmt.setString(2, answer.id)
|
||||
val rs: ResultSet = selectPstmt.executeQuery()
|
||||
val psOpt = if (rs.first()) {
|
||||
|
@ -3,8 +3,7 @@ package lc.core
|
||||
import lc.captchas._
|
||||
import lc.captchas.interfaces.ChallengeProvider
|
||||
import lc.captchas.interfaces.Challenge
|
||||
import org.json4s.{DefaultFormats, JObject, JField, JArray, JString}
|
||||
import org.json4s.jackson.Serialization.write
|
||||
import scala.collection.mutable.Map
|
||||
|
||||
object CaptchaProviders {
|
||||
private val providers = Map(
|
||||
@ -23,10 +22,9 @@ object CaptchaProviders {
|
||||
}
|
||||
}
|
||||
|
||||
implicit val formats: DefaultFormats.type = DefaultFormats
|
||||
private val seed = Config.getSeed
|
||||
private val seed = Config.seed
|
||||
private val random = new scala.util.Random(seed)
|
||||
private val config = Config.getCaptchaConfig
|
||||
private val config = Config.captchaConfigMap
|
||||
|
||||
private def getNextRandomInt(max: Int): Int =
|
||||
random.synchronized {
|
||||
@ -37,26 +35,21 @@ object CaptchaProviders {
|
||||
return providers(id)
|
||||
}
|
||||
|
||||
private def filterProviderByParam(param: Parameters): List[(String, String)] = {
|
||||
private def filterProviderByParam(param: Parameters): Iterable[(List[String], List[String])] = {
|
||||
for {
|
||||
JObject(child) <- config
|
||||
JField("name", JString(name)) <- child
|
||||
JField("supportedLevels", JArray(supportedLevels)) <- child
|
||||
JField("supportedMedia", JArray(supportedMedia)) <- child
|
||||
JField("supportedinputType", JArray(supportedinputType)) <- child
|
||||
JField("config", config) <- child
|
||||
if supportedLevels.contains(JString(param.level))
|
||||
if supportedMedia.contains(JString(param.media))
|
||||
if supportedinputType.contains(JString(param.input_type))
|
||||
} yield (name, write(config))
|
||||
configValue <- config.values
|
||||
if configValue("supportedLevels").contains(param.level)
|
||||
if configValue("supportedMedia").contains(param.media)
|
||||
if configValue("supportedinputType").contains(param.input_type)
|
||||
} yield (configValue("name"), configValue("config"))
|
||||
}
|
||||
|
||||
def getProvider(param: Parameters): ChallengeProvider = {
|
||||
val providerConfig = filterProviderByParam(param)
|
||||
val providerConfig = filterProviderByParam(param).toList
|
||||
val randomIndex = getNextRandomInt(providerConfig.length)
|
||||
val providerIndex = providerConfig(randomIndex)._1
|
||||
val selectedProvider = providers(providerIndex)
|
||||
selectedProvider.configure(providerConfig(randomIndex)._2)
|
||||
val selectedProvider = providers(providerIndex(0))
|
||||
selectedProvider.configure(providerConfig(randomIndex)._2(0))
|
||||
selectedProvider
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package lc.core
|
||||
import scala.io.Source.fromFile
|
||||
import org.json4s.{DefaultFormats, JValue, JObject, JField}
|
||||
import org.json4s.jackson.JsonMethods.parse
|
||||
import scala.collection.immutable.HashMap
|
||||
|
||||
object Config {
|
||||
|
||||
@ -14,16 +15,17 @@ object Config {
|
||||
finally configFile.close
|
||||
private val configJson = parse(configString)
|
||||
|
||||
private val port = (configJson \ "port").extract[Int]
|
||||
private val throttle = (configJson \ "throttle").extract[Int]
|
||||
private val seed = (configJson \ "randomSeed").extract[Int]
|
||||
private val captchaExpiryTimeLimit = (configJson \ "captchaExpiryTimeLimit").extract[Int]
|
||||
private val threadDelay = (configJson \ "threadDelay").extract[Int]
|
||||
private val capthcaConfig = (configJson \ "captchas")
|
||||
val port: Int = (configJson \ "port").extract[Int]
|
||||
val throttle: Int = (configJson \ "throttle").extract[Int]
|
||||
val seed: Int = (configJson \ "randomSeed").extract[Int]
|
||||
val captchaExpiryTimeLimit: Int = (configJson \ "captchaExpiryTimeLimit").extract[Int]
|
||||
val threadDelay: Int = (configJson \ "threadDelay").extract[Int]
|
||||
private val captchaConfig = (configJson \ "captchas")
|
||||
val captchaConfigMap: Map[String,HashMap[String,List[String]]] = captchaConfig.values.asInstanceOf[Map[String, HashMap[String, List[String]]]]
|
||||
|
||||
private val supportedLevels = getAllValues(configJson, "supportedLevels")
|
||||
private val supportedMedia = getAllValues(configJson, "supportedMedia")
|
||||
private val supportedinputType = getAllValues(configJson, "supportedinputType")
|
||||
val supportedLevels: Set[String] = getAllValues(configJson, "supportedLevels")
|
||||
val supportedMedia: Set[String] = getAllValues(configJson, "supportedMedia")
|
||||
val supportedinputType: Set[String] = getAllValues(configJson, "supportedinputType")
|
||||
|
||||
private def getAllValues(config: JValue, param: String): Set[String] = {
|
||||
val configValues = (config \\ param)
|
||||
@ -41,40 +43,4 @@ object Config {
|
||||
valueSet
|
||||
}
|
||||
|
||||
def getPort(): Int = {
|
||||
port
|
||||
}
|
||||
|
||||
def getThrottle(): Int = {
|
||||
throttle
|
||||
}
|
||||
|
||||
def getSeed(): Int = {
|
||||
seed
|
||||
}
|
||||
|
||||
def getCaptchaExpiryTimeLimit(): Int = {
|
||||
captchaExpiryTimeLimit
|
||||
}
|
||||
|
||||
def getThreadDelay(): Int = {
|
||||
threadDelay
|
||||
}
|
||||
|
||||
def getCaptchaConfig(): JValue = {
|
||||
capthcaConfig
|
||||
}
|
||||
|
||||
def getSupportedLevels(): Set[String] = {
|
||||
supportedLevels
|
||||
}
|
||||
|
||||
def getSupportedMedia(): Set[String] = {
|
||||
supportedMedia
|
||||
}
|
||||
|
||||
def getSupportedinputType(): Set[String] = {
|
||||
supportedinputType
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user