diff --git a/cmd/mesh/main.go b/cmd/mesh/main.go
index 008e0245..ca79e91f 100644
--- a/cmd/mesh/main.go
+++ b/cmd/mesh/main.go
@@ -294,10 +294,10 @@ func run(args yggArgs, ctx context.Context) {
return
}
//override httpaddress and wwwroot parameters in cfg
- if len(args.httpaddress) > 0 {
+ if len(cfg.HttpAddress) == 0 {
cfg.HttpAddress = args.httpaddress
}
- if len(args.wwwroot) > 0 {
+ if len(cfg.WwwRoot) == 0 {
cfg.WwwRoot = args.wwwroot
}
diff --git a/contrib/deb/generate-gui.sh b/contrib/deb/generate-gui.sh
index f87a7e91..a262dbfd 100755
--- a/contrib/deb/generate-gui.sh
+++ b/contrib/deb/generate-gui.sh
@@ -57,7 +57,7 @@ cat > /tmp/$PKGNAME/usr/share/applications/riv.desktop << EOF
Name=RiV mesh
GenericName=Mesh network
Comment=RiV-mesh is an early-stage implementation of a fully end-to-end encrypted IPv6 network
-Exec=sh -c "/usr/bin/mesh-ui /usr/share/riv/ui/index.html"
+Exec=sh -c "/usr/bin/mesh-ui http://localhost:19019"
Terminal=false
Type=Application
Icon=riv
diff --git a/contrib/macos/create-pkg-gui.sh b/contrib/macos/create-pkg-gui.sh
index df6181f7..10be6cef 100644
--- a/contrib/macos/create-pkg-gui.sh
+++ b/contrib/macos/create-pkg-gui.sh
@@ -54,7 +54,7 @@ cp contrib/macos/mesh.plist pkgbuild/root/Library/LaunchDaemons
cat > pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/open-mesh-ui << EOF
#!/usr/bin/env bash
-exec /Applications/RiV-mesh.app/Contents/MacOS/mesh-ui /Applications/RiV-mesh.app/Contents/Resources/ui/index.html 1>/tmp/mesh-ui.stdout.log 2>/tmp/mesh-ui.stderr.log
+exec /Applications/RiV-mesh.app/Contents/MacOS/mesh-ui http://localhost:19019 1>/tmp/mesh-ui.stdout.log 2>/tmp/mesh-ui.stderr.log
EOF
# Create the postinstall script
diff --git a/contrib/macos/mesh.plist b/contrib/macos/mesh.plist
index fb9bb01d..86461721 100644
--- a/contrib/macos/mesh.plist
+++ b/contrib/macos/mesh.plist
@@ -9,6 +9,12 @@
/Applications/RiV-mesh.app/Contents/MacOS/mesh
-useconffile
/etc/mesh.conf
+ -logto
+ /var/log/mesh.log
+ -httpaddress
+ http://localhost:19019
+ -wwwroot
+ /Applications/RiV-mesh.app/Contents/Resources/ui
KeepAlive
diff --git a/contrib/msi/build-msi-gui.sh b/contrib/msi/build-msi-gui.sh
index 1ff27896..66b9825d 100644
--- a/contrib/msi/build-msi-gui.sh
+++ b/contrib/msi/build-msi-gui.sh
@@ -52,8 +52,6 @@ PKGNAME=$(sh contrib/semver/name.sh)
PKGVERSION=$(sh contrib/msi/msversion.sh --bare)
PKGVERSIONMS=$(echo $PKGVERSION | tr - .)
PKGUIFOLDER=contrib/ui/mesh-ui/ui/
-PKGWEBVIEWRESOURCESFOLDER="${PKGUIFOLDER}assets/"
-PKGFONTSRESOURCESFOLDER="${PKGUIFOLDER}webfonts/"
PKGLICENSEFILE=LICENSE.rtf
@@ -112,6 +110,10 @@ else
exit 1
fi
+PKG_UI_ASSETS_ZIP=$(pwd)/ui.zip
+( cd "$PKGUIFOLDER" && 7z a "$PKG_UI_ASSETS_ZIP" * )
+PKG_UI_ASSETS_ZIP=ui.zip
+
if [ $PKGNAME != "master" ]; then
PKGDISPLAYNAME="RiV-mesh Network (${PKGNAME} branch)"
else
@@ -155,49 +157,10 @@ cat > wix.xml << EOF
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
wix.xml << EOF
Name="Mesh"
Start="auto"
Type="ownProcess"
- Arguments='-useconffile "%ALLUSERSPROFILE%\\RiV-mesh\\mesh.conf" -logto "%ALLUSERSPROFILE%\\RiV-mesh\\mesh.log"'
+ Arguments='-useconffile "%ALLUSERSPROFILE%\\RiV-mesh\\mesh.conf" -logto "%ALLUSERSPROFILE%\\RiV-mesh\\mesh.log" -httpaddress "http://localhost:19019" -wwwroot "[MeshInstallFolder]ui.zip"'
Vital="yes" />
wix.xml << EOF
DiskId="1"
Source="${PKGWEBVIEWFILELOADER}" />
+
+
@@ -268,7 +237,7 @@ cat > wix.xml << EOF
DiskId="1"
Source="updateconfig.bat"
KeyPath="yes"/>
-
+
@@ -276,9 +245,6 @@ cat > wix.xml << EOF
-
-
-
@@ -306,7 +272,7 @@ cat > wix.xml << EOF
@@ -325,7 +291,7 @@ cat > wix.xml << EOF
Description="RiV-mesh is IoT E2E encrypted network"
Directory="DesktopFolder"
Target="[MeshInstallFolder]mesh-ui.exe"
- Arguments="ui\index.html"
+ Arguments="http://localhost:19019"
WorkingDirectory="MeshInstallFolder"/>
wix.xml << EOF
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Name="RiV-mesh client"
Type="string"
- Value='"[MeshInstallFolder]mesh-ui.exe" "[MeshInstallFolder]ui\index.html"' />
+ Value='"[MeshInstallFolder]mesh-ui.exe" "http://localhost:19019"' />
ASSISTANCE_START_VIA_REGISTRY
diff --git a/contrib/systemd/mesh.service b/contrib/systemd/mesh.service
index 6cf5962f..f6c2557e 100644
--- a/contrib/systemd/mesh.service
+++ b/contrib/systemd/mesh.service
@@ -12,7 +12,7 @@ ProtectSystem=true
SyslogIdentifier=mesh
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE
ExecStartPre=+-/sbin/modprobe tun
-ExecStart=/usr/bin/mesh -useconffile /etc/mesh.conf
+ExecStart=/usr/bin/mesh -useconffile /etc/mesh.conf -logto /var/log/mesh.log -httpaddress "http://localhost:19019" -wwwroot "/usr/share/riv/ui"
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
TimeoutStopSec=5
diff --git a/go.mod b/go.mod
index 6b5c8383..2ca37c24 100644
--- a/go.mod
+++ b/go.mod
@@ -21,6 +21,8 @@ require (
golang.zx2c4.com/wireguard/windows v0.4.12
)
+require gerace.dev/zipfs v0.2.0 // indirect
+
require (
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
@@ -33,11 +35,11 @@ require (
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/uuid v1.1.2 // indirect
- github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/rivo/uniseg v0.2.0 // indirect
+ github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
diff --git a/go.sum b/go.sum
index 4c41cad8..8e39951c 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,5 @@
+gerace.dev/zipfs v0.2.0 h1:3U1GsasLdxGVhf7lCYbccsH4mpuSpMpLOy37GmfT+KY=
+gerace.dev/zipfs v0.2.0/go.mod h1:L6cxA6m8uVfWDawsBHnki/J6Gos5uSlu/6RJZhafrfQ=
github.com/Arceliar/ironwood v0.0.0-20221115123222-ec61cea2f439 h1:eOW6/XIs06TnUn9GPCnfv71CQZw8edP3u3mH3lZt6iM=
github.com/Arceliar/ironwood v0.0.0-20221115123222-ec61cea2f439/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk=
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 h1:WndgpSW13S32VLQ3ugUxx2EnnWmgba1kCqPkd4Gk1yQ=
@@ -79,6 +81,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
@@ -173,6 +176,7 @@ golang.zx2c4.com/wireguard/windows v0.4.12 h1:CUmbdWKVNzTSsVb4yUAiEwL3KsabdJkEPd
golang.zx2c4.com/wireguard/windows v0.4.12/go.mod h1:PW4y+d9oY83XU9rRwRwrJDwEMuhVjMxu2gfD1cfzS7w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/src/admin/admin.go b/src/admin/admin.go
index 6cfb3201..6d708398 100644
--- a/src/admin/admin.go
+++ b/src/admin/admin.go
@@ -5,14 +5,17 @@ import (
"errors"
"fmt"
"net"
- "net/url"
"net/http"
+ "net/url"
"os"
"sort"
+ "archive/zip"
"strings"
"time"
+ "gerace.dev/zipfs"
+
"github.com/RiV-chain/RiV-mesh/src/config"
"github.com/RiV-chain/RiV-mesh/src/core"
)
@@ -203,26 +206,26 @@ func (a *AdminSocket) SetupAdminHandlers() {
return res, nil
},
)
- _ = a.AddHandler("addPeers", "Add peers to this node", []string{"uri", "[interface]"}, func(in json.RawMessage) (interface{}, error) {
- req := &AddPeersRequest{}
- res := &AddPeersResponse{}
+ _ = a.AddHandler("addPeers", "Add peers to this node", []string{"uri", "[interface]"}, func(in json.RawMessage) (interface{}, error) {
+ req := &AddPeersRequest{}
+ res := &AddPeersResponse{}
- fmt.Println("json addpeers request %s", string(in[:]))
+ fmt.Println("json addpeers request %s", string(in[:]))
- if err := json.Unmarshal(in, &req); err != nil {
- return nil, err
- }
+ if err := json.Unmarshal(in, &req); err != nil {
+ return nil, err
+ }
- if err := a.addPeersHandler(req, res); err != nil {
- return nil, err
- }
- return res, nil
- })
- _ = a.AddHandler("removePeers", "Remove all peers from this node", []string{}, func(in json.RawMessage) (interface{}, error) {
- a.core.RemovePeers()
- res := &AddPeersResponse{}
- return res, nil
- })
+ if err := a.addPeersHandler(req, res); err != nil {
+ return nil, err
+ }
+ return res, nil
+ })
+ _ = a.AddHandler("removePeers", "Remove all peers from this node", []string{}, func(in json.RawMessage) (interface{}, error) {
+ a.core.RemovePeers()
+ res := &AddPeersResponse{}
+ return res, nil
+ })
//_ = a.AddHandler("getNodeInfo", []string{"key"}, t.proto.nodeinfo.nodeInfoAdminHandler)
//_ = a.AddHandler("debug_remoteGetSelf", []string{"key"}, t.proto.getSelfHandler)
@@ -232,16 +235,16 @@ func (a *AdminSocket) SetupAdminHandlers() {
// Start runs http server
func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
- if nc.HttpAddress != "none" && nc.HttpAddress != "" && nc.WwwRoot != "none" && nc.WwwRoot != ""{
+ if nc.HttpAddress != "none" && nc.HttpAddress != "" && nc.WwwRoot != "none" && nc.WwwRoot != "" {
u, err := url.Parse(nc.HttpAddress)
if err != nil {
a.log.Errorln("An error occurred parsing http address:", err)
return
}
- http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request){
+ http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Following methods are allowed: getself, getpeers. litening"+u.Host)
})
- http.HandleFunc("/api/getself", func(w http.ResponseWriter, r *http.Request){
+ http.HandleFunc("/api/getself", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
req := &GetSelfRequest{}
res := &GetSelfResponse{}
@@ -254,7 +257,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
}
fmt.Fprintf(w, string(b[:]))
})
- http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request){
+ http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
req := &GetPeersRequest{}
res := &GetPeersResponse{}
@@ -268,12 +271,25 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
}
fmt.Fprintf(w, string(b[:]))
})
- http.Handle("/", http.FileServer(http.Dir(nc.WwwRoot)))
+ var docFs = ""
+ pakReader, err := zip.OpenReader(nc.WwwRoot)
+ if err == nil {
+ defer pakReader.Close()
+ fs, err := zipfs.NewZipFileSystem(&pakReader.Reader, zipfs.ServeIndexForMissing())
+ if err == nil {
+ http.Handle("/", http.FileServer(fs))
+ docFs = "zipfs"
+ }
+ }
+ if docFs == "" {
+ http.Handle("/", http.FileServer(http.Dir(nc.WwwRoot)))
+ docFs = "local fs"
+ }
l, e := net.Listen("tcp4", u.Host)
if e != nil {
a.log.Errorln("%s\n", e)
} else {
- a.log.Infof("Http server listening on %s\n", u.Host)
+ a.log.Infof("Http server is listening on %s and is supplied from %s %s\n", nc.HttpAddress, docFs, nc.WwwRoot)
}
go func() {
a.log.Errorln(http.Serve(l, nil))