mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
gc: get public hostname as config parameter
This commit is contained in:
@@ -69,4 +69,5 @@ password = "password"
|
|||||||
|
|
||||||
[survey]
|
[survey]
|
||||||
nodes = ["http://localhost:7001"]
|
nodes = ["http://localhost:7001"]
|
||||||
rate_limit = 3600 # upload every hour
|
rate_limit = 10 # upload every hour
|
||||||
|
instance_root_url = "http://localhost:7000"
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ pub struct Redis {
|
|||||||
pub struct Survey {
|
pub struct Survey {
|
||||||
pub nodes: Vec<url::Url>,
|
pub nodes: Vec<url::Url>,
|
||||||
pub rate_limit: u64,
|
pub rate_limit: u64,
|
||||||
|
pub instance_root_url: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
|
||||||
@@ -105,7 +106,7 @@ pub struct Settings {
|
|||||||
pub allow_registration: bool,
|
pub allow_registration: bool,
|
||||||
pub allow_demo: bool,
|
pub allow_demo: bool,
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
pub survey: Survey,
|
pub survey: Option<Survey>,
|
||||||
pub redis: Option<Redis>,
|
pub redis: Option<Redis>,
|
||||||
pub server: Server,
|
pub server: Server,
|
||||||
pub captcha: Captcha,
|
pub captcha: Captcha,
|
||||||
@@ -163,7 +164,6 @@ const ENV_VAR_CONFIG: [(&str, &str); 29] = [
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
const DEPRECATED_ENV_VARS: [(&str, &str); 23] = [
|
const DEPRECATED_ENV_VARS: [(&str, &str); 23] = [
|
||||||
("debug", "MCAPTCHA_DEBUG"),
|
("debug", "MCAPTCHA_DEBUG"),
|
||||||
("commercial", "MCAPTCHA_COMMERCIAL"),
|
("commercial", "MCAPTCHA_COMMERCIAL"),
|
||||||
@@ -179,9 +179,18 @@ const DEPRECATED_ENV_VARS: [(&str, &str); 23] = [
|
|||||||
("server.proxy_has_tls", "MCAPTCHA_SERVER_PROXY_HAS_TLS"),
|
("server.proxy_has_tls", "MCAPTCHA_SERVER_PROXY_HAS_TLS"),
|
||||||
("captcha.salt", "MCAPTCHA_CAPTCHA_SALT"),
|
("captcha.salt", "MCAPTCHA_CAPTCHA_SALT"),
|
||||||
("captcha.gc", "MCAPTCHA_CAPTCHA_GC"),
|
("captcha.gc", "MCAPTCHA_CAPTCHA_GC"),
|
||||||
("captcha.default_difficulty_strategy.avg_traffic_difficulty", "MCAPTCHA_CAPTCHA_AVG_TRAFFIC_DIFFICULTY"),
|
(
|
||||||
("captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty", "MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY"),
|
"captcha.default_difficulty_strategy.avg_traffic_difficulty",
|
||||||
("captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty", "MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC"),
|
"MCAPTCHA_CAPTCHA_AVG_TRAFFIC_DIFFICULTY",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty",
|
||||||
|
"MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty",
|
||||||
|
"MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC",
|
||||||
|
),
|
||||||
("smtp.from", "MCAPTCHA_SMTP_FROM"),
|
("smtp.from", "MCAPTCHA_SMTP_FROM"),
|
||||||
("smtp.reply", "MCAPTCHA_SMTP_REPLY_TO"),
|
("smtp.reply", "MCAPTCHA_SMTP_REPLY_TO"),
|
||||||
("smtp.url", "MCAPTCHA_SMTP_URL"),
|
("smtp.url", "MCAPTCHA_SMTP_URL"),
|
||||||
@@ -244,7 +253,6 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn env_override(mut s: ConfigBuilder<DefaultState>) -> ConfigBuilder<DefaultState> {
|
fn env_override(mut s: ConfigBuilder<DefaultState>) -> ConfigBuilder<DefaultState> {
|
||||||
|
|
||||||
for (parameter, env_var_name) in DEPRECATED_ENV_VARS.iter() {
|
for (parameter, env_var_name) in DEPRECATED_ENV_VARS.iter() {
|
||||||
if let Ok(val) = env::var(env_var_name) {
|
if let Ok(val) = env::var(env_var_name) {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
@@ -254,7 +262,6 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (parameter, env_var_name) in ENV_VAR_CONFIG.iter() {
|
for (parameter, env_var_name) in ENV_VAR_CONFIG.iter() {
|
||||||
if let Ok(val) = env::var(env_var_name) {
|
if let Ok(val) = env::var(env_var_name) {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
@@ -284,8 +291,6 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deprecated_env_override_works() {
|
fn deprecated_env_override_works() {
|
||||||
use crate::tests::get_settings;
|
use crate::tests::get_settings;
|
||||||
@@ -314,7 +319,11 @@ mod tests {
|
|||||||
/* top level */
|
/* top level */
|
||||||
helper!("MCAPTCHA_DEBUG", !init_settings.debug, debug);
|
helper!("MCAPTCHA_DEBUG", !init_settings.debug, debug);
|
||||||
helper!("MCAPTCHA_COMMERCIAL", !init_settings.commercial, commercial);
|
helper!("MCAPTCHA_COMMERCIAL", !init_settings.commercial, commercial);
|
||||||
helper!("MCAPTCHA_ALLOW_REGISTRATION", !init_settings.allow_registration, allow_registration);
|
helper!(
|
||||||
|
"MCAPTCHA_ALLOW_REGISTRATION",
|
||||||
|
!init_settings.allow_registration,
|
||||||
|
allow_registration
|
||||||
|
);
|
||||||
helper!("MCAPTCHA_ALLOW_DEMO", !init_settings.allow_demo, allow_demo);
|
helper!("MCAPTCHA_ALLOW_DEMO", !init_settings.allow_demo, allow_demo);
|
||||||
|
|
||||||
/* database_type */
|
/* database_type */
|
||||||
@@ -371,8 +380,20 @@ mod tests {
|
|||||||
999,
|
999,
|
||||||
captcha.default_difficulty_strategy.avg_traffic_difficulty
|
captcha.default_difficulty_strategy.avg_traffic_difficulty
|
||||||
);
|
);
|
||||||
helper!("MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY", 999 , captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty);
|
helper!(
|
||||||
helper!("MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC", 999 , captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty);
|
"MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY",
|
||||||
|
999,
|
||||||
|
captcha
|
||||||
|
.default_difficulty_strategy
|
||||||
|
.peak_sustainable_traffic_difficulty
|
||||||
|
);
|
||||||
|
helper!(
|
||||||
|
"MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC",
|
||||||
|
999,
|
||||||
|
captcha
|
||||||
|
.default_difficulty_strategy
|
||||||
|
.broke_my_site_traffic_difficulty
|
||||||
|
);
|
||||||
|
|
||||||
/* SMTP */
|
/* SMTP */
|
||||||
|
|
||||||
@@ -407,7 +428,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn env_override_works() {
|
fn env_override_works() {
|
||||||
use crate::tests::get_settings;
|
use crate::tests::get_settings;
|
||||||
|
|||||||
Reference in New Issue
Block a user