From d964809278f1442be5fbe453bc307bf223daaeaa Mon Sep 17 00:00:00 2001 From: jialiya Date: Sun, 7 Sep 2014 20:13:48 -0700 Subject: [PATCH 1/3] print unsecure network security if there's no password present --- bin/tessel-wifi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tessel-wifi.js b/bin/tessel-wifi.js index c021225..04c4b6e 100755 --- a/bin/tessel-wifi.js +++ b/bin/tessel-wifi.js @@ -98,7 +98,7 @@ common.controller({stop: false}, function (err, client) { pass = new Buffer(String(pass)); } - var security = new Buffer((String(argv.security) || (pass ? 'wpa2' : 'unsecure')).toLowerCase()); + var security = new Buffer((pass.length ? String(argv.security) : 'unsecure').toLowerCase()); client.configureWifi(ssid, pass, security, { timeout: argv.timeout From 7412d20e4dd879cfdc7a6de46d1a7ce2a7b60ef9 Mon Sep 17 00:00:00 2001 From: jialiya Date: Sun, 7 Sep 2014 20:37:17 -0700 Subject: [PATCH 2/3] throwing error on bad combos of password & security --- bin/tessel-wifi.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/tessel-wifi.js b/bin/tessel-wifi.js index 04c4b6e..cebd7e1 100755 --- a/bin/tessel-wifi.js +++ b/bin/tessel-wifi.js @@ -38,7 +38,6 @@ var argv = require("nomnom") }) .option('security', { abbr: 's', - default: 'wpa2', help: '[Tessel] Security type of the network, one of (wpa2|wpa|wep). Omit for unsecured networks.' }) .option('timeout', { @@ -98,7 +97,26 @@ common.controller({stop: false}, function (err, client) { pass = new Buffer(String(pass)); } - var security = new Buffer((pass.length ? String(argv.security) : 'unsecure').toLowerCase()); + var security = argv.security; + if (!pass.length) { + if (security && security.toLowerCase() != 'unsecure') { + // there is no password and security was specified + logs.err('A password is needed for', security); + client.close(); + } else { + // if there isn't a password then assume security type is unsecure + security = new Buffer('unsecure'); + } + } else if (!security) { + // if there is no security specified, default to wpa2 + security = new Buffer('wpa2'); + } else if (security.toLowerCase() == 'unsecure') { + logs.err('Cannot connect to an unsecure network with a password specified'); + client.close(); + } else { + // otherwise use chosen security type + security = new Buffer(security.toLowerCase()); + } client.configureWifi(ssid, pass, security, { timeout: argv.timeout From c2d3bbc820367e1003246d2ecceb1a6c659500fd Mon Sep 17 00:00:00 2001 From: jialiya Date: Sun, 7 Sep 2014 20:57:44 -0700 Subject: [PATCH 3/3] exit after error --- bin/tessel-wifi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/tessel-wifi.js b/bin/tessel-wifi.js index cebd7e1..25d6802 100755 --- a/bin/tessel-wifi.js +++ b/bin/tessel-wifi.js @@ -103,6 +103,7 @@ common.controller({stop: false}, function (err, client) { // there is no password and security was specified logs.err('A password is needed for', security); client.close(); + process.exit(1); } else { // if there isn't a password then assume security type is unsecure security = new Buffer('unsecure'); @@ -113,6 +114,7 @@ common.controller({stop: false}, function (err, client) { } else if (security.toLowerCase() == 'unsecure') { logs.err('Cannot connect to an unsecure network with a password specified'); client.close(); + process.exit(1); } else { // otherwise use chosen security type security = new Buffer(security.toLowerCase());