-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (72 loc) · 2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
// This app is a server for client requests for ssh type stuff.
import (
"bufio"
"flag"
"fmt"
"log"
"net/http"
"strings"
"github.com/howeyc/gopass"
"bozosonparade/gsh"
"bozosonparade/gtailer/resources"
"os"
)
// main is the entry point for this app.
func main() {
log.SetFlags(log.Lshortfile)
// Command line flags
configPtr := flag.String("config", "", "Config name to use.")
userPtr := flag.String("user", "", "Username to use for sshing.")
aConfigs := gsh.LoadConfigs()
strConfig := ""
flag.Parse()
// Check command line options
if len(*configPtr) > 0 {
strConfig = *configPtr
fmt.Printf("Using config: %s\n", strConfig)
} else {
strConfs := ""
for _, conf := range aConfigs {
if len(strConfs) > 0 {
strConfs += ", "
}
strConfs += conf.Name
}
strConfig = readLine(fmt.Sprintf("Select configuration to load (%s): ", strConfs))
}
for _, conf := range aConfigs {
if strings.EqualFold(conf.Name, strConfig) {
gsh.CurrentConfig = &conf
break
}
}
if gsh.CurrentConfig == nil {
log.Fatalf("Unable to load config %s", strConfig)
}
if len(*userPtr) > 0 {
resources.SshUser = *userPtr
fmt.Printf("Using user: %s\n", resources.SshUser)
} else {
resources.SshUser = readLine("Please enter the ssh user to use: ")
}
fmt.Printf("Password:")
resources.SshPwd = string(gopass.GetPasswdMasked())
// other service endpoints
http.HandleFunc("/hosts", resources.HostsResourceHandler)
http.HandleFunc("/operations", resources.OperationsResourceHandler)
http.HandleFunc("/subscribe/", resources.SubscribeResourceHandler)
// static files
http.Handle("/", http.FileServer(http.Dir("webroot")))
//log.Fatal(http.ListenAndServe(":8080", nil))
fmt.Println("gSSH Utilities started and serving data.")
log.Fatal(http.ListenAndServeTLS(":7443", "cert.pem", "key.pem", nil))
}
func readLine(msg string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(msg)
text, _ := reader.ReadString('\n')
// Clear out white space
text = strings.TrimSpace(text)
return text
}