vncproxy

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: MIT Imports: 10 Imported by: 1

README

go-vncproxy

A tiny vnc websocket proxy written by golang supports noVNC client.

Feature

  • Token handler: like websockify, you can customlize the token handler to access multiple vnc backends by a single proxy instance.
  • Authentication: it depends on your vnc servers, since the proxy just copy the stream of both clients and servers.

Usage

package main

import (
	"net/http"

	"github.com/evangwt/go-vncproxy"

	"github.com/gin-gonic/gin"
	"golang.org/x/net/websocket"
)

func main() {
	r := gin.Default()

	vncProxy := NewVNCProxy()
	r.GET("/ws", func(ctx *gin.Context) {
		h := websocket.Handler(vncProxy.ServeWS)
		h.ServeHTTP(ctx.Writer, ctx.Request)
	})

	if err := r.Run(); err != nil {
		panic(err)
	}
}

func NewVNCProxy() *vncproxy.Proxy {
	return vncproxy.New(&vncproxy.Config{
		LogLevel: vncproxy.DebugLevel,
		TokenHandler: func(r *http.Request) (addr string, err error) {
      		// validate token and get forward vnc addr
      		// ...
      		addr = ":5901"
      		return
		},
	})
}

Documentation

Index

Constants

View Source
const (
	InfoFlag  uint32 = 0x1 << 0
	DebugFlag uint32 = 0x1 << 1

	InfoLevel  uint32 = InfoFlag
	DebugLevel uint32 = InfoFlag | DebugFlag
)

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(level uint32, instance Logger) *logger

func NewPeer

func NewPeer(ws *websocket.Conn, addr string, dialTimeout time.Duration) (*peer, error)

Types

type Config

type Config struct {
	LogLevel    uint32
	Logger      Logger
	DialTimeout time.Duration
	TokenHandler
}

Config represents vnc proxy config

type Logger added in v1.1.0

type Logger interface {
	Infof(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}

type Proxy

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

Proxy represents vnc proxy

func New

func New(conf *Config) *Proxy

New returns a vnc proxy If token handler is nil, vnc backend address will always be :5901

func (*Proxy) Peers

func (p *Proxy) Peers() map[*peer]struct{}

func (*Proxy) ServeWS

func (p *Proxy) ServeWS(ws *websocket.Conn)

ServeWS provides websocket handler

type TokenHandler

type TokenHandler func(r *http.Request) (addr string, err error)

Jump to

Keyboard shortcuts

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