-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
45 lines (38 loc) · 1.27 KB
/
main.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
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/emulbreh/sshub/libsshub"
"golang.org/x/crypto/ssh"
kingpin "gopkg.in/alecthomas/kingpin.v2"
"io/ioutil"
"net/http"
"os"
)
var (
privateKeyFile = kingpin.Flag("key-file", "Private key of the server").Short('k').Default("/etc/sshub/key").String()
address = kingpin.Flag("address", "Listen address of the SSH server").Default(":4022").TCP()
httpAddress = kingpin.Flag("http", "Listen address of the HTTP api").Default(":4080").TCP()
)
func main() {
kingpin.Parse()
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
log.Infof("Loading private key from %s", *privateKeyFile)
privateBytes, err := ioutil.ReadFile(*privateKeyFile)
if err != nil {
log.Errorf("Failed to load private: %v", *privateKeyFile, err)
os.Exit(1)
}
private, err := ssh.ParsePrivateKey(privateBytes)
if err != nil {
panic("Failed to parse private key")
}
log.Infof("Listening for ssh connections on %v", *address)
hub := libsshub.NewHub(private)
go hub.Listen((*address).String())
log.Infof("Listening for http connections on %v", *httpAddress)
libsshub.InstallHttpHandlers(hub)
err = http.ListenAndServe((*httpAddress).String(), nil)
if err != nil {
log.Errorf("Failed to serve http api: %s", err)
}
}