Skip to content

Commit

Permalink
feat: 🎸 add frpc
Browse files Browse the repository at this point in the history
  • Loading branch information
monlor committed Oct 18, 2024
1 parent 1e8cc95 commit 5865c73
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-image-manual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
- jenkins
- subconverter
- frps
- frpc
- vmianqian
- tokenpay
- n8n
Expand Down
13 changes: 13 additions & 0 deletions frpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ghcr.io/fatedier/frpc:v0.61.0

LABEL MAINTAINER [email protected]
LABEL VERSION v0.61.0

RUN apk add --no-cache dumb-init

# 复制入口脚本
COPY --chmod=755 entrypoint.sh /entrypoint.sh

# 设置入口点
ENTRYPOINT [ "dumb-init", "--", "/entrypoint.sh" ]

74 changes: 74 additions & 0 deletions frpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frpc Docker Service

This is a Docker service for frpc (Fast Reverse Proxy Client) that uses environment variables for configuration. You can easily set up various network tunnels by configuring environment variables.

## Usage

1. Pull the Docker image:

```bash
docker pull monlor/frpc
```

2. Run the Docker container with the necessary environment variables:

```bash
docker run -d \
-e SERVER_ADDR=your_frps_server_address \
-e SERVER_PORT=7000 \
-e TOKEN=your_frps_token \
-e TCP_SSH_22=127.0.0.1:22 \
-e HTTP_WEB_WWW=127.0.0.1:80 \
monlor/frpc
```

## Environment Variables

- `SERVER_ADDR`: frps server address (default: 127.0.0.1)
- `SERVER_PORT`: frps server port (default: 7000)
- `TOKEN`: frps authentication token (optional)

### Configuring Tunnels

You can configure tunnels by adding environment variables. The format is as follows:

1. TCP/UDP/KCP:
```
{PROTOCOL}_{NAME}_{REMOTE_PORT}=LOCAL_IP:LOCAL_PORT
```

2. HTTP/HTTPS:
```
{PROTOCOL}_{NAME}_{DOMAIN}=LOCAL_IP:LOCAL_PORT
```

3. HTTP_PROXY:
```
PROXY_{NAME}_{REMOTE_PORT}_{USER}={PASSWORD}
```

- `PROTOCOL`: Can be TCP, UDP, HTTP, HTTPS, or KCP
- `NAME`: Configuration name
- `REMOTE_PORT`: Port on the remote server
- `LOCAL_IP`: Local IP address
- `LOCAL_PORT`: Local port
- `DOMAIN`: Domain or subdomain for HTTP/HTTPS services (use underscores instead of dots for full domains)
- `USER`: Username for HTTP proxy
- `PASSWORD`: Password for HTTP proxy

Examples:

- `TCP_SSH_22=127.0.0.1:22`: Map local port 22 (SSH service) to remote server port 22
- `HTTP_WEB_WWW=127.0.0.1:80`: Map local port 80 (Web service) to subdomain www
- `HTTP_WEB_WWW_EXAMPLE_COM=127.0.0.1:80`: Map local port 80 to custom domain www.example.com
- `PROXY_HTTP_8080_USER=password`: Configure HTTP proxy on remote port 8080 with authentication

You can add any number of similar environment variables to configure multiple tunnels.

## Notes

- Ensure your frps server is properly configured and running
- Adjust firewall settings as needed to allow necessary port communications
- Do not expose sensitive services in public environments
- Some configuration types may require corresponding settings on the frps server side
- All domain names and configuration names are converted to lowercase in the final configuration
74 changes: 74 additions & 0 deletions frpc/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frpc Docker 服务

这是一个基于环境变量配置的frpc Docker服务。通过设置环境变量,您可以轻松配置frpc进行各种网络穿透。

## 使用方法

1. 拉取Docker镜像:

```bash
docker pull monlor/frpc
```

2. 运行Docker容器,设置必要的环境变量:

```bash
docker run -d \
-e SERVER_ADDR=your_frps_server_address \
-e SERVER_PORT=7000 \
-e TOKEN=your_frps_token \
-e TCP_SSH_22=127.0.0.1:22 \
-e HTTP_WEB_WWW=127.0.0.1:80 \
monlor/frpc
```

## 环境变量说明

- `SERVER_ADDR`: frps服务器地址 (默认: 127.0.0.1)
- `SERVER_PORT`: frps服务器端口 (默认: 7000)
- `TOKEN`: frps认证令牌 (可选)

### 配置穿透规则

您可以通过添加环境变量来配置穿透规则。格式如下:

1. TCP/UDP/KCP:
```
{PROTOCOL}_{NAME}_{REMOTE_PORT}=LOCAL_IP:LOCAL_PORT
```

2. HTTP/HTTPS:
```
{PROTOCOL}_{NAME}_{DOMAIN}=LOCAL_IP:LOCAL_PORT
```

3. HTTP_PROXY:
```
PROXY_{NAME}_{REMOTE_PORT}_{USER}={PASSWORD}
```

- `PROTOCOL`: 可以是TCP, UDP, HTTP, HTTPS, 或 KCP
- `NAME`: 配置名称
- `REMOTE_PORT`: 远程服务器上的端口
- `LOCAL_IP`: 本地IP地址
- `LOCAL_PORT`: 本地端口
- `DOMAIN`: HTTP/HTTPS服务的域名或子域名(使用下划线代替点来表示完整域名)
- `USER`: HTTP代理的用户名
- `PASSWORD`: HTTP代理的密码

例如:

- `TCP_SSH_22=127.0.0.1:22`: 将本地的22端口(SSH服务)映射到远程服务器的22端口
- `HTTP_WEB_WWW=127.0.0.1:80`: 将本地的80端口(Web服务)映射到子域名www
- `HTTP_WEB_WWW_EXAMPLE_COM=127.0.0.1:80`: 将本地的80端口映射到自定义域名www.example.com
- `PROXY_HTTP_8080_USER=password`: 在远程8080端口配置带认证的HTTP代理

您可以添加任意数量的类似环境变量来配置多个穿透规则。

## 注意事项

- 确保您的frps服务器已正确配置并运行
- 根据需要调整防火墙设置,以允许必要的端口通信
- 请勿在公共环境中暴露敏感服务
- 某些配置类型可能需要在frps服务器端进行相应的设置
- 所有域名和配置名称在最终配置中都会被转换为小写
68 changes: 68 additions & 0 deletions frpc/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh

# 生成frpc.toml配置文件
cat > /frpc.toml <<EOF
serverAddr = "${SERVER_ADDR:-127.0.0.1}"
serverPort = ${SERVER_PORT:-7000}
[auth]
token = "${TOKEN:-}"
EOF

# 处理环境变量,生成frpc配置
env | grep -E "^(TCP|UDP|HTTP|HTTPS|PROXY|KCP)_" | while read -r line; do
name=$(echo "$line" | cut -d'=' -f1)
value=$(echo "$line" | cut -d'=' -f2-)

protocol=$(echo "$name" | cut -d'_' -f1 | tr '[:upper:]' '[:lower:]')

if [ "$protocol" = "http" ] || [ "$protocol" = "https" ]; then
config_name=$(echo "$name" | cut -d'_' -f2 | tr '[:upper:]' '[:lower:]')
domain=$(echo "$name" | cut -d'_' -f3- | tr '_' '.' | tr '[:upper:]' '[:lower:]')
port=$(echo $value | cut -d':' -f2)
config_name="${config_name}_${port}"
elif [ "$protocol" = "proxy" ]; then
config_name=$(echo "$name" | cut -d'_' -f2 | tr '[:upper:]' '[:lower:]')
remote_port=$(echo "$name" | cut -d'_' -f3)
user=$(echo "$name" | cut -d'_' -f4)
config_name="${config_name}_${remote_port}"
else
config_name=$(echo "$name" | cut -d'_' -f2- | tr '[:upper:]' '[:lower:]')
fi

echo "[[proxies]]" >> /frpc.toml
echo "name = \"$config_name\"" >> /frpc.toml

case $protocol in
http|https)
echo "type = \"$protocol\"" >> /frpc.toml
echo "localIP = \"$(echo $value | cut -d':' -f1)\"" >> /frpc.toml
echo "localPort = $port" >> /frpc.toml
if echo "$domain" | grep -q "\\."; then
echo "customDomains = [\"$domain\"]" >> /frpc.toml
else
echo "subdomain = \"$domain\"" >> /frpc.toml
fi
;;
tcp|udp|kcp)
echo "type = \"$protocol\"" >> /frpc.toml
echo "localIP = \"$(echo $value | cut -d':' -f1)\"" >> /frpc.toml
echo "localPort = $(echo $value | cut -d':' -f2)" >> /frpc.toml
echo "remotePort = $(echo $name | cut -d'_' -f3)" >> /frpc.toml
;;
proxy)
echo "type = \"tcp\"" >> /frpc.toml
echo "remotePort = $remote_port" >> /frpc.toml
echo "[proxies.plugin]" >> /frpc.toml
echo "type = \"http_proxy\"" >> /frpc.toml
echo "httpUser = \"$user\"" >> /frpc.toml
echo "httpPassword = \"$value\"" >> /frpc.toml
;;
esac

echo "" >> /frpc.toml
done

# 启动frpc
exec frpc -c /frpc.toml

0 comments on commit 5865c73

Please sign in to comment.