]> git.proxmox.com Git - pmg-gui.git/blame - js/Utils.js
reword the action success message to not show the id
[pmg-gui.git] / js / Utils.js
CommitLineData
2c1d504e 1/*global Proxmox */
fe81f069
DM
2Ext.ns('PMG');
3
fe81f069
DM
4console.log("Starting PMG Manager");
5
fe81f069 6
2c7b542d
DM
7Ext.define('PMG.Utils', {
8 singleton: true,
ad834b6f 9
fe81f069
DM
10 // this singleton contains miscellaneous utilities
11
f9b851e8
DM
12 senderText: gettext('Sender'),
13 receiverText: gettext('Receiver'),
ad88af09 14 scoreText: gettext('Score'),
012f0f49 15
7818f0a3
DM
16 user_role_text: {
17 root: gettext('Superuser'),
18 admin: gettext('Administrator'),
751d131c 19 helpdesk: gettext('Help Desk'),
7818f0a3 20 qmanager: gettext('Quarantine Manager'),
771bd0b9 21 audit: gettext('Auditor')
7818f0a3
DM
22 },
23
24 format_user_role: function(role) {
25 return PMG.Utils.user_role_text[role] || role;
26 },
27
c790d2ab
DM
28 oclass_text: {
29 who: gettext('Who Objects'),
30 what: gettext('What Objects'),
31 when: gettext('When Objects'),
076d6a72
DC
32 action: gettext('Action Objects'),
33 from: gettext('From'),
34 to: gettext('To')
35 },
36
37 oclass_icon: {
38 who: '<span class="fa fa-fw fa-user-circle"></span> ',
39 what: '<span class="fa fa-fw fa-cube"></span> ',
40 when: '<span class="fa fa-fw fa-clock-o"></span> ',
41 action: '<span class="fa fa-fw fa-flag"></span> ',
42 from: '<span class="fa fa-fw fa-user-circle"></span> ',
cc6b80b6 43 to: '<span class="fa fa-fw fa-user-circle"></span> '
076d6a72
DC
44 },
45
cf248533
DM
46 mail_status_map: {
47 2: 'delivered',
48 4: 'deferred',
49 5: 'bounced',
50 N: 'rejected',
51 G: 'greylisted',
52 A: 'accepted',
53 B: 'blocked',
54 Q: 'quarantine'
55 },
56
20d8d037
DC
57 icon_status_map_class: {
58 2: 'check-circle',
59 4: 'clock-o',
60 5: 'mail-reply',
61 N: 'times-circle',
62 G: 'list',
63 A: 'check',
64 B: 'ban',
65 Q: 'cube'
66 },
67
68 icon_status_map_color: {
69 2: 'green',
70 5: 'gray',
71 A: 'green',
72 B: 'red'
c4ff49f7
DC
73 },
74
75 format_status_icon: function(status) {
20d8d037
DC
76 var icon = PMG.Utils.icon_status_map_class[status] || 'question-circle';
77 var color = PMG.Utils.icon_status_map_color[status] || '';
78 return '<i class="fa fa-' + icon + ' ' + color + '"></i> ';
c4ff49f7
DC
79 },
80
076d6a72
DC
81 format_oclass: function(oclass) {
82 var icon = PMG.Utils.oclass_icon[oclass] || '';
83 var text = PMG.Utils.oclass_text[oclass] || oclass;
84 return icon + text;
c790d2ab 85 },
ad834b6f
DM
86
87 rule_direction_text: {
88 0: gettext('In'),
89 1: gettext('Out'),
90 2: gettext('In & Out')
91 },
92
4b7e5c48 93 rule_direction_icon: {
2b97521b
DC
94 0: '<span class="fa fa-fw fa-long-arrow-left"></span> ',
95 1: '<span class="fa fa-fw fa-long-arrow-right"></span> ',
96 2: '<span class="fa fa-fw fa-exchange"></span> '
4b7e5c48
DC
97 },
98
ad834b6f 99 format_rule_direction: function(dir) {
4b7e5c48
DC
100 var icon = PMG.Utils.rule_direction_icon[dir] || '';
101 var text = PMG.Utils.rule_direction_text[dir] || dir;
102 return icon + text;
ad834b6f
DM
103 },
104
012f0f49
DM
105 format_otype: function(otype) {
106 var editor = PMG.Utils.object_editors[otype];
ea4f2a79 107 var iconCls = 'fa fa-question-circle';
012f0f49 108 if (editor) {
ea4f2a79
DC
109 var icon = '<span class="fa-fw ' + (editor.iconCls || iconCls) + '"></span> ';
110 return icon + editor.subject;
012f0f49 111 }
ea4f2a79
DC
112
113 return '<span class="fa-fw ' + iconCls + '"></span> unknown';
f6b1b3bf
DM
114 },
115
116 format_ldap_protocol: function(p) {
cc6b80b6
DM
117 if (p === undefined) { return 'LDAP'; }
118 if (p === 'ldap') { return 'LDAP'; }
119 if (p === 'ldaps') { return 'LDAPS'; }
f6b1b3bf 120 return 'unknown';
012f0f49
DM
121 },
122
b79fbba8
DC
123 convert_field_to_per_min: function(value, record) {
124 return (value/(record.data.timespan/60));
125 },
126
012f0f49
DM
127 object_editors: {
128 1000: {
ea4f2a79 129 iconCls: 'fa fa-filter',
5f3ec152 130 xtype: 'proxmoxWindowEdit',
012f0f49
DM
131 subdir: 'regex',
132 subject: gettext("Regular Expression"),
f7be608f 133 width: 400,
012f0f49
DM
134 items: [
135 {
136 xtype: 'textfield',
137 name: 'regex',
f7be608f 138 labelWidth: 150,
6994550a 139 reference: 'regex',
012f0f49 140 fieldLabel: gettext("Regular Expression")
6994550a
DC
141 },
142 {
143 labelWidth: 150,
144 fieldLabel: gettext('Test String'),
145 xtype: 'pmgRegexTester',
146 regexFieldReference: 'regex'
012f0f49
DM
147 }
148 ]
149 },
5f3ec152 150 1005: {
ea4f2a79 151 iconCls: 'fa fa-users',
5f3ec152
DM
152 xtype: 'pmgLDAPGroupEditor',
153 subdir: 'ldap',
154 subject: gettext("LDAP Group")
155 },
6c137003 156 1006: {
ea4f2a79 157 iconCls: 'fa fa-user',
6c137003
DM
158 xtype: 'pmgLDAPUserEditor',
159 subdir: 'ldapuser',
160 subject: gettext("LDAP User")
161 },
012f0f49 162 1009: {
ea4f2a79 163 iconCls: 'fa fa-filter',
5f3ec152 164 xtype: 'proxmoxWindowEdit',
012f0f49
DM
165 subdir: 'receiver_regex',
166 subject: gettext("Regular Expression"),
f7be608f
DM
167 receivertest: true,
168 width: 400,
012f0f49
DM
169 items: [
170 {
171 xtype: 'textfield',
172 name: 'regex',
f7be608f 173 labelWidth: 150,
012f0f49
DM
174 fieldLabel: gettext("Regular Expression")
175 }
176 ]
177 },
178 1001: {
ea4f2a79 179 iconCls: 'fa fa-envelope-o',
5f3ec152 180 xtype: 'proxmoxWindowEdit',
012f0f49 181 subdir: 'email',
64fb657f 182 subject: gettext("E-Mail"),
f7be608f 183 width: 400,
012f0f49
DM
184 items: [
185 {
186 xtype: 'textfield',
187 name: 'email',
64fb657f 188 fieldLabel: gettext("E-Mail")
012f0f49
DM
189 }
190 ]
191 },
192 1007: {
ea4f2a79 193 iconCls: 'fa fa-envelope-o',
5f3ec152 194 xtype: 'proxmoxWindowEdit',
012f0f49 195 subdir: 'receiver',
64fb657f 196 subject: gettext("E-Mail"),
f7be608f
DM
197 receivertest: true,
198 width: 400,
012f0f49
DM
199 items: [
200 {
201 xtype: 'textfield',
202 name: 'email',
64fb657f 203 fieldLabel: gettext("E-Mail")
012f0f49
DM
204 }
205 ]
206 },
207 1002: {
ea4f2a79 208 iconCls: 'fa fa-globe',
5f3ec152 209 xtype: 'proxmoxWindowEdit',
012f0f49
DM
210 subdir: 'domain',
211 subject: gettext("Domain"),
f7be608f 212 width: 400,
012f0f49
DM
213 items: [
214 {
215 xtype: 'textfield',
216 name: 'domain',
217 fieldLabel: gettext("Domain")
218 }
219 ]
220 },
221 1008: {
ea4f2a79 222 iconCls: 'fa fa-globe',
5f3ec152 223 xtype: 'proxmoxWindowEdit',
012f0f49
DM
224 subdir: 'receiver_domain',
225 subject: gettext("Domain"),
f7be608f
DM
226 receivertest: true,
227 width: 400,
012f0f49
DM
228 items: [
229 {
230 xtype: 'textfield',
231 name: 'domain',
232 fieldLabel: gettext("Domain")
233 }
234 ]
235 },
236 1003: {
ea4f2a79 237 iconCls: 'fa fa-globe',
5f3ec152 238 xtype: 'proxmoxWindowEdit',
012f0f49
DM
239 subdir: 'ip',
240 subject: gettext("IP Address"),
f7be608f 241 width: 400,
012f0f49
DM
242 items: [
243 {
244 xtype: 'textfield',
245 name: 'ip',
246 fieldLabel: gettext("IP Address")
247 }
248 ]
249 },
250 1004: {
ea4f2a79 251 iconCls: 'fa fa-globe',
5f3ec152 252 xtype: 'proxmoxWindowEdit',
012f0f49
DM
253 subdir: 'network',
254 subject: gettext("IP Network"),
f7be608f 255 width: 400,
012f0f49
DM
256 items: [
257 {
258 xtype: 'textfield',
259 name: 'cidr',
260 fieldLabel: gettext("IP Network")
261 }
262 ]
b4eee4f7
DM
263 },
264 2000: {
ea4f2a79 265 iconCls: 'fa fa-clock-o',
5f3ec152 266 xtype: 'proxmoxWindowEdit',
b4eee4f7
DM
267 subdir: 'timeframe',
268 subject: gettext("TimeFrame"),
269 items: [
270 {
271 xtype: 'timefield',
272 name: 'start',
273 format: 'H:i',
274 fieldLabel: gettext("Start Time")
275 },
276 {
277 xtype: 'timefield',
278 name: 'end',
279 format: 'H:i',
280 fieldLabel: gettext("End Time")
281 }
282 ]
f5de8682 283 },
bed64e74 284 3000: {
ea4f2a79 285 iconCls: 'fa fa-bullhorn',
bed64e74
DC
286 xtype: 'proxmoxWindowEdit',
287 subdir: 'spamfilter',
288 subject: gettext('Spam Filter'),
289 items: [
290 {
291 xtype: 'proxmoxintegerfield',
292 name: 'spamlevel',
293 allowBlank: false,
294 minValue: 0,
295 fieldLabel: gettext('Level')
cc6b80b6 296 }
bed64e74
DC
297 ]
298 },
8ddd9c44 299 3001: {
ea4f2a79 300 iconCls: 'fa fa-bug',
8ddd9c44
DC
301 xtype: 'proxmoxWindowEdit',
302 subdir: 'virusfilter',
303 subject: gettext('Virus Filter'),
304 uneditable: true,
305 // there are no parameters to give, so we simply submit it
306 listeners: {
307 show: function(win) {
308 win.submit();
309 }
310 }
311 },
3a9b95a7 312 3002: {
ea4f2a79 313 iconCls: 'fa fa-code',
3a9b95a7
DC
314 xtype: 'proxmoxWindowEdit',
315 subdir: 'matchfield',
316 subject: gettext('Match Field'),
50fa6520 317 width: 400,
3a9b95a7
DC
318 items: [
319 {
320 xtype: 'textfield',
321 name: 'field',
50fa6520 322 labelWidth: 150,
3a9b95a7
DC
323 allowBlank: false,
324 fieldLabel: gettext('Field')
325 },
326 {
327 xtype: 'textfield',
50fa6520 328 reference: 'value',
3a9b95a7 329 name: 'value',
50fa6520 330 labelWidth: 150,
3a9b95a7
DC
331 allowBlank: false,
332 fieldLabel: gettext('Value')
333 },
50fa6520
DC
334 {
335 labelWidth: 150,
336 fieldLabel: gettext('Test String'),
337 xtype: 'pmgRegexTester',
cc6b80b6 338 regexFieldReference: 'value'
50fa6520 339 }
3a9b95a7
DC
340 ]
341 },
342 3003: {
ea4f2a79 343 iconCls: 'fa fa-file-image-o',
3a9b95a7
DC
344 xtype: 'proxmoxWindowEdit',
345 subdir: 'contenttype',
346 width: 400,
3fb5067f 347 subject: gettext('Content Type Filter'),
3a9b95a7
DC
348 items: [
349 {
350 xtype: 'combobox',
351 displayField: 'text',
352 labelWidth: 150,
353 valueField: 'mimetype',
354 name: 'contenttype',
355 editable: true,
356 queryMode: 'local',
357 store: {
358 autoLoad: true,
359 proxy: {
360 type: 'proxmox',
361 url: '/api2/json/config/mimetypes'
cc6b80b6 362 }
3a9b95a7
DC
363 },
364 fieldLabel: gettext('Content Type'),
365 anyMatch: true,
366 matchFieldWidth: false,
367 listeners: {
368 change: function(cb, value) {
369 var me = this;
370 me.up().down('displayfield').setValue(value);
371 }
372 }
373 },
374 {
375 xtype: 'displayfield',
376 fieldLabel: gettext('Value'),
377 labelWidth: 150,
378 allowBlank: false,
3fb5067f 379 reset: Ext.emptyFn
cc6b80b6 380 }
3a9b95a7
DC
381 ]
382 },
6af39772 383 3004: {
ea4f2a79 384 iconCls: 'fa fa-file-o',
6af39772
DC
385 xtype: 'proxmoxWindowEdit',
386 subdir: 'filenamefilter',
387 width: 400,
388 subject: gettext('Match Filename'),
389 items: [
390 {
391 xtype: 'textfield',
392 name: 'filename',
393 reference: 'filename',
394 fieldLabel: gettext('Filename'),
395 labelWidth: 150,
396 allowBlank: false
397 },
398 {
399 labelWidth: 150,
400 fieldLabel: gettext('Test String'),
401 wholeMatch: true,
402 xtype: 'pmgRegexTester',
403 regexFieldReference: 'filename'
404 }
405 ]
406 },
e234e99d 407 3005: {
ea4f2a79 408 iconCls: 'fa fa-file-archive-o',
e234e99d
DC
409 xtype: 'proxmoxWindowEdit',
410 subdir: 'archivefilter',
411 width: 400,
412 subject: gettext('Archive Filter'),
413 items: [
414 {
415 xtype: 'combobox',
416 displayField: 'text',
417 labelWidth: 150,
418 valueField: 'mimetype',
419 name: 'contenttype',
420 editable: true,
421 queryMode: 'local',
422 store: {
423 autoLoad: true,
424 proxy: {
425 type: 'proxmox',
426 url: '/api2/json/config/mimetypes'
cc6b80b6 427 }
e234e99d
DC
428 },
429 fieldLabel: gettext('Content Type'),
430 anyMatch: true,
431 matchFieldWidth: false,
432 listeners: {
433 change: function(cb, value) {
434 var me = this;
435 me.up().down('displayfield').setValue(value);
436 }
437 }
438 },
439 {
440 xtype: 'displayfield',
441 fieldLabel: gettext('Value'),
442 labelWidth: 150,
443 allowBlank: false,
444 reset: Ext.emptyFn
445 }
446 ]
447 },
628eccdb
DC
448 4002: {
449 xtype: 'proxmoxWindowEdit',
450 subdir: 'notification',
451 subject: gettext('Notification'),
452 width: 400,
453 items: [
454 {
455 xtype: 'textfield',
456 name: 'name',
457 allowBlank: false,
458 fieldLabel: gettext('Name')
459 },
460 {
461 xtype: 'textareafield',
462 name: 'info',
463 fieldLabel: gettext("Description")
464 },
465 {
466 xtype: 'textfield',
467 name: 'to',
468 allowBlank: false,
469 value: '__ADMIN__',
470 fieldLabel: gettext('Receiver')
471 },
472 {
473 xtype: 'textfield',
474 name: 'subject',
475 allowBlank: false,
476 value: 'Notification: __SUBJECT__',
477 fieldLabel: gettext('Subject')
478 },
479 {
480 xtype: 'textarea',
481 name: 'body',
482 allowBlank: false,
483 grow: true,
484 growMax: 250,
485 value:
486 "Proxmox Notifcation:\n\n" +
487 "Sender: __SENDER__\n" +
488 "Receiver: __RECEIVERS__\n" +
489 "Targets: __TARGETS__\n\n" +
490 "Subject: __SUBJECT__\n\n" +
491 "Matching Rule: __RULE__\n\n" +
492 "__RULE_INFO__\n\n" +
493 "__VIRUS_INFO__\n" +
494 "__SPAM_INFO__\n",
495 fieldLabel: gettext('Body')
496 },
497 {
498 xtype: 'proxmoxcheckbox',
499 name: 'attach',
500 fieldLabel: gettext("Attach orig. Mail")
501 }
502 ]
503 },
504 4003: {
505 xtype: 'proxmoxWindowEdit',
506 subdir: 'field',
507 subject: gettext('Header Attribute'),
508 width: 400,
509 items: [
510 {
511 xtype: 'textfield',
512 name: 'name',
513 allowBlank: false,
514 fieldLabel: gettext('Name')
515 },
516 {
517 xtype: 'textareafield',
518 name: 'info',
519 fieldLabel: gettext("Description")
520 },
521 {
522 xtype: 'textfield',
523 name: 'field',
524 allowBlank: false,
525 fieldLabel: gettext('Field')
526 },
527 {
528 xtype: 'textfield',
529 reference: 'value',
530 name: 'value',
531 allowBlank: false,
532 fieldLabel: gettext('Value')
533 }
534 ]
535 },
f5de8682 536 4005: {
5f3ec152 537 xtype: 'proxmoxWindowEdit',
f5de8682
DM
538 subdir: 'bcc',
539 subject: gettext('BCC'),
540 width: 400,
541 items: [
542 {
543 xtype: 'textfield',
544 name: 'name',
545 allowBlank: false,
546 fieldLabel: gettext('Name')
547 },
548 {
549 xtype: 'textareafield',
550 name: 'info',
551 fieldLabel: gettext("Description")
552 },
553 {
554 xtype: 'textfield',
555 name: 'target',
556 allowBlank: false,
557 fieldLabel: gettext("Target")
558 },
559 {
560 xtype: 'proxmoxcheckbox',
561 checked: true,
562 name: 'original',
563 fieldLabel: gettext("send orig. Mail")
564 }
565 ]
566
628eccdb
DC
567 },
568 4007: {
569 xtype: 'proxmoxWindowEdit',
570 subdir: 'removeattachments',
571 subject: gettext('Remove Attachments'),
572 width: 500,
573 fieldDefaults: {
574 labelWidth: 150
575 },
576 items: [
577 {
578 xtype: 'textfield',
579 name: 'name',
580 allowBlank: false,
581 fieldLabel: gettext('Name')
582 },
583 {
584 xtype: 'textareafield',
585 name: 'info',
586 fieldLabel: gettext("Description")
587 },
588 {
589 xtype: 'textareafield',
590 name: 'text',
591 grow: true,
592 growMax: 250,
593 fieldLabel: gettext("Text Replacement")
594 },
595 {
596 xtype: 'proxmoxcheckbox',
597 checked: true,
598 name: 'all',
599 fieldLabel: gettext("Remove all attachments")
600 }
601 ]
602 },
603 4009: {
604 xtype: 'proxmoxWindowEdit',
605 subdir: 'disclaimer',
606 subject: gettext('Disclaimer'),
607 width: 400,
608 items: [
609 {
610 xtype: 'textfield',
611 name: 'name',
612 allowBlank: false,
613 fieldLabel: gettext('Name')
614 },
615 {
616 xtype: 'textareafield',
617 name: 'info',
618 fieldLabel: gettext("Description")
619 },
620 {
621 xtype: 'textareafield',
622 name: 'disclaimer',
623 grow: true,
624 growMax: 250,
625 fieldLabel: gettext("Disclaimer")
626 }
627 ]
012f0f49
DM
628 }
629 },
ad834b6f 630
f1ab2a14
DC
631 updateLoginData: function(data) {
632 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
633 Proxmox.UserName = data.username;
634 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
635 },
636
258d48b5
DM
637 quarantineActionExtracted: false,
638
639 extractQuarantineAction: function() {
640
cc6b80b6 641 if (PMG.Utils.quarantineActionExtracted) { return; }
258d48b5
DM
642
643 PMG.Utils.quarantineActionExtracted = true;
644
645 var qs = Ext.Object.fromQueryString(location.search);
646
647 var cselect = qs.cselect;
648 var action = qs.action;
649 var ticket = qs.ticket;
a0a98b8d
DC
650 var dateString = qs.date;
651
652 if (dateString) {
653 var date = new Date(dateString).getTime()/1000;
654
655 // set from date for QuarantineList
656 /*jslint confusion: true*/
657 /*from is a string above and number here */
658 PMG.QuarantineList.from = date;
659 /*jslint confusion: false*/
660 }
258d48b5
DM
661
662 delete qs.cselect;
663 delete qs.action;
664 delete qs.ticket;
a0a98b8d 665 delete qs.date;
258d48b5
DM
666
667 var newsearch = Ext.Object.toQueryString(qs);
668
669 var newurl = location.protocol + "//" + location.host + location.pathname;
cc6b80b6 670 if (newsearch) { newurl += '?' + newsearch; }
258d48b5
DM
671 newurl += location.hash;
672
673 if (window.history) {
674 window.history.pushState({ path:newurl }, '', newurl);
675 }
676
207471c0 677 if (action || cselect) {
258d48b5
DM
678 return { action: action, cselect: cselect };
679 }
680 },
681
aac17b9b 682 doQuarantineAction: function(action, id, callback) {
74901b37
DC
683 var count = id.split(';').length;
684 var successMessage = "Action '{0}'";
685 if (count > 1) {
686 successMessage += " for '{1}' items";
687 }
688 successMessage += " successful";
689
690 /*jslint confusion: true*/
691 /*format is string and function*/
cf5268ca
DC
692 Proxmox.Utils.API2Request({
693 url: '/quarantine/content/',
aac17b9b
DM
694 params: {
695 action: action,
696 id: id
697 },
cf5268ca
DC
698 method: 'POST',
699 failure: function(response, opts) {
700 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
701 },
702 success: function(response, opts) {
2fa0b505
DC
703 var win = Ext.create('Ext.window.MessageBox',{
704 closeAction: 'destroy'
705 }).show({
cf5268ca 706 title: gettext('Info'),
74901b37 707 message: Ext.String.format(successMessage, action, count),
cf5268ca
DC
708 buttons: Ext.Msg.OK,
709 icon: Ext.MessageBox.INFO
710 });
711
712 if (Ext.isFunction(callback)) {
713 callback();
714 }
715 }
716 });
74901b37 717 /*jslint confusion: false*/
cf5268ca
DC
718 },
719
720 sender_renderer: function(value, metaData, rec) {
721 var subject = Ext.htmlEncode(value);
722 var from = Ext.htmlEncode(rec.data.from);
723 var sender = Ext.htmlEncode(rec.data.sender);
724 if (sender) {
de0ebd99
DC
725 /*jslint confusion: true*/
726 /*format is a string above*/
cf5268ca
DC
727 from = Ext.String.format(gettext("{0} on behalf of {1}"),
728 sender, from);
de0ebd99 729 /*jslint confusion: false*/
cf5268ca
DC
730 }
731 return '<small>' + from + '</small><br>' + subject;
732 },
733
fe81f069
DM
734 constructor: function() {
735 var me = this;
fe81f069 736
2c7b542d 737 // do whatever you want here
fe81f069
DM
738 }
739});