-
Notifications
You must be signed in to change notification settings - Fork 11
/
gooverssh.go
62 lines (54 loc) · 1.48 KB
/
gooverssh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/scottkiss/gosshtool"
"io/ioutil"
"log"
)
var config tomlConfig
func loadconfig() {
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
fmt.Println(err)
panic("load config error")
}
}
func main() {
loadconfig()
server := new(gosshtool.LocalForwardServer)
server.LocalBindAddress = config.SSH.LocalBindAddress
server.RemoteAddress = config.Remote.Host + ":" + config.Remote.Port
server.SshServerAddress = config.SSH.SshServerAddress
if config.SSH.SshUserPassword == "" && config.SSH.SshPrivateKey == "" {
panic("password or private key path is empty")
}
if config.SSH.SshUserPassword != "" && config.SSH.SshPrivateKey == "" {
server.SshUserPassword = config.SSH.SshUserPassword
}
if config.SSH.SshUserPassword == "" && config.SSH.SshPrivateKey != "" {
buf, _ := ioutil.ReadFile(config.SSH.SshPrivateKey)
server.SshPrivateKey = string(buf)
}
server.SshUserName = config.SSH.SshUserName
server.Start(started)
defer server.Stop()
}
func started() {
log.Println("go over ssh server started")
}
type tomlConfig struct {
Title string
SSH ssh
Remote remote
}
type ssh struct {
LocalBindAddress string `toml:"local_bind_address"`
SshServerAddress string `toml:"ssh_server"`
SshUserName string `toml:"ssh_user"`
SshUserPassword string `toml:"ssh_password"`
SshPrivateKey string `toml:"private_key_path"`
}
type remote struct {
Host string `toml:"host"`
Port string `toml:"port"`
}