cmd

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Index

Constants

This section is empty.

Variables

View Source
var ForwardCmd = &cobra.Command{
	Use:   "forward -f <address:port> [flags] -t <address:port> [flags]",
	Short: "Proxy a locally accessible address to a remote address port",
	RunE: func(cmd *cobra.Command, args []string) error {
		pflags.Parse()

		tunnel := newTunnel()
		s := server.NewSSHTunnelServer(tunnel)

		ms := cores.NewPuzzleCore(
			cores.WithService("Ssh-Proxy"),
			grpcuipuzzle.WithCoreGrpcUI(),
			grpcpuzzle.WithCoreGrpcPuzzle(func(srv *grpc.Server) {
				sshtunnelpb.RegisterSshTunnelServer(srv, s)
			}),
			cores.WithDaemonWorker(func(ctx context.Context) error {
				in := &sshtunnelpb.ConnectRequest{
					Local:  localAddr,
					Remote: remoteAddr,
				}

				if strings.HasPrefix(in.Local, ":") {
					in.Local = "0.0.0.0" + in.Local
				}

				if strings.HasPrefix(in.Remote, ":") {
					in.Remote = "0.0.0.0" + in.Remote
				}

				resp, err := s.Forward(ctx, in)
				if err != nil {
					return err
				}

				table := make(map[string][]string)
				table[resp.Uuid] = append(
					table[resp.Uuid],
					[]string{string(server.Forward), fmt.Sprintf("%v -> %v", localAddr, remoteAddr)}...,
				)
				plog.Infof(prettyMaps(table))

				<-ctx.Done()
				tunnel.Close()
				return nil
			}),
		)
		return cores.Start(ms, port())
	},
}

ForwardCmd represents the connect command

View Source
var ReverseCmd = &cobra.Command{
	Use:   "reverse -r <address:port> [flags] -l <address:port> [flags]",
	Short: "Proxy a remote accessible address to a local address port",

	RunE: func(cmd *cobra.Command, args []string) error {
		pflags.Parse()

		tunnel := newTunnel()
		s := server.NewSSHTunnelServer(tunnel)

		ms := cores.NewPuzzleCore(
			cores.WithService("Ssh-Proxy"),
			grpcuipuzzle.WithCoreGrpcUI(),
			grpcpuzzle.WithCoreGrpcPuzzle(func(srv *grpc.Server) {
				sshtunnelpb.RegisterSshTunnelServer(srv, s)
			}),
			cores.WithDaemonWorker(func(ctx context.Context) error {
				in := &sshtunnelpb.ConnectRequest{
					Local:  localAddr,
					Remote: remoteAddr,
				}

				if strings.HasPrefix(in.Local, ":") {
					in.Local = "0.0.0.0" + in.Local
				}

				if strings.HasPrefix(in.Remote, ":") {
					in.Remote = "0.0.0.0" + in.Remote
				}

				resp, err := s.Reverse(ctx, in)
				if err != nil {
					return err
				}

				table := make(map[string][]string)
				table[resp.Uuid] = append(
					table[resp.Uuid],
					[]string{string(server.Reverse), fmt.Sprintf("%v -> %v", remoteAddr, localAddr)}...,
				)
				plog.Infof(prettyMaps(table))

				<-ctx.Done()
				tunnel.Close()
				return nil
			}),
		)

		return cores.Start(ms, port())
	},
}

ReverseCmd represents the list command

Functions

This section is empty.

Types

type ConnectionProfile

type ConnectionProfile struct {
	EnvName string
	Host    *sshtunnel.SshConfig
}

func (*ConnectionProfile) PopulateDefault

func (cp *ConnectionProfile) PopulateDefault(identityFile string)

func (*ConnectionProfile) Validate

func (cp *ConnectionProfile) Validate() error

Jump to

Keyboard shortcuts

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