]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
ui: Utils: add capture group for the id in bus_match
[pve-manager.git] / www / manager6 / Utils.js
index e927a2fd7d0f3e9dd3050860b67096af7244edef..71e5fc9abf207dcfd97e9d42336f6f18dff39293 100644 (file)
@@ -1,12 +1,5 @@
 Ext.ns('PVE');
 
-// avoid errors related to Accessible Rich Internet Applications
-// (access for people with disabilities)
-// TODO reenable after all components are upgraded
-Ext.enableAria = false;
-Ext.enableAriaButtons = false;
-Ext.enableAriaPanels = false;
-
 console.log("Starting Proxmox VE Manager");
 
 Ext.Ajax.defaultHeaders = {
@@ -20,7 +13,7 @@ Ext.define('PVE.Utils', {
 
     toolkit: undefined, // (extjs|touch), set inside Toolkit.js
 
-    bus_match: /^(ide|sata|virtio|scsi)\d+$/,
+    bus_match: /^(ide|sata|virtio|scsi)(\d+)$/,
 
     log_severity_hash: {
        0: "panic",
@@ -733,22 +726,38 @@ Ext.define('PVE.Utils', {
            ipanel: 'pveAuthADPanel',
            syncipanel: 'pveAuthLDAPSyncPanel',
            add: true,
+           tfa: true,
+           pwchange: true,
        },
        ldap: {
            name: gettext('LDAP Server'),
            ipanel: 'pveAuthLDAPPanel',
            syncipanel: 'pveAuthLDAPSyncPanel',
            add: true,
+           tfa: true,
+           pwchange: true,
+       },
+       openid: {
+           name: gettext('OpenID Connect Server'),
+           ipanel: 'pveAuthOpenIDPanel',
+           add: true,
+           tfa: false,
+           pwchange: false,
+           iconCls: 'pmx-itype-icon-openid-logo',
        },
        pam: {
            name: 'Linux PAM',
            ipanel: 'pveAuthBasePanel',
            add: false,
+           tfa: true,
+           pwchange: true,
        },
        pve: {
            name: 'Proxmox VE authentication server',
            ipanel: 'pveAuthBasePanel',
            add: false,
+           tfa: true,
+           pwchange: true,
        },
     },
 
@@ -771,6 +780,12 @@ Ext.define('PVE.Utils', {
            faIcon: 'folder',
            backups: false,
        },
+       btrfs: {
+           name: 'BTRFS',
+           ipanel: 'BTRFSInputPanel',
+           faIcon: 'folder',
+           backups: true,
+       },
        nfs: {
            name: 'NFS',
            ipanel: 'NFSInputPanel',
@@ -1500,18 +1515,19 @@ Ext.define('PVE.Utils', {
     },
 
     loadSSHKeyFromFile: function(file, callback) {
-       // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
-       // a user@host comment, 1420 for 8192 bits; current max is 16kbit
-       // assume: 740*8 for max. 32kbit (5920 byte file)
-       // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
-       if (file.size > 8192) {
-           Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
+       // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key,  current max is 16 kbit, so assume:
+       // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
+       PVE.Utils.loadFile(file, callback, 8192);
+    },
+
+    loadFile: function(file, callback, maxSize) {
+       maxSize = maxSize || 32 * 1024;
+       if (file.size > maxSize) {
+           Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`);
            return;
        }
        let reader = new FileReader();
-       reader.onload = function(evt) {
-           callback(evt.target.result);
-       };
+       reader.onload = evt => callback(evt.target.result);
        reader.readAsText(file);
     },
 
@@ -1741,6 +1757,52 @@ Ext.define('PVE.Utils', {
 
        return true;
     },
+
+    sortByPreviousUsage: function(vmconfig, controllerList) {
+       if (!controllerList) {
+           controllerList = ['ide', 'virtio', 'scsi', 'sata'];
+       }
+       let usedControllers = {};
+       for (const type of Object.keys(PVE.Utils.diskControllerMaxIDs)) {
+           usedControllers[type] = 0;
+       }
+
+       for (const property of Object.keys(vmconfig)) {
+           if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) {
+               const foundController = property.match(PVE.Utils.bus_match)[1];
+               usedControllers[foundController]++;
+           }
+       }
+
+       let sortPriority = PVE.qemu.OSDefaults.getDefaults(vmconfig.ostype).busPriority;
+
+       let sortedList = Ext.clone(controllerList);
+       sortedList.sort(function(a, b) {
+           if (usedControllers[b] === usedControllers[a]) {
+               return sortPriority[b] - sortPriority[a];
+           }
+           return usedControllers[b] - usedControllers[a];
+       });
+
+       return sortedList;
+    },
+
+    nextFreeDisk: function(controllers, config) {
+       for (const controller of controllers) {
+           for (let i = 0; i < PVE.Utils.diskControllerMaxIDs[controller]; i++) {
+               let confid = controller + i.toString();
+               if (!Ext.isDefined(config[confid])) {
+                   return {
+                       controller,
+                       id: i,
+                       confid,
+                   };
+               }
+           }
+       }
+
+       return undefined;
+    },
 },
 
     singleton: true,
@@ -1775,7 +1837,7 @@ Ext.define('PVE.Utils', {
            clusterjoin: ['', gettext('Join Cluster')],
            dircreate: [gettext('Directory Storage'), gettext('Create')],
            dirremove: [gettext('Directory'), gettext('Remove')],
-           download: ['', gettext('Download')],
+           download: [gettext('File'), gettext('Download')],
            hamigrate: ['HA', gettext('Migrate')],
            hashutdown: ['HA', gettext('Shutdown')],
            hastart: ['HA', gettext('Start')],
@@ -1813,6 +1875,7 @@ Ext.define('PVE.Utils', {
            startall: ['', gettext('Start all VMs and Containers')],
            stopall: ['', gettext('Stop all VMs and Containers')],
            unknownimgdel: ['', gettext('Destroy image from unknown guest')],
+           wipedisk: ['Device', gettext('Wipe Disk')],
            vncproxy: ['VM/CT', gettext('Console')],
            vncshell: ['', gettext('Shell')],
            vzclone: ['CT', gettext('Clone')],