aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts2
-rw-r--r--server/initializers/checker-after-init.ts14
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/lib/emailer.ts11
-rw-r--r--server/middlewares/validators/server.ts2
5 files changed, 20 insertions, 11 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 43b20e078..dd06a0597 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -65,7 +65,7 @@ async function getConfig (req: express.Request, res: express.Response) {
65 } 65 }
66 }, 66 },
67 email: { 67 email: {
68 enabled: Emailer.Instance.isEnabled() 68 enabled: Emailer.isEnabled()
69 }, 69 },
70 contactForm: { 70 contactForm: {
71 enabled: CONFIG.CONTACT_FORM.ENABLED 71 enabled: CONFIG.CONTACT_FORM.ENABLED
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts
index 72d846957..955d55206 100644
--- a/server/initializers/checker-after-init.ts
+++ b/server/initializers/checker-after-init.ts
@@ -10,6 +10,7 @@ import { getServerActor } from '../helpers/utils'
10import { RecentlyAddedStrategy } from '../../shared/models/redundancy' 10import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
11import { isArray } from '../helpers/custom-validators/misc' 11import { isArray } from '../helpers/custom-validators/misc'
12import { uniq } from 'lodash' 12import { uniq } from 'lodash'
13import { Emailer } from '../lib/emailer'
13 14
14async function checkActivityPubUrls () { 15async function checkActivityPubUrls () {
15 const actor = await getServerActor() 16 const actor = await getServerActor()
@@ -32,9 +33,19 @@ async function checkActivityPubUrls () {
32// Some checks on configuration files 33// Some checks on configuration files
33// Return an error message, or null if everything is okay 34// Return an error message, or null if everything is okay
34function checkConfig () { 35function checkConfig () {
35 const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY 36
37 if (!Emailer.isEnabled()) {
38 if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
39 return 'Emailer is disabled but you require signup email verification.'
40 }
41
42 if (CONFIG.CONTACT_FORM.ENABLED) {
43 logger.warn('Emailer is disabled so the contact form will not work.')
44 }
45 }
36 46
37 // NSFW policy 47 // NSFW policy
48 const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY
38 { 49 {
39 const available = [ 'do_not_list', 'blur', 'display' ] 50 const available = [ 'do_not_list', 'blur', 'display' ]
40 if (available.indexOf(defaultNSFWPolicy) === -1) { 51 if (available.indexOf(defaultNSFWPolicy) === -1) {
@@ -68,6 +79,7 @@ function checkConfig () {
68 } 79 }
69 } 80 }
70 81
82 // Check storage directory locations
71 if (isProdInstance()) { 83 if (isProdInstance()) {
72 const configStorage = config.get('storage') 84 const configStorage = config.get('storage')
73 for (const key of Object.keys(configStorage)) { 85 for (const key of Object.keys(configStorage)) {
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index a7bc7eec8..7905d9ffa 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -15,7 +15,7 @@ function checkMissedConfig () {
15 'storage.redundancy', 'storage.tmp', 15 'storage.redundancy', 'storage.tmp',
16 'log.level', 16 'log.level',
17 'user.video_quota', 'user.video_quota_daily', 17 'user.video_quota', 'user.video_quota_daily',
18 'cache.previews.size', 'admin.email', 18 'cache.previews.size', 'admin.email', 'contact_form.enabled',
19 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 19 'signup.enabled', 'signup.limit', 'signup.requires_email_verification',
20 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 20 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
21 'redundancy.videos.strategies', 'redundancy.videos.check_interval', 21 'redundancy.videos.strategies', 'redundancy.videos.check_interval',
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 9b1c5122f..f384a254e 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -18,7 +18,6 @@ class Emailer {
18 private static instance: Emailer 18 private static instance: Emailer
19 private initialized = false 19 private initialized = false
20 private transporter: Transporter 20 private transporter: Transporter
21 private enabled = false
22 21
23 private constructor () {} 22 private constructor () {}
24 23
@@ -27,7 +26,7 @@ class Emailer {
27 if (this.initialized === true) return 26 if (this.initialized === true) return
28 this.initialized = true 27 this.initialized = true
29 28
30 if (CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) { 29 if (Emailer.isEnabled()) {
31 logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) 30 logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
32 31
33 let tls 32 let tls
@@ -55,8 +54,6 @@ class Emailer {
55 tls, 54 tls,
56 auth 55 auth
57 }) 56 })
58
59 this.enabled = true
60 } else { 57 } else {
61 if (!isTestInstance()) { 58 if (!isTestInstance()) {
62 logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') 59 logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!')
@@ -64,8 +61,8 @@ class Emailer {
64 } 61 }
65 } 62 }
66 63
67 isEnabled () { 64 static isEnabled () {
68 return this.enabled 65 return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
69 } 66 }
70 67
71 async checkConnectionOrDie () { 68 async checkConnectionOrDie () {
@@ -374,7 +371,7 @@ class Emailer {
374 } 371 }
375 372
376 sendMail (to: string[], subject: string, text: string, from?: string) { 373 sendMail (to: string[], subject: string, text: string, from?: string) {
377 if (!this.enabled) { 374 if (!Emailer.isEnabled()) {
378 throw new Error('Cannot send mail because SMTP is not configured.') 375 throw new Error('Cannot send mail because SMTP is not configured.')
379 } 376 }
380 377
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts
index d82e19230..d85afc2ff 100644
--- a/server/middlewares/validators/server.ts
+++ b/server/middlewares/validators/server.ts
@@ -50,7 +50,7 @@ const contactAdministratorValidator = [
50 .end() 50 .end()
51 } 51 }
52 52
53 if (Emailer.Instance.isEnabled() === false) { 53 if (Emailer.isEnabled() === false) {
54 return res 54 return res
55 .status(409) 55 .status(409)
56 .send({ error: 'Emailer is not enabled on this instance.' }) 56 .send({ error: 'Emailer is not enabled on this instance.' })