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)
filename := ""
// TODO: figure out how to look for this file in the right
// place under Linux, MacOS and Windows
// TODO: confirm this is correct for MacOS and Windows
if runtime.GOOS == "linux" {
log.Println("OS: Linux")
filename = user.HomeDir + "/.config/cloud-control-panel.json"
@ -59,28 +58,10 @@ func loadConfigFile() {
tmp := loadConfigFromFilename(filename)
config = &tmp
// os.Exit(1)
// junk := marshalEvent()
// spew.Dump(junk)
// config = unmarshalConfig(junk)
// config = unmarshalConfig(string(b))
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() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
@ -124,24 +105,14 @@ func parseFlags() {
log.Println("ENABLE 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 == "") {
config.Hostname = hostname
}
// never allow these to be set in the config file
config.Debugging = *debugging
config.Debugtable = *debugtable
log.Println("config.Width", config.Width)
log.Println("config.Debugging", config.Debugging)
}
func parseConfig() {
@ -151,30 +122,19 @@ func parseConfig() {
// override the config file from the command line
parseFlags()
log.Println("config.width", config.Width)
log.Println("config.height", config.Height)
log.Println("config.debugging", config.Debugging)
// use this to restore the default config
// defaultConfig, _ := packrBox.FindString("cloud.json")
// config = pb.MakeDefaultConfig()
// spew.Dump(config)
log.Println("config.width", config.Width)
log.Println("config.height", config.Height)
log.Println("config.debugging", config.Debugging)
}
func marshalEvent() string {
// This is how you marshal into JSON from a Protobuf
// Convert a Protobuf to JSON
func PBtoJSON() string {
// this makes a sample protobuf
c := pb.MakeDefaultConfig()
marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(c)
log.Println(stuff)
// also:
// var j *bytes.Buffer
// marshaler.Marshal(j, event)
// w.Write(j.Bytes())
return stuff
}
@ -194,17 +154,6 @@ func saveConfig() {
log.Println(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) {
log.Println("gorillaSendProtobuf() START", time.Now())
log.Println("gorillaSendProtobuf()", msg)
if (gorillaConn == nil) {
log.Println("gorillaSendProtobuf() gorillaConn == nil")
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)
if err != nil {
log.Println("gorilla Dial failed", err)
log.Println("gorillaDial failed", err)
} else {
log.Println("RESPONSE HEADER = ", resp.Header)
log.Println("RESPONSE HEADER = ", resp.Header)
resp.Header.Set("jcarrname", "jcarrvalue")
log.Println("RESPONSE HEADER = ", resp.Header)
gorillaConn = conn
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 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
// import "github.com/imdario/mergo"
// 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)
// 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) {
log.Println("Sleep for 1 second")
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?")
} else {
gui.Data.Current = b.Account
log.Println("mainMouseClick() setting current account = ", b.Account)
onExit("mainMouseClick() got b = nil")
}
log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")")
if (b.Action == "BACK") {
gui.Data.State = "splash"
} else if (b.Action == "QUIT") {
onExit(nil)
} else if (b.Action == "CREATE") {
log.Println("TRY TO ADD A NEW VIRTUAL MACHINE")
log.Println("\tTRIGGER CREATE VM")
gui.Data.State = "CREATE"
} else if (b.Action == "CONFIG") {
loadDefaultConfig()
gui.Data.State = "done"
} else if (b.Action == "DEBUG") {
log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)")
debug.PrintStack()
} else if (b.Action == "DEBUG FULL") {
log.Println("ATTEMPT FULL STACK DUMP")
buf := make([]byte, 1<<16)
runtime.Stack(buf, true)
log.Printf("%s", buf)
log.Println("FINISHED FULL STACK DUMP")
} else if (b.Action == "ADD") {
log.Println("\tSHOULD ADD ACCOUNT HERE")
if (gui.Data.CurrentTab != nil) {
gui.Data.Current = b.Account
log.Println("mainMouseClick() setting current account = ", b.Account)
log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")")
if (b.Action == "BACK") {
gui.Data.State = "splash"
} else if (b.Action == "QUIT") {
onExit(nil)
} else if (b.Action == "CREATE") {
log.Println("TRY TO ADD A NEW VIRTUAL MACHINE")
log.Println("\tTRIGGER CREATE VM")
gui.Data.State = "CREATE"
} else if (b.Action == "CONFIG") {
loadDefaultConfig()
gui.Data.State = "done"
} else if (b.Action == "DEBUG") {
log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)")
debug.PrintStack()
} else if (b.Action == "DEBUG FULL") {
log.Println("ATTEMPT FULL STACK DUMP")
buf := make([]byte, 1<<16)
runtime.Stack(buf, true)
log.Printf("%s", buf)
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) {
nick := gui.Data.CurrentTab.EntryNick.Text()
username := gui.Data.CurrentTab.EntryUser.Text()
@ -191,86 +195,86 @@ func mainMouseClick(b *gui.ButtonMap) {
config.Accounts = append(config.Accounts, acc)
}
}
} else if (b.Action == "LOGIN") {
log.Println("\tTRIGGER LOGIN ACCOUNT")
gui.Data.State = "SEND LOGIN"
count := 0
for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "NEW PROTOBUF") {
if (currentMessage == nil) {
gui.SocketError()
gui.Data.State = "done"
} else {
log.Println("LOGIN currentMessage =", currentMessage)
if (currentMessage.Type == pb.Event_OK) {
log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!")
msg := "On account " + b.Account.Nick + "\n"
gui.MessageWindow("Login OK", msg)
}
if (currentMessage.Type == pb.Event_FAIL) {
log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED")
msg := "On account " + b.Account.Nick + "\n"
msg += "pb.Comment = " + currentMessage.Comment + "\n"
msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n"
msg += "pb.Email = " + currentMessage.Email + "\n"
msg += "pb.Username = " + currentMessage.Username + "\n"
gui.ErrorWindow("Login Failed", msg)
}
currentMessage = nil
gui.Data.State = "done"
}
} else if (b.Action == "LOGIN") {
log.Println("\tTRIGGER LOGIN ACCOUNT")
gui.Data.State = "SEND LOGIN"
count := 0
for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "NEW PROTOBUF") {
if (currentMessage == nil) {
gui.SocketError()
gui.Data.State = "done"
} else {
log.Println("LOGIN currentMessage =", currentMessage)
if (currentMessage.Type == pb.Event_OK) {
log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!")
log.Println("LOGIN WAS OK!")
msg := "On account " + b.Account.Nick + "\n"
gui.MessageWindow("Login OK", msg)
}
if (currentMessage.Type == pb.Event_FAIL) {
log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED")
log.Println("LOGIN FAILED")
msg := "On account " + b.Account.Nick + "\n"
msg += "pb.Comment = " + currentMessage.Comment + "\n"
msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n"
msg += "pb.Email = " + currentMessage.Email + "\n"
msg += "pb.Username = " + currentMessage.Username + "\n"
gui.ErrorWindow("Login Failed", msg)
}
return
}
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil
gui.Data.State = "done"
return
}
return
}
} else if (b.Action == "SHOW") {
log.Println("\tTRIGGER DISPLAY ACCOUNT")
gui.Data.State = "SEND WEBSOCKET"
count := 0
for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "NEW PROTOBUF") {
if (currentMessage == nil) {
gui.SocketError()
gui.Data.State = "done"
} else {
count := countVMS(currentMessage)
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)
}
currentMessage = nil
gui.Data.State = "done"
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil
gui.Data.State = "done"
return
}
}
} else if (b.Action == "SHOW") {
log.Println("\tTRIGGER DISPLAY ACCOUNT")
gui.Data.State = "SEND WEBSOCKET"
count := 0
for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "NEW PROTOBUF") {
if (currentMessage == nil) {
gui.SocketError()
gui.Data.State = "done"
} else {
count := countVMS(currentMessage)
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
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") {
gui.ShowAccountQuestionTab()
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
func watchGUI() {
count := 0
@ -299,47 +314,19 @@ func watchGUI() {
time.Sleep(200 * time.Millisecond)
if (gui.Data.State == "SEND WEBSOCKET") {
log.Println("\tTRIGGERING SEND WEBSOCKET")
event := pb.MakeGetEvent()
if (gui.Data.Current != nil) {
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"
prepareAndSend(event)
}
if (gui.Data.State == "SEND LOGIN") {
log.Println("\tTRIGGERING LOGIN")
event := pb.MakeLoginEvent()
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("\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"
prepareAndSend(event)
}
if (gui.Data.State == "CREATE") {
log.Println("\tTRIGGERING CREATE HERE")
log.Println("\tTRIGGERING CREATE")
event := pb.MakeAddVmEvent()
if (gui.Data.Current != nil) {
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"
prepareAndSend(event)
}
if (gui.Data.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>