]> git.proxmox.com Git - pmg-gui.git/blame - js/Utils.js
utils: align notification toast to bottom-right again
[pmg-gui.git] / js / Utils.js
CommitLineData
fe81f069
DM
1Ext.ns('PMG');
2
fe81f069
DM
3console.log("Starting PMG Manager");
4
fe81f069 5
2c7b542d
DM
6Ext.define('PMG.Utils', {
7 singleton: true,
ad834b6f 8
fe81f069
DM
9 // this singleton contains miscellaneous utilities
10
139d9b7a
TL
11 // use in panels with object spread (...) operator, for example:
12 // ...PMG.Utils.onlineHelpTool('sysadmin_certificate_management'),
13 onlineHelpTool: function(blockid) {
14 let info = Proxmox.Utils.get_help_info(blockid);
15 if (info === undefined) {
16 info = Proxmox.Utils.get_help_info('pmg_documentation_index');
17 if (info === undefined) {
18 throw "get_help_info failed"; // should not happen
19 }
20 }
21
22 let docsURI = window.location.origin + info.link;
23 let title = info.title || gettext('Help');
24 if (info.subtitle) {
25 title += ' - ' + info.subtitle;
26 }
27 return {
28 tools: [
29 {
30 type: 'help',
31 tooltip: title,
32 handler: () => window.open(docsURI),
33 },
34 ],
35 };
36 },
37
f9b851e8
DM
38 senderText: gettext('Sender'),
39 receiverText: gettext('Receiver'),
ad88af09 40 scoreText: gettext('Score'),
012f0f49 41
7818f0a3
DM
42 user_role_text: {
43 root: gettext('Superuser'),
44 admin: gettext('Administrator'),
751d131c 45 helpdesk: gettext('Help Desk'),
7818f0a3 46 qmanager: gettext('Quarantine Manager'),
8153da61 47 audit: gettext('Auditor'),
7818f0a3
DM
48 },
49
50 format_user_role: function(role) {
51 return PMG.Utils.user_role_text[role] || role;
52 },
53
c790d2ab
DM
54 oclass_text: {
55 who: gettext('Who Objects'),
56 what: gettext('What Objects'),
57 when: gettext('When Objects'),
076d6a72
DC
58 action: gettext('Action Objects'),
59 from: gettext('From'),
8153da61 60 to: gettext('To'),
076d6a72
DC
61 },
62
63 oclass_icon: {
64 who: '<span class="fa fa-fw fa-user-circle"></span> ',
65 what: '<span class="fa fa-fw fa-cube"></span> ',
66 when: '<span class="fa fa-fw fa-clock-o"></span> ',
67 action: '<span class="fa fa-fw fa-flag"></span> ',
68 from: '<span class="fa fa-fw fa-user-circle"></span> ',
8153da61 69 to: '<span class="fa fa-fw fa-user-circle"></span> ',
076d6a72
DC
70 },
71
cf248533
DM
72 mail_status_map: {
73 2: 'delivered',
74 4: 'deferred',
75 5: 'bounced',
76 N: 'rejected',
77 G: 'greylisted',
78 A: 'accepted',
79 B: 'blocked',
8153da61 80 Q: 'quarantine',
cf248533
DM
81 },
82
20d8d037
DC
83 icon_status_map_class: {
84 2: 'check-circle',
85 4: 'clock-o',
86 5: 'mail-reply',
87 N: 'times-circle',
88 G: 'list',
89 A: 'check',
90 B: 'ban',
8153da61 91 Q: 'cube',
20d8d037
DC
92 },
93
94 icon_status_map_color: {
95 2: 'green',
96 5: 'gray',
97 A: 'green',
8153da61 98 B: 'red',
c4ff49f7
DC
99 },
100
101 format_status_icon: function(status) {
20d8d037
DC
102 var icon = PMG.Utils.icon_status_map_class[status] || 'question-circle';
103 var color = PMG.Utils.icon_status_map_color[status] || '';
104 return '<i class="fa fa-' + icon + ' ' + color + '"></i> ';
c4ff49f7
DC
105 },
106
076d6a72
DC
107 format_oclass: function(oclass) {
108 var icon = PMG.Utils.oclass_icon[oclass] || '';
109 var text = PMG.Utils.oclass_text[oclass] || oclass;
110 return icon + text;
c790d2ab 111 },
ad834b6f
DM
112
113 rule_direction_text: {
114 0: gettext('In'),
115 1: gettext('Out'),
8153da61 116 2: gettext('In & Out'),
ad834b6f
DM
117 },
118
4b7e5c48 119 rule_direction_icon: {
2b97521b
DC
120 0: '<span class="fa fa-fw fa-long-arrow-left"></span> ',
121 1: '<span class="fa fa-fw fa-long-arrow-right"></span> ',
8153da61 122 2: '<span class="fa fa-fw fa-exchange"></span> ',
4b7e5c48
DC
123 },
124
ad834b6f 125 format_rule_direction: function(dir) {
4b7e5c48
DC
126 var icon = PMG.Utils.rule_direction_icon[dir] || '';
127 var text = PMG.Utils.rule_direction_text[dir] || dir;
128 return icon + text;
ad834b6f
DM
129 },
130
012f0f49
DM
131 format_otype: function(otype) {
132 var editor = PMG.Utils.object_editors[otype];
ea4f2a79 133 var iconCls = 'fa fa-question-circle';
012f0f49 134 if (editor) {
ea4f2a79
DC
135 var icon = '<span class="fa-fw ' + (editor.iconCls || iconCls) + '"></span> ';
136 return icon + editor.subject;
012f0f49 137 }
ea4f2a79
DC
138
139 return '<span class="fa-fw ' + iconCls + '"></span> unknown';
f6b1b3bf
DM
140 },
141
142 format_ldap_protocol: function(p) {
cc6b80b6
DM
143 if (p === undefined) { return 'LDAP'; }
144 if (p === 'ldap') { return 'LDAP'; }
145 if (p === 'ldaps') { return 'LDAPS'; }
3600c3c7 146 if (p === 'ldap+starttls') { return 'LDAP+STARTTLS'; }
f6b1b3bf 147 return 'unknown';
012f0f49
DM
148 },
149
b79fbba8 150 convert_field_to_per_min: function(value, record) {
8153da61 151 return value/(record.data.timespan/60);
b79fbba8
DC
152 },
153
012f0f49
DM
154 object_editors: {
155 1000: {
573a6e8b 156 onlineHelp: 'pmg_mailfilter_regex',
ea4f2a79 157 iconCls: 'fa fa-filter',
5f3ec152 158 xtype: 'proxmoxWindowEdit',
012f0f49
DM
159 subdir: 'regex',
160 subject: gettext("Regular Expression"),
f7be608f 161 width: 400,
012f0f49
DM
162 items: [
163 {
164 xtype: 'textfield',
165 name: 'regex',
f7be608f 166 labelWidth: 150,
6994550a 167 reference: 'regex',
8153da61 168 fieldLabel: gettext("Regular Expression"),
6994550a
DC
169 },
170 {
171 labelWidth: 150,
172 fieldLabel: gettext('Test String'),
173 xtype: 'pmgRegexTester',
4eab05c2 174 wholeMatch: true,
8153da61
TL
175 regexFieldReference: 'regex',
176 },
177 ],
012f0f49 178 },
5f3ec152 179 1005: {
573a6e8b 180 onlineHelp: 'pmgconfig_ldap',
ea4f2a79 181 iconCls: 'fa fa-users',
5f3ec152
DM
182 xtype: 'pmgLDAPGroupEditor',
183 subdir: 'ldap',
8153da61 184 subject: gettext("LDAP Group"),
5f3ec152 185 },
6c137003 186 1006: {
573a6e8b 187 onlineHelp: 'pmgconfig_ldap',
ea4f2a79 188 iconCls: 'fa fa-user',
6c137003
DM
189 xtype: 'pmgLDAPUserEditor',
190 subdir: 'ldapuser',
8153da61 191 subject: gettext("LDAP User"),
6c137003 192 },
012f0f49 193 1009: {
573a6e8b 194 onlineHelp: 'pmg_mailfilter_regex',
ea4f2a79 195 iconCls: 'fa fa-filter',
5f3ec152 196 xtype: 'proxmoxWindowEdit',
012f0f49
DM
197 subdir: 'receiver_regex',
198 subject: gettext("Regular Expression"),
f7be608f
DM
199 receivertest: true,
200 width: 400,
012f0f49
DM
201 items: [
202 {
203 xtype: 'textfield',
204 name: 'regex',
f7be608f 205 labelWidth: 150,
8153da61
TL
206 fieldLabel: gettext("Regular Expression"),
207 },
208 ],
012f0f49
DM
209 },
210 1001: {
573a6e8b 211 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 212 iconCls: 'fa fa-envelope-o',
5f3ec152 213 xtype: 'proxmoxWindowEdit',
012f0f49 214 subdir: 'email',
64fb657f 215 subject: gettext("E-Mail"),
f7be608f 216 width: 400,
012f0f49
DM
217 items: [
218 {
219 xtype: 'textfield',
220 name: 'email',
8153da61
TL
221 fieldLabel: gettext("E-Mail"),
222 },
223 ],
012f0f49
DM
224 },
225 1007: {
573a6e8b 226 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 227 iconCls: 'fa fa-envelope-o',
5f3ec152 228 xtype: 'proxmoxWindowEdit',
012f0f49 229 subdir: 'receiver',
64fb657f 230 subject: gettext("E-Mail"),
f7be608f
DM
231 receivertest: true,
232 width: 400,
012f0f49
DM
233 items: [
234 {
235 xtype: 'textfield',
236 name: 'email',
8153da61
TL
237 fieldLabel: gettext("E-Mail"),
238 },
239 ],
012f0f49
DM
240 },
241 1002: {
573a6e8b 242 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 243 iconCls: 'fa fa-globe',
5f3ec152 244 xtype: 'proxmoxWindowEdit',
012f0f49
DM
245 subdir: 'domain',
246 subject: gettext("Domain"),
f7be608f 247 width: 400,
012f0f49
DM
248 items: [
249 {
250 xtype: 'textfield',
251 name: 'domain',
8153da61
TL
252 fieldLabel: gettext("Domain"),
253 },
254 ],
012f0f49
DM
255 },
256 1008: {
573a6e8b 257 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 258 iconCls: 'fa fa-globe',
5f3ec152 259 xtype: 'proxmoxWindowEdit',
012f0f49
DM
260 subdir: 'receiver_domain',
261 subject: gettext("Domain"),
f7be608f
DM
262 receivertest: true,
263 width: 400,
012f0f49
DM
264 items: [
265 {
266 xtype: 'textfield',
267 name: 'domain',
8153da61
TL
268 fieldLabel: gettext("Domain"),
269 },
270 ],
012f0f49
DM
271 },
272 1003: {
573a6e8b 273 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 274 iconCls: 'fa fa-globe',
5f3ec152 275 xtype: 'proxmoxWindowEdit',
012f0f49
DM
276 subdir: 'ip',
277 subject: gettext("IP Address"),
f7be608f 278 width: 400,
012f0f49
DM
279 items: [
280 {
281 xtype: 'textfield',
282 name: 'ip',
8153da61
TL
283 fieldLabel: gettext("IP Address"),
284 },
285 ],
012f0f49
DM
286 },
287 1004: {
573a6e8b 288 onlineHelp: 'pmg_mailfilter_who',
ea4f2a79 289 iconCls: 'fa fa-globe',
5f3ec152 290 xtype: 'proxmoxWindowEdit',
012f0f49
DM
291 subdir: 'network',
292 subject: gettext("IP Network"),
f7be608f 293 width: 400,
012f0f49
DM
294 items: [
295 {
296 xtype: 'textfield',
297 name: 'cidr',
8153da61
TL
298 fieldLabel: gettext("IP Network"),
299 },
300 ],
b4eee4f7
DM
301 },
302 2000: {
573a6e8b 303 onlineHelp: 'pmg_mailfilter_when',
ea4f2a79 304 iconCls: 'fa fa-clock-o',
5f3ec152 305 xtype: 'proxmoxWindowEdit',
b4eee4f7
DM
306 subdir: 'timeframe',
307 subject: gettext("TimeFrame"),
308 items: [
309 {
310 xtype: 'timefield',
311 name: 'start',
312 format: 'H:i',
8153da61 313 fieldLabel: gettext("Start Time"),
b4eee4f7
DM
314 },
315 {
316 xtype: 'timefield',
317 name: 'end',
318 format: 'H:i',
8153da61
TL
319 fieldLabel: gettext("End Time"),
320 },
321 ],
f5de8682 322 },
bed64e74 323 3000: {
573a6e8b 324 onlineHelp: 'pmg_mailfilter_what',
ea4f2a79 325 iconCls: 'fa fa-bullhorn',
bed64e74
DC
326 xtype: 'proxmoxWindowEdit',
327 subdir: 'spamfilter',
328 subject: gettext('Spam Filter'),
329 items: [
330 {
331 xtype: 'proxmoxintegerfield',
332 name: 'spamlevel',
333 allowBlank: false,
334 minValue: 0,
8153da61
TL
335 fieldLabel: gettext('Level'),
336 },
337 ],
bed64e74 338 },
8ddd9c44 339 3001: {
573a6e8b 340 onlineHelp: 'pmg_mailfilter_what',
ea4f2a79 341 iconCls: 'fa fa-bug',
8ddd9c44
DC
342 xtype: 'proxmoxWindowEdit',
343 subdir: 'virusfilter',
344 subject: gettext('Virus Filter'),
345 uneditable: true,
346 // there are no parameters to give, so we simply submit it
347 listeners: {
348 show: function(win) {
349 win.submit();
8153da61
TL
350 },
351 },
8ddd9c44 352 },
3a9b95a7 353 3002: {
573a6e8b 354 onlineHelp: 'pmg_mailfilter_regex',
ea4f2a79 355 iconCls: 'fa fa-code',
3a9b95a7
DC
356 xtype: 'proxmoxWindowEdit',
357 subdir: 'matchfield',
358 subject: gettext('Match Field'),
50fa6520 359 width: 400,
3a9b95a7
DC
360 items: [
361 {
362 xtype: 'textfield',
363 name: 'field',
50fa6520 364 labelWidth: 150,
3a9b95a7 365 allowBlank: false,
8153da61 366 fieldLabel: gettext('Field'),
3a9b95a7
DC
367 },
368 {
369 xtype: 'textfield',
50fa6520 370 reference: 'value',
3a9b95a7 371 name: 'value',
50fa6520 372 labelWidth: 150,
3a9b95a7 373 allowBlank: false,
8153da61 374 fieldLabel: gettext('Value'),
3a9b95a7 375 },
50fa6520
DC
376 {
377 labelWidth: 150,
378 fieldLabel: gettext('Test String'),
379 xtype: 'pmgRegexTester',
8153da61
TL
380 regexFieldReference: 'value',
381 },
382 ],
3a9b95a7
DC
383 },
384 3003: {
573a6e8b 385 onlineHelp: 'pmg_mailfilter_what',
ea4f2a79 386 iconCls: 'fa fa-file-image-o',
3a9b95a7
DC
387 xtype: 'proxmoxWindowEdit',
388 subdir: 'contenttype',
389 width: 400,
3fb5067f 390 subject: gettext('Content Type Filter'),
3a9b95a7
DC
391 items: [
392 {
393 xtype: 'combobox',
394 displayField: 'text',
395 labelWidth: 150,
396 valueField: 'mimetype',
397 name: 'contenttype',
398 editable: true,
399 queryMode: 'local',
400 store: {
401 autoLoad: true,
402 proxy: {
403 type: 'proxmox',
8153da61
TL
404 url: '/api2/json/config/mimetypes',
405 },
3a9b95a7
DC
406 },
407 fieldLabel: gettext('Content Type'),
408 anyMatch: true,
409 matchFieldWidth: false,
410 listeners: {
411 change: function(cb, value) {
412 var me = this;
413 me.up().down('displayfield').setValue(value);
8153da61
TL
414 },
415 },
3a9b95a7
DC
416 },
417 {
418 xtype: 'displayfield',
419 fieldLabel: gettext('Value'),
420 labelWidth: 150,
421 allowBlank: false,
8153da61
TL
422 reset: Ext.emptyFn,
423 },
424 ],
3a9b95a7 425 },
6af39772 426 3004: {
573a6e8b 427 onlineHelp: 'pmg_mailfilter_regex',
ea4f2a79 428 iconCls: 'fa fa-file-o',
6af39772
DC
429 xtype: 'proxmoxWindowEdit',
430 subdir: 'filenamefilter',
431 width: 400,
432 subject: gettext('Match Filename'),
433 items: [
434 {
435 xtype: 'textfield',
436 name: 'filename',
437 reference: 'filename',
438 fieldLabel: gettext('Filename'),
439 labelWidth: 150,
8153da61 440 allowBlank: false,
6af39772
DC
441 },
442 {
443 labelWidth: 150,
444 fieldLabel: gettext('Test String'),
445 wholeMatch: true,
446 xtype: 'pmgRegexTester',
8153da61
TL
447 regexFieldReference: 'filename',
448 },
449 ],
6af39772 450 },
e234e99d 451 3005: {
573a6e8b 452 onlineHelp: 'pmg_mailfilter_what',
ea4f2a79 453 iconCls: 'fa fa-file-archive-o',
e234e99d
DC
454 xtype: 'proxmoxWindowEdit',
455 subdir: 'archivefilter',
456 width: 400,
457 subject: gettext('Archive Filter'),
458 items: [
459 {
460 xtype: 'combobox',
461 displayField: 'text',
462 labelWidth: 150,
463 valueField: 'mimetype',
464 name: 'contenttype',
465 editable: true,
466 queryMode: 'local',
467 store: {
468 autoLoad: true,
469 proxy: {
470 type: 'proxmox',
8153da61
TL
471 url: '/api2/json/config/mimetypes',
472 },
e234e99d
DC
473 },
474 fieldLabel: gettext('Content Type'),
475 anyMatch: true,
476 matchFieldWidth: false,
477 listeners: {
478 change: function(cb, value) {
479 var me = this;
480 me.up().down('displayfield').setValue(value);
8153da61
TL
481 },
482 },
e234e99d
DC
483 },
484 {
485 xtype: 'displayfield',
486 fieldLabel: gettext('Value'),
487 labelWidth: 150,
488 allowBlank: false,
8153da61
TL
489 reset: Ext.emptyFn,
490 },
491 ],
e234e99d 492 },
74468b03
DC
493 3006: {
494 onlineHelp: 'pmg_mailfilter_regex',
495 iconCls: 'fa fa-file-archive-o',
496 xtype: 'proxmoxWindowEdit',
497 subdir: 'archivefilenamefilter',
498 width: 400,
499 subject: gettext('Match Archive Filename'),
500 items: [
501 {
502 xtype: 'textfield',
503 name: 'filename',
504 reference: 'filename',
505 fieldLabel: gettext('Filename'),
506 labelWidth: 150,
8153da61 507 allowBlank: false,
74468b03
DC
508 },
509 {
510 labelWidth: 150,
511 fieldLabel: gettext('Test String'),
512 wholeMatch: true,
513 xtype: 'pmgRegexTester',
8153da61
TL
514 regexFieldReference: 'filename',
515 },
516 ],
74468b03 517 },
628eccdb 518 4002: {
573a6e8b 519 onlineHelp: 'pmg_mailfilter_action',
628eccdb
DC
520 xtype: 'proxmoxWindowEdit',
521 subdir: 'notification',
522 subject: gettext('Notification'),
523 width: 400,
524 items: [
525 {
526 xtype: 'textfield',
527 name: 'name',
528 allowBlank: false,
8153da61 529 fieldLabel: gettext('Name'),
628eccdb
DC
530 },
531 {
532 xtype: 'textareafield',
533 name: 'info',
8153da61 534 fieldLabel: gettext("Comment"),
628eccdb
DC
535 },
536 {
537 xtype: 'textfield',
538 name: 'to',
539 allowBlank: false,
540 value: '__ADMIN__',
8153da61 541 fieldLabel: gettext('Receiver'),
628eccdb
DC
542 },
543 {
544 xtype: 'textfield',
545 name: 'subject',
546 allowBlank: false,
547 value: 'Notification: __SUBJECT__',
8153da61 548 fieldLabel: gettext('Subject'),
628eccdb
DC
549 },
550 {
551 xtype: 'textarea',
552 name: 'body',
553 allowBlank: false,
554 grow: true,
555 growMax: 250,
556 value:
557 "Proxmox Notifcation:\n\n" +
558 "Sender: __SENDER__\n" +
559 "Receiver: __RECEIVERS__\n" +
560 "Targets: __TARGETS__\n\n" +
561 "Subject: __SUBJECT__\n\n" +
562 "Matching Rule: __RULE__\n\n" +
563 "__RULE_INFO__\n\n" +
564 "__VIRUS_INFO__\n" +
565 "__SPAM_INFO__\n",
8153da61 566 fieldLabel: gettext('Body'),
628eccdb
DC
567 },
568 {
569 xtype: 'proxmoxcheckbox',
570 name: 'attach',
8153da61
TL
571 fieldLabel: gettext("Attach orig. Mail"),
572 },
573 ],
628eccdb
DC
574 },
575 4003: {
573a6e8b 576 onlineHelp: 'pmg_mailfilter_action',
628eccdb
DC
577 xtype: 'proxmoxWindowEdit',
578 subdir: 'field',
579 subject: gettext('Header Attribute'),
580 width: 400,
581 items: [
582 {
583 xtype: 'textfield',
584 name: 'name',
585 allowBlank: false,
8153da61 586 fieldLabel: gettext('Name'),
628eccdb
DC
587 },
588 {
589 xtype: 'textareafield',
590 name: 'info',
8153da61 591 fieldLabel: gettext("Comment"),
628eccdb
DC
592 },
593 {
594 xtype: 'textfield',
595 name: 'field',
596 allowBlank: false,
8153da61 597 fieldLabel: gettext('Field'),
628eccdb
DC
598 },
599 {
600 xtype: 'textfield',
601 reference: 'value',
602 name: 'value',
603 allowBlank: false,
8153da61
TL
604 fieldLabel: gettext('Value'),
605 },
606 ],
628eccdb 607 },
f5de8682 608 4005: {
573a6e8b 609 onlineHelp: 'pmg_mailfilter_action',
5f3ec152 610 xtype: 'proxmoxWindowEdit',
f5de8682
DM
611 subdir: 'bcc',
612 subject: gettext('BCC'),
613 width: 400,
614 items: [
615 {
616 xtype: 'textfield',
617 name: 'name',
618 allowBlank: false,
8153da61 619 fieldLabel: gettext('Name'),
f5de8682
DM
620 },
621 {
622 xtype: 'textareafield',
623 name: 'info',
8153da61 624 fieldLabel: gettext("Comment"),
f5de8682
DM
625 },
626 {
627 xtype: 'textfield',
628 name: 'target',
629 allowBlank: false,
8153da61 630 fieldLabel: gettext("Target"),
f5de8682
DM
631 },
632 {
633 xtype: 'proxmoxcheckbox',
634 checked: true,
635 name: 'original',
8153da61
TL
636 fieldLabel: gettext("send orig. Mail"),
637 },
638 ],
f5de8682 639
628eccdb
DC
640 },
641 4007: {
573a6e8b 642 onlineHelp: 'pmg_mailfilter_action',
628eccdb
DC
643 xtype: 'proxmoxWindowEdit',
644 subdir: 'removeattachments',
645 subject: gettext('Remove Attachments'),
646 width: 500,
647 fieldDefaults: {
8153da61 648 labelWidth: 150,
628eccdb
DC
649 },
650 items: [
651 {
652 xtype: 'textfield',
653 name: 'name',
654 allowBlank: false,
8153da61 655 fieldLabel: gettext('Name'),
628eccdb
DC
656 },
657 {
658 xtype: 'textareafield',
659 name: 'info',
8153da61 660 fieldLabel: gettext("Comment"),
628eccdb
DC
661 },
662 {
663 xtype: 'textareafield',
664 name: 'text',
665 grow: true,
666 growMax: 250,
8153da61 667 fieldLabel: gettext("Text Replacement"),
628eccdb
DC
668 },
669 {
670 xtype: 'proxmoxcheckbox',
671 checked: true,
672 name: 'all',
8153da61 673 fieldLabel: gettext("Remove all attachments"),
572198b7
DC
674 },
675 {
676 xtype: 'proxmoxcheckbox',
677 checked: false,
678 name: 'quarantine',
8153da61
TL
679 fieldLabel: gettext("Copy orignal mail to Attachment Quarantine"),
680 },
681 ],
628eccdb
DC
682 },
683 4009: {
573a6e8b 684 onlineHelp: 'pmg_mailfilter_action',
628eccdb
DC
685 xtype: 'proxmoxWindowEdit',
686 subdir: 'disclaimer',
687 subject: gettext('Disclaimer'),
688 width: 400,
689 items: [
690 {
691 xtype: 'textfield',
692 name: 'name',
693 allowBlank: false,
8153da61 694 fieldLabel: gettext('Name'),
628eccdb
DC
695 },
696 {
697 xtype: 'textareafield',
698 name: 'info',
8153da61 699 fieldLabel: gettext("Comment"),
628eccdb
DC
700 },
701 {
702 xtype: 'textareafield',
703 name: 'disclaimer',
704 grow: true,
705 growMax: 250,
8153da61
TL
706 fieldLabel: gettext("Disclaimer"),
707 },
708 ],
709 },
012f0f49 710 },
ad834b6f 711
f1ab2a14
DC
712 updateLoginData: function(data) {
713 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
714 Proxmox.UserName = data.username;
8153da61 715 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true);
f1ab2a14
DC
716 },
717
258d48b5
DM
718 quarantineActionExtracted: false,
719
720 extractQuarantineAction: function() {
8153da61
TL
721 if (PMG.Utils.quarantineActionExtracted) {
722 return null;
723 }
258d48b5
DM
724
725 PMG.Utils.quarantineActionExtracted = true;
726
8153da61 727 let qs = Ext.Object.fromQueryString(location.search);
258d48b5 728
8153da61
TL
729 let cselect = qs.cselect;
730 let action = qs.action;
731 let dateString = qs.date;
a0a98b8d
DC
732
733 if (dateString) {
8153da61 734 let date = new Date(dateString).getTime()/1000;
a0a98b8d
DC
735
736 // set from date for QuarantineList
a0a98b8d 737 PMG.QuarantineList.from = date;
a0a98b8d 738 }
258d48b5
DM
739
740 delete qs.cselect;
741 delete qs.action;
742 delete qs.ticket;
a0a98b8d 743 delete qs.date;
258d48b5
DM
744
745 var newsearch = Ext.Object.toQueryString(qs);
746
747 var newurl = location.protocol + "//" + location.host + location.pathname;
cc6b80b6 748 if (newsearch) { newurl += '?' + newsearch; }
258d48b5
DM
749 newurl += location.hash;
750
751 if (window.history) {
8153da61 752 window.history.pushState({ path: newurl }, '', newurl);
258d48b5
DM
753 }
754
207471c0 755 if (action || cselect) {
8153da61
TL
756 return {
757 action: action,
758 cselect: cselect,
759 };
258d48b5 760 }
8153da61 761 return null;
258d48b5
DM
762 },
763
aac17b9b 764 doQuarantineAction: function(action, id, callback) {
cf5268ca
DC
765 Proxmox.Utils.API2Request({
766 url: '/quarantine/content/',
aac17b9b
DM
767 params: {
768 action: action,
8153da61 769 id: id,
aac17b9b 770 },
cf5268ca
DC
771 method: 'POST',
772 failure: function(response, opts) {
773 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
774 },
775 success: function(response, opts) {
467eb50b
TL
776 let count = id.split(';').length;
777 let fmt = count > 1
778 ? gettext("Action '{0}' for '{1}' items successful")
779 : gettext("Action '{0}' successful")
780 ;
781 let message = Ext.String.format(fmt, action, count);
782 let title = Ext.String.format("{0} successful", Ext.String.capitalize(action));
783
784 Ext.toast({
785 html: message,
786 title: title,
787 minWidth: 200,
788 hideDuration: 250,
789 slideBackDuration: 250,
790 slideBackAnimation: 'easeOut',
791 iconCls: 'fa fa-check',
92b6c1f3 792 shadow: true,
44362902 793 align: 'br',
cf5268ca
DC
794 });
795
796 if (Ext.isFunction(callback)) {
797 callback();
798 }
8153da61 799 },
cf5268ca
DC
800 });
801 },
802
19b455dd
DC
803 render_filetype: function(value) {
804 let iconCls = 'fa-file-o';
805 let text = Proxmox.Utils.unknownText;
806
807 if (!value) {
808 return `<i class='fa ${iconCls}'></i> ${text}`;
809 }
810
811 text = value.toString().toLowerCase();
8153da61 812 const type = text.split('/')[0];
19b455dd
DC
813
814 switch (type) {
815 case 'audio':
816 case 'image':
817 case 'video':
818 case 'text':
819 iconCls = `fa-file-${type}-o`;
820 break;
8153da61
TL
821 case 'application': {
822 const subtypes = ['excel', 'pdf', 'word', 'powerpoint'];
19b455dd
DC
823 let found = subtypes.find(st => text.includes(st));
824 if (found !== undefined) {
825 iconCls = `fa-file-${found}-o`;
826 }
8153da61 827 } break;
19b455dd
DC
828 default:
829 break;
830 }
831
832 return `<i class='fa ${iconCls}'></i> ${text}`;
833 },
834
cf5268ca
DC
835 sender_renderer: function(value, metaData, rec) {
836 var subject = Ext.htmlEncode(value);
837 var from = Ext.htmlEncode(rec.data.from);
838 var sender = Ext.htmlEncode(rec.data.sender);
839 if (sender) {
840 from = Ext.String.format(gettext("{0} on behalf of {1}"),
841 sender, from);
842 }
843 return '<small>' + from + '</small><br>' + subject;
844 },
845
fe81f069
DM
846 constructor: function() {
847 var me = this;
fe81f069 848
2c7b542d 849 // do whatever you want here
0db5cdb1
DC
850 Proxmox.Utils.override_task_descriptions({
851 applycustomscores: ['', gettext('Apply custom SpamAssassin scores')],
852 avupdate: ['', gettext('ClamAV update')],
853 backup: ['', gettext('Backup')],
854 clustercreate: ['', gettext('Create Cluster')],
855 clusterjoin: ['', gettext('Join Cluster')],
856 restore: ['', gettext('Restore')],
857 saupdate: ['', gettext('SpamAssassin update')],
858 });
8153da61 859 },
fe81f069 860});
3168b7f7
TL
861
862Ext.define('PMG.Async', {
863 singleton: true,
864
865 // Returns a Promise which executes a quarantine action when awaited.
866 // Shows a Toast message box once completed, if batchNumber and batchTotal
867 // are set, they will be included into the title of that toast.
868 doQAction: function(action, ids, batchNumber, batchTotal) {
869 if (!Ext.isArray(ids)) {
870 ids = [ids];
871 }
872 return Proxmox.Async.api2({
873 url: '/quarantine/content/',
874 params: {
875 action: action,
876 id: ids.join(';'),
877 },
878 method: 'POST',
879 }).then(
880 response => {
881 let count = ids.length;
882 let fmt = count > 1
883 ? gettext("Action '{0}' for '{1}' items successful")
884 : gettext("Action '{0}' successful")
885 ;
886 let message = Ext.String.format(fmt, action, count);
887 let titleFmt = batchNumber !== undefined && batchTotal > 1
888 ? gettext("{0} ({1}/{2}) successful")
889 : gettext("{0} successful")
890 ;
891 let title = Ext.String.format(
892 titleFmt,
893 Ext.String.capitalize(action),
894 batchNumber,
895 batchTotal,
896 );
897
898 Ext.toast({
899 html: message,
900 title: title,
901 minWidth: 200,
902 hideDuration: 250,
903 slideBackDuration: 250,
904 slideBackAnimation: 'easeOut',
905 iconCls: 'fa fa-check',
906 shadow: true,
44362902 907 align: 'br',
3168b7f7
TL
908 });
909 },
910 response => Proxmox.Utils.alertResponseFailure(response),
911 );
912 },
913});