Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6.c;
- unit class Net::Telnet::Chunk;
- enum TelnetOption is export (
- 'TRANSMIT_BINARY' => 0x00.chr,
- 'ECHO' => 0x01.chr,
- 'RCP' => 0x02.chr, # Reconnection
- 'SGA' => 0x03.chr, # Suppress Go Ahead
- 'NAMS' => 0x04.chr, # Message Size Negotiation
- 'STATUS' => 0x05.chr,
- 'TIMING_MARK' => 0x06.chr,
- 'RCTE' => 0x07.chr, # Remote Controlled Trans and Echo
- 'NAOL' => 0x08.chr, # Output Line Width
- 'NAOP' => 0x09.chr, # Output Line Height
- 'NAOCRD' => 0x0A.chr, # Output Carriage-Return Disposition
- 'NAOHTS' => 0x0B.chr, # Output Horizontal Tab Stops
- 'NAOHTD' => 0x0C.chr, # Output Horizontal Tab Disposition
- 'NAOFFD' => 0x0D.chr, # Output Formfeed Disposition
- 'NAOVTS' => 0x0E.chr, # Output Vertical Stops
- 'NAOVTD' => 0x0F.chr, # Output Vertical Disposition
- 'NAOLFD' => 0x10.chr, # Output Linefeed Disposition
- 'XASCII' => 0x11.chr, # Extended ASCII
- 'LOGOUT' => 0x12.chr,
- 'BM' => 0x13.chr, # Byte Macro
- 'DET' => 0x14.chr, # Data Entry Terminal
- 'SUPDUP' => 0x15.chr,
- 'SUPDUP_OUTPUT' => 0x16.chr,
- 'SEND_LOCATION' => 0x17.chr,
- 'TERMINAL_TYPE' => 0x18.chr,
- 'END_OF_RECORD' => 0x19.chr,
- 'TUID' => 0x1A.chr, # TACACS User Identification
- 'OUTMRK' => 0x1B.chr, # Output Marking
- 'TTYLOC' => 0x1C.chr, # Terminal Location Number
- '3270_REGIME' => 0x1D.chr,
- 'X_3_PAD' => 0x1E.chr,
- 'NAWS' => 0x1F.chr, # Negotiate About Window Size
- 'TERMINAL_SPEED' => 0x20.chr,
- 'TOGGLE_FLOW_CONTROL' => 0x21.chr,
- 'LINEMODE' => 0x22.chr,
- 'XDISPLOC' => 0x23.chr, # X Display Location
- 'ENVIRON' => 0x24.chr, # Environment
- 'AUTHENTICATION' => 0x25.chr,
- 'ENCRYPT' => 0x26.chr,
- 'NEW_ENVIRON' => 0x27.chr,
- 'TN3270E' => 0x28.chr,
- 'XAUTH' => 0x29.chr,
- 'CHARSET' => 0x2A.chr,
- 'RSP' => 0x2B.chr, # Remote Serial Port
- 'COM_PORT_OPTION' => 0x2C.chr,
- 'SLE' => 0x2D.chr, # Suppress Local Echo
- 'START_TLS' => 0x2E.chr,
- 'KERMIT' => 0x2F.chr,
- 'SEND_URL' => 0x30.chr,
- 'FORWARD_X' => 0x31.chr,
- 'PRAGMA_LOGON' => 0x8A.chr,
- 'SSPI_LOGON' => 0x8B.chr,
- 'PRAGMA_HEARTBEAT' => 0x8C.chr,
- 'EXOPL' => 0xFF.chr
- );
- enum TelnetCommand is export (
- 'SE' => 0xF0.chr, # Subnegotiation End
- 'NOP' => 0xF1.chr, # No Operation
- 'DM' => 0xF2.chr, # Data Mark
- 'BRK' => 0xF3.chr, # Break
- 'IP' => 0xF4.chr, # Interrupt Process
- 'AO' => 0xF5.chr, # Abort Output
- 'AYT' => 0xF6.chr, # Are You There?
- 'EC' => 0xF7.chr, # Erase Character
- 'EL' => 0xF8.chr, # Erase Line
- 'GA' => 0xF9.chr, # Go Ahead
- 'SB' => 0xFA.chr, # Subnegotiation Begin
- 'WILL' => 0xFB.chr,
- 'WONT' => 0xFC.chr,
- 'DO' => 0xFD.chr,
- 'DONT' => 0xFE.chr,
- 'IAC' => 0xFF.chr # Interpret As Command
- );
- grammar Grammar {
- method debug($/, $message) {
- note $message;
- note "Commannd: $/";
- }
- token TOP { <chunk>+ }
- token chunk {
- :my TelnetCommand $*ACTION;
- :my Bool $*SUPPRESS-GO-AHEAD;
- <action> | <data>
- }
- token data { <:ascii>+ }
- proto token action {*}
- token action:sym(SE) { <{IAC}> <command=sym> }
- token action:sym(NOP) { <{IAC}> <command=sym> }
- token action:sym(DM) { <{IAC}> <command=sym> }
- token action:sym(BRK) { <{IAC}> <command=sym> }
- token action:sym(IP) { <{IAC}> <command=sym> }
- token action:sym(AO) { <{IAC}> <command=sym> }
- token action:sym(AYT) { <{IAC}> <command=sym> }
- token action:sym(EC) { <{IAC}> <command=sym> }
- token action:sym(EL) { <{IAC}> <command=sym> }
- token action:sym(GA) {
- | { $*SUPPRESS-GO-AHEAD == False } <{IAC}> <command=sym>
- | { $*SUPPRESS-GO-AHEAD == True } <.debug: "$/", "Received GA when SUPPRESS-GO-AHEAD was already enabled">
- }
- token action:sym(SB) {
- <(
- <{IAC}> <command=sym>
- { $*ACTION = SB }
- <subnegotiation>
- )>
- <?action:sym(SE)>
- }
- token action:sym(WILL) {
- <{IAC}> <command=sym>
- { $*ACTION = WILL }
- <negotiation>
- }
- token action:sym(WONT) {
- {IAC}> <command=sym>
- { $*ACTION = WONT }
- <negotiation>
- }
- token action:sym(DO) {
- <{IAC}> <command=sym>
- { $*ACTION = DO }
- <negotiation>
- }
- token action:sym(DONT) {
- <{IAC}> <command=sym>
- { $*ACTION = DONT }
- <negotiation>
- }
- proto token negotiation {*}
- token negotiation:sym(SGA)($action) {
- <option=sym>
- {
- given $*ACTION {
- when WILL { $*SUPPRESS-GO-AHEAD = True }
- when WONT { $*SUPPRESS-GO-AHEAD = False }
- when DO { $*SUPPRESS-GO-AHEAD = True }
- when DONT { $*SUPPRESS-GO-AHEAD = False }
- when SB { self.debug: $/, "SUPPRESS-GO-AHEAD does no subnegotiatioddn"> }
- }
- }
- }
- proto token subnegotiation {*}
- token subnegotiation:sym(NAWS) {
- <option=sym>
- <width-upper=<:latin>>
- <width-lower=<:latin>>
- <height-upper=<:latin>>
- <height-lower=<:latin>>
- }
- }
- role Command {
- has TelnetCommand $.command;
- proto method Str(--> Str) { "{IAC.key} {$!command.key} {{*}}" }
- }
- class Negotiation does Command {
- has TelnetOption $.option;
- multi method Str(--> Str) { $!option.key }
- }
- role Subnegotiation does Command {
- has TelnetOption $.option;
- multi method Str(--> Str) { "{$!option.key} {{*}} {SE.key}" }
- }
- class Subnegotiation::NAMS does Subnegotiation {
- has Int $.width;
- has Int $.height;
- method new(
- Str :$option,
- Str :$width-upper,
- Str :$width-lower,
- Str :$height-upper,
- Str :$height-lower
- ) {
- my $option = TelnetOption($sym);
- my $width = $width-upper.ord +< 8 +| $width-lower.ord;
- my $height = $height-upper.ord +< 8 +| $height-lower.ord;
- self.bless: :$option, :$width, :$height;
- }
- multi method Str(--> Str) { "$!width $!height" }
- }
- class Actions {
- method TOP($/) {
- # ???
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement