Skip to content

Commit

Permalink
feat: support add comment for frps
Browse files Browse the repository at this point in the history
  • Loading branch information
VaalaCat committed Jan 20, 2024
1 parent 3f6cecc commit dcf0ccb
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 173 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,34 @@ frp-panel可选docker和直接运行模式部署,直接部署请到release下
```bash
docker run -d -p 9000:9000 \
-p 9001:9001 \
--restart=unless-stopped \
-v /opt/frp-panel:/data \
-e APP_GLOBAL_SECRET=your_secret \ # Master的secret注意不要泄漏,客户端和服务端的是通过Master生成的
-e MASTER_RPC_HOST=0.0.0.0 \
vaalacat/frp-panel
# 或者
docker run -d \
--network=host \
--restart=unless-stopped \
-v /opt/frp-panel:/data \
-e APP_GLOBAL_SECRET=your_secret \ # Master的secret注意不要泄漏,客户端和服务端的是通过Master生成的
-e MASTER_RPC_HOST=0.0.0.0 \
vaalacat/frp-panel

```
- client

```bash
docker run -d -p your_port:your_port \
docker run -d \
--network=host \
--restart=unless-stopped \
vaalacat/frp-panel client -s xxx -i xxx # 在master WebUI复制的参数
```
- server

```bash
docker run -d -p your_port:your_port \
-p 服务器开放端口70011:服务器开放端口7001 \
-p 服务器开放端口8000-8100:服务器开放端口8000-8100 \
docker run -d \
--network=host \
--restart=unless-stopped \
vaalacat/frp-panel server -s xxx -i xxx # 在master WebUI复制的参数
```

Expand Down
8 changes: 5 additions & 3 deletions biz/master/server/get_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ func GetServerHandler(c context.Context, req *pb.GetServerRequest) (*pb.GetServe
return &pb.GetServerResponse{
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_SUCCESS, Message: "ok"},
Server: &pb.Server{
Id: lo.ToPtr(serverEntity.ServerID),
Config: lo.ToPtr(string(serverEntity.ConfigContent)),
Secret: lo.ToPtr(serverEntity.ConnectSecret),
Id: lo.ToPtr(serverEntity.ServerID),
Config: lo.ToPtr(string(serverEntity.ConfigContent)),
Secret: lo.ToPtr(serverEntity.ConnectSecret),
Comment: lo.ToPtr(serverEntity.Comment),
Ip: lo.ToPtr(serverEntity.ServerIP),
},
}, nil
}
9 changes: 5 additions & 4 deletions biz/master/server/list_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ func ListServersHandler(c context.Context, req *pb.ListServersRequest) (*pb.List
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_SUCCESS, Message: "ok"},
Servers: lo.Map(servers, func(c *models.ServerEntity, _ int) *pb.Server {
return &pb.Server{
Id: lo.ToPtr(c.ServerID),
Config: lo.ToPtr(string(c.ConfigContent)),
Secret: lo.ToPtr(c.ConnectSecret),
Ip: lo.ToPtr(c.ServerIP),
Id: lo.ToPtr(c.ServerID),
Config: lo.ToPtr(string(c.ConfigContent)),
Secret: lo.ToPtr(c.ConnectSecret),
Ip: lo.ToPtr(c.ServerIP),
Comment: lo.ToPtr(c.Comment),
}
}),
Total: lo.ToPtr(int32(serverCounts)),
Expand Down
2 changes: 2 additions & 0 deletions biz/master/server/update_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func UpdateFrpsHander(c context.Context, req *pb.UpdateFRPSRequest) (*pb.UpdateF
return nil, err
}

srv.Comment = req.GetComment()

if err := dao.UpdateServer(userInfo, srv); err != nil {
logrus.WithError(err).Errorf("cannot update server, id: [%s]", serverID)
return nil, err
Expand Down
19 changes: 8 additions & 11 deletions biz/server/rpc_pull_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,18 @@ func PullConfig(serverID, serverSecret string) error {

ctrl := tunnel.GetServerController()

if t := ctrl.Get(serverID); t == nil {
ctrl.Add(serverID, server.NewServerHandler(s))
ctrl.Run(serverID)
} else {
if t := ctrl.Get(serverID); t != nil {
if !reflect.DeepEqual(t.GetCommonCfg(), s) {
t.Stop()
ctrl.Delete(serverID)
logrus.Infof("server %s config changed, will recreate it", serverID)
srv := ctrl.Get(serverID)
if srv != nil {
srv.Stop()
ctrl.Delete(serverID)
}
ctrl.Add(serverID, server.NewServerHandler(s))
ctrl.Run(serverID)
} else {
logrus.Infof("server %s config not changed", serverID)
return nil
}
}
ctrl.Add(serverID, server.NewServerHandler(s))
ctrl.Run(serverID)

logrus.Infof("pull server config success, serverID: [%s]", serverID)
return nil
Expand Down
13 changes: 11 additions & 2 deletions biz/server/update_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"reflect"

"github.com/VaalaCat/frp-panel/pb"
"github.com/VaalaCat/frp-panel/services/server"
Expand All @@ -25,8 +26,16 @@ func UpdateFrpsHander(ctx context.Context, req *pb.UpdateFRPSRequest) (*pb.Updat

serverID := req.GetServerId()
if cli := tunnel.GetServerController().Get(serverID); cli != nil {
cli.Stop()
tunnel.GetClientController().Delete(serverID)
if !reflect.DeepEqual(cli.GetCommonCfg(), s) {
cli.Stop()
tunnel.GetClientController().Delete(serverID)
logrus.Infof("server %s config changed, will recreate it", serverID)
} else {
logrus.Infof("server %s config not changed", serverID)
return &pb.UpdateFRPSResponse{
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_SUCCESS, Message: "ok"},
}, nil
}
}
tunnel.GetServerController().Add(serverID, server.NewServerHandler(s))
tunnel.GetServerController().Run(serverID)
Expand Down
2 changes: 2 additions & 0 deletions idl/api_server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ option go_package="../pb";
message InitServerRequest {
optional string server_id = 1;
optional string server_ip = 2;
optional string comment = 3;
}

message InitServerResponse {
Expand Down Expand Up @@ -45,6 +46,7 @@ message DeleteServerResponse {
message UpdateFRPSRequest {
optional string server_id = 1;
optional bytes config = 2;
optional string comment = 3;
}

message UpdateFRPSResponse {
Expand Down
2 changes: 2 additions & 0 deletions idl/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ message Client {
optional string id = 1;
optional string secret = 2;
optional string config = 3;
optional string comment = 5; // 用户自定义的备注
}

message Server {
optional string id = 1;
optional string secret = 2;
optional string ip = 3;
optional string config = 4; // 在定义上,ip和port只是为了方便使用
optional string comment = 5; // 用户自定义的备注
}

message User {
Expand Down
1 change: 1 addition & 0 deletions models/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ServerEntity struct {
ServerIP string `json:"server_ip"`
ConfigContent []byte `json:"config_content"`
ConnectSecret string `json:"connect_secret" gorm:"not null"`
Comment string `json:"comment"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
Expand Down
Loading

0 comments on commit dcf0ccb

Please sign in to comment.