Skip to content

Commit b28cca7

Browse files
committed
Integrate secondary SMTP and move secondary SMTP enable check to Advanced Settings
Merged secondary SMTP code from the previous branch into the latest devel branch. Added SMTP check and moved it from Notifications to Advanced Settings
1 parent 3c224e8 commit b28cca7

File tree

16 files changed

+532
-132
lines changed

16 files changed

+532
-132
lines changed

backend/globaleaks/handlers/admin/operation.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,29 @@ def disable_user_permission_file_upload(session, tid, user_session):
161161
user_session.permissions['can_upload_files'] = False
162162

163163

164-
def db_reset_smtp_settings(session, tid):
164+
def db_reset_smtp_settings(session, tid, use_smtp2=False):
165165
config = ConfigFactory(session, tid)
166-
config.set_val('smtp_server', 'mail.globaleaks.org')
167-
config.set_val('smtp_port', 587)
168-
config.set_val('smtp_username', 'globaleaks')
169-
config.set_val('smtp_password', 'globaleaks')
170-
config.set_val('smtp_source_email', 'notifications@globaleaks.org')
171-
config.set_val('smtp_security', 'TLS')
172-
config.set_val('smtp_authentication', True)
173166

167+
if use_smtp2:
168+
config.set_val('smtp2_server', 'mail.globaleaks.org')
169+
config.set_val('smtp2_port', 587)
170+
config.set_val('smtp2_username', 'globaleaks')
171+
config.set_val('smtp2_password', 'globaleaks')
172+
config.set_val('smtp2_source_email', 'notifications@globaleaks.org')
173+
config.set_val('smtp2_security', 'TLS')
174+
config.set_val('smtp2_authentication', True)
175+
else:
176+
config.set_val('smtp_server', 'mail.globaleaks.org')
177+
config.set_val('smtp_port', 587)
178+
config.set_val('smtp_username', 'globaleaks')
179+
config.set_val('smtp_password', 'globaleaks')
180+
config.set_val('smtp_source_email', 'notifications@globaleaks.org')
181+
config.set_val('smtp_security', 'TLS')
182+
config.set_val('smtp_authentication', True)
174183

175184
@transact
176-
def reset_smtp_settings(session, tid):
177-
return db_reset_smtp_settings(session, tid)
178-
185+
def reset_smtp_settings(session, tid, use_smtp2):
186+
return db_reset_smtp_settings(session, tid, use_smtp2)
179187

180188
@transact
181189
def reset_templates(session, tid):
@@ -271,7 +279,8 @@ def enable_encryption(self, req_args, *args, **kwargs):
271279
return enable_encryption(self.request.tid)
272280

273281
def reset_smtp_settings(self, req_args, *args, **kwargs):
274-
return reset_smtp_settings(self.request.tid)
282+
use_smtp2 = req_args.get('smtp2', False)
283+
return reset_smtp_settings(self.request.tid, use_smtp2=use_smtp2)
275284

276285
def disable_2fa(self, req_args, *args, **kwargs):
277286
return disable_2fa(self.request.tid, self.session.user_id, req_args['value'])
@@ -339,7 +348,9 @@ def test_mail(self, req_args, *args, **kwargs):
339348

340349
subject, body = Templating().get_mail_subject_and_body(data)
341350

342-
yield self.state.sendmail(tid, user['mail_address'], subject, body)
351+
use_smtp2 = req_args.get('smtp2', False)
352+
mail_address = req_args.get('to_mail_address', '')
353+
yield self.state.sendmail(tid, mail_address, subject, body, use_smtp2=use_smtp2)
343354

344355
def toggle_escrow(self, req_args, *args, **kwargs):
345356
return toggle_escrow(self.request.tid, self.session)

backend/globaleaks/models/config_desc.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Int(Item):
2828
class Bool(Item):
2929
_type = bool
3030

31+
class List(Item):
32+
_type = list
33+
34+
def __init__(self, *args, **kwargs):
35+
if 'default' not in kwargs:
36+
kwargs['default'] = []
37+
Item.__init__(self, *args, **kwargs)
3138

3239
ConfigDescriptor = {
3340
'acme': Bool(default=False),
@@ -108,14 +115,16 @@ class Bool(Item):
108115
'smtp_server': Unicode(default='mail.globaleaks.org'),
109116
'smtp_source_email': Unicode(default='notifications@globaleaks.org'),
110117
'smtp_username': Unicode(default='globaleaks'),
111-
'smtp2_password': Unicode(default=''),
118+
'smtp2_password': Unicode(default='globaleaks'),
112119
'smtp2_port': Int(default=587),
113-
'smtp2_security': Unicode(default=''),
114-
'smtp2_authentication': Bool(default=False),
115-
'smtp2_server': Unicode(default=''),
120+
'smtp2_security': Unicode(default='TLS'),
121+
'smtp2_authentication': Bool(default=True),
122+
'smtp2_server': Unicode(default='mail.globaleaks.org'),
116123
'smtp2_enabled': Bool(default=False),
117-
'smtp2_source_email': Unicode(default=''),
118-
'smtp2_username': Unicode(default=''),
124+
'smtp2_template_types': List(default=[]),
125+
'smtp2_failover': Bool(default=False),
126+
'smtp2_source_email': Unicode(default='notifications@globaleaks.org'),
127+
'smtp2_username': Unicode(default='globaleaks'),
119128
'subdomain': Unicode(default=''),
120129
'threshold_free_disk_megabytes_high': Int(default=200),
121130
'threshold_free_disk_megabytes_low': Int(default=1000),
@@ -211,6 +220,7 @@ class Bool(Item):
211220
'signup_tos1_enable',
212221
'signup_tos2_enable',
213222
'simplified_login',
223+
'smtp2_enabled',
214224
'subdomain',
215225
'threshold_free_disk_megabytes_high',
216226
'threshold_free_disk_megabytes_low',
@@ -278,6 +288,7 @@ class Bool(Item):
278288
'signup_tos1_enable',
279289
'signup_tos2_enable',
280290
'simplified_login',
291+
'smtp2_enabled',
281292
'subdomain',
282293
'threshold_free_disk_megabytes_high',
283294
'threshold_free_disk_megabytes_low',
@@ -362,10 +373,11 @@ class Bool(Item):
362373
'smtp2_port',
363374
'smtp2_security',
364375
'smtp2_server',
365-
'smtp2_enabled',
376+
'smtp2_template_types',
366377
'smtp2_source_email',
367378
'smtp2_username',
368-
'smtp2_authentication'
379+
'smtp2_authentication',
380+
'smtp2_failover'
369381
],
370382
'public_node': [
371383
'adminonly',

backend/globaleaks/rest/requests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def get_multilang_request_format(request_format, localized_strings):
246246
'adminonly': bool,
247247
'custom_support_url': url_regexp_or_empty,
248248
'pgp': bool,
249+
'smtp2_enabled': bool,
249250
'user_privacy_policy_text': str,
250251
'user_privacy_policy_url': str
251252
}
@@ -276,6 +277,15 @@ def get_multilang_request_format(request_format, localized_strings):
276277
'smtp_username': str,
277278
'smtp_password': str,
278279
'smtp_source_email': email_regexp,
280+
'smtp2_template_types': [str],
281+
'smtp2_server': str,
282+
'smtp2_port': int,
283+
'smtp2_security': str, # 'TLS' or 'SSL' only
284+
'smtp2_authentication': bool,
285+
'smtp2_username': str,
286+
'smtp2_password': str,
287+
'smtp2_source_email': email_regexp,
288+
'smtp2_failover': bool,
279289
'enable_admin_notification_emails': bool,
280290
'enable_analyst_notification_emails': bool,
281291
'enable_custodian_notification_emails': bool,

backend/globaleaks/state.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,50 @@ def reset_minutely(self):
196196
self.exceptions.clear()
197197
self.exceptions_email_count = 0
198198

199-
def sendmail(self, tid, to_address, subject, body):
199+
def sendmail(self, tid, to_address, subject, body, use_smtp2=False):
200200
if self.settings.disable_notifications:
201201
return succeed(True)
202-
202+
203203
if self.tenants[tid].cache.mode != 'default':
204204
tid = 1
205-
206-
return sendmail(tid,
207-
self.tenants[tid].cache.notification.smtp_server,
208-
self.tenants[tid].cache.notification.smtp_port,
209-
self.tenants[tid].cache.notification.smtp_security,
210-
self.tenants[tid].cache.notification.smtp_authentication,
211-
self.tenants[tid].cache.notification.smtp_username,
212-
self.tenants[tid].cache.notification.smtp_password,
213-
self.tenants[tid].cache.name,
214-
self.tenants[tid].cache.notification.smtp_source_email,
215-
to_address,
216-
self.tenants[tid].cache.name + ' - ' + subject,
217-
body,
218-
self.tenants[1].cache.anonymize_outgoing_connections,
219-
self.settings.socks_port)
220-
205+
206+
notification = self.tenants[tid].cache.notification
207+
smtp2_enabled = getattr(self.tenants[tid].cache, "smtp2_enabled", False)
208+
209+
if smtp2_enabled and use_smtp2:
210+
smtp_server = notification.smtp2_server
211+
smtp_port = notification.smtp2_port
212+
smtp_security = notification.smtp2_security
213+
smtp_authentication = notification.smtp2_authentication
214+
smtp_username = notification.smtp2_username
215+
smtp_password = notification.smtp2_password
216+
smtp_source_email = notification.smtp2_source_email
217+
else:
218+
smtp_server = notification.smtp_server
219+
smtp_port = notification.smtp_port
220+
smtp_security = notification.smtp_security
221+
smtp_authentication = notification.smtp_authentication
222+
smtp_username = notification.smtp_username
223+
smtp_password = notification.smtp_password
224+
smtp_source_email = notification.smtp_source_email
225+
226+
return sendmail(
227+
tid,
228+
smtp_server,
229+
smtp_port,
230+
smtp_security,
231+
smtp_authentication,
232+
smtp_username,
233+
smtp_password,
234+
self.tenants[tid].cache.name,
235+
smtp_source_email,
236+
to_address,
237+
self.tenants[tid].cache.name + ' - ' + subject,
238+
body,
239+
self.tenants[1].cache.anonymize_outgoing_connections,
240+
self.settings.socks_port
241+
)
242+
221243
def schedule_support_email(self, tid, text):
222244
subject = "Support request"
223245
delivery_list = set.union(set(self.tenants[1].cache.notification.admin_list),

client/app/src/models/resolvers/node-resolver-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class nodeResolverModel {
2929
signup_tos1_enable: boolean;
3030
signup_tos2_enable: boolean;
3131
simplified_login: boolean;
32+
smtp2_enabled: boolean;
3233
subdomain: string;
3334
threshold_free_disk_megabytes_high: number;
3435
threshold_free_disk_megabytes_low: number;

client/app/src/models/resolvers/notification-resolver-model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export class notificationResolverModel {
1010
smtp_server: string;
1111
smtp_source_email: string;
1212
smtp_username: string;
13+
smtp2_template_types: any;
14+
smtp2_failover: boolean
15+
smtp2_authentication: boolean;
16+
smtp2_password: string;
17+
smtp2_port: number;
18+
smtp2_security: string;
19+
smtp2_server: string;
20+
smtp2_source_email: string;
21+
smtp2_username: string;
1322
tip_expiration_threshold: number;
1423
account_activation_mail_template: string;
1524
account_activation_mail_title: string;

client/app/src/models/resolvers/rtips-resolver-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Data} from "@app/models/receiver/receiver-tip-data";
22

33
export interface rtipResolverModel {
44
submissionStatusStr: string;
5+
reportModificationStr: string;
56
context_name: string;
67
context?: any;
78
id: string;

0 commit comments

Comments
 (0)