Documentation
¶
Overview ¶
Package frp 托管 frpc(内网穿透客户端)与 frps(服务端): 在界面中维护多个 frpc / frps 实例与代理列表,生成配置文件并守护外部 frp 进程。
Index ¶
- Constants
- func ClientTOML(c ClientSettings, proxies []Proxy) string
- func ServerTOML(s ServerSettings) string
- type BinaryView
- type Client
- type ClientSettings
- type ClientView
- type ImportRequest
- type ImportResponse
- type ImportResult
- type InstanceState
- type Module
- func (m *Module) ID() string
- func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
- func (m *Module) Init(env module.Env) error
- func (m *Module) Routes(r module.Router)
- func (m *Module) SelfCheck(_ context.Context, _ module.CheckEnv) []module.CheckResult
- func (m *Module) SetHTTPClient(fn func() *http.Client)
- func (m *Module) Start(context.Context) error
- func (m *Module) Stop() error
- func (m *Module) Summary() []module.SummaryItem
- func (m *Module) Title() string
- type PortRange
- type Proxy
- type Server
- type ServerSettings
- type ServerView
- type Settings
- type SettingsView
Constants ¶
const ( TypeTCP = "tcp" TypeUDP = "udp" TypeHTTP = "http" TypeHTTPS = "https" TypeSTCP = "stcp" TypeXTCP = "xtcp" )
代理类型。
const ( // ProxyAppend 只追加名称不存在的代理,同名代理保持不变 ProxyAppend = "append" // ProxyReplace 用导入的代理替换现有全部代理 ProxyReplace = "replace" )
代理导入方式。
const ( RoleClient = "client" RoleServer = "server" )
导入的角色。
const ID = "frp"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
func ClientTOML ¶
func ClientTOML(c ClientSettings, proxies []Proxy) string
ClientTOML 生成 frpc 配置文件内容(frp 0.52+ 的 TOML 格式)。
Types ¶
type BinaryView ¶ added in v0.6.0
type BinaryView struct {
// Binary 为实际使用的可执行文件路径
Binary string `json:"binary"`
Version string `json:"version"`
Error string `json:"error"`
}
BinaryView 是一种可执行文件的查找结果。
type Client ¶ added in v0.6.0
type Client struct {
Key string `json:"key"`
Name string `json:"name"`
// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
Group string `json:"group"`
Enable bool `json:"enable"`
ClientSettings
Remark string `json:"remark"`
}
Client 是一个 frpc 实例:连接一台 frps,运行一个独立的 frpc 进程,代理通过 Proxy.Client 归属到实例。
type ClientSettings ¶
type ClientSettings struct {
ServerAddr string `json:"serverAddr"`
ServerPort int `json:"serverPort"`
Token string `json:"token"`
User string `json:"user"`
// Protocol 为 frpc 与 frps 之间的传输协议,留空使用 tcp
Protocol string `json:"protocol"`
}
ClientSettings 是 frpc(客户端)与 frps 之间的连接参数。
func (*ClientSettings) Validate ¶
func (c *ClientSettings) Validate() error
Validate 校验并规范化连接参数;服务端地址是否必填由 Client.Validate 按启用状态判断。
type ClientView ¶ added in v0.6.0
type ClientView struct {
Client
InstanceState
}
ClientView 是界面展示的 frpc 实例,令牌已脱敏。
type ImportRequest ¶
type ImportRequest struct {
// Role 为 client(frpc)或 server(frps)
Role string `json:"role"`
Content string `json:"content"`
Apply bool `json:"apply"`
// ProxyMode 为 append 或 replace,仅导入到已有 frpc 实例时有效,留空等同 append
ProxyMode string `json:"proxyMode"`
// Target 为导入到的已有实例 key,留空时新建一个停用的实例
Target string `json:"target"`
// Name 为新建实例的名称,留空时使用服务端地址(frpc)或 frps
Name string `json:"name"`
}
ImportRequest 是导入请求。Apply 为 false 时只返回解析预览,不保存。
type ImportResponse ¶
type ImportResponse struct {
Applied bool `json:"applied"`
Role string `json:"role"`
Client *ClientSettings `json:"client,omitempty"`
Server *ServerSettings `json:"server,omitempty"`
Proxies []Proxy `json:"proxies"`
Warnings []string `json:"warnings"`
// Added 为实际新增的代理数量
Added int `json:"added"`
// Key 为导入到的实例 key,仅 Applied 为 true 时有值
Key string `json:"key,omitempty"`
}
ImportResponse 是导入响应,密钥均已脱敏。
type ImportResult ¶
type ImportResult struct {
Role string `json:"role"`
Client *ClientSettings `json:"client,omitempty"`
Server *ServerSettings `json:"server,omitempty"`
Proxies []Proxy `json:"proxies"`
Warnings []string `json:"warnings"`
}
ImportResult 是解析结果,Warnings 列出被忽略或需要用户留意的内容。
func ParseImport ¶
func ParseImport(role, content string) (*ImportResult, error)
ParseImport 解析 frpc 或 frps 配置文本。
type InstanceState ¶ added in v0.6.0
InstanceState 是实例的运行状态。
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 是 frp 模块。
func (*Module) ImportLucky ¶ added in v0.4.0
func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
ImportLucky 实现 luckyimport.Importer。Lucky 中的每个客户端、服务端实例分别导入为 Gately 的 frpc、frps 实例。
func (*Module) SelfCheck ¶ added in v0.5.5
SelfCheck 实现 module.SelfChecker:检查本机配置中的重名代理,以及近期日志中 frps 报告的代理名、域名或端口冲突。 多台设备复制同一份 frpc 配置连到同一个 frps 时,后连上的设备会注册失败,对应的网站表现为超时,很难直接看出原因。
func (*Module) SetHTTPClient ¶ added in v0.5.9
SetHTTPClient 实现 module.HTTPClientAware。
func (*Module) Summary ¶
func (m *Module) Summary() []module.SummaryItem
Summary 实现 module.Summarizer。
type PortRange ¶
type PortRange struct{ Start, End int }
PortRange 是闭区间端口范围。
func ParseAllowPorts ¶
ParseAllowPorts 解析 "6000-6100,7000" 形式的端口范围。
type Proxy ¶
type Proxy struct {
Key string `json:"key"`
Name string `json:"name"`
// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
Group string `json:"group"`
Type string `json:"type"`
Enable bool `json:"enable"`
LocalIP string `json:"localIp"`
LocalPort int `json:"localPort"`
// RemotePort 用于 tcp 与 udp
RemotePort int `json:"remotePort"`
// CustomDomains 与 Subdomain 用于 http 与 https
CustomDomains []string `json:"customDomains"`
Subdomain string `json:"subdomain"`
// SecretKey 用于 stcp 与 xtcp,访问端需使用相同密钥
SecretKey string `json:"secretKey"`
Remark string `json:"remark"`
// Client 是代理所属 frpc 实例的 key
Client string `json:"client"`
}
Proxy 是一条 frpc 代理,把本地服务暴露到 frps。
type Server ¶ added in v0.6.0
type Server struct {
Key string `json:"key"`
Name string `json:"name"`
// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
Group string `json:"group"`
Enable bool `json:"enable"`
ServerSettings
Remark string `json:"remark"`
}
Server 是一个 frps 实例,运行一个独立的 frps 进程。
type ServerSettings ¶
type ServerSettings struct {
// BindAddr 是 frpc 连接端口的监听地址,留空监听所有地址;
// 填 127.0.0.1 时可放在反向代理之后,让 frpc 用 websocket / wss 连接
BindAddr string `json:"bindAddr"`
// BindPort 是 frpc 连接的端口
BindPort int `json:"bindPort"`
Token string `json:"token"`
// ProxyBindAddr 是 HTTP / HTTPS 端口与 tcp / udp 代理远程端口的监听地址,留空监听所有地址
ProxyBindAddr string `json:"proxyBindAddr"`
// VhostHTTPPort 与 VhostHTTPSPort 为 0 时不启用 http / https 代理
VhostHTTPPort int `json:"vhostHttpPort"`
VhostHTTPSPort int `json:"vhostHttpsPort"`
// SubdomainHost 是子域名代理的根域名
SubdomainHost string `json:"subdomainHost"`
// AllowPorts 限制 frpc 可申请的远程端口,例如 "6000-6100,7000",留空不限制
AllowPorts string `json:"allowPorts"`
// 控制台端口为 0 时关闭
DashboardPort int `json:"dashboardPort"`
DashboardAddr string `json:"dashboardAddr"`
DashboardUser string `json:"dashboardUser"`
DashboardPwd string `json:"dashboardPwd"`
}
ServerSettings 是 frps(服务端)的监听与认证参数。
type ServerView ¶ added in v0.6.0
type ServerView struct {
Server
InstanceState
}
ServerView 是界面展示的 frps 实例,令牌与控制台密码已脱敏。
type Settings ¶ added in v0.6.0
type Settings struct {
// FrpcPath、FrpsPath 为空时依次在配置目录 bin 与 PATH 下查找 frpc、frps
FrpcPath string `json:"frpcPath"`
FrpsPath string `json:"frpsPath"`
}
Settings 是模块级设置。
type SettingsView ¶ added in v0.6.0
type SettingsView struct {
Settings Settings `json:"settings"`
Frpc BinaryView `json:"frpc"`
Frps BinaryView `json:"frps"`
}
SettingsView 是 GET /settings 的返回内容。