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