diff --git a/README.md b/README.md index e95abab..1225c11 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,8 @@ Authorize a device: ```bash my_subdomain="xxxx" -curl -X POST http://mgmt.example.com:3010/api/devices \ +my_mgmt_host=http://mgmt.example.com:3010 +curl -X POST $my_mgmt_host/api/devices \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "slug": "'$my_subdomain'" }' diff --git a/cmd/telebit/telebit.go b/cmd/telebit/telebit.go index 68324b5..28be566 100644 --- a/cmd/telebit/telebit.go +++ b/cmd/telebit/telebit.go @@ -243,7 +243,7 @@ func main() { done := make(chan error) for _, addr := range bindAddrs { - go func() { + go func(addr string) { fmt.Printf("Listening on %s\n", addr) ln, err := net.Listen("tcp", addr) if nil != err { @@ -256,7 +256,7 @@ func main() { done <- err return } - }() + }(addr) } //connected := make(chan net.Conn) @@ -296,7 +296,7 @@ func main() { }() //connected <- tun //tun := <-connected - fmt.Printf("Listening at %s\n", *relay) + fmt.Printf("Listening through %s\n", *relay) err = telebit.ListenAndServe(tun, mux) log.Fatal("Closed server: ", err) done <- err diff --git a/examples/client.env b/examples/client.env index 69f27c1..ad11c49 100644 --- a/examples/client.env +++ b/examples/client.env @@ -1,3 +1,5 @@ +MGMT_BASEURL=http://devices.example.com:3010 +CLIENT_SUBJECT=newbie RELAY=wss://devices.example.com:8443 SECRET=xxxxxxxxxxxxxxxx -LOCALS=https:xxx.devices.example.com:3000,http:xxx.devices.example.com:3000 +LOCALS=https:$CLIENT_SUBJECT.devices.example.com:3000,http:$CLIENT_SUBJECT.devices.example.com:3000 diff --git a/examples/register-new-device.sh b/examples/register-new-device.sh new file mode 100644 index 0000000..d9527fc --- /dev/null +++ b/examples/register-new-device.sh @@ -0,0 +1,9 @@ +source .env +TOKEN=$(go run -mod=vendor cmd/signjwt/*.go $SECRET) +MGMT_BASEURL=${MGMT_BASEURL:-"http://mgmt.example.com:3010"} + +CLIENT_SUBJECT=${CLIENT_SUBJECT:-"newbie"} +curl -X POST $MGMT_BASEURL/api/devices \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ "slug": "'$CLIENT_SUBJECT'" }' diff --git a/examples/run-as-client.sh b/examples/run-as-client.sh new file mode 100644 index 0000000..c39afe5 --- /dev/null +++ b/examples/run-as-client.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e +set -u + +go generate -mod=vendor ./... +go build -mod=vendor -o telebit cmd/telebit/*.go + +source .env + +ACME_RELAY_BASEURL=${ACME_RELAY_BASEURL:-"https://devices.examples.com"} +AUTH_BASEURL=${AUTH_BASEURL:-"https://devices.examples.com"} +CLIENT_SECRET=${CLIENT_SECRET:-"yyyyyyyyyyyyyyyy"} + +./telebit --acme-agree=true \ + --acme-relay $ACME_RELAY_BASEURL/api \ + --auth-url $AUTH_BASEURL/api \ + --app-id test-id --secret "$CLIENT_SECRET" diff --git a/examples/run-as-server.sh b/examples/run-as-server.sh new file mode 100644 index 0000000..a66e410 --- /dev/null +++ b/examples/run-as-server.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +set -u + +go generate -mod=vendor ./... +go build -mod=vendor -o telebit cmd/telebit/*.go + +source .env + +ADMIN_HOSTNAME=${ADMIN_HOSTNAME:-"devices.example.com"} +AUTH_BASEURL=${AUTH_BASEURL:-"https://devices.example.com"} +SECRET=${SECRET:-"xxxxxxxxxxxxxxxx"} + +./telebit --acme-agree=true \ + --admin-hostname $ADMIN_HOSTNAME \ + --auth-url $AUTH_BASEURL/api \ + --secret "$SECRET" \ + --listen 3020,3030