feat: load config to make captcha stats optional

This commit is contained in:
realaravinth 2022-05-27 15:25:33 +05:30
parent 4cd4605266
commit 851874f8cf
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 5 additions and 0 deletions

View file

@ -28,6 +28,7 @@ salt = "asdl;kjfhjawehfpa;osdkjasdvjaksndfpoanjdfainsdfaijdsfajlkjdsaf;ajsdfwero
# garbage collection period to manage mCaptcha system
# leave untouched if you don't know what you are doing
gc = 30
enable_stats = true
[captcha.default_difficulty_strategy]
avg_traffic_difficulty = 50000 # almost instant solution

View file

@ -36,6 +36,7 @@ pub struct Server {
pub struct Captcha {
pub salt: String,
pub gc: u64,
pub enable_stats: bool,
pub default_difficulty_strategy: DefaultDifficultyStrategy,
}
@ -124,6 +125,9 @@ impl Settings {
const CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/mcaptcha/config.toml";
s.set("capatcha.enable_stats", true.to_string())
.expect("unable to set capatcha.enable_stats default config");
if let Ok(path) = env::var("MCAPTCHA_CONFIG") {
s.merge(File::with_name(&path))?;
} else if Path::new(CURRENT_DIR).exists() {