rcon_hub

package module
v0.0.0-...-5dfbd27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 17 Imported by: 0

README

GitHub issues Docker Pulls GitHub release CircleCI Buy me a coffee

Provides an SSH server that enables rcon connections to configured game servers

Configuration

Create a YAML file named config.yml and place it in the current directory, /etc/rcon-hub, or in a .rcon-hub directory located in your home directory.

Top-level keys of the configuration include:

  • host-key-file : PEM encoded file that will be used for the SSH host key file. If it doesn't exist, an RSA private key file will be created. If not specified, a new one is generated in-memory at startup; however, this will require you remove the known hosts entry on each startup
  • history-size : Size of command history. Default is 100.
  • bind : the host:port where SSH connections are accepted. Default is :2222.

On Windows you can generate a host key file using PuTTY Key Generator and exporting the private key without a password using the "Conversions > Export OpenSSH key" menu.

On Linux you can generate a host key file using ssh-keygen.

Users

One or more users can be declared under the users key with a key-object entry each. The sub-key is the username and object requires:

  • password : the SSH password of the user

Connections

One or more RCON connections can be declared under the connections key with a key-object entry each. The sub-key is the name of the connection that will be used with the hub's connect command. The object requires:

  • address : a host:port declaration of the RCON endpoint
  • password : the RCON password to authenticate with the endpoint
  • auto-disconnect : set to true if you want to disconnect from the connection when detaching

Example

The following example declares one SSH user with the username testing and a password of pw. It also declares a single RCON connection named local-mc that will connect to localhost:25575 with the password minecraft.

users:
  testing:
    password: pw
connections:
  mc:
    address: localhost:25575
    password: minecraft
host-key-file: host_key.pem

Usage

With the configuration described above, start the hub:

rcon-hub

Passing help or --help will display additional command-line options.

Docker Usage

A containerized version is provided at itzg/rcon-hub. It exposes the SSH port at 2222 and declares two volumes:

  • /etc/rcon-hub : this is where the config.yml file is loaded
  • /data : by default the container will write the host key file to /data/host_key.pem, but a pre-generated key file can be mounted at that path

Rather than using the config file, the following environment variables are supported:

  • RH_USER : the username to register for SSH authentication. Default is user.
  • RH_PASSWORD : if specified, a user with username $RH_USER will be registered with the given password
  • RH_CONNECTION : a space delimited list of connection definitions of the form name=password@host:port

For example, the following starts a container with the same user and connection as the YAML file above

docker run -d --name rcon-hub -p 2222:2222 \
  -e RH_USER=testing -e RH_PASSWORD=pw -e RH_CONNECTION=mc=minecraft@localhost:25575 \
  itzg/rcon-hub

To ensure the generated host key persists across restarts, be sure to attach the /data volume, such as with this Docker compose file:

version: "3.7"

services:
  rcon-hub:
    image: itzg/rcon-hub
    environment:
      RH_USER: testing
      RH_PASSWORD: pw
      RH_CONNECTION: mc=minecraft@mc:25575
    ports:
      - 2222:2222
    volumes:
      - rcon-hub:/data
volumes:
  # declare volume with default volume engine
  rcon-hub: {}

A full example is located at examples/docker-compose.yml

Connecting

You can connect to the running hub server using any ssh client and using password authentication, such as:

ssh -p 2222 testing@localhost

Shell usage

Once connected, you interact with a simple shell environment. The help command lists the other commands available within the shell. The command history can be accessed by pressing the up/down arrow keys.

Documentation

Index

Constants

View Source
const (
	ConfigHistorySize = "history-size"
	ConfigBind        = "bind"
	ConfigHostKeyFile = "host-key-file"
	ConfigUser        = "user"
	ConfigPassword    = "password"
	ConfigConnection  = "connection"

	ConnectionFormat = "name=password@host:port"
)
View Source
const (
	ETX = 0x3 // control-C
	EOT = 0x4 // control-D
	BEL = 0x7
	BS  = 0x8
	LF  = 0xa
	CR  = 0xd
	ESC = 0x1b
	CSI = '['
	DEL = 0x7f
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth(config *Config) *Auth

func (*Auth) PasswordHandler

func (a *Auth) PasswordHandler(ctx ssh.Context, password string) bool

type Commander

type Commander struct {
	// contains filtered or unexported fields
}

func NewCommander

func NewCommander(config *Config, shell *Shell) *Commander

func (*Commander) HandleEof

func (c *Commander) HandleEof() error

func (*Commander) Process

func (c *Commander) Process(command string) error

type Config

type Config struct {
	HistorySize int    `mapstructure:"history-size"`
	HostKeyFile string `mapstructure:"host-key-file"`
	Users       map[string]User
	Connections map[string]Connection
}

func LoadConfig

func LoadConfig() (*Config, error)

func (*Config) AddExtraConnection

func (c *Config) AddExtraConnection(s string) error

type Connection

type Connection struct {
	Address        string
	Password       string
	AutoDisconnect bool `mapstructure:"auto-disconnect"`
}

type HostKeyResolver

type HostKeyResolver struct {
	// contains filtered or unexported fields
}

func NewHostKeyResolver

func NewHostKeyResolver(config *Config) *HostKeyResolver

func (*HostKeyResolver) Resolve

func (r *HostKeyResolver) Resolve() string

func (*HostKeyResolver) ResolveOption

func (r *HostKeyResolver) ResolveOption() ssh.Option

type Shell

type Shell struct {
	// contains filtered or unexported fields
}

func NewShell

func NewShell(rw io.ReadWriter, config *Config) *Shell

func (*Shell) Add

func (s *Shell) Add(b byte) error

func (*Shell) AddString

func (s *Shell) AddString(val string) error

func (*Shell) Bell

func (s *Shell) Bell() error

func (*Shell) OutputLine

func (s *Shell) OutputLine(line string) error

func (*Shell) Read

func (s *Shell) Read() (string, error)

Read blocks until the next line of input, such as a command, is available and returns that line. The error will be io.EOF if Control-D was pressed.

func (*Shell) Refresh

func (s *Shell) Refresh() error

func (*Shell) SetPrompt

func (s *Shell) SetPrompt(prompt string)

type SshServer

type SshServer struct {
	// contains filtered or unexported fields
}

func NewSshServer

func NewSshServer(config *Config) *SshServer

func (*SshServer) ListenAndServe

func (s *SshServer) ListenAndServe() error

type User

type User struct {
	Password string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL