-/*global Proxmox */
Ext.ns('PMG');
console.log("Starting PMG Manager");
// this singleton contains miscellaneous utilities
+ // use in panels with object spread (...) operator, for example:
+ // ...PMG.Utils.onlineHelpTool('sysadmin_certificate_management'),
+ onlineHelpTool: function(blockid) {
+ let info = Proxmox.Utils.get_help_info(blockid);
+ if (info === undefined) {
+ info = Proxmox.Utils.get_help_info('pmg_documentation_index');
+ if (info === undefined) {
+ throw "get_help_info failed"; // should not happen
+ }
+ }
+
+ let docsURI = window.location.origin + info.link;
+ let title = info.title || gettext('Help');
+ if (info.subtitle) {
+ title += ' - ' + info.subtitle;
+ }
+ return {
+ tools: [
+ {
+ type: 'help',
+ tooltip: title,
+ handler: () => window.open(docsURI),
+ },
+ ],
+ };
+ },
+
senderText: gettext('Sender'),
receiverText: gettext('Receiver'),
scoreText: gettext('Score'),
admin: gettext('Administrator'),
helpdesk: gettext('Help Desk'),
qmanager: gettext('Quarantine Manager'),
- audit: gettext('Auditor')
+ audit: gettext('Auditor'),
},
format_user_role: function(role) {
when: gettext('When Objects'),
action: gettext('Action Objects'),
from: gettext('From'),
- to: gettext('To')
+ to: gettext('To'),
},
oclass_icon: {
when: '<span class="fa fa-fw fa-clock-o"></span> ',
action: '<span class="fa fa-fw fa-flag"></span> ',
from: '<span class="fa fa-fw fa-user-circle"></span> ',
- to: '<span class="fa fa-fw fa-user-circle"></span> '
+ to: '<span class="fa fa-fw fa-user-circle"></span> ',
},
mail_status_map: {
G: 'greylisted',
A: 'accepted',
B: 'blocked',
- Q: 'quarantine'
+ Q: 'quarantine',
},
icon_status_map_class: {
G: 'list',
A: 'check',
B: 'ban',
- Q: 'cube'
+ Q: 'cube',
},
icon_status_map_color: {
2: 'green',
5: 'gray',
A: 'green',
- B: 'red'
+ B: 'red',
},
format_status_icon: function(status) {
rule_direction_text: {
0: gettext('In'),
1: gettext('Out'),
- 2: gettext('In & Out')
+ 2: gettext('In & Out'),
},
rule_direction_icon: {
0: '<span class="fa fa-fw fa-long-arrow-left"></span> ',
1: '<span class="fa fa-fw fa-long-arrow-right"></span> ',
- 2: '<span class="fa fa-fw fa-exchange"></span> '
+ 2: '<span class="fa fa-fw fa-exchange"></span> ',
},
format_rule_direction: function(dir) {
},
convert_field_to_per_min: function(value, record) {
- return (value/(record.data.timespan/60));
+ return value/(record.data.timespan/60);
},
object_editors: {
name: 'regex',
labelWidth: 150,
reference: 'regex',
- fieldLabel: gettext("Regular Expression")
+ fieldLabel: gettext("Regular Expression"),
},
{
labelWidth: 150,
fieldLabel: gettext('Test String'),
xtype: 'pmgRegexTester',
wholeMatch: true,
- regexFieldReference: 'regex'
- }
- ]
+ regexFieldReference: 'regex',
+ },
+ ],
},
1005: {
onlineHelp: 'pmgconfig_ldap',
iconCls: 'fa fa-users',
xtype: 'pmgLDAPGroupEditor',
subdir: 'ldap',
- subject: gettext("LDAP Group")
+ subject: gettext("LDAP Group"),
},
1006: {
onlineHelp: 'pmgconfig_ldap',
iconCls: 'fa fa-user',
xtype: 'pmgLDAPUserEditor',
subdir: 'ldapuser',
- subject: gettext("LDAP User")
+ subject: gettext("LDAP User"),
},
1009: {
onlineHelp: 'pmg_mailfilter_regex',
xtype: 'textfield',
name: 'regex',
labelWidth: 150,
- fieldLabel: gettext("Regular Expression")
- }
- ]
+ fieldLabel: gettext("Regular Expression"),
+ },
+ ],
},
1001: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'email',
- fieldLabel: gettext("E-Mail")
- }
- ]
+ fieldLabel: gettext("E-Mail"),
+ },
+ ],
},
1007: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'email',
- fieldLabel: gettext("E-Mail")
- }
- ]
+ fieldLabel: gettext("E-Mail"),
+ },
+ ],
},
1002: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'domain',
- fieldLabel: gettext("Domain")
- }
- ]
+ fieldLabel: gettext("Domain"),
+ },
+ ],
},
1008: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'domain',
- fieldLabel: gettext("Domain")
- }
- ]
+ fieldLabel: gettext("Domain"),
+ },
+ ],
},
1003: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'ip',
- fieldLabel: gettext("IP Address")
- }
- ]
+ fieldLabel: gettext("IP Address"),
+ },
+ ],
},
1004: {
onlineHelp: 'pmg_mailfilter_who',
{
xtype: 'textfield',
name: 'cidr',
- fieldLabel: gettext("IP Network")
- }
- ]
+ fieldLabel: gettext("IP Network"),
+ },
+ ],
},
2000: {
onlineHelp: 'pmg_mailfilter_when',
xtype: 'timefield',
name: 'start',
format: 'H:i',
- fieldLabel: gettext("Start Time")
+ fieldLabel: gettext("Start Time"),
},
{
xtype: 'timefield',
name: 'end',
format: 'H:i',
- fieldLabel: gettext("End Time")
- }
- ]
+ fieldLabel: gettext("End Time"),
+ },
+ ],
},
3000: {
onlineHelp: 'pmg_mailfilter_what',
name: 'spamlevel',
allowBlank: false,
minValue: 0,
- fieldLabel: gettext('Level')
- }
- ]
+ fieldLabel: gettext('Level'),
+ },
+ ],
},
3001: {
onlineHelp: 'pmg_mailfilter_what',
listeners: {
show: function(win) {
win.submit();
- }
- }
+ },
+ },
},
3002: {
onlineHelp: 'pmg_mailfilter_regex',
name: 'field',
labelWidth: 150,
allowBlank: false,
- fieldLabel: gettext('Field')
+ fieldLabel: gettext('Field'),
},
{
xtype: 'textfield',
name: 'value',
labelWidth: 150,
allowBlank: false,
- fieldLabel: gettext('Value')
+ fieldLabel: gettext('Value'),
},
{
labelWidth: 150,
fieldLabel: gettext('Test String'),
xtype: 'pmgRegexTester',
- regexFieldReference: 'value'
- }
- ]
+ regexFieldReference: 'value',
+ },
+ ],
},
3003: {
onlineHelp: 'pmg_mailfilter_what',
autoLoad: true,
proxy: {
type: 'proxmox',
- url: '/api2/json/config/mimetypes'
- }
+ url: '/api2/json/config/mimetypes',
+ },
},
fieldLabel: gettext('Content Type'),
anyMatch: true,
change: function(cb, value) {
var me = this;
me.up().down('displayfield').setValue(value);
- }
- }
+ },
+ },
},
{
xtype: 'displayfield',
fieldLabel: gettext('Value'),
labelWidth: 150,
allowBlank: false,
- reset: Ext.emptyFn
- }
- ]
+ reset: Ext.emptyFn,
+ },
+ ],
},
3004: {
onlineHelp: 'pmg_mailfilter_regex',
reference: 'filename',
fieldLabel: gettext('Filename'),
labelWidth: 150,
- allowBlank: false
+ allowBlank: false,
},
{
labelWidth: 150,
fieldLabel: gettext('Test String'),
wholeMatch: true,
xtype: 'pmgRegexTester',
- regexFieldReference: 'filename'
- }
- ]
+ regexFieldReference: 'filename',
+ },
+ ],
},
3005: {
onlineHelp: 'pmg_mailfilter_what',
autoLoad: true,
proxy: {
type: 'proxmox',
- url: '/api2/json/config/mimetypes'
- }
+ url: '/api2/json/config/mimetypes',
+ },
},
fieldLabel: gettext('Content Type'),
anyMatch: true,
change: function(cb, value) {
var me = this;
me.up().down('displayfield').setValue(value);
- }
- }
+ },
+ },
},
{
xtype: 'displayfield',
fieldLabel: gettext('Value'),
labelWidth: 150,
allowBlank: false,
- reset: Ext.emptyFn
- }
- ]
+ reset: Ext.emptyFn,
+ },
+ ],
+ },
+ 3006: {
+ onlineHelp: 'pmg_mailfilter_regex',
+ iconCls: 'fa fa-file-archive-o',
+ xtype: 'proxmoxWindowEdit',
+ subdir: 'archivefilenamefilter',
+ width: 400,
+ subject: gettext('Match Archive Filename'),
+ items: [
+ {
+ xtype: 'textfield',
+ name: 'filename',
+ reference: 'filename',
+ fieldLabel: gettext('Filename'),
+ labelWidth: 150,
+ allowBlank: false,
+ },
+ {
+ labelWidth: 150,
+ fieldLabel: gettext('Test String'),
+ wholeMatch: true,
+ xtype: 'pmgRegexTester',
+ regexFieldReference: 'filename',
+ },
+ ],
},
4002: {
onlineHelp: 'pmg_mailfilter_action',
xtype: 'textfield',
name: 'name',
allowBlank: false,
- fieldLabel: gettext('Name')
+ fieldLabel: gettext('Name'),
},
{
xtype: 'textareafield',
name: 'info',
- fieldLabel: gettext("Description")
+ fieldLabel: gettext("Comment"),
},
{
xtype: 'textfield',
name: 'to',
allowBlank: false,
value: '__ADMIN__',
- fieldLabel: gettext('Receiver')
+ fieldLabel: gettext('Receiver'),
},
{
xtype: 'textfield',
name: 'subject',
allowBlank: false,
value: 'Notification: __SUBJECT__',
- fieldLabel: gettext('Subject')
+ fieldLabel: gettext('Subject'),
},
{
xtype: 'textarea',
"__RULE_INFO__\n\n" +
"__VIRUS_INFO__\n" +
"__SPAM_INFO__\n",
- fieldLabel: gettext('Body')
+ fieldLabel: gettext('Body'),
},
{
xtype: 'proxmoxcheckbox',
name: 'attach',
- fieldLabel: gettext("Attach orig. Mail")
- }
- ]
+ fieldLabel: gettext("Attach orig. Mail"),
+ },
+ ],
},
4003: {
onlineHelp: 'pmg_mailfilter_action',
xtype: 'textfield',
name: 'name',
allowBlank: false,
- fieldLabel: gettext('Name')
+ fieldLabel: gettext('Name'),
},
{
xtype: 'textareafield',
name: 'info',
- fieldLabel: gettext("Description")
+ fieldLabel: gettext("Comment"),
},
{
xtype: 'textfield',
name: 'field',
allowBlank: false,
- fieldLabel: gettext('Field')
+ fieldLabel: gettext('Field'),
},
{
xtype: 'textfield',
reference: 'value',
name: 'value',
allowBlank: false,
- fieldLabel: gettext('Value')
- }
- ]
+ fieldLabel: gettext('Value'),
+ },
+ ],
},
4005: {
onlineHelp: 'pmg_mailfilter_action',
xtype: 'textfield',
name: 'name',
allowBlank: false,
- fieldLabel: gettext('Name')
+ fieldLabel: gettext('Name'),
},
{
xtype: 'textareafield',
name: 'info',
- fieldLabel: gettext("Description")
+ fieldLabel: gettext("Comment"),
},
{
xtype: 'textfield',
name: 'target',
allowBlank: false,
- fieldLabel: gettext("Target")
+ fieldLabel: gettext("Target"),
},
{
xtype: 'proxmoxcheckbox',
checked: true,
name: 'original',
- fieldLabel: gettext("send orig. Mail")
- }
- ]
+ fieldLabel: gettext("send orig. Mail"),
+ },
+ ],
},
4007: {
subject: gettext('Remove Attachments'),
width: 500,
fieldDefaults: {
- labelWidth: 150
+ labelWidth: 150,
},
items: [
{
xtype: 'textfield',
name: 'name',
allowBlank: false,
- fieldLabel: gettext('Name')
+ fieldLabel: gettext('Name'),
},
{
xtype: 'textareafield',
name: 'info',
- fieldLabel: gettext("Description")
+ fieldLabel: gettext("Comment"),
},
{
xtype: 'textareafield',
name: 'text',
grow: true,
growMax: 250,
- fieldLabel: gettext("Text Replacement")
+ fieldLabel: gettext("Text Replacement"),
},
{
xtype: 'proxmoxcheckbox',
checked: true,
name: 'all',
- fieldLabel: gettext("Remove all attachments")
+ fieldLabel: gettext("Remove all attachments"),
},
{
xtype: 'proxmoxcheckbox',
checked: false,
name: 'quarantine',
- fieldLabel: gettext("Copy orignal mail to Attachment Quarantine")
- }
- ]
+ fieldLabel: gettext("Copy orignal mail to Attachment Quarantine"),
+ },
+ ],
},
4009: {
onlineHelp: 'pmg_mailfilter_action',
xtype: 'textfield',
name: 'name',
allowBlank: false,
- fieldLabel: gettext('Name')
+ fieldLabel: gettext('Name'),
},
{
xtype: 'textareafield',
name: 'info',
- fieldLabel: gettext("Description")
+ fieldLabel: gettext("Comment"),
},
{
xtype: 'textareafield',
name: 'disclaimer',
grow: true,
growMax: 250,
- fieldLabel: gettext("Disclaimer")
- }
- ]
- }
+ fieldLabel: gettext("Disclaimer"),
+ },
+ ],
+ },
},
updateLoginData: function(data) {
Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
Proxmox.UserName = data.username;
- Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
+ Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true);
},
quarantineActionExtracted: false,
extractQuarantineAction: function() {
-
- if (PMG.Utils.quarantineActionExtracted) { return; }
+ if (PMG.Utils.quarantineActionExtracted) {
+ return null;
+ }
PMG.Utils.quarantineActionExtracted = true;
- var qs = Ext.Object.fromQueryString(location.search);
+ let qs = Ext.Object.fromQueryString(location.search);
- var cselect = qs.cselect;
- var action = qs.action;
- var ticket = qs.ticket;
- var dateString = qs.date;
+ let cselect = qs.cselect;
+ let action = qs.action;
+ let dateString = qs.date;
if (dateString) {
- var date = new Date(dateString).getTime()/1000;
+ let date = new Date(dateString).getTime()/1000;
// set from date for QuarantineList
- /*jslint confusion: true*/
- /*from is a string above and number here */
PMG.QuarantineList.from = date;
- /*jslint confusion: false*/
}
delete qs.cselect;
newurl += location.hash;
if (window.history) {
- window.history.pushState({ path:newurl }, '', newurl);
+ window.history.pushState({ path: newurl }, '', newurl);
}
if (action || cselect) {
- return { action: action, cselect: cselect };
+ return {
+ action: action,
+ cselect: cselect,
+ };
}
+ return null;
},
doQuarantineAction: function(action, id, callback) {
- var count = id.split(';').length;
- var successMessage = "Action '{0}'";
- if (count > 1) {
- successMessage += " for '{1}' items";
- }
- successMessage += " successful";
-
- /*jslint confusion: true*/
- /*format is string and function*/
Proxmox.Utils.API2Request({
url: '/quarantine/content/',
params: {
action: action,
- id: id
+ id: id,
},
method: 'POST',
failure: function(response, opts) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
},
success: function(response, opts) {
- var win = Ext.create('Ext.window.MessageBox',{
- closeAction: 'destroy'
- }).show({
- title: gettext('Info'),
- message: Ext.String.format(successMessage, action, count),
- buttons: Ext.Msg.OK,
- icon: Ext.MessageBox.INFO
+ let count = id.split(';').length;
+ let fmt = count > 1
+ ? gettext("Action '{0}' for '{1}' items successful")
+ : gettext("Action '{0}' successful")
+ ;
+ let message = Ext.String.format(fmt, action, count);
+ let title = Ext.String.format("{0} successful", Ext.String.capitalize(action));
+
+ Ext.toast({
+ html: message,
+ title: title,
+ minWidth: 200,
+ hideDuration: 250,
+ slideBackDuration: 250,
+ slideBackAnimation: 'easeOut',
+ iconCls: 'fa fa-check',
+ shadow: true,
+ align: 'br',
});
if (Ext.isFunction(callback)) {
callback();
}
- }
+ },
});
- /*jslint confusion: false*/
},
render_filetype: function(value) {
}
text = value.toString().toLowerCase();
- let type = text.split('/')[0];
+ const type = text.split('/')[0];
switch (type) {
case 'audio':
case 'text':
iconCls = `fa-file-${type}-o`;
break;
- case 'application':
- let subtypes = ['excel', 'pdf', 'word', 'powerpoint'];
+ case 'application': {
+ const subtypes = ['excel', 'pdf', 'word', 'powerpoint'];
let found = subtypes.find(st => text.includes(st));
if (found !== undefined) {
iconCls = `fa-file-${found}-o`;
}
- break;
+ } break;
default:
break;
}
var from = Ext.htmlEncode(rec.data.from);
var sender = Ext.htmlEncode(rec.data.sender);
if (sender) {
- /*jslint confusion: true*/
- /*format is a string above*/
from = Ext.String.format(gettext("{0} on behalf of {1}"),
sender, from);
- /*jslint confusion: false*/
}
return '<small>' + from + '</small><br>' + subject;
},
var me = this;
// do whatever you want here
- }
+ Proxmox.Utils.override_task_descriptions({
+ applycustomscores: ['', gettext('Apply custom SpamAssassin scores')],
+ avupdate: ['', gettext('ClamAV update')],
+ backup: ['', gettext('Backup')],
+ clustercreate: ['', gettext('Create Cluster')],
+ clusterjoin: ['', gettext('Join Cluster')],
+ restore: ['', gettext('Restore')],
+ saupdate: ['', gettext('SpamAssassin update')],
+ });
+ },
+});
+
+Ext.define('PMG.Async', {
+ singleton: true,
+
+ // Returns a Promise which executes a quarantine action when awaited.
+ // Shows a Toast message box once completed, if batchNumber and batchTotal
+ // are set, they will be included into the title of that toast.
+ doQAction: function(action, ids, batchNumber, batchTotal) {
+ if (!Ext.isArray(ids)) {
+ ids = [ids];
+ }
+ return Proxmox.Async.api2({
+ url: '/quarantine/content/',
+ params: {
+ action: action,
+ id: ids.join(';'),
+ },
+ method: 'POST',
+ }).then(
+ response => {
+ let count = ids.length;
+ let fmt = count > 1
+ ? gettext("Action '{0}' for '{1}' items successful")
+ : gettext("Action '{0}' successful")
+ ;
+ let message = Ext.String.format(fmt, action, count);
+ let titleFmt = batchNumber !== undefined && batchTotal > 1
+ ? gettext("{0} ({1}/{2}) successful")
+ : gettext("{0} successful")
+ ;
+ let title = Ext.String.format(
+ titleFmt,
+ Ext.String.capitalize(action),
+ batchNumber,
+ batchTotal,
+ );
+
+ Ext.toast({
+ html: message,
+ title: title,
+ minWidth: 200,
+ hideDuration: 250,
+ slideBackDuration: 250,
+ slideBackAnimation: 'easeOut',
+ iconCls: 'fa fa-check',
+ shadow: true,
+ align: 'br',
+ });
+ },
+ response => Proxmox.Utils.alertResponseFailure(response),
+ );
+ },
});