Skip to content

Commit

Permalink
add admin UI for frpc
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Feb 1, 2019
1 parent d879b82 commit 96d7e2d
Show file tree
Hide file tree
Showing 39 changed files with 16,189 additions and 30 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ build: frps frpc

# compile assets into binary file
file:
rm -rf ./assets/static/*
cp -rf ./web/frps/dist/* ./assets/static
go get -d github.com/rakyll/statik
go install github.com/rakyll/statik
rm -rf ./assets/statik
rm -rf ./assets/frps/static/*
rm -rf ./assets/frpc/static/*
cp -rf ./web/frps/dist/* ./assets/frps/static
cp -rf ./web/frpc/dist/* ./assets/frpc/static
rm -rf ./assets/frps/statik
rm -rf ./assets/frpc/statik
go generate ./assets/...

fmt:
go fmt ./...

frps:
go build -o bin/frps ./cmd/frps
@cp -rf ./assets/static ./bin

frpc:
go build -o bin/frpc ./cmd/frpc
Expand Down
8 changes: 4 additions & 4 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

package assets

//go:generate statik -src=./static
//go:generate go fmt statik/statik.go
//go:generate statik -src=./frps/static -dest=./frps
//go:generate statik -src=./frpc/static -dest=./frpc
//go:generate go fmt ./frps/statik/statik.go
//go:generate go fmt ./frpc/statik/statik.go

import (
"io/ioutil"
Expand All @@ -24,8 +26,6 @@ import (
"path"

"github.com/rakyll/statik/fs"

_ "github.com/fatedier/frp/assets/statik"
)

var (
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions assets/frpc/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frp client admin UI</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?eb6e6e7683a17c61011d"></script><script type="text/javascript" src="vendor.js?1fbc6539feeed727105b"></script></body> </html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/frpc/static/vendor.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions assets/frpc/statik/statik.go

Large diffs are not rendered by default.

Binary file not shown.
Binary file added assets/frps/static/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/static/index.html → assets/frps/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?14bea8276eef86cc7c61"></script><script type="text/javascript" src="vendor.js?51925ec1a77936b64d61"></script></body> </html>
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?bc42bc4eff72df8da372"></script><script type="text/javascript" src="vendor.js?ee403fce53c8757fc931"></script></body> </html>
1 change: 1 addition & 0 deletions assets/frps/static/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/frps/static/vendor.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions assets/frps/statik/statik.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion assets/static/vendor.js

This file was deleted.

12 changes: 0 additions & 12 deletions assets/statik/statik.go

This file was deleted.

8 changes: 8 additions & 0 deletions client/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"time"

"github.com/fatedier/frp/assets"
"github.com/fatedier/frp/g"
frpNet "github.com/fatedier/frp/utils/net"

Expand All @@ -44,6 +45,13 @@ func (svr *Service) RunAdminServer(addr string, port int) (err error) {
router.HandleFunc("/api/config", svr.apiGetConfig).Methods("GET")
router.HandleFunc("/api/config", svr.apiPutConfig).Methods("PUT")

// view
router.Handle("/favicon.ico", http.FileServer(assets.FileSystem)).Methods("GET")
router.PathPrefix("/static/").Handler(frpNet.MakeHttpGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET")
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/static/", http.StatusMovedPermanently)
})

address := fmt.Sprintf("%s:%d", addr, port)
server := &http.Server{
Addr: address,
Expand Down
10 changes: 9 additions & 1 deletion client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync/atomic"
"time"

"github.com/fatedier/frp/assets"
"github.com/fatedier/frp/g"
"github.com/fatedier/frp/models/config"
"github.com/fatedier/frp/models/msg"
Expand Down Expand Up @@ -49,7 +50,14 @@ type Service struct {
closedCh chan int
}

func NewService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf) (svr *Service) {
func NewService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf) (svr *Service, err error) {
// Init assets
err = assets.Load("")
if err != nil {
err = fmt.Errorf("Load assets error: %v", err)
return
}

svr = &Service{
pxyCfgs: pxyCfgs,
visitorCfgs: visitorCfgs,
Expand Down
3 changes: 2 additions & 1 deletion cmd/frpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main // "github.com/fatedier/frp/cmd/frpc"
package main

import (
_ "github.com/fatedier/frp/assets/frpc/statik"
"github.com/fatedier/frp/cmd/frpc/sub"

"github.com/fatedier/golib/crypto"
Expand Down
6 changes: 5 additions & 1 deletion cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]co
},
}
}
svr := client.NewService(pxyCfgs, visitorCfgs)
svr, errRet := client.NewService(pxyCfgs, visitorCfgs)
if errRet != nil {
err = errRet
return
}

// Capture the exit signal if we use kcp.
if g.GlbClientCfg.Protocol == "kcp" {
Expand Down
4 changes: 3 additions & 1 deletion cmd/frps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main // "github.com/fatedier/frp/cmd/frps"
package main

import (
"github.com/fatedier/golib/crypto"

_ "github.com/fatedier/frp/assets/frps/statik"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewService() (svr *Service, err error) {
// Init group controller
svr.rc.TcpGroupCtl = group.NewTcpGroupCtl(svr.rc.TcpPortManager)

// Init assets.
// Init assets
err = assets.Load(cfg.AssetsDir)
if err != nil {
err = fmt.Errorf("Load assets error: %v", err)
Expand Down
14 changes: 14 additions & 0 deletions web/frpc/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
6 changes: 6 additions & 0 deletions web/frpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
node_modules/
dist/
npm-debug.log
.idea
.vscode/settings.json
6 changes: 6 additions & 0 deletions web/frpc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: dist build
build:
@npm run build

dev:
@npm run dev
Loading

0 comments on commit 96d7e2d

Please sign in to comment.