From 5f3ee8e61b38801b0fc73e826dfee99f40566fa8 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 15 Jul 2021 04:03:51 +0200 Subject: [PATCH] Updated Management validation checks --- plugins/dynamix/ManagementAccess.page | 76 ++++++++++++--------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/plugins/dynamix/ManagementAccess.page b/plugins/dynamix/ManagementAccess.page index c579b1256..c11cd223a 100644 --- a/plugins/dynamix/ManagementAccess.page +++ b/plugins/dynamix/ManagementAccess.page @@ -98,67 +98,59 @@ function validatePorts(form) { } function checkPorts(form,provision) { var portsInUse = JSON.parse(''); - if (provision) // SSL is already set to auto - var check = [{'key':'PORTSSL','port':'','default':'443',name:'_(HTTPS port)_'}]; - else - var check = [ - {'key':'PORTTELNET','port':'','default':'23',name:'_(TELNET port)_'}, - {'key':'PORTSSH','port':'','default':'22',name:'_(SSH port)_'}, - {'key':'PORT','port':'','default':'80',name:'_(HTTP port)_'}, - {'key':'PORTSSL','port':'','default':'443',name:'_(HTTPS port)_'} + var range = [], list = [], duplicates = []; + if (provision) { // SSL is already set to auto + var checks = [{'key':"PORTSSL", 'used':"", 'port':"", 'default':"443", 'name':"_(HTTPS port)_"}]; + } else { + var checks = [ + {'key':"PORTTELNET", 'used':"", 'port':"", 'default':"23" , 'name':"_(TELNET port)_"}, + {'key':"PORTSSH" , 'used':"" , 'port':"" , 'default':"22" , 'name':"_(SSH port)_"}, + {'key':"PORT" , 'used':"" , 'port':"" , 'default':"80" , 'name':"_(HTTP port)_"}, + {'key':"PORTSSL" , 'used':"" , 'port':"" , 'default':"443", 'name':"_(HTTPS port)_"} ]; - var list = []; - var dupeCheck = []; - var range = []; - for (var i=0; i < check.length; i++) { - var key = check[i]['key']; - var port = check[i]['port']; - var portdefault = check[i]['default']; - var name = check[i]['name']; - var item = $(form).find('input[name="'+key+'"]'); - if (!item.val()) item.val(portdefault); - item.val(parseInt(item.val())); + } + for (var i=0,check; check=checks[i]; i++) { + var item = $(form).find('input[name="'+check['key']+'"]'); if ($(item).is(':disabled')) continue; - if (provision) - var userPort = ''; - else { - var userPort = item.val(); - if ( userPort < 1 || userPort > 65535 ) - range.push(userPort+" ("+name+")"); + var current = (check['port']||check['default']).toString(); + if (provision) { + var userPort = current; + } else { + var userPort = parseInt(item.val()||check['default']).toString(); + if (userPort < 1 || userPort > 65535) range.push(userPort+' ('+check['name']+')'); } - - dupeCheck.push(userPort); - if ( userPort !== port || provision) { - if ( portsInUse.includes(userPort) ) - list.push(userPort+" ("+name+")"); + duplicates.push(userPort); + if ((check['used'] == '1' && userPort != current) || provision) { + if (portsInUse.includes(userPort)) list.push(userPort+' ('+check['name']+')'); } } - var duplicates = dupeCheck.reduce(function(acc, el, i, arr) { + duplicates = duplicates.reduce(function(acc, el, i, arr) { if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc; }, []); - if ( range.length > 0 ) { + if (range.length > 0) { swal({title:'_(Port out of range)_',text:sprintf('_(Port %s is out of range (minimum 1 maximum 65535))_',range.join(', ')),type:'error',showCancelButton:false,confirmButtonText:"_(OK)_"}); return false; } - if ( list.length > 0 ) { + if (list.length > 0) { swal({title:'_(Port already in use)_',text:sprintf('_(Port %s is already in use by other services)_',list.join(', ')),type:'error',showCancelButton:false,confirmButtonText:"_(OK)_"}); return false; } - if ( duplicates.length > 0 ) { + if (duplicates.length > 0) { swal({title:'_(Duplicate port entered)_',text:sprintf('_(Port %s is duplicated)_',duplicates.join(', ')),type:'error',showCancelButton:false,confirmButtonText:"_(OK)_"}); return false; } return true; } function updateTELNET(form) { - form.PORTTELNET.disabled = form.USE_TELNET.value=="no"; + form.PORTTELNET.disabled = form.USE_TELNET.value=='no'; } function updateSSH(form) { - form.PORTSSH.disabled = form.USE_SSH.value=="no"; + form.PORTSSH.disabled = form.USE_SSH.value=='no'; } function updateSSL(form) { - form.PORTSSL.disabled = form.USE_SSL.value=="no"; + form.PORT.disabled = form.USE_SSL.value=='yes'; + form.PORTSSL.disabled = form.USE_SSL.value=='no'; } $(function(){ var form = document.SSLSettings; @@ -202,7 +194,7 @@ _(Use TELNET)_: :mgmt_use_telnet_help: _(TELNET port)_: -: +: :mgmt_telnet_port_help: @@ -215,7 +207,7 @@ _(Use SSH)_: :mgmt_use_ssh_help: _(SSH port)_: -: +: :mgmt_ssh_port_help: @@ -237,12 +229,12 @@ _(Use SSL/TLS)_: :mgmt_use_ssl_tls_help: _(HTTP port)_: -: +: :mgmt_http_port_help: _(HTTPS port)_: -: +: :mgmt_https_port_help: @@ -295,7 +287,7 @@ _(CA-signed certificate file)_:   -: +: :mgmt_certificate_expiration_help: