From 3b25ba9f11bebbadef2102a7e97d42227264eece Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Sat, 23 Feb 2019 13:25:55 -0600 Subject: [PATCH 1/5] initial pure js impl for IBM i AIX variant --- aix.js | 40 ++++++++++++++++++++++++++++++++++++++++ index.js | 1 + 2 files changed, 41 insertions(+) create mode 100644 aix.js diff --git a/aix.js b/aix.js new file mode 100644 index 0000000..0ba659c --- /dev/null +++ b/aix.js @@ -0,0 +1,40 @@ +"use strict"; + +const execa = require("execa"); + +const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?"; + +const checkVariant = () => {if(require("os").type() != "OS400") throw new Error("Unsupported AIX variant"); } + +const parse = stdout => { + let result; + try { + let resultObj = JSON.parse(stdout); + const gateway = resultObj.records[0].NEXT_HOP; + const iface = +resultObj.records[0].LOCAL_BINDING_INTERFACE; + result = {gateway, iface}; + } catch {} + if (!result) { + throw new Error("Unable to determine default gateway"); + } + return result; +}; + +const promise = family => { + checkVariant(); + return execa.stdout("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]).then(stdout => { + return parse(stdout); + }); +}; + +const sync = family => { + checkVariant(); + const result = execa.sync("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]); + return parse(result.stdout); +}; + +module.exports.v4 = () => promise("IPV4"); +module.exports.v6 = () => promise("IPV6"); + +module.exports.v4.sync = () => sync("IPV4"); +module.exports.v6.sync = () => sync("IPV6"); diff --git a/index.js b/index.js index 0c9c5ce..80fc735 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ if ([ "openbsd", "sunos", "win32", + "aix", ].indexOf(platform) !== -1) { const families = require(`./${platform}`); module.exports.v4 = () => families.v4(); From a580cf303ae523ffe71f8a1a48b281f19fc0fa7b Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Sat, 23 Feb 2019 13:37:46 -0600 Subject: [PATCH 2/5] Fix style errors --- aix.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aix.js b/aix.js index 0ba659c..daf752a 100644 --- a/aix.js +++ b/aix.js @@ -4,16 +4,16 @@ const execa = require("execa"); const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?"; -const checkVariant = () => {if(require("os").type() != "OS400") throw new Error("Unsupported AIX variant"); } +const checkVariant = () => {if (require("os").type() !== "OS400") throw new Error("Unsupported AIX variant"); }; const parse = stdout => { - let result; + const result; try { - let resultObj = JSON.parse(stdout); - const gateway = resultObj.records[0].NEXT_HOP; - const iface = +resultObj.records[0].LOCAL_BINDING_INTERFACE; - result = {gateway, iface}; - } catch {} + let resultObj = JSON.parse(stdout); + const gateway = resultObj.records[0].NEXT_HOP; + const iface = +resultObj.records[0].LOCAL_BINDING_INTERFACE; + result = {gateway, iface}; + } catch {} if (!result) { throw new Error("Unable to determine default gateway"); } From 046a21ac00cc5b37e2891c93fdfee8e5955d6646 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Sat, 23 Feb 2019 13:40:41 -0600 Subject: [PATCH 3/5] minor bugfix with unassigned const --- aix.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aix.js b/aix.js index daf752a..6f543e7 100644 --- a/aix.js +++ b/aix.js @@ -7,7 +7,7 @@ const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_I const checkVariant = () => {if (require("os").type() !== "OS400") throw new Error("Unsupported AIX variant"); }; const parse = stdout => { - const result; + let result = undefined; try { let resultObj = JSON.parse(stdout); const gateway = resultObj.records[0].NEXT_HOP; From 03beb70ca17dba60081a89973fefc502a265497f Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Sat, 23 Feb 2019 13:58:06 -0600 Subject: [PATCH 4/5] fix style errors #2 --- aix.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aix.js b/aix.js index 6f543e7..d039d46 100644 --- a/aix.js +++ b/aix.js @@ -7,9 +7,9 @@ const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_I const checkVariant = () => {if (require("os").type() !== "OS400") throw new Error("Unsupported AIX variant"); }; const parse = stdout => { - let result = undefined; + let result; try { - let resultObj = JSON.parse(stdout); + const resultObj = JSON.parse(stdout); const gateway = resultObj.records[0].NEXT_HOP; const iface = +resultObj.records[0].LOCAL_BINDING_INTERFACE; result = {gateway, iface}; From 1b354f82c2e72a8899395537e0c9af285f95e714 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski Date: Sat, 23 Feb 2019 15:32:31 -0600 Subject: [PATCH 5/5] remove silly plus sign --- aix.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aix.js b/aix.js index d039d46..8f20f4d 100644 --- a/aix.js +++ b/aix.js @@ -11,7 +11,7 @@ const parse = stdout => { try { const resultObj = JSON.parse(stdout); const gateway = resultObj.records[0].NEXT_HOP; - const iface = +resultObj.records[0].LOCAL_BINDING_INTERFACE; + const iface = resultObj.records[0].LOCAL_BINDING_INTERFACE; result = {gateway, iface}; } catch {} if (!result) {