Skip to content

Commit

Permalink
add server manage plugin doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Jan 3, 2020
1 parent 13e48c6 commit e91c947
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ frp also has a P2P connect mode.
* [URL routing](#url-routing)
* [Connecting to frps via HTTP PROXY](#connecting-to-frps-via-http-proxy)
* [Range ports mapping](#range-ports-mapping)
* [Plugins](#plugins)
* [Client Plugins](#client-plugins)
* [Server Manage Plugins](#server-manage-plugins)
* [Development Plan](#development-plan)
* [Contributing](#contributing)
* [Donation](#donation)
Expand Down Expand Up @@ -806,7 +807,7 @@ remote_port = 6000-6006,6007

frpc will generate 8 proxies like `test_tcp_0`, `test_tcp_1`, ..., `test_tcp_7`.

### Plugins
### Client Plugins

frpc only forwards requests to local TCP or UDP ports by default.

Expand All @@ -828,6 +829,10 @@ plugin_http_passwd = abc

`plugin_http_user` and `plugin_http_passwd` are configuration parameters used in `http_proxy` plugin.

### Server Manage Plugins

Read the [document](/doc/server_plugin.md).

## Development Plan

* Log HTTP request information in frps.
Expand Down
11 changes: 8 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
* [URL 路由](#url-路由)
* [通过代理连接 frps](#通过代理连接-frps)
* [范围端口映射](#范围端口映射)
* [插件](#插件)
* [客户端插件](#客户端插件)
* [服务端管理插件](#服务端管理插件)
* [开发计划](#开发计划)
* [为 frp 做贡献](#为-frp-做贡献)
* [捐助](#捐助)
Expand Down Expand Up @@ -858,11 +859,11 @@ remote_port = 6000-6006,6007

实际连接成功后会创建 8 个 proxy,命名为 `test_tcp_0, test_tcp_1 ... test_tcp_7`

### 插件
### 客户端插件

默认情况下,frpc 只会转发请求到本地 tcp 或 udp 端口。

插件模式是为了在客户端提供更加丰富的功能,目前内置的插件有 `unix_domain_socket``http_proxy``socks5``static_file`。具体使用方式请查看[使用示例](#使用示例)
客户端插件模式是为了在客户端提供更加丰富的功能,目前内置的插件有 `unix_domain_socket``http_proxy``socks5``static_file`。具体使用方式请查看[使用示例](#使用示例)

通过 `plugin` 指定需要使用的插件,插件的配置参数都以 `plugin_` 开头。使用插件后 `local_ip``local_port` 不再需要配置。

Expand All @@ -880,6 +881,10 @@ plugin_http_passwd = abc

`plugin_http_user``plugin_http_passwd` 即为 `http_proxy` 插件可选的配置参数。

### 服务端管理插件

[使用说明](/doc/server_plugin_zh.md)

## 开发计划

计划在后续版本中加入的功能与优化,排名不分先后,如果有其他功能建议欢迎在 [issues](https://github.com/fatedier/frp/issues) 中反馈。
Expand Down
171 changes: 171 additions & 0 deletions doc/server_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
### Manage Plugin

frp manage plugin is aim to extend frp's ability without modifing self code.

It runs as a process and listen on a port to provide RPC interface. Before frps doing some operations, frps will send RPC requests to manage plugin and do operations by it's response.

### RPC request

Support HTTP first.

When manage plugin accept the operation request, it can give three different responses.

* Reject operation and return the reason.
* Allow operation and keep original content.
* Allow operation and return modified content.

### Interface

HTTP path can be configured for each manage plugin in frps. Assume here is `/handler`.

Request

```
POST /handler
{
"version": "0.1.0",
"op": "Login",
"content": {
... // Operation info
}
}
Request Header
X-Frp-Reqid: for tracing
```

Response

Error if not return 200 http code.

Reject opeartion

```
{
"reject": true,
"reject_reason": "invalid user"
}
```

Allow operation and keep original content

```
{
"reject": false,
"unchange": true
}
```

Allow opeartion and modify content

```
{
"unchange": "false",
"content": {
... // Replaced content
}
}
```

### Operation

Now it supports `Login` and `NewProxy`.

#### Login

Client login operation

```
{
"content": {
"version": <string>,
"hostname": <string>,
"os": <string>,
"arch": <string>,
"user": <string>,
"timestamp": <int64>,
"privilege_key": <string>,
"run_id": <string>,
"pool_count": <int>,
"metas": map<string>string
}
}
```

#### NewProxy

Create new proxy

```
{
"content": {
"user": {
"user": <string>,
"metas": map<string>string
},
"proxy_name": <string>,
"proxy_type": <string>,
"use_encryption": <bool>,
"use_compression": <bool>,
"group": <string>,
"group_key": <string>,
// tcp and udp only
"remote_port": <int>,
// http and https only
"custom_domains": []<string>,
"subdomain": <string>,
"locations": <string>,
"http_user": <string>,
"http_pwd": <string>,
"host_header_rewrite": <string>,
"headers": map<string>string,
"metas": map<string>string
}
}
```

### manage plugin configure

```ini
[common]
bind_port = 7000

[plugin.user-manager]
addr = 127.0.0.1:9000
path = /handler
ops = Login

[plugin.port-manager]
addr = 127.0.0.1:9001
path = /handler
ops = NewProxy
```

addr: plugin listen on.
path: http request url path.
ops: opeartions plugin needs handle.

### meta data

Meta data will be sent to manage plugin in each RCP request.

Meta data start with `meta_`. It can be configured in `common` and each proxy.

```
# frpc.ini
[common]
server_addr = 127.0.0.1
server_port = 7000
user = fake
meta_token = fake
meta_version = 1.0.0
[ssh]
type = tcp
local_port = 22
remote_port = 6000
meta_id = 123
```
Loading

0 comments on commit e91c947

Please sign in to comment.