-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmailing_setting.html.twig
418 lines (370 loc) · 16.9 KB
/
mailing_setting.html.twig
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
{#
# ---------------------------------------------------------------------
#
# GLPI - Gestionnaire Libre de Parc Informatique
#
# http://glpi-project.org
#
# @copyright 2015-2025 Teclib' and contributors.
# @copyright 2003-2014 by the INDEPNET Development Team.
# @licence https://www.gnu.org/licenses/gpl-3.0.html
#
# ---------------------------------------------------------------------
#
# LICENSE
#
# This file is part of GLPI.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------
#}
{% import 'components/form/fields_macros.html.twig' as fields %}
{% if (config('notifications_mailing') == 1) %}
{% set rand = random() %}
{% set field_options = {
'field_class': 'col-12 col-xxl-6 col-sm-6',
'rand': rand,
} %}
<form action="{{ 'NotificationMailingSetting'|itemtype_form_path }}" method="post">
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="id" value="1" />
<div class="row">
{{ fields.emailField(
'admin_email',
config('admin_email'),
__('Administrator email address'),
field_options
) }}
{{ fields.textField(
'admin_email_name',
config('admin_email_name'),
__('Administrator name'),
field_options
) }}
{{ fields.emailField(
'from_email',
config('from_email'),
__('Email sender address'),
field_options|merge({
'helper': __('Address to use in from for sent emails.') ~ '\n' ~ __('If not set, main or entity administrator email address will be used.')
})
) }}
{{ fields.textField(
'from_email_name',
config('from_email_name'),
__('Email sender name'),
field_options|merge({
'helper': __('Name to use in from for sent emails.') ~ '\n' ~ __('If not set, main or entity administrator email name will be used.')
})
) }}
{{ fields.emailField(
'replyto_email',
config('replyto_email'),
__('Reply-To address'),
field_options|merge({
'helper': __('Optionnal reply to address.') ~ '\n' ~ __('If not set, main or entity administrator email address will be used.')
})
) }}
{{ fields.textField(
'replyto_email_name',
config('replyto_email_name'),
__('Reply-To name'),
field_options|merge({
'helper': __('Optionnal reply to name.') ~ '\n' ~ __('If not set, main or entity administrator name will be used.')
})
) }}
{{ fields.emailField(
'noreply_email',
config('noreply_email'),
__('No-Reply address'),
field_options|merge({
'helper': __('Optionnal No-Reply address.') ~ '\n' ~ __('If set, it will be used for notifications that doesnʼt expect a reply.')
})
) }}
{{ fields.textField(
'noreply_email_name',
config('noreply_email_name'),
__('No-Reply name'),
field_options|merge({
'helper': __('Optionnal No-Reply name.') ~ '\n' ~ __('If not set, main or entity administrator name will be used.')
})
) }}
{{ fields.dropdownArrayField(
"attach_ticket_documents_to_mail",
config('attach_ticket_documents_to_mail'),
attach_documents_values,
__('Add documents into ticket notifications'),
field_options
) }}
{{ fields.nullField() }}
{{ fields.textareaField(
'mailing_signature',
config('mailing_signature'),
__('Email signature'),
field_options
) }}
{{ fields.nullField() }}
{% set extra_options = {} %}
{% if not is_mail_function_available %}
{% set extra_options = {
'helper': __('The PHP mail function is unknown or is not activated on your system.') ~ '\n' ~ __('The use of a SMTP is needed.')
} %}
{% endif %}
{{ fields.dropdownArrayField(
"smtp_mode",
config('smtp_mode'),
mail_methods,
__('Way of sending emails'),
field_options|merge(extra_options)
) }}
<script type="text/javascript">
$(function() {
$('[name=smtp_mode]').on('change', function() {
const value = $(this).find('option:selected').val();
const is_mail = value === '{{ constant('MAIL_MAIL') }}';
const is_oauth = value === '{{ constant('MAIL_SMTPOAUTH') }}';
$('#smtp_config').toggle(!is_mail);
// show/hide elements not related to Oauth
$('#dropdown_smtp_check_certificate{{ rand }}').closest('.form-field').toggle(!is_oauth);
$('#smtp_passwd_{{ rand }}').closest('.form-field').toggle(!is_oauth);
$('#smtp_username_{{ rand }}').closest('.form-field').toggle(!is_oauth);
// show/hide elements related to Oauth
$('#oauth_redirect_alert_{{ rand }}').toggleClass('d-none', !is_oauth);
$('#_smtp_oauth_callback_url_{{ rand }}').closest('.form-field').toggle(is_oauth);
$('#dropdown_smtp_oauth_provider{{ rand }}').closest('.form-field').toggle(is_oauth);
$('#smtp_oauth_client_id_{{ rand }}').closest('.form-field').toggle(is_oauth);
$('#smtp_oauth_client_secret_{{ rand }}').closest('.form-field').toggle(is_oauth);
$('#_force_redirect_to_smtp_oauth_{{ rand }}').closest('.form-field').toggle(is_oauth);
$('[name=smtp_oauth_provider]').trigger('change'); // refresh additional params using dedicated method
});
$('[name=smtp_mode]').trigger('change');
});
</script>
{{ fields.nullField() }}
{{ fields.numberField(
'smtp_max_retries',
config('smtp_max_retries'),
__('Max. delivery retries'),
field_options
) }}
{{ fields.numberField(
'smtp_retry_time',
config('smtp_retry_time'),
__('Try to deliver again in (minutes)'),
field_options|merge({
'min': 0,
'max': 60,
'step': 1,
})
) }}
</div>
<div class="row" id="smtp_config">
<div class="hr-text">
<i class="{{ 'AuthMail'|itemtype_icon }}"></i>
<span>{{ 'AuthMail'|itemtype_name }}</span>
</div>
<div id="oauth_redirect_alert_{{ rand }}" class="d-flex alert alert-info mx-2">
<i class="ti ti-info-circle fs-2x alert-icon"></i>
{{ __('Once the form has been validated, you will be redirected to your supplierʼs authentication page if necessary.') }}
</div>
{{ fields.dropdownArrayField(
'smtp_oauth_provider',
config('smtp_oauth_provider'),
providers_values,
__('Oauth provider'),
field_options|merge({'display_emptychoice': true})
) }}
{{ fields.textField(
'_smtp_oauth_callback_url',
config('url_base') ~ '/front/smtp_oauth2_callback.php',
_x('oauth', 'Callback URL'),
field_options|merge({
'helper': _x('oauth', 'This is the callback URL that you will have to declare in your provider application.'),
'is_copyable': true,
'readonly': true,
})
) }}
{{ fields.textField(
'smtp_oauth_client_id',
config('smtp_oauth_client_id'),
_x('oauth', 'Client ID'),
field_options,
) }}
{{ fields.passwordField(
'smtp_oauth_client_secret',
'',
_x('oauth', 'Client secret'),
field_options|merge({
'clearable': false,
'additional_attributes': {
'autocomplete': 'new-password',
}
}),
) }}
{% for provider_class in supported_providers %}
{% for param_specs in call(provider_class ~ '::getAdditionalParameters') %}
{% set extra_options = {
'additional_attributes': {
'data-oauth_additional_parameter': 'true',
'data-oauth_provider': provider_class,
},
} %}
{% if param_specs.helper is defined %}
{% set extra_options = extra_options|merge({
'helper': param_specs['helper'],
}) %}
{% endif %}
{{ fields.textField(
'smtp_oauth_options[' ~ param_specs['key'] ~ ']',
config('smtp_oauth_provider') == provider_class ? (provider_options[param_specs['key']] ?? param_specs['default'] ?? '') : '',
param_specs['label'],
field_options|merge(extra_options),
) }}
{# force new line #}
<div class="w-100"></div>
{% endfor %}
{% endfor %}
<script type='text/javascript'>
$(function() {
$('[name=smtp_oauth_provider]').on('change', function() {
const value = $(this).find('option:selected').val();
$(this.closest('form')).find('[data-oauth_additional_parameter="true"]').each(
function (key, field) {
const row = $(field).closest('.form-field');
const matches_current_provider = value === $(field).attr('data-oauth_provider');
row.toggle(matches_current_provider);
row.find('input, select').prop('disabled', !matches_current_provider);
}
);
});
$('[name=smtp_oauth_provider]').trigger('change');
});
</script>
{% if config('smtp_oauth_refresh_token') != '' %}
{{ fields.checkboxField(
'_force_redirect_to_smtp_oauth',
'',
_x('oauth', 'Force OAuth authentication refresh'),
field_options|merge({
'helper': _x('oauth', 'You can use this option to force redirection to the OAuth authentication process. This will trigger generation of a new OAuth token.')
})
) }}
{# force new line #}
<div class="w-100"></div>
{% endif %}
{{ fields.dropdownYesNo(
'smtp_check_certificate',
config('smtp_check_certificate'),
__('Check certificate'),
field_options,
) }}
{# force new line #}
<div class="w-100"></div>
{{ fields.textField(
'smtp_host',
config('smtp_host'),
__('SMTP host'),
field_options,
) }}
{{ fields.numberField(
'smtp_port',
config('smtp_port'),
_n('Port', 'Ports', 1),
field_options,
) }}
{{ fields.textField(
'smtp_username',
config('smtp_username'),
__('SMTP login (optional)'),
field_options,
) }}
{{ fields.passwordField(
'smtp_passwd',
'',
__('SMTP password (optional)'),
field_options|merge({
'additional_attributes': {
'autocomplete': 'new-password',
}
}),
) }}
{{ fields.emailField(
'smtp_sender',
config('smtp_sender'),
__('Email sender'),
field_options|merge({
'helper': __('May be required for some mails providers.') ~ '\n' ~ __('If not set, main administrator email will be used.')
})
) }}
</div>
<div class="card-footer mx-n2 mb-4 d-flex flex-row-reverse align-items-start flex-wrap">
<button type="submit" name="update" value="1" class="btn btn-primary">
<i class="ti ti-device-floppy"></i>
<span>{{ _x('button', 'Save') }}</span>
</button>
<button type="button" id="test-email-btn" class="btn btn-outline-secondary me-2" name="test_smtp_send" value="1">
{{ __('Send a test email to the administrator') }}
</button>
<div class="modal fade" id="mailTestLogModal" tabindex="-1" role="dialog" aria-labelledby="mailTestLogModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="mailTestLogModalLabel">{{ __('Email sending test result') }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
<script>
$('#test-email-btn').on('click', function () {
const $modal = $('#mailTestLogModal');
$.ajax({
url: CFG_GLPI.root_doc + '/ajax/notificationmailingsettings.php',
method: 'POST',
data: {
'test_smtp_send': 1
}
}).done(function (data) {
const successText = data.success ? __('Success') : __('Error');
const successClass = data.success ? 'bg-success' : 'bg-danger';
const errorSection = data.error ? `<div><h4>${__('Error')}</h4><pre style="white-space: pre-wrap;">${data.error}</pre></div>` : '';
const debugSection = data.debug ? `<div><h4>${__('Logs')}</h4><pre style="white-space: pre-wrap;">${data.debug}</pre></div>` : '';
const modalBodyContent = `
<div>
<span class="badge mb-3 ${successClass}">${successText}</span>
</div>
${errorSection}
${debugSection}
`;
$modal.find('.modal-body').html(modalBodyContent);
$modal.modal('show');
});
});
</script>
</div>
</form>
{% else %}
<div class="row">
<div class="col">
<div class="alert alert-info">
<i class="ti ti-info-circle fs-2x alert-icon"></i>
{{ __('Notifications are disabled.') }}
<a href="{{ config('root_doc') }}/front/setup.notification.php">{{ __('See configuration') }}</a>
</div>
</div>
</div>
{% endif %}