add SSH key check

This commit is contained in:
Jordan Rodgers 2018-09-26 23:07:17 -04:00
parent 8bf49a664a
commit 2693f6f138

View file

@ -267,6 +267,7 @@ $("#create-vm").click(function(){
const max_cpu = $(this).data('max_cpu');
const max_mem = $(this).data('max_mem');
const max_disk = $(this).data('max_disk');
var ssh_regex = new RegExp("ssh-rsa AAAA[0-9A-Za-z+/]+[=]{0,3}( [^@]+@[^@]+)?")
var disk = document.getElementById('disk').value;
fetch(`/template/${template}/disk`, {
credentials: 'same-origin',
@ -279,7 +280,9 @@ $("#create-vm").click(function(){
return disk
}).then((disk) => {
if (name && disk) {
if (disk > max_disk) {
if (!ssh_regex.test(ssh_key)) {
swal("Uh oh...", "Invalid SSH key!", "error");
} else if (disk > max_disk) {
swal("Uh oh...", `You do not have enough disk resources available! Please lower the VM disk size to ${max_disk}GB or lower.`, "error");
} else if (template != 'none' && cores > max_cpu) {
swal("Uh oh...", `You do not have enough CPU resources available! Please lower the VM cores to ${max_cpu} or lower.`, "error");