-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
67 lines (55 loc) · 1.26 KB
/
cli.go
File metadata and controls
67 lines (55 loc) · 1.26 KB
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
65
66
67
package main
import (
"flag"
"fmt"
"os"
"time"
log "github.com/sirupsen/logrus"
)
type Data struct {
Host string
User string
RemoteUser string
RemoteHost string
Tty string
Timestamp time.Time
}
var (
Version = "dev"
CommitHash = "n/a"
BuildTimestamp = "n/a"
)
var flagVersion bool
var flagConfig string
var flagTemplate string
func main() {
flag.BoolVar(&flagVersion, "version", false, "Print the tool version and exit.")
flag.StringVar(&flagConfig, "config", "smtp-cli.json", "The config file to use.")
flag.StringVar(&flagTemplate, "template", "template.gotmpl", "A file to load the go template from.")
flag.Parse()
if flagVersion {
fmt.Printf("smtp-cli %s \n\nRevision : %s \nTimestamp : %s \n", Version, CommitHash, BuildTimestamp)
os.Exit(0)
}
config, err := LoadConfig(&flagConfig)
if err != nil {
log.Fatal(err)
}
log.SetLevel(log.DebugLevel)
data := getData()
SendMail(config, flagTemplate, data)
}
func getData() Data {
hostname, err := os.Hostname()
if err != nil {
log.Fatal(err)
}
return Data{
Host: hostname,
User: os.Getenv("PAM_USER"),
RemoteUser: os.Getenv("PAM_RUSER"),
RemoteHost: os.Getenv("PAM_RHOST"),
Tty: os.Getenv("PAM_TTY"),
Timestamp: time.Now(),
}
}