Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
blacknon committed Aug 13, 2024
1 parent 01331e2 commit 9b57fd8
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 2 deletions.
42 changes: 40 additions & 2 deletions cmd/lssh/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ USAGE:
app.Version = "0.6.12"

// TODO(blacknon): オプションの追加
// -m ... NFSマウントで、リモートホストの特定ディレクトリをローカルにマウント可能にする (v0.7.0)
// -M ... リバースNFSマウントで、リモートホストの特定ディレクトリをローカルにマウント可能にする (v0.7.0)
// -n ... NFSマウントで、リモートホストの特定ディレクトリをローカルにマウント可能にする (v0.7.0)
// -m ... リバースNFSマウントで、リモートホストの特定ディレクトリをローカルにマウント可能にする (v0.7.0)
// -f ... バックグラウンドでの接続(X11接続やport forwardingをバックグラウンドで実行する場合など)。
// 「ssh -f」と同じ。 (v0.7.0)
// (https://github.com/sevlyar/go-daemon)
Expand All @@ -85,6 +85,8 @@ USAGE:
cli.StringFlag{Name: "D", Usage: "Dynamic port forward mode(Socks5). Specify a `port`. Only single connection works."},
cli.StringFlag{Name: "d", Usage: "HTTP Dynamic port forward mode. Specify a `port`. Only single connection works."},
cli.StringFlag{Name: "r", Usage: "HTTP Reverse Dynamic port forward mode. Specify a `port`. Only single connection works."},
cli.StringFlag{Name: "n", Usage: "NFS Dynamic forward mode. Specify a `port:/path/to/remote`. Only single connection works."},
cli.StringFlag{Name: "m", Usage: "NFS Reverse Dynamic forward mode. Specify a `port:/path/to/local`. Only single connection works."},

// Other bool
cli.BoolFlag{Name: "w", Usage: "Displays the server header when in command execution mode."},
Expand Down Expand Up @@ -236,6 +238,36 @@ USAGE:
}
}

// Set NFS Forwarding
nfsForwarding := c.String("n")
if nfsForwarding != "" {
port, path, err := common.ParseNFSForwardPortPath(nfsForwarding)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}

path = common.GetFullPath(path)

r.NFSDynamicForwardPort = port
r.NFSDynamicForwardPath = path
}

// Set NFS Reverse Forwarding
nfsReverseForwarding := c.String("m")
if nfsReverseForwarding != "" {
port, path, err := common.ParseNFSForwardPortPath(nfsReverseForwarding)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}

path = common.GetFullPath(path)

r.NFSReverseDynamicForwardPort = port
r.NFSReverseDynamicForwardPath = path
}

// if err
if err != nil {
fmt.Printf("Error: %s \n", err)
Expand All @@ -256,6 +288,12 @@ USAGE:
// HTTP Reverse Dynamic port forwarding port
r.HTTPReverseDynamicPortForward = c.String("r")

// NFS Dynamic forwarding port
// r.NFSDynamicPortForward = c.String("n")

// NFS Reverse Dynamic forwarding port
// r.NFSReverseDynamicPortForward = c.String("m")

r.Start()
return nil
}
Expand Down
13 changes: 13 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ func ParseForwardPort(value string) (local, remote string, err error) {
return
}

func ParseNFSForwardPortPath(value string) (port, path string, err error) {
data := strings.Split(value, ":")
if len(data) != 2 {
err = errors.New("Could not parse.")
return
}

port = data[0]
path = data[1]

return
}

// ParseHostPath return host and path, from host:/path/to/dir/file.
func ParseHostPath(value string) (host []string, path string) {
if !strings.Contains(value, ":") {
Expand Down
16 changes: 16 additions & 0 deletions conf/conf_struct_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ type ServerConfig struct {
// ex.) "11080"
HTTPReverseDynamicPortForward string `toml:"http_reverse_dynamic_port_forward"`

// NFS Dynamic Forward port setting
// ex.) "12049"
NFSDynamicForwardPort string `toml:"nfs_dynamic_forward"`

// NFS Dynamic Forward path setting
// ex.) "/path/to/remote"
NFSDynamicForwardPath string `toml:"nfs_dynamic_forward_path"`

// NFS Reverse Dynamic Forward port setting
// ex.) "12049"
NFSReverseDynamicForwardPort string `toml:"nfs_reverse_dynamic_forward"`

// NFS Reverse Dynamic Forward path setting
// ex.) "/path/to/local"
NFSReverseDynamicForwardPath string `toml:"nfs_reverse_dynamic_forward_path"`

// x11 forwarding setting
X11 bool `toml:"x11"`

Expand Down
14 changes: 14 additions & 0 deletions ssh/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ func (r *Run) cmd() (err error) {
go c.HTTPReverseDynamicForward("localhost", config.HTTPReverseDynamicPortForward)
}

// NFS Dynamic Forward
if r.NFSDynamicForwardPort != "" && r.NFSDynamicForwardPath != "" {
config.NFSDynamicForwardPort = r.NFSDynamicForwardPort
config.NFSDynamicForwardPath = r.NFSDynamicForwardPath
go c.NFSForward("localhost", config.NFSDynamicForwardPort, config.NFSDynamicForwardPath)
}

// NFS Reverse Dynamic Forward
if r.NFSReverseDynamicForwardPath != "" && r.NFSReverseDynamicForwardPath != "" {
config.NFSReverseDynamicForwardPort = r.NFSReverseDynamicForwardPort
config.NFSReverseDynamicForwardPath = r.NFSReverseDynamicForwardPath
go c.NFSReverseForward("localhost", config.NFSReverseDynamicForwardPort, config.NFSReverseDynamicForwardPath)
}

// if tty
if r.IsTerm {
c.Stdin = os.Stdin
Expand Down
36 changes: 36 additions & 0 deletions ssh/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"golang.org/x/crypto/ssh/terminal"
)

// TOOD(blacknon): なんかProxyのポートが表示おかしいので、修正する(v0.7.0)

// TODO(blacknon): 自動再接続機能の追加(v1.0.0)
// autosshのように、接続が切れた際に自動的に再接続を試みる動作をさせたい
// パラメータでの有効・無効指定が必要になる。
Expand Down Expand Up @@ -95,6 +97,22 @@ type Run struct {
// set remotehost port num (ex. 11080).
HTTPReverseDynamicPortForward string

// NFS Dynamic Forward
// set localhost port num (ex. 12049).
NFSDynamicForwardPort string

// NFS Dynamic Forward Path
// set remotehost path (ex. /path/to/remote).
NFSDynamicForwardPath string

// NFS Reverse Dynamic Forward
// set remotehost port num (ex. 12049).
NFSReverseDynamicForwardPort string

// NFS Reverse Dynamic Forward Path
// set localhost path (ex. /path/to/local).
NFSReverseDynamicForwardPath string

// Exec command
ExecCmd []string

Expand Down Expand Up @@ -263,6 +281,24 @@ func (r *Run) printHTTPReverseDynamicPortForward(port string) {
}
}

// printNFSDynamicForward is printout forwarding.
// use ssh command run header. only use shell().
func (r *Run) printNFSDynamicForward(port, path string) {
if port != "" {
fmt.Fprintf(os.Stderr, "NFSDynamicForward:%s:%s\n", port, path)
fmt.Fprintf(os.Stderr, " %s\n", "connect NFS.")
}
}

// printNFSReverseDynamicForward is printout forwarding.
// use ssh command run header. only use shell().
func (r *Run) printNFSReverseDynamicForward(port, path string) {
if port != "" {
fmt.Fprintf(os.Stderr, "NFSReverseDynamicForward:%s:%s\n", port, path)
fmt.Fprintf(os.Stderr, " %s\n", "connect NFS.")
}
}

// printProxy is printout proxy route.
// use ssh command run header. only use shell().
func (r *Run) printProxy(server string) {
Expand Down
30 changes: 30 additions & 0 deletions ssh/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ func (r *Run) shell() (err error) {
config.HTTPReverseDynamicPortForward = r.HTTPReverseDynamicPortForward
}

// OverWrite nfs dynacmic forwarding
if r.NFSDynamicForwardPort != "" {
config.NFSDynamicForwardPort = r.NFSDynamicForwardPort
}

// OverWrite nfs dynamic path
if r.NFSDynamicForwardPath != "" {
config.NFSDynamicForwardPath = r.NFSDynamicForwardPath
}

// OverWrite nfs reverse dynamic forwarding
if r.NFSReverseDynamicForwardPort != "" {
config.NFSReverseDynamicForwardPort = r.NFSReverseDynamicForwardPort
}

// OverWrite nfs reverse dynamic path
if r.NFSReverseDynamicForwardPath != "" {
config.NFSReverseDynamicForwardPath = r.NFSReverseDynamicForwardPath
}

// OverWrite local bashrc use
if r.IsBashrc {
config.LocalRcUse = "yes"
Expand Down Expand Up @@ -131,6 +151,16 @@ func (r *Run) shell() (err error) {
go connect.HTTPReverseDynamicForward("localhost", config.HTTPReverseDynamicPortForward)
}

// NFS Dynamic Forwarding
if config.NFSDynamicForwardPort != "" && config.NFSDynamicForwardPath != "" {
go connect.NFSForward("localhost", config.NFSDynamicForwardPort, config.NFSDynamicForwardPath)
}

// NFS Reverse Dynamic Forwarding
if config.NFSReverseDynamicForwardPort != "" && config.NFSReverseDynamicForwardPath != "" {
go connect.NFSReverseForward("localhost", config.NFSReverseDynamicForwardPort, config.NFSReverseDynamicForwardPath)
}

// switch check Not-execute flag
// TODO(blacknon): Backgroundフラグを実装したら追加
switch {
Expand Down

0 comments on commit 9b57fd8

Please sign in to comment.