Skip to content

Commit

Permalink
Implement basic SSH wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed May 15, 2021
1 parent 68fab17 commit db6e0fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions actions/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package actions
import (
"fmt"
"github.com/pkg/browser"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -105,6 +107,16 @@ func ServerLogin(host types.Server, generateOnly bool) error {
return nil
}

func ServerSsh(host types.Server) error {
fmt.Printf("Login to %s using SSH...\n", host.Host)

cmd := exec.Command("ssh", host.Host)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

func ServerList() error {
for _, i := range config.GetServers() {
fmt.Printf(
Expand Down
29 changes: 29 additions & 0 deletions cmd/servers/ssh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 1999-2021. Plesk International GmbH.

package cmd

import (
"github.com/plesk/pleskapp/plesk/actions"
"github.com/plesk/pleskapp/plesk/config"
"github.com/plesk/pleskapp/plesk/locales"
"github.com/spf13/cobra"
)

var sshCmd = &cobra.Command{
Use: "ssh [SERVER]",
Short: locales.L.Get("server.ssh.description"),
RunE: func(cmd *cobra.Command, args []string) error {
server, err := config.GetServer(args[0])
if err != nil {
return err
}

cmd.SilenceUsage = true

return actions.ServerSsh(*server)
},
}

func init() {
ServersCmd.AddCommand(sshCmd)
}
1 change: 1 addition & 0 deletions locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func init() {
"server.login.description": "Automatic login to the specified server",
"server.login.success": "Generated login link: %s",
"server.login.generate.flag": "Only generate the link (without autologin attempt)",
"server.ssh.description": "Login to server using SSH",

"errors.server.remove.failure": "Could not remove server %s: %s",
"errors.feature.not.supported": "Feature %s is not supported on Windows",
Expand Down

0 comments on commit db6e0fe

Please sign in to comment.