]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Utils.js
make who regex tests anchored
[pmg-gui.git] / js / Utils.js
index b3df9cc6aa7db4417a1184bde9220f96320549e5..ce15d06ebbe0d9a1443cb4a1e8fa12c73e399e18 100644 (file)
@@ -13,6 +13,18 @@ Ext.define('PMG.Utils', {
     receiverText: gettext('Receiver'),
     scoreText: gettext('Score'),
 
+    user_role_text: {
+       root: gettext('Superuser'),
+       admin: gettext('Administrator'),
+       helpdesk: gettext('Help Desk'),
+       qmanager: gettext('Quarantine Manager'),
+       audit: gettext('Auditor')
+    },
+
+    format_user_role: function(role) {
+       return PMG.Utils.user_role_text[role] || role;
+    },
+
     oclass_text: {
        who: gettext('Who Objects'),
        what: gettext('What Objects'),
@@ -42,41 +54,28 @@ Ext.define('PMG.Utils', {
        Q: 'quarantine'
     },
 
-    icon_status_map: {
-       2: {
-           fa: 'check-circle',
-           color: 'green'
-       },
-       4: {
-           fa: 'clock-o',
-       },
-       5: {
-           fa: 'mail-reply',
-           color: 'gray'
-       },
-       N: {
-           fa: 'times-circle'
-       },
-       G: {
-           fa: 'list'
-       },
-       A: {
-           fa: 'check',
-           color: 'green'
-       },
-       B: {
-           fa: 'ban',
-           color: 'red'
-       },
-       Q: {
-           fa: 'cube'
-       }
+    icon_status_map_class: {
+       2: 'check-circle',
+       4: 'clock-o',
+       5: 'mail-reply',
+       N: 'times-circle',
+       G: 'list',
+       A: 'check',
+       B: 'ban',
+       Q: 'cube'
+    },
+
+    icon_status_map_color: {
+       2: 'green',
+       5: 'gray',
+       A: 'green',
+       B: 'red'
     },
 
     format_status_icon: function(status) {
-       var icon = PMG.Utils.icon_status_map[status] || {};
-       return '<i class="fa fa-' + (icon.fa || 'question-circle') + ' ' +
-              (icon.color || '') + '"></i> ';
+       var icon = PMG.Utils.icon_status_map_class[status] || 'question-circle';
+       var color = PMG.Utils.icon_status_map_color[status] || '';
+       return '<i class="fa fa-' + icon + ' ' + color + '"></i> ';
     },
 
     format_oclass: function(oclass) {
@@ -105,10 +104,13 @@ Ext.define('PMG.Utils', {
 
     format_otype: function(otype) {
        var editor = PMG.Utils.object_editors[otype];
+       var iconCls = 'fa fa-question-circle';
        if (editor) {
-           return editor.subject;
+           var icon = '<span class="fa-fw ' + (editor.iconCls || iconCls) + '"></span> ';
+           return icon + editor.subject;
        }
-       return 'unknown';
+
+       return '<span class="fa-fw ' + iconCls + '"></span> unknown';
     },
 
     format_ldap_protocol: function(p) {
@@ -118,8 +120,14 @@ Ext.define('PMG.Utils', {
        return 'unknown';
     },
 
+    convert_field_to_per_min: function(value, record) {
+       return (value/(record.data.timespan/60));
+    },
+
     object_editors: {
        1000: {
+           onlineHelp: 'pmg_mailfilter_regex',
+           iconCls: 'fa fa-filter',
            xtype: 'proxmoxWindowEdit',
            subdir: 'regex',
            subject: gettext("Regular Expression"),
@@ -129,21 +137,35 @@ Ext.define('PMG.Utils', {
                    xtype: 'textfield',
                    name: 'regex',
                    labelWidth: 150,
+                   reference: 'regex',
                    fieldLabel: gettext("Regular Expression")
+               },
+               {
+                   labelWidth: 150,
+                   fieldLabel: gettext('Test String'),
+                   xtype: 'pmgRegexTester',
+                   wholeMatch: true,
+                   regexFieldReference: 'regex'
                }
            ]
        },
        1005: {
+           onlineHelp: 'pmgconfig_ldap',
+           iconCls: 'fa fa-users',
            xtype: 'pmgLDAPGroupEditor',
            subdir: 'ldap',
            subject: gettext("LDAP Group")
        },
        1006: {
+           onlineHelp: 'pmgconfig_ldap',
+           iconCls: 'fa fa-user',
            xtype: 'pmgLDAPUserEditor',
            subdir: 'ldapuser',
            subject: gettext("LDAP User")
        },
        1009: {
+           onlineHelp: 'pmg_mailfilter_regex',
+           iconCls: 'fa fa-filter',
            xtype: 'proxmoxWindowEdit',
            subdir: 'receiver_regex',
            subject: gettext("Regular Expression"),
@@ -159,33 +181,39 @@ Ext.define('PMG.Utils', {
            ]
        },
        1001: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-envelope-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'email',
-           subject: gettext("Email"),
+           subject: gettext("E-Mail"),
            width: 400,
            items: [
                {
                    xtype: 'textfield',
                    name: 'email',
-                   fieldLabel: gettext("Email")
+                   fieldLabel: gettext("E-Mail")
                }
            ]
        },
        1007: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-envelope-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'receiver',
-           subject: gettext("Email"),
+           subject: gettext("E-Mail"),
            receivertest: true,
            width: 400,
            items: [
                {
                    xtype: 'textfield',
                    name: 'email',
-                   fieldLabel: gettext("Email")
+                   fieldLabel: gettext("E-Mail")
                }
            ]
        },
        1002: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-globe',
            xtype: 'proxmoxWindowEdit',
            subdir: 'domain',
            subject: gettext("Domain"),
@@ -199,6 +227,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        1008: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-globe',
            xtype: 'proxmoxWindowEdit',
            subdir: 'receiver_domain',
            subject: gettext("Domain"),
@@ -213,6 +243,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        1003: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-globe',
            xtype: 'proxmoxWindowEdit',
            subdir: 'ip',
            subject: gettext("IP Address"),
@@ -226,6 +258,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        1004: {
+           onlineHelp: 'pmg_mailfilter_who',
+           iconCls: 'fa fa-globe',
            xtype: 'proxmoxWindowEdit',
            subdir: 'network',
            subject: gettext("IP Network"),
@@ -239,6 +273,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        2000: {
+           onlineHelp: 'pmg_mailfilter_when',
+           iconCls: 'fa fa-clock-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'timeframe',
            subject: gettext("TimeFrame"),
@@ -258,6 +294,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        3000: {
+           onlineHelp: 'pmg_mailfilter_what',
+           iconCls: 'fa fa-bullhorn',
            xtype: 'proxmoxWindowEdit',
            subdir: 'spamfilter',
            subject: gettext('Spam Filter'),
@@ -271,7 +309,23 @@ Ext.define('PMG.Utils', {
                }
            ]
        },
+       3001: {
+           onlineHelp: 'pmg_mailfilter_what',
+           iconCls: 'fa fa-bug',
+           xtype: 'proxmoxWindowEdit',
+           subdir: 'virusfilter',
+           subject: gettext('Virus Filter'),
+           uneditable: true,
+           // there are no parameters to give, so we simply submit it
+           listeners: {
+               show: function(win) {
+                   win.submit();
+               }
+           }
+       },
        3002: {
+           onlineHelp: 'pmg_mailfilter_regex',
+           iconCls: 'fa fa-code',
            xtype: 'proxmoxWindowEdit',
            subdir: 'matchfield',
            subject: gettext('Match Field'),
@@ -301,6 +355,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        3003: {
+           onlineHelp: 'pmg_mailfilter_what',
+           iconCls: 'fa fa-file-image-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'contenttype',
            width: 400,
@@ -341,6 +397,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        3004: {
+           onlineHelp: 'pmg_mailfilter_regex',
+           iconCls: 'fa fa-file-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'filenamefilter',
            width: 400,
@@ -364,6 +422,8 @@ Ext.define('PMG.Utils', {
            ]
        },
        3005: {
+           onlineHelp: 'pmg_mailfilter_what',
+           iconCls: 'fa fa-file-archive-o',
            xtype: 'proxmoxWindowEdit',
            subdir: 'archivefilter',
            width: 400,
@@ -403,7 +463,98 @@ Ext.define('PMG.Utils', {
                }
            ]
        },
+       4002: {
+           onlineHelp: 'pmg_mailfilter_action',
+           xtype: 'proxmoxWindowEdit',
+           subdir: 'notification',
+           subject: gettext('Notification'),
+           width: 400,
+           items: [
+               {
+                   xtype: 'textfield',
+                   name: 'name',
+                   allowBlank: false,
+                   fieldLabel: gettext('Name')
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'info',
+                   fieldLabel: gettext("Description")
+               },
+               {
+                   xtype: 'textfield',
+                   name: 'to',
+                   allowBlank: false,
+                   value: '__ADMIN__',
+                   fieldLabel: gettext('Receiver')
+               },
+               {
+                   xtype: 'textfield',
+                   name: 'subject',
+                   allowBlank: false,
+                   value: 'Notification: __SUBJECT__',
+                   fieldLabel: gettext('Subject')
+               },
+               {
+                   xtype: 'textarea',
+                   name: 'body',
+                   allowBlank: false,
+                   grow: true,
+                   growMax: 250,
+                   value:
+                       "Proxmox Notifcation:\n\n" +
+                       "Sender:   __SENDER__\n" +
+                       "Receiver: __RECEIVERS__\n" +
+                       "Targets:  __TARGETS__\n\n" +
+                       "Subject:  __SUBJECT__\n\n" +
+                       "Matching Rule: __RULE__\n\n" +
+                       "__RULE_INFO__\n\n" +
+                       "__VIRUS_INFO__\n" +
+                       "__SPAM_INFO__\n",
+                   fieldLabel: gettext('Body')
+               },
+               {
+                   xtype: 'proxmoxcheckbox',
+                   name: 'attach',
+                   fieldLabel: gettext("Attach orig. Mail")
+               }
+           ]
+       },
+       4003: {
+           onlineHelp: 'pmg_mailfilter_action',
+           xtype: 'proxmoxWindowEdit',
+           subdir: 'field',
+           subject: gettext('Header Attribute'),
+           width: 400,
+           items: [
+               {
+                   xtype: 'textfield',
+                   name: 'name',
+                   allowBlank: false,
+                   fieldLabel: gettext('Name')
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'info',
+                   fieldLabel: gettext("Description")
+               },
+               {
+                   xtype: 'textfield',
+                   name: 'field',
+                   allowBlank: false,
+                   fieldLabel: gettext('Field')
+               },
+               {
+                   xtype: 'textfield',
+                   reference: 'value',
+                   name: 'value',
+                   allowBlank: false,
+                   fieldLabel: gettext('Value')
+               }
+           ]
+       },
        4005: {
+           onlineHelp: 'pmg_mailfilter_action',
            xtype: 'proxmoxWindowEdit',
            subdir: 'bcc',
            subject: gettext('BCC'),
@@ -434,20 +585,72 @@ Ext.define('PMG.Utils', {
                }
            ]
 
+       },
+       4007: {
+           onlineHelp: 'pmg_mailfilter_action',
+           xtype: 'proxmoxWindowEdit',
+           subdir: 'removeattachments',
+           subject: gettext('Remove Attachments'),
+           width: 500,
+           fieldDefaults: {
+               labelWidth: 150
+           },
+           items: [
+               {
+                   xtype: 'textfield',
+                   name: 'name',
+                   allowBlank: false,
+                   fieldLabel: gettext('Name')
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'info',
+                   fieldLabel: gettext("Description")
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'text',
+                   grow: true,
+                   growMax: 250,
+                   fieldLabel: gettext("Text Replacement")
+               },
+               {
+                   xtype: 'proxmoxcheckbox',
+                   checked: true,
+                   name: 'all',
+                   fieldLabel: gettext("Remove all attachments")
+               }
+           ]
+       },
+       4009: {
+           onlineHelp: 'pmg_mailfilter_action',
+           xtype: 'proxmoxWindowEdit',
+           subdir: 'disclaimer',
+           subject: gettext('Disclaimer'),
+           width: 400,
+           items: [
+               {
+                   xtype: 'textfield',
+                   name: 'name',
+                   allowBlank: false,
+                   fieldLabel: gettext('Name')
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'info',
+                   fieldLabel: gettext("Description")
+               },
+               {
+                   xtype: 'textareafield',
+                   name: 'disclaimer',
+                   grow: true,
+                   growMax: 250,
+                   fieldLabel: gettext("Disclaimer")
+               }
+           ]
        }
     },
 
-    openVNCViewer: function(consoletype, nodename) {
-       var url = Ext.urlEncode({
-           console: consoletype, // upgrade or shell
-           novnc: 1,
-           node: nodename
-       });
-       var nw = window.open("?" + url, '_blank',
-                            "innerWidth=745,innerheight=427");
-       nw.focus();
-    },
-
     updateLoginData: function(data) {
        Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
        Proxmox.UserName = data.username;
@@ -467,10 +670,22 @@ Ext.define('PMG.Utils', {
        var cselect = qs.cselect;
        var action = qs.action;
        var ticket = qs.ticket;
+       var dateString = qs.date;
+
+       if (dateString) {
+           var 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;
        delete qs.action;
        delete qs.ticket;
+       delete qs.date;
 
        var newsearch = Ext.Object.toQueryString(qs);
 
@@ -488,6 +703,15 @@ Ext.define('PMG.Utils', {
     },
 
     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: {
@@ -499,10 +723,11 @@ Ext.define('PMG.Utils', {
                Ext.Msg.alert(gettext('Error'), response.htmlStatus);
            },
            success: function(response, opts) {
-               Ext.Msg.show({
+               var win = Ext.create('Ext.window.MessageBox',{
+                   closeAction: 'destroy'
+               }).show({
                    title: gettext('Info'),
-                   message: "Action '" + action + ' ' +
-                   id + "' successful",
+                   message: Ext.String.format(successMessage, action, count),
                    buttons: Ext.Msg.OK,
                    icon: Ext.MessageBox.INFO
                });
@@ -512,6 +737,7 @@ Ext.define('PMG.Utils', {
                }
            }
        });
+       /*jslint confusion: false*/
     },
 
     sender_renderer: function(value, metaData, rec) {
@@ -519,8 +745,11 @@ Ext.define('PMG.Utils', {
        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;
     },