/
GlobalSettings.js
290 lines (237 loc) · 11 KB
/
GlobalSettings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { Meteor } from 'meteor/meteor';
import { LdapSettings } from '/imports/config/LdapSettings';
import _ from 'lodash';
function getSetting(path, def = undefined) {
return _.get(Meteor.settings, path, def);
}
/**
* Wrapper to access our Global Settings.
*/
export class GlobalSettings {
/**
* Publish designated settings which should be
* accessible for the client (e.g. enableEmailDelivery).
* This method should be called on meteor server startup.
* Caution: do not publish settings like api keys or passwords!
*/
static publishSettings() {
if (Meteor.settings.public === undefined) {
Meteor.settings.public = {};
}
Meteor.settings.public.enableMailDelivery =
(Meteor.settings.email && Meteor.settings.email.enableMailDelivery !== undefined)
? Meteor.settings.email.enableMailDelivery
: false;
Meteor.settings.public.branding = {};
Meteor.settings.public.branding.topLeftLogoHTML =
(Meteor.settings.branding && Meteor.settings.branding.topLeftLogoHTML !== undefined)
? Meteor.settings.branding.topLeftLogoHTML
: '4Minitz.com';
Meteor.settings.public.branding.showGithubCorner =
(Meteor.settings.branding && Meteor.settings.branding.showGithubCorner !== undefined)
? Meteor.settings.branding.showGithubCorner
: true;
Meteor.settings.public.branding.showInfoOnLogin =
(Meteor.settings.branding && Meteor.settings.branding.showInfoOnLogin !== undefined)
? Meteor.settings.branding.showInfoOnLogin
: true;
Meteor.settings.public.branding.createDemoAccount =
(Meteor.settings.branding && Meteor.settings.branding.createDemoAccount !== undefined)
? Meteor.settings.branding.createDemoAccount
: false; // #Security: if this setting is not present, we will *NOT* create a demo user account!
Meteor.settings.public.branding.legalNotice =
(Meteor.settings.branding && Meteor.settings.branding.legalNotice !== undefined)
? Meteor.settings.branding.legalNotice
: { enabled: false,
linkText: '',
content: ['']};
Meteor.settings.public.attachments = {};
Meteor.settings.public.attachments.enabled =
(Meteor.settings.attachments && Meteor.settings.attachments.enabled !== undefined)
? Meteor.settings.attachments.enabled
: false;
Meteor.settings.public.attachments.allowExtensions =
(Meteor.settings.attachments && Meteor.settings.attachments.allowExtensions !== undefined)
? Meteor.settings.attachments.allowExtensions
: '.*';
Meteor.settings.public.attachments.denyExtensions =
(Meteor.settings.attachments && Meteor.settings.attachments.denyExtensions !== undefined)
? Meteor.settings.attachments.denyExtensions
: 'exe|app|bat|sh|cmd|com|cpl|exe|gad|hta|inf|jar|jpe|jse|lnk|msc|msh|msi|msp|pif|ps1|ps2|psc|reg|scf|scr|vbe|vbs|wsc|wsf|wsh';
Meteor.settings.public.attachments.maxFileSize =
(Meteor.settings.attachments && Meteor.settings.attachments.maxFileSize !== undefined)
? Meteor.settings.attachments.maxFileSize
: 10 * 1024 * 1024; // default: 10 MB
Meteor.settings.public.docGeneration = {};
Meteor.settings.public.docGeneration.enabled =
(Meteor.settings.docGeneration && Meteor.settings.docGeneration.enabled !== undefined)
? Meteor.settings.docGeneration.enabled
: false;
Meteor.settings.public.docGeneration.format =
(Meteor.settings.docGeneration && Meteor.settings.docGeneration.enabled !== undefined)
? Meteor.settings.docGeneration.format
: 'html';
Meteor.settings.public.forbidClientAccountCreation =
(Meteor.settings.forbidClientAccountCreation !== undefined)
? Meteor.settings.forbidClientAccountCreation
: false;
Meteor.settings.public.sendVerificationEmail =
(Meteor.settings.email && Meteor.settings.email.sendVerificationEmail !== undefined)
? Meteor.settings.email.sendVerificationEmail
: false;
Meteor.settings.public.showResendVerificationEmailLink =
(Meteor.settings.email && Meteor.settings.email.showResendVerificationEmailLink !== undefined)
? Meteor.settings.email.showResendVerificationEmailLink
: false;
Meteor.settings.public.showForgotPasswordLink =
(Meteor.settings.email && Meteor.settings.email.showForgotPasswordLink !== undefined)
? Meteor.settings.email.showForgotPasswordLink
: false;
Meteor.settings.public.isEnd2EndTest = Meteor.settings.isEnd2EndTest;
// enforce slash "/" at the end
if (Meteor.settings.attachments && Meteor.settings.attachments.storagePath) {
if (! Meteor.settings.attachments.storagePath.match(/\/$/)) {
Meteor.settings.attachments.storagePath = Meteor.settings.attachments.storagePath + '/';
}
}
LdapSettings.publish();
}
static getAdminIDs() {
let adminIDs = [];
if (Meteor.settings.adminIDs && Array.isArray(Meteor.settings.adminIDs)) {
adminIDs = adminIDs.concat(Meteor.settings.adminIDs);
}
return adminIDs;
}
static forbidClientAccountCreation() {
return getSetting('forbidClientAccountCreation', false);
}
static getRootUrl(path) {
if (Meteor.settings.ROOT_URL) {
return Meteor.absoluteUrl(path, { rootUrl: Meteor.settings.ROOT_URL });
}
return Meteor.absoluteUrl(path);
}
static hasImportUsersCronTab() {
return !!(Meteor.settings.ldap && Meteor.settings.ldap.enabled && Meteor.settings.ldap.importCronTab);
}
static getImportUsersCronTab() {
if (Meteor.settings.ldap && Meteor.settings.ldap.enabled) {
return Meteor.settings.ldap.importCronTab;
}
}
static getImportUsersOnLaunch() {
if (Meteor.settings.ldap && Meteor.settings.ldap.enabled) {
if (Meteor.settings.ldap.importOnLaunch !== undefined) {
return Meteor.settings.ldap.importOnLaunch;
}
return true;
}
return false;
}
static getLDAPSettings() {
return Meteor.settings.ldap || {};
}
static isTrustedIntranetInstallation() {
// returns false instead of undefined
return !!Meteor.settings.trustedIntranetInstallation;
}
static getDefaultLabels() {
if (!Meteor.settings.defaultLabels) return [];
return Meteor.settings.defaultLabels;
}
static getSiteName() {
if (!Meteor.settings.siteName) {
return '4Minitz';
}
return Meteor.settings.siteName;
}
static getDefaultEmailSenderAddress(alternativeSender) {
let address = (Meteor.settings.email)
? Meteor.settings.email.defaultEMailSenderAddress
: undefined;
if (address
&& alternativeSender
&& Meteor.settings.email
&& Meteor.settings.email.defaultEMailSenderExceptionDomains
&& Meteor.settings.email.defaultEMailSenderExceptionDomains.length > 0) {
let senderDomain = alternativeSender.replace(/^.*@/, '').toLowerCase(); // me@mycompany.com => mycompany.com
for (let i=0; i<Meteor.settings.email.defaultEMailSenderExceptionDomains.length; i++) {
if (Meteor.settings.email.defaultEMailSenderExceptionDomains[i].toLowerCase() === senderDomain) {
address = alternativeSender;
break;
}
}
}
if (address !== undefined) { // we have default from settings
if (address === '') { // but it's empty!
return (alternativeSender) // luckily we have a real user profile mail
? alternativeSender // we take it!
: GlobalSettings.getFallbackEMailSenderAddress(); // nope. use fallback!
} else {
return address;
}
}
throw new Meteor.Error('illegal-state', 'defaultEMailSenderAddress not defined in settings');
}
static getFallbackEMailSenderAddress() {
if (Meteor.settings.email && Meteor.settings.email.fallbackEMailSenderAddress) {
return Meteor.settings.email.fallbackEMailSenderAddress;
}
throw new Meteor.Error('illegal-state', 'fallback email sender address required but not defined in settings');
}
static isEMailDeliveryEnabled() {
if (!Meteor.settings.public) {
return false;
}
return Meteor.settings.public.enableMailDelivery;
}
static getMailDeliverer() {
if (Meteor.settings.email && Meteor.settings.email.mailDeliverer) {
return Meteor.settings.email.mailDeliverer;
}
return 'smtp';
}
static sendVerificationEmail() {
const mailEnabled = getSetting('email.enableMailDelivery', false),
sendVerificationEmail = getSetting('email.sendVerificationEmail', false);
return mailEnabled && sendVerificationEmail;
}
static showResendVerificationEmailLink() {
const mailEnabled = getSetting('email.enableMailDelivery', false),
showResendVerificationEmailLink = getSetting('email.showResendVerificationEmailLink', false);
return mailEnabled && showResendVerificationEmailLink;
}
static showForgotPasswordLink() {
const mailEnabled = getSetting('email.enableMailDelivery', false),
showForgotPasswordLink = getSetting('email.showForgotPasswordLink', false);
return mailEnabled && showForgotPasswordLink;
}
static getSMTPMailUrl() {
if (Meteor.settings.email && Meteor.settings.email.smtp && Meteor.settings.email.smtp.mailUrl) {
return Meteor.settings.email.smtp.mailUrl;
}
return '';
}
static getMailgunSettings() {
if (Meteor.settings.email && Meteor.settings.email.mailgun) {
return Meteor.settings.email.mailgun;
}
throw new Meteor.Error('illegal-state', 'mailgun settings not defined in meteor settings');
}
static getBrandingLogoHTML() {
return Meteor.settings.public.branding.topLeftLogoHTML;
}
static showGithubCorner() {
return Meteor.settings.public.branding.showGithubCorner;
}
static showInfoOnLogin() {
return Meteor.settings.public.branding.showInfoOnLogin;
}
static createDemoAccount() {
return Meteor.settings.public.branding.createDemoAccount;
}
static getAttachmentsEnabled() {
return Meteor.settings.public.attachments.enabled;
}
}