Skip to content

Commit

Permalink
Merge pull request #38 from blacknon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
blacknon authored Mar 2, 2019
2 parents 682ed3e + a1c7a06 commit cf68a21
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 90 deletions.
100 changes: 64 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ TUI list select ssh/scp client.

## Description

command to read a prepared list in advance and connect ssh/scp the selected host. List file is set in yaml format.When selecting a host, you can filter by keywords. Can execute commands concurrently to multiple hosts. Supported multiple ssh proxy, and supported http/socks5 proxy.
command to read a prepared list in advance and connect ssh/scp the selected host. List file is set in yaml format. When selecting a host, you can filter by keywords. Can execute commands concurrently to multiple hosts. Supported multiple ssh proxy, and supported http/socks5 proxy.

## Features

* List selection type ssh client.
* Pure Go.
* Commands can be executed by ssh connection in parallel.
* Supported multiple proxy.
* Can use bashrc of local machine at ssh connection destination.

## Demo

Expand All @@ -23,7 +31,7 @@ lscp is need the following command in remote server.

## Install

compile gofile(tested go1.8.3).
compile gofile(tested go1.11.5).

go get github.com/blacknon/lssh
cd $GOPATH/src/github.com/blacknon/lssh
Expand All @@ -40,9 +48,10 @@ brew install(Mac OS X)
# generate .lssh.conf(use ~/.ssh/config.not support proxy)
lssh --generate > ~/.lssh.conf

## Usage
## Config

Please edit "~/.lssh.conf". The connection information at servers,can be divided into external files. log dir "\<Date\>" => date(YYYYMMDD) ,"\<Hostname\>" => Servername.
Please edit "~/.lssh.conf".
For details see [wiki](https://github.com/blacknon/lssh/wiki/Config).

example:

Expand All @@ -53,7 +62,7 @@ example:
dirpath = "/path/to/logdir"

# server common settings
[common]
[common]
port = "22"
user = "test"

Expand Down Expand Up @@ -132,69 +141,76 @@ example:
addr = "example.com"
port = "54321"

After run command.

## Usage

run command.

lssh


option(lssh)

NAME:
lssh - TUI list select and parallel ssh client command.
lssh - TUI list select and parallel ssh client command.
USAGE:
lssh [options] [commands...]

lssh [options] [commands...]
OPTIONS:
--host value, -H value connect servernames
--list, -l print server list from config
--file value, -f value config file path (default: "$HOME/.lssh.conf")
--term, -t run specified command at terminal
--parallel, -p run command parallel node(tail -F etc...)
--generate (beta) generate .lssh.conf from .ssh/config.(not support ProxyCommand)
--help, -h print this help
--version, -v print the version

--host value, -H value connect servernames
--list, -l print server list from config
--file value, -f value config file path (default: "/home/blacknon/.lssh.conf")
--portforward-local value port forwarding local port(ex. 127.0.0.1:8080)
--portforward-remote value port forwarding remote port(ex. 127.0.0.1:80)
--term, -t run specified command at terminal
--parallel, -p run command parallel node(tail -F etc...)
--generate (beta) generate .lssh.conf from .ssh/config.(not support ProxyCommand)
--help, -h print this help
--version, -v print the version
COPYRIGHT:
blacknon([email protected])

blacknon([email protected])
VERSION:
0.5.1

0.5.2
USAGE:
# connect ssh
lssh

# parallel run command in select server over ssh
lssh -p command...

# connect ssh
lssh
# parallel run command in select server over ssh
lssh -p command...

option(lscp)

option(lscp)

NAME:
lscp - TUI list select and parallel scp client command.
USAGE:
lscp [options] (local|remote):from_path... (local|remote):to_path

OPTIONS:
--host value, -H value connect servernames
--list, -l print server list from config
--file value, -f value config file path (default: "$HOME/.lssh.conf")
--file value, -f value config file path (default: "/home/blacknon/.lssh.conf")
--permission, -p copy file permission
--help, -h print this help
--version, -v print the version

COPYRIGHT:
blacknon([email protected])

VERSION:
0.5.1

0.5.2
USAGE:
# local to remote scp
lscp /path/to/local... /path/to/remote

# remote to local scp
lscp remote:/path/to/remote... /path/to/local

If you specify a command as an argument, you can select multiple hosts. Select host 'Tab', select all displayed hosts 'Ctrl + A'.

Expand Down Expand Up @@ -226,6 +242,10 @@ You can scp like copy files using stdin/stdout.It also supports multiple nodes(p

sample lssh.conf

<p align="center">
<img src="./example/lssh_iterm2.gif" />
</p>

[server.iTerm2_sample]
addr = "192.168.100.103"
key = "/path/to/private_key"
Expand All @@ -234,6 +254,14 @@ sample lssh.conf
post_cmd = 'printf "\033]50;SetProfile=Default\a"' # local theme
post_cmd = "(option) exec command after ssh disconnected."

[server.GnomeTerminal_sample]
addr = "192.168.100.103"
key = "/path/to/private_key"
note = "Before/After run local command"
pre_cmd = 'printf "\033]50;SetProfile=dq\a"' # ssh theme
post_cmd = 'printf "\033]50;SetProfile=Default\a"' # local theme
post_cmd = "(option) exec command after ssh disconnected."


### [lssh] use local bashrc file.

Expand Down
2 changes: 1 addition & 1 deletion args/lscp_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ USAGE:
app.Name = "lscp"
app.Usage = "TUI list select and parallel scp client command."
app.Copyright = "blacknon([email protected])"
app.Version = "0.5.1"
app.Version = "0.5.2"

app.Flags = []cli.Flag{
cli.StringSliceFlag{Name: "host,H", Usage: "connect servernames"},
Expand Down
11 changes: 8 additions & 3 deletions args/lssh_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ VERSION:
{{.Version}}
{{end}}
USAGE:
# connect ssh
{{.Name}}
# connect ssh
{{.Name}}
# parallel run command in select server over ssh
{{.Name}} -p command...
Expand All @@ -51,13 +51,15 @@ USAGE:
app.Name = "lssh"
app.Usage = "TUI list select and parallel ssh client command."
app.Copyright = "blacknon([email protected])"
app.Version = "0.5.1"
app.Version = "0.5.2"

// Set options
app.Flags = []cli.Flag{
cli.StringSliceFlag{Name: "host,H", Usage: "connect servernames"},
cli.BoolFlag{Name: "list,l", Usage: "print server list from config"},
cli.StringFlag{Name: "file,f", Value: defConf, Usage: "config file path"},
cli.StringFlag{Name: "portforward-local", Usage: "port forwarding local port(ex. 127.0.0.1:8080)"},
cli.StringFlag{Name: "portforward-remote", Usage: "port forwarding remote port(ex. 127.0.0.1:80)"},
cli.BoolFlag{Name: "term,t", Usage: "run specified command at terminal"},
cli.BoolFlag{Name: "parallel,p", Usage: "run command parallel node(tail -F etc...)"},
cli.BoolFlag{Name: "generate", Usage: "(beta) generate .lssh.conf from .ssh/config.(not support ProxyCommand)"},
Expand Down Expand Up @@ -136,6 +138,9 @@ USAGE:
r.IsParallel = c.Bool("parallel")
r.ExecCmd = c.Args()

r.PortForwardLocal = c.String("portforward-local")
r.PortForwardRemote = c.String("portforward-remote")

r.Start()
return nil
}
Expand Down
1 change: 1 addition & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func GetFilesBase64(list []string) (result string, err error) {
}

data = append(data, file_data...)
data = append(data, '\n')
}

result = base64.StdEncoding.EncodeToString(data)
Expand Down
74 changes: 54 additions & 20 deletions conf/conf.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package conf

import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"os/user"
"strings"
"time"

"github.com/BurntSushi/toml"
"github.com/blacknon/lssh/common"
)

type Config struct {
Log LogConfig
Include map[string]IncludeConfig
Common ServerConfig
Server map[string]ServerConfig
Proxy map[string]ProxyConfig
Log LogConfig
Include map[string]IncludeConfig
Includes IncludesConfig
Common ServerConfig
Server map[string]ServerConfig
Proxy map[string]ProxyConfig
}

type LogConfig struct {
Expand All @@ -24,25 +28,33 @@ type LogConfig struct {
Dir string `toml:"dirpath"`
}

type IncludesConfig struct {
Path []string `toml:"path"`
}

type IncludeConfig struct {
Path string `toml:"path"`
}

type ServerConfig struct {
Addr string `toml:"addr"`
Port string `toml:"port"`
User string `toml:"user"`
Pass string `toml:"pass"`
Key string `toml:"key"`
KeyPass string `toml:"keypass"`
PreCmd string `toml:"pre_cmd"`
PostCmd string `toml:"post_cmd"`
ProxyType string `toml:"proxy_type"`
Proxy string `toml:"proxy"`
LocalRcUse string `toml:"local_rc"` // yes|no
LocalRcPath []string `toml:"local_rc_file"`
LocalRcDecodeCmd string `toml:"local_rc_decode_cmd"`
Note string `toml:"note"`
Addr string `toml:"addr"`
Port string `toml:"port"`
User string `toml:"user"`
Pass string `toml:"pass"`
Key string `toml:"key"`
KeyPass string `toml:"keypass"`
PreCmd string `toml:"pre_cmd"`
PostCmd string `toml:"post_cmd"`
ProxyType string `toml:"proxy_type"`
Proxy string `toml:"proxy"`
LocalRcUse string `toml:"local_rc"` // yes|no
LocalRcPath []string `toml:"local_rc_file"`
LocalRcDecodeCmd string `toml:"local_rc_decode_cmd"`
PortForwardLocal string `toml:"port_forward_local"` // port forward (local). "host:port"
PortForwardRemote string `toml:"port_forward_remote"` // port forward (remote). "host:port"
SSHAgentUse bool `toml:"ssh_agent"`
SSHAgentKeyPath []string `toml:"ssh_agent_key"` // "keypath::passphase"
Note string `toml:"note"`
}

type ProxyConfig struct {
Expand All @@ -54,6 +66,9 @@ type ProxyConfig struct {
}

func ReadConf(confPath string) (checkConf Config) {
// user path
usr, _ := user.Current()

if !common.IsExist(confPath) {
fmt.Printf("Config file(%s) Not Found.\nPlease create file.\n\n", confPath)
fmt.Printf("sample: %s\n", "https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml")
Expand All @@ -72,13 +87,32 @@ func ReadConf(confPath string) (checkConf Config) {
checkConf.Server[key] = setValue
}

// for append includes to include.path
if checkConf.Includes.Path != nil {
if checkConf.Include == nil {
checkConf.Include = map[string]IncludeConfig{}
}

for _, includePath := range checkConf.Includes.Path {
unixTime := time.Now().Unix()
keyString := strings.Join([]string{string(unixTime), includePath}, "_")

// key to md5
hasher := md5.New()
hasher.Write([]byte(keyString))
key := string(hex.EncodeToString(hasher.Sum(nil)))

// append checkConf.Include[key]
checkConf.Include[key] = IncludeConfig{strings.Replace(includePath, "~", usr.HomeDir, 1)}
}
}

// Read include files
if checkConf.Include != nil {
for _, v := range checkConf.Include {
var includeConf Config

// user path
usr, _ := user.Current()
path := strings.Replace(v.Path, "~", usr.HomeDir, 1)

// Read include config file
Expand Down
1 change: 1 addition & 0 deletions example/config.tml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[log]
enable = true
timestamp = true
dirpath = "/path/to/logdir"

[server.PasswordAuth_ServerName]
Expand Down
Binary file modified example/lssh.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/lssh_iterm2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions list/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func (l *ListInfo) keyEvent() (lineData []string) {

for {
switch ev := termbox.PollEvent(); ev.Type {

// Get Key Event
// Type Key
case termbox.EventKey:
switch ev.Key {
// ESC or Ctrl + C Key (Exit)
Expand Down Expand Up @@ -138,6 +137,20 @@ func (l *ListInfo) keyEvent() (lineData []string) {
l.draw()
}
}

// Type Mouse
case termbox.EventMouse:
if ev.Key == termbox.MouseLeft {
// mouse select line is (ev.MouseY - headLine) line.
mouseSelectLine := ev.MouseY - headLine

if mouseSelectLine <= len(l.ViewText)-headLine {
l.CursorLine = mouseSelectLine
}
l.draw()
}

// Other
default:
l.draw()
}
Expand Down
Loading

0 comments on commit cf68a21

Please sign in to comment.