Skip to content

Commit

Permalink
Merge pull request #2 from ricoschulte/1-implement-the-sysclient-prot…
Browse files Browse the repository at this point in the history
…ocol

implementation of the Sysclient protocol
  • Loading branch information
ricoschulte authored Feb 6, 2023
2 parents 8ed001b + e35489c commit 41beeaf
Show file tree
Hide file tree
Showing 13 changed files with 2,140 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
# local sessions
myapps_session*


#### sysclient
# local sysclient sessions
sysclient_*.txt
# static folder for sysclient
devices/

# vscode
.vscode/

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# go-myapps

A golang client to connect to one or more myApps accounts of users at a innovaphone pbx via websocket.
- A golang client to connect to one or more myApps accounts of users at a innovaphone pbx via websocket.

- A implementation of the sysclient protocol. See README.md in the ./sysclient/ folder.

## Introduction

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ go 1.19
require (
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.8.1
gotest.tools v2.2.0+incompatible
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -17,3 +21,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
146 changes: 146 additions & 0 deletions sysclient/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Sysclient

An implementation of the Sysclient protocol described at [Sysclient protocol](https://sdk.innovaphone.com/13r3/doc/protocol/sysclient.htm)

- connects a Go client to the innovaphone Devices App as a sysclient like any other device.
- can be used to provide a web interface with text or other functions.
- or to record or check the configurations devices receive from the Devices app.
- useful during the development of myApps apps when they have to have access to devices. Allows to use mock/dummy devices instead of having to maintain real ones.

## Example usage of the libary

This example code deploys a sysclient that connects to the Devices app's websocket.
It then serves HTTP endpoints that are accessible through the interface in the Devices app.
It issues the requests with the received configurations on the console.

``` go
package main

import (
"fmt"
"net/http"
"time"

"github.com/ricoschulte/go-myapps/sysclient"
)



func main() {
// define the properties of the device that connects to the devices app as sysclient
identity := sysclient.Identity{
Id: "f19033480af9",
Product: "IP232",
Version: "13r2 dvl [13.4250/131286/1300]",
FwBuild: "134250",
BcBuild: "131286",
Major: "13r2",
Fw: "ip222.bin",
Bc: "boot222.bin",
Mini: false,
PbxActive: false,
Other: false,
Platform: sysclient.Platform{
Type: "PHONE",
},
EthIfs: []sysclient.EthIf{
{
If: "ETH0",
Ipv4: "172.16.4.141",
Ipv6: "2002:91fd:9d07:0:290:33ff:fe46:af2",
},
},
}

sc, err_creating_sysclient := sysclient.NewSysclient(
// the identity from above
identity,


// the Devices App URL to connect to
// ws[s]://<ip/host>[:<port>]/<domain></instance>/sysclients
"wss://apps.company.com/company.com/devices/sysclients",

// a timeout duration for the websocket
time.Duration(2*time.Second),

// InsecureSkipVerify: if true, the verification of the TLS certificate is skipped.
// Do not use in production. You have been warned.
false,

// a SeveMux for requested HTTP request, see below
getServeMux(),

// filenames to store the password of the sysclient and a received and decoded admin password
"sysclient_password.txt",
"sysclient_administrativepassword.txt",
)

// when no error has happend while creating the client ...
if err_creating_sysclient != nil {
panic(err_creating_sysclient)
}
// ... start it.
sc.Connect()

select {} // keep the program running
}

// create a ServeMux for handling Tunnel Http Requests
func getServeMux() *http.ServeMux {
mux := http.NewServeMux()

// Serve a file for the /admin.xml path
mux.HandleFunc("/admin.xml", func(w http.ResponseWriter, r *http.Request) {
response_text := `<html><body>`
response_text += fmt.Sprintf(`page on %s`, r.URL.Path)
response_text += "</body></html>"

w.Header().Add("Content-Length", fmt.Sprint(len(response_text)))
w.WriteHeader(http.StatusOK)
w.Write([]byte(response_text))
})

// Serve a file for the /CMD0/mod_cmd.xml endpoint the will receive configurations
mux.HandleFunc("/CMD0/mod_cmd.xml", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("---------------------------")
fmt.Println("received on", r.URL.Path)
fmt.Println("received headers", r.Header)
for key, value := range r.URL.Query() {
fmt.Println("received param", key, value)
}

response_text := `<html><body>`
response_text += fmt.Sprintf(`mod_cmd.xml page on %s`, r.URL.Path)
response_text += "</body></html>"

w.Header().Add("Content-Length", fmt.Sprint(len(response_text)))
w.WriteHeader(http.StatusOK)
w.Write([]byte(response_text))
})

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
// catch not existing path with error log
response_text := fmt.Sprintf("Path %s not found", r.URL.Path)
fmt.Println("REQUEST 404", r.URL.Path)
w.Header().Add("Content-Length", fmt.Sprint(len(response_text)))
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(response_text))

return
}

response_text := `<html><body>`
response_text += fmt.Sprintf(`page on %s`, r.URL.Path)
response_text += "</body></html>"

w.Header().Add("Content-Length", fmt.Sprint(len(response_text)))
w.WriteHeader(http.StatusOK)
w.Write([]byte(response_text))

})

return mux
}
```
Loading

0 comments on commit 41beeaf

Please sign in to comment.