{"action":"created","comment":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/45955570","id":45955570,"diff_hunk":"@@ -705,39 +710,152 @@ controller.disableAccessPoint = function(opts) {\n   });\n };\n \n+// clear terminal windows and linux\n+controller.clear = function() {\n+  return new Promise(function(resolve) {\n+    // clears terminal\n+    if (!global.IS_TEST_ENV) {\n+      process.stdout.write('\\u001b[2J\\u001b[0;0H');\n+    }\n+    resolve();\n+  });\n+};\n+\n+// ssh connection with advanced options and error handling\n+controller.remote = function(tessel, opts) {\n+  logs.info('Starting remote SSH Session on Tessel at ' + opts.ip + '.\\nType \\'exit\\' at the prompt to end.');\n+  return new Promise(function(resolve, reject) {\n+    var options = ['-i',\n+      opts.key,\n+      '-p',\n+      opts.port,\n+      '-e',\n+      opts.escape_char,\n+      opts.username + '@' + tessel.lanConnection.ip\n+    ];\n+\n+    var ch = require('child_process')\n+      .spawn('ssh', options, {\n+        stdio: 'inherit'\n+      });\n+\n+    // error handling\n+    ch.once('error', function(e) {\n+      if (e === 255) {\n+        controller.clear()\n+          .then(function() {\n+            logs.warn('Login to Tessel at failed with KEY ' + opts.key + ' !');\n+          }).then(resolve);\n+      } else {\n+        reject('Error while connected to ' + tessel.name + ':', e);\n+      }\n+    });\n+\n+    // exit handling\n+    ch.once('exit', function(e) {\n+      if (e === 127 || e === 0) { // exit by user\n+        // clear console\n+        controller.clear()\n+          .then(function() {\n+            logs.warn('Connection to ' + tessel.name + ' closed!\\n');\n+            resolve();\n+          });\n+      } else if (e === 255) {\n+        controller.clear()\n+          .then(function() {\n+            logs.warn('You are not authorized with key ' + opts.key);\n+          }).then(resolve);\n+      } else {\n+        controller.clear()\n+          .then(function() {\n+            logs.warn('Connection to ' + tessel.name + ' closed due to reason (error code): ', e);\n+            reject(e);\n+          });\n+      }\n+    });\n+  });\n+};\n+\n /*\n   The T2 root command is used to login into the Tessel's root shell.\n */\n controller.root = function(opts) {\n+\n   // Only give us LAN connections\n   opts.lan = true;\n+\n   // We must already be authorized\n   opts.authorized = true;\n-  // Fetch a Tessel\n-  return controller.standardTesselCommand(opts, function(tessel) {\n-    logs.info('Starting SSH Session on Tessel. Type \\'exit\\' at the prompt to end.');\n+\n+  // by --ip tessels outside the netmask are also accessable if key is valid\n+  if (opts.ip) {\n+    debug('Using IP ' + opts.ip + ' instead of hostname!');\n+\n+    // remote connection expected (outside netmask)\n     return new Promise(function(resolve, reject) {\n-      // Spawn a new SSH process\n-      var child = cp.spawn('ssh', ['-i',\n-        // Use the provided key path\n-        opts.key,\n-        // Connect to the Tessel's IP Address\n-        'root@' + tessel.lanConnection.ip\n-      ], {\n-        // Pipe our standard streams to the console\n-        stdio: 'inherit'\n-      });\n+      var data = {\n+        ip: opts.ip,\n+        host: opts.name || opts.ip,\n+        port: opts.port,\n+        auth: {\n+          host: opts.ip,\n+          username: opts.username || 'root',\n+          passphrase: opts.passphrase || '',\n+          privateKey: fs.readFileSync(opts.key),\n+          readyTimeout: 5000\n+        },\n+        connectionType: 'LAN',\n+        authorized: false,\n+        ssh: undefined\n+      };\n+      var conn = new lan.LAN.Connection(data);\n+      var tessel = new Tessel(conn);\n+      tessel.connection.open()\n+        .then(function() {\n+          if (tessel.lanConnection.authorized) {\n+            tessel.getName()\n+              .then(function() {\n+                controller.clear().then(function() {\n+                  controller.remote(tessel, opts)\n+                    .then(resolve).catch(function() {\n+                      resolve();\n+                    });","path":"lib/controller.js","position":138,"original_position":138,"commit_id":"19cdd765bfcdbd8b445fc838e31faa8f1c6c9b1a","original_commit_id":"19cdd765bfcdbd8b445fc838e31faa8f1c6c9b1a","user":{"login":"LinusU","id":189580,"avatar_url":"https://avatars.githubusercontent.com/u/189580?v=3","gravatar_id":"","url":"https://api.github.com/users/LinusU","html_url":"https://github.com/LinusU","followers_url":"https://api.github.com/users/LinusU/followers","following_url":"https://api.github.com/users/LinusU/following{/other_user}","gists_url":"https://api.github.com/users/LinusU/gists{/gist_id}","starred_url":"https://api.github.com/users/LinusU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LinusU/subscriptions","organizations_url":"https://api.github.com/users/LinusU/orgs","repos_url":"https://api.github.com/users/LinusU/repos","events_url":"https://api.github.com/users/LinusU/events{/privacy}","received_events_url":"https://api.github.com/users/LinusU/received_events","type":"User","site_admin":false},"body":"This is probably not the correct place to discuss this at all, but still. Since we already using stuff that only works in Node >= 4, shouldn't we use fat-arrow for binding this instead of `self = this`?\r\n\r\n```javascript\r\ntessel.getName()\r\n.then(controller.clear)\r\n.then(() => controller.remote(tessel, opts))\r\n.then(resolve)\r\n.catch(reject); // Changed this to reject as well, correct?\r\n```","created_at":"2015-11-26T09:02:18Z","updated_at":"2015-11-26T09:02:18Z","html_url":"https://github.com/tessel/t2-cli/pull/466#discussion_r45955570","pull_request_url":"https://api.github.com/repos/tessel/t2-cli/pulls/466","_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/45955570"},"html":{"href":"https://github.com/tessel/t2-cli/pull/466#discussion_r45955570"},"pull_request":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/466"}}},"pull_request":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/466","id":51856261,"html_url":"https://github.com/tessel/t2-cli/pull/466","diff_url":"https://github.com/tessel/t2-cli/pull/466.diff","patch_url":"https://github.com/tessel/t2-cli/pull/466.patch","issue_url":"https://api.github.com/repos/tessel/t2-cli/issues/466","number":466,"state":"open","locked":false,"title":"t2 root remote","user":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"body":"This commit adds the ability to connect to a Tessel is accessible by\r\nport forwarding.\r\nTests are covered by @rwaldron awesome using a hammer test :wink:\r\n\r\nIn general all common ssh options are implemented.\r\n\r\nController.js got the following new or changed objects:\r\n\r\n|  Object | return | Description |\r\n|---|---|---|\r\n| controller.clear() | promise | clears terminal on mac, windows and linux |\r\n| controller.remote(tessel, opts) | promise | ssh connection with advanced options, error handling and port forwarding support. The `tessel` option is used to get `tessel.name` for creating event handlers of the child process |\r\n| controller.root(opts) | promise | conditional switch on `opts.ip` for connecting Tessels outside the current netmask (mDNS limit) |","created_at":"2015-11-25T23:10:23Z","updated_at":"2015-11-26T09:02:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d732f09cd08793c3098e1133a1765e85a8e2e25","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tessel/t2-cli/pulls/466/commits","review_comments_url":"https://api.github.com/repos/tessel/t2-cli/pulls/466/comments","review_comment_url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tessel/t2-cli/issues/466/comments","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/19cdd765bfcdbd8b445fc838e31faa8f1c6c9b1a","head":{"label":"Student007:t2root","ref":"t2root","sha":"19cdd765bfcdbd8b445fc838e31faa8f1c6c9b1a","user":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"repo":{"id":39995577,"name":"t2-cli","full_name":"Student007/t2-cli","owner":{"login":"Student007","id":5132566,"avatar_url":"https://avatars.githubusercontent.com/u/5132566?v=3","gravatar_id":"","url":"https://api.github.com/users/Student007","html_url":"https://github.com/Student007","followers_url":"https://api.github.com/users/Student007/followers","following_url":"https://api.github.com/users/Student007/following{/other_user}","gists_url":"https://api.github.com/users/Student007/gists{/gist_id}","starred_url":"https://api.github.com/users/Student007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Student007/subscriptions","organizations_url":"https://api.github.com/users/Student007/orgs","repos_url":"https://api.github.com/users/Student007/repos","events_url":"https://api.github.com/users/Student007/events{/privacy}","received_events_url":"https://api.github.com/users/Student007/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Student007/t2-cli","description":"Command line interface to Tessel 2.","fork":true,"url":"https://api.github.com/repos/Student007/t2-cli","forks_url":"https://api.github.com/repos/Student007/t2-cli/forks","keys_url":"https://api.github.com/repos/Student007/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Student007/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Student007/t2-cli/teams","hooks_url":"https://api.github.com/repos/Student007/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/Student007/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/Student007/t2-cli/events","assignees_url":"https://api.github.com/repos/Student007/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/Student007/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/Student007/t2-cli/tags","blobs_url":"https://api.github.com/repos/Student007/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Student007/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Student007/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/Student007/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Student007/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/Student007/t2-cli/languages","stargazers_url":"https://api.github.com/repos/Student007/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/Student007/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/Student007/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/Student007/t2-cli/subscription","commits_url":"https://api.github.com/repos/Student007/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/Student007/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/Student007/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/Student007/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/Student007/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/Student007/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Student007/t2-cli/merges","archive_url":"https://api.github.com/repos/Student007/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Student007/t2-cli/downloads","issues_url":"https://api.github.com/repos/Student007/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/Student007/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/Student007/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/Student007/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Student007/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/Student007/t2-cli/releases{/id}","created_at":"2015-07-31T08:38:19Z","updated_at":"2015-07-31T08:38:19Z","pushed_at":"2015-11-25T23:10:20Z","git_url":"git://github.com/Student007/t2-cli.git","ssh_url":"git@github.com:Student007/t2-cli.git","clone_url":"https://github.com/Student007/t2-cli.git","svn_url":"https://github.com/Student007/t2-cli","homepage":"","size":844,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tessel:master","ref":"master","sha":"bc2c88ddcf62d8174be56dc6868e5b503ff73af3","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":30388450,"name":"t2-cli","full_name":"tessel/t2-cli","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/t2-cli","description":"Command line interface to Tessel 2.","fork":false,"url":"https://api.github.com/repos/tessel/t2-cli","forks_url":"https://api.github.com/repos/tessel/t2-cli/forks","keys_url":"https://api.github.com/repos/tessel/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/t2-cli/teams","hooks_url":"https://api.github.com/repos/tessel/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/tessel/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/t2-cli/events","assignees_url":"https://api.github.com/repos/tessel/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/t2-cli/tags","blobs_url":"https://api.github.com/repos/tessel/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/t2-cli/languages","stargazers_url":"https://api.github.com/repos/tessel/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/tessel/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/tessel/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/tessel/t2-cli/subscription","commits_url":"https://api.github.com/repos/tessel/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/t2-cli/merges","archive_url":"https://api.github.com/repos/tessel/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/t2-cli/downloads","issues_url":"https://api.github.com/repos/tessel/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/tessel/t2-cli/releases{/id}","created_at":"2015-02-06T01:27:53Z","updated_at":"2015-11-17T14:45:55Z","pushed_at":"2015-11-26T05:18:50Z","git_url":"git://github.com/tessel/t2-cli.git","ssh_url":"git@github.com:tessel/t2-cli.git","clone_url":"https://github.com/tessel/t2-cli.git","svn_url":"https://github.com/tessel/t2-cli","homepage":"","size":1032,"stargazers_count":36,"watchers_count":36,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":69,"forks":14,"open_issues":69,"watchers":36,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/466"},"html":{"href":"https://github.com/tessel/t2-cli/pull/466"},"issue":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/466"},"comments":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/466/comments"},"review_comments":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/466/comments"},"review_comment":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/466/commits"},"statuses":{"href":"https://api.github.com/repos/tessel/t2-cli/statuses/19cdd765bfcdbd8b445fc838e31faa8f1c6c9b1a"}}}}