telnet-client
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -33,3 +33,3 @@ // Node.js Telnet client | ||
this.irs = (typeof opts.irs !== 'undefined' ? opts.irs : '\r\n'); | ||
this.ors = (typeof opts.ors !== 'undefined' ? opts.ors : '\n'); | ||
this.ors = (typeof opts.ors !== 'undefined' ? opts.ors : '\r\n'); | ||
this.echoLines = (typeof opts.echoLines !== 'undefined' ? opts.echoLines : 1); | ||
@@ -45,2 +45,3 @@ this.response = ''; | ||
self.stringData = ''; | ||
self.emit('connect'); | ||
}); | ||
@@ -79,16 +80,18 @@ | ||
this.telnetSocket.write(cmd, function() { | ||
self.telnetState = 'response'; | ||
self.emit('writedone'); | ||
if (this.telnetSocket.writable) { | ||
this.telnetSocket.write(cmd, function() { | ||
self.telnetState = 'response'; | ||
self.emit('writedone'); | ||
self.on('responseready', function() { | ||
if (callback && self.cmdOutput !== 'undefined') { | ||
callback(self.cmdOutput.join('\n')); | ||
} | ||
else if (callback && self.cmdOutput === 'undefined') callback; | ||
self.on('responseready', function() { | ||
if (callback && self.cmdOutput !== 'undefined') { | ||
callback(self.cmdOutput.join('\n')); | ||
} | ||
else if (callback && self.cmdOutput === 'undefined') callback; | ||
// reset stored response | ||
self.stringData = ''; | ||
// reset stored response | ||
self.stringData = ''; | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -108,9 +111,10 @@ | ||
if (chunk[0] === 255 && chunk[1] !== 255) { | ||
telnetObj.telnetState = 'negotiate'; | ||
telnetObj.stringData = ''; | ||
var negReturn = negotiate(telnetObj, chunk); | ||
negotiate(telnetObj, chunk); | ||
return; | ||
if (negReturn == undefined) return; | ||
else chunk = negReturn; | ||
} | ||
else if (telnetObj.telnetState === 'start') { | ||
if (telnetObj.telnetState === 'start') { | ||
telnetObj.telnetState = 'getprompt'; | ||
@@ -160,24 +164,38 @@ } | ||
if (handle === 'username') { | ||
telnetObj.telnetSocket.write(telnetObj.username + '\n', function() { | ||
telnetObj.telnetState = 'getprompt'; | ||
}); | ||
if (telnetObj.telnetSocket.writable) { | ||
telnetObj.telnetSocket.write(telnetObj.username + '\r\n', function() { | ||
telnetObj.telnetState = 'getprompt'; | ||
}); | ||
} | ||
} | ||
else if (handle === 'password') { | ||
telnetObj.telnetSocket.write(telnetObj.password + '\n', function() { | ||
telnetObj.telnetState = 'getprompt'; | ||
}); | ||
if (telnetObj.telnetSocket.writable) { | ||
telnetObj.telnetSocket.write(telnetObj.password + '\r\n', function() { | ||
telnetObj.telnetState = 'getprompt'; | ||
}); | ||
} | ||
} | ||
} | ||
function negotiate(telnetObj, telnetCmd) { | ||
function negotiate(telnetObj, chunk) { | ||
// info: http://tools.ietf.org/html/rfc1143#section-7 | ||
// refuse to start performing and ack the start of performance | ||
// DO -> WONT; WILL -> DO | ||
var negResp = telnetCmd.toString('hex').replace(/fd/g, 'fc').replace(/fb/g, 'fd'); | ||
var packetLength = chunk.length, negData = chunk, cmdData, negResp; | ||
telnetObj.telnetSocket.write( | ||
Buffer(negResp, "hex"), | ||
function() { | ||
telnetObj.telnetState = 'getprompt'; | ||
}); | ||
for (var i = 0; i < packetLength; i+=3) { | ||
if (chunk[i] != 255) { | ||
negData = chunk.slice(0, i); | ||
cmdData = chunk.slice(i); | ||
break; | ||
} | ||
} | ||
negResp = negData.toString('hex').replace(/fd/g, 'fc').replace(/fb/g, 'fd'); | ||
if (telnetObj.telnetSocket.writable) | ||
telnetObj.telnetSocket.write(Buffer(negResp, 'hex')); | ||
if (cmdData != undefined) return cmdData; | ||
else return; | ||
} | ||
@@ -184,0 +202,0 @@ |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "./lib/telnet-client.js", | ||
@@ -15,2 +15,8 @@ "engine": "node >= 0.10.23", | ||
}, | ||
"devDependencies": { | ||
"nodeunit": ">= 0.9.0" | ||
}, | ||
"scripts": { | ||
"test": "nodeunit test" | ||
}, | ||
"repository": { | ||
@@ -24,8 +30,4 @@ "type": "git", | ||
"email": "petar.koretic@sartura.hr" | ||
}, | ||
{ | ||
"name": "Robert Lesac", | ||
"email": "" | ||
} | ||
] | ||
} |
@@ -34,3 +34,3 @@ # node-telnet-client | ||
connection.end(); | ||
); | ||
}); | ||
@@ -78,2 +78,6 @@ connection.on('close', function() { | ||
### Event: 'connect' | ||
Emitted when a socket connection is successfully established. | ||
### Event: 'ready' | ||
@@ -80,0 +84,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11263
7
183
106
1