From a12fbc65b455291dcdaac721fa709c01a6a1f6b5 Mon Sep 17 00:00:00 2001 From: juanescarraga <32574306+juanescarraga@users.noreply.github.com> Date: Tue, 12 Nov 2019 11:46:27 -0500 Subject: [PATCH] Code refactor 8021x on windows --- lib/network.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/network.js b/lib/network.js index 19b5038..a7f5600 100644 --- a/lib/network.js +++ b/lib/network.js @@ -300,22 +300,27 @@ function getWindowsIEEE8021x(connectionType) { }; if(connectionType == 'wired'){ try { - const state8021x = execSync('netsh lan show interface', util.execOptsWin); - console.log('state funtion', state8021x); - const stateRsult = state8021x.output.split('\n').pop(); - const currentState = stateRsult.includes('auth'); - i8021x.state = currentState ? 'Enabled' : 'Disabled'; - if (i8021x.state === 'Disabled') { - return i8021x; - } - const protocol8021x = execSync('netsh lan show profiles', util.execOptsWin); - console.log('protocol function', protocol8021x); - protocol8021x.output.split('\r\n').filter((protocolauth) => { - const currentProtocol = protocolauth.includes('EAP'); - if(currentProtocol) i8021x.protocol = protocolauth.split(':').pop(); + + const result = execSync('netsh lan show profiles', util.execOptsWin); + const arrayResult = result.split('\r\n'); + + const state8021x = arrayResult.find((element) => { + return element.includes('802.1x'); }); - return i8021x; - + + if(state8021x.includes('Disabled')){ + i8021x.state = "Disabled"; + i8021x.protocol = "Not Configured"; + return i8021x; + } else { + const protocol8021x = arrayResult.find((element) => { + return element.includes('EAP'); + }); + i8021x.protocol = protocol8021x.split(':').pop(); + i8021x.state = "Enabled"; + return i8021x; + } + } catch (error) { return i8021x; }