diff --git a/README.md b/README.md index 69d71ff2d..f0fb366fc 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,12 @@ It will listen to http and websocket connections on a range of ports from `8990` ### Discover the port You should make GET request to the `/info` endpoint on the possible ports, until you find a reply: - $ curl http://localhost:8990/info - curl: (7) Failed to connect to localhost port 8990: Connection refused - $ curl http://localhost:8991/info + $ curl http://127.0.0.1:8990/info + curl: (7) Failed to connect to 127.0.0.1 port 8990: Connection refused + $ curl http://127.0.0.1:8991/info  - $ curl http://localhost:8992/info - {"http":"http://localhost:8992","https":"https://localhost:8991","version":"1.0.36","ws":"ws://localhost:8992","wss":"wss://localhost:8991"} + $ curl http://127.0.0.1:8992/info + {"http":"http://127.0.0.1:8992","https":"https://127.0.0.1:8991","version":"1.0.36","ws":"ws://127.0.0.1:8992","wss":"wss://127.0.0.1:8991"} The reply will contain a json with info about the version and the http and https endpoints to use @@ -176,7 +176,7 @@ where you should replace /dev/ttyACM0 with the actual port and 9600 with the bau You will receive a message like: ```json -{ +{ "Cmd":"Open", "Desc":"Got register/open on port.", "Port":"/dev/ttyACM0", @@ -189,7 +189,7 @@ You will receive a message like: or ```json -{ +{ "Cmd":"OpenFail", "Desc":"Error opening port. Serial port busy", "Port":"/dev/ttyACM0", @@ -204,7 +204,7 @@ You can then close the port with You will receive a message like: ```json -{ +{ "Cmd":"Close", "Desc":"Got unregister/close on port.", "Port":"/dev/ttyACM0", @@ -216,7 +216,7 @@ or ```json -{ +{ "Error":"We could not find the serial port /dev/ttyACM0 that you were trying to close." } ``` @@ -238,7 +238,7 @@ with a reply like You can receive output from the serial port by listening to messages like this: ```json -{ +{ "D":"output string\r\n" } ``` diff --git a/certificates.go b/certificates.go index b84f46495..a27816649 100644 --- a/certificates.go +++ b/certificates.go @@ -29,7 +29,7 @@ import ( ) var ( - host = "localhost" + host = "127.0.0.1" validFrom = "" validFor = 365 * 24 * time.Hour * 2 // 2 years rsaBits = 2048 @@ -104,7 +104,7 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) { Subject: pkix.Name{ Organization: []string{"Arduino LLC US"}, Country: []string{"US"}, - CommonName: "localhost", + CommonName: "127.0.0.1", OrganizationalUnit: []string{"IT"}, }, NotBefore: notBefore, diff --git a/info.go b/info.go index 098b1a717..af41596dd 100644 --- a/info.go +++ b/info.go @@ -1,17 +1,23 @@ package main import ( + "strings" + "github.com/gin-gonic/gin" "go.bug.st/serial.v1" ) func infoHandler(c *gin.Context) { + host := c.Request.Host + parts := strings.Split(host, ":") + host = parts[0] + c.JSON(200, gin.H{ "version": version, - "http": "http://localhost" + port, - "https": "https://localhost" + portSSL, - "ws": "ws://localhost" + port, - "wss": "wss://localhost" + portSSL, + "http": "http://" + host + port, + "https": "https://" + host + portSSL, + "ws": "ws://" + host + port, + "wss": "wss://" + host + portSSL, }) } diff --git a/trayicon.go b/trayicon.go index 78c8f6ea9..533487623 100644 --- a/trayicon.go +++ b/trayicon.go @@ -83,7 +83,10 @@ func getConfigs() []ConfigIni { filepath.Walk(dest, func(path string, f os.FileInfo, _ error) error { if !f.IsDir() { if filepath.Ext(path) == ".ini" { - cfg, _ := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, filepath.Join(dest, f.Name())) + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, filepath.Join(dest, f.Name())) + if err != nil { + return err + } defaultSection, err := cfg.GetSection("") name := defaultSection.Key("name").String() if name == "" || err != nil { @@ -183,7 +186,7 @@ func setupSysTrayReal() { for { <-mDebug.ClickedCh logAction("log on") - open.Start("http://localhost" + port) + open.Start("http://127.0.0.1" + port) } }()