Protocols¶
x84.server
¶
Package provides base server for x/84.
-
class
x84.server.
BaseServer
[source]¶ Bases:
object
Base class for server implementations.
-
LISTEN_BACKLOG
= 5¶ Number of clients that can wait to be accepted
-
MAX_CONNECTIONS
= 100¶ Maximum number of clients
-
client_factory
= None¶ Client factory should be a class defining what should be instantiated for the client instance.
-
classmethod
client_factory_kwargs
(instance)[source]¶ Return keyword arguments for the client_factory.
Method should be derived and modified, A dictionary may be substituted. The default return value is an empty dictionary.
:rtype dict
-
clients
= {}¶ Dictionary of active clients, (file descriptor, Client, …)
-
clients_ready
(ready_fds=None)[source]¶ Return list of clients with data ready to be receive.
Parameters: ready_fds (list) – file descriptors already known to be ready
-
connect_factory
= None¶ Connect factory should be a class, derived from threading.Thread, that should be instantiated on-connect to perform negotiation and launch the bbs session upon success.
-
classmethod
connect_factory_kwargs
(instance)[source]¶ Return keyword arguments for the connect_factory.
Method should be derived and modified, A dictionary may be substituted. The default return value is an empty dictionary.
:rtype dict
-
env
= {}¶ Dictionary of environment variables received by negotiation
-
threads
= []¶ List of on-connect negotiating threads.
-
x84.client
¶
Base classes for clients and connections of x/84.
-
class
x84.client.
BaseClient
(sock, address_pair, on_naws=None)[source]¶ Bases:
object
Base class for remote client implementations.
Instantiated by the corresponding
BaseServer
class.Class initializer.
-
BLOCKSIZE_RECV
= 64¶ maximum unit of data received for each call to socket_recv()
-
TTYPE_UNDETECTED
= 'unknown'¶ terminal type identifier when not yet negotiated
-
addrport
¶ IP address and port of connection as string (ip:port).
-
get_input
()[source]¶ Receive input from client into
self.recv_buffer
.Should be called conditionally when
input_ready()
returns True.
-
kind
= None¶ Override in subclass: a general string identifier for the connecting protocol (for example, ‘telnet’, ‘ssh’, ‘rlogin’)
-
recv_ready
()[source]¶ Subclass and implement: whether socket_recv() should be called.
:raises NotImplementedError
-
send
()[source]¶ Send any data buffered and return number of bytes send.
Raises: Disconnected – client has disconnected (cannot write to socket).
-
send_unicode
(ucs, encoding='utf8')[source]¶ Buffer unicode string, encoded for client as ‘encoding’.
-
shutdown
()[source]¶ Shutdown and close socket.
Called by event loop after client is marked by
deactivate()
.
-
-
class
x84.client.
BaseConnect
(client)[source]¶ Bases:
threading.Thread
Base class for client connect factories.
Class initializer.
Write data on-connect, callback from
run()
.
-
run
()[source]¶ Negotiate a connecting session.
In the case of telnet and ssh, for example, negotiates and inquires about terminal type, telnet options, window size, and tcp socket options before spawning a new session.
-
stopped
= False¶ whether this thread is completed. Set to
True
to cause an on-connect thread to forcefully exit.
x84.telnet
¶
Telnet server for x84.
Limitations:
- No linemode support, character-at-a-time only.
- No out-of-band / data mark (DM) / sync supported
- No flow control (
^S
,^Q
)
This is a modified version of miniboa retrieved from svn address http://miniboa.googlecode.com/svn/trunk/miniboa which is meant for MUD’s. This server would not be safe for most (linemode) MUD clients.
Changes from miniboa:
- character-at-a-time input instead of linemode
- encoding option on send
- strict rejection of linemode
- terminal type detection
- environment variable support
- GA and SGA
- utf-8 safe
-
class
x84.telnet.
ConnectTelnet
(client)[source]¶ Bases:
x84.client.BaseConnect
Accept new Telnet Connection and negotiate options.
Class initializer.
-
TIME_NEGOTIATE
= 2.5¶ maximum time elapsed allowed to begin on-connect negotiation
-
TIME_POLL
= 0.1¶ polling duration during negotiation
-
TIME_WAIT_STAGE
= 3.5¶ wait upto 3500ms for all stages of negotiation to complete
This method is called after the connection is initiated.
This routine happens to communicate with a wide variety of network scanners when listening on the default port on a public IP address.
-
-
class
x84.telnet.
TelnetClient
(sock, address_pair, on_naws=None)[source]¶ Bases:
x84.client.BaseClient
Represents a remote Telnet Client, instantiated from TelnetServer.
-
SB_MAXLEN
= 65534¶ maximum size of telnet subnegotiation string, allowing for a fairly large value for NEW_ENVIRON.
-
-
class
x84.telnet.
TelnetOption
[source]¶ Bases:
object
Simple class used to track the status of an extended Telnet option.
Attributes and their state values:
local_option
: UNKNOWN (default), True, or False.remote_option
: UNKNOWN (default), True, or False.reply_pending
: True or Fale.
Set attribute defaults on init.
-
class
x84.telnet.
TelnetServer
(config)[source]¶ Bases:
x84.server.BaseServer
Poll sockets for new connections and sending/receiving data from clients.
Create a new Telnet Server.
Parameters: config (ConfigParser.ConfigParser) – configuration section [telnet]
, with options'addr'
,'port'
-
client_factory
¶ alias of
TelnetClient
-
connect_factory
¶ alias of
ConnectTelnet
-
x84.ssh
¶
x84.rlogin
¶
rlogin server for x84.
This only exists to demonstrate alternative client protocols rather than only ssh or telnet. rlogin is a very insecure and not recommended!
-
class
x84.rlogin.
ConnectRLogin
(client)[source]¶ Bases:
x84.client.BaseConnect
rlogin protocol connection handler.
Takes care of the (initial) handshake, terminal and session setup.
Class initializer.
-
TIME_NEGOTIATE
= 5.0¶ maximum time elapsed allowed for on-connect negotiation
-
TIME_POLL
= 0.1¶ poll interval for on-connect negotiation
-
apply_environment
(parsed)[source]¶ Cherry-pick rlogin values into client environment variables.
Parameters: parsed (dict) – values identified by class method parse_connect_data()
Return type: None
-
get_connect_data
()[source]¶ Receive four null-terminated strings transmitted by client on-connect.
Returns: bytes received, containing at least 4 NUL-terminated strings. Return type: str Raises: ValueError – on-connect data timeout or bandwidth exceeded.
-
-
class
x84.rlogin.
RLoginClient
(sock, address_pair, on_naws=None)[source]¶ Bases:
x84.client.BaseClient
rlogin protocol client handler.
-
send
()[source]¶ Send any data buffered and return number of bytes send.
Raises: Disconnected – client has disconnected (cannot write to socket).
-
-
class
x84.rlogin.
RLoginServer
(config)[source]¶ Bases:
x84.server.BaseServer
RLogin/RSH protocol server.
Class initializer.
-
client_factory
¶ alias of
RLoginClient
-
connect_factory
¶ alias of
ConnectRLogin
-