pinggy

package module
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeFile

func ServeFile(path string)

Serve content of the `path` via pinggy as a http server.

func ServeFileWithConfig

func ServeFileWithConfig(conf FileServerConfig)

Serve files as http.

func ServeFileWithToken

func ServeFileWithToken(token string, path string)

Serve content of the `path` via pinggy with token.

Types

type Config

type Config struct {
	/*
		Token is a string. It identify an user. You can find a token at the https://dashboard.pinggy.io.
		Token is required to connect in TCP and TLS tunnel.
	*/
	Token string

	/*
		Tunnel type. It can be one of TCP or TLS or HTTP or empty.
		Both type and altType cannot be empty.
	*/
	Type TunnelType

	/*
		Alternate AltTunnelType. It can be UDP or empty. However,
		both type and altType cannot be empty. As of now only one of
		them can be populated.
	*/
	AltType UDPTunnelType

	/*
		This module log several thing. We use the Logger for this task. If Logger is `nil`, we use the default Logger.
	*/
	Logger *log.Logger

	/*
		Pinggy supports ssh over ssl when user is behind a firewall which does not allow anything but ssl.
		Simply enable this flag and this package would take care of this problem.
	*/
	SshOverSsl bool

	/*
		Pinggy server to connect to. Default value `a.pinggy.io`
		Users are discouraged to use this.
	*/
	Server string

	/*
		Automatically forward connection to this address. Keep empty to disable it.
	*/
	TcpForwardingAddr string

	/*
		Automatically forward udp packet to this address. Keep empty to disable it.
	*/
	UdpForwardingAddr string

	/*
		IP Whitelist
	*/
	IpWhiteList []*net.IPNet

	/*
		Configure Header Manipulation, Basic auth, and Bearer auth for HTTP tunnels.
		The configuration will be ignored for tunnels other than HTTP tunnels.
	*/
	HeaderManipulationAndAuth *HttpHeaderManipulationAndAuthConfig

	/*
		Remote command output writer. By default it would be a instance of io.Discard.

		One need to be carefull while using these file. There is a fixed amount of
		buffering that is shared for the two streams. If either blocks it may
		eventually cause the remote command to block.
	*/
	Stdout io.Writer
	Stderr io.Writer

	// Timeout is the maximum amount of time for the TCP connection to establish.
	//
	// A Timeout of zero means no timeout.
	Timeout time.Duration

	/*
		Force login.
	*/
	Force bool

	/*
		ServerConnection to be used to setup ssh connection. Proxy configuration
		won't be effective here.

		Keep it nil unless you know what you are doing.
	*/
	ServerConnection net.Conn

	/*
		Proxy url. it wii be used to connect to the server.
	*/
	Proxy *url.URL
	// contains filtered or unexported fields
}

type FileServerConfig

type FileServerConfig struct {
	/*
		Pinggy tunnel config. check pinggy config for more details.
	*/
	TunnelConf Config

	/*
		Local directory path. The server would list all the file inside the directory.
		The pathe would be used only if `Fs` is nil.
	*/
	Path string

	/*
		A file system object. It can initiated by `os.DirFS(path)`. However, it can be a
		simple object with implements the `fs.FS` interface. Pinggy util module implements
		one such object.
	*/
	Fs fs.FS

	/*
		Whether pinggy webdebug is enabled or not. Kindly provide valid port to enable it.
	*/
	WebDebugEnabled bool

	/*
		The port where pinggy webdebug would listen.
		If you provide port at 8080, you can access the debugg ui at localhost:8080
	*/
	WebDebugPort int
}

Configuration for a simple http file server. This struct can be used to create simple file server using pinggy.

type HeaderManipulationInterface added in v0.6.5

type HeaderManipulationInterface interface {
	AddBasicAuth(username, password string)
	AddBearerAuth(key string)
	SetHostname(hostname string)
	RemoveHeader(headerName string) bool
	RemoveHeaderValue(headerName, headerValue string)
	AppendHeaderValue(headerName, headerValue string)
	RemoveHeaderManipulation(headerName string)
	ListHeaderManipulations() []byte
	ReconstructHeaderManipulationDataFromJson([]byte) error
	SetXFFHeader(xff string)
	SetHttpsOnly(val bool)
	SetFullUrl(val bool)
}

type HttpHeaderManipulationAndAuthConfig added in v0.6.5

type HttpHeaderManipulationAndAuthConfig struct {
	/*
		New value for the `Host` Header. It is special header.
	*/
	HostName string `json:"hostName"`

	/*
		Request Header modification info.
	*/
	Headers map[string]*PinggyHttpHeaderInfo `json:"headers"`

	/*
		List of base64 encoded basic auth info.
	*/
	BasicAuths map[string]bool `json:"basicAuths"`

	/*
		List of keys for bearer authentication
	*/
	BearerAuths map[string]bool `json:"bearerAuths"`

	/*
		The XFF header name. The server would set the header with value containing
		original source. It is expected to set X-Forwarded-For header. However, users
		allowed to use any header they want.
	*/
	XFF string `json:"xff"` //header name. empty means not do not set

	/*
		Enable https only mode. You will keep getting http url. However, those url would redirected to
		https counter part via 301.
	*/
	HttpsOnly bool `json:"httpsOnly"` //All the http would be redirected

	/*
		In case user wants to know the original url of the request, pinggy can provide the same if user
		enable this option. Pinggy would add a new header `X-Pinggy-Url` which contains the original
		url. It may not contain the query string part of the url.
	*/
	FullRequestUrl bool `json:"fullRequestUrl"` //Will add X-Pinggy-Url to add entire url

}

func NewHeaderManipulationAndAuthConfig added in v0.6.5

func NewHeaderManipulationAndAuthConfig() *HttpHeaderManipulationAndAuthConfig

New HeaderManipulationAndConfig struct. This is a safe way create the object

func (*HttpHeaderManipulationAndAuthConfig) AddBasicAuth added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) AddBasicAuth(username, password string)

Add username password, basic authentication. One can add more than one username password. Along with bearer auth.

func (*HttpHeaderManipulationAndAuthConfig) AddBearerAuth added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) AddBearerAuth(key string)

Add bearer key authentication. It would enable the bearer authentication mode. It can be use along with username password authentication.

func (*HttpHeaderManipulationAndAuthConfig) AddHeader added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) AddHeader(headerName, headerValue string) error

Add header to the http request. It would not remove same existing header.

func (*HttpHeaderManipulationAndAuthConfig) RemoveHeader added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) RemoveHeader(headerName string) error

Remove a particular header from the http request.

func (*HttpHeaderManipulationAndAuthConfig) SetHostname added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) SetHostname(hostname string)

Set hostname.

func (*HttpHeaderManipulationAndAuthConfig) UpdateHeader added in v0.6.5

func (hmd *HttpHeaderManipulationAndAuthConfig) UpdateHeader(headerName, headerValue string) error

Update a header. It would remove existing header and append new headers. It would append new headers even if same header does not exists.

type PinggyHttpHeaderInfo added in v0.6.5

type PinggyHttpHeaderInfo struct {
	/*
		Header name. Case insensitive
		Key can be any header name. However, host is not allowed here.
	*/
	Key string `json:"headerName"`

	/*
		Whether or not to remove existing headers
	*/
	Remove bool `json:"remove"`

	/*
		New Values for the header. If Remove is false, new headers
		would be added again.
	*/
	NewValues []string `json:"values"`
}

type PinggyListener

type PinggyListener interface {
	net.Listener
	net.PacketConn

	/*
		Return the remote urls to access the tunnels.
	*/
	RemoteUrls() []string

	/*
		Start webdebugger. This can not be called more than once.
		Once the debugger started, it cannot be closed.
		The webdebugger only available for `http` tunnels.
	*/
	InitiateWebDebug(addr string) error

	/*
		Start a webserver.
	*/
	ServeHttp(fs fs.FS) error

	/*
		Forward tcp tunnel to this new address.
	*/
	UpdateTcpForwarding(addr string) error

	/*
		Forward tcp tunnel to this new address.
	*/
	UpdateUdpForwarding(addr string) error

	/*
		Start forwarding. It would work only if
		Forwarding address is present
	*/
	StartForwarding() error

	/*
		Dial a connection to tunnel server. It can be useful to get various infomation without starting webdebugger.
		One can acheive exact same result with a webdebugger as well.
	*/
	Dial() (net.Conn, error)

	/*
		Receive usages update. Server would provide updates when it has any. You can set only one update listener.
		Set update listener with nil to stop listening
	*/
	SetUsagesUpdateListener(usagesUpdate PinggyUsagesUpdateListener) error

	/*
		It would wait till the server has any update. It would provide only one update.
	*/
	LongPollUsages() (string, error)

	/*
		This would provide the current usages without waiting.
	*/
	GetCurUsages() (string, error)
}

func Connect

func Connect(typ TunnelType) (PinggyListener, error)

Connect to pinggy service and receive a PinggyListener object. This function does not take any argument. So, it creates an annonymous tunnel with HTTP.

func ConnectUdp

func ConnectUdp(token string) (PinggyListener, error)

Create a UDP Tunnel. One have to use ReadFrom and WriteTo method to receive and send datagram. This tunnel is unreliable.

One can not send to any arbitary address. One can only reply to a address when it receives an datagram from that address.

func ConnectWithConfig

func ConnectWithConfig(conf Config) (PinggyListener, error)

Create tunnel with config.

func ConnectWithToken

func ConnectWithToken(token string, typ TunnelType) (PinggyListener, error)

Same as Connect() func, however it require a token. Token can be found at Pinggy Dashboard (dashboard.pinggy.io). One can pass empty string as token as well.

type PinggyUsagesUpdateListener added in v0.6.5

type PinggyUsagesUpdateListener interface {
	Update(line string)
}

type TunnelType

type TunnelType string
const (
	TCP    TunnelType = "tcp"
	TLS    TunnelType = "tls"
	HTTP   TunnelType = "http"
	TLSTCP TunnelType = "tlstcp"
)

type UDPTunnelType

type UDPTunnelType string
const (
	UDP UDPTunnelType = "udp"
)

Jump to

Keyboard shortcuts

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