mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-02-12 03:08:06 -05:00
Merge pull request #116 from rr83019/max-attempts-config
Max attempts config
This commit is contained in:
commit
4fc2d4ebb0
@ -3,6 +3,7 @@ package lc
|
|||||||
import lc.core.{CaptchaProviders, Captcha, Config}
|
import lc.core.{CaptchaProviders, Captcha, Config}
|
||||||
import lc.server.Server
|
import lc.server.Server
|
||||||
import lc.background.BackgroundTask
|
import lc.background.BackgroundTask
|
||||||
|
import lc.database.Statements
|
||||||
|
|
||||||
object LCFramework {
|
object LCFramework {
|
||||||
def main(args: scala.Array[String]): Unit = {
|
def main(args: scala.Array[String]): Unit = {
|
||||||
@ -12,6 +13,7 @@ object LCFramework {
|
|||||||
"data/config.json"
|
"data/config.json"
|
||||||
}
|
}
|
||||||
val config = new Config(configFilePath)
|
val config = new Config(configFilePath)
|
||||||
|
Statements.maxAttempts = config.maxAttempts
|
||||||
val captchaProviders = new CaptchaProviders(config = config)
|
val captchaProviders = new CaptchaProviders(config = config)
|
||||||
val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
|
val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
|
||||||
val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
|
val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package lc.core
|
package lc.core
|
||||||
|
|
||||||
import java.sql.ResultSet
|
import lc.captchas.interfaces.{Challenge, ChallengeProvider}
|
||||||
import java.util.UUID
|
|
||||||
import java.io.ByteArrayInputStream
|
|
||||||
import lc.database.Statements
|
import lc.database.Statements
|
||||||
import lc.core.CaptchaProviders
|
import java.io.ByteArrayInputStream
|
||||||
import lc.captchas.interfaces.ChallengeProvider
|
import java.sql.{Blob, ResultSet}
|
||||||
import lc.captchas.interfaces.Challenge
|
import java.util.UUID
|
||||||
import java.sql.Blob
|
|
||||||
|
|
||||||
class Captcha(config: Config, captchaProviders: CaptchaProviders) {
|
class Captcha(config: Config, captchaProviders: CaptchaProviders) {
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ object AttributesEnum extends Enumeration {
|
|||||||
val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled")
|
val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled")
|
||||||
val CORS_HEADER: Value = Value("corsHeader")
|
val CORS_HEADER: Value = Value("corsHeader")
|
||||||
val CONFIG: Value = Value("config")
|
val CONFIG: Value = Value("config")
|
||||||
|
val MAX_ATTEMPTS: Value = Value("maxAttempts")
|
||||||
}
|
}
|
||||||
|
|
||||||
object ResultEnum extends Enumeration {
|
object ResultEnum extends Enumeration {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package lc.core
|
package lc.core
|
||||||
|
|
||||||
import lc.captchas._
|
import lc.captchas.*
|
||||||
import lc.captchas.interfaces.ChallengeProvider
|
import lc.captchas.interfaces.ChallengeProvider
|
||||||
import lc.captchas.interfaces.Challenge
|
import lc.captchas.interfaces.Challenge
|
||||||
import scala.collection.mutable.Map
|
import scala.collection.mutable.Map
|
||||||
@ -50,7 +50,7 @@ class CaptchaProviders(config: Config) {
|
|||||||
|
|
||||||
def getProvider(param: Parameters): Option[ChallengeProvider] = {
|
def getProvider(param: Parameters): Option[ChallengeProvider] = {
|
||||||
val providerConfig = filterProviderByParam(param).toList
|
val providerConfig = filterProviderByParam(param).toList
|
||||||
if (providerConfig.length > 0) {
|
if (providerConfig.nonEmpty) {
|
||||||
val randomIndex = HelperFunctions.randomNumber(providerConfig.length)
|
val randomIndex = HelperFunctions.randomNumber(providerConfig.length)
|
||||||
val providerIndex = providerConfig(randomIndex)._1
|
val providerIndex = providerConfig(randomIndex)._1
|
||||||
val selectedProvider = providers(providerIndex)
|
val selectedProvider = providers(providerIndex)
|
||||||
|
@ -47,6 +47,7 @@ class Config(configFilePath: String) {
|
|||||||
val threadDelay: Int = (configJson \ AttributesEnum.THREAD_DELAY.toString).extract[Int]
|
val threadDelay: Int = (configJson \ AttributesEnum.THREAD_DELAY.toString).extract[Int]
|
||||||
val playgroundEnabled: Boolean = (configJson \ AttributesEnum.PLAYGROUND_ENABLED.toString).extract[Boolean]
|
val playgroundEnabled: Boolean = (configJson \ AttributesEnum.PLAYGROUND_ENABLED.toString).extract[Boolean]
|
||||||
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
|
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
|
||||||
|
val maxAttempts: Int = (configJson \ AttributesEnum.MAX_ATTEMPTS.toString).extract[Int]
|
||||||
|
|
||||||
private val captchaConfigJson = (configJson \ "captchas")
|
private val captchaConfigJson = (configJson \ "captchas")
|
||||||
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
||||||
@ -69,6 +70,7 @@ class Config(configFilePath: String) {
|
|||||||
(AttributesEnum.THREAD_DELAY.toString -> 2) ~
|
(AttributesEnum.THREAD_DELAY.toString -> 2) ~
|
||||||
(AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~
|
(AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~
|
||||||
(AttributesEnum.CORS_HEADER.toString -> "") ~
|
(AttributesEnum.CORS_HEADER.toString -> "") ~
|
||||||
|
(AttributesEnum.MAX_ATTEMPTS.toString -> 10) ~
|
||||||
("captchas" -> List(
|
("captchas" -> List(
|
||||||
(
|
(
|
||||||
(AttributesEnum.NAME.toString -> "FilterChallenge") ~
|
(AttributesEnum.NAME.toString -> "FilterChallenge") ~
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package lc.database
|
package lc.database
|
||||||
|
|
||||||
import java.sql._
|
import java.sql.{Connection, DriverManager, Statement}
|
||||||
|
|
||||||
class DBConn() {
|
class DBConn() {
|
||||||
val con: Connection = DriverManager.getConnection("jdbc:h2:./data/H2/captcha2", "sa", "")
|
val con: Connection = DriverManager.getConnection("jdbc:h2:./data/H2/captcha2", "sa", "")
|
||||||
|
@ -118,6 +118,6 @@ object Statements {
|
|||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
private val dbConn: DBConn = new DBConn()
|
private val dbConn: DBConn = new DBConn()
|
||||||
private val maxAttempts = 10
|
var maxAttempts: Int = 10
|
||||||
val tlStmts: ThreadLocal[Statements] = ThreadLocal.withInitial(() => new Statements(dbConn, maxAttempts))
|
val tlStmts: ThreadLocal[Statements] = ThreadLocal.withInitial(() => new Statements(dbConn, maxAttempts))
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"threadDelay" : 2,
|
"threadDelay" : 2,
|
||||||
"playgroundEnabled" : false,
|
"playgroundEnabled" : false,
|
||||||
"corsHeader" : "*",
|
"corsHeader" : "*",
|
||||||
|
"maxAttempts" : 20,
|
||||||
"captchas" : [ {
|
"captchas" : [ {
|
||||||
"name" : "DebugCaptcha",
|
"name" : "DebugCaptcha",
|
||||||
"allowedLevels" : [ "debug" ],
|
"allowedLevels" : [ "debug" ],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user