-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use library --------- Co-authored-by: naison <895703375@qq.com>
- Loading branch information
1 parent
895fd9c
commit 028cf0a
Showing
40 changed files
with
1,960 additions
and
1,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## TLS Tunnel | ||
## SSH-VPN | ||
|
||
A safety virtual personal network with TLS or DTLS | ||
A safety virtual personal network over SSH and Gvisor |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package cmds | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/wencaiwulue/kubevpn/v2/pkg/util" | ||
|
||
"github.com/wencaiwulue/tlstunnel/pkg/client" | ||
"github.com/wencaiwulue/tlstunnel/pkg/config" | ||
) | ||
|
||
func CmdClient() *cobra.Command { | ||
var mode config.ProxyType | ||
var pacPath string | ||
var extraCIDR []string | ||
var sshConf util.SshConfig | ||
|
||
cmd := &cobra.Command{ | ||
Use: "client", | ||
Short: "client to connect server", | ||
Long: `client to connect server`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
switch mode { | ||
case config.ProxyTypeGlobe: | ||
//if len(remote) == 0 { | ||
// log.Fatal("Globe mode, remote ip should not be empty") | ||
//} | ||
case config.ProxyTypePAC: | ||
if len(pacPath) == 0 { | ||
log.Fatal("PAC mode, PAC path should not be empty") | ||
} | ||
default: | ||
log.Fatal("Not support proxy mode " + mode) | ||
} | ||
ctx, cancelFunc := context.WithCancel(cmd.Context()) | ||
defer cancelFunc() | ||
go func() { | ||
signals := make(chan os.Signal) | ||
signal.Notify(signals, os.Kill, os.Interrupt) | ||
<-signals | ||
cancelFunc() | ||
}() | ||
return client.Connect(ctx, extraCIDR, sshConf) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
cmd.Flags().StringVar((*string)(&mode), "mode", string(config.ProxyTypeGlobe), "Only support mode globe or pac") | ||
_ = cmd.Flags().MarkHidden("mode") | ||
cmd.Flags().StringVar(&pacPath, "pac", "", "The path of PAC, can be a url or local path") | ||
_ = cmd.Flags().MarkHidden("pac") | ||
cmd.Flags().IntVarP(&config.TCPPort, "tcp-port", "t", config.TCPPort, "The tcp port of remote linux server") | ||
cmd.Flags().IntVarP(&config.UDPPort, "udp-port", "u", config.UDPPort, "The udp port of remote linux server") | ||
cmd.Flags().StringArrayVar(&extraCIDR, "extra-cidr", []string{}, "CIDR string, eg: --cidr 192.168.0.159/24 --cidr 192.168.1.160/32") | ||
addSshFlags(cmd, &sshConf) | ||
return cmd | ||
} | ||
|
||
func addSshFlags(cmd *cobra.Command, sshConf *util.SshConfig) { | ||
// for ssh jumper host | ||
cmd.Flags().StringVar(&sshConf.Addr, "ssh-addr", "", "Optional ssh jump server address to dial as <hostname>:<port>, eg: 127.0.0.1:22") | ||
cmd.Flags().StringVar(&sshConf.User, "ssh-username", "", "Optional username for ssh jump server") | ||
cmd.Flags().StringVar(&sshConf.Password, "ssh-password", "", "Optional password for ssh jump server") | ||
cmd.Flags().StringVar(&sshConf.Keyfile, "ssh-keyfile", "", "Optional file with private key for SSH authentication") | ||
cmd.Flags().StringVar(&sshConf.ConfigAlias, "ssh-alias", "", "Optional config alias with ~/.ssh/config for SSH authentication") | ||
cmd.Flags().StringVar(&sshConf.GSSAPIPassword, "gssapi-password", "", "GSSAPI password") | ||
cmd.Flags().StringVar(&sshConf.GSSAPIKeytabConf, "gssapi-keytab", "", "GSSAPI keytab file path") | ||
cmd.Flags().StringVar(&sshConf.GSSAPICacheFile, "gssapi-cache", "", "GSSAPI cache file path, use command `kinit -c /path/to/cache USERNAME@RELAM` to generate") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cmds | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/wencaiwulue/tlstunnel/pkg/config" | ||
"github.com/wencaiwulue/tlstunnel/pkg/server" | ||
) | ||
|
||
func CmdServer() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "server", | ||
Short: "server", | ||
Long: `server`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, cancelFunc := context.WithCancel(cmd.Context()) | ||
defer cancelFunc() | ||
go func() { | ||
signals := make(chan os.Signal) | ||
signal.Notify(signals, os.Kill, os.Interrupt) | ||
<-signals | ||
cancelFunc() | ||
}() | ||
return server.Serve(ctx, config.TCPPort, config.UDPPort) | ||
}, | ||
SilenceUsage: true, | ||
} | ||
cmd.Flags().IntVarP(&config.TCPPort, "tcp-port", "t", config.TCPPort, "server listen tcp port") | ||
cmd.Flags().IntVarP(&config.UDPPort, "udp-port", "u", config.UDPPort, "server listen udp port") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
_ "net/http/pprof" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/wencaiwulue/tlstunnel/cmd/cmds" | ||
) | ||
|
||
func main() { | ||
cmd := NewTunnelCommand() | ||
logrus.SetLevel(logrus.DebugLevel) | ||
cmd.AddCommand( | ||
cmds.CmdServer(), | ||
cmds.CmdClient(), | ||
) | ||
_ = cmd.ExecuteContext(context.Background()) | ||
} | ||
|
||
func NewTunnelCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "tunnel", | ||
Short: "connect to remote network", | ||
Long: ` | ||
connect to remote network. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.