mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-12 22:43:20 -05:00
Support to specify config file
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
1a41724fdc
commit
6f38a77c2f
@ -1,25 +1,36 @@
|
|||||||
package lc
|
package lc
|
||||||
|
|
||||||
import lc.core.CaptchaProviders
|
import lc.core.{CaptchaProviders, Captcha, Config}
|
||||||
import lc.server.Server
|
import lc.server.Server
|
||||||
import lc.background.BackgroundTask
|
import lc.background.BackgroundTask
|
||||||
import lc.core.Config
|
|
||||||
|
|
||||||
object LCFramework {
|
object LCFramework {
|
||||||
def main(args: scala.Array[String]): Unit = {
|
def main(args: scala.Array[String]): Unit = {
|
||||||
val backgroundTask = new BackgroundTask(
|
val configFilePath = if (args.length > 0){
|
||||||
throttle = Config.throttle,
|
args(0)
|
||||||
timeLimit = Config.captchaExpiryTimeLimit
|
} else {
|
||||||
)
|
"data/config.json"
|
||||||
backgroundTask.beginThread(delay = Config.threadDelay)
|
}
|
||||||
val server = new Server(port = Config.port)
|
val config = new Config(configFilePath)
|
||||||
|
val captchaProviders = new CaptchaProviders(config = config)
|
||||||
|
val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
|
||||||
|
val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
|
||||||
|
backgroundTask.beginThread(delay = config.threadDelay)
|
||||||
|
val server = new Server(port = config.port, captcha = captcha)
|
||||||
server.start()
|
server.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object MakeSamples {
|
object MakeSamples {
|
||||||
def main(args: scala.Array[String]): Unit = {
|
def main(args: scala.Array[String]): Unit = {
|
||||||
val samples = CaptchaProviders.generateChallengeSamples()
|
val configFilePath = if (args.length > 0){
|
||||||
|
args(0)
|
||||||
|
} else {
|
||||||
|
"data/config.json"
|
||||||
|
}
|
||||||
|
val config = new Config(configFilePath)
|
||||||
|
val captchaProviders = new CaptchaProviders(config = config)
|
||||||
|
val samples = captchaProviders.generateChallengeSamples()
|
||||||
samples.foreach {
|
samples.foreach {
|
||||||
case (key, sample) =>
|
case (key, sample) =>
|
||||||
val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif")
|
val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif")
|
||||||
|
@ -8,11 +8,10 @@ import java.io.{FileNotFoundException, File, PrintWriter}
|
|||||||
import java.{util => ju}
|
import java.{util => ju}
|
||||||
import lc.misc.HelperFunctions
|
import lc.misc.HelperFunctions
|
||||||
|
|
||||||
object Config {
|
class Config(configFilePath: String) {
|
||||||
|
|
||||||
implicit val formats: DefaultFormats.type = DefaultFormats
|
import Config.formats
|
||||||
|
|
||||||
private val configFilePath = "data/config.json"
|
|
||||||
private val configString =
|
private val configString =
|
||||||
try {
|
try {
|
||||||
val configFile = fromFile(configFilePath)
|
val configFile = fromFile(configFilePath)
|
||||||
@ -22,7 +21,12 @@ object Config {
|
|||||||
} catch {
|
} catch {
|
||||||
case _: FileNotFoundException => {
|
case _: FileNotFoundException => {
|
||||||
val configFileContent = getDefaultConfig()
|
val configFileContent = getDefaultConfig()
|
||||||
val configFile = new PrintWriter(new File(configFilePath))
|
val file = if(new File(configFilePath).isDirectory){
|
||||||
|
new File(configFilePath.concat("/config.json"))
|
||||||
|
} else {
|
||||||
|
new File(configFilePath)
|
||||||
|
}
|
||||||
|
val configFile = new PrintWriter(file)
|
||||||
configFile.write(configFileContent)
|
configFile.write(configFileContent)
|
||||||
configFile.close
|
configFile.close
|
||||||
configFileContent
|
configFileContent
|
||||||
@ -94,3 +98,7 @@ object Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Config{
|
||||||
|
implicit val formats: DefaultFormats.type = DefaultFormats
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user