From 7c3c8b2436cdde54cabb3b28e5f931f312bc0eb2 Mon Sep 17 00:00:00 2001 From: ricardopolo Date: Tue, 12 Nov 2019 11:00:35 -0500 Subject: [PATCH] Adding 8021x windows function --- lib/network.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/network.js b/lib/network.js index 3b2a4d6..19b5038 100644 --- a/lib/network.js +++ b/lib/network.js @@ -293,6 +293,36 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) { } } +function getWindowsIEEE8021x(connectionType) { + let i8021x = { + state: 'Unknown', + protocol: 'Unknown', + }; + 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(); + }); + return i8021x; + + } catch (error) { + return i8021x; + } + } + return i8021x; +} + function splitSectionsNics(lines) { const result = []; let section = []; @@ -436,13 +466,15 @@ function getLinuxIfaceDNSsuffix(connectionName) { } } -function getLinuxIfaceAuthProtocol(connectionName) { +function getLinuxIfaceAuth8021x(connectionName) { if(connectionName) { const cmd = `nmcli connection show "${connectionName}" \| grep 802-1x.eap;`; try { const result = execSync(cmd).toString(); const resultFormat = result.replace(/\s+/g,' ').trim(); const authenticationProtocol = resultFormat.split(" ").slice(1).toString(); + + return authenticationProtocol == '--' ? '': authenticationProtocol; } catch (e) { return 'Not configured'; @@ -452,6 +484,17 @@ function getLinuxIfaceAuthProtocol(connectionName) { } } +function getLinuxIfaceState8021x(authenticationProtocol) { + if(authenticationProtocol) { + if(authenticationProtocol == 'Not configured'){ + return 'Disabled'; + } + return 'Enabled'; + } else { + return 'Unknown'; + } +} + function testVirtualNic(iface, ifaceName, mac) { const virtualMacs = ['00:00:00:00:00:00', '00:03:FF', '00:05:69', '00:0C:29', '00:0F:4B', '00:0F:4B', '00:13:07', '00:13:BE', '00:15:5d', '00:16:3E', '00:1C:42', '00:21:F6', '00:21:F6', '00:24:0B', '00:24:0B', '00:50:56', '00:A0:B1', '00:E0:C8', '08:00:27', '0A:00:27', '18:92:2C', '16:DF:49', '3C:F3:92', '54:52:00', 'FC:15:97']; if (mac) { @@ -523,7 +566,8 @@ function networkInterfaces(callback) { let operstate = 'down'; let dhcp = false; let dnsSuffix = ''; - let authProtocol = ''; + let auth8021x = ''; + let state8021x = ''; let type = ''; if (ifaces.hasOwnProperty(dev)) { @@ -580,7 +624,8 @@ function networkInterfaces(callback) { const connectionName = getLinuxIfaceConnectionName(iface); dhcp = getLinuxIfaceDHCPstatus(connectionName); dnsSuffix = getLinuxIfaceDNSsuffix(connectionName); - authProtocol = getLinuxIfaceAuthProtocol(connectionName); + auth8021x = getLinuxIfaceAuth8021x(connectionName); + state8021x = getLinuxIfaceState8021x(auth8021x); lines = execSync(cmd).toString().split('\n'); @@ -603,7 +648,8 @@ function networkInterfaces(callback) { if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; } } if (_windows) { - authProtocol = 'Unknown'; + + dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev); nics.forEach(detail => { if (detail.mac === mac) { @@ -614,6 +660,11 @@ function networkInterfaces(callback) { type = detail.type; } }); + console.log('type', type); + const IEEE8021x = getWindowsIEEE8021x(type); + console.log('result', IEEE8021x); + auth8021x = IEEE8021x.protocol; + state8021x = IEEE8021x.state; if (dev.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wireless') >= 0) { type = 'wireless'; } @@ -635,7 +686,8 @@ function networkInterfaces(callback) { speed, dhcp, dnsSuffix, - authProtocol, + auth8021x, + state8021x, carrierChanges, }); }