]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
ui: Utils: add helper functions for acme domains
[pve-manager.git] / www / manager6 / Utils.js
index 95345be82e69077d3fbbb266afa6b5181009fc34..31e262c0a9644e14aa703eee145fa37452e447b2 100644 (file)
@@ -54,7 +54,7 @@ Ext.define('PVE.Utils', { utilities: {
            { desc: '2.4 Kernel', val: 'l24' }
        ],
        'Microsoft Windows': [
-           { desc: '10/2016', val: 'win10' },
+           { desc: '10/2016/2019', val: 'win10' },
            { desc: '8.x/2012/2012r2', val: 'win8' },
            { desc: '7/2008r2', val: 'win7' },
            { desc: 'Vista/2008', val: 'w2k8' },
@@ -83,6 +83,9 @@ Ext.define('PVE.Utils', { utilities: {
            case 'good':
                icon = 'good fa-check';
                break;
+           case 'upgrade':
+               icon = 'warning fa-upload';
+               break;
            case 'old':
                icon = 'warning fa-refresh';
                break;
@@ -118,11 +121,24 @@ Ext.define('PVE.Utils', { utilities: {
     },
 
     compare_ceph_versions: function(a, b) {
+       let avers = [];
+       let bvers = [];
+
        if (a === b) {
            return 0;
        }
-       let avers = a.toString().split('.');
-       let bvers = b.toString().split('.');
+
+       if (Ext.isArray(a)) {
+           avers = a.slice(); // copy array
+       } else {
+           avers = a.toString().split('.');
+       }
+
+       if (Ext.isArray(b)) {
+           bvers = b.slice(); // copy array
+       } else {
+           bvers = b.toString().split('.');
+       }
 
        while (true) {
            let av = avers.shift();
@@ -154,6 +170,7 @@ Ext.define('PVE.Utils', { utilities: {
 
     map_ceph_health: {
        'HEALTH_OK':'good',
+       'HEALTH_UPGRADE':'upgrade',
        'HEALTH_OLD':'old',
        'HEALTH_WARN':'warning',
        'HEALTH_ERR':'critical'
@@ -272,10 +289,18 @@ Ext.define('PVE.Utils', { utilities: {
            var keystring = '' ;
            agentstring += ', ' + key + ': ';
 
-           if (PVE.Parser.parseBoolean(value)) {
-               agentstring += Proxmox.Utils.enabledText;
+           if (key === 'type') {
+               let map = {
+                   isa: "ISA",
+                   virtio: "VirtIO",
+               };
+               agentstring += map[value] || Proxmox.Utils.unknownText;
            } else {
-               agentstring += Proxmox.Utils.disabledText;
+               if (PVE.Parser.parseBoolean(value)) {
+                   agentstring += Proxmox.Utils.enabledText;
+               } else {
+                   agentstring += Proxmox.Utils.disabledText;
+               }
            }
        });
 
@@ -330,6 +355,22 @@ Ext.define('PVE.Utils', { utilities: {
        }
     },
 
+    render_spice_enhancements: function(values) {
+       let props = PVE.Parser.parsePropertyString(values);
+       if (Ext.Object.isEmpty(props)) {
+           return Proxmox.Utils.noneText;
+       }
+
+       let output = [];
+       if (PVE.Parser.parseBoolean(props.foldersharing)) {
+           output.push('Folder Sharing: ' + gettext('Enabled'));
+       }
+       if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
+           output.push('Video Streaming: ' + props.videostreaming);
+       }
+       return output.join(', ');
+    },
+
     // fixme: auto-generate this
     // for now, please keep in sync with PVE::Tools::kvmkeymaps
     kvm_keymaps: {
@@ -517,6 +558,39 @@ Ext.define('PVE.Utils', { utilities: {
        'snippets': gettext('Snippets')
     },
 
+    volume_is_qemu_backup: function(volid, format) {
+       return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
+    },
+
+    volume_is_lxc_backup: function(volid, format) {
+       return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
+    },
+
+    authSchema: {
+       ad: {
+           name: gettext('Active Directory Server'),
+           ipanel: 'pveAuthADPanel',
+           syncipanel: 'pveAuthLDAPSyncPanel',
+           add: true,
+       },
+       ldap: {
+           name: gettext('LDAP Server'),
+           ipanel: 'pveAuthLDAPPanel',
+           syncipanel: 'pveAuthLDAPSyncPanel',
+           add: true,
+       },
+       pam: {
+           name: 'Linux PAM',
+           ipanel: 'pveAuthBasePanel',
+           add: false,
+       },
+       pve: {
+           name: 'Proxmox VE authentication server',
+           ipanel: 'pveAuthBasePanel',
+           add: false,
+       },
+    },
+
     storageSchema: {
        dir: {
            name: Proxmox.Utils.directoryText,
@@ -585,10 +659,86 @@ Ext.define('PVE.Utils', { utilities: {
            ipanel: 'ZFSPoolInputPanel',
            faIcon: 'folder'
        },
+       pbs: {
+           name: 'Proxmox Backup Server',
+           //ipanel: '', // TODO
+           hideAdd: true,
+           faIcon: 'database',
+       },
        drbd: {
            name: 'DRBD',
-           hideAdd: true
+           hideAdd: true,
+       },
+    },
+
+    sdnvnetSchema: {
+       vnet: {
+           name: 'vnet',
+           faIcon: 'folder'
+       },
+    },
+
+    sdnzoneSchema: {
+       zone: {
+            name: 'zone',
+            hideAdd: true
+       },
+       vlan: {
+           name: 'vlan',
+           ipanel: 'VlanInputPanel',
+           faIcon: 'folder'
+       },
+       qinq: {
+           name: 'qinq',
+           ipanel: 'QinQInputPanel',
+           faIcon: 'folder'
+       },
+       vxlan: {
+           name: 'vxlan',
+           ipanel: 'VxlanInputPanel',
+           faIcon: 'folder'
+       },
+       evpn: {
+           name: 'evpn',
+           ipanel: 'EvpnInputPanel',
+           faIcon: 'folder'
+       },
+    },
+
+    sdncontrollerSchema: {
+       controller: {
+            name: 'controller',
+            hideAdd: true
+       },
+       evpn: {
+           name: 'evpn',
+           ipanel: 'EvpnInputPanel',
+           faIcon: 'folder'
+       },
+    },
+
+    format_sdnvnet_type: function(value, md, record) {
+       var schema = PVE.Utils.sdnvnetSchema[value];
+       if (schema) {
+           return schema.name;
+       }
+       return Proxmox.Utils.unknownText;
+    },
+
+    format_sdnzone_type: function(value, md, record) {
+       var schema = PVE.Utils.sdnzoneSchema[value];
+       if (schema) {
+           return schema.name.toUpperCase();
+       }
+       return Proxmox.Utils.unknownText;
+    },
+
+    format_sdncontroller_type: function(value, md, record) {
+       var schema = PVE.Utils.sdncontrollerSchema[value];
+       if (schema) {
+           return schema.name;
        }
+       return Proxmox.Utils.unknownText;
     },
 
     format_storage_type: function(value, md, record) {
@@ -633,7 +783,7 @@ Ext.define('PVE.Utils', { utilities: {
                Ext.String.leftPad(data.channel,2, '0') +
                " ID " + data.id + " LUN " + data.lun;
        }
-       return data.volid.replace(/^.*:(.*\/)?/,'');
+       return data.volid.replace(/^.*?:(.*?\/)?/,'');
     },
 
     render_serverity: function (value) {
@@ -956,13 +1106,18 @@ Ext.define('PVE.Utils', { utilities: {
     },
 
     openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
+       let scaling = 'off';
+       if (Proxmox.Utils.toolkit !== 'touch') {
+           var sp = Ext.state.Manager.getProvider();
+           scaling = sp.get('novnc-scaling', 'off');
+       }
        var url = Ext.Object.toQueryString({
            console: vmtype, // kvm, lxc, upgrade or shell
            novnc: 1,
            vmid: vmid,
            vmname: vmname,
            node: nodename,
-           resize: 'off',
+           resize: scaling,
            cmd: cmd
        });
        var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
@@ -1029,9 +1184,10 @@ Ext.define('PVE.Utils', { utilities: {
                    Ext.Msg.alert('Error', response.htmlStatus);
                },
                success: function(response, opts) {
+                   let conf = response.result.data;
                    var consoles = {
-                       spice: !!response.result.data.spice,
-                       xtermjs: !!response.result.data.serial,
+                       spice: !!conf.spice,
+                       xtermjs: !!conf.serial,
                    };
                    PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
                }
@@ -1093,7 +1249,11 @@ Ext.define('PVE.Utils', { utilities: {
        if (values[fieldname] === '' || values[fieldname] === default_val) {
            if (!create) {
                if (values['delete']) {
-                   values['delete'] += ',' + fieldname;
+                   if (Ext.isArray(values['delete'])) {
+                       values['delete'].push(fieldname);
+                   } else {
+                       values['delete'] += ',' + fieldname;
+                   }
                } else {
                    values['delete'] = fieldname;
                }
@@ -1122,11 +1282,16 @@ Ext.define('PVE.Utils', { utilities: {
        reader.readAsText(file);
     },
 
-    bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 },
+    diskControllerMaxIDs: {
+       ide: 4,
+       sata: 6,
+       scsi: 31,
+       virtio: 16,
+    },
 
     // types is either undefined (all busses), an array of busses, or a single bus
     forEachBus: function(types, func) {
-       var busses = Object.keys(PVE.Utils.bus_counts);
+       var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
        var i, j, count, cont;
 
        if (Ext.isArray(types)) {
@@ -1137,13 +1302,13 @@ Ext.define('PVE.Utils', { utilities: {
 
        // check if we only have valid busses
        for (i = 0; i < busses.length; i++) {
-           if (!PVE.Utils.bus_counts[busses[i]]) {
+           if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
                throw "invalid bus: '" + busses[i] + "'";
            }
        }
 
        for (i = 0; i < busses.length; i++) {
-           count = PVE.Utils.bus_counts[busses[i]];
+           count = PVE.Utils.diskControllerMaxIDs[busses[i]];
            for (j = 0; j < count; j++) {
                cont = func(busses[i], j);
                if (!cont && cont !== undefined) {
@@ -1176,6 +1341,8 @@ Ext.define('PVE.Utils', { utilities: {
        }
     },
 
+    hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
+
     cleanEmptyObjectKeys: function (obj) {
        var propName;
        for (propName in obj) {
@@ -1187,6 +1354,29 @@ Ext.define('PVE.Utils', { utilities: {
        }
     },
 
+    acmedomain_count: 5,
+
+    add_domain_to_acme: function(acme, domain) {
+       if (acme.domains === undefined) {
+           acme.domains = [domain];
+       } else {
+           acme.domains.push(domain);
+           acme.domains = acme.domains.filter((value, index, self) => {
+               return self.indexOf(value) === index;
+           });
+       }
+       return acme;
+    },
+
+    remove_domain_from_acme: function(acme, domain) {
+       if (acme.domains !== undefined) {
+           acme.domains = acme.domains.filter((value, index, self) => {
+               return self.indexOf(value) === index && value !== domain;
+           });
+       }
+       return acme;
+    },
+
     handleStoreErrorOrMask: function(me, store, regex, callback) {
 
        me.mon(store, 'load', function (proxy, response, success, operation) {
@@ -1234,7 +1424,59 @@ Ext.define('PVE.Utils', { utilities: {
        } else {
            return false;
        }
-    }
+    },
+
+    propertyStringSet: function(target, source, name, value) {
+       if (source) {
+           if (value === undefined) {
+               target[name] = source;
+           } else {
+               target[name] = value;
+           }
+       } else {
+           delete target[name];
+       }
+    },
+
+    updateColumns: function(container) {
+       let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
+       let factor;
+       if (mode !== 'auto') {
+           factor = parseInt(mode, 10);
+           if (Number.isNaN(factor)) {
+               factor = 1;
+           }
+       } else {
+           factor = container.getSize().width < 1400 ? 1 : 2;
+       }
+
+       if (container.oldFactor === factor) {
+           return;
+       }
+
+       let items = container.query('>'); // direct childs
+       factor = Math.min(factor, items.length);
+       container.oldFactor = factor;
+
+       items.forEach((item) => {
+           item.columnWidth = 1 / factor;
+       });
+
+       // we have to update the layout twice, since the first layout change
+       // can trigger the scrollbar which reduces the amount of space left
+       container.updateLayout();
+       container.updateLayout();
+    },
+
+    forEachCorosyncLink: function(nodeinfo, cb) {
+       let re = /(?:ring|link)(\d+)_addr/;
+       Ext.iterate(nodeinfo, (prop, val) => {
+           let match = re.exec(prop);
+           if (match) {
+               cb(Number(match[1]), val);
+           }
+       });
+    },
 },
 
     singleton: true,
@@ -1244,4 +1486,3 @@ Ext.define('PVE.Utils', { utilities: {
     }
 
 });
-