Skip to content

Commit

Permalink
feat: client detail monitor and remote console
Browse files Browse the repository at this point in the history
  • Loading branch information
VaalaCat committed Dec 4, 2024
1 parent 2fe5fe3 commit 8de5419
Show file tree
Hide file tree
Showing 59 changed files with 2,823 additions and 575 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/latest.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: npm setup
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -43,8 +45,13 @@ jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
Expand All @@ -53,6 +60,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.standalone
push: true
platforms: linux/amd64,linux/arm64
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/tag.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: npm setup
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -44,8 +46,18 @@ jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get git tag history
run: git fetch -a
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
Expand All @@ -54,6 +66,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.standalone
push: true
platforms: linux/amd64,linux/arm64
Expand Down
17 changes: 9 additions & 8 deletions Dockerfile.standalone
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Stage 1: Building frontend
FROM node:20-alpine AS frontend
WORKDIR /app/www
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata git openssh
RUN npm config set registry https://registry.npmmirror.com
# RUN npm config set registry https://registry.npmmirror.com
COPY www/package*.json .
RUN corepack enable && corepack prepare pnpm@latest-9 --activate && pnpm install

Expand All @@ -27,19 +27,20 @@ RUN ls && mkdir -p ../cmd/frpp && pnpm build
# Stage 2: Building binary
FROM golang:1.22-alpine AS builder
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata git
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata git bash
COPY go.mod go.sum ./
RUN CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go mod download
# RUN CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go mod download
RUN CGO_ENABLED=0 go mod download
COPY . .
RUN rm -rf /app/cmd/frpp/out
COPY --from=frontend /app/www/out ./cmd/frpp/out
RUN CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go build -ldflags="-s -w" -o frp-panel cmd/frpp/*.go
RUN ./build.sh --current --skip-frontend

# Stage 3: Build image
FROM alpine:latest
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata git && mkdir -p /data
COPY --from=builder /app/frp-panel .

Expand All @@ -48,6 +49,6 @@ EXPOSE 9000
# rpc port
EXPOSE 9001

ENV DB_DSN /data/data.db
ENV DB_DSN=/data/data.db
ENTRYPOINT ["/app/frp-panel"]
CMD ["master"]
65 changes: 49 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ frp-panel 可选 docker 和直接运行模式部署,直接部署请到 release
- master

```bash
docker run -d -p 9000:9000 \ # API控制台端口
-p 9001:9001 \ # rpc端口
-p 7000:7000 \ # frps 端口
-p 20000-20050:20000-20050 \ # 给frps预留的端口
# 推荐
docker run -d \
--network=host \
--restart=unless-stopped \
-v /opt/frp-panel:/data \ # 数据存储位置
-v /opt/frp-panel:/data \
-e APP_GLOBAL_SECRET=your_secret \ # Master的secret注意不要泄漏,客户端和服务端的是通过Master生成的
-e MASTER_RPC_HOST=0.0.0.0 \ # 这里要改成你服务器的外部IP
vaalacat/frp-panel
# 或者
docker run -d \
--network=host \
docker run -d -p 9000:9000 \ # API控制台端口
-p 9001:9001 \ # rpc端口
-p 7000:7000 \ # frps 端口
-p 20000-20050:20000-20050 \ # 给frps预留的端口
--restart=unless-stopped \
-v /opt/frp-panel:/data \
-v /opt/frp-panel:/data \ # 数据存储位置
-e APP_GLOBAL_SECRET=your_secret \ # Master的secret注意不要泄漏,客户端和服务端的是通过Master生成的
-e MASTER_RPC_HOST=0.0.0.0 \ # 这里要改成你服务器的外部IP
vaalacat/frp-panel
Expand Down Expand Up @@ -80,34 +81,34 @@ docker run -d \

注意修改 IP

```powershell
```bash
APP_GLOBAL_SECRET=your_secret MASTER_RPC_HOST=0.0.0.0 frp-panel master
```

- client

```powershell
```bash
frp-panel client -s xxxx -i xxxx -a xxxx -r 127.0.0.1 -c 9001 -p 9000 -e http # 在master WebUI复制的参数
```

- server

```powershell
```bash
frp-panel server -s xxxx -i xxxx -a xxxx -r 127.0.0.1 -c 9001 -p 9000 -e http # 在master WebUI复制的参数
```

### 直接运行(Windows)

在下载的可执行文件同名文件夹下创建一个 `.env` 文件(注意不要有后缀名),然后输入以下内容保存后运行对应命令,注意,client 和 server 的对应参数需要在 web 页面复制

- master: `frp-panel-amd64.exe master`

```
APP_GLOBAL_SECRET=your_secret
MASTER_RPC_HOST=IP
DB_DSN=data.db
```

- master: `frp-panel-amd64.exe master`

client 和 server 要使用在 master WebUI 复制的参数

- client: `frp-panel-amd64.exe client -s xxxx -i xxxx -a xxxx -r 127.0.0.1 -c 9001 -p 9000 -e http # 在master WebUI复制的参数`
Expand All @@ -124,7 +125,7 @@ client 和 server 要使用在 master WebUI 复制的参数

### 服务管理

如果您使用的是面板自带的安装脚本,对于 Linux 使用 systemd 控制,对于 Windows 使用 nssm 控制
如果您使用的是面板自带的安装脚本,对于 Linux 使用 systemd 控制,对于 Windows 使用 本程序 控制

Linux 安装后使用示例:

Expand All @@ -136,10 +137,42 @@ systemctl start frpp
Windows 安装后使用示例:

```
C:/frpp/nssm.exe stop frpp
C:/frpp/nssm.exe remove frpp
C:/frpp/frpp.exe start
C:/frpp/frpp.exe stop
C:/frpp/frpp.exe uninstall
```

### 配置说明

| 类型 | 环境变量名 | 默认值 | 描述 |
|--------|-------------------------------------|--------------------|----------------------------------------------------------------|
| string | `APP_SECRET` | - | 应用密钥,用于客户端和服务器的和Master的通信加密 |
| string | `APP_GLOBAL_SECRET` | `frp-panel` | 全局密钥,用于管理生成密钥,需妥善保管 |
| int | `APP_COOKIE_AGE` | `86400` | Cookie 的有效期(秒),默认值为 1 天 |
| string | `APP_COOKIE_NAME` | `frp-panel-cookie` | Cookie 名称 |
| string | `APP_COOKIE_PATH` | `/` | Cookie 路径 |
| string | `APP_COOKIE_DOMAIN` | - | Cookie 域 |
| bool | `APP_COOKIE_SECURE` | `false` | Cookie 是否安全 |
| bool | `APP_COOKIE_HTTP_ONLY` | `true` | Cookie 是否仅限 HTTP |
| bool | `APP_ENABLE_REGISTER` | `false` | 是否启用注册,仅允许第一个管理员注册 |
| int | `MASTER_API_PORT` | `9000` | 主节点 API 端口 |
| string | `MASTER_API_HOST` | - | 主节点域名,可以在反向代理和CDN后 |
| string | `MASTER_API_SCHEME` | `http` | 主节点 API 协议(注意,这里不影响主机行为,设置为https只是为了方便复制客户端启动命令,HTTPS需要自行反向代理)|
| int | `MASTER_CACHE_SIZE` | `10` | 缓存大小(MB) |
| string | `MASTER_RPC_HOST` | `127.0.0.1` | Master节点公共 IP 或域名 |
| int | `MASTER_RPC_PORT` | `9001` | Master节点 RPC 端口 |
| bool | `MASTER_COMPATIBLE_MODE` | `false` | 兼容模式,用于官方 frp 客户端 |
| string | `MASTER_INTERNAL_FRP_SERVER_HOST` | - | Master内置 frps 服务器主机,用于客户端连接 |
| int | `MASTER_INTERNAL_FRP_SERVER_PORT` | `9002` | Master内置 frps 服务器端口,用于客户端连接 |
| string | `MASTER_INTERNAL_FRP_AUTH_SERVER_HOST` | `127.0.0.1` | Master内置 frps 认证服务器主机 |
| int | `MASTER_INTERNAL_FRP_AUTH_SERVER_PORT` | `8999` | Master内置 frps 认证服务器端口 |
| string | `MASTER_INTERNAL_FRP_AUTH_SERVER_PATH` | `/auth` | Master内置 frps 认证服务器路径 |
| int | `SERVER_API_PORT` | `8999` | 服务器 API 端口 |
| string | `DB_TYPE` | `sqlite3` | 数据库类型,如 mysql postgres 或 sqlite3 等 |
| string | `DB_DSN` | `data.db` | 数据库 DSN,默认使用sqlite3,数据默认存储在可执行文件同目录下,对于 sqlite 是路径,其他数据库为 DSN,参见 [MySQL DSN](https://github.com/go-sql-driver/mysql#dsn-data-source-name) |
| string | `CLIENT_ID` | - | 客户端 ID |
| string | `CLIENT_SECRET` | - | 客户端密钥 |

## 项目开发指南

### 平台架构设计
Expand Down
32 changes: 18 additions & 14 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ Note⚠️: The startup commands for client and server may change as the project
- master

```bash
docker run -d -p 9000:9000 \ # API control console port
-p 9001:9001 \ # rpc port
-p 7000:7000 \ # frps port
-p 20000-20050:20000-20050 \ # Reserved ports for frps
# recommended
docker run -d \
--network=host \
--restart=unless-stopped \
-v /opt/frp-panel:/data \ # Data storage location
-v /opt/frp-panel:/data \
-e APP_GLOBAL_SECRET=your_secret \ # Master's secret, be careful not to leak it, the client and server secrets are generated by the Master
-e MASTER_RPC_HOST=0.0.0.0 \ # Change this to your server's external IP
vaalacat/frp-panel

# or
docker run -d \
--network=host \

docker run -d -p 9000:9000 \ # API control console port
-p 9001:9001 \ # rpc port
-p 7000:7000 \ # frps port
-p 20000-20050:20000-20050 \ # Reserved ports for frps
--restart=unless-stopped \
-v /opt/frp-panel:/data \
-v /opt/frp-panel:/data \ # Data storage location
-e APP_GLOBAL_SECRET=your_secret \ # Master's secret, be careful not to leak it, the client and server secrets are generated by the Master
-e MASTER_RPC_HOST=0.0.0.0 \ # Change this to your server's external IP
vaalacat/frp-panel
Expand Down Expand Up @@ -76,19 +79,19 @@ docker run -d \

Note: Modify the IP

```powershell
```bash
APP_GLOBAL_SECRET=your_secret MASTER_RPC_HOST=0.0.0.0 frp-panel master
```

- client

```powershell
```bash
frp-panel client -s xxxx -i xxxx -a xxxx -r 127.0.0.1 -c 9001 -p 9000 -e http # Copy the parameters from the master WebUI
```

- server

```powershell
```bash
frp-panel server -s xxxx -i xxxx -a xxxx -r 127.0.0.1 -c 9001 -p 9000 -e http # Copy the parameters from the master WebUI
```

Expand Down Expand Up @@ -120,7 +123,7 @@ The program will read the contents of the following files in order as the config

### Service Management

If you are using the installation script provided by the panel, systemd is used for Linux control, and nssm is used for Windows control.
If you are using the installation script provided by the panel, systemd is used for Linux control, and frpp.exe is used for Windows control.

Examples of using Linux after installation:

Expand All @@ -132,8 +135,9 @@ systemctl start frpp
Examples of using Windows after installation:

```
C:/frpp/nssm.exe stop frpp
C:/frpp/nssm.exe remove frpp
C:/frpp/frpp.exe start
C:/frpp/frpp.exe stop
C:/frpp/frpp.exe uninstall
```

## Project Development Guide
Expand Down
18 changes: 18 additions & 0 deletions biz/client/pty_connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package client

import (
"context"

"github.com/VaalaCat/frp-panel/biz/common"
"github.com/VaalaCat/frp-panel/conf"
"github.com/VaalaCat/frp-panel/pb"
)

func StartPTYConnect(c context.Context, req *pb.CommonRequest) (*pb.CommonResponse, error) {
return common.StartPTYConnect(c, req, &pb.PTYClientMessage{Base: &pb.PTYClientMessage_ClientBase{
ClientBase: &pb.ClientBase{
ClientId: conf.Get().Client.ID,
ClientSecret: conf.Get().Client.Secret,
},
}})
}
8 changes: 7 additions & 1 deletion biz/client/rpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"runtime/debug"

"github.com/VaalaCat/frp-panel/common"

"github.com/VaalaCat/frp-panel/conf"
"github.com/VaalaCat/frp-panel/logger"
"github.com/VaalaCat/frp-panel/pb"
"google.golang.org/protobuf/proto"
)

func HandleServerMessage(req *pb.ServerMessage) *pb.ClientMessage {
Expand All @@ -31,10 +34,13 @@ func HandleServerMessage(req *pb.ServerMessage) *pb.ClientMessage {
return common.WrapperServerMsg(req, StartSteamLogHandler)
case pb.Event_EVENT_STOP_STREAM_LOG:
return common.WrapperServerMsg(req, StopSteamLogHandler)
case pb.Event_EVENT_START_PTY_CONNECT:
return common.WrapperServerMsg(req, StartPTYConnect)
case pb.Event_EVENT_PING:
rawData, _ := proto.Marshal(conf.GetVersion().ToProto())
return &pb.ClientMessage{
Event: pb.Event_EVENT_PONG,
Data: []byte("pong"),
Data: rawData,
}
default:
}
Expand Down
Loading

0 comments on commit 8de5419

Please sign in to comment.