mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2025-09-26 19:31:18 +08:00
feat: fx
This commit is contained in:
2
.github/workflows/latest.workflow.yml
vendored
2
.github/workflows/latest.workflow.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.22.x"
|
||||
go-version: "1.24.x"
|
||||
- name: npm install and build
|
||||
run: |
|
||||
cd www
|
||||
|
2
.github/workflows/tag.workflow.yml
vendored
2
.github/workflows/tag.workflow.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.22.x"
|
||||
go-version: "1.24.x"
|
||||
- name: npm install and build
|
||||
run: |
|
||||
cd www
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -20,7 +20,6 @@ dist/
|
||||
.vite_opt_cache
|
||||
.vscode
|
||||
dist
|
||||
cache
|
||||
temp
|
||||
examples-temp
|
||||
node_modules
|
||||
|
@@ -3,9 +3,9 @@ package client
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
)
|
||||
|
||||
func StartPTYConnect(c *app.Context, req *pb.CommonRequest) (*pb.CommonResponse, error) {
|
||||
|
@@ -4,9 +4,9 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func RemoveFrpcHandler(ctx *app.Context, req *pb.RemoveFRPCRequest) (*pb.RemoveFRPCResponse, error) {
|
||||
|
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/client"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ func PullConfig(appInstance app.Application, clientID, clientSecret string) erro
|
||||
|
||||
logger.Logger(ctx).Infof("start to pull client config, clientID: [%s]", clientID)
|
||||
cli := appInstance.GetMasterCli()
|
||||
resp, err := cli.PullClientConfig(ctx, &pb.PullClientConfigReq{
|
||||
resp, err := cli.Call().PullClientConfig(ctx, &pb.PullClientConfigReq{
|
||||
Base: &pb.ClientBase{
|
||||
ClientId: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StartFRPCHandler(ctx *app.Context, req *pb.StartFRPCRequest) (*pb.StartFRPCResponse, error) {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StopFRPCHandler(ctx *app.Context, req *pb.StopFRPCRequest) (*pb.StopFRPCResponse, error) {
|
||||
|
@@ -3,11 +3,11 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StartSteamLogHandler(ctx *app.Context, req *pb.CommonRequest) (*pb.CommonResponse, error) {
|
||||
@@ -22,10 +22,10 @@ func initStreamLog(ctx *app.Context, h app.StreamLogHookMgr) {
|
||||
clientID := ctx.GetApp().GetConfig().Client.ID
|
||||
clientSecret := ctx.GetApp().GetConfig().Client.Secret
|
||||
|
||||
handler, err := ctx.GetApp().GetClientRPCHandler().GetCli().PushClientStreamLog(
|
||||
handler, err := ctx.GetApp().GetClientRPCHandler().GetCli().Call().PushClientStreamLog(
|
||||
context.Background())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logger.Logger(ctx).Error(err)
|
||||
}
|
||||
|
||||
h.AddStream(func(msg string) {
|
||||
|
@@ -3,11 +3,11 @@ package client
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/client"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func UpdateFrpcHander(ctx *app.Context, req *pb.UpdateFRPCRequest) (*pb.UpdateFRPCResponse, error) {
|
||||
|
@@ -4,16 +4,16 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/pty"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
||||
func StartPTYConnect(c *app.Context, req *pb.CommonRequest, initMsg *pb.PTYClientMessage) (*pb.CommonResponse, error) {
|
||||
conn, err := c.GetApp().GetClientRPCHandler().GetCli().PTYConnect(c)
|
||||
conn, err := c.GetApp().GetClientRPCHandler().GetCli().Call().PTYConnect(c)
|
||||
if err != nil {
|
||||
logger.Logger(c).WithError(err).Infof("rpc connect master error")
|
||||
return nil, err
|
||||
|
@@ -3,9 +3,9 @@ package common
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
)
|
||||
|
||||
func GetClientCert(ctx *app.Context, req *pb.GetClientCertRequest) (*pb.GetClientCertResponse, error) {
|
||||
|
@@ -3,10 +3,10 @@ package auth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/cache"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/cache"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@@ -3,18 +3,17 @@ package auth
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/cache"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/cache"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func InitAuth(appInstance app.Application) {
|
||||
appCtx := app.NewContext(context.Background(), appInstance)
|
||||
logrus.Info("start to init frp user auth token")
|
||||
logger.Logger(appCtx).Info("start to init frp user auth token")
|
||||
|
||||
u, err := dao.NewQuery(appCtx).AdminGetAllUsers()
|
||||
if err != nil {
|
||||
|
@@ -3,11 +3,11 @@ package auth
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/middleware"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
)
|
||||
|
||||
func LoginHandler(ctx *app.Context, req *pb.LoginRequest) (*pb.LoginResponse, error) {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@@ -3,10 +3,10 @@ package auth
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@@ -3,12 +3,12 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func DeleteClientHandler(ctx *app.Context, req *pb.DeleteClientRequest) (*pb.DeleteClientResponse, error) {
|
||||
|
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func RemoveFrpcHandler(c *app.Context, req *pb.RemoveFRPCRequest) (*pb.RemoveFRPCResponse, error) {
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,11 +3,11 @@ package client
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
"github.com/tiendc/go-deepcopy"
|
||||
)
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,11 +3,11 @@ package client
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,12 +3,12 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StartFRPCHandler(ctx *app.Context, req *pb.StartFRPCRequest) (*pb.StartFRPCResponse, error) {
|
||||
|
@@ -3,12 +3,12 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StopFRPCHandler(ctx *app.Context, req *pb.StopFRPCRequest) (*pb.StopFRPCResponse, error) {
|
||||
|
@@ -3,11 +3,11 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -5,15 +5,15 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
@@ -3,7 +3,6 @@ package master
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/auth"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/platform"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"github.com/VaalaCat/frp-panel/biz/master/streamlog"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/user"
|
||||
"github.com/VaalaCat/frp-panel/middleware"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
@@ -3,11 +3,11 @@ package platform
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@@ -4,14 +4,14 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/samber/lo"
|
||||
|
||||
|
@@ -3,12 +3,12 @@ package proxy
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
@@ -3,13 +3,13 @@ package proxy
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
// GetProxyStatsByClientID get proxy info by client id
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
// GetProxyStatsByServerID get proxy info by server id
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,10 +3,10 @@ package proxy
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,14 +3,14 @@ package proxy
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
)
|
||||
|
||||
func DeleteServerHandler(c *app.Context, req *pb.DeleteServerRequest) (*pb.DeleteServerResponse, error) {
|
||||
|
@@ -3,12 +3,12 @@ package server
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func RemoveFrpsHandler(c *app.Context, req *pb.RemoveFRPSRequest) (*pb.RemoveFRPSResponse, error) {
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,9 +3,9 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
)
|
||||
|
||||
type ValidateableServerRequest interface {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/cache"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/cache"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func FRPAuth(ctx *app.Context, req *pb.FRPAuthRequest) (*pb.FRPAuthResponse, error) {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
)
|
||||
|
||||
func PushProxyInfo(ctx *app.Context, req *pb.PushProxyInfoReq) (*pb.PushProxyInfoResp, error) {
|
||||
|
@@ -4,15 +4,15 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
)
|
||||
|
||||
|
@@ -7,11 +7,11 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/fatedier/golib/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/server"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func PTYConnect(ctx *app.Context, sender pb.Master_PTYConnectServer) error {
|
||||
|
@@ -6,12 +6,12 @@ import (
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/server"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@@ -5,11 +5,11 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
@@ -3,9 +3,9 @@ package user
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
|
@@ -3,14 +3,14 @@ package user
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func UpdateUserInfoHander(c *app.Context, req *pb.UpdateUserInfoRequest) (*pb.UpdateUserInfoResponse, error) {
|
||||
|
@@ -3,10 +3,10 @@ package server
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -68,7 +68,7 @@ func HandleLogin(ctx *app.Context) (interface{}, error) {
|
||||
return res, nil
|
||||
}
|
||||
cli := ctx.GetApp().GetMasterCli()
|
||||
authResponse, err := cli.FRPCAuth(ctx, &pb.FRPAuthRequest{User: content.User, Token: token})
|
||||
authResponse, err := cli.Call().FRPCAuth(ctx, &pb.FRPAuthRequest{User: content.User, Token: token})
|
||||
if err != nil {
|
||||
res.Reject = true
|
||||
res.RejectReason = "invalid meta token"
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
)
|
||||
|
||||
func StartPTYConnect(c *app.Context, req *pb.CommonRequest) (*pb.CommonResponse, error) {
|
||||
|
@@ -3,9 +3,9 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func RemoveFrpsHandler(ctx *app.Context, req *pb.RemoveFRPSRequest) (*pb.RemoveFRPSResponse, error) {
|
||||
|
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/server"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func PullConfig(appInstance app.Application, serverID, serverSecret string) error {
|
||||
@@ -16,7 +16,7 @@ func PullConfig(appInstance app.Application, serverID, serverSecret string) erro
|
||||
logger.Logger(ctx).Infof("start to pull server config, serverID: [%s]", serverID)
|
||||
|
||||
cli := appInstance.GetMasterCli()
|
||||
resp, err := cli.PullServerConfig(ctx, &pb.PullServerConfigReq{
|
||||
resp, err := cli.Call().PullServerConfig(ctx, &pb.PullServerConfigReq{
|
||||
Base: &pb.ServerBase{
|
||||
ServerId: serverID,
|
||||
ServerSecret: serverSecret,
|
||||
|
@@ -3,9 +3,9 @@ package server
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@@ -46,7 +46,7 @@ func PushProxyInfo(appInstance app.Application, serverID, serverSecret string) e
|
||||
if len(proxyInfos) > 0 {
|
||||
ctx := context.Background()
|
||||
cli := appInstance.GetMasterCli()
|
||||
_, err := cli.PushProxyInfo(ctx, &pb.PushProxyInfoReq{
|
||||
_, err := cli.Call().PushProxyInfo(ctx, &pb.PushProxyInfoReq{
|
||||
Base: &pb.ServerBase{
|
||||
ServerId: serverID,
|
||||
ServerSecret: serverSecret,
|
||||
|
@@ -3,11 +3,11 @@ package server
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func StartSteamLogHandler(ctx *app.Context, req *pb.CommonRequest) (*pb.CommonResponse, error) {
|
||||
@@ -22,10 +22,10 @@ func initStreamLog(ctx *app.Context, h app.StreamLogHookMgr) {
|
||||
clientID := ctx.GetApp().GetConfig().Client.ID
|
||||
clientSecret := ctx.GetApp().GetConfig().Client.Secret
|
||||
|
||||
handler, err := ctx.GetApp().GetClientRPCHandler().GetCli().PushServerStreamLog(
|
||||
handler, err := ctx.GetApp().GetClientRPCHandler().GetCli().Call().PushServerStreamLog(
|
||||
context.Background())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logger.Logger(ctx).Error(err)
|
||||
}
|
||||
|
||||
h.AddStream(func(msg string) {
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/server"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func UpdateFrpsHander(ctx *app.Context, req *pb.UpdateFRPSRequest) (*pb.UpdateFRPSResponse, error) {
|
||||
|
@@ -3,70 +3,81 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
bizclient "github.com/VaalaCat/frp-panel/biz/client"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
||||
"github.com/VaalaCat/frp-panel/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/watcher"
|
||||
"github.com/VaalaCat/frp-panel/services/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/services/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/fatedier/golib/crypto"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/sourcegraph/conc"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
func runClient(appInstance app.Application) {
|
||||
type runClientParam struct {
|
||||
fx.In
|
||||
|
||||
Lc fx.Lifecycle
|
||||
|
||||
Ctx *app.Context
|
||||
AppInstance app.Application
|
||||
TaskManager watcher.Client `name:"clientTaskManager"`
|
||||
Cfg conf.Config
|
||||
}
|
||||
|
||||
func runClient(param runClientParam) {
|
||||
var (
|
||||
c = context.Background()
|
||||
clientID = appInstance.GetConfig().Client.ID
|
||||
clientSecret = appInstance.GetConfig().Client.Secret
|
||||
ctx = param.Ctx
|
||||
clientID = param.AppInstance.GetConfig().Client.ID
|
||||
clientSecret = param.AppInstance.GetConfig().Client.Secret
|
||||
appInstance = param.AppInstance
|
||||
)
|
||||
crypto.DefaultSalt = appInstance.GetConfig().App.Secret
|
||||
logger.Logger(c).Infof("start to run client")
|
||||
crypto.DefaultSalt = param.AppInstance.GetConfig().App.Secret
|
||||
logger.Logger(ctx).Infof("start to run client")
|
||||
if len(clientSecret) == 0 {
|
||||
logrus.Fatal("client secret cannot be empty")
|
||||
logger.Logger(ctx).Fatal("client secret cannot be empty")
|
||||
}
|
||||
|
||||
if len(clientID) == 0 {
|
||||
logrus.Fatal("client id cannot be empty")
|
||||
logger.Logger(ctx).Fatal("client id cannot be empty")
|
||||
}
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(
|
||||
appInstance,
|
||||
clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPC))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
param.TaskManager.AddDurationTask(defs.PullConfigDuration,
|
||||
bizclient.PullConfig, appInstance, clientID, clientSecret)
|
||||
|
||||
appInstance.SetClientCred(cred)
|
||||
appInstance.SetMasterCli(rpc.NewMasterCli(appInstance))
|
||||
var wg conc.WaitGroup
|
||||
param.Lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
appInstance.SetRPCCred(NewClientCred(appInstance))
|
||||
appInstance.SetMasterCli(NewClientMasterCli(appInstance))
|
||||
appInstance.SetClientController(tunnel.NewClientController())
|
||||
|
||||
r := rpcclient.NewClientRPCHandler(
|
||||
cliRpcHandler := rpcclient.NewClientRPCHandler(
|
||||
appInstance,
|
||||
clientID,
|
||||
clientSecret,
|
||||
pb.Event_EVENT_REGISTER_CLIENT,
|
||||
bizclient.HandleServerMessage,
|
||||
)
|
||||
appInstance.SetClientRPCHandler(r)
|
||||
|
||||
w := watcher.NewClient()
|
||||
w.AddDurationTask(defs.PullConfigDuration,
|
||||
bizclient.PullConfig, appInstance, clientID, clientSecret)
|
||||
appInstance.SetClientRPCHandler(cliRpcHandler)
|
||||
|
||||
initClientOnce(appInstance, clientID, clientSecret)
|
||||
|
||||
defer w.Stop()
|
||||
defer r.Stop()
|
||||
wg.Go(cliRpcHandler.Run)
|
||||
wg.Go(param.TaskManager.Run)
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
param.TaskManager.Stop()
|
||||
appInstance.GetClientRPCHandler().Stop()
|
||||
|
||||
var wg conc.WaitGroup
|
||||
wg.Go(r.Run)
|
||||
wg.Go(w.Run)
|
||||
wg.Wait()
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func initClientOnce(appInstance app.Application, clientID, clientSecret string) {
|
||||
|
467
cmd/frpp/cmd.go
467
cmd/frpp/cmd.go
@@ -6,162 +6,264 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var (
|
||||
clientCmd *cobra.Command
|
||||
serverCmd *cobra.Command
|
||||
masterCmd *cobra.Command
|
||||
rootCmd *cobra.Command
|
||||
type CommonArgs struct {
|
||||
ClientSecret *string
|
||||
ClientID *string
|
||||
AppSecret *string
|
||||
RpcUrl *string
|
||||
ApiUrl *string
|
||||
|
||||
RpcHost *string
|
||||
ApiHost *string
|
||||
RpcPort *int
|
||||
ApiPort *int
|
||||
ApiScheme *string
|
||||
}
|
||||
|
||||
func buildCommand() *cobra.Command {
|
||||
cfg := conf.NewConfig()
|
||||
|
||||
return NewRootCmd(
|
||||
NewMasterCmd(cfg),
|
||||
NewClientCmd(cfg),
|
||||
NewServerCmd(cfg),
|
||||
NewJoinCmd(),
|
||||
NewInstallServiceCmd(),
|
||||
NewUninstallServiceCmd(),
|
||||
NewStartServiceCmd(),
|
||||
NewStopServiceCmd(),
|
||||
NewRestartServiceCmd(),
|
||||
NewVersionCmd(),
|
||||
)
|
||||
|
||||
func initCommand(appInstance app.Application) {
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "frp-panel",
|
||||
Short: "frp-panel is a frp panel QwQ",
|
||||
}
|
||||
CmdListWithFlag := initCmdWithFlag(appInstance)
|
||||
CmdListWithoutFlag := initCmdWithoutFlag(appInstance)
|
||||
rootCmd.AddCommand(CmdListWithFlag...)
|
||||
rootCmd.AddCommand(CmdListWithoutFlag...)
|
||||
}
|
||||
|
||||
func initCmdWithFlag(appInstance app.Application) []*cobra.Command {
|
||||
var (
|
||||
clientSecret string
|
||||
clientID string
|
||||
rpcHost string
|
||||
apiHost string
|
||||
appSecret string
|
||||
rpcPort int
|
||||
apiPort int
|
||||
apiScheme string
|
||||
joinToken string
|
||||
rpcUrl string
|
||||
apiUrl string
|
||||
)
|
||||
func AddCommonFlags(commonCmd *cobra.Command) {
|
||||
commonCmd.Flags().StringP("secret", "s", "", "client secret")
|
||||
commonCmd.Flags().StringP("id", "i", "", "client id")
|
||||
commonCmd.Flags().StringP("app", "a", "", "app secret")
|
||||
commonCmd.Flags().String("rpc-url", "", "rpc url, master rpc url, scheme can be grpc/ws/wss://hostname:port")
|
||||
commonCmd.Flags().String("api-url", "", "api url, master api url, scheme can be http/https://hostname:port")
|
||||
|
||||
clientCmd = &cobra.Command{
|
||||
Use: "client [-s client secret] [-i client id] [-a app secret] [-t api host] [-r rpc host] [-c rpc port] [-p api port]",
|
||||
Short: "run managed frpc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
run := func() {
|
||||
patchConfig(appInstance,
|
||||
apiHost, rpcHost, appSecret,
|
||||
clientID, clientSecret,
|
||||
apiScheme, rpcPort, apiPort,
|
||||
apiUrl, rpcUrl)
|
||||
runClient(appInstance)
|
||||
}
|
||||
if srv, err := utils.CreateSystemService(args, run); err != nil {
|
||||
run()
|
||||
} else {
|
||||
srv.Run()
|
||||
}
|
||||
},
|
||||
// deprecated start
|
||||
commonCmd.Flags().StringP("rpc", "r", "", "deprecated, use --rpc-url instead, rpc host, canbe ip or domain")
|
||||
commonCmd.Flags().StringP("api", "t", "", "deprecated, use --api-url instead, api host, canbe ip or domain")
|
||||
commonCmd.Flags().IntP("rpc-port", "c", 0, "deprecated, use --rpc-url instead, rpc port, master rpc port, scheme is grpc")
|
||||
commonCmd.Flags().IntP("api-port", "p", 0, "deprecated, use --api-url instead, api port, master api port, scheme is http/https")
|
||||
commonCmd.Flags().StringP("api-scheme", "e", "", "deprecated, use --api-url instead, api scheme, master api scheme, scheme is http/https")
|
||||
// deprecated end
|
||||
}
|
||||
|
||||
serverCmd = &cobra.Command{
|
||||
Use: "server [-s client secret] [-i client id] [-a app secret] [-r rpc host] [-c rpc port] [-p api port]",
|
||||
Short: "run managed frps",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
run := func() {
|
||||
patchConfig(appInstance,
|
||||
apiHost, rpcHost, appSecret,
|
||||
clientID, clientSecret,
|
||||
apiScheme, rpcPort, apiPort,
|
||||
apiUrl, rpcUrl)
|
||||
runServer(appInstance)
|
||||
}
|
||||
if srv, err := utils.CreateSystemService(args, run); err != nil {
|
||||
run()
|
||||
} else {
|
||||
srv.Run()
|
||||
}
|
||||
},
|
||||
func GetCommonArgs(cmd *cobra.Command) CommonArgs {
|
||||
var commonArgs CommonArgs
|
||||
|
||||
if clientSecret, err := cmd.Flags().GetString("secret"); err == nil {
|
||||
commonArgs.ClientSecret = &clientSecret
|
||||
}
|
||||
|
||||
if clientID, err := cmd.Flags().GetString("id"); err == nil {
|
||||
commonArgs.ClientID = &clientID
|
||||
}
|
||||
|
||||
if appSecret, err := cmd.Flags().GetString("app"); err == nil {
|
||||
commonArgs.AppSecret = &appSecret
|
||||
}
|
||||
|
||||
if rpcURL, err := cmd.Flags().GetString("rpc-url"); err == nil {
|
||||
commonArgs.RpcUrl = &rpcURL
|
||||
}
|
||||
|
||||
if apiURL, err := cmd.Flags().GetString("api-url"); err == nil {
|
||||
commonArgs.ApiUrl = &apiURL
|
||||
}
|
||||
|
||||
if rpcHost, err := cmd.Flags().GetString("rpc-host"); err == nil {
|
||||
commonArgs.RpcHost = &rpcHost
|
||||
}
|
||||
|
||||
if apiHost, err := cmd.Flags().GetString("api-host"); err == nil {
|
||||
commonArgs.ApiHost = &apiHost
|
||||
}
|
||||
|
||||
if rpcPort, err := cmd.Flags().GetInt("rpc-port"); err == nil {
|
||||
commonArgs.RpcPort = &rpcPort
|
||||
}
|
||||
|
||||
if apiPort, err := cmd.Flags().GetInt("api-port"); err == nil {
|
||||
commonArgs.ApiPort = &apiPort
|
||||
}
|
||||
|
||||
if apiScheme, err := cmd.Flags().GetString("api-scheme"); err == nil {
|
||||
commonArgs.ApiScheme = &apiScheme
|
||||
}
|
||||
|
||||
return commonArgs
|
||||
}
|
||||
|
||||
type JoinArgs struct {
|
||||
CommonArgs
|
||||
JoinToken *string
|
||||
}
|
||||
|
||||
func NewJoinCmd() *cobra.Command {
|
||||
joinCmd := &cobra.Command{
|
||||
Use: "join [-j join token] [-r rpc host] [-p api port] [-e api scheme]",
|
||||
Short: "join to master with token, save param to config",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pullRunConfig(appInstance,
|
||||
joinToken, appSecret, rpcHost,
|
||||
apiScheme, rpcPort, apiPort,
|
||||
clientID, apiHost,
|
||||
apiUrl, rpcUrl)
|
||||
commonArgs := GetCommonArgs(cmd)
|
||||
joinArgs := &JoinArgs{
|
||||
CommonArgs: commonArgs,
|
||||
}
|
||||
if joinToken, err := cmd.Flags().GetString("join-token"); err == nil {
|
||||
joinArgs.JoinToken = &joinToken
|
||||
}
|
||||
|
||||
appInstance := app.NewApp()
|
||||
pullRunConfig(appInstance, joinArgs)
|
||||
},
|
||||
}
|
||||
|
||||
clientCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
|
||||
serverCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
|
||||
clientCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
|
||||
serverCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
|
||||
joinCmd.Flags().StringP("join-token", "j", "", "your token from master")
|
||||
AddCommonFlags(joinCmd)
|
||||
|
||||
clientCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret")
|
||||
serverCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret")
|
||||
|
||||
serverCmd.Flags().StringVar(&rpcUrl, "rpc-url", "", "rpc url, master rpc url, scheme can be grpc/ws/wss://hostname:port")
|
||||
clientCmd.Flags().StringVar(&rpcUrl, "rpc-url", "", "rpc url, master rpc url, scheme can be grpc/ws/wss://hostname:port")
|
||||
|
||||
serverCmd.Flags().StringVar(&apiUrl, "api-url", "", "api url, master api url, scheme can be http/https://hostname:port")
|
||||
clientCmd.Flags().StringVar(&apiUrl, "api-url", "", "api url, master api url, scheme can be http/https://hostname:port")
|
||||
|
||||
// deprecated start
|
||||
clientCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "deprecated, use --rpc-url instead, rpc host, canbe ip or domain")
|
||||
serverCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "deprecated, use --rpc-url instead, rpc host, canbe ip or domain")
|
||||
clientCmd.Flags().StringVarP(&apiHost, "api", "t", "", "deprecated, use --api-url instead, api host, canbe ip or domain")
|
||||
serverCmd.Flags().StringVarP(&apiHost, "api", "t", "", "deprecated, use --api-url instead, api host, canbe ip or domain")
|
||||
clientCmd.Flags().IntVarP(&rpcPort, "rpc-port", "c", 0, "deprecated, use --rpc-url instead, rpc port, master rpc port, scheme is grpc")
|
||||
serverCmd.Flags().IntVarP(&rpcPort, "rpc-port", "c", 0, "deprecated, use --rpc-url instead, rpc port, master rpc port, scheme is grpc")
|
||||
clientCmd.Flags().IntVarP(&apiPort, "api-port", "p", 0, "deprecated, use --api-url instead, api port, master api port, scheme is http/https")
|
||||
serverCmd.Flags().IntVarP(&apiPort, "api-port", "p", 0, "deprecated, use --api-url instead, api port, master api port, scheme is http/https")
|
||||
clientCmd.Flags().StringVarP(&apiScheme, "api-scheme", "e", "", "deprecated, use --api-url instead, api scheme, master api scheme, scheme is http/https")
|
||||
serverCmd.Flags().StringVarP(&apiScheme, "api-scheme", "e", "", "deprecated, use --api-url instead, api scheme, master api scheme, scheme is http/https")
|
||||
joinCmd.Flags().IntVarP(&rpcPort, "rpc-port", "c", 0, "deprecated, use --rpc-url instead, rpc port, master rpc port, scheme is grpc")
|
||||
joinCmd.Flags().IntVarP(&apiPort, "api-port", "p", 0, "deprecated, use --api-url instead, api port, master api port, scheme is http/https")
|
||||
joinCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "deprecated, use --rpc-url instead, rpc host, canbe ip or domain")
|
||||
joinCmd.Flags().StringVarP(&apiHost, "api", "t", "", "deprecated, use --api-url instead, api host, canbe ip or domain")
|
||||
joinCmd.Flags().StringVarP(&apiScheme, "api-scheme", "e", "", "deprecated, use --api-url instead, api scheme, master api scheme, scheme is http/https")
|
||||
// deprecated end
|
||||
|
||||
joinCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret")
|
||||
joinCmd.Flags().StringVarP(&joinToken, "join-token", "j", "", "your token from master")
|
||||
joinCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
|
||||
joinCmd.Flags().StringVar(&rpcUrl, "rpc-url", "", "rpc url, master rpc url, scheme can be grpc/ws/wss://hostname:port")
|
||||
joinCmd.Flags().StringVar(&apiUrl, "api-url", "", "api url, master api url, scheme can be http/https://hostname:port")
|
||||
|
||||
return []*cobra.Command{clientCmd, serverCmd, joinCmd}
|
||||
return joinCmd
|
||||
}
|
||||
|
||||
func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
masterCmd = &cobra.Command{
|
||||
func NewMasterCmd(cfg conf.Config) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "master",
|
||||
Short: "run frp-panel manager",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
opts := []fx.Option{
|
||||
commonMod,
|
||||
masterMod,
|
||||
serverMod,
|
||||
fx.Supply(
|
||||
CommonArgs{},
|
||||
fx.Annotate(cfg, fx.ResultTags(`name:"originConfig"`)),
|
||||
),
|
||||
fx.Provide(fx.Annotate(NewDefaultServerConfig, fx.ResultTags(`name:"defaultServerConfig"`))),
|
||||
fx.Invoke(runMaster),
|
||||
fx.Invoke(runServer),
|
||||
}
|
||||
|
||||
if !cfg.IsDebug {
|
||||
opts = append(opts, fx.NopLogger)
|
||||
}
|
||||
|
||||
run := func() {
|
||||
runMaster(appInstance)
|
||||
masterApp := fx.New(opts...)
|
||||
masterApp.Run()
|
||||
if err := masterApp.Err(); err != nil {
|
||||
logger.Logger(context.Background()).Fatalf("masterApp FX Application Error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if srv, err := utils.CreateSystemService(args, run); err != nil {
|
||||
run()
|
||||
} else {
|
||||
srv.Run()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewClientCmd(cfg conf.Config) *cobra.Command {
|
||||
clientCmd := &cobra.Command{
|
||||
Use: "client [-s client secret] [-i client id] [-a app secret] [-t api host] [-r rpc host] [-c rpc port] [-p api port]",
|
||||
Short: "run managed frpc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
commonArgs := GetCommonArgs(cmd)
|
||||
|
||||
opts := []fx.Option{
|
||||
clientMod,
|
||||
commonMod,
|
||||
fx.Supply(
|
||||
commonArgs,
|
||||
fx.Annotate(cfg, fx.ResultTags(`name:"originConfig"`)),
|
||||
),
|
||||
fx.Invoke(runClient),
|
||||
}
|
||||
|
||||
if !cfg.IsDebug {
|
||||
opts = append(opts, fx.NopLogger)
|
||||
}
|
||||
|
||||
run := func() {
|
||||
clientApp := fx.New(opts...)
|
||||
clientApp.Run()
|
||||
if err := clientApp.Err(); err != nil {
|
||||
logger.Logger(context.Background()).Fatalf("clientApp FX Application Error: %v", err)
|
||||
}
|
||||
}
|
||||
if srv, err := utils.CreateSystemService(args, run); err != nil {
|
||||
runMaster(appInstance)
|
||||
run()
|
||||
} else {
|
||||
srv.Run()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
installServiceCmd := &cobra.Command{
|
||||
AddCommonFlags(clientCmd)
|
||||
|
||||
return clientCmd
|
||||
}
|
||||
|
||||
func NewServerCmd(cfg conf.Config) *cobra.Command {
|
||||
serverCmd := &cobra.Command{
|
||||
Use: "server [-s client secret] [-i client id] [-a app secret] [-r rpc host] [-c rpc port] [-p api port]",
|
||||
Short: "run managed frps",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
commonArgs := GetCommonArgs(cmd)
|
||||
opts := []fx.Option{
|
||||
serverMod,
|
||||
commonMod,
|
||||
fx.Supply(
|
||||
commonArgs,
|
||||
fx.Annotate(cfg, fx.ResultTags(`name:"originConfig"`)),
|
||||
),
|
||||
fx.Invoke(runServer),
|
||||
}
|
||||
|
||||
if !cfg.IsDebug {
|
||||
opts = append(opts, fx.NopLogger)
|
||||
}
|
||||
|
||||
run := func() {
|
||||
serverApp := fx.New(opts...)
|
||||
serverApp.Run()
|
||||
if err := serverApp.Err(); err != nil {
|
||||
logger.Logger(context.Background()).Fatalf("serverApp FX Application Error: %v", err)
|
||||
}
|
||||
}
|
||||
if srv, err := utils.CreateSystemService(args, run); err != nil {
|
||||
run()
|
||||
} else {
|
||||
srv.Run()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
AddCommonFlags(serverCmd)
|
||||
|
||||
return serverCmd
|
||||
}
|
||||
|
||||
func NewInstallServiceCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "install frp-panel as service",
|
||||
DisableFlagParsing: true,
|
||||
@@ -170,8 +272,10 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
utils.ControlSystemService(args, "install", func() {})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
uninstallServiceCmd := &cobra.Command{
|
||||
func NewUninstallServiceCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "uninstall",
|
||||
Short: "uninstall frp-panel service",
|
||||
DisableFlagParsing: true,
|
||||
@@ -180,8 +284,10 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
utils.ControlSystemService(args, "uninstall", func() {})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
startServiceCmd := &cobra.Command{
|
||||
func NewStartServiceCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "start frp-panel service",
|
||||
DisableFlagParsing: true,
|
||||
@@ -190,8 +296,10 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
utils.ControlSystemService(args, "start", func() {})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
stopServiceCmd := &cobra.Command{
|
||||
func NewStopServiceCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "stop frp-panel service",
|
||||
DisableFlagParsing: true,
|
||||
@@ -200,8 +308,10 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
utils.ControlSystemService(args, "stop", func() {})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
restartServiceCmd := &cobra.Command{
|
||||
func NewRestartServiceCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "restart",
|
||||
Short: "restart frp-panel service",
|
||||
DisableFlagParsing: true,
|
||||
@@ -210,8 +320,10 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
utils.ControlSystemService(args, "restart", func() {})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
versionCmd := &cobra.Command{
|
||||
func NewVersionCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version info of frp-panel",
|
||||
Long: `All software has versions. This is frp-panel's`,
|
||||
@@ -219,70 +331,60 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
fmt.Println(conf.GetVersion().String())
|
||||
},
|
||||
}
|
||||
return []*cobra.Command{
|
||||
masterCmd,
|
||||
installServiceCmd,
|
||||
uninstallServiceCmd,
|
||||
startServiceCmd,
|
||||
stopServiceCmd,
|
||||
restartServiceCmd,
|
||||
versionCmd,
|
||||
}
|
||||
}
|
||||
|
||||
func initLogger() {
|
||||
logger.Instance().SetReportCaller(true)
|
||||
logrus.SetReportCaller(true)
|
||||
}
|
||||
|
||||
func patchConfig(appInstance app.Application, apiHost, rpcHost, secret, clientID, clientSecret, apiScheme string, rpcPort, apiPort int, apiUrl, rpcUrl string) {
|
||||
func patchConfig(appInstance app.Application, commonArgs CommonArgs) conf.Config {
|
||||
c := context.Background()
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
if len(rpcHost) != 0 {
|
||||
tmpCfg.Master.RPCHost = rpcHost
|
||||
tmpCfg.Master.APIHost = rpcHost
|
||||
|
||||
if commonArgs.RpcHost != nil {
|
||||
tmpCfg.Master.RPCHost = *commonArgs.RpcHost
|
||||
tmpCfg.Master.APIHost = *commonArgs.RpcHost
|
||||
}
|
||||
|
||||
if len(apiHost) != 0 {
|
||||
tmpCfg.Master.APIHost = apiHost
|
||||
if commonArgs.ApiHost != nil {
|
||||
tmpCfg.Master.APIHost = *commonArgs.ApiHost
|
||||
}
|
||||
|
||||
if len(secret) != 0 {
|
||||
tmpCfg.App.Secret = secret
|
||||
if commonArgs.AppSecret != nil {
|
||||
tmpCfg.App.Secret = *commonArgs.AppSecret
|
||||
}
|
||||
if rpcPort != 0 {
|
||||
tmpCfg.Master.RPCPort = rpcPort
|
||||
if commonArgs.RpcPort != nil {
|
||||
tmpCfg.Master.RPCPort = *commonArgs.RpcPort
|
||||
}
|
||||
if apiPort != 0 {
|
||||
tmpCfg.Master.APIPort = apiPort
|
||||
if commonArgs.ApiPort != nil {
|
||||
tmpCfg.Master.APIPort = *commonArgs.ApiPort
|
||||
}
|
||||
if len(apiScheme) != 0 {
|
||||
tmpCfg.Master.APIScheme = apiScheme
|
||||
if commonArgs.ApiScheme != nil {
|
||||
tmpCfg.Master.APIScheme = *commonArgs.ApiScheme
|
||||
}
|
||||
if len(clientID) != 0 {
|
||||
tmpCfg.Client.ID = clientID
|
||||
if commonArgs.ClientID != nil {
|
||||
tmpCfg.Client.ID = *commonArgs.ClientID
|
||||
}
|
||||
if len(clientSecret) != 0 {
|
||||
tmpCfg.Client.Secret = clientSecret
|
||||
if commonArgs.ClientSecret != nil {
|
||||
tmpCfg.Client.Secret = *commonArgs.ClientSecret
|
||||
}
|
||||
|
||||
if len(apiUrl) != 0 {
|
||||
tmpCfg.Client.APIUrl = apiUrl
|
||||
if commonArgs.ApiUrl != nil {
|
||||
tmpCfg.Client.APIUrl = *commonArgs.ApiUrl
|
||||
}
|
||||
if len(rpcUrl) != 0 {
|
||||
tmpCfg.Client.RPCUrl = rpcUrl
|
||||
if commonArgs.RpcUrl != nil {
|
||||
tmpCfg.Client.RPCUrl = *commonArgs.RpcUrl
|
||||
}
|
||||
|
||||
if rpcPort != 0 || apiPort != 0 || len(apiScheme) != 0 || len(rpcHost) != 0 || len(apiHost) != 0 {
|
||||
if commonArgs.RpcPort != nil || commonArgs.ApiPort != nil ||
|
||||
commonArgs.ApiScheme != nil ||
|
||||
commonArgs.RpcHost != nil || commonArgs.ApiHost != nil {
|
||||
logger.Logger(c).Warnf("deprecatedenv configs !!! rpc host: %s, rpc port: %d, api host: %s, api port: %d, api scheme: %s",
|
||||
tmpCfg.Master.RPCHost, tmpCfg.Master.RPCPort,
|
||||
tmpCfg.Master.APIHost, tmpCfg.Master.APIPort,
|
||||
tmpCfg.Master.APIScheme)
|
||||
}
|
||||
logger.Logger(c).Infof("env config, api url: %s, rpc url: %s", tmpCfg.Client.APIUrl, tmpCfg.Client.RPCUrl)
|
||||
return tmpCfg
|
||||
}
|
||||
|
||||
func setMasterCommandIfNonePresent() {
|
||||
func setMasterCommandIfNonePresent(rootCmd *cobra.Command) {
|
||||
cmd, _, err := rootCmd.Find(os.Args[1:])
|
||||
if err == nil && cmd.Use == rootCmd.Use && cmd.Flags().Parse(os.Args[1:]) != pflag.ErrHelp {
|
||||
args := append([]string{"master"}, os.Args[1:]...)
|
||||
@@ -290,9 +392,9 @@ func setMasterCommandIfNonePresent() {
|
||||
}
|
||||
}
|
||||
|
||||
func pullRunConfig(appInstance app.Application, joinToken, appSecret, rpcHost, apiScheme string, rpcPort, apiPort int, clientID, apiHost string, apiUrl, rpcUrl string) {
|
||||
func pullRunConfig(appInstance app.Application, joinArgs *JoinArgs) {
|
||||
c := context.Background()
|
||||
if err := checkPullParams(joinToken, apiHost, apiScheme, apiPort, apiUrl); err != nil {
|
||||
if err := checkPullParams(joinArgs); err != nil {
|
||||
logger.Logger(c).Errorf("check pull params failed: %s", err.Error())
|
||||
return
|
||||
}
|
||||
@@ -302,14 +404,16 @@ func pullRunConfig(appInstance app.Application, joinToken, appSecret, rpcHost, a
|
||||
return
|
||||
}
|
||||
|
||||
if len(clientID) == 0 {
|
||||
var clientID string
|
||||
|
||||
if cliID := joinArgs.ClientID; cliID == nil || len(*cliID) == 0 {
|
||||
clientID = utils.GetHostnameWithIP()
|
||||
}
|
||||
|
||||
clientID = utils.MakeClientIDPermited(clientID)
|
||||
patchConfig(appInstance, apiHost, rpcHost, appSecret, "", "", apiScheme, rpcPort, apiPort, apiUrl, rpcUrl)
|
||||
patchConfig(appInstance, joinArgs.CommonArgs)
|
||||
|
||||
initResp, err := rpc.InitClient(appInstance, clientID, joinToken)
|
||||
initResp, err := rpc.InitClient(appInstance, clientID, *joinArgs.JoinToken)
|
||||
if err != nil {
|
||||
logger.Logger(c).Errorf("init client failed: %s", err.Error())
|
||||
return
|
||||
@@ -324,7 +428,7 @@ func pullRunConfig(appInstance app.Application, joinToken, appSecret, rpcHost, a
|
||||
}
|
||||
|
||||
clientID = initResp.GetClientId()
|
||||
clientResp, err := rpc.GetClient(appInstance, clientID, joinToken)
|
||||
clientResp, err := rpc.GetClient(appInstance, clientID, *joinArgs.JoinToken)
|
||||
if err != nil {
|
||||
logger.Logger(c).Errorf("get client failed: %s", err.Error())
|
||||
return
|
||||
@@ -350,11 +454,11 @@ func pullRunConfig(appInstance app.Application, joinToken, appSecret, rpcHost, a
|
||||
logger.Logger(c).Warnf("read env file failed, try to create: %s", err.Error())
|
||||
}
|
||||
|
||||
envMap[defs.EnvAppSecret] = appSecret
|
||||
envMap[defs.EnvAppSecret] = *joinArgs.AppSecret
|
||||
envMap[defs.EnvClientID] = clientID
|
||||
envMap[defs.EnvClientSecret] = client.GetSecret()
|
||||
envMap[defs.EnvClientAPIUrl] = apiUrl
|
||||
envMap[defs.EnvClientRPCUrl] = rpcUrl
|
||||
envMap[defs.EnvClientAPIUrl] = *joinArgs.ApiUrl
|
||||
envMap[defs.EnvClientRPCUrl] = *joinArgs.RpcUrl
|
||||
|
||||
if err = godotenv.Write(envMap, defs.SysEnvPath); err != nil {
|
||||
logger.Logger(c).Errorf("write env file failed: %s", err.Error())
|
||||
@@ -363,21 +467,34 @@ func pullRunConfig(appInstance app.Application, joinToken, appSecret, rpcHost, a
|
||||
logger.Logger(c).Infof("config saved to env file: %s, you can use `frp-panel client` without args to run client,\n\nconfig is: [%v]", defs.SysEnvPath, envMap)
|
||||
}
|
||||
|
||||
func checkPullParams(joinToken, apiHost, apiScheme string, apiPort int, apiUrl string) error {
|
||||
if len(joinToken) == 0 {
|
||||
func checkPullParams(joinArgs *JoinArgs) error {
|
||||
if joinToken := joinArgs.JoinToken; joinToken != nil && len(*joinToken) == 0 {
|
||||
return errors.New("join token is empty")
|
||||
}
|
||||
if len(apiUrl) == 0 {
|
||||
if len(apiHost) == 0 {
|
||||
|
||||
if apiUrl := joinArgs.ApiUrl; apiUrl == nil || len(*apiUrl) == 0 {
|
||||
if apiHost := joinArgs.ApiHost; apiHost == nil || len(*apiHost) == 0 {
|
||||
return errors.New("api host is empty")
|
||||
}
|
||||
if len(apiScheme) == 0 {
|
||||
if apiScheme := joinArgs.ApiScheme; apiScheme == nil || len(*apiScheme) == 0 {
|
||||
return errors.New("api scheme is empty")
|
||||
}
|
||||
}
|
||||
|
||||
if apiPort == 0 {
|
||||
if apiPort := joinArgs.ApiPort; apiPort == nil || *apiPort == 0 {
|
||||
return errors.New("api port is empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRootCmd(cmds ...*cobra.Command) *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "frp-panel",
|
||||
Short: "frp-panel is a frp panel QwQ",
|
||||
}
|
||||
|
||||
rootCmd.AddCommand(cmds...)
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
@@ -1,30 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/shell"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func main() {
|
||||
initLogger()
|
||||
logger.InitLogger()
|
||||
cobra.MousetrapHelpText = ""
|
||||
cfg := conf.NewConfig()
|
||||
|
||||
appInstance := app.NewApp()
|
||||
appInstance.SetConfig(cfg)
|
||||
appInstance.SetClientsManager(rpc.NewClientsManager())
|
||||
appInstance.SetStreamLogHookMgr(&common.HookMgr{})
|
||||
appInstance.SetShellPTYMgr(shell.NewPTYMgr())
|
||||
appInstance.SetClientRecvMap(&sync.Map{})
|
||||
|
||||
initCommand(appInstance)
|
||||
|
||||
setMasterCommandIfNonePresent()
|
||||
rootCmd := buildCommand()
|
||||
setMasterCommandIfNonePresent(rootCmd)
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
@@ -2,199 +2,77 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
bizmaster "github.com/VaalaCat/frp-panel/biz/master"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/auth"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/proxy"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/streamlog"
|
||||
bizserver "github.com/VaalaCat/frp-panel/biz/server"
|
||||
"github.com/VaalaCat/frp-panel/cache"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/cache"
|
||||
"github.com/VaalaCat/frp-panel/services/master"
|
||||
"github.com/VaalaCat/frp-panel/services/mux"
|
||||
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
||||
"github.com/VaalaCat/frp-panel/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/services/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/wsgrpc"
|
||||
"github.com/VaalaCat/frp-panel/watcher"
|
||||
"github.com/fatedier/golib/crypto"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sourcegraph/conc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
//go:embed all:out
|
||||
var fs embed.FS
|
||||
type runMasterParam struct {
|
||||
fx.In
|
||||
|
||||
func runMaster(appInstance app.Application) {
|
||||
c := app.NewContext(context.Background(), appInstance)
|
||||
cfg := appInstance.GetConfig()
|
||||
Lc fx.Lifecycle
|
||||
|
||||
Ctx *app.Context
|
||||
AppInstance app.Application
|
||||
DBManagerMgr app.DBManager
|
||||
HTTPMuxServer mux.MuxServer `name:"httpMux"`
|
||||
TLSMuxServer mux.MuxServer `name:"tlsMux"`
|
||||
MasterRouter *gin.Engine `name:"masterRouter"`
|
||||
ClientLogManager app.ClientLogManager
|
||||
WsGrpcHandler gin.HandlerFunc `name:"wsGrpcHandler"`
|
||||
MasterService master.MasterService `name:"wsMasterService"`
|
||||
TaskManager watcher.Client `name:"masterTaskManager"`
|
||||
WsListener *wsgrpc.WSListener
|
||||
DefaultServerConfig conf.Config `name:"defaultServerConfig"`
|
||||
}
|
||||
|
||||
func runMaster(param runMasterParam) {
|
||||
cfg := param.AppInstance.GetConfig()
|
||||
crypto.DefaultSalt = conf.MasterDefaultSalt(cfg)
|
||||
|
||||
appInstance.SetClientLogManager(streamlog.NewClientLogManager())
|
||||
param.AppInstance.SetClientLogManager(param.ClientLogManager)
|
||||
param.MasterRouter.GET("/wsgrpc", param.WsGrpcHandler)
|
||||
|
||||
initDatabase(c, appInstance)
|
||||
cache.InitCache(cfg)
|
||||
auth.InitAuth(appInstance)
|
||||
creds := dao.NewQuery(c).InitCert(conf.GetCertTemplate(cfg))
|
||||
cache.InitCache(param.AppInstance.GetConfig())
|
||||
auth.InitAuth(param.AppInstance)
|
||||
|
||||
router := bizmaster.NewRouter(fs, appInstance)
|
||||
|
||||
lisOpt := conf.GetListener(c, cfg)
|
||||
|
||||
// ---- ws grpc start -----
|
||||
wsListener := wsgrpc.NewWSListener("ws-listener", "wsgrpc", 100)
|
||||
|
||||
upgrader := &websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
router.GET("/wsgrpc", wsgrpc.GinWSHandler(wsListener, upgrader))
|
||||
// ---- ws grpc end -----
|
||||
|
||||
masterService := master.NewMasterService(appInstance, credentials.NewTLS(creds))
|
||||
server := masterService.GetServer()
|
||||
muxServer := mux.NewMux(server, router, lisOpt.MuxLis, creds)
|
||||
|
||||
masterH2CService := master.NewMasterService(appInstance, insecure.NewCredentials())
|
||||
serverH2c := masterH2CService.GetServer()
|
||||
httpMuxServer := mux.NewMux(serverH2c, router, lisOpt.ApiLis, nil)
|
||||
|
||||
tasks := watcher.NewClient()
|
||||
tasks.AddCronTask("0 0 3 * * *", proxy.CollectDailyStats, appInstance)
|
||||
defer tasks.Stop()
|
||||
param.TaskManager.AddCronTask("0 0 3 * * *", proxy.CollectDailyStats, param.AppInstance)
|
||||
defer param.TaskManager.Stop()
|
||||
|
||||
logger.Logger(param.Ctx).Infof("start to run master")
|
||||
var wg conc.WaitGroup
|
||||
|
||||
logger.Logger(c).Infof("start to run master")
|
||||
|
||||
go func() {
|
||||
wsGrpcServer := master.NewMasterService(appInstance, insecure.NewCredentials()).GetServer()
|
||||
if err := wsGrpcServer.Serve(wsListener); err != nil {
|
||||
logrus.Fatalf("gRPC server error: %v", err)
|
||||
param.Lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
wg.Go(func() {
|
||||
if err := param.MasterService.GetServer().Serve(param.WsListener); err != nil {
|
||||
logger.Logger(param.Ctx).Fatalf("gRPC server error: %v", err)
|
||||
}
|
||||
}()
|
||||
wg.Go(func() { runDefaultInternalServer(appInstance) })
|
||||
wg.Go(muxServer.Run)
|
||||
wg.Go(httpMuxServer.Run)
|
||||
wg.Go(tasks.Run)
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func initDatabase(c context.Context, appInstance app.Application) {
|
||||
logger.Logger(c).Infof("start to init database, type: %s", appInstance.GetConfig().DB.Type)
|
||||
mgr := models.NewDBManager(nil, appInstance.GetConfig().DB.Type)
|
||||
appInstance.SetDBManager(mgr)
|
||||
|
||||
if appInstance.GetConfig().IsDebug {
|
||||
appInstance.GetDBManager().SetDebug(true)
|
||||
}
|
||||
|
||||
switch appInstance.GetConfig().DB.Type {
|
||||
case "sqlite3":
|
||||
if err := utils.EnsureDirectoryExists(appInstance.GetConfig().DB.DSN); err != nil {
|
||||
logrus.WithError(err).Warnf("ensure directory failed, data location: [%s], keep data in current directory",
|
||||
appInstance.GetConfig().DB.DSN)
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
tmpCfg.DB.DSN = filepath.Base(appInstance.GetConfig().DB.DSN)
|
||||
appInstance.SetConfig(tmpCfg)
|
||||
logrus.Infof("new data location: [%s]", appInstance.GetConfig().DB.DSN)
|
||||
}
|
||||
|
||||
if sqlitedb, err := gorm.Open(sqlite.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logrus.Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("sqlite3", sqlitedb)
|
||||
logger.Logger(c).Infof("init database success, data location: [%s]", appInstance.GetConfig().DB.DSN)
|
||||
}
|
||||
case "mysql":
|
||||
if mysqlDB, err := gorm.Open(mysql.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logrus.Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("mysql", mysqlDB)
|
||||
logger.Logger(c).Infof("init database success, data type: [%s]", "mysql")
|
||||
}
|
||||
case "postgres":
|
||||
if postgresDB, err := gorm.Open(postgres.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logrus.Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("postgres", postgresDB)
|
||||
logger.Logger(c).Infof("init database success, data type: [%s]", "postgres")
|
||||
}
|
||||
default:
|
||||
logrus.Panicf("currently unsupported database type: %s", appInstance.GetConfig().DB.Type)
|
||||
}
|
||||
|
||||
appInstance.GetDBManager().Init()
|
||||
}
|
||||
|
||||
func runDefaultInternalServer(appInstance app.Application) {
|
||||
logger.Logger(context.Background()).Infof("init default internal server")
|
||||
|
||||
appCtx := app.NewContext(clientCmd.Context(), appInstance)
|
||||
|
||||
dao.NewQuery(appCtx).InitDefaultServer(appInstance.GetConfig().Master.APIHost)
|
||||
defaultServer, err := dao.NewQuery(appCtx).GetDefaultServer()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(
|
||||
appInstance,
|
||||
defaultServer.ServerID, defaultServer.ConnectSecret, pb.ClientType_CLIENT_TYPE_FRPS))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
appInstance.SetClientCred(cred)
|
||||
|
||||
appInstance.SetMasterCli(rpc.NewMasterCli(appInstance))
|
||||
appInstance.SetServerController(tunnel.NewServerController())
|
||||
|
||||
cliHandler := rpcclient.NewClientRPCHandler(
|
||||
appInstance,
|
||||
defaultServer.ServerID, defaultServer.ConnectSecret,
|
||||
pb.Event_EVENT_REGISTER_SERVER,
|
||||
bizserver.HandleServerMessage,
|
||||
)
|
||||
|
||||
appInstance.SetClientRPCHandler(cliHandler)
|
||||
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
tmpCfg.Client.ID = defaultServer.ServerID
|
||||
tmpCfg.Client.Secret = defaultServer.ConnectSecret
|
||||
appInstance.SetConfig(tmpCfg)
|
||||
|
||||
r := cliHandler
|
||||
|
||||
w := watcher.NewClient()
|
||||
w.AddDurationTask(defs.PullConfigDuration, bizserver.PullConfig, appInstance, defaultServer.ServerID, defaultServer.ConnectSecret)
|
||||
w.AddDurationTask(defs.PushProxyInfoDuration, bizserver.PushProxyInfo, appInstance, defaultServer.ServerID, defaultServer.ConnectSecret)
|
||||
|
||||
go initServerOnce(appInstance, defaultServer.ServerID, defaultServer.ConnectSecret)
|
||||
var wg conc.WaitGroup
|
||||
|
||||
defer w.Stop()
|
||||
defer r.Stop()
|
||||
|
||||
wg.Go(w.Run)
|
||||
wg.Go(r.Run)
|
||||
|
||||
})
|
||||
wg.Go(param.TLSMuxServer.Run)
|
||||
wg.Go(param.HTTPMuxServer.Run)
|
||||
wg.Go(param.TaskManager.Run)
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
param.MasterService.GetServer().Stop()
|
||||
param.TLSMuxServer.Stop()
|
||||
param.HTTPMuxServer.Stop()
|
||||
param.TaskManager.Stop()
|
||||
wg.Wait()
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
44
cmd/frpp/modules.go
Normal file
44
cmd/frpp/modules.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var (
|
||||
clientMod = fx.Module("cmd.client", fx.Provide(
|
||||
fx.Annotate(NewWatcher, fx.ResultTags(`name:"clientTaskManager"`)),
|
||||
))
|
||||
|
||||
serverMod = fx.Module("cmd.server", fx.Provide(
|
||||
fx.Annotate(NewServerAPI, fx.ResultTags(`name:"serverApiService"`)),
|
||||
fx.Annotate(NewServerRouter, fx.ResultTags(`name:"serverRouter"`)),
|
||||
fx.Annotate(NewWatcher, fx.ResultTags(`name:"serverTaskManager"`)),
|
||||
))
|
||||
|
||||
masterMod = fx.Module("cmd.master", fx.Provide(
|
||||
NewListenerOptions,
|
||||
NewDBManager,
|
||||
NewWSListener,
|
||||
NewMasterTLSConfig,
|
||||
NewWSUpgrader,
|
||||
NewFs,
|
||||
NewClientLogManager,
|
||||
fx.Annotate(NewWatcher, fx.ResultTags(`name:"masterTaskManager"`)),
|
||||
fx.Annotate(NewMasterRouter, fx.ResultTags(`name:"masterRouter"`)),
|
||||
fx.Annotate(NewHTTPMasterService, fx.ResultTags(`name:"httpMasterService"`)),
|
||||
fx.Annotate(NewHTTPMasterService, fx.ResultTags(`name:"wsMasterService"`)),
|
||||
fx.Annotate(NewTLSMasterService, fx.ResultTags(`name:"tlsMasterService"`)),
|
||||
fx.Annotate(NewMux, fx.ResultTags(`name:"tlsMux"`)),
|
||||
fx.Annotate(NewHTTPMux, fx.ResultTags(`name:"httpMux"`)),
|
||||
fx.Annotate(NewWSGrpcHandler, fx.ResultTags(`name:"wsGrpcHandler"`)),
|
||||
))
|
||||
|
||||
commonMod = fx.Module("common", fx.Provide(
|
||||
NewPatchedConfig,
|
||||
NewLogHookManager,
|
||||
NewPTYManager,
|
||||
NewBaseApp,
|
||||
NewContext,
|
||||
NewClientsManager,
|
||||
))
|
||||
)
|
278
cmd/frpp/providers.go
Normal file
278
cmd/frpp/providers.go
Normal file
@@ -0,0 +1,278 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"embed"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
bizcommon "github.com/VaalaCat/frp-panel/biz/common"
|
||||
bizmaster "github.com/VaalaCat/frp-panel/biz/master"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/shell"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/streamlog"
|
||||
bizserver "github.com/VaalaCat/frp-panel/biz/server"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/services/api"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/master"
|
||||
"github.com/VaalaCat/frp-panel/services/mux"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/wsgrpc"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/gorilla/websocket"
|
||||
"go.uber.org/fx"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
//go:embed all:out
|
||||
var fs embed.FS
|
||||
|
||||
func NewLogHookManager() app.StreamLogHookMgr {
|
||||
return &bizcommon.HookMgr{}
|
||||
}
|
||||
|
||||
func NewPTYManager() app.ShellPTYMgr {
|
||||
return shell.NewPTYMgr()
|
||||
}
|
||||
|
||||
func NewBaseApp(param struct {
|
||||
fx.In
|
||||
|
||||
Cfg conf.Config `name:"originConfig"`
|
||||
CliMgr app.ClientsManager
|
||||
HookMgr app.StreamLogHookMgr
|
||||
PtyMgr app.ShellPTYMgr
|
||||
}) app.Application {
|
||||
appInstance := app.NewApp()
|
||||
appInstance.SetConfig(param.Cfg)
|
||||
appInstance.SetClientsManager(param.CliMgr)
|
||||
appInstance.SetStreamLogHookMgr(param.HookMgr)
|
||||
appInstance.SetShellPTYMgr(param.PtyMgr)
|
||||
appInstance.SetClientRecvMap(&sync.Map{})
|
||||
return appInstance
|
||||
}
|
||||
|
||||
func NewClientsManager() app.ClientsManager {
|
||||
return rpc.NewClientsManager()
|
||||
}
|
||||
|
||||
func NewFs() embed.FS {
|
||||
return fs
|
||||
}
|
||||
|
||||
func NewPatchedConfig(param struct {
|
||||
fx.In
|
||||
|
||||
AppInstance app.Application
|
||||
CommonArgs CommonArgs
|
||||
}) conf.Config {
|
||||
patchedCfg := patchConfig(param.AppInstance, param.CommonArgs)
|
||||
param.AppInstance.SetConfig(patchedCfg)
|
||||
|
||||
return patchedCfg
|
||||
}
|
||||
|
||||
func NewContext(appInstance app.Application) *app.Context {
|
||||
return app.NewContext(context.Background(), appInstance)
|
||||
}
|
||||
|
||||
func NewClientLogManager() app.ClientLogManager {
|
||||
return streamlog.NewClientLogManager()
|
||||
}
|
||||
|
||||
func NewDBManager(ctx *app.Context, appInstance app.Application) app.DBManager {
|
||||
logger.Logger(ctx).Infof("start to init database, type: %s", appInstance.GetConfig().DB.Type)
|
||||
mgr := models.NewDBManager(nil, appInstance.GetConfig().DB.Type)
|
||||
appInstance.SetDBManager(mgr)
|
||||
|
||||
if appInstance.GetConfig().IsDebug {
|
||||
appInstance.GetDBManager().SetDebug(true)
|
||||
}
|
||||
|
||||
switch appInstance.GetConfig().DB.Type {
|
||||
case "sqlite3":
|
||||
if err := utils.EnsureDirectoryExists(appInstance.GetConfig().DB.DSN); err != nil {
|
||||
logger.Logger(ctx).WithError(err).Warnf("ensure directory failed, data location: [%s], keep data in current directory",
|
||||
appInstance.GetConfig().DB.DSN)
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
tmpCfg.DB.DSN = filepath.Base(appInstance.GetConfig().DB.DSN)
|
||||
appInstance.SetConfig(tmpCfg)
|
||||
logger.Logger(ctx).Infof("new data location: [%s]", appInstance.GetConfig().DB.DSN)
|
||||
}
|
||||
|
||||
if sqlitedb, err := gorm.Open(sqlite.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logger.Logger(ctx).Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("sqlite3", sqlitedb)
|
||||
logger.Logger(ctx).Infof("init database success, data location: [%s]", appInstance.GetConfig().DB.DSN)
|
||||
}
|
||||
case "mysql":
|
||||
if mysqlDB, err := gorm.Open(mysql.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logger.Logger(ctx).Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("mysql", mysqlDB)
|
||||
logger.Logger(ctx).Infof("init database success, data type: [%s]", "mysql")
|
||||
}
|
||||
case "postgres":
|
||||
if postgresDB, err := gorm.Open(postgres.Open(appInstance.GetConfig().DB.DSN), &gorm.Config{}); err != nil {
|
||||
logger.Logger(ctx).Panic(err)
|
||||
} else {
|
||||
appInstance.GetDBManager().SetDB("postgres", postgresDB)
|
||||
logger.Logger(ctx).Infof("init database success, data type: [%s]", "postgres")
|
||||
}
|
||||
default:
|
||||
logger.Logger(ctx).Panicf("currently unsupported database type: %s", appInstance.GetConfig().DB.Type)
|
||||
}
|
||||
|
||||
appInstance.GetDBManager().Init()
|
||||
return mgr
|
||||
}
|
||||
|
||||
func NewMasterTLSConfig(ctx *app.Context) *tls.Config {
|
||||
return dao.NewQuery(ctx).InitCert(conf.GetCertTemplate(ctx.GetApp().GetConfig()))
|
||||
}
|
||||
|
||||
func NewMasterRouter(fs embed.FS, appInstance app.Application) *gin.Engine {
|
||||
return bizmaster.NewRouter(fs, appInstance)
|
||||
}
|
||||
|
||||
func NewListenerOptions(ctx *app.Context, cfg conf.Config) conf.LisOpt {
|
||||
return conf.GetListener(ctx, cfg)
|
||||
}
|
||||
|
||||
func NewTLSMasterService(appInstance app.Application, masterTLSConfig *tls.Config) master.MasterService {
|
||||
return master.NewMasterService(appInstance, credentials.NewTLS(masterTLSConfig))
|
||||
}
|
||||
|
||||
func NewHTTPMasterService(appInstance app.Application) master.MasterService {
|
||||
return master.NewMasterService(appInstance, insecure.NewCredentials())
|
||||
}
|
||||
|
||||
func NewServerMasterCli(appInstance app.Application) app.MasterClient {
|
||||
return rpc.NewMasterCli(appInstance)
|
||||
}
|
||||
|
||||
func NewClientMasterCli(appInstance app.Application) app.MasterClient {
|
||||
return rpc.NewMasterCli(appInstance)
|
||||
}
|
||||
|
||||
func NewMux(param struct {
|
||||
fx.In
|
||||
|
||||
MasterService master.MasterService `name:"tlsMasterService"`
|
||||
Router *gin.Engine `name:"masterRouter"`
|
||||
LisOpt conf.LisOpt
|
||||
TLSCfg *tls.Config
|
||||
}) mux.MuxServer {
|
||||
return mux.NewMux(param.MasterService.GetServer(), param.Router, param.LisOpt.MuxLis, param.TLSCfg)
|
||||
}
|
||||
|
||||
func NewHTTPMux(param struct {
|
||||
fx.In
|
||||
|
||||
MasterService master.MasterService `name:"httpMasterService"`
|
||||
Router *gin.Engine `name:"masterRouter"`
|
||||
LisOpt conf.LisOpt
|
||||
}) mux.MuxServer {
|
||||
return mux.NewMux(param.MasterService.GetServer(), param.Router, param.LisOpt.ApiLis, nil)
|
||||
}
|
||||
|
||||
func NewWatcher() watcher.Client {
|
||||
return watcher.NewClient()
|
||||
}
|
||||
|
||||
func NewWSListener(ctx *app.Context, cfg conf.Config) *wsgrpc.WSListener {
|
||||
return wsgrpc.NewWSListener("ws-listener", "wsgrpc", 100)
|
||||
}
|
||||
|
||||
func NewWSGrpcHandler(ctx *app.Context, ws *wsgrpc.WSListener, upgrader *websocket.Upgrader) gin.HandlerFunc {
|
||||
return wsgrpc.GinWSHandler(ws, upgrader)
|
||||
}
|
||||
|
||||
func NewWSUpgrader(ctx *app.Context, cfg conf.Config) *websocket.Upgrader {
|
||||
return &websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
}
|
||||
|
||||
func NewServerRouter(appInstance app.Application) *gin.Engine {
|
||||
return bizserver.NewRouter(appInstance)
|
||||
}
|
||||
|
||||
func NewServerAPI(param struct {
|
||||
fx.In
|
||||
Ctx *app.Context
|
||||
ServerRouter *gin.Engine `name:"serverRouter"`
|
||||
}) app.Service {
|
||||
l, err := net.Listen("tcp", conf.ServerAPIListenAddr(param.Ctx.GetApp().GetConfig()))
|
||||
if err != nil {
|
||||
logger.Logger(param.Ctx).WithError(err).Fatalf("failed to listen addr: %v", conf.ServerAPIListenAddr(param.Ctx.GetApp().GetConfig()))
|
||||
return nil
|
||||
}
|
||||
|
||||
return api.NewApiService(l, param.ServerRouter, true)
|
||||
}
|
||||
|
||||
func NewServerCred(appInstance app.Application) credentials.TransportCredentials {
|
||||
cfg := appInstance.GetConfig()
|
||||
clientID := cfg.Client.ID
|
||||
clientSecret := cfg.Client.Secret
|
||||
ctx := context.Background()
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(appInstance, clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPS))
|
||||
if err != nil {
|
||||
logger.Logger(ctx).WithError(err).Fatal("new tls client cert failed")
|
||||
}
|
||||
logger.Logger(ctx).Infof("new tls server cert success")
|
||||
|
||||
return cred
|
||||
}
|
||||
|
||||
func NewClientCred(appInstance app.Application) credentials.TransportCredentials {
|
||||
cfg := appInstance.GetConfig()
|
||||
clientID := cfg.Client.ID
|
||||
clientSecret := cfg.Client.Secret
|
||||
ctx := context.Background()
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(appInstance, clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPC))
|
||||
if err != nil {
|
||||
logger.Logger(ctx).WithError(err).Fatal("new tls client cert failed")
|
||||
}
|
||||
logger.Logger(ctx).Infof("new tls client cert success")
|
||||
|
||||
return cred
|
||||
}
|
||||
|
||||
func NewDefaultServerConfig(ctx *app.Context) conf.Config {
|
||||
appInstance := ctx.GetApp()
|
||||
|
||||
logger.Logger(ctx).Infof("init default internal server")
|
||||
|
||||
dao.NewQuery(ctx).InitDefaultServer(appInstance.GetConfig().Master.APIHost)
|
||||
defaultServer, err := dao.NewQuery(ctx).GetDefaultServer()
|
||||
|
||||
if err != nil {
|
||||
logger.Logger(ctx).WithError(err).Fatal("get default server failed")
|
||||
}
|
||||
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
tmpCfg.Client.ID = defaultServer.ServerID
|
||||
tmpCfg.Client.Secret = defaultServer.ConnectSecret
|
||||
appInstance.SetConfig(tmpCfg)
|
||||
|
||||
return tmpCfg
|
||||
}
|
@@ -2,56 +2,60 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
bizserver "github.com/VaalaCat/frp-panel/biz/server"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/api"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
||||
"github.com/VaalaCat/frp-panel/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/watcher"
|
||||
"github.com/VaalaCat/frp-panel/services/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/services/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/fatedier/golib/crypto"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/sourcegraph/conc"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
func runServer(appInstance app.Application) {
|
||||
type runServerParam struct {
|
||||
fx.In
|
||||
|
||||
Lc fx.Lifecycle
|
||||
|
||||
AppInstance app.Application
|
||||
AppCtx *app.Context
|
||||
ServerApiService app.Service `name:"serverApiService"`
|
||||
TaskManager watcher.Client `name:"serverTaskManager"`
|
||||
Cfg conf.Config
|
||||
}
|
||||
|
||||
func runServer(param runServerParam) {
|
||||
var (
|
||||
c = context.Background()
|
||||
clientID = appInstance.GetConfig().Client.ID
|
||||
clientSecret = appInstance.GetConfig().Client.Secret
|
||||
cfg = appInstance.GetConfig()
|
||||
clientID = param.AppInstance.GetConfig().Client.ID
|
||||
clientSecret = param.AppInstance.GetConfig().Client.Secret
|
||||
cfg = param.AppInstance.GetConfig()
|
||||
appInstance = param.AppInstance
|
||||
ctx = param.AppCtx
|
||||
)
|
||||
|
||||
crypto.DefaultSalt = cfg.App.Secret
|
||||
logger.Logger(c).Infof("start to run server")
|
||||
logger.Logger(c).Infof("start to init server")
|
||||
|
||||
if len(clientID) == 0 {
|
||||
logrus.Fatal("client id cannot be empty")
|
||||
logger.Logger(ctx).Fatal("client id cannot be empty")
|
||||
}
|
||||
|
||||
l, err := net.Listen("tcp", conf.ServerAPIListenAddr(cfg))
|
||||
if err != nil {
|
||||
logger.Logger(c).WithError(err).Fatalf("failed to listen addr: %v", conf.ServerAPIListenAddr(cfg))
|
||||
return
|
||||
}
|
||||
param.TaskManager.AddDurationTask(defs.PullConfigDuration, bizserver.PullConfig, appInstance, clientID, clientSecret)
|
||||
param.TaskManager.AddDurationTask(defs.PushProxyInfoDuration, bizserver.PushProxyInfo, appInstance, clientID, clientSecret)
|
||||
|
||||
a := api.NewApiService(l, bizserver.NewRouter(appInstance), true)
|
||||
defer a.Stop()
|
||||
var wg conc.WaitGroup
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(appInstance, clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPS))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
appInstance.SetClientCred(cred)
|
||||
|
||||
appInstance.SetMasterCli(rpc.NewMasterCli(appInstance))
|
||||
appInstance.SetServerController(tunnel.NewServerController())
|
||||
param.Lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
logger.Logger(ctx).Infof("start to run server, serverID: [%s]", clientID)
|
||||
appInstance.SetRPCCred(NewServerCred(appInstance))
|
||||
appInstance.SetMasterCli(NewServerMasterCli(appInstance))
|
||||
|
||||
cliHandler := rpcclient.NewClientRPCHandler(
|
||||
appInstance,
|
||||
@@ -62,22 +66,24 @@ func runServer(appInstance app.Application) {
|
||||
)
|
||||
|
||||
appInstance.SetClientRPCHandler(cliHandler)
|
||||
appInstance.SetServerController(tunnel.NewServerController())
|
||||
|
||||
r := cliHandler
|
||||
defer r.Stop()
|
||||
|
||||
w := watcher.NewClient()
|
||||
w.AddDurationTask(defs.PullConfigDuration, bizserver.PullConfig, clientID, clientSecret)
|
||||
w.AddDurationTask(defs.PushProxyInfoDuration, bizserver.PushProxyInfo, clientID, clientSecret)
|
||||
defer w.Stop()
|
||||
|
||||
initServerOnce(appInstance, clientID, clientSecret)
|
||||
|
||||
var wg conc.WaitGroup
|
||||
wg.Go(r.Run)
|
||||
wg.Go(w.Run)
|
||||
wg.Go(a.Run)
|
||||
go initServerOnce(appInstance, clientID, clientSecret)
|
||||
wg.Go(cliHandler.Run)
|
||||
wg.Go(param.TaskManager.Run)
|
||||
wg.Go(param.ServerApiService.Run)
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
param.TaskManager.Stop()
|
||||
appInstance.GetClientRPCHandler().Stop()
|
||||
param.ServerApiService.Stop()
|
||||
wg.Wait()
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
logger.Logger(ctx).Infof("server started successfully, serverID: [%s]", clientID)
|
||||
}
|
||||
|
||||
func initServerOnce(appInstance app.Application, clientID, clientSecret string) {
|
||||
|
@@ -11,7 +11,7 @@ package main
|
||||
// Data: []byte(fmt.Sprint(cnt)),
|
||||
// })
|
||||
// if string(resp.Data) != fmt.Sprint(cnt) {
|
||||
// logrus.Panicf("resp: %+v", resp)
|
||||
// logger.Logger(ctx).Panicf("resp: %+v", resp)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
@@ -3,18 +3,17 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
bizclient "github.com/VaalaCat/frp-panel/biz/client"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/rpcclient"
|
||||
"github.com/VaalaCat/frp-panel/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/services/tunnel"
|
||||
"github.com/VaalaCat/frp-panel/services/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/watcher"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/fatedier/golib/crypto"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/sourcegraph/conc"
|
||||
)
|
||||
|
||||
@@ -23,23 +22,24 @@ func runClient(appInstance app.Application) {
|
||||
c = context.Background()
|
||||
clientID = appInstance.GetConfig().Client.ID
|
||||
clientSecret = appInstance.GetConfig().Client.Secret
|
||||
ctx = context.Background()
|
||||
)
|
||||
crypto.DefaultSalt = appInstance.GetConfig().App.Secret
|
||||
logger.Logger(c).Infof("start to run client")
|
||||
if len(clientSecret) == 0 {
|
||||
logrus.Fatal("client secret cannot be empty")
|
||||
logger.Logger(ctx).Fatal("client secret cannot be empty")
|
||||
}
|
||||
|
||||
if len(clientID) == 0 {
|
||||
logrus.Fatal("client id cannot be empty")
|
||||
logger.Logger(ctx).Fatal("client id cannot be empty")
|
||||
}
|
||||
|
||||
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(appInstance, clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPC))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
|
||||
appInstance.SetClientCred(cred)
|
||||
appInstance.SetRPCCred(cred)
|
||||
appInstance.SetMasterCli(rpc.NewMasterCli(appInstance))
|
||||
appInstance.SetClientController(tunnel.NewClientController())
|
||||
|
||||
|
@@ -6,15 +6,14 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@@ -180,11 +179,6 @@ func initCmdWithoutFlag(appInstance app.Application) []*cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
func initLogger() {
|
||||
logger.Instance().SetReportCaller(true)
|
||||
logrus.SetReportCaller(true)
|
||||
}
|
||||
|
||||
func patchConfig(appInstance app.Application, apiHost, rpcHost, secret, clientID, clientSecret, apiScheme string, rpcPort, apiPort int, apiUrl, rpcUrl string) {
|
||||
c := context.Background()
|
||||
tmpCfg := appInstance.GetConfig()
|
||||
|
@@ -3,16 +3,17 @@ package main
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/common"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/shell"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func main() {
|
||||
initLogger()
|
||||
logger.InitLogger()
|
||||
cobra.MousetrapHelpText = ""
|
||||
cfg := conf.NewConfig()
|
||||
|
||||
|
@@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
)
|
||||
|
||||
|
@@ -6,10 +6,10 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -77,15 +77,19 @@ func NewConfig() Config {
|
||||
}
|
||||
|
||||
if !useEnvFile {
|
||||
logrus.Info("use runtime env variables")
|
||||
logger.Logger(ctx).Info("use runtime env variables")
|
||||
}
|
||||
|
||||
cfg := Config{}
|
||||
if err = cleanenv.ReadEnv(&cfg); err != nil {
|
||||
logrus.Panic(err)
|
||||
logger.Logger(ctx).Panic(err)
|
||||
}
|
||||
cfg.Complete()
|
||||
|
||||
if !cfg.IsDebug {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
|
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cache
|
13
go.mod
13
go.mod
@@ -28,9 +28,10 @@ require (
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/tiendc/go-deepcopy v1.2.0
|
||||
go.uber.org/fx v1.23.0
|
||||
golang.org/x/crypto v0.31.0
|
||||
golang.org/x/net v0.33.0
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/grpc v1.67.1
|
||||
google.golang.org/protobuf v1.35.2
|
||||
gorm.io/driver/mysql v1.5.2
|
||||
gorm.io/driver/postgres v1.5.4
|
||||
@@ -105,6 +106,7 @@ require (
|
||||
github.com/refraction-networking/utls v1.6.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/templexxx/cpu v0.1.1 // indirect
|
||||
@@ -116,19 +118,20 @@ require (
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
github.com/xtaci/kcp-go/v5 v5.6.13 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/dig v1.18.1 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/zap v1.26.0 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/oauth2 v0.20.0 // indirect
|
||||
golang.org/x/oauth2 v0.22.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
28
go.sum
28
go.sum
@@ -225,8 +225,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
|
||||
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
|
||||
@@ -282,14 +282,18 @@ github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37/go.mod h1:HpMP7DB2
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/dig v1.18.1 h1:rLww6NuajVjeQn+49u5NcezUJEGwd5uXmyoCKW2g5Es=
|
||||
go.uber.org/dig v1.18.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
|
||||
go.uber.org/fx v1.23.0 h1:lIr/gYWQGfTwGcSXWXu4vP5Ws6iqnNEIY+F/aFzCKTg=
|
||||
go.uber.org/fx v1.23.0/go.mod h1:o/D9n+2mLP6v1EG+qsdT1O8wKopYAsqZasju97SDFCU=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
|
||||
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
|
||||
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
@@ -327,8 +331,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
|
||||
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
|
||||
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -391,14 +395,14 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@@ -5,12 +5,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/tiendc/go-deepcopy"
|
||||
)
|
||||
|
@@ -4,13 +4,12 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
type application struct {
|
||||
streamLogHookMgr StreamLogHookMgr
|
||||
masterCli pb.MasterClient
|
||||
masterCli MasterClient
|
||||
|
||||
shellPTYMgr ShellPTYMgr
|
||||
clientLogManager ClientLogManager
|
||||
@@ -21,13 +20,18 @@ type application struct {
|
||||
clientsManager ClientsManager
|
||||
serverHandler ServerHandler
|
||||
serverController ServerController
|
||||
clientCred credentials.TransportCredentials
|
||||
rpcCred credentials.TransportCredentials
|
||||
conf conf.Config
|
||||
}
|
||||
|
||||
// GetClientCred implements Application.
|
||||
func (a *application) GetClientCred() credentials.TransportCredentials {
|
||||
return a.clientCred
|
||||
func (a *application) GetRPCCred() credentials.TransportCredentials {
|
||||
return a.rpcCred
|
||||
}
|
||||
|
||||
// SetClientCred implements Application.
|
||||
func (a *application) SetRPCCred(cred credentials.TransportCredentials) {
|
||||
a.rpcCred = cred
|
||||
}
|
||||
|
||||
// GetConfig implements Application.
|
||||
@@ -35,11 +39,6 @@ func (a *application) GetConfig() conf.Config {
|
||||
return a.conf
|
||||
}
|
||||
|
||||
// SetClientCred implements Application.
|
||||
func (a *application) SetClientCred(cred credentials.TransportCredentials) {
|
||||
a.clientCred = cred
|
||||
}
|
||||
|
||||
// SetConfig implements Application.
|
||||
func (a *application) SetConfig(c conf.Config) {
|
||||
a.conf = c
|
||||
@@ -86,12 +85,12 @@ func (a *application) SetClientRPCHandler(clientRPCHandler ClientRPCHandler) {
|
||||
}
|
||||
|
||||
// GetMasterCli implements Application.
|
||||
func (a *application) GetMasterCli() pb.MasterClient {
|
||||
func (a *application) GetMasterCli() MasterClient {
|
||||
return a.masterCli
|
||||
}
|
||||
|
||||
// SetMasterCli implements Application.
|
||||
func (a *application) SetMasterCli(masterCli pb.MasterClient) {
|
||||
func (a *application) SetMasterCli(masterCli MasterClient) {
|
||||
a.masterCli = masterCli
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
@@ -23,8 +22,8 @@ type Application interface {
|
||||
SetClientRecvMap(*sync.Map)
|
||||
GetClientsManager() ClientsManager
|
||||
SetClientsManager(ClientsManager)
|
||||
GetMasterCli() pb.MasterClient
|
||||
SetMasterCli(pb.MasterClient)
|
||||
GetMasterCli() MasterClient
|
||||
SetMasterCli(MasterClient)
|
||||
GetClientRPCHandler() ClientRPCHandler
|
||||
SetClientRPCHandler(ClientRPCHandler)
|
||||
GetServerHandler() ServerHandler
|
||||
@@ -35,8 +34,8 @@ type Application interface {
|
||||
SetServerController(ServerController)
|
||||
GetConfig() conf.Config
|
||||
SetConfig(conf.Config)
|
||||
GetClientCred() credentials.TransportCredentials
|
||||
SetClientCred(credentials.TransportCredentials)
|
||||
GetRPCCred() credentials.TransportCredentials
|
||||
SetRPCCred(credentials.TransportCredentials)
|
||||
}
|
||||
|
||||
type Context struct {
|
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
@@ -114,7 +114,7 @@ type ClientHandler interface {
|
||||
type ClientRPCHandler interface {
|
||||
Run()
|
||||
Stop()
|
||||
GetCli() pb.MasterClient
|
||||
GetCli() MasterClient
|
||||
}
|
||||
|
||||
type ClientController interface {
|
||||
@@ -152,3 +152,8 @@ type ServerHandler interface {
|
||||
GetMem() *mem.ServerStats
|
||||
GetProxyStatsByType(v1.ProxyType) []*mem.ProxyStats
|
||||
}
|
||||
|
||||
// rpc/master.go
|
||||
type MasterClient interface {
|
||||
Call() pb.MasterClient
|
||||
}
|
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/coocood/freecache"
|
||||
)
|
||||
|
@@ -7,9 +7,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/fatedier/frp/client"
|
||||
"github.com/fatedier/frp/client/proxy"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
|
@@ -2,6 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/tls"
|
||||
@@ -10,22 +11,23 @@ import (
|
||||
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
)
|
||||
|
||||
func (q *queryImpl) InitCert(template *x509.Certificate) *tls.Config {
|
||||
ctx := context.Background()
|
||||
var (
|
||||
certPem []byte
|
||||
keyPem []byte
|
||||
)
|
||||
cnt, err := q.CountCerts()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
if cnt == 0 {
|
||||
certPem, keyPem, err = GenX509Info(template)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
if err = q.ctx.GetApp().GetDBManager().GetDefaultDB().Create(&models.Cert{
|
||||
Name: "default",
|
||||
@@ -33,18 +35,18 @@ func (q *queryImpl) InitCert(template *x509.Certificate) *tls.Config {
|
||||
CaFile: certPem,
|
||||
KeyFile: keyPem,
|
||||
}).Error; err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
} else {
|
||||
keyPem, certPem, err = q.GetDefaultKeyPair()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := utils.TLSServerCert(certPem, keyPem)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
logger.Logger(ctx).Fatal(err)
|
||||
}
|
||||
return resp
|
||||
}
|
@@ -6,10 +6,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sourcegraph/conc/pool"
|
||||
"gorm.io/gorm"
|
@@ -1,6 +1,6 @@
|
||||
package dao
|
||||
|
||||
import "github.com/VaalaCat/frp-panel/app"
|
||||
import "github.com/VaalaCat/frp-panel/services/app"
|
||||
|
||||
type Query interface{}
|
||||
|
@@ -6,18 +6,17 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/app"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
masterserver "github.com/VaalaCat/frp-panel/biz/master/server"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/shell"
|
||||
"github.com/VaalaCat/frp-panel/biz/master/streamlog"
|
||||
"github.com/VaalaCat/frp-panel/conf"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/defs"
|
||||
"github.com/VaalaCat/frp-panel/logger"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/rpc"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/VaalaCat/frp-panel/services/app"
|
||||
"github.com/VaalaCat/frp-panel/services/dao"
|
||||
"github.com/VaalaCat/frp-panel/services/rpc"
|
||||
"github.com/VaalaCat/frp-panel/utils/logger"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
@@ -38,14 +37,16 @@ func newRpcServer(appInstance app.Application, creds credentials.TransportCreden
|
||||
}
|
||||
|
||||
func runRpcServer(appInstance app.Application, s *grpc.Server) {
|
||||
ctx := context.Background()
|
||||
|
||||
lis, err := net.Listen("tcp", conf.RPCListenAddr(appInstance.GetConfig()))
|
||||
if err != nil {
|
||||
logrus.Fatalf("rpc server failed to listen: %v", err)
|
||||
logger.Logger(ctx).Fatalf("rpc server failed to listen: %v", err)
|
||||
}
|
||||
|
||||
logrus.Infof("start server")
|
||||
logger.Logger(ctx).Infof("start server")
|
||||
if err := s.Serve(lis); err != nil {
|
||||
logrus.Fatalf("failed to serve: %v", err)
|
||||
logger.Logger(ctx).Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user