Add initial web UI to pinecomms_c2

This commit is contained in:
0x1a8510f2 2022-10-07 07:01:03 +01:00
parent 782ba1dcb4
commit ec2ce5a677
Signed by: 0x1a8510f2
GPG Key ID: 1C692E355D76775D
6 changed files with 25 additions and 25 deletions

View File

@ -2,10 +2,13 @@ package main
import (
"crypto/ed25519"
"embed"
"encoding/hex"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"os/signal"
"strings"
@ -14,6 +17,9 @@ import (
"git.0x1a8510f2.space/wraith-labs/wraith-module-pinecomms/internal/pmanager"
)
//go:embed ui
var ui embed.FS
const (
DEFAULT_PANEL_LISTEN_ADDR = "127.0.0.1:48080"
DEFAULT_PANEL_ACCESS_TOKEN = "wraith!"
@ -88,18 +94,14 @@ func main() {
// Main body
//
// Define routes which should be accessible over pinecone.
/*routes := make(map[string]http.HandlerFunc)
for _, route := range []proto.Route{
proto.ROUTE_PING,
proto.ROUTE_SEND,
} {
routeString, routeHandler := route.Handler(func() {})
routes[routeString] = routeHandler
// Use pmanager non-pinecone webserver to host web UI and an API to communicate with it.
ui, err := fs.Sub(ui, "ui")
if err != nil {
panic(err)
}
pm.SetPineconeWebserverHandlers(routes)*/
pm.SetWebserverHandlers(map[string]http.Handler{
"/": http.FileServer(http.FS(ui)),
})
// Start pinecone.
go pm.Start()

View File

@ -0,0 +1 @@
Hello World

5
go.mod
View File

@ -3,7 +3,6 @@ module git.0x1a8510f2.space/wraith-labs/wraith-module-pinecomms
go 1.19
require (
github.com/cristalhq/jwt/v4 v4.0.2
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/matrix-org/pinecone v0.0.0-20221003135901-d05e7fbb5d8f
@ -22,10 +21,10 @@ require (
github.com/onsi/ginkgo v1.16.5 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/exp v0.0.0-20221004215720-b9f4876ce741 // indirect
golang.org/x/exp v0.0.0-20221006183845-316c7553db56 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
nhooyr.io/websocket v1.8.7 // indirect

10
go.sum
View File

@ -23,8 +23,6 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cristalhq/jwt/v4 v4.0.2 h1:g/AD3h0VicDamtlM70GWGElp8kssQEv+5wYd7L9WOhU=
github.com/cristalhq/jwt/v4 v4.0.2/go.mod h1:HnYraSNKDRag1DZP92rYHyrjyQHnVEHPNqesmzs+miQ=
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=
@ -236,8 +234,8 @@ golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b h1:huxqepDufQpLLIRXiVkTvn
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp v0.0.0-20221004215720-b9f4876ce741 h1:fGZugkZk2UgYBxtpKmvub51Yno1LJDeEsRp2xGD+0gY=
golang.org/x/exp v0.0.0-20221004215720-b9f4876ce741/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20221006183845-316c7553db56 h1:BrYbdKcCNjLyrN6aKqXy4hPw9qGI8IATkj4EWv9Q+kQ=
golang.org/x/exp v0.0.0-20221006183845-316c7553db56/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -319,8 +317,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220730100132-1609e554cd39/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 h1:AzgQNqF+FKwyQ5LbVrVqOcuuFB67N47F9+htZYH0wFM=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -47,7 +47,7 @@ type configSnapshot struct {
// efficiency, to allow nodes which also need to run a regular webserver to
// use the one used by pinecone for websockets. This saves allocating another
// port and other system resources.
webserverHandlers map[string]http.HandlerFunc
webserverHandlers map[string]http.Handler
}
// This struct represents the configuration for a pinecone manager. Values can be
@ -144,7 +144,7 @@ func (pm *manager) SetStaticPeers(u []string) {
pm.conf.staticPeers = u
}
func (pm *manager) SetWebserverHandlers(u map[string]http.HandlerFunc) {
func (pm *manager) SetWebserverHandlers(u map[string]http.Handler) {
defer pm.conf.autolock()()
pm.conf.webserverHandlers = u
@ -196,7 +196,7 @@ func (pm *manager) GetStaticPeers() []string {
return pm.conf.staticPeers
}
func (pm *manager) GetWebserverHandlers() map[string]http.HandlerFunc {
func (pm *manager) GetWebserverHandlers() map[string]http.Handler {
defer pm.conf.autorlock()()
return pm.conf.webserverHandlers

View File

@ -218,7 +218,7 @@ func (pm *manager) Start() {
// If additional handlers are configured for the webserver, add them.
for route, handler := range c.webserverHandlers {
httpRouter.HandleFunc(route, handler)
httpRouter.Handle(route, handler)
}
// Non-pinecone HTTP server.
@ -423,7 +423,7 @@ func GetInstance() *manager {
webserverDebugPath: "",
useMulticast: false,
staticPeers: []string{},
webserverHandlers: map[string]http.HandlerFunc{},
webserverHandlers: map[string]http.Handler{},
}
// Set default config values to ensure that the config is never