Skip to content

Commit

Permalink
Merge pull request #18 from TNK-Studio/dev
Browse files Browse the repository at this point in the history
[MOD] add scp file to server by jumperserver
  • Loading branch information
elfgzp authored Dec 12, 2019
2 parents 777aa30 + bc94308 commit dc89c5a
Show file tree
Hide file tree
Showing 8 changed files with 609 additions and 29 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ starting ssh server on port 2222...

## How to use

### First Time

After the gortal service is started, an sshd service will be started on port `2222`. You can also set the startup port through `-p`.

After the service is started, you only need to use the `ssh` command to access the service.
Expand All @@ -54,12 +56,29 @@ The default user password for the first access is `newuser`, and then the comman
```shell
$ ssh root@127.0.0.1 -p 2222
root@127.0.0.1's password:
Use the arrow keys to navigate: ↓ ↑ → ←
? Please select the function you need:
Use the arrow keys to navigate: ↓ ↑ → ←
? Please select the function you need:
▸ List servers
Edit users
Edit servers
Edit personal info
Quit
```
You can use it after logging in with your password again.
You can use it after logging in with your password again.
### Copy files to server via jumpserver
If you want to copy files to the server via a springboard, you can use the `scp` command in the following format:
```shell
$ scp -P 2222 ~/Desktop/README.md gzp@jumpserver:gzp@server2:~/Desktop/README1.md
README.md 100% 9279 73.9KB/s 00:00
```
Note the use of `:` after `gzp@jumpserver` plus the `key` and `username` of the server you need to transfer, and finally write the destination path.
Folder transfer is currently not supported. Please compress the file and upload it.
### Copy files from server via jumpserver
> To do
13 changes: 9 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,15 @@ func (c *Config) GetUserByUsername(username string) *User {
return nil
}

// // GetUsers GetUsers
// func (c *Config) GetUsers() []*User {

// }
// GetServerByName GetServerByName
func (c *Config) GetServerByName(name string) *Server {
for _, server := range *c.Servers {
if server.Name == name {
return server
}
}
return nil
}

// GetUserServers get user servers list
func (c *Config) GetUserServers(user *User) map[string]*Server {
Expand Down
7 changes: 5 additions & 2 deletions core/pui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func GetServersMenu() func(int, *MenuItem, *ssh.Session, []*MenuItem) *[]*MenuIt
menu = append(
menu,
&MenuItem{
Label: server.Name,
Label: fmt.Sprintf("%s: %s", serverKey, server.Name),
Info: info,
SubMenuTitle: fmt.Sprintf("Please select ssh user to login '%s'", server.Name),
GetSubMenu: GetServerSSHUsersMenu(server),
Expand Down Expand Up @@ -323,7 +323,7 @@ func GetEditedServersMenu(
menu = append(
menu,
&MenuItem{
Label: server.Name,
Label: fmt.Sprintf("%s: %s", serverKey, server.Name),
Info: info,
SubMenuTitle: fmt.Sprintf("Please select. "),
GetSubMenu: getSubMenu,
Expand Down Expand Up @@ -522,6 +522,9 @@ func DelSSHUser(server *config.Server, sshUserKey string, sess *ssh.Session) err
// GetEditedSSHUsersMenu GetEditedSSHUsersMenu
func GetEditedSSHUsersMenu(server *config.Server) *[]*MenuItem {
menu := make([]*MenuItem, 0)
if server.SSHUsers == nil {
return nil
}

for sshUserKey, sshUser := range *server.SSHUsers {
info := make(map[string]string)
Expand Down
Loading

0 comments on commit dc89c5a

Please sign in to comment.