strip iac
This commit is contained in:
parent
a4c233ca8c
commit
3f1e1a8505
|
@ -106,6 +106,8 @@ const (
|
||||||
TELOPT_TTYLOC = 28
|
TELOPT_TTYLOC = 28
|
||||||
// TELOPT_NAWS - Negotiate About Window Size
|
// TELOPT_NAWS - Negotiate About Window Size
|
||||||
TELOPT_NAWS = 31
|
TELOPT_NAWS = 31
|
||||||
|
// TELOPT_FLOWCTRL - remote flow control
|
||||||
|
TELOPT_FLOWCTRL = 33
|
||||||
|
|
||||||
// TELOPT_SB_SEND SEND subneg
|
// TELOPT_SB_SEND SEND subneg
|
||||||
TELOPT_SB_SEND = 1
|
TELOPT_SB_SEND = 1
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package tclient
|
package tclient
|
||||||
|
|
||||||
|
// ignore: TELNET_AYT, TELNET_AO
|
||||||
|
// accept: 0x01, 0x03, 0x18, 0x1f == TELOPT_ECHO, TELOPT_SGA, TELOPT_TTYPE, TELOPT_NAWS
|
||||||
func (c *TelnetClient) negotiate(sequence []byte) error {
|
func (c *TelnetClient) negotiate(sequence []byte) error {
|
||||||
if len(sequence) < 3 {
|
if len(sequence) < 3 {
|
||||||
// do nothing
|
// do nothing
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
//fmt.Println(sequence)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// DO sequence
|
// DO sequence
|
||||||
|
@ -29,6 +31,16 @@ func (c *TelnetClient) negotiate(sequence []byte) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WONT -> DONT
|
||||||
|
if sequence[1] == TELNET_WONT && len(sequence) == 3 {
|
||||||
|
err = c.WriteRaw([]byte{TELNET_IAC, TELNET_DONT, sequence[2]})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WILL -> DO
|
||||||
|
if sequence[1] == TELNET_WILL && len(sequence) == 3 {
|
||||||
|
err = c.WriteRaw([]byte{TELNET_IAC, TELNET_DO, sequence[2]})
|
||||||
|
}
|
||||||
|
|
||||||
// subseq SEND request
|
// subseq SEND request
|
||||||
if len(sequence) == 6 && sequence[1] == TELNET_SB && sequence[3] == TELOPT_SB_SEND {
|
if len(sequence) == 6 && sequence[1] == TELNET_SB && sequence[3] == TELOPT_SB_SEND {
|
||||||
// what to send?
|
// what to send?
|
||||||
|
@ -42,6 +54,8 @@ func (c *TelnetClient) negotiate(sequence []byte) error {
|
||||||
err = c.WriteRaw([]byte{TELNET_IAC, TELNET_SB, TELOPT_SB_NEV_ENVIRON, TELOPT_SB_IS, TELNET_IAC, TELNET_SE})
|
err = c.WriteRaw([]byte{TELNET_IAC, TELNET_SB, TELOPT_SB_NEV_ENVIRON, TELOPT_SB_IS, TELNET_IAC, TELNET_SE})
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
// accept all
|
||||||
|
err = c.WriteRaw([]byte{TELNET_IAC, TELNET_SB, sequence[2], 0, TELNET_IAC, TELNET_SE})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
29
reader.go
29
reader.go
|
@ -108,6 +108,25 @@ func (c *TelnetClient) ReadUntil(waitfor string) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not IAC sequence, but IAC char =\
|
||||||
|
if b == TELNET_IAC {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove \r ; remove backspaces
|
||||||
|
if b == 8 {
|
||||||
|
if lastLine.Len() > 0 {
|
||||||
|
lastLine.Truncate(lastLine.Len() - 1)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if b == '\r' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
//fmt.Printf("%s | %d\n", string(b), b)
|
||||||
|
//fmt.Printf("%s", string(b))
|
||||||
|
|
||||||
// this is not escape sequence, so write this byte to buffer
|
// this is not escape sequence, so write this byte to buffer
|
||||||
// update: strip '\r'
|
// update: strip '\r'
|
||||||
/*if b != '\r' {
|
/*if b != '\r' {
|
||||||
|
@ -130,16 +149,6 @@ func (c *TelnetClient) ReadUntil(waitfor string) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove \r ; remove backspaces
|
|
||||||
if b == 8 {
|
|
||||||
if lastLine.Len() > 0 {
|
|
||||||
lastLine.Truncate(lastLine.Len() - 1)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if b == '\r' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// check for CRLF.
|
// check for CRLF.
|
||||||
// We need last line to compare with prompt.
|
// We need last line to compare with prompt.
|
||||||
//if b == '\n' && prev == '\r' {
|
//if b == '\n' && prev == '\r' {
|
||||||
|
|
|
@ -48,7 +48,7 @@ func New(tout int, login string, password string, prompt string) *TelnetClient {
|
||||||
login: login,
|
login: login,
|
||||||
password: password,
|
password: password,
|
||||||
prompt: `(?msi:[\$%#>]$)`,
|
prompt: `(?msi:[\$%#>]$)`,
|
||||||
loginPrompt: `[Uu]ser(\s)?[Nn]ame\:$`,
|
loginPrompt: `[Uu]ser(\s)?[Nn]ame\:(\s+)?$`,
|
||||||
passwordPrompt: `[Pp]ass[Ww]ord\:$`,
|
passwordPrompt: `[Pp]ass[Ww]ord\:$`,
|
||||||
closed: false,
|
closed: false,
|
||||||
Options: make([]int,0),
|
Options: make([]int,0),
|
||||||
|
|
Loading…
Reference in New Issue