return min < width ? width : min;
},
+ // returns username + realm
+ parse_userid: function(userid) {
+ if (!Ext.isString(userid)) {
+ return [undefined, undefined];
+ }
+
+ let match = userid.match(/^(.+)@([^@]+)$/);
+ if (match !== null) {
+ return [match[1], match[2]];
+ }
+
+ return [undefined, undefined];
+ },
+
+ render_username: function(userid) {
+ let username = Proxmox.Utils.parse_userid(userid)[0] || "";
+ return Ext.htmlEncode(username);
+ },
+
+ render_realm: function(userid) {
+ let username = Proxmox.Utils.parse_userid(userid)[1] || "";
+ return Ext.htmlEncode(username);
+ },
+
getStoredAuth: function() {
let storedAuth = JSON.parse(window.localStorage.getItem('ProxmoxUser'));
return storedAuth || {};
window.localStorage.removeItem("ProxmoxUser");
},
+ // The End-User gets redirected back here after login on the OpenID auth. portal, and in the
+ // redirection URL the state and auth.code are passed as URL GET params, this helper parses those
+ getOpenIDRedirectionAuthorization: function() {
+ const auth = Ext.Object.fromQueryString(window.location.search);
+ if (auth.state !== undefined && auth.code !== undefined) {
+ return auth;
+ }
+ return undefined;
+ },
+
// comp.setLoading() is buggy in ExtJS 4.0.7, so we
// use el.mask() instead
setErrorMask: function(comp, msg) {
return msg.join('<br>');
},
- monStoreErrors: function(component, store, clearMaskBeforeLoad) {
+ monStoreErrors: function(component, store, clearMaskBeforeLoad, errorCallback) {
if (clearMaskBeforeLoad) {
component.mon(store, 'beforeload', function(s, operation, eOpts) {
Proxmox.Utils.setErrorMask(component, false);
let error = request._operation.getError();
let msg = Proxmox.Utils.getResponseErrorMessage(error);
- Proxmox.Utils.setErrorMask(component, msg);
+ if (!errorCallback || !errorCallback(error, msg)) {
+ Proxmox.Utils.setErrorMask(component, msg);
+ }
});
},
});
},
- updateColumnWidth: function(container) {
+ updateColumnWidth: function(container, thresholdWidth) {
let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
let factor;
if (mode !== 'auto') {
factor = 1;
}
} else {
- factor = container.getSize().width < 1600 ? 1 : 2;
+ thresholdWidth = (thresholdWidth || 1400) + 1;
+ factor = Math.ceil(container.getSize().width / thresholdWidth);
}
if (container.oldFactor === factor) {
container.updateLayout();
},
+ // NOTE: depreacated, use updateColumnWidth
+ updateColumns: container => Proxmox.Utils.updateColumnWidth(container),
+
dialog_title: function(subject, create, isAdd) {
if (create) {
if (isAdd) {
Proxmox.Utils.unknownText;
},
+ // NOTE: only add general, product agnostic, ones here! Else use override helper in product repos
task_desc_table: {
aptupdate: ['', gettext('Update package database')],
diskinit: ['Disk', gettext('Initialize Disk with GPT')],
return text;
},
- format_size: function(size) {
- let units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
- let num = 0;
- while (size >= 1024 && num++ <= units.length) {
- size = size / 1024;
+ format_size: function(size, useSI) {
+ let units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
+ let order = 0;
+ const baseValue = useSI ? 1000 : 1024;
+ while (size >= baseValue && order < units.length) {
+ size = size / baseValue;
+ order++;
+ }
+
+ let unit = units[order], commaDigits = 2;
+ if (order === 0) {
+ commaDigits = 0;
+ } else if (!useSI) {
+ unit += 'i';
}
+ return `${size.toFixed(commaDigits)} ${unit}B`;
+ },
+
+ SizeUnits: {
+ 'B': 1,
+
+ 'KiB': 1024,
+ 'MiB': 1024*1024,
+ 'GiB': 1024*1024*1024,
+ 'TiB': 1024*1024*1024*1024,
+ 'PiB': 1024*1024*1024*1024*1024,
- return size.toFixed(num > 0?2:0) + " " + units[num] + "B";
+ 'KB': 1000,
+ 'MB': 1000*1000,
+ 'GB': 1000*1000*1000,
+ 'TB': 1000*1000*1000*1000,
+ 'PB': 1000*1000*1000*1000*1000,
},
render_upid: function(value, metaData, record) {
return 'error';
},
+ format_task_status: function(status) {
+ let parsed = Proxmox.Utils.parse_task_status(status);
+ switch (parsed) {
+ case 'unknown': return Proxmox.Utils.unknownText;
+ case 'error': return Proxmox.Utils.errorText + ': ' + status;
+ case 'warning': return status.replace('WARNINGS', Proxmox.Utils.warningsText);
+ case 'ok': // fall-through
+ default: return status;
+ }
+ },
+
render_duration: function(value) {
if (value === undefined) {
return '-';
return value;
},
- render_usage: val => (val*100).toFixed(2) + '%',
+ render_usage: val => (val * 100).toFixed(2) + '%',
render_cpu_usage: function(val, max) {
return Ext.String.format(
);
},
- render_size_usage: function(val, max) {
+ render_size_usage: function(val, max, useSI) {
if (max === 0) {
return gettext('N/A');
}
- return (val*100/max).toFixed(2) + '% (' +
- Ext.String.format(gettext('{0} of {1}'),
- Proxmox.Utils.render_size(val), Proxmox.Utils.render_size(max)) + ')';
+ let fmt = v => Proxmox.Utils.format_size(v, useSI);
+ let ratio = (val * 100 / max).toFixed(2);
+ return ratio + '% (' + Ext.String.format(gettext('{0} of {1}'), fmt(val), fmt(max)) + ')';
},
render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
return acme;
},
- 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;
+ get_health_icon: function(state, circle) {
+ if (circle === undefined) {
+ circle = false;
}
- if (container.oldFactor === factor) {
- return;
+ if (state === undefined) {
+ state = 'uknown';
}
- let items = container.query('>'); // direct childs
- factor = Math.min(factor, items.length);
- container.oldFactor = factor;
+ var icon = 'faded fa-question';
+ switch (state) {
+ case 'good':
+ icon = 'good fa-check';
+ break;
+ case 'upgrade':
+ icon = 'warning fa-upload';
+ break;
+ case 'old':
+ icon = 'warning fa-refresh';
+ break;
+ case 'warning':
+ icon = 'warning fa-exclamation';
+ break;
+ case 'critical':
+ icon = 'critical fa-times';
+ break;
+ default: break;
+ }
- items.forEach((item) => {
- item.columnWidth = 1 / factor;
- });
+ if (circle) {
+ icon += '-circle';
+ }
- // 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();
+ return icon;
+ },
+
+ formatNodeRepoStatus: function(status, product) {
+ let fmt = (txt, cls) => `<i class="fa fa-fw fa-lg fa-${cls}"></i>${txt}`;
+
+ let getUpdates = Ext.String.format(gettext('{0} updates'), product);
+ let noRepo = Ext.String.format(gettext('No {0} repository enabled!'), product);
+
+ if (status === 'ok') {
+ return fmt(getUpdates, 'check-circle good') + ' ' +
+ fmt(gettext('Production-ready Enterprise repository enabled'), 'check-circle good');
+ } else if (status === 'no-sub') {
+ return fmt(gettext('Production-ready Enterprise repository enabled'), 'check-circle good') + ' ' +
+ fmt(gettext('Enterprise repository needs valid subscription'), 'exclamation-circle warning');
+ } else if (status === 'non-production') {
+ return fmt(getUpdates, 'check-circle good') + ' ' +
+ fmt(gettext('Non production-ready repository enabled!'), 'exclamation-circle warning');
+ } else if (status === 'no-repo') {
+ return fmt(noRepo, 'exclamation-circle critical');
+ }
+
+ return Proxmox.Utils.unknownText;
+ },
+
+ render_u2f_error: function(error) {
+ var ErrorNames = {
+ '1': gettext('Other Error'),
+ '2': gettext('Bad Request'),
+ '3': gettext('Configuration Unsupported'),
+ '4': gettext('Device Ineligible'),
+ '5': gettext('Timeout'),
+ };
+ return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
+ },
+
+ // Convert an ArrayBuffer to a base64url encoded string.
+ // A `null` value will be preserved for convenience.
+ bytes_to_base64url: function(bytes) {
+ if (bytes === null) {
+ return null;
+ }
+
+ return btoa(Array
+ .from(new Uint8Array(bytes))
+ .map(val => String.fromCharCode(val))
+ .join(''),
+ )
+ .replace(/\+/g, '-')
+ .replace(/\//g, '_')
+ .replace(/[=]/g, '');
+ },
+
+ // Convert an a base64url string to an ArrayBuffer.
+ // A `null` value will be preserved for convenience.
+ base64url_to_bytes: function(b64u) {
+ if (b64u === null) {
+ return null;
+ }
+
+ return new Uint8Array(
+ atob(b64u
+ .replace(/-/g, '+')
+ .replace(/_/g, '/'),
+ )
+ .split('')
+ .map(val => val.charCodeAt(0)),
+ );
},
},
let DnsName_REGEXP = "(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*(?:[A-Za-z0-9](?:[A-Za-z0-9\\-]*[A-Za-z0-9])?))";
me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
+ me.DnsName_or_Wildcard_match = new RegExp("^(?:\\*\\.)?" + DnsName_REGEXP + "$");
me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(?::(\\d+))?$");
me.HostPortBrackets_match = new RegExp("^\\[(" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](?::(\\d+))?$");