]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Adding starttls support. Fixes #1997 (#2051)
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use doku::Document;
2 use serde::{Deserialize, Serialize};
3 use std::net::{IpAddr, Ipv4Addr};
4
5 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
6 #[serde(default)]
7 pub struct Settings {
8   /// settings related to the postgresql database
9   #[serde(default)]
10   pub database: DatabaseConfig,
11   #[default(Some(RateLimitConfig::default()))]
12   /// rate limits for various user actions, by user ip
13   pub rate_limit: Option<RateLimitConfig>,
14   /// Settings related to activitypub federation
15   #[default(FederationConfig::default())]
16   pub federation: FederationConfig,
17   #[default(CaptchaConfig::default())]
18   pub captcha: CaptchaConfig,
19   /// Email sending configuration. All options except login/password are mandatory
20   #[default(None)]
21   pub email: Option<EmailConfig>,
22   /// Parameters for automatic configuration of new instance (only used at first start)
23   #[default(None)]
24   pub setup: Option<SetupConfig>,
25   /// the domain name of your instance (mandatory)
26   #[default("unset")]
27   #[doku(example = "example.com")]
28   pub hostname: String,
29   /// Address where lemmy should listen for incoming requests
30   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
31   #[doku(as = "String")]
32   pub bind: IpAddr,
33   /// Port where lemmy should listen for incoming requests
34   #[default(8536)]
35   pub port: u16,
36   /// Whether the site is available over TLS. Needs to be true for federation to work.
37   #[default(true)]
38   pub tls_enabled: bool,
39   /// Address where pictrs is available (for image hosting)
40   #[default(None)]
41   #[doku(example = "http://localhost:8080")]
42   pub pictrs_url: Option<String>,
43   #[default(None)]
44   #[doku(example = "(\\bThis\\b)|(\\bis\\b)|(\\bsample\\b)")]
45   pub slur_filter: Option<String>,
46   /// Maximum length of local community and user names
47   #[default(20)]
48   pub actor_name_max_length: usize,
49   /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
50   #[default(25)]
51   pub http_fetch_retry_limit: i32,
52
53   #[default(None)]
54   #[doku(example = "http://localhost:4317")]
55   pub opentelemetry_url: Option<String>,
56 }
57
58 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
59 #[serde(default)]
60 pub struct CaptchaConfig {
61   /// Whether captcha is required for signup
62   #[default(false)]
63   pub enabled: bool,
64   /// Can be easy, medium, or hard
65   #[default("medium")]
66   pub difficulty: String,
67 }
68
69 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
70 #[serde(default)]
71 pub struct DatabaseConfig {
72   /// Username to connect to postgres
73   #[default("lemmy")]
74   pub(super) user: String,
75   /// Password to connect to postgres
76   #[default("password")]
77   pub password: String,
78   #[default("localhost")]
79   /// Host where postgres is running
80   pub host: String,
81   /// Port where postgres can be accessed
82   #[default(5432)]
83   pub(super) port: i32,
84   /// Name of the postgres database for lemmy
85   #[default("lemmy")]
86   pub(super) database: String,
87   /// Maximum number of active sql connections
88   #[default(5)]
89   pub pool_size: u32,
90 }
91
92 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
93 pub struct EmailConfig {
94   /// Hostname and port of the smtp server
95   #[doku(example = "localhost:25")]
96   pub smtp_server: String,
97   /// Login name for smtp server
98   pub smtp_login: Option<String>,
99   /// Password to login to the smtp server
100   pub smtp_password: Option<String>,
101   #[doku(example = "noreply@example.com")]
102   /// Address to send emails from, eg "noreply@your-instance.com"
103   pub smtp_from_address: String,
104   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
105   #[default("none")]
106   #[doku(example = "none")]
107   pub tls_type: String,
108 }
109
110 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
111 #[serde(default)]
112 pub struct FederationConfig {
113   /// Whether to enable activitypub federation.
114   #[default(false)]
115   pub enabled: bool,
116   /// Allows and blocks are described here:
117   /// https://join-lemmy.org/docs/en/federation/administration.html///instance-allowlist-and-blocklist
118   ///
119   /// list of instances with which federation is allowed
120   #[default(None)]
121   #[doku(example = "instance1.tld")]
122   #[doku(example = "instance2.tld")]
123   pub allowed_instances: Option<Vec<String>>,
124   /// Instances which we never federate anything with (but previously federated objects are unaffected)
125   #[default(None)]
126   pub blocked_instances: Option<Vec<String>>,
127   /// If true, only federate with instances on the allowlist and block everything else. If false,
128   /// use allowlist only for remote communities, and posts/comments in local communities
129   /// (meaning remote communities will show content from arbitrary instances).
130   #[default(true)]
131   pub strict_allowlist: bool,
132 }
133
134 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
135 #[serde(default)]
136 pub struct RateLimitConfig {
137   /// Maximum number of messages created in interval
138   #[default(180)]
139   pub message: i32,
140   /// Interval length for message limit, in seconds
141   #[default(60)]
142   pub message_per_second: i32,
143   /// Maximum number of posts created in interval
144   #[default(6)]
145   pub post: i32,
146   /// Interval length for post limit, in seconds
147   #[default(600)]
148   pub post_per_second: i32,
149   /// Maximum number of registrations in interval
150   #[default(3)]
151   pub register: i32,
152   /// Interval length for registration limit, in seconds
153   #[default(3600)]
154   pub register_per_second: i32,
155   /// Maximum number of image uploads in interval
156   #[default(6)]
157   pub image: i32,
158   /// Interval length for image uploads, in seconds
159   #[default(3600)]
160   pub image_per_second: i32,
161   /// Maximum number of comments created in interval
162   #[default(6)]
163   pub comment: i32,
164   /// Interval length for comment limit, in seconds
165   #[default(600)]
166   pub comment_per_second: i32,
167 }
168
169 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
170 pub struct SetupConfig {
171   /// Username for the admin user
172   #[doku(example = "admin")]
173   pub admin_username: String,
174   /// Password for the admin user. It must be at least 10 characters.
175   #[doku(example = "my_passwd_longer_than_ten_characters")]
176   pub admin_password: String,
177   /// Name of the site (can be changed later)
178   #[doku(example = "My Lemmy Instance")]
179   pub site_name: String,
180   /// Email for the admin user (optional, can be omitted and set later through the website)
181   #[default(None)]
182   pub admin_email: Option<String>,
183   #[default(None)]
184   pub sidebar: Option<String>,
185   #[default(None)]
186   pub description: Option<String>,
187   #[default(None)]
188   pub icon: Option<String>,
189   #[default(None)]
190   pub banner: Option<String>,
191   #[default(None)]
192   pub enable_downvotes: Option<bool>,
193   #[default(None)]
194   pub open_registration: Option<bool>,
195   #[default(None)]
196   pub enable_nsfw: Option<bool>,
197   #[default(None)]
198   pub community_creation_admin_only: Option<bool>,
199   #[default(None)]
200   pub require_email_verification: Option<bool>,
201   #[default(None)]
202   pub require_application: Option<bool>,
203   #[default(None)]
204   pub application_question: Option<String>,
205   #[default(None)]
206   pub private_instance: Option<bool>,
207 }