3 console
.log("Starting PMG Manager");
6 Ext
.define('PMG.Utils', {
9 // this singleton contains miscellaneous utilities
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
22 let docsURI
= window
.location
.origin
+ info
.link
;
23 let title
= info
.title
|| gettext('Help');
25 title
+= ' - ' + info
.subtitle
;
32 handler
: () => window
.open(docsURI
),
38 senderText
: gettext('Sender'),
39 receiverText
: gettext('Receiver'),
40 scoreText
: gettext('Score'),
43 root
: gettext('Superuser'),
44 admin
: gettext('Administrator'),
45 helpdesk
: gettext('Help Desk'),
46 qmanager
: gettext('Quarantine Manager'),
47 audit
: gettext('Auditor'),
50 format_user_role: function(role
) {
51 return PMG
.Utils
.user_role_text
[role
] || role
;
55 who
: gettext('Who Objects'),
56 what
: gettext('What Objects'),
57 when
: gettext('When Objects'),
58 action
: gettext('Action Objects'),
59 from: gettext('From'),
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> ',
69 to
: '<span class="fa fa-fw fa-user-circle"></span> ',
83 icon_status_map_class
: {
94 icon_status_map_color
: {
101 format_status_icon: function(status
) {
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> ';
107 format_oclass: function(oclass
) {
108 var icon
= PMG
.Utils
.oclass_icon
[oclass
] || '';
109 var text
= PMG
.Utils
.oclass_text
[oclass
] || oclass
;
113 rule_direction_text
: {
116 2: gettext('In & Out'),
119 rule_direction_icon
: {
120 0: '<span class="fa fa-fw fa-long-arrow-left"></span> ',
121 1: '<span class="fa fa-fw fa-long-arrow-right"></span> ',
122 2: '<span class="fa fa-fw fa-exchange"></span> ',
125 format_rule_direction: function(dir
) {
126 var icon
= PMG
.Utils
.rule_direction_icon
[dir
] || '';
127 var text
= PMG
.Utils
.rule_direction_text
[dir
] || dir
;
131 format_otype: function(otype
) {
132 var editor
= PMG
.Utils
.object_editors
[otype
];
133 var iconCls
= 'fa fa-question-circle';
135 var icon
= '<span class="fa-fw ' + (editor
.iconCls
|| iconCls
) + '"></span> ';
136 return icon
+ editor
.subject
;
139 return '<span class="fa-fw ' + iconCls
+ '"></span> unknown';
142 format_ldap_protocol: function(p
) {
143 if (p
=== undefined) { return 'LDAP'; }
144 if (p
=== 'ldap') { return 'LDAP'; }
145 if (p
=== 'ldaps') { return 'LDAPS'; }
146 if (p
=== 'ldap+starttls') { return 'LDAP+STARTTLS'; }
150 convert_field_to_per_min: function(value
, record
) {
151 return value
/(record.data.timespan/60);
156 onlineHelp
: 'pmg_mailfilter_regex',
157 iconCls
: 'fa fa-filter',
158 xtype
: 'proxmoxWindowEdit',
160 subject
: gettext("Regular Expression"),
168 fieldLabel
: gettext("Regular Expression"),
172 fieldLabel
: gettext('Test String'),
173 xtype
: 'pmgRegexTester',
175 regexFieldReference
: 'regex',
180 onlineHelp
: 'pmgconfig_ldap',
181 iconCls
: 'fa fa-users',
182 xtype
: 'pmgLDAPGroupEditor',
184 subject
: gettext("LDAP Group"),
187 onlineHelp
: 'pmgconfig_ldap',
188 iconCls
: 'fa fa-user',
189 xtype
: 'pmgLDAPUserEditor',
191 subject
: gettext("LDAP User"),
194 onlineHelp
: 'pmg_mailfilter_regex',
195 iconCls
: 'fa fa-filter',
196 xtype
: 'proxmoxWindowEdit',
197 subdir
: 'receiver_regex',
198 subject
: gettext("Regular Expression"),
206 fieldLabel
: gettext("Regular Expression"),
211 onlineHelp
: 'pmg_mailfilter_who',
212 iconCls
: 'fa fa-envelope-o',
213 xtype
: 'proxmoxWindowEdit',
215 subject
: gettext("E-Mail"),
221 fieldLabel
: gettext("E-Mail"),
226 onlineHelp
: 'pmg_mailfilter_who',
227 iconCls
: 'fa fa-envelope-o',
228 xtype
: 'proxmoxWindowEdit',
230 subject
: gettext("E-Mail"),
237 fieldLabel
: gettext("E-Mail"),
242 onlineHelp
: 'pmg_mailfilter_who',
243 iconCls
: 'fa fa-globe',
244 xtype
: 'proxmoxWindowEdit',
246 subject
: gettext("Domain"),
252 fieldLabel
: gettext("Domain"),
257 onlineHelp
: 'pmg_mailfilter_who',
258 iconCls
: 'fa fa-globe',
259 xtype
: 'proxmoxWindowEdit',
260 subdir
: 'receiver_domain',
261 subject
: gettext("Domain"),
268 fieldLabel
: gettext("Domain"),
273 onlineHelp
: 'pmg_mailfilter_who',
274 iconCls
: 'fa fa-globe',
275 xtype
: 'proxmoxWindowEdit',
277 subject
: gettext("IP Address"),
283 fieldLabel
: gettext("IP Address"),
288 onlineHelp
: 'pmg_mailfilter_who',
289 iconCls
: 'fa fa-globe',
290 xtype
: 'proxmoxWindowEdit',
292 subject
: gettext("IP Network"),
298 fieldLabel
: gettext("IP Network"),
303 onlineHelp
: 'pmg_mailfilter_when',
304 iconCls
: 'fa fa-clock-o',
305 xtype
: 'proxmoxWindowEdit',
307 subject
: gettext("TimeFrame"),
313 fieldLabel
: gettext("Start Time"),
319 fieldLabel
: gettext("End Time"),
324 onlineHelp
: 'pmg_mailfilter_what',
325 iconCls
: 'fa fa-bullhorn',
326 xtype
: 'proxmoxWindowEdit',
327 subdir
: 'spamfilter',
328 subject
: gettext('Spam Filter'),
331 xtype
: 'proxmoxintegerfield',
335 fieldLabel
: gettext('Level'),
340 onlineHelp
: 'pmg_mailfilter_what',
341 iconCls
: 'fa fa-bug',
342 xtype
: 'proxmoxWindowEdit',
343 subdir
: 'virusfilter',
344 subject
: gettext('Virus Filter'),
346 // there are no parameters to give, so we simply submit it
348 show: function(win
) {
354 onlineHelp
: 'pmg_mailfilter_regex',
355 iconCls
: 'fa fa-code',
356 xtype
: 'proxmoxWindowEdit',
357 subdir
: 'matchfield',
358 subject
: gettext('Match Field'),
366 fieldLabel
: gettext('Field'),
374 fieldLabel
: gettext('Value'),
378 fieldLabel
: gettext('Test String'),
379 xtype
: 'pmgRegexTester',
380 regexFieldReference
: 'value',
385 onlineHelp
: 'pmg_mailfilter_what',
386 iconCls
: 'fa fa-file-image-o',
387 xtype
: 'proxmoxWindowEdit',
388 subdir
: 'contenttype',
390 subject
: gettext('Content Type Filter'),
394 displayField
: 'text',
396 valueField
: 'mimetype',
404 url
: '/api2/json/config/mimetypes',
407 fieldLabel
: gettext('Content Type'),
409 matchFieldWidth
: false,
411 change: function(cb
, value
) {
413 me
.up().down('displayfield').setValue(value
);
418 xtype
: 'displayfield',
419 fieldLabel
: gettext('Value'),
427 onlineHelp
: 'pmg_mailfilter_regex',
428 iconCls
: 'fa fa-file-o',
429 xtype
: 'proxmoxWindowEdit',
430 subdir
: 'filenamefilter',
432 subject
: gettext('Match Filename'),
437 reference
: 'filename',
438 fieldLabel
: gettext('Filename'),
444 fieldLabel
: gettext('Test String'),
446 xtype
: 'pmgRegexTester',
447 regexFieldReference
: 'filename',
452 onlineHelp
: 'pmg_mailfilter_what',
453 iconCls
: 'fa fa-file-archive-o',
454 xtype
: 'proxmoxWindowEdit',
455 subdir
: 'archivefilter',
457 subject
: gettext('Archive Filter'),
461 displayField
: 'text',
463 valueField
: 'mimetype',
471 url
: '/api2/json/config/mimetypes',
474 fieldLabel
: gettext('Content Type'),
476 matchFieldWidth
: false,
478 change: function(cb
, value
) {
480 me
.up().down('displayfield').setValue(value
);
485 xtype
: 'displayfield',
486 fieldLabel
: gettext('Value'),
494 onlineHelp
: 'pmg_mailfilter_regex',
495 iconCls
: 'fa fa-file-archive-o',
496 xtype
: 'proxmoxWindowEdit',
497 subdir
: 'archivefilenamefilter',
499 subject
: gettext('Match Archive Filename'),
504 reference
: 'filename',
505 fieldLabel
: gettext('Filename'),
511 fieldLabel
: gettext('Test String'),
513 xtype
: 'pmgRegexTester',
514 regexFieldReference
: 'filename',
519 onlineHelp
: 'pmg_mailfilter_action',
520 xtype
: 'proxmoxWindowEdit',
521 subdir
: 'notification',
522 subject
: gettext('Notification'),
529 fieldLabel
: gettext('Name'),
532 xtype
: 'textareafield',
534 fieldLabel
: gettext("Comment"),
541 fieldLabel
: gettext('Receiver'),
547 value
: 'Notification: __SUBJECT__',
548 fieldLabel
: gettext('Subject'),
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" +
566 fieldLabel
: gettext('Body'),
569 xtype
: 'proxmoxcheckbox',
571 fieldLabel
: gettext("Attach orig. Mail"),
576 onlineHelp
: 'pmg_mailfilter_action',
577 xtype
: 'proxmoxWindowEdit',
579 subject
: gettext('Header Attribute'),
586 fieldLabel
: gettext('Name'),
589 xtype
: 'textareafield',
591 fieldLabel
: gettext("Comment"),
597 fieldLabel
: gettext('Field'),
604 fieldLabel
: gettext('Value'),
609 onlineHelp
: 'pmg_mailfilter_action',
610 xtype
: 'proxmoxWindowEdit',
612 subject
: gettext('BCC'),
619 fieldLabel
: gettext('Name'),
622 xtype
: 'textareafield',
624 fieldLabel
: gettext("Comment"),
630 fieldLabel
: gettext("Target"),
633 xtype
: 'proxmoxcheckbox',
636 fieldLabel
: gettext("send orig. Mail"),
642 onlineHelp
: 'pmg_mailfilter_action',
643 xtype
: 'proxmoxWindowEdit',
644 subdir
: 'removeattachments',
645 subject
: gettext('Remove Attachments'),
655 fieldLabel
: gettext('Name'),
658 xtype
: 'textareafield',
660 fieldLabel
: gettext("Comment"),
663 xtype
: 'textareafield',
667 fieldLabel
: gettext("Text Replacement"),
670 xtype
: 'proxmoxcheckbox',
673 fieldLabel
: gettext("Remove all attachments"),
676 xtype
: 'proxmoxcheckbox',
679 fieldLabel
: gettext("Copy orignal mail to Attachment Quarantine"),
684 onlineHelp
: 'pmg_mailfilter_action',
685 xtype
: 'proxmoxWindowEdit',
686 subdir
: 'disclaimer',
687 subject
: gettext('Disclaimer'),
694 fieldLabel
: gettext('Name'),
697 xtype
: 'textareafield',
699 fieldLabel
: gettext("Comment"),
702 xtype
: 'textareafield',
706 fieldLabel
: gettext("Disclaimer"),
712 updateLoginData: function(data
) {
713 Proxmox
.CSRFPreventionToken
= data
.CSRFPreventionToken
;
714 Proxmox
.UserName
= data
.username
;
715 Ext
.util
.Cookies
.set('PMGAuthCookie', data
.ticket
, null, '/', null, true);
718 quarantineActionExtracted
: false,
720 extractQuarantineAction: function() {
721 if (PMG
.Utils
.quarantineActionExtracted
) {
725 PMG
.Utils
.quarantineActionExtracted
= true;
727 let qs
= Ext
.Object
.fromQueryString(location
.search
);
729 let cselect
= qs
.cselect
;
730 let action
= qs
.action
;
731 let dateString
= qs
.date
;
734 let date
= new Date(dateString
).getTime()/1000;
736 // set from date for QuarantineList
737 PMG
.QuarantineList
.from = date
;
745 var newsearch
= Ext
.Object
.toQueryString(qs
);
747 var newurl
= location
.protocol
+ "//" + location
.host
+ location
.pathname
;
748 if (newsearch
) { newurl
+= '?' + newsearch
; }
749 newurl
+= location
.hash
;
751 if (window
.history
) {
752 window
.history
.pushState({ path
: newurl
}, '', newurl
);
755 if (action
|| cselect
) {
764 doQuarantineAction: function(action
, id
, callback
) {
765 Proxmox
.Utils
.API2Request({
766 url
: '/quarantine/content/',
772 failure: function(response
, opts
) {
773 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
775 success: function(response
, opts
) {
776 let count
= id
.split(';').length
;
778 ? gettext("Action '{0}' for '{1}' items successful")
779 : gettext("Action '{0}' successful")
781 let message
= Ext
.String
.format(fmt
, action
, count
);
782 let title
= Ext
.String
.format("{0} successful", Ext
.String
.capitalize(action
));
789 slideBackDuration
: 250,
790 slideBackAnimation
: 'easeOut',
791 iconCls
: 'fa fa-check',
795 if (Ext
.isFunction(callback
)) {
802 render_filetype: function(value
) {
803 let iconCls
= 'fa-file-o';
804 let text
= Proxmox
.Utils
.unknownText
;
807 return `<i class='fa ${iconCls}'></i> ${text}`;
810 text
= value
.toString().toLowerCase();
811 const type
= text
.split('/')[0];
818 iconCls
= `fa-file-${type}-o`;
820 case 'application': {
821 const subtypes
= ['excel', 'pdf', 'word', 'powerpoint'];
822 let found
= subtypes
.find(st
=> text
.includes(st
));
823 if (found
!== undefined) {
824 iconCls
= `fa-file-${found}-o`;
831 return `<i class='fa ${iconCls}'></i> ${text}`;
834 sender_renderer: function(value
, metaData
, rec
) {
835 var subject
= Ext
.htmlEncode(value
);
836 var from = Ext
.htmlEncode(rec
.data
.from);
837 var sender
= Ext
.htmlEncode(rec
.data
.sender
);
839 from = Ext
.String
.format(gettext("{0} on behalf of {1}"),
842 return '<small>' + from + '</small><br>' + subject
;
845 constructor: function() {
848 // do whatever you want here
849 Proxmox
.Utils
.override_task_descriptions({
850 applycustomscores
: ['', gettext('Apply custom SpamAssassin scores')],
851 avupdate
: ['', gettext('ClamAV update')],
852 backup
: ['', gettext('Backup')],
853 clustercreate
: ['', gettext('Create Cluster')],
854 clusterjoin
: ['', gettext('Join Cluster')],
855 restore
: ['', gettext('Restore')],
856 saupdate
: ['', gettext('SpamAssassin update')],