-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain.go
executable file
·64 lines (53 loc) · 1.42 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"os"
"fmt"
"log"
"strings"
"io/ioutil"
"log/syslog"
"github.com/jessevdk/go-flags"
)
var config *SSHConfig
var authLogger *syslog.Writer
var opts struct {
Config string `short:"c" long:"config" description:"Configuration YAML file location" required:"true"`
}
func main() {
_, err := flags.Parse(&opts)
if err != nil {
os.Exit(1)
}
if _, err := os.Stat(opts.Config); err != nil {
log.Fatalf("Specified config file doesn't exist!\n")
}
config, err = fetchConfig(opts.Config)
if err != nil {
panic(err)
}
authLogger, err = syslog.New(syslog.LOG_AUTH | syslog.LOG_ALERT, "ssh-bastion")
if err != nil {
panic(err)
}
s, err := NewSSHServer()
if err != nil {
panic(err)
}
s.ListenAndServe(config.Global.ListenPath)
}
func GetMOTD() (string) {
if len(config.Global.MOTDPath) > 0 {
str, err := ioutil.ReadFile(config.Global.MOTDPath)
if err != nil {
log.Printf("Error reading MOTD file (%s): %s", config.Global.MOTDPath, err)
return ""
} else {
return strings.Replace(string(str), "\n", "\r\n", -1)
}
} else {
return ""
}
}
func WriteAuthLog(format string, v ...interface{}) {
authLogger.Write([]byte(fmt.Sprintf(format, v...)))
}