Skip to content

[Daemon] telnet server

Houzuo Guo edited this page Oct 14, 2020 · 6 revisions

Introduction

The plain text telnet server provide access to app commands via rudimentary client software such as telnet, netcat, and HyperTerminal.

The server is capable of operating on both TCP and UDP. Due to the simplicity of underlying protocol, data are exchanged in plain text between client software and this server daemon. See tips below.

Configuration

  1. Construct the following JSON object and place it under JSON key PlainSocketDaemon in configuration file:
Property Type Meaning Default value
TCPPort integer TCP port number to listen to. Use 0 to disable the TCP listener. (This is a mandatory property without a default value)
UDPPort integer UDP port number to listen on. Use 0 to disable the UDP listener. (This is a mandatory property without a default value)
Address string The address network to listen on. "0.0.0.0" - listen on all network interfaces.
PerIPLimit integer Maximum number of times a client (identified by IP) may communicate with the server in a second. 2 - good enough for personal use
  1. Follow command processor to construct configuration for JSON key PlainSocketFilters.

Here is a minimal setup example:

{
    ...

    "PlainSocketDaemon": {
        "TCPPort": 53,
        "UDPPort": 53
    },
    "PlainSocketFilters": {
        "PINAndShortcuts": {
            "Passwords": ["VerySecretPassword"],
            "Shortcuts": {
                "watsup": ".eruntime",
                "EmergencyStop": ".estop",
                "EmergencyLock": ".elock"
            }
        },
        "TranslateSequences": {
            "Sequences": [
                ["#/", "|"]
            ]
        },
        "LintText": {
            "CompressSpaces": false,
            "CompressToSingleLine": false,
            "KeepVisible7BitCharOnly": false,
            "MaxLength": 4096,
            "TrimSpaces": false
        },
        "NotifyViaEmail": {
            "Recipients": ["me@example.com"]
        }
    },

    ...
}

Run

Tell laitos to run chat bot daemon in the command line:

sudo ./laitos -config <CONFIG FILE> -daemons ...,plainsocket,...

Usage

Use any TCP/UDP connection tool such as netcat (also called nc), telnet (TCP only), or HyperTerminal (TCP only) to connect to plain text daemon:

nc <laitos-server-IP> <TCPPort>

And type an app command (the example uses a system shell command to retrieve system uptime):

VerySecretPassword .s uptime
11:09am  up   2:58,  3 users,  load average: 0.23, 0.29, 0.27 (the response)

The UDP socket functions in similar way (the -u switch tells netcat to make UDP connection):

nc -u <laitos-server-IP> <UDPPort>

And type app commands similar to the TCP example.

Tips

  • The plain text daemon helps to invoke app commands in the unlikely event of losing access to all other daemons. The primitive nature of the protocol opens up possibility of eavesdropping, consider using one-time password in place of password.
  • The size of app command and command response are limited to roughly 1200 characters each when using UDP.
  • When using Telnet client program on Linux and Unix, the client program displays (echos) the keyboard input automatically. However on Windows the Telnet program does not display input automatically, to work around it, type Ctrl+] after establishing telnet connection, and then type set localecho to enable input display.
Clone this wiki locally