WIP
This commit is contained in:
parent
ede46dc7a6
commit
ee34620d53
2 changed files with 199 additions and 121 deletions
|
@ -469,24 +469,7 @@ fn create_new_server_config(
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let server_config = server::Config {
|
let network = server::Network {
|
||||||
config_revision: Revision::V1,
|
|
||||||
server_info: Some(server::ServerInfo {
|
|
||||||
name: meta.name.to_owned(),
|
|
||||||
description: meta.description.to_owned(),
|
|
||||||
maintainer_name: meta.maintainer_name.to_owned(),
|
|
||||||
contact_info: meta.maintainer_email.to_owned(),
|
|
||||||
open_registrations: !meta.disable_registration,
|
|
||||||
repository_url,
|
|
||||||
default_reaction: Some(meta.default_reaction.to_owned()),
|
|
||||||
}),
|
|
||||||
timeline: Some(server::Timeline {
|
|
||||||
local: !meta.disable_local_timeline,
|
|
||||||
global: !meta.disable_global_timeline,
|
|
||||||
recommended: !meta.disable_recommended_timeline,
|
|
||||||
publish: meta.enable_guest_timeline,
|
|
||||||
}),
|
|
||||||
network: server::Network {
|
|
||||||
protocol: match protocol.as_str() {
|
protocol: match protocol.as_str() {
|
||||||
"http" => Some(server::HttpProtocol::Http),
|
"http" => Some(server::HttpProtocol::Http),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -510,8 +493,9 @@ fn create_new_server_config(
|
||||||
media_proxy,
|
media_proxy,
|
||||||
summaly_proxy,
|
summaly_proxy,
|
||||||
smtp_proxy,
|
smtp_proxy,
|
||||||
},
|
};
|
||||||
database: server::Database {
|
|
||||||
|
let database = server::Database {
|
||||||
host: db
|
host: db
|
||||||
.get(&Yaml::String("host".to_string()))
|
.get(&Yaml::String("host".to_string()))
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
|
@ -538,8 +522,9 @@ fn create_new_server_config(
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.ok_or(Error::InvalidConfig("db.db"))?
|
.ok_or(Error::InvalidConfig("db.db"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
},
|
};
|
||||||
cache_server: server::CacheServer {
|
|
||||||
|
let cache_server = server::CacheServer {
|
||||||
host: redis
|
host: redis
|
||||||
.get(&Yaml::String("host".to_string()))
|
.get(&Yaml::String("host".to_string()))
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
|
@ -585,10 +570,103 @@ fn create_new_server_config(
|
||||||
),
|
),
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let server_info = Some(server::ServerInfo {
|
||||||
|
name: meta.name.to_owned(),
|
||||||
|
description: meta.description.to_owned(),
|
||||||
|
maintainer_name: meta.maintainer_name.to_owned(),
|
||||||
|
contact_info: meta.maintainer_email.to_owned(),
|
||||||
|
open_registrations: !meta.disable_registration,
|
||||||
|
repository_url,
|
||||||
|
default_reaction: Some(meta.default_reaction.to_owned()),
|
||||||
|
});
|
||||||
|
|
||||||
|
let timeline = Some(server::Timeline {
|
||||||
|
local: !meta.disable_local_timeline,
|
||||||
|
global: !meta.disable_global_timeline,
|
||||||
|
recommended: !meta.disable_recommended_timeline,
|
||||||
|
publish: meta.enable_guest_timeline,
|
||||||
|
});
|
||||||
|
|
||||||
|
if meta.enable_hcaptcha && meta.enable_recaptcha {
|
||||||
|
return Err(Error::InvalidConfig(
|
||||||
|
"Both hCaptcha and reCAPTCHA are enabled",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let captcha = match (meta.enable_hcaptcha, meta.enable_recaptcha) {
|
||||||
|
(false, false) => None,
|
||||||
|
(true, true) => {
|
||||||
|
return Err(Error::InvalidConfig(
|
||||||
|
"Both hCaptcha and reCAPTCHA are enabled",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
(true, false) => Some(server::Captcha {
|
||||||
|
enabled: true,
|
||||||
|
provider: server::CaptchaProvider::HCaptcha,
|
||||||
|
site_key: meta
|
||||||
|
.hcaptcha_site_key
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("hCaptcha site key is not set"))?,
|
||||||
|
secret_key: meta
|
||||||
|
.hcaptcha_secret_key
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("hCaptcha secret key is not set"))?,
|
||||||
|
}),
|
||||||
|
(false, true) => Some(server::Captcha {
|
||||||
|
enabled: true,
|
||||||
|
provider: server::CaptchaProvider::ReCaptcha,
|
||||||
|
site_key: meta
|
||||||
|
.recaptcha_site_key
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("reCAPTCHA site key is not set"))?,
|
||||||
|
secret_key: meta
|
||||||
|
.recaptcha_secret_key
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("reCAPTCHA secret key is not set"))?,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut security: Option<server::Security> = None;
|
||||||
|
|
||||||
|
if meta.secure_mode
|
||||||
|
|| meta.private_mode
|
||||||
|
|| captcha.is_some()
|
||||||
|
|| meta.enable_active_email_validation
|
||||||
|
|| meta.enable_ip_logging
|
||||||
|
{
|
||||||
|
security = Some(server::Security {
|
||||||
|
require_authorized_fetch: match meta.secure_mode {
|
||||||
|
false => None,
|
||||||
|
true => Some(true),
|
||||||
},
|
},
|
||||||
|
private_mode: match meta.private_mode {
|
||||||
|
false => None,
|
||||||
|
true => Some(true),
|
||||||
|
},
|
||||||
|
captcha,
|
||||||
|
enable_strict_email_check: match meta.enable_active_email_validation {
|
||||||
|
false => None,
|
||||||
|
true => Some(true),
|
||||||
|
},
|
||||||
|
enable_ip_logging: match meta.enable_ip_logging {
|
||||||
|
false => None,
|
||||||
|
true => Some(true),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let server_config = server::Config {
|
||||||
|
config_revision: Revision::V1,
|
||||||
|
server_info,
|
||||||
|
timeline,
|
||||||
|
network,
|
||||||
|
database,
|
||||||
|
cache_server,
|
||||||
id,
|
id,
|
||||||
service_worker,
|
service_worker,
|
||||||
security: todo!(),
|
security,
|
||||||
file,
|
file,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -164,21 +164,21 @@ pub struct Security {
|
||||||
pub require_authorized_fetch: Option<bool>,
|
pub require_authorized_fetch: Option<bool>,
|
||||||
pub private_mode: Option<bool>,
|
pub private_mode: Option<bool>,
|
||||||
#[validate(nested)]
|
#[validate(nested)]
|
||||||
pub captcha: Option<CaptchaConfig>,
|
pub captcha: Option<Captcha>,
|
||||||
pub enable_strict_email_check: Option<bool>,
|
pub enable_strict_email_check: Option<bool>,
|
||||||
pub log_ip_address: Option<bool>,
|
pub enable_ip_logging: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Validate, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Validate, Debug, Clone)]
|
||||||
pub struct CaptchaConfig {
|
pub struct Captcha {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub kind: Captcha,
|
pub provider: CaptchaProvider,
|
||||||
pub site_key: String,
|
pub site_key: String,
|
||||||
pub secret_key: String,
|
pub secret_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
pub enum Captcha {
|
pub enum CaptchaProvider {
|
||||||
#[serde(rename = "hCaptcha")]
|
#[serde(rename = "hCaptcha")]
|
||||||
HCaptcha,
|
HCaptcha,
|
||||||
#[serde(rename = "reCAPTCHA")]
|
#[serde(rename = "reCAPTCHA")]
|
||||||
|
|
Loading…
Reference in a new issue