sshooks

package module
v0.0.0-...-6791d54 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2017 License: MIT Imports: 13 Imported by: 1

README

Build Status Coverage Status Go Report Card

sshooks - React to ssh commands

API

struct SSHKeygenConfig
type SSHKeygenConfig struct {
	// Default to rsa
	Type string
	// Default to no password (empty string)
	Passphrase string
}
struct ServerConfig
type ServerConfig struct {
	// Default to localhost
	Host              string
	Port              uint
	PrivatekeyPath    string
	PublicKeyCallback func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)
	KeygenConfig      SSHKeygenConfig
	CommandsCallbacks map[string]func(args string) error
    // Logger based on the interface defined in sshooks/log
 	Log               log.Log
}
func Listen
func Listen(config *ServerConfig)

Example

In this example we setup a server responding to the command git-upload-pack commands (e.g: sent by git clone ssh://git@localhost:1337/dgellow/nanogit.git). You can read the example program for more details.

func publicKeyHandler(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
    // Do something with the public key
	return &ssh.Permissions{}, nil
}

func handleUploadPack(args string) error {
    // Do something with the args
	return nil
}

func main() {
	logger = &Logger{LogLevel: 0, Prefix: "example"}

	commandsHandlers := map[string]func (string) error {
		"git-upload-pack": handleUploadPack,
	}

	config := &sshooks.ServerConfig{
		Host:              "localhost",
		Port:              1337,
		PrivatekeyPath:    "key.rsa",
		KeygenConfig:      sshooks.SSHKeygenConfig{"rsa", ""},
		PublicKeyCallback: publicKeyHandler,
		CommandsCallbacks: commandsHandlers,
        Log:               logger,
	}

	sshooks.Listen(config)

	// Keep the program running
	for {
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecCmd

func ExecCmd(cmdName string, args ...string) (string, string, error)

func FileExists

func FileExists(path string) bool

func Listen

func Listen(config *ServerConfig) error

Starts an SSH server on given port

func UIntToStr

func UIntToStr(i uint) string

Types

type SSHKeygenConfig

type SSHKeygenConfig struct {
	// Default to rsa
	Type string
	// Default to no password (empty string)
	Passphrase string
}

type ServerConfig

type ServerConfig struct {
	// Default to localhost
	Host              string
	Port              uint
	PrivatekeyPath    string
	PublicKeyCallback func(conn ssh.ConnMetadata, key ssh.PublicKey) (keyId string, err error)
	KeygenConfig      SSHKeygenConfig
	CommandsCallbacks map[string]func(keyId string, cmd string, args string) (*exec.Cmd, error)
	// Logger based on the interface defined in sshooks/log
	Log log.Log
}

func (*ServerConfig) Validate

func (sc *ServerConfig) Validate() error

type Session

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

func (*Session) Run

func (s *Session) Run()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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