diff --git a/server/lemmy_utils/src/settings.rs b/server/lemmy_utils/src/settings.rs index 6a566de7e..55b6cbb32 100644 --- a/server/lemmy_utils/src/settings.rs +++ b/server/lemmy_utils/src/settings.rs @@ -133,6 +133,20 @@ impl Settings { fs::read_to_string(CONFIG_FILE) } + pub fn get_allowed_instances(&self) -> Vec { + let mut allowed_instances: Vec = self + .federation + .allowed_instances + .split(',') + .map(|d| d.to_string()) + .collect(); + + // The defaults.hjson config always returns a [""] + allowed_instances.retain(|d| !d.eq("")); + + allowed_instances + } + pub fn save_config_file(data: &str) -> Result { fs::write(CONFIG_FILE, data)?; diff --git a/server/src/api/site.rs b/server/src/api/site.rs index dcbd62167..515c3e5be 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -130,6 +130,7 @@ pub struct GetSiteResponse { pub online: usize, version: String, my_user: Option, + federated_instances: Vec, } #[derive(Serialize, Deserialize)] @@ -433,6 +434,7 @@ impl Perform for Oper { online, version: version::VERSION.to_string(), my_user, + federated_instances: Settings::get().get_allowed_instances(), }) } } @@ -659,6 +661,7 @@ impl Perform for Oper { online: 0, version: version::VERSION.to_string(), my_user: Some(user), + federated_instances: Settings::get().get_allowed_instances(), }) } } diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index f67471982..491762680 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -76,12 +76,8 @@ fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> { return Err(anyhow!("invalid apub id scheme: {:?}", apub_id.scheme()).into()); } - let mut allowed_instances: Vec = Settings::get() - .federation - .allowed_instances - .split(',') - .map(|d| d.to_string()) - .collect(); + let mut allowed_instances: Vec = Settings::get().get_allowed_instances(); + // need to allow this explicitly because apub activities might contain objects from our local // instance. replace is needed to remove the port in our federation test setup. let settings = Settings::get(); diff --git a/server/src/routes/index.rs b/server/src/routes/index.rs index b579a1958..88a36c398 100644 --- a/server/src/routes/index.rs +++ b/server/src/routes/index.rs @@ -40,7 +40,8 @@ pub fn config(cfg: &mut web::ServiceConfig) { ) .route("/search", web::get().to(index)) .route("/sponsors", web::get().to(index)) - .route("/password_change/{token}", web::get().to(index)); + .route("/password_change/{token}", web::get().to(index)) + .route("/instances", web::get().to(index)); } async fn index() -> Result { diff --git a/ui/src/components/admin-settings.tsx b/ui/src/components/admin-settings.tsx index 8157d4a3a..fe50b1e94 100644 --- a/ui/src/components/admin-settings.tsx +++ b/ui/src/components/admin-settings.tsx @@ -48,6 +48,7 @@ export class AdminSettings extends Component { banned: [], online: null, version: null, + federated_instances: null, }, siteConfigForm: { config_hjson: null, diff --git a/ui/src/components/footer.tsx b/ui/src/components/footer.tsx index e911370fa..6e7acb7a0 100644 --- a/ui/src/components/footer.tsx +++ b/ui/src/components/footer.tsx @@ -51,6 +51,11 @@ export class Footer extends Component { {i18n.t('modlog')} +