command_tunnel

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TunnelCmd = &cobra.Command{
	Use: `tunnel <protocol> <port> <name>

  protocol      The type of endpoint, either http or https.
  port          The port to tunnel to.
  name          The name of the tunnel.
`,
	Short: "Manage a tunnel",
	Long: `The tunnel command allows you to create a tunnel to expose a local port on the internet.

The tunnel can be created to expose either an http or https endpoint, the name provided is prepended with the username e.g. <user>--<tunnel_name>.<domain>.`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		viper.BindPFlag("client.server", cmd.PersistentFlags().Lookup("server"))
		viper.BindEnv("client.server", config.CONFIG_ENV_PREFIX+"_SERVER")

		viper.BindPFlag("client.token", cmd.PersistentFlags().Lookup("token"))
		viper.BindEnv("client.token", config.CONFIG_ENV_PREFIX+"_TOKEN")

		viper.BindPFlag("tls_skip_verify", cmd.Flags().Lookup("tls-skip-verify"))
		viper.BindEnv("tls_skip_verify", config.CONFIG_ENV_PREFIX+"_TLS_SKIP_VERIFY")
		viper.SetDefault("tls_skip_verify", true)
	},
	Args: cobra.ExactArgs(3),
	Run: func(cmd *cobra.Command, args []string) {

		if args[0] != "http" && args[0] != "https" {
			cobra.CheckErr("Invalid protocol type, must be either http or https")
		}

		port, err := strconv.Atoi(args[1])
		if err != nil {
			cobra.CheckErr("Invalid port number, port numbers must be between 1 and 65535")
		}

		if !validate.Name(args[2]) {
			cobra.CheckErr("Invalid name, must be all lowercase and only contain letters, numbers and dashes")
		}

		cfg := config.GetServerAddr()
		tunnel_server.ConnectAndForward(cfg.WsServer, args[0], uint16(port), args[2], cmd.Flag("hostname").Value.String())

		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, syscall.SIGTERM)

		<-c

		agent_client.Shutdown()
		fmt.Println("\r")
		log.Info().Msg("tunnel: shutdown")
		os.Exit(0)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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