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