move in one tab. Add IANA root DNS anchors

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-25 21:28:21 -07:00
parent 3ed2a0956a
commit e09e613347
4 changed files with 149 additions and 199 deletions

View File

@ -44,8 +44,7 @@ func loadConfigFile() {
spew.Dump(user) spew.Dump(user)
filename := "" filename := ""
// TODO: figure out how to look for this file in the right // TODO: confirm this is correct for MacOS and Windows
// place under Linux, MacOS and Windows
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
log.Println("OS: Linux") log.Println("OS: Linux")
filename = user.HomeDir + "/.config/cloud-control-panel.json" filename = user.HomeDir + "/.config/cloud-control-panel.json"
@ -59,28 +58,10 @@ func loadConfigFile() {
tmp := loadConfigFromFilename(filename) tmp := loadConfigFromFilename(filename)
config = &tmp config = &tmp
// os.Exit(1)
// junk := marshalEvent()
// spew.Dump(junk)
// config = unmarshalConfig(junk)
// config = unmarshalConfig(string(b))
config.Filename = filename config.Filename = filename
} }
/* NEVER USE THIS
func unmarshalConfig(a string) *pb.Config {
var newpb *pb.Config
log.Println("ATTEMTED TO UNMARSHAL string =", a)
err := jsonpb.UnmarshalString(a, newpb)
log.Println("ATTEMTED TO UNMARSHAL err =", err)
spew.Dump(newpb)
return newpb
}
*/
var customUsage = func() { var customUsage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]) fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults() flag.PrintDefaults()
@ -124,24 +105,14 @@ func parseFlags() {
log.Println("ENABLE height =", int32(*height)) log.Println("ENABLE height =", int32(*height))
config.Height = int32(*height) config.Height = int32(*height)
} }
log.Println("ENABLE nogui =", *nogui)
log.Println("ENABLE debugging =", *debugging)
if (*debugging) {
log.Println("ENABLE width =", *width)
log.Println("ENABLE debugging =", *debugging)
} else {
log.Println("DISABLE DEBUG debugging =", *debugging)
}
if (hostname == "") { if (hostname == "") {
config.Hostname = hostname config.Hostname = hostname
} }
// never allow these to be set in the config file
config.Debugging = *debugging config.Debugging = *debugging
config.Debugtable = *debugtable config.Debugtable = *debugtable
log.Println("config.Width", config.Width)
log.Println("config.Debugging", config.Debugging)
} }
func parseConfig() { func parseConfig() {
@ -151,30 +122,19 @@ func parseConfig() {
// override the config file from the command line // override the config file from the command line
parseFlags() parseFlags()
log.Println("config.width", config.Width) log.Println("config.width", config.Width)
log.Println("config.height", config.Height) log.Println("config.height", config.Height)
log.Println("config.debugging", config.Debugging) log.Println("config.debugging", config.Debugging)
// use this to restore the default config
// defaultConfig, _ := packrBox.FindString("cloud.json")
// config = pb.MakeDefaultConfig()
// spew.Dump(config)
} }
func marshalEvent() string { // Convert a Protobuf to JSON
// This is how you marshal into JSON from a Protobuf func PBtoJSON() string {
// this makes a sample protobuf
c := pb.MakeDefaultConfig() c := pb.MakeDefaultConfig()
marshaler := &jsonpb.Marshaler{} marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(c) stuff, _ := marshaler.MarshalToString(c)
log.Println(stuff) log.Println(stuff)
// also:
// var j *bytes.Buffer
// marshaler.Marshal(j, event)
// w.Write(j.Bytes())
return stuff return stuff
} }
@ -194,17 +154,6 @@ func saveConfig() {
log.Println(stuff) log.Println(stuff)
writeToFile(filename, stuff) writeToFile(filename, stuff)
/*
f, err := os.Create(filename + ".yaml")
if err == nil {
// DumpTo(f, "yaml")
}
f, err = os.Create(filename)
if err == nil {
// DumpTo(f, "json")
}
*/
} }
} }

View File

@ -42,6 +42,7 @@ func gorillaReadProtobuf(conn *websocket.Conn) {
func gorillaSendProtobuf(msg *pb.Event) { func gorillaSendProtobuf(msg *pb.Event) {
log.Println("gorillaSendProtobuf() START", time.Now()) log.Println("gorillaSendProtobuf() START", time.Now())
log.Println("gorillaSendProtobuf()", msg)
if (gorillaConn == nil) { if (gorillaConn == nil) {
log.Println("gorillaSendProtobuf() gorillaConn == nil") log.Println("gorillaSendProtobuf() gorillaConn == nil")
log.Println("Need to re-open connection here") log.Println("Need to re-open connection here")
@ -95,12 +96,9 @@ func gorillaDial(hostname string) {
conn, resp, err := websocket.DefaultDialer.Dial(u.String(), nil) conn, resp, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil { if err != nil {
log.Println("gorilla Dial failed", err) log.Println("gorillaDial failed", err)
} else { } else {
log.Println("RESPONSE HEADER = ", resp.Header)
log.Println("RESPONSE HEADER = ", resp.Header)
resp.Header.Set("jcarrname", "jcarrvalue") resp.Header.Set("jcarrname", "jcarrvalue")
log.Println("RESPONSE HEADER = ", resp.Header)
gorillaConn = conn gorillaConn = conn
origconn := conn.UnderlyingConn() origconn := conn.UnderlyingConn()

257
main.go
View File

@ -25,12 +25,6 @@ var GITCOMMIT string // this is passed in as an ldflag
var GOVERSION string // this is passed in as an ldflag var GOVERSION string // this is passed in as an ldflag
var BUILDTIME string // this is passed in as an ldflag var BUILDTIME string // this is passed in as an ldflag
// reminder to use this for JSON
// https://github.com/tidwall/gjson
// value := gjson.Get(json, "name.last")
// println(value.String())
// value := gjson.Get(json, friends.#[last=="Murphy"].first)
// use mergo to merge structs // use mergo to merge structs
// import "github.com/imdario/mergo" // import "github.com/imdario/mergo"
// mergo.Merge(&dest, src) // mergo.Merge(&dest, src)
@ -41,6 +35,14 @@ var BUILDTIME string // this is passed in as an ldflag
// several smart slice functions (new project. April 2019) // several smart slice functions (new project. April 2019)
// https://github.com/elliotchance/pie // https://github.com/elliotchance/pie
// look into this for dns if possible
// https://en.wikipedia.org/wiki/DNSCrypt
// https://en.wikipedia.org/wiki/DNS_over_HTTPS
// DNS over TLS plugin for coredns
// uses protobuf's and gRPC in pb/dns.proto
// https://github.com/coredns/coredns/tree/master/plugin/tls
func onExit(err error) { func onExit(err error) {
log.Println("Sleep for 1 second") log.Println("Sleep for 1 second")
time.Sleep(1 * 1000 * 1000 * 1000) time.Sleep(1 * 1000 * 1000 * 1000)
@ -148,34 +150,36 @@ func mainMouseClick(b *gui.ButtonMap) {
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?") log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
} else { onExit("mainMouseClick() got b = nil")
gui.Data.Current = b.Account }
log.Println("mainMouseClick() setting current account = ", b.Account)
log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")") gui.Data.Current = b.Account
if (b.Action == "BACK") { log.Println("mainMouseClick() setting current account = ", b.Account)
gui.Data.State = "splash"
} else if (b.Action == "QUIT") { log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")")
onExit(nil) if (b.Action == "BACK") {
} else if (b.Action == "CREATE") { gui.Data.State = "splash"
log.Println("TRY TO ADD A NEW VIRTUAL MACHINE") } else if (b.Action == "QUIT") {
log.Println("\tTRIGGER CREATE VM") onExit(nil)
gui.Data.State = "CREATE" } else if (b.Action == "CREATE") {
} else if (b.Action == "CONFIG") { log.Println("TRY TO ADD A NEW VIRTUAL MACHINE")
loadDefaultConfig() log.Println("\tTRIGGER CREATE VM")
gui.Data.State = "done" gui.Data.State = "CREATE"
} else if (b.Action == "DEBUG") { } else if (b.Action == "CONFIG") {
log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)") loadDefaultConfig()
debug.PrintStack() gui.Data.State = "done"
} else if (b.Action == "DEBUG FULL") { } else if (b.Action == "DEBUG") {
log.Println("ATTEMPT FULL STACK DUMP") log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)")
buf := make([]byte, 1<<16) debug.PrintStack()
runtime.Stack(buf, true) } else if (b.Action == "DEBUG FULL") {
log.Printf("%s", buf) log.Println("ATTEMPT FULL STACK DUMP")
log.Println("FINISHED FULL STACK DUMP") buf := make([]byte, 1<<16)
} else if (b.Action == "ADD") { runtime.Stack(buf, true)
log.Println("\tSHOULD ADD ACCOUNT HERE") log.Printf("%s", buf)
if (gui.Data.CurrentTab != nil) { log.Println("FINISHED FULL STACK DUMP")
} else if (b.Action == "ADD") {
log.Println("\tSHOULD ADD ACCOUNT HERE")
if (gui.Data.CurrentTab != nil) {
if (gui.Data.CurrentTab.EntryNick != nil) { if (gui.Data.CurrentTab.EntryNick != nil) {
nick := gui.Data.CurrentTab.EntryNick.Text() nick := gui.Data.CurrentTab.EntryNick.Text()
username := gui.Data.CurrentTab.EntryUser.Text() username := gui.Data.CurrentTab.EntryUser.Text()
@ -191,86 +195,86 @@ func mainMouseClick(b *gui.ButtonMap) {
config.Accounts = append(config.Accounts, acc) config.Accounts = append(config.Accounts, acc)
} }
} }
} else if (b.Action == "LOGIN") { } else if (b.Action == "LOGIN") {
log.Println("\tTRIGGER LOGIN ACCOUNT") log.Println("\tTRIGGER LOGIN ACCOUNT")
gui.Data.State = "SEND LOGIN" gui.Data.State = "SEND LOGIN"
count := 0 count := 0
for { for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State) log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "NEW PROTOBUF") { if (gui.Data.State == "NEW PROTOBUF") {
if (currentMessage == nil) { if (currentMessage == nil) {
gui.SocketError() gui.SocketError()
gui.Data.State = "done" gui.Data.State = "done"
} else { } else {
log.Println("LOGIN currentMessage =", currentMessage) log.Println("LOGIN currentMessage =", currentMessage)
if (currentMessage.Type == pb.Event_OK) { if (currentMessage.Type == pb.Event_OK) {
log.Println("LOGIN WAS OK!") log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!") log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!") log.Println("LOGIN WAS OK!")
msg := "On account " + b.Account.Nick + "\n" msg := "On account " + b.Account.Nick + "\n"
gui.MessageWindow("Login OK", msg) gui.MessageWindow("Login OK", msg)
} }
if (currentMessage.Type == pb.Event_FAIL) { if (currentMessage.Type == pb.Event_FAIL) {
log.Println("LOGIN FAILED") log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED") log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED") log.Println("LOGIN FAILED")
msg := "On account " + b.Account.Nick + "\n" msg := "On account " + b.Account.Nick + "\n"
msg += "pb.Comment = " + currentMessage.Comment + "\n" msg += "pb.Comment = " + currentMessage.Comment + "\n"
msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n" msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n"
msg += "pb.Email = " + currentMessage.Email + "\n" msg += "pb.Email = " + currentMessage.Email + "\n"
msg += "pb.Username = " + currentMessage.Username + "\n" msg += "pb.Username = " + currentMessage.Username + "\n"
gui.ErrorWindow("Login Failed", msg) gui.ErrorWindow("Login Failed", msg)
}
currentMessage = nil
gui.Data.State = "done"
} }
return
}
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil currentMessage = nil
gui.Data.State = "done" gui.Data.State = "done"
return
} }
return
} }
} else if (b.Action == "SHOW") { count += 1
log.Println("\tTRIGGER DISPLAY ACCOUNT") if (count > 10) {
gui.Data.State = "SEND WEBSOCKET" log.Println("ERROR: waited too long for a resposne")
count := 0 currentMessage = nil
for { gui.Data.State = "done"
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State) return
time.Sleep(200 * time.Millisecond) }
if (gui.Data.State == "NEW PROTOBUF") { }
if (currentMessage == nil) { } else if (b.Action == "SHOW") {
gui.SocketError() log.Println("\tTRIGGER DISPLAY ACCOUNT")
gui.Data.State = "done" gui.Data.State = "SEND WEBSOCKET"
} else { count := 0
count := countVMS(currentMessage) for {
log.Println("SHOW VMS currentMessage =", currentMessage) log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
log.Println("SHOW VMS count =", count) time.Sleep(200 * time.Millisecond)
if (count != 0) { if (gui.Data.State == "NEW PROTOBUF") {
name := "Virtual Machines (" + b.Account.Nick + ")" if (currentMessage == nil) {
mh := gui.AddVmsTab(name, count, b.Account) gui.SocketError()
ReadReceivedData(currentMessage, mh) gui.Data.State = "done"
} } else {
currentMessage = nil count := countVMS(currentMessage)
gui.Data.State = "done" log.Println("SHOW VMS currentMessage =", currentMessage)
log.Println("SHOW VMS count =", count)
if (count != 0) {
name := "Virtual Machines (" + b.Account.Nick + ")"
mh := gui.AddVmsTab(name, count, b.Account)
ReadReceivedData(currentMessage, mh)
} }
return
}
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil currentMessage = nil
gui.Data.State = "done" gui.Data.State = "done"
return
} }
return
}
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil
gui.Data.State = "done"
return
} }
} }
} }
if (gui.Data.State == "splash") { if (gui.Data.State == "splash") {
gui.ShowAccountQuestionTab() gui.ShowAccountQuestionTab()
gui.Data.State = "account1" gui.Data.State = "account1"
@ -286,6 +290,17 @@ func mainMouseClick(b *gui.ButtonMap) {
} }
} }
func prepareAndSend(event *pb.Event) {
if (gui.Data.Current != nil) {
event.Token = gui.Data.Current.Token
event.Username = gui.Data.Current.Username
event.Password = gui.Data.Current.Password
}
log.Println("\tpb.MakeLoginEvent() event.Token =", event.Token)
gorillaSendProtobuf(event)
gui.Data.State = "READ PROTOBUF"
}
// this watches the GUI primarily to process protobuf's // this watches the GUI primarily to process protobuf's
func watchGUI() { func watchGUI() {
count := 0 count := 0
@ -299,47 +314,19 @@ func watchGUI() {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "SEND WEBSOCKET") { if (gui.Data.State == "SEND WEBSOCKET") {
log.Println("\tTRIGGERING SEND WEBSOCKET")
event := pb.MakeGetEvent() event := pb.MakeGetEvent()
if (gui.Data.Current != nil) { prepareAndSend(event)
event.Token = gui.Data.Current.Token
event.Username = gui.Data.Current.Username
}
log.Println("\tTRIGGERING event.Token =", event.Token)
log.Println("\tTRIGGERING event.Username =", event.Username)
log.Println("\tTRIGGERING event.Email =", event.Email)
gorillaSendProtobuf(event)
gui.Data.State = "READ PROTOBUF"
} }
if (gui.Data.State == "SEND LOGIN") { if (gui.Data.State == "SEND LOGIN") {
log.Println("\tTRIGGERING LOGIN")
event := pb.MakeLoginEvent() event := pb.MakeLoginEvent()
if (gui.Data.Current != nil) { prepareAndSend(event)
event.Token = gui.Data.Current.Token
event.Username = gui.Data.Current.Username
event.Password = gui.Data.Current.Password
}
log.Println("\tTRIGGERING event.Token =", event.Token)
log.Println("\tTRIGGERING event.Username =", event.Username)
log.Println("\tTRIGGERING event.Email =", event.Email)
gorillaSendProtobuf(event)
gui.Data.State = "READ PROTOBUF"
} }
if (gui.Data.State == "CREATE") { if (gui.Data.State == "CREATE") {
log.Println("\tTRIGGERING CREATE HERE") log.Println("\tTRIGGERING CREATE")
event := pb.MakeAddVmEvent() event := pb.MakeAddVmEvent()
if (gui.Data.Current != nil) { prepareAndSend(event)
event.Token = gui.Data.Current.Token
event.Username = gui.Data.Current.Username
}
log.Println("\tTRIGGERING event.Token =", event.Token)
log.Println("\tTRIGGERING event.Username =", event.Username)
log.Println("\tTRIGGERING event.Email =", event.Email)
spew.Dump(event)
gorillaSendProtobuf(event)
log.Println("\tEVENT SENT TO GORILLA WEBSOCKET")
gui.Data.State = "READ PROTOBUF"
} }
if (gui.Data.State == "kill") { if (gui.Data.State == "kill") {
log.Println("gui.State = kill") log.Println("gui.State = kill")

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<TrustAnchor id="380DC50D-484E-40D0-A3AE-68F2B18F61C7" source="http://data.iana.org/root-anchors/root-anchors.xml">
<Zone>.</Zone>
<KeyDigest id="Kjqmt7v" validFrom="2010-07-15T00:00:00+00:00" validUntil="2019-01-11T00:00:00+00:00">
<KeyTag>19036</KeyTag>
<Algorithm>8</Algorithm>
<DigestType>2</DigestType>
<Digest>49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5</Digest>
</KeyDigest>
<KeyDigest id="Klajeyz" validFrom="2017-02-02T00:00:00+00:00">
<KeyTag>20326</KeyTag>
<Algorithm>8</Algorithm>
<DigestType>2</DigestType>
<Digest>E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D</Digest>
</KeyDigest>
</TrustAnchor>