Giter Club home page Giter Club logo

sshooks's Introduction

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 {
	}
}

sshooks's People

Contributors

dgellow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.