Skip to content

Commit

Permalink
Merge pull request #6 from suutaku/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
suutaku authored May 24, 2022
2 parents c7e5bd7 d45fb19 commit d59f6e0
Show file tree
Hide file tree
Showing 32 changed files with 1,065 additions and 1,396 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 2,3 @@
./signaling
./sshx
./sshx-linux

sshx
1 change: 1 addition & 0 deletions cmd/sshx/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 8,7 @@ import (
func cmdDaemon(cmd *cli.Cmd) {
cmd.Action = func() {
n := node.NewNode(getRootPath())
defer n.Stop()
n.Start()
}
}
1 change: 1 addition & 0 deletions cmd/sshx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@ func main() {
app.Command("proxy", "start proxy", cmdProxy)
app.Command("status", "get status", cmdStatus)
app.Command("fs", "sshfs filesystem", cmdSSHFS)
app.Command("vnc", "vnc service", cmdVNCService)
app.Run(os.Args)

}
32 changes: 10 additions & 22 deletions cmd/sshx/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 5,17 @@ import (

cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/conf"
"github.com/suutaku/sshx/pkg/impl"
"github.com/suutaku/sshx/pkg/types"
)

func cmdStopProxy(cmd *cli.Cmd) {
cmd.Spec = "PID"
pairId := cmd.StringArg("PID", "", "Connection pair id which can found by using status command")
cmd.Action = func() {
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewProxyImpl()
param := impl.ImplParam{
Config: *cm.Conf,
PairId: *pairId,
}
dialer.Init(param)
dialer.Close()
sender := impl.NewSender(&impl.Proxy{}, types.OPTION_TYPE_DOWN)
sender.PairId = []byte(*pairId)
sender.SendDetach()
}
}

Expand All @@ -37,22 32,15 @@ func cmdStartProxy(cmd *cli.Cmd) {
if addr == nil || *addr == "" {
fmt.Println("please set a remote device")
}
fmt.Println("Press Ctrl C to close proxy")

cm := conf.NewConfManager(getRootPath())
dialer := impl.NewProxyImpl()
proxy := impl.NewProxy(int32(*proxyPort), *addr)
proxy.Preper()

// init dialer
param := impl.ImplParam{
Config: *cm.Conf,
HostId: *addr,
}
dialer.Init(param)
dialer.SetProxyPort(int32(*proxyPort))
if err := dialer.Dial(); err != nil {
logrus.Debug(err)
sender := impl.NewSender(proxy, types.OPTION_TYPE_UP)
_, err := sender.SendDetach()
if err != nil {
logrus.Error(err)
}

}
}

Expand Down
24 changes: 7 additions & 17 deletions cmd/sshx/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 3,8 @@ package main
import (
cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/conf"
"github.com/suutaku/sshx/pkg/impl"
"github.com/suutaku/sshx/pkg/types"
)

func cmdCopy(cmd *cli.Cmd) {
Expand All @@ -19,28 19,18 @@ func cmdCopy(cmd *cli.Cmd) {
if destPath == nil || *destPath == "" {
return
}
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewScpImpl()

// init dialer
param := impl.ImplParam{
Config: *cm.Conf,
}
dialer.Init(param)

err := dialer.ParsePaths(*srcPath, *destPath)
imp := impl.NewSCP(*srcPath, *destPath, *ident)
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
// parse client option
dialer.PrivateKeyOption(*ident)
logrus.Debug("cmd connect")
err = dialer.Dial()
sender := impl.NewSender(imp, types.OPTION_TYPE_UP)
_, err = sender.Send()
if err != nil {
logrus.Info(err)
logrus.Error(err)
return
}
dialer.Close()

}
}
50 changes: 13 additions & 37 deletions cmd/sshx/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 3,8 @@ package main
import (
cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/conf"
"github.com/suutaku/sshx/pkg/impl"
"github.com/suutaku/sshx/pkg/types"
)

func cmdCopyId(cmd *cli.Cmd) {
Expand All @@ -14,30 14,19 @@ func cmdCopyId(cmd *cli.Cmd) {
if addr == nil || *addr == "" {
return
}
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewSshImpl()

// init dialer
param := impl.ImplParam{
Config: *cm.Conf,
}
dialer.Init(param)

// parse user name
err := dialer.DecodeAddress(*addr)
imp := impl.NewSSH(*addr, false, "", false)
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
dialer.CopyId()
// parse client option
logrus.Debug("cmd connect")
err = dialer.Dial()
sender := impl.NewSender(imp, types.OPTION_TYPE_UP)
conn, err := sender.Send()
if err != nil {
logrus.Info(err)
logrus.Error(err)
return
}
dialer.Close()
imp.OpenTerminal(conn)
}
}

Expand All @@ -52,31 41,18 @@ func cmdConnect(cmd *cli.Cmd) {
if addr == nil || *addr == "" {
return
}
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewSshImpl()

// init dialer
param := impl.ImplParam{
Config: *cm.Conf,
}
dialer.Init(param)

// parse user name
err := dialer.DecodeAddress(*addr)
imp := impl.NewSSH(*addr, *tmp, *ident, false)
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
// parse client option
dialer.PrivateKeyOption(*ident)
// parse x11 option
dialer.X11Option(*tmp)
logrus.Debug("cmd connect")
err = dialer.Dial()
sender := impl.NewSender(imp, types.OPTION_TYPE_UP)
conn, err := sender.Send()
if err != nil {
logrus.Info(err)
logrus.Error(err)
return
}
dialer.Close()
imp.OpenTerminal(conn)
}
}
34 changes: 18 additions & 16 deletions cmd/sshx/sfs.go → cmd/sshx/sshfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 5,8 @@ import (

cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/conf"
"github.com/suutaku/sshx/pkg/impl"
"github.com/suutaku/sshx/pkg/types"
)

func cmdSSHFS(cmd *cli.Cmd) {
Expand All @@ -15,7 15,16 @@ func cmdSSHFS(cmd *cli.Cmd) {
}

func cmdUnmount(cmd *cli.Cmd) {

cmd.Spec = "PID"
pidOpt := cmd.StringArg("PID", "", "vnc server pair Id")
cmd.Action = func() {
if pidOpt == nil || *pidOpt == "" {
return
}
sender := impl.NewSender(&impl.SSHFS{}, types.OPTION_TYPE_DOWN)
sender.PairId = []byte(*pidOpt)
sender.SendDetach()
}
}

func splitMountPoint(mtopt string) (root, mt string) {
Expand All @@ -37,27 46,20 @@ func cmdMount(cmd *cli.Cmd) {
if host == nil || *(host) == "" {
return
}
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewSfsImpl()
param := impl.ImplParam{
Config: *cm.Conf,
}
dialer.Init(param)
err := dialer.DecodeAddress(*host)
root, mtp := splitMountPoint(*mtpOpt)
imp := impl.NewSSHFS(mtp, root, *host, *ident)
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
root, mtp := splitMountPoint(*mtpOpt)
dialer.SetMountPoint(mtp)
dialer.SetRoot(root)
dialer.PrivateKeyOption(*ident)

err = dialer.Dial()
sender := impl.NewSender(imp, types.OPTION_TYPE_UP)
_, err = sender.SendDetach()
if err != nil {
logrus.Info(err)
logrus.Error(err)
return
}

logrus.Infof("Mount %s %s to %s\n", imp.HostId(), root, mtp)
}
}
44 changes: 33 additions & 11 deletions cmd/sshx/stat.go
Original file line number Diff line number Diff line change
@@ -1,27 1,49 @@
package main

import (
"encoding/gob"

"github.com/suutaku/sshx/pkg/types"

cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/conf"
"github.com/suutaku/sshx/pkg/impl"
)

func cmdStatus(cmd *cli.Cmd) {
// cmd.Spec = "[-t]"
// typeFilter := cmd.StringOpt("t type","","application type filter")
cmd.Spec = "[ -t ]"
treeOpt := cmd.BoolOpt("t", false, "display in tree view")
cmd.Action = func() {
cm := conf.NewConfManager(getRootPath())
dialer := impl.NewStatImpl()
defer dialer.Close()
param := impl.ImplParam{
Config: *cm.Conf,
imp := impl.NewSTAT()
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
dialer.Init(param)
err := dialer.Dial()

sender := impl.NewSender(imp, types.OPTION_TYPE_STAT)
if sender == nil {
logrus.Error("cannot create sender")
return
}
conn, err := sender.SendDetach()
if err != nil {
logrus.Info(err)
logrus.Error(err)
return
}
defer conn.Close()
logrus.Debug("impl responsed")
var pld []types.Status
err = gob.NewDecoder(conn).Decode(&pld)
if err != nil {
logrus.Error(err)
return
}
logrus.Debug("show response")
displayStyle := impl.DISPLAY_TABLE
if *treeOpt {
displayStyle = impl.DISPLAY_TREE
}
imp.ShowStatus(pld, displayStyle)
}
}
49 changes: 49 additions & 0 deletions cmd/sshx/vnc.go
Original file line number Diff line number Diff line change
@@ -0,0 1,49 @@
package main

import (
cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
"github.com/suutaku/sshx/pkg/impl"
"github.com/suutaku/sshx/pkg/types"
)

func cmdStartVNCService(cmd *cli.Cmd) {
cmd.Spec = "[-P]"
vncServerPort := cmd.IntOpt("P", 80, "local proxy port")
cmd.Action = func() {
imp := impl.NewVNCService(int32(*vncServerPort))
err := imp.Preper()
if err != nil {
logrus.Error(err)
return
}
sender := impl.NewSender(imp, types.OPTION_TYPE_UP)
if sender == nil {
logrus.Error("can not create impl")
return
}
_, err = sender.SendDetach()
if err != nil {
logrus.Error(err)
return
}
}
}

func cmdStopVNCService(cmd *cli.Cmd) {
cmd.Spec = "PID"
pidOpt := cmd.StringArg("PID", "", "vnc server pair Id")
cmd.Action = func() {
if pidOpt == nil || *pidOpt == "" {
return
}
sender := impl.NewSender(&impl.VNCService{}, types.OPTION_TYPE_DOWN)
sender.PairId = []byte(*pidOpt)
sender.SendDetach()
}
}

func cmdVNCService(cmd *cli.Cmd) {
cmd.Command("start", "start vnc service", cmdStartVNCService)
cmd.Command("stop", "stop vnc service", cmdStopVNCService)
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,9 @@ require (
github.com/hanwen/go-fuse/v2 v2.1.0
github.com/jawher/mow.cli v1.2.0
github.com/jedib0t/go-pretty/v6 v6.3.1
github.com/kr/text v0.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20220326011226-f1430873d8db // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pion/webrtc/v3 v3.1.33
github.com/pkg/sftp v1.13.4
github.com/povsister/scp v0.0.0-20210427074412-33febfd9f13e
Expand All @@ -25,4 27,5 @@ require (
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
Loading

0 comments on commit d59f6e0

Please sign in to comment.