mirror of
https://github.com/fatedier/frp.git
synced 2025-07-29 09:18:11 +00:00
Compare commits
176 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a4189ba474 | ||
|
e2d28d9929 | ||
|
9ec84f8143 | ||
|
7678938c08 | ||
|
b2e3946800 | ||
|
af0b7939a7 | ||
|
2f66dc3e99 | ||
|
649df8827c | ||
|
da51adc276 | ||
|
e5af37bc8c | ||
|
8ab474cc97 | ||
|
e8c8d5903a | ||
|
a301046f3d | ||
|
34ab6b0e74 | ||
|
cf66ca10b4 | ||
|
3fbe6b659e | ||
|
6a71d71e58 | ||
|
6ecc97c857 | ||
|
ba492f07c3 | ||
|
9d077b02cf | ||
|
f4e4fbea62 | ||
|
3e721d122b | ||
|
1bc899ec12 | ||
|
6f2571980c | ||
|
8888610d83 | ||
|
fa7c05c617 | ||
|
218b354f82 | ||
|
c652b8ef07 | ||
|
5b8b145577 | ||
|
fe5fb0326b | ||
|
0711295b0a | ||
|
4af85da0c2 | ||
|
bd89eaba2f | ||
|
a72259c604 | ||
|
44eb513f05 | ||
|
eb1e19a821 | ||
|
6c658586f6 | ||
|
888ed25314 | ||
|
21240ed962 | ||
|
6481870d03 | ||
|
a7a4ba270d | ||
|
915d9f4c09 | ||
|
18a2af4703 | ||
|
305e40fa8a | ||
|
10f2620131 | ||
|
4acae540c8 | ||
|
11b13533a0 | ||
|
100d556336 | ||
|
452fe25cc6 | ||
|
63efa6b776 | ||
|
37c27169ac | ||
|
ce677820c6 | ||
|
1f88a7a0b8 | ||
|
eeea7602d9 | ||
|
bf635c0e90 | ||
|
cd31359a27 | ||
|
19739ed31a | ||
|
10100c28d9 | ||
|
88fcc079e8 | ||
|
ddc1e163c4 | ||
|
d20a6d3d75 | ||
|
6194273615 | ||
|
b2311e55e7 | ||
|
07873d471f | ||
|
2dab5d0bca | ||
|
9ca2b586f8 | ||
|
e59eacb8a2 | ||
|
0db4fc07fb | ||
|
70f4caac23 | ||
|
293003fcdb | ||
|
4bfc89d988 | ||
|
22412851b4 | ||
|
e9775bd70f | ||
|
ff7b8b0b62 | ||
|
491c1d7dc4 | ||
|
ea568e8a4f | ||
|
0fb6aeef58 | ||
|
032f33fe5a | ||
|
bbc8b438d5 | ||
|
05b1ace21f | ||
|
cbdd73b94f | ||
|
bf06e3b107 | ||
|
143750901e | ||
|
71489d194c | ||
|
85aa3df256 | ||
|
f1a51eba18 | ||
|
1d26ea440b | ||
|
998e678a7f | ||
|
0cee1877e3 | ||
|
72a7fd948e | ||
|
357c9b0dcb | ||
|
14bd0716d0 | ||
|
2f74f54f18 | ||
|
a62a9431b1 | ||
|
42745a3da2 | ||
|
82f80a22be | ||
|
f570dcb307 | ||
|
997d406ec2 | ||
|
87e60683ed | ||
|
86b2e686a5 | ||
|
09f39de74e | ||
|
2a68c1152f | ||
|
df5859b5f7 | ||
|
3dd888a9ea | ||
|
a51e221db3 | ||
|
fe4e9b55f3 | ||
|
3f11b6a082 | ||
|
8a333c2ae0 | ||
|
1fd6ba2738 | ||
|
a98a9616f6 | ||
|
95cd9ab900 | ||
|
900454e58b | ||
|
c7d4637382 | ||
|
56925961df | ||
|
cfd1a3128a | ||
|
2393923870 | ||
|
5f594e9a71 | ||
|
57577ea044 | ||
|
8637077d90 | ||
|
ccb85a9926 | ||
|
02b12df887 | ||
|
c32a2ed140 | ||
|
9ae322cccf | ||
|
9cebfccb39 | ||
|
630dad50ed | ||
|
0d84da91d4 | ||
|
2408f1df04 | ||
|
fbaa5f866e | ||
|
c5c79e4148 | ||
|
9a849a29e9 | ||
|
6b80861bd6 | ||
|
fa0e84382e | ||
|
1a11b28f8d | ||
|
bed13d7ef1 | ||
|
e7d76b180d | ||
|
dba8925eaa | ||
|
55da58eca4 | ||
|
fdef7448a7 | ||
|
0ff27fc9ac | ||
|
76a1efccd9 | ||
|
9f8db314d6 | ||
|
980f084ad1 | ||
|
0c35863d97 | ||
|
184a0ff9ab | ||
|
8e25f13201 | ||
|
b5aee82ca9 | ||
|
0a2384a283 | ||
|
78b8bb7bc6 | ||
|
8fcd4f4a95 | ||
|
976fd81d4d | ||
|
52d5c9e25b | ||
|
fa89671452 | ||
|
3621aad1c1 | ||
|
3bf1eb8565 | ||
|
a821db3f45 | ||
|
ecb6ed9258 | ||
|
b2ae433e18 | ||
|
b26080589b | ||
|
aff979c2b6 | ||
|
46f809d711 | ||
|
72595b2da8 | ||
|
c842558ace | ||
|
ed61049041 | ||
|
abe6f580c0 | ||
|
e940066012 | ||
|
1e846df870 | ||
|
0ab055e946 | ||
|
fca59c71e2 | ||
|
fae2f8768d | ||
|
3d9499f554 | ||
|
7adeeedd55 | ||
|
127a31ea6a | ||
|
a85bd9a4d9 | ||
|
01d551ec8d | ||
|
16cabf4127 | ||
|
968be4a2c2 |
25
.circleci/config.yml
Normal file
25
.circleci/config.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
go-version-latest:
|
||||||
|
docker:
|
||||||
|
- image: cimg/go:1.19-node
|
||||||
|
resource_class: large
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: make
|
||||||
|
- run: make alltest
|
||||||
|
go-version-last:
|
||||||
|
docker:
|
||||||
|
- image: cimg/go:1.18-node
|
||||||
|
resource_class: large
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: make
|
||||||
|
- run: make alltest
|
||||||
|
|
||||||
|
workflows:
|
||||||
|
version: 2
|
||||||
|
build_and_test:
|
||||||
|
jobs:
|
||||||
|
- go-version-latest
|
||||||
|
- go-version-last
|
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [fatedier]
|
44
.github/ISSUE_TEMPLATE/bug-report.md
vendored
44
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@@ -1,44 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug Report
|
|
||||||
about: Bug Report for FRP
|
|
||||||
title: ''
|
|
||||||
labels: Requires Testing
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<!-- From Chinese to English by machine translation, welcome to revise and polish. -->
|
|
||||||
|
|
||||||
<!-- ⚠️⚠️ Incomplete reports will be marked as invalid, and closed, with few exceptions ⚠️⚠️ -->
|
|
||||||
<!-- in addition, please use search well so that the same solution can be found in the feedback, we will close it directly -->
|
|
||||||
<!-- for convenience of differentiation, use FRPS or FRPC to refer to the FRP server or client -->
|
|
||||||
|
|
||||||
**[REQUIRED] hat version of frp are you using**
|
|
||||||
<!-- Use ./frpc -v or ./frps -v -->
|
|
||||||
Version:
|
|
||||||
|
|
||||||
**[REQUIRED] What operating system and processor architecture are you using**
|
|
||||||
OS:
|
|
||||||
CPU architecture:
|
|
||||||
|
|
||||||
**[REQUIRED] description of errors**
|
|
||||||
|
|
||||||
**confile**
|
|
||||||
<!-- Please pay attention to hiding the token, server_addr and other privacy information -->
|
|
||||||
|
|
||||||
**log file**
|
|
||||||
<!-- If the file is too large, use Pastebin, for example https://pastebin.ubuntu.com/ -->
|
|
||||||
|
|
||||||
**Steps to reproduce the issue**
|
|
||||||
1.
|
|
||||||
2.
|
|
||||||
3.
|
|
||||||
|
|
||||||
**Supplementary information**
|
|
||||||
|
|
||||||
**Can you guess what caused this issue**
|
|
||||||
|
|
||||||
**Checklist**:
|
|
||||||
<!--- Make sure you've completed the following steps (put an "X" between of brackets): -->
|
|
||||||
- [] I included all information required in the sections above
|
|
||||||
- [] I made sure there are no duplicates of this report [(Use Search)](https://github.com/fatedier/frp/issues?q=is%3Aissue)
|
|
77
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
77
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
name: Bug report
|
||||||
|
description: Report a bug to help us improve frp
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: bug-description
|
||||||
|
attributes:
|
||||||
|
label: Bug Description
|
||||||
|
description: Tell us what issues you ran into
|
||||||
|
placeholder: Include information about what you tried, what you expected to happen, and what actually happened. The more details, the better!
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: frpc-version
|
||||||
|
attributes:
|
||||||
|
label: frpc Version
|
||||||
|
description: Include the output of `frpc -v`
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: frps-version
|
||||||
|
attributes:
|
||||||
|
label: frps Version
|
||||||
|
description: Include the output of `frps -v`
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: system-architecture
|
||||||
|
attributes:
|
||||||
|
label: System Architecture
|
||||||
|
description: Include which architecture you used, such as `linux/amd64`, `windows/amd64`
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: config
|
||||||
|
attributes:
|
||||||
|
label: Configurations
|
||||||
|
description: Include what configurrations you used and ran into this problem
|
||||||
|
placeholder: Pay attention to hiding the token and password in your output
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: log
|
||||||
|
attributes:
|
||||||
|
label: Logs
|
||||||
|
description: Prefer you providing releated error logs here
|
||||||
|
placeholder: Pay attention to hiding your personal informations
|
||||||
|
- type: textarea
|
||||||
|
id: steps-to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: How to reproduce it? It's important for us to find the bug
|
||||||
|
value: |
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
...
|
||||||
|
- type: checkboxes
|
||||||
|
id: area
|
||||||
|
attributes:
|
||||||
|
label: Affected area
|
||||||
|
options:
|
||||||
|
- label: "Docs"
|
||||||
|
- label: "Installation"
|
||||||
|
- label: "Performance and Scalability"
|
||||||
|
- label: "Security"
|
||||||
|
- label: "User Experience"
|
||||||
|
- label: "Test and Release"
|
||||||
|
- label: "Developer Infrastructure"
|
||||||
|
- label: "Client Plugin"
|
||||||
|
- label: "Server Plugin"
|
||||||
|
- label: "Extensions"
|
||||||
|
- label: "Others"
|
4
.github/ISSUE_TEMPLATE/config.yml
vendored
4
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
contact_links:
|
|
||||||
- name: DOCS
|
|
||||||
url: https://github.com/fatedier/frp
|
|
||||||
about: Here you can find out how to configure frp.
|
|
||||||
|
22
.github/ISSUE_TEMPLATE/feature_request.md
vendored
22
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: "[+] Enhancement"
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<!-- From Chinese to English by machine translation, welcome to revise and polish. -->
|
|
||||||
|
|
||||||
**The solution you want**
|
|
||||||
<!--A clear and concise description of the solution you want. -->
|
|
||||||
|
|
||||||
**Alternatives considered**
|
|
||||||
<!--A clear and concise description of any alternative solutions or features you have considered. -->
|
|
||||||
|
|
||||||
**How to implement this function**
|
|
||||||
<!--Implementation steps for the solution you want. -->
|
|
||||||
|
|
||||||
**Application scenarios of this function**
|
|
||||||
<!--Make a clear and concise description of the application scenario of the solution you want. -->
|
|
36
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
36
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
name: Feature Request
|
||||||
|
description: Suggest an idea to improve frp
|
||||||
|
title: "[Feature Request] "
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
This is only used to request new product features.
|
||||||
|
- type: textarea
|
||||||
|
id: feature-request
|
||||||
|
attributes:
|
||||||
|
label: Describe the feature request
|
||||||
|
description: Tell us what's you want and why it should be added in frp.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: alternatives
|
||||||
|
attributes:
|
||||||
|
label: Describe alternatives you've considered
|
||||||
|
- type: checkboxes
|
||||||
|
id: area
|
||||||
|
attributes:
|
||||||
|
label: Affected area
|
||||||
|
options:
|
||||||
|
- label: "Docs"
|
||||||
|
- label: "Installation"
|
||||||
|
- label: "Performance and Scalability"
|
||||||
|
- label: "Security"
|
||||||
|
- label: "User Experience"
|
||||||
|
- label: "Test and Release"
|
||||||
|
- label: "Developer Infrastructure"
|
||||||
|
- label: "Client Plugin"
|
||||||
|
- label: "Server Plugin"
|
||||||
|
- label: "Extensions"
|
||||||
|
- label: "Others"
|
130
.github/workflows/build-and-push-image.yml
vendored
130
.github/workflows/build-and-push-image.yml
vendored
@@ -9,79 +9,49 @@ on:
|
|||||||
description: 'Image tag'
|
description: 'Image tag'
|
||||||
required: true
|
required: true
|
||||||
default: 'test'
|
default: 'test'
|
||||||
jobs:
|
permissions:
|
||||||
binary:
|
contents: read
|
||||||
name: Build Golang project
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Set up Go 1.x
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.15
|
|
||||||
-
|
|
||||||
run: go version
|
|
||||||
-
|
|
||||||
name: Check out code into the Go module directory
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
-
|
|
||||||
name: Build
|
|
||||||
run: make build
|
|
||||||
-
|
|
||||||
name: Archive artifacts for frpc
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
|
||||||
name: frpc
|
|
||||||
path: bin/frpc
|
|
||||||
-
|
|
||||||
name: Archive artifacts for frps
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
|
||||||
name: frps
|
|
||||||
path: bin/frps
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
image:
|
image:
|
||||||
name: Build Image from Dockerfile and binaries
|
name: Build Image from Dockerfile and binaries
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: binary
|
|
||||||
steps:
|
steps:
|
||||||
# environment
|
# environment
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
uses: actions/checkout@v3
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
with:
|
||||||
fetch-depth: '0'
|
fetch-depth: '0'
|
||||||
-
|
|
||||||
name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
# download binaries of frpc and frps
|
|
||||||
-
|
|
||||||
name: Download binary of frpc
|
|
||||||
uses: actions/download-artifact@v2
|
|
||||||
with:
|
|
||||||
name: frpc
|
|
||||||
path: bin/frpc
|
|
||||||
-
|
|
||||||
name: Download binary of frps
|
|
||||||
uses: actions/download-artifact@v2
|
|
||||||
with:
|
|
||||||
name: frps
|
|
||||||
path: bin/frps
|
|
||||||
# get image tag name
|
# get image tag name
|
||||||
-
|
- name: Get Image Tag Name
|
||||||
name: Get Image Tag Name
|
|
||||||
run: |
|
run: |
|
||||||
if [ x${{ github.event.inputs.tag }} == x"" ]; then
|
if [ x${{ github.event.inputs.tag }} == x"" ]; then
|
||||||
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
else
|
else
|
||||||
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
|
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Login to the GPR
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GPR_TOKEN }}
|
||||||
|
|
||||||
# prepare image tags
|
# prepare image tags
|
||||||
-
|
- name: Prepare Image Tags
|
||||||
name: Prepare Image Tags
|
|
||||||
run: |
|
run: |
|
||||||
echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV
|
echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV
|
||||||
echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV
|
echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV
|
||||||
@@ -89,27 +59,25 @@ jobs:
|
|||||||
echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
||||||
echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
||||||
echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
|
||||||
# build images
|
|
||||||
-
|
- name: Build and push frpc
|
||||||
name: Build Images
|
uses: docker/build-push-action@v3
|
||||||
run: |
|
with:
|
||||||
# for Docker hub
|
context: .
|
||||||
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC }} .
|
file: ./dockerfiles/Dockerfile-for-frpc
|
||||||
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS }} .
|
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
|
||||||
# for GPR
|
push: true
|
||||||
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC_GPR }} .
|
tags: |
|
||||||
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS_GPR }} .
|
${{ env.TAG_FRPC }}
|
||||||
# push to dockerhub
|
${{ env.TAG_FRPC_GPR }}
|
||||||
-
|
|
||||||
name: Publish to Dockerhub
|
- name: Build and push frps
|
||||||
run: |
|
uses: docker/build-push-action@v3
|
||||||
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
with:
|
||||||
docker push ${{ env.TAG_FRPC }}
|
context: .
|
||||||
docker push ${{ env.TAG_FRPS }}
|
file: ./dockerfiles/Dockerfile-for-frps
|
||||||
# push to gpr
|
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
|
||||||
-
|
push: true
|
||||||
name: Publish to GPR
|
tags: |
|
||||||
run: |
|
${{ env.TAG_FRPS }}
|
||||||
echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
|
${{ env.TAG_FRPS_GPR }}
|
||||||
docker push ${{ env.TAG_FRPC_GPR }}
|
|
||||||
docker push ${{ env.TAG_FRPS_GPR }}
|
|
||||||
|
41
.github/workflows/golangci-lint.yml
vendored
Normal file
41
.github/workflows/golangci-lint.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
name: golangci-lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- dev
|
||||||
|
pull_request:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||||
|
pull-requests: read
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.19
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||||
|
version: v1.49.0
|
||||||
|
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
# args: --issues-exit-code=0
|
||||||
|
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
# only-new-issues: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the all caching functionality will be complete disabled,
|
||||||
|
# takes precedence over all other caching options.
|
||||||
|
# skip-cache: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
||||||
|
# skip-pkg-cache: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||||
|
# skip-build-cache: true
|
12
.github/workflows/goreleaser.yml
vendored
12
.github/workflows/goreleaser.yml
vendored
@@ -8,23 +8,23 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.19
|
||||||
|
|
||||||
- name: Make All
|
- name: Make All
|
||||||
run: |
|
run: |
|
||||||
./package.sh
|
./package.sh
|
||||||
|
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v2
|
uses: goreleaser/goreleaser-action@v3
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: release --rm-dist --release-notes=./Release.md
|
args: release --rm-dist --release-notes=./Release.md
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GPR_TOKEN }}
|
||||||
|
18
.github/workflows/stale.yml
vendored
18
.github/workflows/stale.yml
vendored
@@ -8,19 +8,27 @@ on:
|
|||||||
description: 'In debug mod'
|
description: 'In debug mod'
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
|
permissions:
|
||||||
|
issues: write # for actions/stale to close stale issues
|
||||||
|
pull-requests: write # for actions/stale to close stale PRs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v6
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'Issues go stale after 45d of inactivity. Stale issues rot after an additional 10d of inactivity and eventually close.'
|
stale-issue-message: 'Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.'
|
||||||
stale-pr-message: 'Issues go stale after 45d of inactivity. Stale issues rot after an additional 10d of inactivity and eventually close.'
|
stale-pr-message: "PRs go stale after 30d of inactivity. Stale PRs rot after an additional 7d of inactivity and eventually close."
|
||||||
stale-issue-label: 'lifecycle/stale'
|
stale-issue-label: 'lifecycle/stale'
|
||||||
exempt-issue-labels: 'bug,doc,enhancement,future,proposal,question,testing,todo,easy,help wanted,assigned'
|
exempt-issue-labels: 'bug,doc,enhancement,future,proposal,question,testing,todo,easy,help wanted,assigned'
|
||||||
stale-pr-label: 'lifecycle/stale'
|
stale-pr-label: 'lifecycle/stale'
|
||||||
exempt-pr-labels: 'bug,doc,enhancement,future,proposal,question,testing,todo,easy,help wanted,assigned'
|
exempt-pr-labels: 'bug,doc,enhancement,future,proposal,question,testing,todo,easy,help wanted,assigned'
|
||||||
days-before-stale: 45
|
days-before-stale: 30
|
||||||
days-before-close: 10
|
days-before-close: 7
|
||||||
debug-only: ${{ github.event.inputs.debug-only }}
|
debug-only: ${{ github.event.inputs.debug-only }}
|
||||||
|
exempt-all-pr-milestones: true
|
||||||
|
exempt-all-pr-assignees: true
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,6 +30,8 @@ release/
|
|||||||
test/bin/
|
test/bin/
|
||||||
vendor/
|
vendor/
|
||||||
dist/
|
dist/
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# Cache
|
# Cache
|
||||||
*.swp
|
*.swp
|
||||||
|
140
.golangci.yml
Normal file
140
.golangci.yml
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
service:
|
||||||
|
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the istio/tools repo.
|
||||||
|
golangci-lint-version: 1.49.x # use the fixed version to not introduce new linters unexpectedly
|
||||||
|
|
||||||
|
run:
|
||||||
|
concurrency: 4
|
||||||
|
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||||
|
deadline: 20m
|
||||||
|
build-tags:
|
||||||
|
- integ
|
||||||
|
- integfuzz
|
||||||
|
# which dirs to skip: they won't be analyzed;
|
||||||
|
# can use regexp here: generated.*, regexp is applied on full path;
|
||||||
|
# default value is empty list, but next dirs are always skipped independently
|
||||||
|
# from this option's value:
|
||||||
|
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||||
|
skip-dirs:
|
||||||
|
- genfiles$
|
||||||
|
- vendor$
|
||||||
|
- bin$
|
||||||
|
|
||||||
|
# which files to skip: they will be analyzed, but issues from them
|
||||||
|
# won't be reported. Default value is empty list, but there is
|
||||||
|
# no need to include all autogenerated files, we confidently recognize
|
||||||
|
# autogenerated files. If it's not please let us know.
|
||||||
|
skip-files:
|
||||||
|
- ".*\\.pb\\.go"
|
||||||
|
- ".*\\.gen\\.go"
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- unused
|
||||||
|
- errcheck
|
||||||
|
- exportloopref
|
||||||
|
- gocritic
|
||||||
|
- gofumpt
|
||||||
|
- goimports
|
||||||
|
- revive
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- lll
|
||||||
|
- misspell
|
||||||
|
- staticcheck
|
||||||
|
- stylecheck
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- gci
|
||||||
|
- gosec
|
||||||
|
- asciicheck
|
||||||
|
- prealloc
|
||||||
|
- predeclared
|
||||||
|
- makezero
|
||||||
|
fast: false
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
errcheck:
|
||||||
|
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
|
||||||
|
# default is false: such cases aren't reported by default.
|
||||||
|
check-type-assertions: false
|
||||||
|
|
||||||
|
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||||
|
# default is false: such cases aren't reported by default.
|
||||||
|
check-blank: false
|
||||||
|
govet:
|
||||||
|
# report about shadowed variables
|
||||||
|
check-shadowing: false
|
||||||
|
maligned:
|
||||||
|
# print struct with more effective memory layout or not, false by default
|
||||||
|
suggest-new: true
|
||||||
|
misspell:
|
||||||
|
# Correct spellings using locale preferences for US or UK.
|
||||||
|
# Default is to use a neutral variety of English.
|
||||||
|
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||||
|
locale: US
|
||||||
|
ignore-words:
|
||||||
|
- cancelled
|
||||||
|
- marshalled
|
||||||
|
lll:
|
||||||
|
# max line length, lines longer will be reported. Default is 120.
|
||||||
|
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||||
|
line-length: 160
|
||||||
|
# tab width in spaces. Default to 1.
|
||||||
|
tab-width: 1
|
||||||
|
gocritic:
|
||||||
|
disabled-checks:
|
||||||
|
- exitAfterDefer
|
||||||
|
unused:
|
||||||
|
check-exported: false
|
||||||
|
unparam:
|
||||||
|
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||||
|
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||||
|
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||||
|
# with golangci-lint call it on a directory with the changed file.
|
||||||
|
check-exported: false
|
||||||
|
gci:
|
||||||
|
sections:
|
||||||
|
- standard
|
||||||
|
- default
|
||||||
|
- prefix(github.com/fatedier/frp/)
|
||||||
|
gosec:
|
||||||
|
severity: "low"
|
||||||
|
confidence: "low"
|
||||||
|
excludes:
|
||||||
|
- G102
|
||||||
|
- G112
|
||||||
|
- G306
|
||||||
|
- G401
|
||||||
|
- G402
|
||||||
|
- G404
|
||||||
|
- G501
|
||||||
|
|
||||||
|
issues:
|
||||||
|
# List of regexps of issue texts to exclude, empty list by default.
|
||||||
|
# But independently from this option we use default exclude patterns,
|
||||||
|
# it can be disabled by `exclude-use-default: false`. To list all
|
||||||
|
# excluded by default patterns execute `golangci-lint run --help`
|
||||||
|
# exclude:
|
||||||
|
# - composite literal uses unkeyed fields
|
||||||
|
|
||||||
|
exclude-rules:
|
||||||
|
# Exclude some linters from running on test files.
|
||||||
|
- path: _test\.go$|^tests/|^samples/
|
||||||
|
linters:
|
||||||
|
- errcheck
|
||||||
|
- maligned
|
||||||
|
|
||||||
|
# Independently from option `exclude` we use default exclude patterns,
|
||||||
|
# it can be disabled by this option. To list all
|
||||||
|
# excluded by default patterns execute `golangci-lint run --help`.
|
||||||
|
# Default value for this option is true.
|
||||||
|
exclude-use-default: true
|
||||||
|
|
||||||
|
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||||
|
max-per-linter: 0
|
||||||
|
|
||||||
|
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||||
|
max-same-issues: 0
|
@@ -1,7 +1,10 @@
|
|||||||
builds:
|
builds:
|
||||||
- skip: true
|
- skip: true
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: '{{ .ProjectName }}_sha256_checksums.txt'
|
||||||
|
algorithm: sha256
|
||||||
|
extra_files:
|
||||||
|
- glob: ./release/packages/*
|
||||||
release:
|
release:
|
||||||
# Same as for github
|
# Same as for github
|
||||||
# Note: it can only be one: either github, gitlab or gitea
|
# Note: it can only be one: either github, gitlab or gitea
|
||||||
|
12
.travis.yml
12
.travis.yml
@@ -1,12 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.14.x
|
|
||||||
- 1.15.x
|
|
||||||
|
|
||||||
install:
|
|
||||||
- make
|
|
||||||
|
|
||||||
script:
|
|
||||||
- make alltest
|
|
14
Makefile
14
Makefile
@@ -12,13 +12,13 @@ file:
|
|||||||
rm -rf ./assets/frpc/static/*
|
rm -rf ./assets/frpc/static/*
|
||||||
cp -rf ./web/frps/dist/* ./assets/frps/static
|
cp -rf ./web/frps/dist/* ./assets/frps/static
|
||||||
cp -rf ./web/frpc/dist/* ./assets/frpc/static
|
cp -rf ./web/frpc/dist/* ./assets/frpc/static
|
||||||
rm -rf ./assets/frps/statik
|
|
||||||
rm -rf ./assets/frpc/statik
|
|
||||||
go generate ./assets/...
|
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
vet:
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
frps:
|
frps:
|
||||||
env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/frps ./cmd/frps
|
env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/frps ./cmd/frps
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ gotest:
|
|||||||
go test -v --cover ./server/...
|
go test -v --cover ./server/...
|
||||||
go test -v --cover ./pkg/...
|
go test -v --cover ./pkg/...
|
||||||
|
|
||||||
ci:
|
|
||||||
go test -count=1 -p=1 -v ./tests/...
|
|
||||||
|
|
||||||
e2e:
|
e2e:
|
||||||
./hack/run-e2e.sh
|
./hack/run-e2e.sh
|
||||||
|
|
||||||
alltest: gotest ci e2e
|
e2e-trace:
|
||||||
|
DEBUG=true LOG_LEVEL=trace ./hack/run-e2e.sh
|
||||||
|
|
||||||
|
alltest: vet gotest e2e
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ./bin/frpc
|
rm -f ./bin/frpc
|
||||||
|
@@ -2,34 +2,24 @@ export PATH := $(GOPATH)/bin:$(PATH)
|
|||||||
export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
LDFLAGS := -s -w
|
LDFLAGS := -s -w
|
||||||
|
|
||||||
|
os-archs=darwin:amd64 darwin:arm64 freebsd:386 freebsd:amd64 linux:386 linux:amd64 linux:arm linux:arm64 windows:386 windows:amd64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
build: app
|
build: app
|
||||||
|
|
||||||
app:
|
app:
|
||||||
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_darwin_amd64 ./cmd/frpc
|
@$(foreach n, $(os-archs),\
|
||||||
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_darwin_amd64 ./cmd/frps
|
os=$(shell echo "$(n)" | cut -d : -f 1);\
|
||||||
env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_freebsd_386 ./cmd/frpc
|
arch=$(shell echo "$(n)" | cut -d : -f 2);\
|
||||||
env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_freebsd_386 ./cmd/frps
|
gomips=$(shell echo "$(n)" | cut -d : -f 3);\
|
||||||
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_freebsd_amd64 ./cmd/frpc
|
target_suffix=$${os}_$${arch};\
|
||||||
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_freebsd_amd64 ./cmd/frps
|
echo "Build $${os}-$${arch}...";\
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_386 ./cmd/frpc
|
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_$${target_suffix} ./cmd/frpc;\
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_386 ./cmd/frps
|
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_$${target_suffix} ./cmd/frps;\
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_amd64 ./cmd/frpc
|
echo "Build $${os}-$${arch} done";\
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_amd64 ./cmd/frps
|
)
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_arm ./cmd/frpc
|
@mv ./release/frpc_windows_386 ./release/frpc_windows_386.exe
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_arm ./cmd/frps
|
@mv ./release/frps_windows_386 ./release/frps_windows_386.exe
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_arm64 ./cmd/frpc
|
@mv ./release/frpc_windows_amd64 ./release/frpc_windows_amd64.exe
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_arm64 ./cmd/frps
|
@mv ./release/frps_windows_amd64 ./release/frps_windows_amd64.exe
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_windows_386.exe ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_windows_386.exe ./cmd/frps
|
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_windows_amd64.exe ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_windows_amd64.exe ./cmd/frps
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_mips64 ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_mips64 ./cmd/frps
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_mips64le ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_mips64le ./cmd/frps
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_mips ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_mips ./cmd/frps
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_linux_mipsle ./cmd/frpc
|
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_linux_mipsle ./cmd/frps
|
|
||||||
|
229
README.md
229
README.md
@@ -1,10 +1,26 @@
|
|||||||
|
|
||||||
# frp
|
# frp
|
||||||
|
|
||||||
[](https://travis-ci.org/fatedier/frp)
|
[](https://circleci.com/gh/fatedier/frp)
|
||||||
[](https://github.com/fatedier/frp/releases)
|
[](https://github.com/fatedier/frp/releases)
|
||||||
|
|
||||||
[README](README.md) | [中文文档](README_zh.md)
|
[README](README.md) | [中文文档](README_zh.md)
|
||||||
|
|
||||||
|
<h3 align="center">Gold Sponsors</h3>
|
||||||
|
<!--gold sponsors start-->
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
|
||||||
|
<img width="300px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!--gold sponsors end-->
|
||||||
|
|
||||||
|
<h3 align="center">Silver Sponsors</h3>
|
||||||
|
|
||||||
|
* Sakura Frp - 欢迎点击 "加入我们"
|
||||||
|
|
||||||
## What is frp?
|
## What is frp?
|
||||||
|
|
||||||
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it supports **TCP** and **UDP**, as well as **HTTP** and **HTTPS** protocols, where requests can be forwarded to internal services by domain name.
|
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it supports **TCP** and **UDP**, as well as **HTTP** and **HTTPS** protocols, where requests can be forwarded to internal services by domain name.
|
||||||
@@ -23,12 +39,13 @@ frp also has a P2P connect mode.
|
|||||||
* [Forward DNS query request](#forward-dns-query-request)
|
* [Forward DNS query request](#forward-dns-query-request)
|
||||||
* [Forward Unix domain socket](#forward-unix-domain-socket)
|
* [Forward Unix domain socket](#forward-unix-domain-socket)
|
||||||
* [Expose a simple HTTP file server](#expose-a-simple-http-file-server)
|
* [Expose a simple HTTP file server](#expose-a-simple-http-file-server)
|
||||||
* [Enable HTTPS for local HTTP service](#enable-https-for-local-http-service)
|
* [Enable HTTPS for local HTTP(S) service](#enable-https-for-local-https-service)
|
||||||
* [Expose your service privately](#expose-your-service-privately)
|
* [Expose your service privately](#expose-your-service-privately)
|
||||||
* [P2P Mode](#p2p-mode)
|
* [P2P Mode](#p2p-mode)
|
||||||
* [Features](#features)
|
* [Features](#features)
|
||||||
* [Configuration Files](#configuration-files)
|
* [Configuration Files](#configuration-files)
|
||||||
* [Using Environment Variables](#using-environment-variables)
|
* [Using Environment Variables](#using-environment-variables)
|
||||||
|
* [Split Configures Into Different Files](#split-configures-into-different-files)
|
||||||
* [Dashboard](#dashboard)
|
* [Dashboard](#dashboard)
|
||||||
* [Admin UI](#admin-ui)
|
* [Admin UI](#admin-ui)
|
||||||
* [Monitor](#monitor)
|
* [Monitor](#monitor)
|
||||||
@@ -46,6 +63,7 @@ frp also has a P2P connect mode.
|
|||||||
* [For Each Proxy](#for-each-proxy)
|
* [For Each Proxy](#for-each-proxy)
|
||||||
* [TCP Stream Multiplexing](#tcp-stream-multiplexing)
|
* [TCP Stream Multiplexing](#tcp-stream-multiplexing)
|
||||||
* [Support KCP Protocol](#support-kcp-protocol)
|
* [Support KCP Protocol](#support-kcp-protocol)
|
||||||
|
* [Support QUIC Protocol](#support-quic-protocol)
|
||||||
* [Connection Pooling](#connection-pooling)
|
* [Connection Pooling](#connection-pooling)
|
||||||
* [Load balancing](#load-balancing)
|
* [Load balancing](#load-balancing)
|
||||||
* [Service Health Check](#service-health-check)
|
* [Service Health Check](#service-health-check)
|
||||||
@@ -65,9 +83,8 @@ frp also has a P2P connect mode.
|
|||||||
* [Development Plan](#development-plan)
|
* [Development Plan](#development-plan)
|
||||||
* [Contributing](#contributing)
|
* [Contributing](#contributing)
|
||||||
* [Donation](#donation)
|
* [Donation](#donation)
|
||||||
* [AliPay](#alipay)
|
* [GitHub Sponsors](#github-sponsors)
|
||||||
* [Wechat Pay](#wechat-pay)
|
* [PayPal](#paypal)
|
||||||
* [Paypal](#paypal)
|
|
||||||
|
|
||||||
<!-- vim-markdown-toc -->
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
@@ -75,7 +92,9 @@ frp also has a P2P connect mode.
|
|||||||
|
|
||||||
frp is under development. Try the latest release version in the `master` branch, or use the `dev` branch for the version in development.
|
frp is under development. Try the latest release version in the `master` branch, or use the `dev` branch for the version in development.
|
||||||
|
|
||||||
**The protocol might change at a release and we don't promise backwards compatibility. Please check the release log when upgrading the client and the server.**
|
We are working on v2 version and trying to do some code refactor and improvements. It won't be compatible with v1.
|
||||||
|
|
||||||
|
We will switch v0 to v1 at the right time and only accept bug fixes and improvements instead of big feature requirements.
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
@@ -257,7 +276,9 @@ Configure `frps` same as above.
|
|||||||
|
|
||||||
2. Visit `http://x.x.x.x:6000/static/` from your browser and specify correct user and password to view files in `/tmp/files` on the `frpc` machine.
|
2. Visit `http://x.x.x.x:6000/static/` from your browser and specify correct user and password to view files in `/tmp/files` on the `frpc` machine.
|
||||||
|
|
||||||
### Enable HTTPS for local HTTP service
|
### Enable HTTPS for local HTTP(S) service
|
||||||
|
|
||||||
|
You may substitute `https2https` for the plugin, and point the `plugin_local_addr` to a HTTPS endpoint.
|
||||||
|
|
||||||
1. Start `frpc` with configuration:
|
1. Start `frpc` with configuration:
|
||||||
|
|
||||||
@@ -409,6 +430,27 @@ export FRP_SSH_REMOTE_PORT="6000"
|
|||||||
|
|
||||||
`frpc` will render configuration file template using OS environment variables. Remember to prefix your reference with `.Envs`.
|
`frpc` will render configuration file template using OS environment variables. Remember to prefix your reference with `.Envs`.
|
||||||
|
|
||||||
|
### Split Configures Into Different Files
|
||||||
|
|
||||||
|
You can split multiple proxy configs into different files and include them in the main file.
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# frpc.ini
|
||||||
|
[common]
|
||||||
|
server_addr = x.x.x.x
|
||||||
|
server_port = 7000
|
||||||
|
includes=./confd/*.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# ./confd/test.ini
|
||||||
|
[ssh]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 22
|
||||||
|
remote_port = 6000
|
||||||
|
```
|
||||||
|
|
||||||
### Dashboard
|
### Dashboard
|
||||||
|
|
||||||
Check frp's status and proxies' statistics information by Dashboard.
|
Check frp's status and proxies' statistics information by Dashboard.
|
||||||
@@ -418,12 +460,27 @@ Configure a port for dashboard to enable this feature:
|
|||||||
```ini
|
```ini
|
||||||
[common]
|
[common]
|
||||||
dashboard_port = 7500
|
dashboard_port = 7500
|
||||||
# dashboard's username and password are both optional,if not set, default is admin.
|
# dashboard's username and password are both optional
|
||||||
dashboard_user = admin
|
dashboard_user = admin
|
||||||
dashboard_pwd = admin
|
dashboard_pwd = admin
|
||||||
```
|
```
|
||||||
|
|
||||||
Then visit `http://[server_addr]:7500` to see the dashboard, with username and password both being `admin` by default.
|
Then visit `http://[server_addr]:7500` to see the dashboard, with username and password both being `admin`.
|
||||||
|
|
||||||
|
Additionally, you can use HTTPS port by using your domains wildcard or normal SSL certificate:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[common]
|
||||||
|
dashboard_port = 7500
|
||||||
|
# dashboard's username and password are both optional
|
||||||
|
dashboard_user = admin
|
||||||
|
dashboard_pwd = admin
|
||||||
|
dashboard_tls_mode = true
|
||||||
|
dashboard_tls_cert_file = server.crt
|
||||||
|
dashboard_tls_key_file = server.key
|
||||||
|
```
|
||||||
|
|
||||||
|
Then visit `https://[server_addr]:7500` to see the dashboard in secure HTTPS connection, with username and password both being `admin`.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -441,7 +498,7 @@ admin_user = admin
|
|||||||
admin_pwd = admin
|
admin_pwd = admin
|
||||||
```
|
```
|
||||||
|
|
||||||
Then visit `http://127.0.0.1:7400` to see admin UI, with username and password both being `admin` by default.
|
Then visit `http://127.0.0.1:7400` to see admin UI, with username and password both being `admin`.
|
||||||
|
|
||||||
### Monitor
|
### Monitor
|
||||||
|
|
||||||
@@ -515,11 +572,100 @@ use_compression = true
|
|||||||
|
|
||||||
frp supports the TLS protocol between `frpc` and `frps` since v0.25.0.
|
frp supports the TLS protocol between `frpc` and `frps` since v0.25.0.
|
||||||
|
|
||||||
Config `tls_enable = true` in the `[common]` section to `frpc.ini` to enable this feature.
|
|
||||||
|
|
||||||
For port multiplexing, frp sends a first byte `0x17` to dial a TLS connection.
|
For port multiplexing, frp sends a first byte `0x17` to dial a TLS connection.
|
||||||
|
|
||||||
To enforce `frps` to only accept TLS connections - configure `tls_only = true` in the `[common]` section in `frps.ini`.
|
Configure `tls_enable = true` in the `[common]` section to `frpc.ini` to enable this feature.
|
||||||
|
|
||||||
|
To **enforce** `frps` to only accept TLS connections - configure `tls_only = true` in the `[common]` section in `frps.ini`. **This is optional.**
|
||||||
|
|
||||||
|
**`frpc` TLS settings (under the `[common]` section):**
|
||||||
|
```ini
|
||||||
|
tls_enable = true
|
||||||
|
tls_cert_file = certificate.crt
|
||||||
|
tls_key_file = certificate.key
|
||||||
|
tls_trusted_ca_file = ca.crt
|
||||||
|
```
|
||||||
|
|
||||||
|
**`frps` TLS settings (under the `[common]` section):**
|
||||||
|
```ini
|
||||||
|
tls_only = true
|
||||||
|
tls_enable = true
|
||||||
|
tls_cert_file = certificate.crt
|
||||||
|
tls_key_file = certificate.key
|
||||||
|
tls_trusted_ca_file = ca.crt
|
||||||
|
```
|
||||||
|
|
||||||
|
You will need **a root CA cert** and **at least one SSL/TLS certificate**. It **can** be self-signed or regular (such as Let's Encrypt or another SSL/TLS certificate provider).
|
||||||
|
|
||||||
|
If you using `frp` via IP address and not hostname, make sure to set the appropriate IP address in the Subject Alternative Name (SAN) area when generating SSL/TLS Certificates.
|
||||||
|
|
||||||
|
Given an example:
|
||||||
|
|
||||||
|
* Prepare openssl config file. It exists at `/etc/pki/tls/openssl.cnf` in Linux System and `/System/Library/OpenSSL/openssl.cnf` in MacOS, and you can copy it to current path, like `cp /etc/pki/tls/openssl.cnf ./my-openssl.cnf`. If not, you can build it by yourself, like:
|
||||||
|
```
|
||||||
|
cat > my-openssl.cnf << EOF
|
||||||
|
[ ca ]
|
||||||
|
default_ca = CA_default
|
||||||
|
[ CA_default ]
|
||||||
|
x509_extensions = usr_cert
|
||||||
|
[ req ]
|
||||||
|
default_bits = 2048
|
||||||
|
default_md = sha256
|
||||||
|
default_keyfile = privkey.pem
|
||||||
|
distinguished_name = req_distinguished_name
|
||||||
|
attributes = req_attributes
|
||||||
|
x509_extensions = v3_ca
|
||||||
|
string_mask = utf8only
|
||||||
|
[ req_distinguished_name ]
|
||||||
|
[ req_attributes ]
|
||||||
|
[ usr_cert ]
|
||||||
|
basicConstraints = CA:FALSE
|
||||||
|
nsComment = "OpenSSL Generated Certificate"
|
||||||
|
subjectKeyIdentifier = hash
|
||||||
|
authorityKeyIdentifier = keyid,issuer
|
||||||
|
[ v3_ca ]
|
||||||
|
subjectKeyIdentifier = hash
|
||||||
|
authorityKeyIdentifier = keyid:always,issuer
|
||||||
|
basicConstraints = CA:true
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
* build ca certificates:
|
||||||
|
```
|
||||||
|
openssl genrsa -out ca.key 2048
|
||||||
|
openssl req -x509 -new -nodes -key ca.key -subj "/CN=example.ca.com" -days 5000 -out ca.crt
|
||||||
|
```
|
||||||
|
|
||||||
|
* build frps certificates:
|
||||||
|
```
|
||||||
|
openssl genrsa -out server.key 2048
|
||||||
|
|
||||||
|
openssl req -new -sha256 -key server.key \
|
||||||
|
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=server.com" \
|
||||||
|
-reqexts SAN \
|
||||||
|
-config <(cat my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com")) \
|
||||||
|
-out server.csr
|
||||||
|
|
||||||
|
openssl x509 -req -days 365 -sha256 \
|
||||||
|
-in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
|
||||||
|
-extfile <(printf "subjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com") \
|
||||||
|
-out server.crt
|
||||||
|
```
|
||||||
|
|
||||||
|
* build frpc certificates:
|
||||||
|
```
|
||||||
|
openssl genrsa -out client.key 2048
|
||||||
|
openssl req -new -sha256 -key client.key \
|
||||||
|
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=client.com" \
|
||||||
|
-reqexts SAN \
|
||||||
|
-config <(cat my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:client.com,DNS:example.client.com")) \
|
||||||
|
-out client.csr
|
||||||
|
|
||||||
|
openssl x509 -req -days 365 -sha256 \
|
||||||
|
-in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
|
||||||
|
-extfile <(printf "subjectAltName=DNS:client.com,DNS:example.client.com") \
|
||||||
|
-out client.crt
|
||||||
|
```
|
||||||
|
|
||||||
### Hot-Reloading frpc configuration
|
### Hot-Reloading frpc configuration
|
||||||
|
|
||||||
@@ -532,10 +678,12 @@ admin_addr = 127.0.0.1
|
|||||||
admin_port = 7400
|
admin_port = 7400
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run command `frpc reload -c ./frpc.ini` and wait for about 10 seconds to let `frpc` create or update or delete proxies.
|
Then run command `frpc reload -c ./frpc.ini` and wait for about 10 seconds to let `frpc` create or update or remove proxies.
|
||||||
|
|
||||||
**Note that parameters in [common] section won't be modified except 'start'.**
|
**Note that parameters in [common] section won't be modified except 'start'.**
|
||||||
|
|
||||||
|
You can run command `frpc verify -c ./frpc.ini` before reloading to check if there are config errors.
|
||||||
|
|
||||||
### Get proxy status from client
|
### Get proxy status from client
|
||||||
|
|
||||||
Use `frpc status -c ./frpc.ini` to get status of all proxies. The `admin_addr` and `admin_port` fields are required for enabling HTTP API.
|
Use `frpc status -c ./frpc.ini` to get status of all proxies. The `admin_addr` and `admin_port` fields are required for enabling HTTP API.
|
||||||
@@ -614,6 +762,35 @@ KCP mode uses UDP as the underlying transport. Using KCP in frp:
|
|||||||
protocol = kcp
|
protocol = kcp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Support QUIC Protocol
|
||||||
|
|
||||||
|
QUIC is a new multiplexed transport built on top of UDP.
|
||||||
|
|
||||||
|
Using QUIC in frp:
|
||||||
|
|
||||||
|
1. Enable QUIC in frps:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# frps.ini
|
||||||
|
[common]
|
||||||
|
bind_port = 7000
|
||||||
|
# Specify a UDP port for QUIC.
|
||||||
|
quic_bind_port = 7000
|
||||||
|
```
|
||||||
|
|
||||||
|
The `quic_bind_port` number can be the same number as `bind_port`, since `bind_port` field specifies a TCP port.
|
||||||
|
|
||||||
|
2. Configure `frpc.ini` to use QUIC to connect to frps:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# frpc.ini
|
||||||
|
[common]
|
||||||
|
server_addr = x.x.x.x
|
||||||
|
# Same as the 'quic_bind_port' in frps.ini
|
||||||
|
server_port = 7000
|
||||||
|
protocol = quic
|
||||||
|
```
|
||||||
|
|
||||||
### Connection Pooling
|
### Connection Pooling
|
||||||
|
|
||||||
By default, frps creates a new frpc connection to the backend service upon a user request. With connection pooling, frps keeps a certain number of pre-established connections, reducing the time needed to establish a connection.
|
By default, frps creates a new frpc connection to the backend service upon a user request. With connection pooling, frps keeps a certain number of pre-established connections, reducing the time needed to establish a connection.
|
||||||
@@ -640,7 +817,7 @@ This feature is suitable for a large number of short connections.
|
|||||||
|
|
||||||
Load balancing is supported by `group`.
|
Load balancing is supported by `group`.
|
||||||
|
|
||||||
This feature is only available for types `tcp` and `http` now.
|
This feature is only available for types `tcp`, `http`, `tcpmux` now.
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
# frpc.ini
|
# frpc.ini
|
||||||
@@ -725,7 +902,7 @@ custom_domains = test.example.com
|
|||||||
host_header_rewrite = dev.example.com
|
host_header_rewrite = dev.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
The HTTP request will have the the `Host` header rewritten to `Host: dev.example.com` when it reaches the actual web server, although the request from the browser probably has `Host: test.example.com`.
|
The HTTP request will have the `Host` header rewritten to `Host: dev.example.com` when it reaches the actual web server, although the request from the browser probably has `Host: test.example.com`.
|
||||||
|
|
||||||
### Setting other HTTP Headers
|
### Setting other HTTP Headers
|
||||||
|
|
||||||
@@ -751,7 +928,7 @@ In this example, it will set header `X-From-Where: frp` in the HTTP request.
|
|||||||
|
|
||||||
This feature is for http proxy only.
|
This feature is for http proxy only.
|
||||||
|
|
||||||
You can get user's real IP from HTTP request headers `X-Forwarded-For` and `X-Real-IP`.
|
You can get user's real IP from HTTP request headers `X-Forwarded-For`.
|
||||||
|
|
||||||
#### Proxy Protocol
|
#### Proxy Protocol
|
||||||
|
|
||||||
@@ -867,11 +1044,13 @@ server_port = 7000
|
|||||||
type = tcpmux
|
type = tcpmux
|
||||||
multiplexer = httpconnect
|
multiplexer = httpconnect
|
||||||
custom_domains = test1
|
custom_domains = test1
|
||||||
|
local_port = 80
|
||||||
|
|
||||||
[proxy2]
|
[proxy2]
|
||||||
type = tcpmux
|
type = tcpmux
|
||||||
multiplexer = httpconnect
|
multiplexer = httpconnect
|
||||||
custom_domains = test2
|
custom_domains = test2
|
||||||
|
local_port = 8080
|
||||||
```
|
```
|
||||||
|
|
||||||
In the above configuration - frps can be contacted on port 1337 with a HTTP CONNECT header such as:
|
In the above configuration - frps can be contacted on port 1337 with a HTTP CONNECT header such as:
|
||||||
@@ -914,7 +1093,7 @@ frpc will generate 8 proxies like `test_tcp_0`, `test_tcp_1`, ..., `test_tcp_7`.
|
|||||||
|
|
||||||
frpc only forwards requests to local TCP or UDP ports by default.
|
frpc only forwards requests to local TCP or UDP ports by default.
|
||||||
|
|
||||||
Plugins are used for providing rich features. There are built-in plugins such as `unix_domain_socket`, `http_proxy`, `socks5`, `static_file` and you can see [example usage](#example-usage).
|
Plugins are used for providing rich features. There are built-in plugins such as `unix_domain_socket`, `http_proxy`, `socks5`, `static_file`, `http2https`, `https2http`, `https2https` and you can see [example usage](#example-usage).
|
||||||
|
|
||||||
Specify which plugin to use with the `plugin` parameter. Configuration parameters of plugin should be started with `plugin_`. `local_ip` and `local_port` are not used for plugin.
|
Specify which plugin to use with the `plugin` parameter. Configuration parameters of plugin should be started with `plugin_`. `local_ip` and `local_port` are not used for plugin.
|
||||||
|
|
||||||
@@ -957,16 +1136,12 @@ Interested in getting involved? We would like to help you!
|
|||||||
|
|
||||||
If frp helps you a lot, you can support us by:
|
If frp helps you a lot, you can support us by:
|
||||||
|
|
||||||
frp QQ group: 606194980
|
### GitHub Sponsors
|
||||||
|
|
||||||
### AliPay
|
Support us by [Github Sponsors](https://github.com/sponsors/fatedier).
|
||||||
|
|
||||||

|
You can have your company's logo placed on README file of this project.
|
||||||
|
|
||||||
### Wechat Pay
|
### PayPal
|
||||||
|
|
||||||

|
Donate money by [PayPal](https://www.paypal.me/fatedier) to my account **fatedier@gmail.com**.
|
||||||
|
|
||||||
### Paypal
|
|
||||||
|
|
||||||
Donate money by [paypal](https://www.paypal.me/fatedier) to my account **fatedier@gmail.com**.
|
|
||||||
|
29
README_zh.md
29
README_zh.md
@@ -7,6 +7,21 @@
|
|||||||
|
|
||||||
frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。
|
frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。
|
||||||
|
|
||||||
|
<h3 align="center">Gold Sponsors</h3>
|
||||||
|
<!--gold sponsors start-->
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
|
||||||
|
<img width="300px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!--gold sponsors end-->
|
||||||
|
|
||||||
|
<h3 align="center">Silver Sponsors</h3>
|
||||||
|
|
||||||
|
* Sakura Frp - 欢迎点击 "加入我们"
|
||||||
|
|
||||||
## 为什么使用 frp ?
|
## 为什么使用 frp ?
|
||||||
|
|
||||||
通过在具有公网 IP 的节点上部署 frp 服务端,可以轻松地将内网服务穿透到公网,同时提供诸多专业的功能特性,这包括:
|
通过在具有公网 IP 的节点上部署 frp 服务端,可以轻松地将内网服务穿透到公网,同时提供诸多专业的功能特性,这包括:
|
||||||
@@ -25,6 +40,10 @@ frp 目前已被很多公司广泛用于测试、生产环境。
|
|||||||
|
|
||||||
master 分支用于发布稳定版本,dev 分支用于开发,您可以尝试下载最新的 release 版本进行测试。
|
master 分支用于发布稳定版本,dev 分支用于开发,您可以尝试下载最新的 release 版本进行测试。
|
||||||
|
|
||||||
|
我们正在进行 v2 大版本的开发,将会尝试在各个方面进行重构和升级,且不会与 v1 版本进行兼容,预计会持续一段时间。
|
||||||
|
|
||||||
|
现在的 v0 版本将会在合适的时间切换为 v1 版本并且保证兼容性,后续只做 bug 修复和优化,不再进行大的功能性更新。
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
完整文档已经迁移至 [https://gofrp.org](https://gofrp.org/docs)。
|
完整文档已经迁移至 [https://gofrp.org](https://gofrp.org/docs)。
|
||||||
@@ -46,6 +65,12 @@ frp 是一个免费且开源的项目,我们欢迎任何人为其开发和进
|
|||||||
|
|
||||||
如果您觉得 frp 对你有帮助,欢迎给予我们一定的捐助来维持项目的长期发展。
|
如果您觉得 frp 对你有帮助,欢迎给予我们一定的捐助来维持项目的长期发展。
|
||||||
|
|
||||||
|
### GitHub Sponsors
|
||||||
|
|
||||||
|
您可以通过 [GitHub Sponsors](https://github.com/sponsors/fatedier) 赞助我们。
|
||||||
|
|
||||||
|
企业赞助者可以将贵公司的 Logo 以及链接放置在项目 README 文件中。
|
||||||
|
|
||||||
### 知识星球
|
### 知识星球
|
||||||
|
|
||||||
如果您想学习 frp 相关的知识和技术,或者寻求任何帮助及咨询,都可以通过微信扫描下方的二维码付费加入知识星球的官方社群:
|
如果您想学习 frp 相关的知识和技术,或者寻求任何帮助及咨询,都可以通过微信扫描下方的二维码付费加入知识星球的官方社群:
|
||||||
@@ -59,7 +84,3 @@ frp 是一个免费且开源的项目,我们欢迎任何人为其开发和进
|
|||||||
### 微信支付捐赠
|
### 微信支付捐赠
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Paypal 捐赠
|
|
||||||
|
|
||||||
海外用户推荐通过 [Paypal](https://www.paypal.me/fatedier) 向我的账户 **fatedier@gmail.com** 进行捐赠。
|
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
### New
|
### New
|
||||||
|
|
||||||
* Command line parameters support `enable_prometheus`.
|
* Add `oidc_scope` parameter to frpc when `authentication_method = oidc`.
|
||||||
|
* Support quic protocol between frpc and frps.
|
||||||
|
|
||||||
|
|
||||||
|
### Improve
|
||||||
|
|
||||||
|
* Upgrade oidc and oauth2 package which is forward compatible.
|
||||||
|
@@ -14,22 +14,15 @@
|
|||||||
|
|
||||||
package assets
|
package assets
|
||||||
|
|
||||||
//go:generate statik -src=./frps/static -dest=./frps
|
|
||||||
//go:generate statik -src=./frpc/static -dest=./frpc
|
|
||||||
//go:generate go fmt ./frps/statik/statik.go
|
|
||||||
//go:generate go fmt ./frpc/statik/statik.go
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"github.com/rakyll/statik/fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// store static files in memory by statik
|
// read-only filesystem created by "embed" for embedded files
|
||||||
|
content fs.FS
|
||||||
|
|
||||||
FileSystem http.FileSystem
|
FileSystem http.FileSystem
|
||||||
|
|
||||||
// if prefix is not empty, we get file content from disk
|
// if prefix is not empty, we get file content from disk
|
||||||
@@ -38,40 +31,18 @@ var (
|
|||||||
|
|
||||||
// if path is empty, load assets in memory
|
// if path is empty, load assets in memory
|
||||||
// or set FileSystem using disk files
|
// or set FileSystem using disk files
|
||||||
func Load(path string) (err error) {
|
func Load(path string) {
|
||||||
prefixPath = path
|
prefixPath = path
|
||||||
if prefixPath != "" {
|
if prefixPath != "" {
|
||||||
FileSystem = http.Dir(prefixPath)
|
FileSystem = http.Dir(prefixPath)
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
FileSystem, err = fs.New()
|
FileSystem = http.FS(content)
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadFile(file string) (content string, err error) {
|
func Register(fileSystem fs.FS) {
|
||||||
if prefixPath == "" {
|
subFs, err := fs.Sub(fileSystem, "static")
|
||||||
file, err := FileSystem.Open(path.Join("/", file))
|
if err == nil {
|
||||||
if err != nil {
|
content = subFs
|
||||||
return content, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
buf, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
return content, err
|
|
||||||
}
|
|
||||||
content = string(buf)
|
|
||||||
} else {
|
|
||||||
file, err := os.Open(path.Join(prefixPath, file))
|
|
||||||
if err != nil {
|
|
||||||
return content, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
buf, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
return content, err
|
|
||||||
}
|
|
||||||
content = string(buf)
|
|
||||||
}
|
}
|
||||||
return content, err
|
|
||||||
}
|
}
|
||||||
|
14
assets/frpc/embed.go
Normal file
14
assets/frpc/embed.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package frpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/assets"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed static/*
|
||||||
|
var content embed.FS
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
assets.Register(content)
|
||||||
|
}
|
BIN
assets/frpc/static/535877f50039c0cb49a6196a5b7517cd.woff
Normal file
BIN
assets/frpc/static/535877f50039c0cb49a6196a5b7517cd.woff
Normal file
Binary file not shown.
Binary file not shown.
BIN
assets/frpc/static/732389ded34cb9c52dd88271f1345af9.ttf
Normal file
BIN
assets/frpc/static/732389ded34cb9c52dd88271f1345af9.ttf
Normal file
Binary file not shown.
@@ -1 +1 @@
|
|||||||
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frp client admin UI</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?d2cd6337d30c7b22e836"></script><script type="text/javascript" src="vendor.js?edb271e1d9c81f857840"></script></body> </html>
|
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frp client admin UI</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?5d5774096cf5c1b4d5af"></script><script type="text/javascript" src="vendor.js?dc42700731a508d39009"></script></body> </html>
|
@@ -1 +1 @@
|
|||||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"edb271e1d9c81f857840"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"dc42700731a508d39009"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14
assets/frps/embed.go
Normal file
14
assets/frps/embed.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package frpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/assets"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed static/*
|
||||||
|
var content embed.FS
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
assets.Register(content)
|
||||||
|
}
|
BIN
assets/frps/static/535877f50039c0cb49a6196a5b7517cd.woff
Normal file
BIN
assets/frps/static/535877f50039c0cb49a6196a5b7517cd.woff
Normal file
Binary file not shown.
Binary file not shown.
BIN
assets/frps/static/732389ded34cb9c52dd88271f1345af9.ttf
Normal file
BIN
assets/frps/static/732389ded34cb9c52dd88271f1345af9.ttf
Normal file
Binary file not shown.
@@ -1 +1 @@
|
|||||||
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?14bea8276eef86cc7c61"></script><script type="text/javascript" src="vendor.js?51925ec1a77936b64d61"></script></body> </html>
|
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?5d154ba4c6b342d8c0c3"></script><script type="text/javascript" src="vendor.js?ddbd1f69fb6e67be4b78"></script></body> </html>
|
@@ -1 +1 @@
|
|||||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"51925ec1a77936b64d61"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,u,c){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in u)Object.prototype.hasOwnProperty.call(u,i)&&(e[i]=u[i]);for(r&&r(t,u,c);s.length;)s.shift()();if(c)for(l=0;l<c.length;l++)f=n(n.s=c[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var u=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=u;var c=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"ddbd1f69fb6e67be4b78"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,c.appendChild(i),u},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -15,43 +15,54 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/fatedier/frp/assets"
|
"github.com/fatedier/frp/assets"
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
frpNet "github.com/fatedier/frp/pkg/util/net"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
httpServerReadTimeout = 10 * time.Second
|
httpServerReadTimeout = 60 * time.Second
|
||||||
httpServerWriteTimeout = 10 * time.Second
|
httpServerWriteTimeout = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func (svr *Service) RunAdminServer(addr string, port int) (err error) {
|
func (svr *Service) RunAdminServer(address string) (err error) {
|
||||||
// url router
|
// url router
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
|
|
||||||
user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd
|
router.HandleFunc("/healthz", svr.healthz)
|
||||||
router.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)
|
|
||||||
|
|
||||||
// api, see dashboard_api.go
|
// debug
|
||||||
router.HandleFunc("/api/reload", svr.apiReload).Methods("GET")
|
if svr.cfg.PprofEnable {
|
||||||
router.HandleFunc("/api/status", svr.apiStatus).Methods("GET")
|
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||||
router.HandleFunc("/api/config", svr.apiGetConfig).Methods("GET")
|
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||||
router.HandleFunc("/api/config", svr.apiPutConfig).Methods("PUT")
|
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||||
|
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||||
|
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
|
||||||
|
}
|
||||||
|
|
||||||
|
subRouter := router.NewRoute().Subrouter()
|
||||||
|
user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd
|
||||||
|
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)
|
||||||
|
|
||||||
|
// api, see admin_api.go
|
||||||
|
subRouter.HandleFunc("/api/reload", svr.apiReload).Methods("GET")
|
||||||
|
subRouter.HandleFunc("/api/status", svr.apiStatus).Methods("GET")
|
||||||
|
subRouter.HandleFunc("/api/config", svr.apiGetConfig).Methods("GET")
|
||||||
|
subRouter.HandleFunc("/api/config", svr.apiPutConfig).Methods("PUT")
|
||||||
|
|
||||||
// view
|
// view
|
||||||
router.Handle("/favicon.ico", http.FileServer(assets.FileSystem)).Methods("GET")
|
subRouter.Handle("/favicon.ico", http.FileServer(assets.FileSystem)).Methods("GET")
|
||||||
router.PathPrefix("/static/").Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET")
|
subRouter.PathPrefix("/static/").Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET")
|
||||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
subRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/static/", http.StatusMovedPermanently)
|
http.Redirect(w, r, "/static/", http.StatusMovedPermanently)
|
||||||
})
|
})
|
||||||
|
|
||||||
address := fmt.Sprintf("%s:%d", addr, port)
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: address,
|
Addr: address,
|
||||||
Handler: router,
|
Handler: router,
|
||||||
@@ -66,6 +77,8 @@ func (svr *Service) RunAdminServer(addr string, port int) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
go server.Serve(ln)
|
go func() {
|
||||||
|
_ = server.Serve(ln)
|
||||||
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,12 @@ package client
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client/proxy"
|
"github.com/fatedier/frp/client/proxy"
|
||||||
@@ -32,37 +35,25 @@ type GeneralResponse struct {
|
|||||||
Msg string
|
Msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/reload
|
// /healthz
|
||||||
|
func (svr *Service) healthz(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(200)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/reload
|
||||||
func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
|
func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
|
||||||
res := GeneralResponse{Code: 200}
|
res := GeneralResponse{Code: 200}
|
||||||
|
|
||||||
log.Info("Http request [/api/reload]")
|
log.Info("api request [/api/reload]")
|
||||||
defer func() {
|
defer func() {
|
||||||
log.Info("Http response [/api/reload], code [%d]", res.Code)
|
log.Info("api response [/api/reload], code [%d]", res.Code)
|
||||||
w.WriteHeader(res.Code)
|
w.WriteHeader(res.Code)
|
||||||
if len(res.Msg) > 0 {
|
if len(res.Msg) > 0 {
|
||||||
w.Write([]byte(res.Msg))
|
_, _ = w.Write([]byte(res.Msg))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
content, err := config.GetRenderedConfFromFile(svr.cfgFile)
|
_, pxyCfgs, visitorCfgs, err := config.ParseClientConfig(svr.cfgFile)
|
||||||
if err != nil {
|
|
||||||
res.Code = 400
|
|
||||||
res.Msg = err.Error()
|
|
||||||
log.Warn("reload frpc config file error: %s", res.Msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
newCommonCfg, err := config.UnmarshalClientConfFromIni(content)
|
|
||||||
if err != nil {
|
|
||||||
res.Code = 400
|
|
||||||
res.Msg = err.Error()
|
|
||||||
log.Warn("reload frpc common section error: %s", res.Msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pxyCfgs, visitorCfgs, err := config.LoadAllConfFromIni(svr.cfg.User, content, newCommonCfg.Start)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = 400
|
res.Code = 400
|
||||||
res.Msg = err.Error()
|
res.Msg = err.Error()
|
||||||
@@ -70,15 +61,13 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = svr.ReloadConf(pxyCfgs, visitorCfgs)
|
if err = svr.ReloadConf(pxyCfgs, visitorCfgs); err != nil {
|
||||||
if err != nil {
|
|
||||||
res.Code = 500
|
res.Code = 500
|
||||||
res.Msg = err.Error()
|
res.Msg = err.Error()
|
||||||
log.Warn("reload frpc proxy config error: %s", res.Msg)
|
log.Warn("reload frpc proxy config error: %s", res.Msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("success reload conf")
|
log.Info("success reload conf")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusResp struct {
|
type StatusResp struct {
|
||||||
@@ -117,48 +106,48 @@ func NewProxyStatusResp(status *proxy.WorkingStatus, serverAddr string) ProxySta
|
|||||||
switch cfg := status.Cfg.(type) {
|
switch cfg := status.Cfg.(type) {
|
||||||
case *config.TCPProxyConf:
|
case *config.TCPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
if status.Err != "" {
|
if status.Err != "" {
|
||||||
psr.RemoteAddr = fmt.Sprintf("%s:%d", serverAddr, cfg.RemotePort)
|
psr.RemoteAddr = net.JoinHostPort(serverAddr, strconv.Itoa(cfg.RemotePort))
|
||||||
} else {
|
} else {
|
||||||
psr.RemoteAddr = serverAddr + status.RemoteAddr
|
psr.RemoteAddr = serverAddr + status.RemoteAddr
|
||||||
}
|
}
|
||||||
case *config.UDPProxyConf:
|
case *config.UDPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
if status.Err != "" {
|
if status.Err != "" {
|
||||||
psr.RemoteAddr = fmt.Sprintf("%s:%d", serverAddr, cfg.RemotePort)
|
psr.RemoteAddr = net.JoinHostPort(serverAddr, strconv.Itoa(cfg.RemotePort))
|
||||||
} else {
|
} else {
|
||||||
psr.RemoteAddr = serverAddr + status.RemoteAddr
|
psr.RemoteAddr = serverAddr + status.RemoteAddr
|
||||||
}
|
}
|
||||||
case *config.HTTPProxyConf:
|
case *config.HTTPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
psr.RemoteAddr = status.RemoteAddr
|
psr.RemoteAddr = status.RemoteAddr
|
||||||
case *config.HTTPSProxyConf:
|
case *config.HTTPSProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
psr.RemoteAddr = status.RemoteAddr
|
psr.RemoteAddr = status.RemoteAddr
|
||||||
case *config.STCPProxyConf:
|
case *config.STCPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
case *config.XTCPProxyConf:
|
case *config.XTCPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
case *config.SUDPProxyConf:
|
case *config.SUDPProxyConf:
|
||||||
if cfg.LocalPort != 0 {
|
if cfg.LocalPort != 0 {
|
||||||
psr.LocalAddr = fmt.Sprintf("%s:%d", cfg.LocalIP, cfg.LocalPort)
|
psr.LocalAddr = net.JoinHostPort(cfg.LocalIP, strconv.Itoa(cfg.LocalPort))
|
||||||
}
|
}
|
||||||
psr.Plugin = cfg.Plugin
|
psr.Plugin = cfg.Plugin
|
||||||
}
|
}
|
||||||
@@ -183,7 +172,7 @@ func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
log.Info("Http response [/api/status]")
|
log.Info("Http response [/api/status]")
|
||||||
buf, _ = json.Marshal(&res)
|
buf, _ = json.Marshal(&res)
|
||||||
w.Write(buf)
|
_, _ = w.Write(buf)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ps := svr.ctl.pm.GetAllProxyStatus()
|
ps := svr.ctl.pm.GetAllProxyStatus()
|
||||||
@@ -212,7 +201,6 @@ func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request) {
|
|||||||
sort.Sort(ByProxyStatusResp(res.STCP))
|
sort.Sort(ByProxyStatusResp(res.STCP))
|
||||||
sort.Sort(ByProxyStatusResp(res.XTCP))
|
sort.Sort(ByProxyStatusResp(res.XTCP))
|
||||||
sort.Sort(ByProxyStatusResp(res.SUDP))
|
sort.Sort(ByProxyStatusResp(res.SUDP))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/config
|
// GET api/config
|
||||||
@@ -224,7 +212,7 @@ func (svr *Service) apiGetConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Info("Http get response [/api/config], code [%d]", res.Code)
|
log.Info("Http get response [/api/config], code [%d]", res.Code)
|
||||||
w.WriteHeader(res.Code)
|
w.WriteHeader(res.Code)
|
||||||
if len(res.Msg) > 0 {
|
if len(res.Msg) > 0 {
|
||||||
w.Write([]byte(res.Msg))
|
_, _ = w.Write([]byte(res.Msg))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -243,7 +231,7 @@ func (svr *Service) apiGetConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rows := strings.Split(content, "\n")
|
rows := strings.Split(string(content), "\n")
|
||||||
newRows := make([]string, 0, len(rows))
|
newRows := make([]string, 0, len(rows))
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
row = strings.TrimSpace(row)
|
row = strings.TrimSpace(row)
|
||||||
@@ -264,12 +252,12 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Info("Http put response [/api/config], code [%d]", res.Code)
|
log.Info("Http put response [/api/config], code [%d]", res.Code)
|
||||||
w.WriteHeader(res.Code)
|
w.WriteHeader(res.Code)
|
||||||
if len(res.Msg) > 0 {
|
if len(res.Msg) > 0 {
|
||||||
w.Write([]byte(res.Msg))
|
_, _ = w.Write([]byte(res.Msg))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// get new config content
|
// get new config content
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = 400
|
res.Code = 400
|
||||||
res.Msg = fmt.Sprintf("read request body error: %v", err)
|
res.Msg = fmt.Sprintf("read request body error: %v", err)
|
||||||
@@ -286,7 +274,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// get token from origin content
|
// get token from origin content
|
||||||
token := ""
|
token := ""
|
||||||
b, err := ioutil.ReadFile(svr.cfgFile)
|
b, err := os.ReadFile(svr.cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = 400
|
res.Code = 400
|
||||||
res.Msg = err.Error()
|
res.Msg = err.Error()
|
||||||
@@ -325,7 +313,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
content = strings.Join(newRows, "\n")
|
content = strings.Join(newRows, "\n")
|
||||||
|
|
||||||
err = ioutil.WriteFile(svr.cfgFile, []byte(content), 0644)
|
err = os.WriteFile(svr.cfgFile, []byte(content), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Code = 500
|
res.Code = 500
|
||||||
res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)
|
res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)
|
||||||
|
@@ -16,25 +16,19 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/control/shutdown"
|
||||||
|
"github.com/fatedier/golib/crypto"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client/proxy"
|
"github.com/fatedier/frp/client/proxy"
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/transport"
|
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
"github.com/fatedier/golib/control/shutdown"
|
|
||||||
"github.com/fatedier/golib/crypto"
|
|
||||||
fmux "github.com/hashicorp/yamux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Control struct {
|
type Control struct {
|
||||||
@@ -51,8 +45,7 @@ type Control struct {
|
|||||||
// control connection
|
// control connection
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
|
||||||
// tcp stream multiplexing, if enabled
|
cm *ConnectionManager
|
||||||
session *fmux.Session
|
|
||||||
|
|
||||||
// put a message in this channel to send it over control connection to server
|
// put a message in this channel to send it over control connection to server
|
||||||
sendCh chan (msg.Message)
|
sendCh chan (msg.Message)
|
||||||
@@ -78,8 +71,6 @@ type Control struct {
|
|||||||
// The UDP port that the server is listening on
|
// The UDP port that the server is listening on
|
||||||
serverUDPPort int
|
serverUDPPort int
|
||||||
|
|
||||||
mu sync.RWMutex
|
|
||||||
|
|
||||||
xl *xlog.Logger
|
xl *xlog.Logger
|
||||||
|
|
||||||
// service context
|
// service context
|
||||||
@@ -89,18 +80,19 @@ type Control struct {
|
|||||||
authSetter auth.Setter
|
authSetter auth.Setter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewControl(ctx context.Context, runID string, conn net.Conn, session *fmux.Session,
|
func NewControl(
|
||||||
|
ctx context.Context, runID string, conn net.Conn, cm *ConnectionManager,
|
||||||
clientCfg config.ClientCommonConf,
|
clientCfg config.ClientCommonConf,
|
||||||
pxyCfgs map[string]config.ProxyConf,
|
pxyCfgs map[string]config.ProxyConf,
|
||||||
visitorCfgs map[string]config.VisitorConf,
|
visitorCfgs map[string]config.VisitorConf,
|
||||||
serverUDPPort int,
|
serverUDPPort int,
|
||||||
authSetter auth.Setter) *Control {
|
authSetter auth.Setter,
|
||||||
|
) *Control {
|
||||||
// new xlog instance
|
// new xlog instance
|
||||||
ctl := &Control{
|
ctl := &Control{
|
||||||
runID: runID,
|
runID: runID,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
session: session,
|
cm: cm,
|
||||||
pxyCfgs: pxyCfgs,
|
pxyCfgs: pxyCfgs,
|
||||||
sendCh: make(chan msg.Message, 100),
|
sendCh: make(chan msg.Message, 100),
|
||||||
readCh: make(chan msg.Message, 100),
|
readCh: make(chan msg.Message, 100),
|
||||||
@@ -130,13 +122,13 @@ func (ctl *Control) Run() {
|
|||||||
|
|
||||||
// start all visitors
|
// start all visitors
|
||||||
go ctl.vm.Run()
|
go ctl.vm.Run()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
|
func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
|
||||||
xl := ctl.xl
|
xl := ctl.xl
|
||||||
workConn, err := ctl.connectServer()
|
workConn, err := ctl.connectServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
xl.Warn("start new connection to server error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +147,7 @@ func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
|
|||||||
|
|
||||||
var startMsg msg.StartWorkConn
|
var startMsg msg.StartWorkConn
|
||||||
if err = msg.ReadMsgInto(workConn, &startMsg); err != nil {
|
if err = msg.ReadMsgInto(workConn, &startMsg); err != nil {
|
||||||
xl.Error("work connection closed before response StartWorkConn message: %v", err)
|
xl.Trace("work connection closed before response StartWorkConn message: %v", err)
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -182,12 +174,17 @@ func (ctl *Control) HandleNewProxyResp(inMsg *msg.NewProxyResp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ctl *Control) Close() error {
|
func (ctl *Control) Close() error {
|
||||||
|
return ctl.GracefulClose(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctl *Control) GracefulClose(d time.Duration) error {
|
||||||
ctl.pm.Close()
|
ctl.pm.Close()
|
||||||
ctl.conn.Close()
|
|
||||||
ctl.vm.Close()
|
ctl.vm.Close()
|
||||||
if ctl.session != nil {
|
|
||||||
ctl.session.Close()
|
time.Sleep(d)
|
||||||
}
|
|
||||||
|
ctl.conn.Close()
|
||||||
|
ctl.cm.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,38 +195,7 @@ func (ctl *Control) ClosedDoneCh() <-chan struct{} {
|
|||||||
|
|
||||||
// connectServer return a new connection to frps
|
// connectServer return a new connection to frps
|
||||||
func (ctl *Control) connectServer() (conn net.Conn, err error) {
|
func (ctl *Control) connectServer() (conn net.Conn, err error) {
|
||||||
xl := ctl.xl
|
return ctl.cm.Connect()
|
||||||
if ctl.clientCfg.TCPMux {
|
|
||||||
stream, errRet := ctl.session.OpenStream()
|
|
||||||
if errRet != nil {
|
|
||||||
err = errRet
|
|
||||||
xl.Warn("start new connection to server error: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
conn = stream
|
|
||||||
} else {
|
|
||||||
var tlsConfig *tls.Config
|
|
||||||
|
|
||||||
if ctl.clientCfg.TLSEnable {
|
|
||||||
tlsConfig, err = transport.NewClientTLSConfig(
|
|
||||||
ctl.clientCfg.TLSCertFile,
|
|
||||||
ctl.clientCfg.TLSKeyFile,
|
|
||||||
ctl.clientCfg.TLSTrustedCaFile,
|
|
||||||
ctl.clientCfg.ServerAddr)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
xl.Warn("fail to build tls configuration when connecting to server, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
conn, err = frpNet.ConnectServerByProxyWithTLS(ctl.clientCfg.HTTPProxy, ctl.clientCfg.Protocol,
|
|
||||||
fmt.Sprintf("%s:%d", ctl.clientCfg.ServerAddr, ctl.clientCfg.ServerPort), tlsConfig)
|
|
||||||
if err != nil {
|
|
||||||
xl.Warn("start new connection to server error: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reader read all messages from frps and send to readCh
|
// reader read all messages from frps and send to readCh
|
||||||
@@ -295,16 +261,27 @@ func (ctl *Control) msgHandler() {
|
|||||||
}()
|
}()
|
||||||
defer ctl.msgHandlerShutdown.Done()
|
defer ctl.msgHandlerShutdown.Done()
|
||||||
|
|
||||||
hbSend := time.NewTicker(time.Duration(ctl.clientCfg.HeartBeatInterval) * time.Second)
|
var hbSendCh <-chan time.Time
|
||||||
defer hbSend.Stop()
|
// TODO(fatedier): disable heartbeat if TCPMux is enabled.
|
||||||
hbCheck := time.NewTicker(time.Second)
|
// Just keep it here to keep compatible with old version frps.
|
||||||
defer hbCheck.Stop()
|
if ctl.clientCfg.HeartbeatInterval > 0 {
|
||||||
|
hbSend := time.NewTicker(time.Duration(ctl.clientCfg.HeartbeatInterval) * time.Second)
|
||||||
|
defer hbSend.Stop()
|
||||||
|
hbSendCh = hbSend.C
|
||||||
|
}
|
||||||
|
|
||||||
|
var hbCheckCh <-chan time.Time
|
||||||
|
// Check heartbeat timeout only if TCPMux is not enabled and users don't disable heartbeat feature.
|
||||||
|
if ctl.clientCfg.HeartbeatInterval > 0 && ctl.clientCfg.HeartbeatTimeout > 0 && !ctl.clientCfg.TCPMux {
|
||||||
|
hbCheck := time.NewTicker(time.Second)
|
||||||
|
defer hbCheck.Stop()
|
||||||
|
hbCheckCh = hbCheck.C
|
||||||
|
}
|
||||||
|
|
||||||
ctl.lastPong = time.Now()
|
ctl.lastPong = time.Now()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-hbSend.C:
|
case <-hbSendCh:
|
||||||
// send heartbeat to server
|
// send heartbeat to server
|
||||||
xl.Debug("send heartbeat to server")
|
xl.Debug("send heartbeat to server")
|
||||||
pingMsg := &msg.Ping{}
|
pingMsg := &msg.Ping{}
|
||||||
@@ -313,8 +290,8 @@ func (ctl *Control) msgHandler() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctl.sendCh <- pingMsg
|
ctl.sendCh <- pingMsg
|
||||||
case <-hbCheck.C:
|
case <-hbCheckCh:
|
||||||
if time.Since(ctl.lastPong) > time.Duration(ctl.clientCfg.HeartBeatTimeout)*time.Second {
|
if time.Since(ctl.lastPong) > time.Duration(ctl.clientCfg.HeartbeatTimeout)*time.Second {
|
||||||
xl.Warn("heartbeat timeout")
|
xl.Warn("heartbeat timeout")
|
||||||
// let reader() stop
|
// let reader() stop
|
||||||
ctl.conn.Close()
|
ctl.conn.Close()
|
||||||
@@ -349,25 +326,20 @@ func (ctl *Control) worker() {
|
|||||||
go ctl.reader()
|
go ctl.reader()
|
||||||
go ctl.writer()
|
go ctl.writer()
|
||||||
|
|
||||||
select {
|
<-ctl.closedCh
|
||||||
case <-ctl.closedCh:
|
// close related channels and wait until other goroutines done
|
||||||
// close related channels and wait until other goroutines done
|
close(ctl.readCh)
|
||||||
close(ctl.readCh)
|
ctl.readerShutdown.WaitDone()
|
||||||
ctl.readerShutdown.WaitDone()
|
ctl.msgHandlerShutdown.WaitDone()
|
||||||
ctl.msgHandlerShutdown.WaitDone()
|
|
||||||
|
|
||||||
close(ctl.sendCh)
|
close(ctl.sendCh)
|
||||||
ctl.writerShutdown.WaitDone()
|
ctl.writerShutdown.WaitDone()
|
||||||
|
|
||||||
ctl.pm.Close()
|
ctl.pm.Close()
|
||||||
ctl.vm.Close()
|
ctl.vm.Close()
|
||||||
|
|
||||||
close(ctl.closedDoneCh)
|
close(ctl.closedDoneCh)
|
||||||
if ctl.session != nil {
|
ctl.cm.Close()
|
||||||
ctl.session.Close()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctl *Control) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf) error {
|
func (ctl *Control) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf) error {
|
||||||
|
@@ -6,18 +6,9 @@ import (
|
|||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Type int
|
var ErrPayloadType = errors.New("error payload type")
|
||||||
|
|
||||||
const (
|
type Handler func(payload interface{}) error
|
||||||
EvStartProxy Type = iota
|
|
||||||
EvCloseProxy
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrPayloadType = errors.New("error payload type")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Handler func(evType Type, payload interface{}) error
|
|
||||||
|
|
||||||
type StartProxyPayload struct {
|
type StartProxyPayload struct {
|
||||||
NewProxyMsg *msg.NewProxy
|
NewProxyMsg *msg.NewProxy
|
||||||
|
@@ -19,7 +19,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -27,9 +26,7 @@ import (
|
|||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrHealthCheckType = errors.New("error health check type")
|
||||||
ErrHealthCheckType = errors.New("error health check type")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
checkType string
|
checkType string
|
||||||
@@ -55,8 +52,8 @@ type Monitor struct {
|
|||||||
func NewMonitor(ctx context.Context, checkType string,
|
func NewMonitor(ctx context.Context, checkType string,
|
||||||
intervalS int, timeoutS int, maxFailedTimes int,
|
intervalS int, timeoutS int, maxFailedTimes int,
|
||||||
addr string, url string,
|
addr string, url string,
|
||||||
statusNormalFn func(), statusFailedFn func()) *Monitor {
|
statusNormalFn func(), statusFailedFn func(),
|
||||||
|
) *Monitor {
|
||||||
if intervalS <= 0 {
|
if intervalS <= 0 {
|
||||||
intervalS = 10
|
intervalS = 10
|
||||||
}
|
}
|
||||||
@@ -153,7 +150,7 @@ func (monitor *Monitor) doTCPCheck(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
|
func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
|
||||||
req, err := http.NewRequest("GET", monitor.url, nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", monitor.url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -162,7 +159,7 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
io.Copy(ioutil.Discard, resp.Body)
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode/100 != 2 {
|
if resp.StatusCode/100 != 2 {
|
||||||
return fmt.Errorf("do http health check, StatusCode is [%d] not 2xx", resp.StatusCode)
|
return fmt.Errorf("do http health check, StatusCode is [%d] not 2xx", resp.StatusCode)
|
||||||
|
@@ -17,15 +17,21 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/errors"
|
||||||
|
frpIo "github.com/fatedier/golib/io"
|
||||||
|
libdial "github.com/fatedier/golib/net/dial"
|
||||||
|
"github.com/fatedier/golib/pool"
|
||||||
|
fmux "github.com/hashicorp/yamux"
|
||||||
|
pp "github.com/pires/go-proxyproto"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
plugin "github.com/fatedier/frp/pkg/plugin/client"
|
plugin "github.com/fatedier/frp/pkg/plugin/client"
|
||||||
@@ -33,13 +39,6 @@ import (
|
|||||||
"github.com/fatedier/frp/pkg/util/limit"
|
"github.com/fatedier/frp/pkg/util/limit"
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
frpNet "github.com/fatedier/frp/pkg/util/net"
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
|
||||||
frpIo "github.com/fatedier/golib/io"
|
|
||||||
"github.com/fatedier/golib/pool"
|
|
||||||
fmux "github.com/hashicorp/yamux"
|
|
||||||
pp "github.com/pires/go-proxyproto"
|
|
||||||
"golang.org/x/time/rate"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Proxy defines how to handle work connections for different proxy type.
|
// Proxy defines how to handle work connections for different proxy type.
|
||||||
@@ -148,7 +147,7 @@ func (pxy *TCPProxy) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
func (pxy *TCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
conn, []byte(pxy.clientCfg.Token), m)
|
conn, []byte(pxy.clientCfg.Token), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +176,7 @@ func (pxy *TCPMuxProxy) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TCPMuxProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
func (pxy *TCPMuxProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
conn, []byte(pxy.clientCfg.Token), m)
|
conn, []byte(pxy.clientCfg.Token), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +205,7 @@ func (pxy *HTTPProxy) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *HTTPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
func (pxy *HTTPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
conn, []byte(pxy.clientCfg.Token), m)
|
conn, []byte(pxy.clientCfg.Token), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +234,7 @@ func (pxy *HTTPSProxy) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *HTTPSProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
func (pxy *HTTPSProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
conn, []byte(pxy.clientCfg.Token), m)
|
conn, []byte(pxy.clientCfg.Token), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +263,7 @@ func (pxy *STCPProxy) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *STCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
func (pxy *STCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
conn, []byte(pxy.clientCfg.Token), m)
|
conn, []byte(pxy.clientCfg.Token), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,8 +306,12 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
Sid: natHoleSidMsg.Sid,
|
Sid: natHoleSidMsg.Sid,
|
||||||
}
|
}
|
||||||
raddr, _ := net.ResolveUDPAddr("udp",
|
raddr, _ := net.ResolveUDPAddr("udp",
|
||||||
fmt.Sprintf("%s:%d", pxy.clientCfg.ServerAddr, pxy.serverUDPPort))
|
net.JoinHostPort(pxy.clientCfg.ServerAddr, strconv.Itoa(pxy.serverUDPPort)))
|
||||||
clientConn, err := net.DialUDP("udp", nil, raddr)
|
clientConn, err := net.DialUDP("udp", nil, raddr)
|
||||||
|
if err != nil {
|
||||||
|
xl.Error("dial server udp addr error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
defer clientConn.Close()
|
defer clientConn.Close()
|
||||||
|
|
||||||
err = msg.WriteMsg(clientConn, natHoleClientMsg)
|
err = msg.WriteMsg(clientConn, natHoleClientMsg)
|
||||||
@@ -319,7 +322,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
|
|
||||||
// Wait for client address at most 5 seconds.
|
// Wait for client address at most 5 seconds.
|
||||||
var natHoleRespMsg msg.NatHoleResp
|
var natHoleRespMsg msg.NatHoleResp
|
||||||
clientConn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
_ = clientConn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||||
|
|
||||||
buf := pool.GetBuf(1024)
|
buf := pool.GetBuf(1024)
|
||||||
n, err := clientConn.Read(buf)
|
n, err := clientConn.Read(buf)
|
||||||
@@ -332,8 +335,8 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
xl.Error("get natHoleRespMsg error: %v", err)
|
xl.Error("get natHoleRespMsg error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clientConn.SetReadDeadline(time.Time{})
|
_ = clientConn.SetReadDeadline(time.Time{})
|
||||||
clientConn.Close()
|
_ = clientConn.Close()
|
||||||
|
|
||||||
if natHoleRespMsg.Error != "" {
|
if natHoleRespMsg.Error != "" {
|
||||||
xl.Error("natHoleRespMsg get error info: %s", natHoleRespMsg.Error)
|
xl.Error("natHoleRespMsg get error info: %s", natHoleRespMsg.Error)
|
||||||
@@ -343,35 +346,34 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
xl.Trace("get natHoleRespMsg, sid [%s], client address [%s] visitor address [%s]", natHoleRespMsg.Sid, natHoleRespMsg.ClientAddr, natHoleRespMsg.VisitorAddr)
|
xl.Trace("get natHoleRespMsg, sid [%s], client address [%s] visitor address [%s]", natHoleRespMsg.Sid, natHoleRespMsg.ClientAddr, natHoleRespMsg.VisitorAddr)
|
||||||
|
|
||||||
// Send detect message
|
// Send detect message
|
||||||
array := strings.Split(natHoleRespMsg.VisitorAddr, ":")
|
host, portStr, err := net.SplitHostPort(natHoleRespMsg.VisitorAddr)
|
||||||
if len(array) <= 1 {
|
if err != nil {
|
||||||
xl.Error("get NatHoleResp visitor address error: %v", natHoleRespMsg.VisitorAddr)
|
xl.Error("get NatHoleResp visitor address [%s] error: %v", natHoleRespMsg.VisitorAddr, err)
|
||||||
}
|
}
|
||||||
laddr, _ := net.ResolveUDPAddr("udp", clientConn.LocalAddr().String())
|
laddr, _ := net.ResolveUDPAddr("udp", clientConn.LocalAddr().String())
|
||||||
/*
|
|
||||||
for i := 1000; i < 65000; i++ {
|
port, err := strconv.ParseInt(portStr, 10, 64)
|
||||||
pxy.sendDetectMsg(array[0], int64(i), laddr, "a")
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
port, err := strconv.ParseInt(array[1], 10, 64)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Error("get natHoleResp visitor address error: %v", natHoleRespMsg.VisitorAddr)
|
xl.Error("get natHoleResp visitor address error: %v", natHoleRespMsg.VisitorAddr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pxy.sendDetectMsg(array[0], int(port), laddr, []byte(natHoleRespMsg.Sid))
|
_ = pxy.sendDetectMsg(host, int(port), laddr, []byte(natHoleRespMsg.Sid))
|
||||||
xl.Trace("send all detect msg done")
|
xl.Trace("send all detect msg done")
|
||||||
|
|
||||||
msg.WriteMsg(conn, &msg.NatHoleClientDetectOK{})
|
if err := msg.WriteMsg(conn, &msg.NatHoleClientDetectOK{}); err != nil {
|
||||||
|
xl.Error("write message error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for clientConn's address and wait for visitor connection
|
// Listen for clientConn's address and wait for visitor connection
|
||||||
lConn, err := net.ListenUDP("udp", laddr)
|
lConn, err := net.ListenUDP("udp", laddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Error("listen on visitorConn's local adress error: %v", err)
|
xl.Error("listen on visitorConn's local address error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer lConn.Close()
|
defer lConn.Close()
|
||||||
|
|
||||||
lConn.SetReadDeadline(time.Now().Add(8 * time.Second))
|
_ = lConn.SetReadDeadline(time.Now().Add(8 * time.Second))
|
||||||
sidBuf := pool.GetBuf(1024)
|
sidBuf := pool.GetBuf(1024)
|
||||||
var uAddr *net.UDPAddr
|
var uAddr *net.UDPAddr
|
||||||
n, uAddr, err = lConn.ReadFromUDP(sidBuf)
|
n, uAddr, err = lConn.ReadFromUDP(sidBuf)
|
||||||
@@ -379,7 +381,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
xl.Warn("get sid from visitor error: %v", err)
|
xl.Warn("get sid from visitor error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lConn.SetReadDeadline(time.Time{})
|
_ = lConn.SetReadDeadline(time.Time{})
|
||||||
if string(sidBuf[:n]) != natHoleRespMsg.Sid {
|
if string(sidBuf[:n]) != natHoleRespMsg.Sid {
|
||||||
xl.Warn("incorrect sid from visitor")
|
xl.Warn("incorrect sid from visitor")
|
||||||
return
|
return
|
||||||
@@ -387,7 +389,10 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
pool.PutBuf(sidBuf)
|
pool.PutBuf(sidBuf)
|
||||||
xl.Info("nat hole connection make success, sid [%s]", natHoleRespMsg.Sid)
|
xl.Info("nat hole connection make success, sid [%s]", natHoleRespMsg.Sid)
|
||||||
|
|
||||||
lConn.WriteToUDP(sidBuf[:n], uAddr)
|
if _, err := lConn.WriteToUDP(sidBuf[:n], uAddr); err != nil {
|
||||||
|
xl.Error("write uaddr error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
kcpConn, err := frpNet.NewKCPConnFromUDP(lConn, false, uAddr.String())
|
kcpConn, err := frpNet.NewKCPConnFromUDP(lConn, false, uAddr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -397,7 +402,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
|
|
||||||
fmuxCfg := fmux.DefaultConfig()
|
fmuxCfg := fmux.DefaultConfig()
|
||||||
fmuxCfg.KeepAliveInterval = 5 * time.Second
|
fmuxCfg.KeepAliveInterval = 5 * time.Second
|
||||||
fmuxCfg.LogOutput = ioutil.Discard
|
fmuxCfg.LogOutput = io.Discard
|
||||||
sess, err := fmux.Server(kcpConn, fmuxCfg)
|
sess, err := fmux.Server(kcpConn, fmuxCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Error("create yamux server from kcp connection error: %v", err)
|
xl.Error("create yamux server from kcp connection error: %v", err)
|
||||||
@@ -410,12 +415,12 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, &pxy.cfg.BaseProxyConf, pxy.limiter,
|
HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter,
|
||||||
muxConn, []byte(pxy.cfg.Sk), m)
|
muxConn, []byte(pxy.cfg.Sk), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *XTCPProxy) sendDetectMsg(addr string, port int, laddr *net.UDPAddr, content []byte) (err error) {
|
func (pxy *XTCPProxy) sendDetectMsg(addr string, port int, laddr *net.UDPAddr, content []byte) (err error) {
|
||||||
daddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", addr, port))
|
daddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(addr, strconv.Itoa(port)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -425,12 +430,13 @@ func (pxy *XTCPProxy) sendDetectMsg(addr string, port int, laddr *net.UDPAddr, c
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//uConn := ipv4.NewConn(tConn)
|
// uConn := ipv4.NewConn(tConn)
|
||||||
//uConn.SetTTL(3)
|
// uConn.SetTTL(3)
|
||||||
|
|
||||||
tConn.Write(content)
|
if _, err := tConn.Write(content); err != nil {
|
||||||
tConn.Close()
|
return err
|
||||||
return nil
|
}
|
||||||
|
return tConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UDP
|
// UDP
|
||||||
@@ -448,7 +454,7 @@ type UDPProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *UDPProxy) Run() (err error) {
|
func (pxy *UDPProxy) Run() (err error) {
|
||||||
pxy.localAddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", pxy.cfg.LocalIP, pxy.cfg.LocalPort))
|
pxy.localAddr, err = net.ResolveUDPAddr("udp", net.JoinHostPort(pxy.cfg.LocalIP, strconv.Itoa(pxy.cfg.LocalPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -540,7 +546,7 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
heartbeatFn := func(conn net.Conn, sendCh chan msg.Message) {
|
heartbeatFn := func(sendCh chan msg.Message) {
|
||||||
var errRet error
|
var errRet error
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Duration(30) * time.Second)
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
@@ -555,7 +561,7 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
|
|
||||||
go workConnSenderFn(pxy.workConn, pxy.sendCh)
|
go workConnSenderFn(pxy.workConn, pxy.sendCh)
|
||||||
go workConnReaderFn(pxy.workConn, pxy.readCh)
|
go workConnReaderFn(pxy.workConn, pxy.readCh)
|
||||||
go heartbeatFn(pxy.workConn, pxy.sendCh)
|
go heartbeatFn(pxy.sendCh)
|
||||||
udp.Forwarder(pxy.localAddr, pxy.readCh, pxy.sendCh, int(pxy.clientCfg.UDPPacketSize))
|
udp.Forwarder(pxy.localAddr, pxy.readCh, pxy.sendCh, int(pxy.clientCfg.UDPPacketSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +576,7 @@ type SUDPProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *SUDPProxy) Run() (err error) {
|
func (pxy *SUDPProxy) Run() (err error) {
|
||||||
pxy.localAddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", pxy.cfg.LocalIP, pxy.cfg.LocalPort))
|
pxy.localAddr, err = net.ResolveUDPAddr("udp", net.JoinHostPort(pxy.cfg.LocalIP, strconv.Itoa(pxy.cfg.LocalPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -686,7 +692,7 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
heartbeatFn := func(conn net.Conn, sendCh chan msg.Message) {
|
heartbeatFn := func(sendCh chan msg.Message) {
|
||||||
ticker := time.NewTicker(30 * time.Second)
|
ticker := time.NewTicker(30 * time.Second)
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
@@ -712,14 +718,15 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
|
|
||||||
go workConnSenderFn(workConn, sendCh)
|
go workConnSenderFn(workConn, sendCh)
|
||||||
go workConnReaderFn(workConn, readCh)
|
go workConnReaderFn(workConn, readCh)
|
||||||
go heartbeatFn(workConn, sendCh)
|
go heartbeatFn(sendCh)
|
||||||
|
|
||||||
udp.Forwarder(pxy.localAddr, readCh, sendCh, int(pxy.clientCfg.UDPPacketSize))
|
udp.Forwarder(pxy.localAddr, readCh, sendCh, int(pxy.clientCfg.UDPPacketSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common handler for tcp work connections.
|
// Common handler for tcp work connections.
|
||||||
func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin,
|
func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf, proxyPlugin plugin.Plugin,
|
||||||
baseInfo *config.BaseProxyConf, limiter *rate.Limiter, workConn net.Conn, encKey []byte, m *msg.StartWorkConn) {
|
baseInfo *config.BaseProxyConf, limiter *rate.Limiter, workConn net.Conn, encKey []byte, m *msg.StartWorkConn,
|
||||||
|
) {
|
||||||
xl := xlog.FromContextSafe(ctx)
|
xl := xlog.FromContextSafe(ctx)
|
||||||
var (
|
var (
|
||||||
remote io.ReadWriteCloser
|
remote io.ReadWriteCloser
|
||||||
@@ -753,12 +760,12 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf
|
|||||||
if m.DstAddr == "" {
|
if m.DstAddr == "" {
|
||||||
m.DstAddr = "127.0.0.1"
|
m.DstAddr = "127.0.0.1"
|
||||||
}
|
}
|
||||||
|
srcAddr, _ := net.ResolveTCPAddr("tcp", net.JoinHostPort(m.SrcAddr, strconv.Itoa(int(m.SrcPort))))
|
||||||
|
dstAddr, _ := net.ResolveTCPAddr("tcp", net.JoinHostPort(m.DstAddr, strconv.Itoa(int(m.DstPort))))
|
||||||
h := &pp.Header{
|
h := &pp.Header{
|
||||||
Command: pp.PROXY,
|
Command: pp.PROXY,
|
||||||
SourceAddress: net.ParseIP(m.SrcAddr),
|
SourceAddr: srcAddr,
|
||||||
SourcePort: m.SrcPort,
|
DestinationAddr: dstAddr,
|
||||||
DestinationAddress: net.ParseIP(m.DstAddr),
|
|
||||||
DestinationPort: m.DstPort,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(m.SrcAddr, ".") {
|
if strings.Contains(m.SrcAddr, ".") {
|
||||||
@@ -774,7 +781,7 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
h.WriteTo(buf)
|
_, _ = h.WriteTo(buf)
|
||||||
extraInfo = buf.Bytes()
|
extraInfo = buf.Bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -787,7 +794,10 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
localConn, err := frpNet.ConnectServer("tcp", fmt.Sprintf("%s:%d", localInfo.LocalIP, localInfo.LocalPort))
|
localConn, err := libdial.Dial(
|
||||||
|
net.JoinHostPort(localInfo.LocalIP, strconv.Itoa(localInfo.LocalPort)),
|
||||||
|
libdial.WithTimeout(10*time.Second),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
xl.Error("connect to local service [%s:%d] error: %v", localInfo.LocalIP, localInfo.LocalPort, err)
|
xl.Error("connect to local service [%s:%d] error: %v", localInfo.LocalIP, localInfo.LocalPort, err)
|
||||||
@@ -798,7 +808,11 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf
|
|||||||
localConn.RemoteAddr().String(), workConn.LocalAddr().String(), workConn.RemoteAddr().String())
|
localConn.RemoteAddr().String(), workConn.LocalAddr().String(), workConn.RemoteAddr().String())
|
||||||
|
|
||||||
if len(extraInfo) > 0 {
|
if len(extraInfo) > 0 {
|
||||||
localConn.Write(extraInfo)
|
if _, err := localConn.Write(extraInfo); err != nil {
|
||||||
|
workConn.Close()
|
||||||
|
xl.Error("write extraInfo to local conn error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frpIo.Join(localConn, remote)
|
frpIo.Join(localConn, remote)
|
||||||
|
@@ -6,12 +6,12 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/errors"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client/event"
|
"github.com/fatedier/frp/client/event"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@@ -75,7 +75,7 @@ func (pm *Manager) HandleWorkConn(name string, workConn net.Conn, m *msg.StartWo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm *Manager) HandleEvent(evType event.Type, payload interface{}) error {
|
func (pm *Manager) HandleEvent(payload interface{}) error {
|
||||||
var m msg.Message
|
var m msg.Message
|
||||||
switch e := payload.(type) {
|
switch e := payload.(type) {
|
||||||
case *event.StartProxyPayload:
|
case *event.StartProxyPayload:
|
||||||
@@ -113,10 +113,8 @@ func (pm *Manager) Reload(pxyCfgs map[string]config.ProxyConf) {
|
|||||||
cfg, ok := pxyCfgs[name]
|
cfg, ok := pxyCfgs[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
del = true
|
del = true
|
||||||
} else {
|
} else if !pxy.Cfg.Compare(cfg) {
|
||||||
if !pxy.Cfg.Compare(cfg) {
|
del = true
|
||||||
del = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if del {
|
if del {
|
||||||
|
@@ -8,13 +8,13 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/errors"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client/event"
|
"github.com/fatedier/frp/client/event"
|
||||||
"github.com/fatedier/frp/client/health"
|
"github.com/fatedier/frp/client/health"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -27,9 +27,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statusCheckInterval time.Duration = 3 * time.Second
|
statusCheckInterval = 3 * time.Second
|
||||||
waitResponseTimeout = 20 * time.Second
|
waitResponseTimeout = 20 * time.Second
|
||||||
startErrTimeout = 30 * time.Second
|
startErrTimeout = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type WorkingStatus struct {
|
type WorkingStatus struct {
|
||||||
@@ -145,7 +145,7 @@ func (pw *Wrapper) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pw *Wrapper) close() {
|
func (pw *Wrapper) close() {
|
||||||
pw.handler(event.EvCloseProxy, &event.CloseProxyPayload{
|
_ = pw.handler(&event.CloseProxyPayload{
|
||||||
CloseProxyMsg: &msg.CloseProxy{
|
CloseProxyMsg: &msg.CloseProxy{
|
||||||
ProxyName: pw.Name,
|
ProxyName: pw.Name,
|
||||||
},
|
},
|
||||||
@@ -174,7 +174,7 @@ func (pw *Wrapper) checkWorker() {
|
|||||||
var newProxyMsg msg.NewProxy
|
var newProxyMsg msg.NewProxy
|
||||||
pw.Cfg.MarshalToMsg(&newProxyMsg)
|
pw.Cfg.MarshalToMsg(&newProxyMsg)
|
||||||
pw.lastSendStartMsg = now
|
pw.lastSendStartMsg = now
|
||||||
pw.handler(event.EvStartProxy, &event.StartProxyPayload{
|
_ = pw.handler(&event.StartProxyPayload{
|
||||||
NewProxyMsg: &newProxyMsg,
|
NewProxyMsg: &newProxyMsg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ func (pw *Wrapper) checkWorker() {
|
|||||||
func (pw *Wrapper) statusNormalCallback() {
|
func (pw *Wrapper) statusNormalCallback() {
|
||||||
xl := pw.xl
|
xl := pw.xl
|
||||||
atomic.StoreUint32(&pw.health, 0)
|
atomic.StoreUint32(&pw.health, 0)
|
||||||
errors.PanicToError(func() {
|
_ = errors.PanicToError(func() {
|
||||||
select {
|
select {
|
||||||
case pw.healthNotifyCh <- struct{}{}:
|
case pw.healthNotifyCh <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
@@ -213,7 +213,7 @@ func (pw *Wrapper) statusNormalCallback() {
|
|||||||
func (pw *Wrapper) statusFailedCallback() {
|
func (pw *Wrapper) statusFailedCallback() {
|
||||||
xl := pw.xl
|
xl := pw.xl
|
||||||
atomic.StoreUint32(&pw.health, 1)
|
atomic.StoreUint32(&pw.health, 1)
|
||||||
errors.PanicToError(func() {
|
_ = errors.PanicToError(func() {
|
||||||
select {
|
select {
|
||||||
case pw.healthNotifyCh <- struct{}{}:
|
case pw.healthNotifyCh <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
@@ -227,7 +227,7 @@ func (pw *Wrapper) InWorkConn(workConn net.Conn, m *msg.StartWorkConn) {
|
|||||||
pw.mu.RLock()
|
pw.mu.RLock()
|
||||||
pxy := pw.pxy
|
pxy := pw.pxy
|
||||||
pw.mu.RUnlock()
|
pw.mu.RUnlock()
|
||||||
if pxy != nil {
|
if pxy != nil && pw.Phase == ProxyPhaseRunning {
|
||||||
xl.Debug("start a new work connection, localAddr: %s remoteAddr: %s", workConn.LocalAddr().String(), workConn.RemoteAddr().String())
|
xl.Debug("start a new work connection, localAddr: %s remoteAddr: %s", workConn.LocalAddr().String(), workConn.RemoteAddr().String())
|
||||||
go pxy.InWorkConn(workConn, m)
|
go pxy.InWorkConn(workConn, m)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -18,13 +18,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/crypto"
|
||||||
|
libdial "github.com/fatedier/golib/net/dial"
|
||||||
|
fmux "github.com/hashicorp/yamux"
|
||||||
|
quic "github.com/lucas-clemente/quic-go"
|
||||||
|
|
||||||
"github.com/fatedier/frp/assets"
|
"github.com/fatedier/frp/assets"
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
@@ -32,12 +40,16 @@ import (
|
|||||||
"github.com/fatedier/frp/pkg/transport"
|
"github.com/fatedier/frp/pkg/transport"
|
||||||
"github.com/fatedier/frp/pkg/util/log"
|
"github.com/fatedier/frp/pkg/util/log"
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
frpNet "github.com/fatedier/frp/pkg/util/net"
|
||||||
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
"github.com/fatedier/frp/pkg/util/version"
|
"github.com/fatedier/frp/pkg/util/version"
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
fmux "github.com/hashicorp/yamux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
crypto.DefaultSalt = "frp"
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
// Service is a client service.
|
// Service is a client service.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
// uniq id got from frps, attach it in loginMsg
|
// uniq id got from frps, attach it in loginMsg
|
||||||
@@ -70,8 +82,12 @@ type Service struct {
|
|||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(cfg config.ClientCommonConf, pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf, cfgFile string) (svr *Service, err error) {
|
func NewService(
|
||||||
|
cfg config.ClientCommonConf,
|
||||||
|
pxyCfgs map[string]config.ProxyConf,
|
||||||
|
visitorCfgs map[string]config.VisitorConf,
|
||||||
|
cfgFile string,
|
||||||
|
) (svr *Service, err error) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
svr = &Service{
|
svr = &Service{
|
||||||
authSetter: auth.NewAuthSetter(cfg.ClientConfig),
|
authSetter: auth.NewAuthSetter(cfg.ClientConfig),
|
||||||
@@ -95,9 +111,24 @@ func (svr *Service) GetController() *Control {
|
|||||||
func (svr *Service) Run() error {
|
func (svr *Service) Run() error {
|
||||||
xl := xlog.FromContextSafe(svr.ctx)
|
xl := xlog.FromContextSafe(svr.ctx)
|
||||||
|
|
||||||
|
// set custom DNSServer
|
||||||
|
if svr.cfg.DNSServer != "" {
|
||||||
|
dnsAddr := svr.cfg.DNSServer
|
||||||
|
if !strings.Contains(dnsAddr, ":") {
|
||||||
|
dnsAddr += ":53"
|
||||||
|
}
|
||||||
|
// Change default dns server for frpc
|
||||||
|
net.DefaultResolver = &net.Resolver{
|
||||||
|
PreferGo: true,
|
||||||
|
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
return net.Dial("udp", dnsAddr)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// login to frps
|
// login to frps
|
||||||
for {
|
for {
|
||||||
conn, session, err := svr.login()
|
conn, cm, err := svr.login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("login to server failed: %v", err)
|
xl.Warn("login to server failed: %v", err)
|
||||||
|
|
||||||
@@ -106,10 +137,10 @@ func (svr *Service) Run() error {
|
|||||||
if svr.cfg.LoginFailExit {
|
if svr.cfg.LoginFailExit {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Second)
|
util.RandomSleep(10*time.Second, 0.9, 1.1)
|
||||||
} else {
|
} else {
|
||||||
// login success
|
// login success
|
||||||
ctl := NewControl(svr.ctx, svr.runID, conn, session, svr.cfg, svr.pxyCfgs, svr.visitorCfgs, svr.serverUDPPort, svr.authSetter)
|
ctl := NewControl(svr.ctx, svr.runID, conn, cm, svr.cfg, svr.pxyCfgs, svr.visitorCfgs, svr.serverUDPPort, svr.authSetter)
|
||||||
ctl.Run()
|
ctl.Run()
|
||||||
svr.ctlMu.Lock()
|
svr.ctlMu.Lock()
|
||||||
svr.ctl = ctl
|
svr.ctl = ctl
|
||||||
@@ -122,12 +153,10 @@ func (svr *Service) Run() error {
|
|||||||
|
|
||||||
if svr.cfg.AdminPort != 0 {
|
if svr.cfg.AdminPort != 0 {
|
||||||
// Init admin server assets
|
// Init admin server assets
|
||||||
err := assets.Load(svr.cfg.AssetsDir)
|
assets.Load(svr.cfg.AssetsDir)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Load assets error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svr.RunAdminServer(svr.cfg.AdminAddr, svr.cfg.AdminPort)
|
address := net.JoinHostPort(svr.cfg.AdminAddr, strconv.Itoa(svr.cfg.AdminPort))
|
||||||
|
err := svr.RunAdminServer(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("run admin server error: %v", err)
|
log.Warn("run admin server error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -157,8 +186,11 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
|
|
||||||
// the first three retry with no delay
|
// the first three retry with no delay
|
||||||
if reconnectCounts > 3 {
|
if reconnectCounts > 3 {
|
||||||
time.Sleep(reconnectDelay)
|
util.RandomSleep(reconnectDelay, 0.9, 1.1)
|
||||||
|
xl.Info("wait %v to reconnect", reconnectDelay)
|
||||||
reconnectDelay *= 2
|
reconnectDelay *= 2
|
||||||
|
} else {
|
||||||
|
util.RandomSleep(time.Second, 0, 0.5)
|
||||||
}
|
}
|
||||||
reconnectCounts++
|
reconnectCounts++
|
||||||
|
|
||||||
@@ -171,12 +203,17 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
if atomic.LoadUint32(&svr.exit) != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
xl.Info("try to reconnect to server...")
|
xl.Info("try to reconnect to server...")
|
||||||
conn, session, err := svr.login()
|
conn, cm, err := svr.login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("reconnect to server error: %v", err)
|
xl.Warn("reconnect to server error: %v, wait %v for another retry", err, delayTime)
|
||||||
time.Sleep(delayTime)
|
util.RandomSleep(delayTime, 0.9, 1.1)
|
||||||
delayTime = delayTime * 2
|
|
||||||
|
delayTime *= 2
|
||||||
if delayTime > maxDelayTime {
|
if delayTime > maxDelayTime {
|
||||||
delayTime = maxDelayTime
|
delayTime = maxDelayTime
|
||||||
}
|
}
|
||||||
@@ -185,7 +222,7 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
// reconnect success, init delayTime
|
// reconnect success, init delayTime
|
||||||
delayTime = time.Second
|
delayTime = time.Second
|
||||||
|
|
||||||
ctl := NewControl(svr.ctx, svr.runID, conn, session, svr.cfg, svr.pxyCfgs, svr.visitorCfgs, svr.serverUDPPort, svr.authSetter)
|
ctl := NewControl(svr.ctx, svr.runID, conn, cm, svr.cfg, svr.pxyCfgs, svr.visitorCfgs, svr.serverUDPPort, svr.authSetter)
|
||||||
ctl.Run()
|
ctl.Run()
|
||||||
svr.ctlMu.Lock()
|
svr.ctlMu.Lock()
|
||||||
if svr.ctl != nil {
|
if svr.ctl != nil {
|
||||||
@@ -201,50 +238,23 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
// login creates a connection to frps and registers it self as a client
|
// login creates a connection to frps and registers it self as a client
|
||||||
// conn: control connection
|
// conn: control connection
|
||||||
// session: if it's not nil, using tcp mux
|
// session: if it's not nil, using tcp mux
|
||||||
func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) {
|
func (svr *Service) login() (conn net.Conn, cm *ConnectionManager, err error) {
|
||||||
xl := xlog.FromContextSafe(svr.ctx)
|
xl := xlog.FromContextSafe(svr.ctx)
|
||||||
var tlsConfig *tls.Config
|
cm = NewConnectionManager(svr.ctx, &svr.cfg)
|
||||||
if svr.cfg.TLSEnable {
|
|
||||||
tlsConfig, err = transport.NewClientTLSConfig(
|
if err = cm.OpenConnection(); err != nil {
|
||||||
svr.cfg.TLSCertFile,
|
return nil, nil, err
|
||||||
svr.cfg.TLSKeyFile,
|
|
||||||
svr.cfg.TLSTrustedCaFile,
|
|
||||||
svr.cfg.ServerAddr)
|
|
||||||
if err != nil {
|
|
||||||
xl.Warn("fail to build tls configuration when service login, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
conn, err = frpNet.ConnectServerByProxyWithTLS(svr.cfg.HTTPProxy, svr.cfg.Protocol,
|
|
||||||
fmt.Sprintf("%s:%d", svr.cfg.ServerAddr, svr.cfg.ServerPort), tlsConfig)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
cm.Close()
|
||||||
if session != nil {
|
|
||||||
session.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if svr.cfg.TCPMux {
|
conn, err = cm.Connect()
|
||||||
fmuxCfg := fmux.DefaultConfig()
|
if err != nil {
|
||||||
fmuxCfg.KeepAliveInterval = 20 * time.Second
|
return
|
||||||
fmuxCfg.LogOutput = ioutil.Discard
|
|
||||||
session, err = fmux.Client(conn, fmuxCfg)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
stream, errRet := session.OpenStream()
|
|
||||||
if errRet != nil {
|
|
||||||
session.Close()
|
|
||||||
err = errRet
|
|
||||||
return
|
|
||||||
}
|
|
||||||
conn = stream
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loginMsg := &msg.Login{
|
loginMsg := &msg.Login{
|
||||||
@@ -268,11 +278,11 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var loginRespMsg msg.LoginResp
|
var loginRespMsg msg.LoginResp
|
||||||
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
_ = conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
if err = msg.ReadMsgInto(conn, &loginRespMsg); err != nil {
|
if err = msg.ReadMsgInto(conn, &loginRespMsg); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conn.SetReadDeadline(time.Time{})
|
_ = conn.SetReadDeadline(time.Time{})
|
||||||
|
|
||||||
if loginRespMsg.Error != "" {
|
if loginRespMsg.Error != "" {
|
||||||
err = fmt.Errorf("%s", loginRespMsg.Error)
|
err = fmt.Errorf("%s", loginRespMsg.Error)
|
||||||
@@ -295,13 +305,184 @@ func (svr *Service) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs
|
|||||||
svr.visitorCfgs = visitorCfgs
|
svr.visitorCfgs = visitorCfgs
|
||||||
svr.cfgMu.Unlock()
|
svr.cfgMu.Unlock()
|
||||||
|
|
||||||
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
|
svr.ctlMu.RLock()
|
||||||
|
ctl := svr.ctl
|
||||||
|
svr.ctlMu.RUnlock()
|
||||||
|
|
||||||
|
if ctl != nil {
|
||||||
|
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svr *Service) Close() {
|
func (svr *Service) Close() {
|
||||||
|
svr.GracefulClose(time.Duration(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svr *Service) GracefulClose(d time.Duration) {
|
||||||
atomic.StoreUint32(&svr.exit, 1)
|
atomic.StoreUint32(&svr.exit, 1)
|
||||||
|
|
||||||
|
svr.ctlMu.RLock()
|
||||||
if svr.ctl != nil {
|
if svr.ctl != nil {
|
||||||
svr.ctl.Close()
|
svr.ctl.GracefulClose(d)
|
||||||
}
|
}
|
||||||
|
svr.ctlMu.RUnlock()
|
||||||
|
|
||||||
svr.cancel()
|
svr.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConnectionManager struct {
|
||||||
|
ctx context.Context
|
||||||
|
cfg *config.ClientCommonConf
|
||||||
|
|
||||||
|
muxSession *fmux.Session
|
||||||
|
quicConn quic.Connection
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConnectionManager(ctx context.Context, cfg *config.ClientCommonConf) *ConnectionManager {
|
||||||
|
return &ConnectionManager{
|
||||||
|
ctx: ctx,
|
||||||
|
cfg: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *ConnectionManager) OpenConnection() error {
|
||||||
|
xl := xlog.FromContextSafe(cm.ctx)
|
||||||
|
|
||||||
|
// special for quic
|
||||||
|
if strings.EqualFold(cm.cfg.Protocol, "quic") {
|
||||||
|
var tlsConfig *tls.Config
|
||||||
|
var err error
|
||||||
|
sn := cm.cfg.TLSServerName
|
||||||
|
if sn == "" {
|
||||||
|
sn = cm.cfg.ServerAddr
|
||||||
|
}
|
||||||
|
if cm.cfg.TLSEnable {
|
||||||
|
tlsConfig, err = transport.NewClientTLSConfig(
|
||||||
|
cm.cfg.TLSCertFile,
|
||||||
|
cm.cfg.TLSKeyFile,
|
||||||
|
cm.cfg.TLSTrustedCaFile,
|
||||||
|
sn)
|
||||||
|
} else {
|
||||||
|
tlsConfig, err = transport.NewClientTLSConfig("", "", "", sn)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
xl.Warn("fail to build tls configuration, err: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tlsConfig.NextProtos = []string{"frp"}
|
||||||
|
|
||||||
|
conn, err := quic.DialAddr(
|
||||||
|
net.JoinHostPort(cm.cfg.ServerAddr, strconv.Itoa(cm.cfg.ServerPort)),
|
||||||
|
tlsConfig, &quic.Config{
|
||||||
|
MaxIdleTimeout: time.Duration(cm.cfg.QUICMaxIdleTimeout) * time.Second,
|
||||||
|
MaxIncomingStreams: int64(cm.cfg.QUICMaxIncomingStreams),
|
||||||
|
KeepAlivePeriod: time.Duration(cm.cfg.QUICKeepalivePeriod) * time.Second,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cm.quicConn = conn
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cm.cfg.TCPMux {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := cm.realConnect()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmuxCfg := fmux.DefaultConfig()
|
||||||
|
fmuxCfg.KeepAliveInterval = time.Duration(cm.cfg.TCPMuxKeepaliveInterval) * time.Second
|
||||||
|
fmuxCfg.LogOutput = io.Discard
|
||||||
|
session, err := fmux.Client(conn, fmuxCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cm.muxSession = session
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *ConnectionManager) Connect() (net.Conn, error) {
|
||||||
|
if cm.quicConn != nil {
|
||||||
|
stream, err := cm.quicConn.OpenStreamSync(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return frpNet.QuicStreamToNetConn(stream, cm.quicConn), nil
|
||||||
|
} else if cm.muxSession != nil {
|
||||||
|
stream, err := cm.muxSession.OpenStream()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return stream, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return cm.realConnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *ConnectionManager) realConnect() (net.Conn, error) {
|
||||||
|
xl := xlog.FromContextSafe(cm.ctx)
|
||||||
|
var tlsConfig *tls.Config
|
||||||
|
var err error
|
||||||
|
if cm.cfg.TLSEnable {
|
||||||
|
sn := cm.cfg.TLSServerName
|
||||||
|
if sn == "" {
|
||||||
|
sn = cm.cfg.ServerAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConfig, err = transport.NewClientTLSConfig(
|
||||||
|
cm.cfg.TLSCertFile,
|
||||||
|
cm.cfg.TLSKeyFile,
|
||||||
|
cm.cfg.TLSTrustedCaFile,
|
||||||
|
sn)
|
||||||
|
if err != nil {
|
||||||
|
xl.Warn("fail to build tls configuration, err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyType, addr, auth, err := libdial.ParseProxyURL(cm.cfg.HTTPProxy)
|
||||||
|
if err != nil {
|
||||||
|
xl.Error("fail to parse proxy url")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dialOptions := []libdial.DialOption{}
|
||||||
|
protocol := cm.cfg.Protocol
|
||||||
|
if protocol == "websocket" {
|
||||||
|
protocol = "tcp"
|
||||||
|
dialOptions = append(dialOptions, libdial.WithAfterHook(libdial.AfterHook{Hook: frpNet.DialHookWebsocket()}))
|
||||||
|
}
|
||||||
|
if cm.cfg.ConnectServerLocalIP != "" {
|
||||||
|
dialOptions = append(dialOptions, libdial.WithLocalAddr(cm.cfg.ConnectServerLocalIP))
|
||||||
|
}
|
||||||
|
dialOptions = append(dialOptions,
|
||||||
|
libdial.WithProtocol(protocol),
|
||||||
|
libdial.WithTimeout(time.Duration(cm.cfg.DialServerTimeout)*time.Second),
|
||||||
|
libdial.WithKeepAlive(time.Duration(cm.cfg.DialServerKeepAlive)*time.Second),
|
||||||
|
libdial.WithProxy(proxyType, addr),
|
||||||
|
libdial.WithProxyAuth(auth),
|
||||||
|
libdial.WithTLSConfig(tlsConfig),
|
||||||
|
libdial.WithAfterHook(libdial.AfterHook{
|
||||||
|
Hook: frpNet.DialHookCustomTLSHeadByte(tlsConfig != nil, cm.cfg.DisableCustomTLSFirstByte),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
conn, err := libdial.Dial(
|
||||||
|
net.JoinHostPort(cm.cfg.ServerAddr, strconv.Itoa(cm.cfg.ServerPort)),
|
||||||
|
dialOptions...,
|
||||||
|
)
|
||||||
|
return conn, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *ConnectionManager) Close() error {
|
||||||
|
if cm.quicConn != nil {
|
||||||
|
_ = cm.quicConn.CloseWithError(0, "")
|
||||||
|
}
|
||||||
|
if cm.muxSession != nil {
|
||||||
|
_ = cm.muxSession.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -19,22 +19,22 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/golib/errors"
|
||||||
|
frpIo "github.com/fatedier/golib/io"
|
||||||
|
"github.com/fatedier/golib/pool"
|
||||||
|
fmux "github.com/hashicorp/yamux"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/proto/udp"
|
"github.com/fatedier/frp/pkg/proto/udp"
|
||||||
frpNet "github.com/fatedier/frp/pkg/util/net"
|
frpNet "github.com/fatedier/frp/pkg/util/net"
|
||||||
"github.com/fatedier/frp/pkg/util/util"
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
"github.com/fatedier/frp/pkg/util/xlog"
|
"github.com/fatedier/frp/pkg/util/xlog"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
|
||||||
frpIo "github.com/fatedier/golib/io"
|
|
||||||
"github.com/fatedier/golib/pool"
|
|
||||||
fmux "github.com/hashicorp/yamux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Visitor is used for forward traffics from local port tot remote service.
|
// Visitor is used for forward traffics from local port tot remote service.
|
||||||
@@ -71,9 +71,8 @@ func NewVisitor(ctx context.Context, ctl *Control, cfg config.VisitorConf) (visi
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BaseVisitor struct {
|
type BaseVisitor struct {
|
||||||
ctl *Control
|
ctl *Control
|
||||||
l net.Listener
|
l net.Listener
|
||||||
closed bool
|
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@@ -86,7 +85,7 @@ type STCPVisitor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sv *STCPVisitor) Run() (err error) {
|
func (sv *STCPVisitor) Run() (err error) {
|
||||||
sv.l, err = net.Listen("tcp", fmt.Sprintf("%s:%d", sv.cfg.BindAddr, sv.cfg.BindPort))
|
sv.l, err = net.Listen("tcp", net.JoinHostPort(sv.cfg.BindAddr, strconv.Itoa(sv.cfg.BindPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -138,13 +137,13 @@ func (sv *STCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newVisitorConnRespMsg msg.NewVisitorConnResp
|
var newVisitorConnRespMsg msg.NewVisitorConnResp
|
||||||
visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
_ = visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("get newVisitorConnRespMsg error: %v", err)
|
xl.Warn("get newVisitorConnRespMsg error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
visitorConn.SetReadDeadline(time.Time{})
|
_ = visitorConn.SetReadDeadline(time.Time{})
|
||||||
|
|
||||||
if newVisitorConnRespMsg.Error != "" {
|
if newVisitorConnRespMsg.Error != "" {
|
||||||
xl.Warn("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
xl.Warn("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
||||||
@@ -175,7 +174,7 @@ type XTCPVisitor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sv *XTCPVisitor) Run() (err error) {
|
func (sv *XTCPVisitor) Run() (err error) {
|
||||||
sv.l, err = net.Listen("tcp", fmt.Sprintf("%s:%d", sv.cfg.BindAddr, sv.cfg.BindPort))
|
sv.l, err = net.Listen("tcp", net.JoinHostPort(sv.cfg.BindAddr, strconv.Itoa(sv.cfg.BindPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -212,7 +211,7 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
raddr, err := net.ResolveUDPAddr("udp",
|
raddr, err := net.ResolveUDPAddr("udp",
|
||||||
fmt.Sprintf("%s:%d", sv.ctl.clientCfg.ServerAddr, sv.ctl.serverUDPPort))
|
net.JoinHostPort(sv.ctl.clientCfg.ServerAddr, strconv.Itoa(sv.ctl.serverUDPPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Error("resolve server UDP addr error")
|
xl.Error("resolve server UDP addr error")
|
||||||
return
|
return
|
||||||
@@ -239,7 +238,7 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
|
|
||||||
// Wait for client address at most 10 seconds.
|
// Wait for client address at most 10 seconds.
|
||||||
var natHoleRespMsg msg.NatHoleResp
|
var natHoleRespMsg msg.NatHoleResp
|
||||||
visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
_ = visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
buf := pool.GetBuf(1024)
|
buf := pool.GetBuf(1024)
|
||||||
n, err := visitorConn.Read(buf)
|
n, err := visitorConn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -252,7 +251,7 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
xl.Warn("get natHoleRespMsg error: %v", err)
|
xl.Warn("get natHoleRespMsg error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
visitorConn.SetReadDeadline(time.Time{})
|
_ = visitorConn.SetReadDeadline(time.Time{})
|
||||||
pool.PutBuf(buf)
|
pool.PutBuf(buf)
|
||||||
|
|
||||||
if natHoleRespMsg.Error != "" {
|
if natHoleRespMsg.Error != "" {
|
||||||
@@ -279,17 +278,20 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
}
|
}
|
||||||
defer lConn.Close()
|
defer lConn.Close()
|
||||||
|
|
||||||
lConn.Write([]byte(natHoleRespMsg.Sid))
|
if _, err := lConn.Write([]byte(natHoleRespMsg.Sid)); err != nil {
|
||||||
|
xl.Error("write sid error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// read ack sid from client
|
// read ack sid from client
|
||||||
sidBuf := pool.GetBuf(1024)
|
sidBuf := pool.GetBuf(1024)
|
||||||
lConn.SetReadDeadline(time.Now().Add(8 * time.Second))
|
_ = lConn.SetReadDeadline(time.Now().Add(8 * time.Second))
|
||||||
n, err = lConn.Read(sidBuf)
|
n, err = lConn.Read(sidBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("get sid from client error: %v", err)
|
xl.Warn("get sid from client error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lConn.SetReadDeadline(time.Time{})
|
_ = lConn.SetReadDeadline(time.Time{})
|
||||||
if string(sidBuf[:n]) != natHoleRespMsg.Sid {
|
if string(sidBuf[:n]) != natHoleRespMsg.Sid {
|
||||||
xl.Warn("incorrect sid from client")
|
xl.Warn("incorrect sid from client")
|
||||||
return
|
return
|
||||||
@@ -308,7 +310,7 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
|
|
||||||
fmuxCfg := fmux.DefaultConfig()
|
fmuxCfg := fmux.DefaultConfig()
|
||||||
fmuxCfg.KeepAliveInterval = 5 * time.Second
|
fmuxCfg.KeepAliveInterval = 5 * time.Second
|
||||||
fmuxCfg.LogOutput = ioutil.Discard
|
fmuxCfg.LogOutput = io.Discard
|
||||||
sess, err := fmux.Client(remote, fmuxCfg)
|
sess, err := fmux.Client(remote, fmuxCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Error("create yamux session error: %v", err)
|
xl.Error("create yamux session error: %v", err)
|
||||||
@@ -353,7 +355,7 @@ type SUDPVisitor struct {
|
|||||||
func (sv *SUDPVisitor) Run() (err error) {
|
func (sv *SUDPVisitor) Run() (err error) {
|
||||||
xl := xlog.FromContextSafe(sv.ctx)
|
xl := xlog.FromContextSafe(sv.ctx)
|
||||||
|
|
||||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", sv.cfg.BindAddr, sv.cfg.BindPort))
|
addr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(sv.cfg.BindAddr, strconv.Itoa(sv.cfg.BindPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sudp ResolveUDPAddr error: %v", err)
|
return fmt.Errorf("sudp ResolveUDPAddr error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -366,7 +368,7 @@ func (sv *SUDPVisitor) Run() (err error) {
|
|||||||
sv.sendCh = make(chan *msg.UDPPacket, 1024)
|
sv.sendCh = make(chan *msg.UDPPacket, 1024)
|
||||||
sv.readCh = make(chan *msg.UDPPacket, 1024)
|
sv.readCh = make(chan *msg.UDPPacket, 1024)
|
||||||
|
|
||||||
xl.Info("sudp start to work")
|
xl.Info("sudp start to work, listen on %s", addr)
|
||||||
|
|
||||||
go sv.dispatcher()
|
go sv.dispatcher()
|
||||||
go udp.ForwardUserConn(sv.udpConn, sv.readCh, sv.sendCh, int(sv.ctl.clientCfg.UDPPacketSize))
|
go udp.ForwardUserConn(sv.udpConn, sv.readCh, sv.sendCh, int(sv.ctl.clientCfg.UDPPacketSize))
|
||||||
@@ -377,29 +379,33 @@ func (sv *SUDPVisitor) Run() (err error) {
|
|||||||
func (sv *SUDPVisitor) dispatcher() {
|
func (sv *SUDPVisitor) dispatcher() {
|
||||||
xl := xlog.FromContextSafe(sv.ctx)
|
xl := xlog.FromContextSafe(sv.ctx)
|
||||||
|
|
||||||
|
var (
|
||||||
|
visitorConn net.Conn
|
||||||
|
err error
|
||||||
|
|
||||||
|
firstPacket *msg.UDPPacket
|
||||||
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// loop for get frpc to frps tcp conn
|
select {
|
||||||
// setup worker
|
case firstPacket = <-sv.sendCh:
|
||||||
// wait worker to finished
|
if firstPacket == nil {
|
||||||
// retry or exit
|
|
||||||
visitorConn, err := sv.getNewVisitorConn()
|
|
||||||
if err != nil {
|
|
||||||
// check if proxy is closed
|
|
||||||
// if checkCloseCh is close, we will return, other case we will continue to reconnect
|
|
||||||
select {
|
|
||||||
case <-sv.checkCloseCh:
|
|
||||||
xl.Info("frpc sudp visitor proxy is closed")
|
xl.Info("frpc sudp visitor proxy is closed")
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
|
case <-sv.checkCloseCh:
|
||||||
|
xl.Info("frpc sudp visitor proxy is closed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(3 * time.Second)
|
visitorConn, err = sv.getNewVisitorConn()
|
||||||
|
if err != nil {
|
||||||
xl.Warn("newVisitorConn to frps error: %v, try to reconnect", err)
|
xl.Warn("newVisitorConn to frps error: %v, try to reconnect", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sv.worker(visitorConn)
|
// visitorConn always be closed when worker done.
|
||||||
|
sv.worker(visitorConn, firstPacket)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-sv.checkCloseCh:
|
case <-sv.checkCloseCh:
|
||||||
@@ -409,7 +415,7 @@ func (sv *SUDPVisitor) dispatcher() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sv *SUDPVisitor) worker(workConn net.Conn) {
|
func (sv *SUDPVisitor) worker(workConn net.Conn, firstPacket *msg.UDPPacket) {
|
||||||
xl := xlog.FromContextSafe(sv.ctx)
|
xl := xlog.FromContextSafe(sv.ctx)
|
||||||
xl.Debug("starting sudp proxy worker")
|
xl.Debug("starting sudp proxy worker")
|
||||||
|
|
||||||
@@ -432,13 +438,13 @@ func (sv *SUDPVisitor) worker(workConn net.Conn) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// frpc will send heartbeat in workConn to frpc visitor for keeping alive
|
// frpc will send heartbeat in workConn to frpc visitor for keeping alive
|
||||||
conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
_ = conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
||||||
if rawMsg, errRet = msg.ReadMsg(conn); errRet != nil {
|
if rawMsg, errRet = msg.ReadMsg(conn); errRet != nil {
|
||||||
xl.Warn("read from workconn for user udp conn error: %v", errRet)
|
xl.Warn("read from workconn for user udp conn error: %v", errRet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.SetReadDeadline(time.Time{})
|
_ = conn.SetReadDeadline(time.Time{})
|
||||||
switch m := rawMsg.(type) {
|
switch m := rawMsg.(type) {
|
||||||
case *msg.Ping:
|
case *msg.Ping:
|
||||||
xl.Debug("frpc visitor get ping message from frpc")
|
xl.Debug("frpc visitor get ping message from frpc")
|
||||||
@@ -446,7 +452,7 @@ func (sv *SUDPVisitor) worker(workConn net.Conn) {
|
|||||||
case *msg.UDPPacket:
|
case *msg.UDPPacket:
|
||||||
if errRet := errors.PanicToError(func() {
|
if errRet := errors.PanicToError(func() {
|
||||||
sv.readCh <- m
|
sv.readCh <- m
|
||||||
xl.Trace("frpc visitor get udp packet from frpc")
|
xl.Trace("frpc visitor get udp packet from workConn: %s", m.Content)
|
||||||
}); errRet != nil {
|
}); errRet != nil {
|
||||||
xl.Info("reader goroutine for udp work connection closed")
|
xl.Info("reader goroutine for udp work connection closed")
|
||||||
return
|
return
|
||||||
@@ -463,6 +469,14 @@ func (sv *SUDPVisitor) worker(workConn net.Conn) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var errRet error
|
var errRet error
|
||||||
|
if firstPacket != nil {
|
||||||
|
if errRet = msg.WriteMsg(conn, firstPacket); errRet != nil {
|
||||||
|
xl.Warn("sender goroutine for udp work connection closed: %v", errRet)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
xl.Trace("send udp package to workConn: %s", firstPacket.Content)
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case udpMsg, ok := <-sv.sendCh:
|
case udpMsg, ok := <-sv.sendCh:
|
||||||
@@ -475,6 +489,7 @@ func (sv *SUDPVisitor) worker(workConn net.Conn) {
|
|||||||
xl.Warn("sender goroutine for udp work connection closed: %v", errRet)
|
xl.Warn("sender goroutine for udp work connection closed: %v", errRet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
xl.Trace("send udp package to workConn: %s", udpMsg.Content)
|
||||||
case <-closeCh:
|
case <-closeCh:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -509,12 +524,12 @@ func (sv *SUDPVisitor) getNewVisitorConn() (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newVisitorConnRespMsg msg.NewVisitorConnResp
|
var newVisitorConnRespMsg msg.NewVisitorConnResp
|
||||||
visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
_ = visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("frpc read newVisitorConnRespMsg error: %v", err)
|
return nil, fmt.Errorf("frpc read newVisitorConnRespMsg error: %v", err)
|
||||||
}
|
}
|
||||||
visitorConn.SetReadDeadline(time.Time{})
|
_ = visitorConn.SetReadDeadline(time.Time{})
|
||||||
|
|
||||||
if newVisitorConnRespMsg.Error != "" {
|
if newVisitorConnRespMsg.Error != "" {
|
||||||
return nil, fmt.Errorf("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
return nil, fmt.Errorf("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
||||||
|
@@ -65,7 +65,7 @@ func (vm *VisitorManager) Run() {
|
|||||||
name := cfg.GetBaseInfo().ProxyName
|
name := cfg.GetBaseInfo().ProxyName
|
||||||
if _, exist := vm.visitors[name]; !exist {
|
if _, exist := vm.visitors[name]; !exist {
|
||||||
xl.Info("try to start visitor [%s]", name)
|
xl.Info("try to start visitor [%s]", name)
|
||||||
vm.startVisitor(cfg)
|
_ = vm.startVisitor(cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vm.mu.Unlock()
|
vm.mu.Unlock()
|
||||||
@@ -99,10 +99,8 @@ func (vm *VisitorManager) Reload(cfgs map[string]config.VisitorConf) {
|
|||||||
cfg, ok := cfgs[name]
|
cfg, ok := cfgs[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
del = true
|
del = true
|
||||||
} else {
|
} else if !oldCfg.Compare(cfg) {
|
||||||
if !oldCfg.Compare(cfg) {
|
del = true
|
||||||
del = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if del {
|
if del {
|
||||||
@@ -123,13 +121,12 @@ func (vm *VisitorManager) Reload(cfgs map[string]config.VisitorConf) {
|
|||||||
if _, ok := vm.cfgs[name]; !ok {
|
if _, ok := vm.cfgs[name]; !ok {
|
||||||
vm.cfgs[name] = cfg
|
vm.cfgs[name] = cfg
|
||||||
addNames = append(addNames, name)
|
addNames = append(addNames, name)
|
||||||
vm.startVisitor(cfg)
|
_ = vm.startVisitor(cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(addNames) > 0 {
|
if len(addNames) > 0 {
|
||||||
xl.Info("visitor added: %v", addNames)
|
xl.Info("visitor added: %v", addNames)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VisitorManager) Close() {
|
func (vm *VisitorManager) Close() {
|
||||||
|
@@ -15,18 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
_ "github.com/fatedier/frp/assets/frpc"
|
||||||
"time"
|
|
||||||
|
|
||||||
_ "github.com/fatedier/frp/assets/frpc/statik"
|
|
||||||
"github.com/fatedier/frp/cmd/frpc/sub"
|
"github.com/fatedier/frp/cmd/frpc/sub"
|
||||||
|
|
||||||
"github.com/fatedier/golib/crypto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
crypto.DefaultSalt = "frp"
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
sub.Execute()
|
sub.Execute()
|
||||||
}
|
}
|
||||||
|
@@ -19,10 +19,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -47,7 +47,7 @@ var httpCmd = &cobra.Command{
|
|||||||
Use: "http",
|
Use: "http",
|
||||||
Short: "Run frpc with a single http proxy",
|
Short: "Run frpc with a single http proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -43,7 +43,7 @@ var httpsCmd = &cobra.Command{
|
|||||||
Use: "https",
|
Use: "https",
|
||||||
Short: "Run frpc with a single https proxy",
|
Short: "Run frpc with a single https proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -17,14 +17,14 @@ package sub
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -35,19 +35,13 @@ var reloadCmd = &cobra.Command{
|
|||||||
Use: "reload",
|
Use: "reload",
|
||||||
Short: "Hot-Reload frpc configuration",
|
Short: "Hot-Reload frpc configuration",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
iniContent, err := config.GetRenderedConfFromFile(cfgFile)
|
cfg, _, _, err := config.ParseClientConfig(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeIni, iniContent)
|
err = reload(cfg)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = reload(clientCfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("frpc reload error: %v\n", err)
|
fmt.Printf("frpc reload error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -82,7 +76,7 @@ func reload(clientCfg config.ClientCommonConf) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -15,23 +15,24 @@
|
|||||||
package sub
|
package sub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client"
|
"github.com/fatedier/frp/client"
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/util/log"
|
"github.com/fatedier/frp/pkg/util/log"
|
||||||
"github.com/fatedier/frp/pkg/util/version"
|
"github.com/fatedier/frp/pkg/util/version"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -41,6 +42,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
|
cfgDir string
|
||||||
showVersion bool
|
showVersion bool
|
||||||
|
|
||||||
serverAddr string
|
serverAddr string
|
||||||
@@ -72,15 +74,12 @@ var (
|
|||||||
bindPort int
|
bindPort int
|
||||||
|
|
||||||
tlsEnable bool
|
tlsEnable bool
|
||||||
|
|
||||||
kcpDoneCh chan struct{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "./frpc.ini", "config file of frpc")
|
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "./frpc.ini", "config file of frpc")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&cfgDir, "config_dir", "", "", "config directory, run one frpc service for each file in config directory")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")
|
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")
|
||||||
|
|
||||||
kcpDoneCh = make(chan struct{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterCommonFlags(cmd *cobra.Command) {
|
func RegisterCommonFlags(cmd *cobra.Command) {
|
||||||
@@ -104,6 +103,32 @@ var rootCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If cfgDir is not empty, run multiple frpc service for each config file in cfgDir.
|
||||||
|
// Note that it's only designed for testing. It's not guaranteed to be stable.
|
||||||
|
if cfgDir != "" {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
_ = filepath.WalkDir(cfgDir, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if d.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
wg.Add(1)
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
err := runClient(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("frpc service error for config file [%s]\n", path)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
wg.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Do not show command usage here.
|
// Do not show command usage here.
|
||||||
err := runClient(cfgFile)
|
err := runClient(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -120,54 +145,27 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSignal(svr *client.Service) {
|
func handleSignal(svr *client.Service, doneCh chan struct{}) {
|
||||||
ch := make(chan os.Signal)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-ch
|
<-ch
|
||||||
svr.Close()
|
svr.GracefulClose(500 * time.Millisecond)
|
||||||
time.Sleep(250 * time.Millisecond)
|
close(doneCh)
|
||||||
close(kcpDoneCh)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseClientCommonCfg(fileType int, content string) (cfg config.ClientCommonConf, err error) {
|
|
||||||
if fileType == CfgFileTypeIni {
|
|
||||||
cfg, err = parseClientCommonCfgFromIni(content)
|
|
||||||
} else if fileType == CfgFileTypeCmd {
|
|
||||||
cfg, err = parseClientCommonCfgFromCmd()
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cfg.Check()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseClientCommonCfgFromIni(content string) (config.ClientCommonConf, error) {
|
|
||||||
cfg, err := config.UnmarshalClientConfFromIni(content)
|
|
||||||
if err != nil {
|
|
||||||
return config.ClientCommonConf{}, err
|
|
||||||
}
|
|
||||||
return cfg, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
|
func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
|
||||||
cfg = config.GetDefaultClientConf()
|
cfg = config.GetDefaultClientConf()
|
||||||
|
|
||||||
strs := strings.Split(serverAddr, ":")
|
ipStr, portStr, err := net.SplitHostPort(serverAddr)
|
||||||
if len(strs) < 2 {
|
if err != nil {
|
||||||
err = fmt.Errorf("invalid server_addr")
|
err = fmt.Errorf("invalid server_addr: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strs[0] != "" {
|
|
||||||
cfg.ServerAddr = strs[0]
|
cfg.ServerAddr = ipStr
|
||||||
}
|
cfg.ServerPort, err = strconv.Atoi(portStr)
|
||||||
cfg.ServerPort, err = strconv.Atoi(strs[1])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("invalid server_addr")
|
err = fmt.Errorf("invalid server_addr: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,11 +174,6 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
|
|||||||
cfg.LogLevel = logLevel
|
cfg.LogLevel = logLevel
|
||||||
cfg.LogFile = logFile
|
cfg.LogFile = logFile
|
||||||
cfg.LogMaxDays = int64(logMaxDays)
|
cfg.LogMaxDays = int64(logMaxDays)
|
||||||
if logFile == "console" {
|
|
||||||
cfg.LogWay = "console"
|
|
||||||
} else {
|
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
cfg.DisableLogColor = disableLogColor
|
cfg.DisableLogColor = disableLogColor
|
||||||
|
|
||||||
// Only token authentication is supported in cmd mode
|
// Only token authentication is supported in cmd mode
|
||||||
@@ -188,28 +181,20 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
|
|||||||
cfg.Token = token
|
cfg.Token = token
|
||||||
cfg.TLSEnable = tlsEnable
|
cfg.TLSEnable = tlsEnable
|
||||||
|
|
||||||
|
cfg.Complete()
|
||||||
|
if err = cfg.Validate(); err != nil {
|
||||||
|
err = fmt.Errorf("parse config error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func runClient(cfgFilePath string) (err error) {
|
func runClient(cfgFilePath string) error {
|
||||||
var content string
|
cfg, pxyCfgs, visitorCfgs, err := config.ParseClientConfig(cfgFilePath)
|
||||||
content, err = config.GetRenderedConfFromFile(cfgFilePath)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg, err := parseClientCommonCfg(CfgFileTypeIni, content)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pxyCfgs, visitorCfgs, err := config.LoadAllConfFromIni(cfg.User, content, cfg.Start)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
|
||||||
err = startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startService(
|
func startService(
|
||||||
@@ -218,22 +203,12 @@ func startService(
|
|||||||
visitorCfgs map[string]config.VisitorConf,
|
visitorCfgs map[string]config.VisitorConf,
|
||||||
cfgFile string,
|
cfgFile string,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
|
|
||||||
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel,
|
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel,
|
||||||
cfg.LogMaxDays, cfg.DisableLogColor)
|
cfg.LogMaxDays, cfg.DisableLogColor)
|
||||||
|
|
||||||
if cfg.DNSServer != "" {
|
if cfgFile != "" {
|
||||||
s := cfg.DNSServer
|
log.Trace("start frpc service for config file [%s]", cfgFile)
|
||||||
if !strings.Contains(s, ":") {
|
defer log.Trace("frpc service for config file [%s] stopped", cfgFile)
|
||||||
s += ":53"
|
|
||||||
}
|
|
||||||
// Change default dns server for frpc
|
|
||||||
net.DefaultResolver = &net.Resolver{
|
|
||||||
PreferGo: true,
|
|
||||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
||||||
return net.Dial("udp", s)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
svr, errRet := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
|
svr, errRet := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
@@ -241,13 +216,14 @@ func startService(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kcpDoneCh := make(chan struct{})
|
||||||
// Capture the exit signal if we use kcp.
|
// Capture the exit signal if we use kcp.
|
||||||
if cfg.Protocol == "kcp" {
|
if cfg.Protocol == "kcp" {
|
||||||
go handleSignal(svr)
|
go handleSignal(svr, kcpDoneCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = svr.Run()
|
err = svr.Run()
|
||||||
if cfg.Protocol == "kcp" {
|
if err == nil && cfg.Protocol == "kcp" {
|
||||||
<-kcpDoneCh
|
<-kcpDoneCh
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@@ -18,16 +18,16 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatedier/frp/client"
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
|
||||||
|
|
||||||
"github.com/rodaine/table"
|
"github.com/rodaine/table"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/client"
|
||||||
|
"github.com/fatedier/frp/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -38,20 +38,13 @@ var statusCmd = &cobra.Command{
|
|||||||
Use: "status",
|
Use: "status",
|
||||||
Short: "Overview of all proxies status",
|
Short: "Overview of all proxies status",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
iniContent, err := config.GetRenderedConfFromFile(cfgFile)
|
cfg, _, _, err := config.ParseClientConfig(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeIni, iniContent)
|
if err = status(cfg); err != nil {
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = status(clientCfg)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("frpc get status error: %v\n", err)
|
fmt.Printf("frpc get status error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -84,7 +77,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
return fmt.Errorf("admin api status code [%d]", resp.StatusCode)
|
return fmt.Errorf("admin api status code [%d]", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -96,7 +89,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
|
|
||||||
fmt.Println("Proxy Status...")
|
fmt.Println("Proxy Status...")
|
||||||
if len(res.TCP) > 0 {
|
if len(res.TCP) > 0 {
|
||||||
fmt.Printf("TCP")
|
fmt.Println("TCP")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.TCP {
|
for _, ps := range res.TCP {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
@@ -105,7 +98,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
if len(res.UDP) > 0 {
|
if len(res.UDP) > 0 {
|
||||||
fmt.Printf("UDP")
|
fmt.Println("UDP")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.UDP {
|
for _, ps := range res.UDP {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
@@ -114,7 +107,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
if len(res.HTTP) > 0 {
|
if len(res.HTTP) > 0 {
|
||||||
fmt.Printf("HTTP")
|
fmt.Println("HTTP")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.HTTP {
|
for _, ps := range res.HTTP {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
@@ -123,7 +116,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
if len(res.HTTPS) > 0 {
|
if len(res.HTTPS) > 0 {
|
||||||
fmt.Printf("HTTPS")
|
fmt.Println("HTTPS")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.HTTPS {
|
for _, ps := range res.HTTPS {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
@@ -132,7 +125,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
if len(res.STCP) > 0 {
|
if len(res.STCP) > 0 {
|
||||||
fmt.Printf("STCP")
|
fmt.Println("STCP")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.STCP {
|
for _, ps := range res.STCP {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
@@ -141,7 +134,7 @@ func status(clientCfg config.ClientCommonConf) error {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
if len(res.XTCP) > 0 {
|
if len(res.XTCP) > 0 {
|
||||||
fmt.Printf("XTCP")
|
fmt.Println("XTCP")
|
||||||
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
tbl := table.New("Name", "Status", "LocalAddr", "Plugin", "RemoteAddr", "Error")
|
||||||
for _, ps := range res.XTCP {
|
for _, ps := range res.XTCP {
|
||||||
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
tbl.AddRow(ps.Name, ps.Status, ps.LocalAddr, ps.Plugin, ps.RemoteAddr, ps.Err)
|
||||||
|
@@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -45,7 +45,7 @@ var stcpCmd = &cobra.Command{
|
|||||||
Use: "stcp",
|
Use: "stcp",
|
||||||
Short: "Run frpc with a single stcp proxy",
|
Short: "Run frpc with a single stcp proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -45,7 +45,7 @@ var sudpCmd = &cobra.Command{
|
|||||||
Use: "sudp",
|
Use: "sudp",
|
||||||
Short: "Run frpc with a single sudp proxy",
|
Short: "Run frpc with a single sudp proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -41,7 +41,7 @@ var tcpCmd = &cobra.Command{
|
|||||||
Use: "tcp",
|
Use: "tcp",
|
||||||
Short: "Run frpc with a single tcp proxy",
|
Short: "Run frpc with a single tcp proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -44,7 +44,7 @@ var tcpMuxCmd = &cobra.Command{
|
|||||||
Use: "tcpmux",
|
Use: "tcpmux",
|
||||||
Short: "Run frpc with a single tcpmux proxy",
|
Short: "Run frpc with a single tcpmux proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -41,7 +41,7 @@ var udpCmd = &cobra.Command{
|
|||||||
Use: "udp",
|
Use: "udp",
|
||||||
Short: "Run frpc with a single udp proxy",
|
Short: "Run frpc with a single udp proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
43
cmd/frpc/sub/verify.go
Normal file
43
cmd/frpc/sub/verify.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2021 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(verifyCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var verifyCmd = &cobra.Command{
|
||||||
|
Use: "verify",
|
||||||
|
Short: "Verify that the configures is valid",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
_, _, _, err := config.ParseClientConfig(cfgFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("frpc: the configuration file %s syntax is ok\n", cfgFile)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -45,7 +45,7 @@ var xtcpCmd = &cobra.Command{
|
|||||||
Use: "xtcp",
|
Use: "xtcp",
|
||||||
Short: "Run frpc with a single xtcp proxy",
|
Short: "Run frpc with a single xtcp proxy",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
|
clientCfg, err := parseClientCommonCfgFromCmd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatedier/golib/crypto"
|
"github.com/fatedier/golib/crypto"
|
||||||
|
|
||||||
_ "github.com/fatedier/frp/assets/frps/statik"
|
_ "github.com/fatedier/frp/assets/frps"
|
||||||
_ "github.com/fatedier/frp/pkg/metrics"
|
_ "github.com/fatedier/frp/pkg/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -18,14 +18,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
"github.com/fatedier/frp/pkg/config"
|
"github.com/fatedier/frp/pkg/config"
|
||||||
"github.com/fatedier/frp/pkg/util/log"
|
"github.com/fatedier/frp/pkg/util/log"
|
||||||
"github.com/fatedier/frp/pkg/util/util"
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
"github.com/fatedier/frp/pkg/util/version"
|
"github.com/fatedier/frp/pkg/util/version"
|
||||||
"github.com/fatedier/frp/server"
|
"github.com/fatedier/frp/server"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -37,31 +37,31 @@ var (
|
|||||||
cfgFile string
|
cfgFile string
|
||||||
showVersion bool
|
showVersion bool
|
||||||
|
|
||||||
bindAddr string
|
bindAddr string
|
||||||
bindPort int
|
bindPort int
|
||||||
bindUDPPort int
|
bindUDPPort int
|
||||||
kcpBindPort int
|
kcpBindPort int
|
||||||
proxyBindAddr string
|
proxyBindAddr string
|
||||||
vhostHTTPPort int
|
vhostHTTPPort int
|
||||||
vhostHTTPSPort int
|
vhostHTTPSPort int
|
||||||
vhostHTTPTimeout int64
|
vhostHTTPTimeout int64
|
||||||
dashboardAddr string
|
dashboardAddr string
|
||||||
dashboardPort int
|
dashboardPort int
|
||||||
dashboardUser string
|
dashboardUser string
|
||||||
dashboardPwd string
|
dashboardPwd string
|
||||||
enablePrometheus bool
|
enablePrometheus bool
|
||||||
assetsDir string
|
logFile string
|
||||||
logFile string
|
logLevel string
|
||||||
logLevel string
|
logMaxDays int64
|
||||||
logMaxDays int64
|
disableLogColor bool
|
||||||
disableLogColor bool
|
token string
|
||||||
token string
|
subDomainHost string
|
||||||
subDomainHost string
|
allowPorts string
|
||||||
tcpMux bool
|
maxPortsPerClient int64
|
||||||
allowPorts string
|
tlsOnly bool
|
||||||
maxPoolCount int64
|
dashboardTLSMode bool
|
||||||
maxPortsPerClient int64
|
dashboardTLSCertFile string
|
||||||
tlsOnly bool
|
dashboardTLSKeyFile string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -91,6 +91,9 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&allowPorts, "allow_ports", "", "", "allow ports")
|
rootCmd.PersistentFlags().StringVarP(&allowPorts, "allow_ports", "", "", "allow ports")
|
||||||
rootCmd.PersistentFlags().Int64VarP(&maxPortsPerClient, "max_ports_per_client", "", 0, "max ports per client")
|
rootCmd.PersistentFlags().Int64VarP(&maxPortsPerClient, "max_ports_per_client", "", 0, "max ports per client")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&tlsOnly, "tls_only", "", false, "frps tls only")
|
rootCmd.PersistentFlags().BoolVarP(&tlsOnly, "tls_only", "", false, "frps tls only")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&dashboardTLSMode, "dashboard_tls_mode", "", false, "dashboard tls mode")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&dashboardTLSCertFile, "dashboard_tls_cert_file", "", "", "dashboard tls cert file")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&dashboardTLSKeyFile, "dashboard_tls_key_file", "", "", "dashboard tls key file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@@ -105,14 +108,14 @@ var rootCmd = &cobra.Command{
|
|||||||
var cfg config.ServerCommonConf
|
var cfg config.ServerCommonConf
|
||||||
var err error
|
var err error
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
var content string
|
var content []byte
|
||||||
content, err = config.GetRenderedConfFromFile(cfgFile)
|
content, err = config.GetRenderedConfFromFile(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
|
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
|
||||||
} else {
|
} else {
|
||||||
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, "")
|
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -133,31 +136,24 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseServerCommonCfg(fileType int, content string) (cfg config.ServerCommonConf, err error) {
|
func parseServerCommonCfg(fileType int, source []byte) (cfg config.ServerCommonConf, err error) {
|
||||||
if fileType == CfgFileTypeIni {
|
if fileType == CfgFileTypeIni {
|
||||||
cfg, err = parseServerCommonCfgFromIni(content)
|
cfg, err = config.UnmarshalServerConfFromIni(source)
|
||||||
} else if fileType == CfgFileTypeCmd {
|
} else if fileType == CfgFileTypeCmd {
|
||||||
cfg, err = parseServerCommonCfgFromCmd()
|
cfg, err = parseServerCommonCfgFromCmd()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cfg.Complete()
|
||||||
err = cfg.Check()
|
err = cfg.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("parse config error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseServerCommonCfgFromIni(content string) (config.ServerCommonConf, error) {
|
|
||||||
cfg, err := config.UnmarshalServerConfFromIni(content)
|
|
||||||
if err != nil {
|
|
||||||
return config.ServerCommonConf{}, err
|
|
||||||
}
|
|
||||||
return cfg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
||||||
cfg = config.GetDefaultServerConf()
|
cfg = config.GetDefaultServerConf()
|
||||||
|
|
||||||
@@ -174,6 +170,9 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
cfg.DashboardUser = dashboardUser
|
cfg.DashboardUser = dashboardUser
|
||||||
cfg.DashboardPwd = dashboardPwd
|
cfg.DashboardPwd = dashboardPwd
|
||||||
cfg.EnablePrometheus = enablePrometheus
|
cfg.EnablePrometheus = enablePrometheus
|
||||||
|
cfg.DashboardTLSCertFile = dashboardTLSCertFile
|
||||||
|
cfg.DashboardTLSKeyFile = dashboardTLSKeyFile
|
||||||
|
cfg.DashboardTLSMode = dashboardTLSMode
|
||||||
cfg.LogFile = logFile
|
cfg.LogFile = logFile
|
||||||
cfg.LogLevel = logLevel
|
cfg.LogLevel = logLevel
|
||||||
cfg.LogMaxDays = logMaxDays
|
cfg.LogMaxDays = logMaxDays
|
||||||
@@ -187,7 +186,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
// e.g. 1000-2000,2001,2002,3000-4000
|
// e.g. 1000-2000,2001,2002,3000-4000
|
||||||
ports, errRet := util.ParseRangeNumbers(allowPorts)
|
ports, errRet := util.ParseRangeNumbers(allowPorts)
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
err = fmt.Errorf("Parse conf error: allow_ports: %v", errRet)
|
err = fmt.Errorf("parse conf error: allow_ports: %v", errRet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,23 +195,24 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.MaxPortsPerClient = maxPortsPerClient
|
cfg.MaxPortsPerClient = maxPortsPerClient
|
||||||
|
|
||||||
if logFile == "console" {
|
|
||||||
cfg.LogWay = "console"
|
|
||||||
} else {
|
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
cfg.DisableLogColor = disableLogColor
|
cfg.DisableLogColor = disableLogColor
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func runServer(cfg config.ServerCommonConf) (err error) {
|
func runServer(cfg config.ServerCommonConf) (err error) {
|
||||||
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)
|
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)
|
||||||
|
|
||||||
|
if cfgFile != "" {
|
||||||
|
log.Info("frps uses config file: %s", cfgFile)
|
||||||
|
} else {
|
||||||
|
log.Info("frps uses command line arguments for config")
|
||||||
|
}
|
||||||
|
|
||||||
svr, err := server.NewService(cfg)
|
svr, err := server.NewService(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info("start frps success")
|
log.Info("frps started successfully")
|
||||||
svr.Run()
|
svr.Run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
53
cmd/frps/verify.go
Normal file
53
cmd/frps/verify.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2021 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(verifyCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var verifyCmd = &cobra.Command{
|
||||||
|
Use: "verify",
|
||||||
|
Short: "Verify that the configures is valid",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if cfgFile == "" {
|
||||||
|
fmt.Println("no config file is specified")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
iniContent, err := config.GetRenderedConfFromFile(cfgFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = parseServerCommonCfg(CfgFileTypeIni, iniContent)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("frps: the configuration file %s syntax is ok\n", cfgFile)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@@ -2,9 +2,17 @@
|
|||||||
[common]
|
[common]
|
||||||
# A literal address or host name for IPv6 must be enclosed
|
# A literal address or host name for IPv6 must be enclosed
|
||||||
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
|
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
|
||||||
|
# For single "server_addr" field, no need square brackets, like "server_addr = ::".
|
||||||
server_addr = 0.0.0.0
|
server_addr = 0.0.0.0
|
||||||
server_port = 7000
|
server_port = 7000
|
||||||
|
|
||||||
|
# The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
|
||||||
|
# dial_server_timeout = 10
|
||||||
|
|
||||||
|
# dial_server_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
|
||||||
|
# If negative, keep-alive probes are disabled.
|
||||||
|
# dial_server_keepalive = 7200
|
||||||
|
|
||||||
# if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set http_proxy here or in global environment variables
|
# if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set http_proxy here or in global environment variables
|
||||||
# it only works when protocol is tcp
|
# it only works when protocol is tcp
|
||||||
# http_proxy = http://user:passwd@192.168.1.128:8080
|
# http_proxy = http://user:passwd@192.168.1.128:8080
|
||||||
@@ -23,15 +31,41 @@ log_max_days = 3
|
|||||||
disable_log_color = false
|
disable_log_color = false
|
||||||
|
|
||||||
# for authentication, should be same as your frps.ini
|
# for authentication, should be same as your frps.ini
|
||||||
# AuthenticateHeartBeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
|
# authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
|
||||||
authenticate_heartbeats = false
|
authenticate_heartbeats = false
|
||||||
|
|
||||||
# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
|
# authenticate_new_work_conns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
|
||||||
authenticate_new_work_conns = false
|
authenticate_new_work_conns = false
|
||||||
|
|
||||||
# auth token
|
# auth token
|
||||||
token = 12345678
|
token = 12345678
|
||||||
|
|
||||||
|
authentication_method =
|
||||||
|
|
||||||
|
# oidc_client_id specifies the client ID to use to get a token in OIDC authentication if AuthenticationMethod == "oidc".
|
||||||
|
# By default, this value is "".
|
||||||
|
oidc_client_id =
|
||||||
|
|
||||||
|
# oidc_client_secret specifies the client secret to use to get a token in OIDC authentication if AuthenticationMethod == "oidc".
|
||||||
|
# By default, this value is "".
|
||||||
|
oidc_client_secret =
|
||||||
|
|
||||||
|
# oidc_audience specifies the audience of the token in OIDC authentication if AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
|
oidc_audience =
|
||||||
|
|
||||||
|
# oidc_scope specifies the permisssions of the token in OIDC authentication if AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
|
oidc_scope =
|
||||||
|
|
||||||
|
# oidc_token_endpoint_url specifies the URL which implements OIDC Token Endpoint.
|
||||||
|
# It will be used to get an OIDC token if AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
|
oidc_token_endpoint_url =
|
||||||
|
|
||||||
|
# oidc_additional_xxx specifies additional parameters to be sent to the OIDC Token Endpoint.
|
||||||
|
# For example, if you want to specify the "audience" parameter, you can set as follow.
|
||||||
|
# frp will add "audience=<value>" "var1=<value>" to the additional parameters.
|
||||||
|
# oidc_additional_audience = https://dev.auth.com/api/v2/
|
||||||
|
# oidc_additional_var1 = foobar
|
||||||
|
|
||||||
# set admin address for control frpc's action by http api such as reload
|
# set admin address for control frpc's action by http api such as reload
|
||||||
admin_addr = 127.0.0.1
|
admin_addr = 127.0.0.1
|
||||||
admin_port = 7400
|
admin_port = 7400
|
||||||
@@ -44,7 +78,11 @@ admin_pwd = admin
|
|||||||
pool_count = 5
|
pool_count = 5
|
||||||
|
|
||||||
# if tcp stream multiplexing is used, default is true, it must be same with frps
|
# if tcp stream multiplexing is used, default is true, it must be same with frps
|
||||||
tcp_mux = true
|
# tcp_mux = true
|
||||||
|
|
||||||
|
# specify keep alive interval for tcp mux.
|
||||||
|
# only valid if tcp_mux is true.
|
||||||
|
# tcp_mux_keepalive_interval = 60
|
||||||
|
|
||||||
# your proxy name will be changed to {user}.{proxy}
|
# your proxy name will be changed to {user}.{proxy}
|
||||||
user = your_name
|
user = your_name
|
||||||
@@ -54,25 +92,36 @@ user = your_name
|
|||||||
login_fail_exit = true
|
login_fail_exit = true
|
||||||
|
|
||||||
# communication protocol used to connect to server
|
# communication protocol used to connect to server
|
||||||
# now it supports tcp, kcp and websocket, default is tcp
|
# supports tcp, kcp, quic and websocket now, default is tcp
|
||||||
protocol = tcp
|
protocol = tcp
|
||||||
|
|
||||||
|
# set client binding ip when connect server, default is empty.
|
||||||
|
# only when protocol = tcp or websocket, the value will be used.
|
||||||
|
connect_server_local_ip = 0.0.0.0
|
||||||
|
|
||||||
|
# quic protocol options
|
||||||
|
# quic_keepalive_period = 10
|
||||||
|
# quic_max_idle_timeout = 30
|
||||||
|
# quic_max_incoming_streams = 100000
|
||||||
|
|
||||||
# if tls_enable is true, frpc will connect frps by tls
|
# if tls_enable is true, frpc will connect frps by tls
|
||||||
tls_enable = true
|
tls_enable = true
|
||||||
|
|
||||||
# tls_cert_file = client.crt
|
# tls_cert_file = client.crt
|
||||||
# tls_key_file = client.key
|
# tls_key_file = client.key
|
||||||
# tls_trusted_ca_file = ca.crt
|
# tls_trusted_ca_file = ca.crt
|
||||||
|
# tls_server_name = example.com
|
||||||
|
|
||||||
# specify a dns server, so frpc will use this instead of default one
|
# specify a dns server, so frpc will use this instead of default one
|
||||||
# dns_server = 8.8.8.8
|
# dns_server = 8.8.8.8
|
||||||
|
|
||||||
# proxy names you want to start seperated by ','
|
# proxy names you want to start separated by ','
|
||||||
# default is empty, means all proxies
|
# default is empty, means all proxies
|
||||||
# start = ssh,dns
|
# start = ssh,dns
|
||||||
|
|
||||||
# heartbeat configure, it's not recommended to modify the default value
|
# heartbeat configure, it's not recommended to modify the default value
|
||||||
# the default value of heartbeat_interval is 10 and heartbeat_timeout is 90
|
# The default value of heartbeat_interval is 10 and heartbeat_timeout is 90. Set negative value
|
||||||
|
# to disable it.
|
||||||
# heartbeat_interval = 30
|
# heartbeat_interval = 30
|
||||||
# heartbeat_timeout = 90
|
# heartbeat_timeout = 90
|
||||||
|
|
||||||
@@ -85,6 +134,17 @@ meta_var2 = 234
|
|||||||
# It affects the udp and sudp proxy.
|
# It affects the udp and sudp proxy.
|
||||||
udp_packet_size = 1500
|
udp_packet_size = 1500
|
||||||
|
|
||||||
|
# include other config files for proxies.
|
||||||
|
# includes = ./confd/*.ini
|
||||||
|
|
||||||
|
# By default, frpc will connect frps with first custom byte if tls is enabled.
|
||||||
|
# If DisableCustomTLSFirstByte is true, frpc will not send that custom byte.
|
||||||
|
disable_custom_tls_first_byte = false
|
||||||
|
|
||||||
|
# Enable golang pprof handlers in admin listener.
|
||||||
|
# Admin port must be set first.
|
||||||
|
pprof_enable = false
|
||||||
|
|
||||||
# 'ssh' is the unique proxy name
|
# 'ssh' is the unique proxy name
|
||||||
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
|
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
|
||||||
[ssh]
|
[ssh]
|
||||||
@@ -161,11 +221,13 @@ use_compression = true
|
|||||||
# if not set, you can access this custom_domains without certification
|
# if not set, you can access this custom_domains without certification
|
||||||
http_user = admin
|
http_user = admin
|
||||||
http_pwd = admin
|
http_pwd = admin
|
||||||
# if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.com
|
# if domain for frps is frps.com, then you can access [web01] proxy by URL http://web01.frps.com
|
||||||
subdomain = web01
|
subdomain = web01
|
||||||
custom_domains = web02.yourdomain.com
|
custom_domains = web01.yourdomain.com
|
||||||
# locations is only available for http type
|
# locations is only available for http type
|
||||||
locations = /,/pic
|
locations = /,/pic
|
||||||
|
# route requests to this service if http basic auto user is abc
|
||||||
|
# route_by_http_user = abc
|
||||||
host_header_rewrite = example.com
|
host_header_rewrite = example.com
|
||||||
# params with prefix "header_" will be used to update http request headers
|
# params with prefix "header_" will be used to update http request headers
|
||||||
header_X-From-Where = frp
|
header_X-From-Where = frp
|
||||||
@@ -231,6 +293,16 @@ plugin_key_path = ./server.key
|
|||||||
plugin_host_header_rewrite = 127.0.0.1
|
plugin_host_header_rewrite = 127.0.0.1
|
||||||
plugin_header_X-From-Where = frp
|
plugin_header_X-From-Where = frp
|
||||||
|
|
||||||
|
[plugin_https2https]
|
||||||
|
type = https
|
||||||
|
custom_domains = test.yourdomain.com
|
||||||
|
plugin = https2https
|
||||||
|
plugin_local_addr = 127.0.0.1:443
|
||||||
|
plugin_crt_path = ./server.crt
|
||||||
|
plugin_key_path = ./server.key
|
||||||
|
plugin_host_header_rewrite = 127.0.0.1
|
||||||
|
plugin_header_X-From-Where = frp
|
||||||
|
|
||||||
[plugin_http2https]
|
[plugin_http2https]
|
||||||
type = http
|
type = http
|
||||||
custom_domains = test.yourdomain.com
|
custom_domains = test.yourdomain.com
|
||||||
@@ -288,3 +360,4 @@ multiplexer = httpconnect
|
|||||||
local_ip = 127.0.0.1
|
local_ip = 127.0.0.1
|
||||||
local_port = 10701
|
local_port = 10701
|
||||||
custom_domains = tunnel1
|
custom_domains = tunnel1
|
||||||
|
# route_by_http_user = user1
|
||||||
|
@@ -2,16 +2,25 @@
|
|||||||
[common]
|
[common]
|
||||||
# A literal address or host name for IPv6 must be enclosed
|
# A literal address or host name for IPv6 must be enclosed
|
||||||
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
|
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
|
||||||
|
# For single "bind_addr" field, no need square brackets, like "bind_addr = ::".
|
||||||
bind_addr = 0.0.0.0
|
bind_addr = 0.0.0.0
|
||||||
bind_port = 7000
|
bind_port = 7000
|
||||||
|
|
||||||
# udp port to help make udp hole to penetrate nat
|
# udp port to help make udp hole to penetrate nat
|
||||||
bind_udp_port = 7001
|
bind_udp_port = 7001
|
||||||
|
|
||||||
# udp port used for kcp protocol, it can be same with 'bind_port'
|
# udp port used for kcp protocol, it can be same with 'bind_port'.
|
||||||
# if not set, kcp is disabled in frps
|
# if not set, kcp is disabled in frps.
|
||||||
kcp_bind_port = 7000
|
kcp_bind_port = 7000
|
||||||
|
|
||||||
|
# udp port used for quic protocol.
|
||||||
|
# if not set, quic is disabled in frps.
|
||||||
|
# quic_bind_port = 7002
|
||||||
|
# quic protocol options
|
||||||
|
# quic_keepalive_period = 10
|
||||||
|
# quic_max_idle_timeout = 30
|
||||||
|
# quic_max_incoming_streams = 100000
|
||||||
|
|
||||||
# specify which address proxy will listen for, default value is same with bind_addr
|
# specify which address proxy will listen for, default value is same with bind_addr
|
||||||
# proxy_bind_addr = 127.0.0.1
|
# proxy_bind_addr = 127.0.0.1
|
||||||
|
|
||||||
@@ -23,27 +32,36 @@ vhost_https_port = 443
|
|||||||
# response header timeout(seconds) for vhost http server, default is 60s
|
# response header timeout(seconds) for vhost http server, default is 60s
|
||||||
# vhost_http_timeout = 60
|
# vhost_http_timeout = 60
|
||||||
|
|
||||||
# TcpMuxHttpConnectPort specifies the port that the server listens for TCP
|
# tcpmux_httpconnect_port specifies the port that the server listens for TCP
|
||||||
# HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
|
# HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
|
||||||
# requests on one single port. If it's not - it will listen on this value for
|
# requests on one single port. If it's not - it will listen on this value for
|
||||||
# HTTP CONNECT requests. By default, this value is 0.
|
# HTTP CONNECT requests. By default, this value is 0.
|
||||||
# tcpmux_httpconnect_port = 1337
|
# tcpmux_httpconnect_port = 1337
|
||||||
|
|
||||||
|
# If tcpmux_passthrough is true, frps won't do any update on traffic.
|
||||||
|
# tcpmux_passthrough = false
|
||||||
|
|
||||||
# set dashboard_addr and dashboard_port to view dashboard of frps
|
# set dashboard_addr and dashboard_port to view dashboard of frps
|
||||||
# dashboard_addr's default value is same with bind_addr
|
# dashboard_addr's default value is same with bind_addr
|
||||||
# dashboard is available only if dashboard_port is set
|
# dashboard is available only if dashboard_port is set
|
||||||
dashboard_addr = 0.0.0.0
|
dashboard_addr = 0.0.0.0
|
||||||
dashboard_port = 7500
|
dashboard_port = 7500
|
||||||
|
|
||||||
# dashboard user and passwd for basic auth protect, if not set, both default value is admin
|
# dashboard user and passwd for basic auth protect
|
||||||
dashboard_user = admin
|
dashboard_user = admin
|
||||||
dashboard_pwd = admin
|
dashboard_pwd = admin
|
||||||
|
|
||||||
|
# dashboard TLS mode
|
||||||
|
dashboard_tls_mode = false
|
||||||
|
# dashboard_tls_cert_file = server.crt
|
||||||
|
# dashboard_tls_key_file = server.key
|
||||||
|
|
||||||
# enable_prometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port} in /metrics api.
|
# enable_prometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port} in /metrics api.
|
||||||
enable_prometheus = true
|
enable_prometheus = true
|
||||||
|
|
||||||
# dashboard assets directory(only for debug mode)
|
# dashboard assets directory(only for debug mode)
|
||||||
# assets_dir = ./static
|
# assets_dir = ./static
|
||||||
|
|
||||||
# console or real logFile path like ./frps.log
|
# console or real logFile path like ./frps.log
|
||||||
log_file = ./frps.log
|
log_file = ./frps.log
|
||||||
|
|
||||||
@@ -58,12 +76,12 @@ disable_log_color = false
|
|||||||
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
||||||
detailed_errors_to_client = true
|
detailed_errors_to_client = true
|
||||||
|
|
||||||
# AuthenticationMethod specifies what authentication method to use authenticate frpc with frps.
|
# authentication_method specifies what authentication method to use authenticate frpc with frps.
|
||||||
# If "token" is specified - token will be read into login message.
|
# If "token" is specified - token will be read into login message.
|
||||||
# If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token".
|
# If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token".
|
||||||
authentication_method = token
|
authentication_method = token
|
||||||
|
|
||||||
# AuthenticateHeartBeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
|
# authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
|
||||||
authenticate_heartbeats = false
|
authenticate_heartbeats = false
|
||||||
|
|
||||||
# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
|
# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
|
||||||
@@ -72,25 +90,30 @@ authenticate_new_work_conns = false
|
|||||||
# auth token
|
# auth token
|
||||||
token = 12345678
|
token = 12345678
|
||||||
|
|
||||||
# OidcClientId specifies the client ID to use to get a token in OIDC authentication if AuthenticationMethod == "oidc".
|
# oidc_issuer specifies the issuer to verify OIDC tokens with.
|
||||||
# By default, this value is "".
|
# By default, this value is "".
|
||||||
oidc_client_id =
|
oidc_issuer =
|
||||||
|
|
||||||
# OidcClientSecret specifies the client secret to use to get a token in OIDC authentication if AuthenticationMethod == "oidc".
|
# oidc_audience specifies the audience OIDC tokens should contain when validated.
|
||||||
# By default, this value is "".
|
# By default, this value is "".
|
||||||
oidc_client_secret =
|
oidc_audience =
|
||||||
|
|
||||||
# OidcAudience specifies the audience of the token in OIDC authentication if AuthenticationMethod == "oidc". By default, this value is "".
|
# oidc_skip_expiry_check specifies whether to skip checking if the OIDC token is expired.
|
||||||
oidc_audience =
|
# By default, this value is false.
|
||||||
|
oidc_skip_expiry_check = false
|
||||||
|
|
||||||
# OidcTokenEndpointUrl specifies the URL which implements OIDC Token Endpoint.
|
# oidc_skip_issuer_check specifies whether to skip checking if the OIDC token's issuer claim matches the issuer specified in OidcIssuer.
|
||||||
# It will be used to get an OIDC token if AuthenticationMethod == "oidc". By default, this value is "".
|
# By default, this value is false.
|
||||||
oidc_token_endpoint_url =
|
oidc_skip_issuer_check = false
|
||||||
|
|
||||||
# heartbeat configure, it's not recommended to modify the default value
|
# heartbeat configure, it's not recommended to modify the default value
|
||||||
# the default value of heartbeat_timeout is 90
|
# the default value of heartbeat_timeout is 90. Set negative value to disable it.
|
||||||
# heartbeat_timeout = 90
|
# heartbeat_timeout = 90
|
||||||
|
|
||||||
|
# user_conn_timeout configure, it's not recommended to modify the default value
|
||||||
|
# the default value of user_conn_timeout is 10
|
||||||
|
# user_conn_timeout = 10
|
||||||
|
|
||||||
# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
|
# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
|
||||||
allow_ports = 2000-3000,3001,3003,4000-50000
|
allow_ports = 2000-3000,3001,3003,4000-50000
|
||||||
|
|
||||||
@@ -100,7 +123,7 @@ max_pool_count = 5
|
|||||||
# max ports can be used for each client, default value is 0 means no limit
|
# max ports can be used for each client, default value is 0 means no limit
|
||||||
max_ports_per_client = 0
|
max_ports_per_client = 0
|
||||||
|
|
||||||
# TlsOnly specifies whether to only accept TLS-encrypted connections. By default, the value is false.
|
# tls_only specifies whether to only accept TLS-encrypted connections. By default, the value is false.
|
||||||
tls_only = false
|
tls_only = false
|
||||||
|
|
||||||
# tls_cert_file = server.crt
|
# tls_cert_file = server.crt
|
||||||
@@ -112,7 +135,15 @@ tls_only = false
|
|||||||
subdomain_host = frps.com
|
subdomain_host = frps.com
|
||||||
|
|
||||||
# if tcp stream multiplexing is used, default is true
|
# if tcp stream multiplexing is used, default is true
|
||||||
tcp_mux = true
|
# tcp_mux = true
|
||||||
|
|
||||||
|
# specify keep alive interval for tcp mux.
|
||||||
|
# only valid if tcp_mux is true.
|
||||||
|
# tcp_mux_keepalive_interval = 60
|
||||||
|
|
||||||
|
# tcp_keepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
|
||||||
|
# If negative, keep-alive probes are disabled.
|
||||||
|
# tcp_keepalive = 7200
|
||||||
|
|
||||||
# custom 404 page for HTTP requests
|
# custom 404 page for HTTP requests
|
||||||
# custom_404_page = /path/to/404.html
|
# custom_404_page = /path/to/404.html
|
||||||
@@ -122,6 +153,10 @@ tcp_mux = true
|
|||||||
# It affects the udp and sudp proxy.
|
# It affects the udp and sudp proxy.
|
||||||
udp_packet_size = 1500
|
udp_packet_size = 1500
|
||||||
|
|
||||||
|
# Enable golang pprof handlers in dashboard listener.
|
||||||
|
# Dashboard port must be set first
|
||||||
|
pprof_enable = false
|
||||||
|
|
||||||
[plugin.user-manager]
|
[plugin.user-manager]
|
||||||
addr = 127.0.0.1:9000
|
addr = 127.0.0.1:9000
|
||||||
path = /handler
|
path = /handler
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Frp Client Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=nobody
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5s
|
|
||||||
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini
|
|
||||||
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@@ -1,14 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Frp Client Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=idle
|
|
||||||
User=nobody
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5s
|
|
||||||
ExecStart=/usr/bin/frpc -c /etc/frp/%i.ini
|
|
||||||
ExecReload=/usr/bin/frpc reload -c /etc/frp/%i.ini
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@@ -1,13 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Frp Server Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=nobody
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5s
|
|
||||||
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@@ -1,13 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Frp Server Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=nobody
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5s
|
|
||||||
ExecStart=/usr/bin/frps -c /etc/frp/%i.ini
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
BIN
doc/pic/sponsor_doppler.png
Normal file
BIN
doc/pic/sponsor_doppler.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
BIN
doc/pic/sponsor_workos.png
Normal file
BIN
doc/pic/sponsor_workos.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
@@ -70,7 +70,7 @@ The response can look like any of the following:
|
|||||||
|
|
||||||
### Operation
|
### Operation
|
||||||
|
|
||||||
Currently `Login`, `NewProxy`, `Ping`, `NewWorkConn` and `NewUserConn` operations are supported.
|
Currently `Login`, `NewProxy`, `CloseProxy`, `Ping`, `NewWorkConn` and `NewUserConn` operations are supported.
|
||||||
|
|
||||||
#### Login
|
#### Login
|
||||||
|
|
||||||
@@ -88,7 +88,8 @@ Client login operation
|
|||||||
"privilege_key": <string>,
|
"privilege_key": <string>,
|
||||||
"run_id": <string>,
|
"run_id": <string>,
|
||||||
"pool_count": <int>,
|
"pool_count": <int>,
|
||||||
"metas": map<string>string
|
"metas": map<string>string,
|
||||||
|
"client_address": <string>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -135,6 +136,26 @@ Create new proxy
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### CloseProxy
|
||||||
|
|
||||||
|
A previously created proxy is closed.
|
||||||
|
|
||||||
|
Please note that one request will be sent for every proxy that is closed, do **NOT** use this
|
||||||
|
if you have too many proxies bound to a single client, as this may exhaust the server's resources.
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"user": {
|
||||||
|
"user": <string>,
|
||||||
|
"metas": map<string>string
|
||||||
|
"run_id": <string>
|
||||||
|
},
|
||||||
|
"proxy_name": <string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### Ping
|
#### Ping
|
||||||
|
|
||||||
Heartbeat from frpc
|
Heartbeat from frpc
|
||||||
@@ -209,9 +230,10 @@ path = /handler
|
|||||||
ops = NewProxy
|
ops = NewProxy
|
||||||
```
|
```
|
||||||
|
|
||||||
addr: the address where the external RPC service listens on.
|
- addr: the address where the external RPC service listens. Defaults to http. For https, specify the schema: `addr = https://127.0.0.1:9001`.
|
||||||
path: http request url path for the POST request.
|
- path: http request url path for the POST request.
|
||||||
ops: operations plugin needs to handle (e.g. "Login", "NewProxy", ...).
|
- ops: operations plugin needs to handle (e.g. "Login", "NewProxy", ...).
|
||||||
|
- tls_verify: When the schema is https, we verify by default. Set this value to false if you want to skip verification.
|
||||||
|
|
||||||
### Metadata
|
### Metadata
|
||||||
|
|
||||||
|
@@ -1,228 +0,0 @@
|
|||||||
### 服务端管理插件
|
|
||||||
|
|
||||||
frp 管理插件的作用是在不侵入自身代码的前提下,扩展 frp 服务端的能力。
|
|
||||||
|
|
||||||
frp 管理插件会以单独进程的形式运行,并且监听在一个端口上,对外提供 RPC 接口,响应 frps 的请求。
|
|
||||||
|
|
||||||
frps 在执行某些操作前,会根据配置向管理插件发送 RPC 请求,根据管理插件的响应来执行相应的操作。
|
|
||||||
|
|
||||||
### RPC 请求
|
|
||||||
|
|
||||||
管理插件接收到操作请求后,可以给出三种回应。
|
|
||||||
|
|
||||||
* 拒绝操作,需要返回拒绝操作的原因。
|
|
||||||
* 允许操作,不需要修改操作内容。
|
|
||||||
* 允许操作,对操作请求进行修改后,返回修改后的内容。
|
|
||||||
|
|
||||||
### 接口
|
|
||||||
|
|
||||||
接口路径可以在 frps 配置中为每个插件单独配置,这里以 `/handler` 为例。
|
|
||||||
|
|
||||||
Request
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /handler
|
|
||||||
{
|
|
||||||
"version": "0.1.0",
|
|
||||||
"op": "Login",
|
|
||||||
"content": {
|
|
||||||
... // 具体的操作信息
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
请求 Header
|
|
||||||
X-Frp-Reqid: 用于追踪请求
|
|
||||||
```
|
|
||||||
|
|
||||||
Response
|
|
||||||
|
|
||||||
非 200 的返回都认为是请求异常。
|
|
||||||
|
|
||||||
拒绝执行操作
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"reject": true,
|
|
||||||
"reject_reason": "invalid user"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
允许且内容不需要变动
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"reject": false,
|
|
||||||
"unchange": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
允许且需要替换操作内容
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"unchange": "false",
|
|
||||||
"content": {
|
|
||||||
... // 替换后的操作信息,格式必须和请求时的一致
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 操作类型
|
|
||||||
|
|
||||||
目前插件支持管理的操作类型有 `Login`、`NewProxy`、`Ping`、`NewWorkConn` 和 `NewUserConn`。
|
|
||||||
|
|
||||||
#### Login
|
|
||||||
|
|
||||||
用户登录操作信息
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"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
|
|
||||||
|
|
||||||
创建代理的相关信息
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Ping
|
|
||||||
|
|
||||||
心跳相关信息
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"user": {
|
|
||||||
"user": <string>,
|
|
||||||
"metas": map<string>string
|
|
||||||
"run_id": <string>
|
|
||||||
},
|
|
||||||
"timestamp": <int64>,
|
|
||||||
"privilege_key": <string>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### NewWorkConn
|
|
||||||
|
|
||||||
新增 `frpc` 连接相关信息
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"user": {
|
|
||||||
"user": <string>,
|
|
||||||
"metas": map<string>string
|
|
||||||
"run_id": <string>
|
|
||||||
},
|
|
||||||
"run_id": <string>
|
|
||||||
"timestamp": <int64>,
|
|
||||||
"privilege_key": <string>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### NewUserConn
|
|
||||||
|
|
||||||
新增 `proxy` 连接相关信息 (支持 `tcp`、`stcp`、`https` 和 `tcpmux` 协议)。
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"user": {
|
|
||||||
"user": <string>,
|
|
||||||
"metas": map<string>string
|
|
||||||
"run_id": <string>
|
|
||||||
},
|
|
||||||
"proxy_name": <string>,
|
|
||||||
"proxy_type": <string>,
|
|
||||||
"remote_addr": <string>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### frps 中插件配置
|
|
||||||
|
|
||||||
```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: 插件监听的网络地址。
|
|
||||||
path: 插件监听的 HTTP 请求路径。
|
|
||||||
ops: 插件需要处理的操作列表,多个 op 以英文逗号分隔。
|
|
||||||
|
|
||||||
### 元数据
|
|
||||||
|
|
||||||
为了减少 frps 的代码修改,同时提高管理插件的扩展能力,在 frpc 的配置文件中引入自定义元数据的概念。元数据会在调用 RPC 请求时发送给插件。
|
|
||||||
|
|
||||||
元数据以 `meta_` 开头,可以配置多个,元数据分为两种,一种配置在 `common` 下,一种配置在各个 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
|
|
||||||
```
|
|
@@ -1,14 +1,12 @@
|
|||||||
FROM alpine:3.12.0 AS temp
|
FROM golang:1.19 AS building
|
||||||
|
|
||||||
COPY bin/frpc /tmp
|
COPY . /building
|
||||||
|
WORKDIR /building
|
||||||
|
|
||||||
RUN chmod -R 777 /tmp/frpc
|
RUN make frpc
|
||||||
|
|
||||||
|
FROM alpine:3
|
||||||
|
|
||||||
FROM alpine:3.12.0
|
COPY --from=building /building/bin/frpc /usr/bin/frpc
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=temp /tmp/frpc /usr/bin
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/frpc"]
|
ENTRYPOINT ["/usr/bin/frpc"]
|
||||||
|
@@ -1,14 +1,12 @@
|
|||||||
FROM alpine:3.12.0 AS temp
|
FROM golang:1.19 AS building
|
||||||
|
|
||||||
COPY bin/frps /tmp
|
COPY . /building
|
||||||
|
WORKDIR /building
|
||||||
|
|
||||||
RUN chmod -R 777 /tmp/frps
|
RUN make frps
|
||||||
|
|
||||||
|
FROM alpine:3
|
||||||
|
|
||||||
FROM alpine:3.12.0
|
COPY --from=building /building/bin/frps /usr/bin/frps
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=temp /tmp/frps /usr/bin
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/frps"]
|
ENTRYPOINT ["/usr/bin/frps"]
|
||||||
|
99
go.mod
99
go.mod
@@ -1,39 +1,76 @@
|
|||||||
module github.com/fatedier/frp
|
module github.com/fatedier/frp
|
||||||
|
|
||||||
go 1.15
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
||||||
github.com/coreos/go-oidc v2.2.1+incompatible
|
github.com/coreos/go-oidc/v3 v3.4.0
|
||||||
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
|
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
|
||||||
github.com/fatedier/golib v0.1.1-0.20200901083111-1f870741e185
|
github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac
|
||||||
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
|
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
|
||||||
github.com/google/uuid v1.1.1
|
github.com/go-playground/validator/v10 v10.11.0
|
||||||
github.com/gorilla/mux v1.7.3
|
github.com/google/uuid v1.3.0
|
||||||
github.com/gorilla/websocket v1.4.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/hashicorp/yamux v0.1.1
|
||||||
github.com/klauspost/cpuid v1.2.0 // indirect
|
github.com/lucas-clemente/quic-go v0.31.0
|
||||||
github.com/klauspost/reedsolomon v1.9.1 // indirect
|
github.com/onsi/ginkgo v1.16.4
|
||||||
github.com/mattn/go-runewidth v0.0.4 // indirect
|
github.com/onsi/gomega v1.20.2
|
||||||
github.com/onsi/ginkgo v1.12.3
|
github.com/pires/go-proxyproto v0.6.2
|
||||||
github.com/onsi/gomega v1.10.1
|
github.com/prometheus/client_golang v1.13.0
|
||||||
github.com/pires/go-proxyproto v0.0.0-20190111085350-4d51b51e3bfc
|
github.com/rodaine/table v1.0.1
|
||||||
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
|
github.com/spf13/cobra v1.1.3
|
||||||
github.com/prometheus/client_golang v1.4.1
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/rakyll/statik v0.1.1
|
golang.org/x/net v0.4.0
|
||||||
github.com/rodaine/table v1.0.0
|
golang.org/x/oauth2 v0.3.0
|
||||||
github.com/spf13/cobra v0.0.3
|
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
|
||||||
github.com/stretchr/testify v1.4.0
|
gopkg.in/ini.v1 v1.67.0
|
||||||
github.com/templexxx/cpufeat v0.0.0-20170927014610-3794dfbfb047 // indirect
|
k8s.io/apimachinery v0.25.0
|
||||||
github.com/templexxx/xor v0.0.0-20170926022130-0af8e873c554 // indirect
|
k8s.io/client-go v0.25.0
|
||||||
github.com/tjfoc/gmsm v0.0.0-20171124023159-98aa888b79d8 // indirect
|
)
|
||||||
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec
|
|
||||||
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect
|
require (
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
|
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
k8s.io/apimachinery v0.18.3
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||||
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
github.com/golang/snappy v0.0.3 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.8 // indirect
|
||||||
|
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.6 // indirect
|
||||||
|
github.com/klauspost/reedsolomon v1.9.15 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/marten-seemann/qtls-go1-18 v0.1.3 // indirect
|
||||||
|
github.com/marten-seemann/qtls-go1-19 v0.1.1 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/nxadm/tail v1.4.8 // indirect
|
||||||
|
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
||||||
|
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
||||||
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
|
golang.org/x/crypto v0.4.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
|
golang.org/x/sys v0.3.0 // indirect
|
||||||
|
golang.org/x/text v0.5.0 // indirect
|
||||||
|
golang.org/x/tools v0.1.12 // indirect
|
||||||
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
|
||||||
)
|
)
|
||||||
|
@@ -5,11 +5,16 @@ ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
|
|||||||
which ginkgo &> /dev/null
|
which ginkgo &> /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ginkgo not found, try to install..."
|
echo "ginkgo not found, try to install..."
|
||||||
go get -u github.com/onsi/ginkgo/ginkgo
|
go install github.com/onsi/ginkgo/ginkgo@v1.16.5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
debug=false
|
debug=false
|
||||||
if [ x${DEBUG} == x"true" ]; then
|
if [ x${DEBUG} == x"true" ]; then
|
||||||
debug=true
|
debug=true
|
||||||
fi
|
fi
|
||||||
ginkgo -nodes=4 ${ROOT}/test/e2e -- -frpc-path=${ROOT}/bin/frpc -frps-path=${ROOT}/bin/frps -log-level=debug -debug=${debug}
|
logLevel=debug
|
||||||
|
if [ x${LOG_LEVEL} != x"" ]; then
|
||||||
|
logLevel=${LOG_LEVEL}
|
||||||
|
fi
|
||||||
|
|
||||||
|
ginkgo -nodes=8 -slowSpecThreshold=20 ${ROOT}/test/e2e -- -frpc-path=${ROOT}/bin/frpc -frps-path=${ROOT}/bin/frps -log-level=${logLevel} -debug=${debug}
|
||||||
|
@@ -15,7 +15,7 @@ rm -rf ./release/packages
|
|||||||
mkdir -p ./release/packages
|
mkdir -p ./release/packages
|
||||||
|
|
||||||
os_all='linux windows darwin freebsd'
|
os_all='linux windows darwin freebsd'
|
||||||
arch_all='386 amd64 arm arm64 mips64 mips64le mips mipsle'
|
arch_all='386 amd64 arm arm64 mips64 mips64le mips mipsle riscv64'
|
||||||
|
|
||||||
cd ./release
|
cd ./release
|
||||||
|
|
||||||
|
@@ -19,101 +19,58 @@ import (
|
|||||||
|
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
|
|
||||||
"github.com/vaughan0/go-ini"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type baseConfig struct {
|
type BaseConfig struct {
|
||||||
// AuthenticationMethod specifies what authentication method to use to
|
// AuthenticationMethod specifies what authentication method to use to
|
||||||
// authenticate frpc with frps. If "token" is specified - token will be
|
// authenticate frpc with frps. If "token" is specified - token will be
|
||||||
// read into login message. If "oidc" is specified - OIDC (Open ID Connect)
|
// read into login message. If "oidc" is specified - OIDC (Open ID Connect)
|
||||||
// token will be issued using OIDC settings. By default, this value is "token".
|
// token will be issued using OIDC settings. By default, this value is "token".
|
||||||
AuthenticationMethod string `json:"authentication_method"`
|
AuthenticationMethod string `ini:"authentication_method" json:"authentication_method"`
|
||||||
// AuthenticateHeartBeats specifies whether to include authentication token in
|
// AuthenticateHeartBeats specifies whether to include authentication token in
|
||||||
// heartbeats sent to frps. By default, this value is false.
|
// heartbeats sent to frps. By default, this value is false.
|
||||||
AuthenticateHeartBeats bool `json:"authenticate_heartbeats"`
|
AuthenticateHeartBeats bool `ini:"authenticate_heartbeats" json:"authenticate_heartbeats"`
|
||||||
// AuthenticateNewWorkConns specifies whether to include authentication token in
|
// AuthenticateNewWorkConns specifies whether to include authentication token in
|
||||||
// new work connections sent to frps. By default, this value is false.
|
// new work connections sent to frps. By default, this value is false.
|
||||||
AuthenticateNewWorkConns bool `json:"authenticate_new_work_conns"`
|
AuthenticateNewWorkConns bool `ini:"authenticate_new_work_conns" json:"authenticate_new_work_conns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultBaseConf() baseConfig {
|
func getDefaultBaseConf() BaseConfig {
|
||||||
return baseConfig{
|
return BaseConfig{
|
||||||
AuthenticationMethod: "token",
|
AuthenticationMethod: "token",
|
||||||
AuthenticateHeartBeats: false,
|
AuthenticateHeartBeats: false,
|
||||||
AuthenticateNewWorkConns: false,
|
AuthenticateNewWorkConns: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalBaseConfFromIni(conf ini.File) baseConfig {
|
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
|
|
||||||
cfg := getDefaultBaseConf()
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "authentication_method"); ok {
|
|
||||||
cfg.AuthenticationMethod = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "authenticate_heartbeats"); ok && tmpStr == "true" {
|
|
||||||
cfg.AuthenticateHeartBeats = true
|
|
||||||
} else {
|
|
||||||
cfg.AuthenticateHeartBeats = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "authenticate_new_work_conns"); ok && tmpStr == "true" {
|
|
||||||
cfg.AuthenticateNewWorkConns = true
|
|
||||||
} else {
|
|
||||||
cfg.AuthenticateNewWorkConns = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type ClientConfig struct {
|
type ClientConfig struct {
|
||||||
baseConfig
|
BaseConfig `ini:",extends"`
|
||||||
oidcClientConfig
|
OidcClientConfig `ini:",extends"`
|
||||||
tokenConfig
|
TokenConfig `ini:",extends"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultClientConf() ClientConfig {
|
func GetDefaultClientConf() ClientConfig {
|
||||||
return ClientConfig{
|
return ClientConfig{
|
||||||
baseConfig: getDefaultBaseConf(),
|
BaseConfig: getDefaultBaseConf(),
|
||||||
oidcClientConfig: getDefaultOidcClientConf(),
|
OidcClientConfig: getDefaultOidcClientConf(),
|
||||||
tokenConfig: getDefaultTokenConf(),
|
TokenConfig: getDefaultTokenConf(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnmarshalClientConfFromIni(conf ini.File) (cfg ClientConfig) {
|
|
||||||
cfg.baseConfig = unmarshalBaseConfFromIni(conf)
|
|
||||||
cfg.oidcClientConfig = unmarshalOidcClientConfFromIni(conf)
|
|
||||||
cfg.tokenConfig = unmarshalTokenConfFromIni(conf)
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
baseConfig
|
BaseConfig `ini:",extends"`
|
||||||
oidcServerConfig
|
OidcServerConfig `ini:",extends"`
|
||||||
tokenConfig
|
TokenConfig `ini:",extends"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultServerConf() ServerConfig {
|
func GetDefaultServerConf() ServerConfig {
|
||||||
return ServerConfig{
|
return ServerConfig{
|
||||||
baseConfig: getDefaultBaseConf(),
|
BaseConfig: getDefaultBaseConf(),
|
||||||
oidcServerConfig: getDefaultOidcServerConf(),
|
OidcServerConfig: getDefaultOidcServerConf(),
|
||||||
tokenConfig: getDefaultTokenConf(),
|
TokenConfig: getDefaultTokenConf(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnmarshalServerConfFromIni(conf ini.File) (cfg ServerConfig) {
|
|
||||||
cfg.baseConfig = unmarshalBaseConfFromIni(conf)
|
|
||||||
cfg.oidcServerConfig = unmarshalOidcServerConfFromIni(conf)
|
|
||||||
cfg.tokenConfig = unmarshalTokenConfFromIni(conf)
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type Setter interface {
|
type Setter interface {
|
||||||
SetLogin(*msg.Login) error
|
SetLogin(*msg.Login) error
|
||||||
SetPing(*msg.Ping) error
|
SetPing(*msg.Ping) error
|
||||||
@@ -123,9 +80,9 @@ type Setter interface {
|
|||||||
func NewAuthSetter(cfg ClientConfig) (authProvider Setter) {
|
func NewAuthSetter(cfg ClientConfig) (authProvider Setter) {
|
||||||
switch cfg.AuthenticationMethod {
|
switch cfg.AuthenticationMethod {
|
||||||
case consts.TokenAuthMethod:
|
case consts.TokenAuthMethod:
|
||||||
authProvider = NewTokenAuth(cfg.baseConfig, cfg.tokenConfig)
|
authProvider = NewTokenAuth(cfg.BaseConfig, cfg.TokenConfig)
|
||||||
case consts.OidcAuthMethod:
|
case consts.OidcAuthMethod:
|
||||||
authProvider = NewOidcAuthSetter(cfg.baseConfig, cfg.oidcClientConfig)
|
authProvider = NewOidcAuthSetter(cfg.BaseConfig, cfg.OidcClientConfig)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("wrong authentication method: '%s'", cfg.AuthenticationMethod))
|
panic(fmt.Sprintf("wrong authentication method: '%s'", cfg.AuthenticationMethod))
|
||||||
}
|
}
|
||||||
@@ -142,9 +99,9 @@ type Verifier interface {
|
|||||||
func NewAuthVerifier(cfg ServerConfig) (authVerifier Verifier) {
|
func NewAuthVerifier(cfg ServerConfig) (authVerifier Verifier) {
|
||||||
switch cfg.AuthenticationMethod {
|
switch cfg.AuthenticationMethod {
|
||||||
case consts.TokenAuthMethod:
|
case consts.TokenAuthMethod:
|
||||||
authVerifier = NewTokenAuth(cfg.baseConfig, cfg.tokenConfig)
|
authVerifier = NewTokenAuth(cfg.BaseConfig, cfg.TokenConfig)
|
||||||
case consts.OidcAuthMethod:
|
case consts.OidcAuthMethod:
|
||||||
authVerifier = NewOidcAuthVerifier(cfg.baseConfig, cfg.oidcServerConfig)
|
authVerifier = NewOidcAuthVerifier(cfg.BaseConfig, cfg.OidcServerConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
return authVerifier
|
return authVerifier
|
||||||
|
143
pkg/auth/oidc.go
143
pkg/auth/oidc.go
@@ -18,90 +18,72 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
|
|
||||||
"github.com/coreos/go-oidc"
|
|
||||||
"github.com/vaughan0/go-ini"
|
|
||||||
"golang.org/x/oauth2/clientcredentials"
|
"golang.org/x/oauth2/clientcredentials"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type oidcClientConfig struct {
|
type OidcClientConfig struct {
|
||||||
// OidcClientID specifies the client ID to use to get a token in OIDC
|
// OidcClientID specifies the client ID to use to get a token in OIDC
|
||||||
// authentication if AuthenticationMethod == "oidc". By default, this value
|
// authentication if AuthenticationMethod == "oidc". By default, this value
|
||||||
// is "".
|
// is "".
|
||||||
OidcClientID string `json:"oidc_client_id"`
|
OidcClientID string `ini:"oidc_client_id" json:"oidc_client_id"`
|
||||||
// OidcClientSecret specifies the client secret to use to get a token in OIDC
|
// OidcClientSecret specifies the client secret to use to get a token in OIDC
|
||||||
// authentication if AuthenticationMethod == "oidc". By default, this value
|
// authentication if AuthenticationMethod == "oidc". By default, this value
|
||||||
// is "".
|
// is "".
|
||||||
OidcClientSecret string `json:"oidc_client_secret"`
|
OidcClientSecret string `ini:"oidc_client_secret" json:"oidc_client_secret"`
|
||||||
// OidcAudience specifies the audience of the token in OIDC authentication
|
// OidcAudience specifies the audience of the token in OIDC authentication
|
||||||
//if AuthenticationMethod == "oidc". By default, this value is "".
|
// if AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
OidcAudience string `json:"oidc_audience"`
|
OidcAudience string `ini:"oidc_audience" json:"oidc_audience"`
|
||||||
|
// OidcScope specifies the scope of the token in OIDC authentication
|
||||||
|
// if AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
|
OidcScope string `ini:"oidc_scope" json:"oidc_scope"`
|
||||||
// OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint.
|
// OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint.
|
||||||
// It will be used to get an OIDC token if AuthenticationMethod == "oidc".
|
// It will be used to get an OIDC token if AuthenticationMethod == "oidc".
|
||||||
// By default, this value is "".
|
// By default, this value is "".
|
||||||
OidcTokenEndpointURL string `json:"oidc_token_endpoint_url"`
|
OidcTokenEndpointURL string `ini:"oidc_token_endpoint_url" json:"oidc_token_endpoint_url"`
|
||||||
|
|
||||||
|
// OidcAdditionalEndpointParams specifies additional parameters to be sent
|
||||||
|
// this field will be transfer to map[string][]string in OIDC token generator
|
||||||
|
// The field will be set by prefix "oidc_additional_"
|
||||||
|
OidcAdditionalEndpointParams map[string]string `ini:"-" json:"oidc_additional_endpoint_params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultOidcClientConf() oidcClientConfig {
|
func getDefaultOidcClientConf() OidcClientConfig {
|
||||||
return oidcClientConfig{
|
return OidcClientConfig{
|
||||||
OidcClientID: "",
|
OidcClientID: "",
|
||||||
OidcClientSecret: "",
|
OidcClientSecret: "",
|
||||||
OidcAudience: "",
|
OidcAudience: "",
|
||||||
OidcTokenEndpointURL: "",
|
OidcScope: "",
|
||||||
|
OidcTokenEndpointURL: "",
|
||||||
|
OidcAdditionalEndpointParams: make(map[string]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalOidcClientConfFromIni(conf ini.File) oidcClientConfig {
|
type OidcServerConfig struct {
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
|
|
||||||
cfg := getDefaultOidcClientConf()
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_client_id"); ok {
|
|
||||||
cfg.OidcClientID = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_client_secret"); ok {
|
|
||||||
cfg.OidcClientSecret = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_audience"); ok {
|
|
||||||
cfg.OidcAudience = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_token_endpoint_url"); ok {
|
|
||||||
cfg.OidcTokenEndpointURL = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type oidcServerConfig struct {
|
|
||||||
// OidcIssuer specifies the issuer to verify OIDC tokens with. This issuer
|
// OidcIssuer specifies the issuer to verify OIDC tokens with. This issuer
|
||||||
// will be used to load public keys to verify signature and will be compared
|
// will be used to load public keys to verify signature and will be compared
|
||||||
// with the issuer claim in the OIDC token. It will be used if
|
// with the issuer claim in the OIDC token. It will be used if
|
||||||
// AuthenticationMethod == "oidc". By default, this value is "".
|
// AuthenticationMethod == "oidc". By default, this value is "".
|
||||||
OidcIssuer string `json:"oidc_issuer"`
|
OidcIssuer string `ini:"oidc_issuer" json:"oidc_issuer"`
|
||||||
// OidcAudience specifies the audience OIDC tokens should contain when validated.
|
// OidcAudience specifies the audience OIDC tokens should contain when validated.
|
||||||
// If this value is empty, audience ("client ID") verification will be skipped.
|
// If this value is empty, audience ("client ID") verification will be skipped.
|
||||||
// It will be used when AuthenticationMethod == "oidc". By default, this
|
// It will be used when AuthenticationMethod == "oidc". By default, this
|
||||||
// value is "".
|
// value is "".
|
||||||
OidcAudience string `json:"oidc_audience"`
|
OidcAudience string `ini:"oidc_audience" json:"oidc_audience"`
|
||||||
// OidcSkipExpiryCheck specifies whether to skip checking if the OIDC token is
|
// OidcSkipExpiryCheck specifies whether to skip checking if the OIDC token is
|
||||||
// expired. It will be used when AuthenticationMethod == "oidc". By default, this
|
// expired. It will be used when AuthenticationMethod == "oidc". By default, this
|
||||||
// value is false.
|
// value is false.
|
||||||
OidcSkipExpiryCheck bool `json:"oidc_skip_expiry_check"`
|
OidcSkipExpiryCheck bool `ini:"oidc_skip_expiry_check" json:"oidc_skip_expiry_check"`
|
||||||
// OidcSkipIssuerCheck specifies whether to skip checking if the OIDC token's
|
// OidcSkipIssuerCheck specifies whether to skip checking if the OIDC token's
|
||||||
// issuer claim matches the issuer specified in OidcIssuer. It will be used when
|
// issuer claim matches the issuer specified in OidcIssuer. It will be used when
|
||||||
// AuthenticationMethod == "oidc". By default, this value is false.
|
// AuthenticationMethod == "oidc". By default, this value is false.
|
||||||
OidcSkipIssuerCheck bool `json:"oidc_skip_issuer_check"`
|
OidcSkipIssuerCheck bool `ini:"oidc_skip_issuer_check" json:"oidc_skip_issuer_check"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultOidcServerConf() oidcServerConfig {
|
func getDefaultOidcServerConf() OidcServerConfig {
|
||||||
return oidcServerConfig{
|
return OidcServerConfig{
|
||||||
OidcIssuer: "",
|
OidcIssuer: "",
|
||||||
OidcAudience: "",
|
OidcAudience: "",
|
||||||
OidcSkipExpiryCheck: false,
|
OidcSkipExpiryCheck: false,
|
||||||
@@ -109,53 +91,32 @@ func getDefaultOidcServerConf() oidcServerConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalOidcServerConfFromIni(conf ini.File) oidcServerConfig {
|
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
|
|
||||||
cfg := getDefaultOidcServerConf()
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_issuer"); ok {
|
|
||||||
cfg.OidcIssuer = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_audience"); ok {
|
|
||||||
cfg.OidcAudience = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_skip_expiry_check"); ok && tmpStr == "true" {
|
|
||||||
cfg.OidcSkipExpiryCheck = true
|
|
||||||
} else {
|
|
||||||
cfg.OidcSkipExpiryCheck = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "oidc_skip_issuer_check"); ok && tmpStr == "true" {
|
|
||||||
cfg.OidcSkipIssuerCheck = true
|
|
||||||
} else {
|
|
||||||
cfg.OidcSkipIssuerCheck = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type OidcAuthProvider struct {
|
type OidcAuthProvider struct {
|
||||||
baseConfig
|
BaseConfig
|
||||||
|
|
||||||
tokenGenerator *clientcredentials.Config
|
tokenGenerator *clientcredentials.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOidcAuthSetter(baseCfg baseConfig, cfg oidcClientConfig) *OidcAuthProvider {
|
func NewOidcAuthSetter(baseCfg BaseConfig, cfg OidcClientConfig) *OidcAuthProvider {
|
||||||
|
eps := make(map[string][]string)
|
||||||
|
for k, v := range cfg.OidcAdditionalEndpointParams {
|
||||||
|
eps[k] = []string{v}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.OidcAudience != "" {
|
||||||
|
eps["audience"] = []string{cfg.OidcAudience}
|
||||||
|
}
|
||||||
|
|
||||||
tokenGenerator := &clientcredentials.Config{
|
tokenGenerator := &clientcredentials.Config{
|
||||||
ClientID: cfg.OidcClientID,
|
ClientID: cfg.OidcClientID,
|
||||||
ClientSecret: cfg.OidcClientSecret,
|
ClientSecret: cfg.OidcClientSecret,
|
||||||
Scopes: []string{cfg.OidcAudience},
|
Scopes: []string{cfg.OidcScope},
|
||||||
TokenURL: cfg.OidcTokenEndpointURL,
|
TokenURL: cfg.OidcTokenEndpointURL,
|
||||||
|
EndpointParams: eps,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &OidcAuthProvider{
|
return &OidcAuthProvider{
|
||||||
baseConfig: baseCfg,
|
BaseConfig: baseCfg,
|
||||||
tokenGenerator: tokenGenerator,
|
tokenGenerator: tokenGenerator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,13 +153,13 @@ func (auth *OidcAuthProvider) SetNewWorkConn(newWorkConnMsg *msg.NewWorkConn) (e
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OidcAuthConsumer struct {
|
type OidcAuthConsumer struct {
|
||||||
baseConfig
|
BaseConfig
|
||||||
|
|
||||||
verifier *oidc.IDTokenVerifier
|
verifier *oidc.IDTokenVerifier
|
||||||
subjectFromLogin string
|
subjectFromLogin string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOidcAuthVerifier(baseCfg baseConfig, cfg oidcServerConfig) *OidcAuthConsumer {
|
func NewOidcAuthVerifier(baseCfg BaseConfig, cfg OidcServerConfig) *OidcAuthConsumer {
|
||||||
provider, err := oidc.NewProvider(context.Background(), cfg.OidcIssuer)
|
provider, err := oidc.NewProvider(context.Background(), cfg.OidcIssuer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -210,7 +171,7 @@ func NewOidcAuthVerifier(baseCfg baseConfig, cfg oidcServerConfig) *OidcAuthCons
|
|||||||
SkipIssuerCheck: cfg.OidcSkipIssuerCheck,
|
SkipIssuerCheck: cfg.OidcSkipIssuerCheck,
|
||||||
}
|
}
|
||||||
return &OidcAuthConsumer{
|
return &OidcAuthConsumer{
|
||||||
baseConfig: baseCfg,
|
BaseConfig: baseCfg,
|
||||||
verifier: provider.Verifier(&verifierConf),
|
verifier: provider.Verifier(&verifierConf),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,47 +20,30 @@ import (
|
|||||||
|
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/util/util"
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
|
|
||||||
"github.com/vaughan0/go-ini"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tokenConfig struct {
|
type TokenConfig struct {
|
||||||
// Token specifies the authorization token used to create keys to be sent
|
// Token specifies the authorization token used to create keys to be sent
|
||||||
// to the server. The server must have a matching token for authorization
|
// to the server. The server must have a matching token for authorization
|
||||||
// to succeed. By default, this value is "".
|
// to succeed. By default, this value is "".
|
||||||
Token string `json:"token"`
|
Token string `ini:"token" json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultTokenConf() tokenConfig {
|
func getDefaultTokenConf() TokenConfig {
|
||||||
return tokenConfig{
|
return TokenConfig{
|
||||||
Token: "",
|
Token: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalTokenConfFromIni(conf ini.File) tokenConfig {
|
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
|
|
||||||
cfg := getDefaultTokenConf()
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "token"); ok {
|
|
||||||
cfg.Token = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
type TokenAuthSetterVerifier struct {
|
type TokenAuthSetterVerifier struct {
|
||||||
baseConfig
|
BaseConfig
|
||||||
|
|
||||||
token string
|
token string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTokenAuth(baseCfg baseConfig, cfg tokenConfig) *TokenAuthSetterVerifier {
|
func NewTokenAuth(baseCfg BaseConfig, cfg TokenConfig) *TokenAuthSetterVerifier {
|
||||||
return &TokenAuthSetterVerifier{
|
return &TokenAuthSetterVerifier{
|
||||||
baseConfig: baseCfg,
|
BaseConfig: baseCfg,
|
||||||
token: cfg.Token,
|
token: cfg.Token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
pkg/config/README.md
Normal file
12
pkg/config/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
So far, there is no mature Go project that does well in parsing `*.ini` files.
|
||||||
|
|
||||||
|
By comparison, we have selected an open source project: `https://github.com/go-ini/ini`.
|
||||||
|
|
||||||
|
This library helped us solve most of the key-value matching, but there are still some problems, such as not supporting parsing `map`.
|
||||||
|
|
||||||
|
We add our own logic on the basis of this library. In the current situationwhich, we need to complete the entire `Unmarshal` in two steps:
|
||||||
|
|
||||||
|
* Step#1, use `go-ini` to complete the basic parameter matching;
|
||||||
|
* Step#2, parse our custom parameters to realize parsing special structure, like `map`, `array`.
|
||||||
|
|
||||||
|
Some of the keywords in `tag`(like inline, extends, etc.) may be different from standard libraries such as `json` and `protobuf` in Go. For details, please refer to the library documentation: https://ini.unknwon.io/docs/intro.
|
415
pkg/config/client.go
Normal file
415
pkg/config/client.go
Normal file
@@ -0,0 +1,415 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClientCommonConf contains information for a client service. It is
|
||||||
|
// recommended to use GetDefaultClientConf instead of creating this object
|
||||||
|
// directly, so that all unspecified fields have reasonable default values.
|
||||||
|
type ClientCommonConf struct {
|
||||||
|
auth.ClientConfig `ini:",extends"`
|
||||||
|
|
||||||
|
// ServerAddr specifies the address of the server to connect to. By
|
||||||
|
// default, this value is "0.0.0.0".
|
||||||
|
ServerAddr string `ini:"server_addr" json:"server_addr"`
|
||||||
|
// ServerPort specifies the port to connect to the server on. By default,
|
||||||
|
// this value is 7000.
|
||||||
|
ServerPort int `ini:"server_port" json:"server_port"`
|
||||||
|
// The maximum amount of time a dial to server will wait for a connect to complete.
|
||||||
|
DialServerTimeout int64 `ini:"dial_server_timeout" json:"dial_server_timeout"`
|
||||||
|
// DialServerKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
|
||||||
|
// If negative, keep-alive probes are disabled.
|
||||||
|
DialServerKeepAlive int64 `ini:"dial_server_keepalive" json:"dial_server_keepalive"`
|
||||||
|
// ConnectServerLocalIP specifies the address of the client bind when it connect to server.
|
||||||
|
// By default, this value is empty.
|
||||||
|
// this value only use in TCP/Websocket protocol. Not support in KCP protocol.
|
||||||
|
ConnectServerLocalIP string `ini:"connect_server_local_ip" json:"connect_server_local_ip"`
|
||||||
|
// HTTPProxy specifies a proxy address to connect to the server through. If
|
||||||
|
// this value is "", the server will be connected to directly. By default,
|
||||||
|
// this value is read from the "http_proxy" environment variable.
|
||||||
|
HTTPProxy string `ini:"http_proxy" json:"http_proxy"`
|
||||||
|
// LogFile specifies a file where logs will be written to. This value will
|
||||||
|
// only be used if LogWay is set appropriately. By default, this value is
|
||||||
|
// "console".
|
||||||
|
LogFile string `ini:"log_file" json:"log_file"`
|
||||||
|
// LogWay specifies the way logging is managed. Valid values are "console"
|
||||||
|
// or "file". If "console" is used, logs will be printed to stdout. If
|
||||||
|
// "file" is used, logs will be printed to LogFile. By default, this value
|
||||||
|
// is "console".
|
||||||
|
LogWay string `ini:"log_way" json:"log_way"`
|
||||||
|
// LogLevel specifies the minimum log level. Valid values are "trace",
|
||||||
|
// "debug", "info", "warn", and "error". By default, this value is "info".
|
||||||
|
LogLevel string `ini:"log_level" json:"log_level"`
|
||||||
|
// LogMaxDays specifies the maximum number of days to store log information
|
||||||
|
// before deletion. This is only used if LogWay == "file". By default, this
|
||||||
|
// value is 0.
|
||||||
|
LogMaxDays int64 `ini:"log_max_days" json:"log_max_days"`
|
||||||
|
// DisableLogColor disables log colors when LogWay == "console" when set to
|
||||||
|
// true. By default, this value is false.
|
||||||
|
DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"`
|
||||||
|
// AdminAddr specifies the address that the admin server binds to. By
|
||||||
|
// default, this value is "127.0.0.1".
|
||||||
|
AdminAddr string `ini:"admin_addr" json:"admin_addr"`
|
||||||
|
// AdminPort specifies the port for the admin server to listen on. If this
|
||||||
|
// value is 0, the admin server will not be started. By default, this value
|
||||||
|
// is 0.
|
||||||
|
AdminPort int `ini:"admin_port" json:"admin_port"`
|
||||||
|
// AdminUser specifies the username that the admin server will use for
|
||||||
|
// login.
|
||||||
|
AdminUser string `ini:"admin_user" json:"admin_user"`
|
||||||
|
// AdminPwd specifies the password that the admin server will use for
|
||||||
|
// login.
|
||||||
|
AdminPwd string `ini:"admin_pwd" json:"admin_pwd"`
|
||||||
|
// AssetsDir specifies the local directory that the admin server will load
|
||||||
|
// resources from. If this value is "", assets will be loaded from the
|
||||||
|
// bundled executable using statik. By default, this value is "".
|
||||||
|
AssetsDir string `ini:"assets_dir" json:"assets_dir"`
|
||||||
|
// PoolCount specifies the number of connections the client will make to
|
||||||
|
// the server in advance. By default, this value is 0.
|
||||||
|
PoolCount int `ini:"pool_count" json:"pool_count"`
|
||||||
|
// TCPMux toggles TCP stream multiplexing. This allows multiple requests
|
||||||
|
// from a client to share a single TCP connection. If this value is true,
|
||||||
|
// the server must have TCP multiplexing enabled as well. By default, this
|
||||||
|
// value is true.
|
||||||
|
TCPMux bool `ini:"tcp_mux" json:"tcp_mux"`
|
||||||
|
// TCPMuxKeepaliveInterval specifies the keep alive interval for TCP stream multipler.
|
||||||
|
// If TCPMux is true, heartbeat of application layer is unnecessary because it can only rely on heartbeat in TCPMux.
|
||||||
|
TCPMuxKeepaliveInterval int64 `ini:"tcp_mux_keepalive_interval" json:"tcp_mux_keepalive_interval"`
|
||||||
|
// User specifies a prefix for proxy names to distinguish them from other
|
||||||
|
// clients. If this value is not "", proxy names will automatically be
|
||||||
|
// changed to "{user}.{proxy_name}". By default, this value is "".
|
||||||
|
User string `ini:"user" json:"user"`
|
||||||
|
// DNSServer specifies a DNS server address for FRPC to use. If this value
|
||||||
|
// is "", the default DNS will be used. By default, this value is "".
|
||||||
|
DNSServer string `ini:"dns_server" json:"dns_server"`
|
||||||
|
// LoginFailExit controls whether or not the client should exit after a
|
||||||
|
// failed login attempt. If false, the client will retry until a login
|
||||||
|
// attempt succeeds. By default, this value is true.
|
||||||
|
LoginFailExit bool `ini:"login_fail_exit" json:"login_fail_exit"`
|
||||||
|
// Start specifies a set of enabled proxies by name. If this set is empty,
|
||||||
|
// all supplied proxies are enabled. By default, this value is an empty
|
||||||
|
// set.
|
||||||
|
Start []string `ini:"start" json:"start"`
|
||||||
|
// Start map[string]struct{} `json:"start"`
|
||||||
|
// Protocol specifies the protocol to use when interacting with the server.
|
||||||
|
// Valid values are "tcp", "kcp", "quic" and "websocket". By default, this value
|
||||||
|
// is "tcp".
|
||||||
|
Protocol string `ini:"protocol" json:"protocol"`
|
||||||
|
// QUIC protocol options
|
||||||
|
QUICKeepalivePeriod int `ini:"quic_keepalive_period" json:"quic_keepalive_period" validate:"gte=0"`
|
||||||
|
QUICMaxIdleTimeout int `ini:"quic_max_idle_timeout" json:"quic_max_idle_timeout" validate:"gte=0"`
|
||||||
|
QUICMaxIncomingStreams int `ini:"quic_max_incoming_streams" json:"quic_max_incoming_streams" validate:"gte=0"`
|
||||||
|
// TLSEnable specifies whether or not TLS should be used when communicating
|
||||||
|
// with the server. If "tls_cert_file" and "tls_key_file" are valid,
|
||||||
|
// client will load the supplied tls configuration.
|
||||||
|
TLSEnable bool `ini:"tls_enable" json:"tls_enable"`
|
||||||
|
// TLSCertPath specifies the path of the cert file that client will
|
||||||
|
// load. It only works when "tls_enable" is true and "tls_key_file" is valid.
|
||||||
|
TLSCertFile string `ini:"tls_cert_file" json:"tls_cert_file"`
|
||||||
|
// TLSKeyPath specifies the path of the secret key file that client
|
||||||
|
// will load. It only works when "tls_enable" is true and "tls_cert_file"
|
||||||
|
// are valid.
|
||||||
|
TLSKeyFile string `ini:"tls_key_file" json:"tls_key_file"`
|
||||||
|
// TLSTrustedCaFile specifies the path of the trusted ca file that will load.
|
||||||
|
// It only works when "tls_enable" is valid and tls configuration of server
|
||||||
|
// has been specified.
|
||||||
|
TLSTrustedCaFile string `ini:"tls_trusted_ca_file" json:"tls_trusted_ca_file"`
|
||||||
|
// TLSServerName specifies the custom server name of tls certificate. By
|
||||||
|
// default, server name if same to ServerAddr.
|
||||||
|
TLSServerName string `ini:"tls_server_name" json:"tls_server_name"`
|
||||||
|
// By default, frpc will connect frps with first custom byte if tls is enabled.
|
||||||
|
// If DisableCustomTLSFirstByte is true, frpc will not send that custom byte.
|
||||||
|
DisableCustomTLSFirstByte bool `ini:"disable_custom_tls_first_byte" json:"disable_custom_tls_first_byte"`
|
||||||
|
// HeartBeatInterval specifies at what interval heartbeats are sent to the
|
||||||
|
// server, in seconds. It is not recommended to change this value. By
|
||||||
|
// default, this value is 30. Set negative value to disable it.
|
||||||
|
HeartbeatInterval int64 `ini:"heartbeat_interval" json:"heartbeat_interval"`
|
||||||
|
// HeartBeatTimeout specifies the maximum allowed heartbeat response delay
|
||||||
|
// before the connection is terminated, in seconds. It is not recommended
|
||||||
|
// to change this value. By default, this value is 90. Set negative value to disable it.
|
||||||
|
HeartbeatTimeout int64 `ini:"heartbeat_timeout" json:"heartbeat_timeout"`
|
||||||
|
// Client meta info
|
||||||
|
Metas map[string]string `ini:"-" json:"metas"`
|
||||||
|
// UDPPacketSize specifies the udp packet size
|
||||||
|
// By default, this value is 1500
|
||||||
|
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
|
||||||
|
// Include other config files for proxies.
|
||||||
|
IncludeConfigFiles []string `ini:"includes" json:"includes"`
|
||||||
|
// Enable golang pprof handlers in admin listener.
|
||||||
|
// Admin port must be set first.
|
||||||
|
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultClientConf returns a client configuration with default values.
|
||||||
|
func GetDefaultClientConf() ClientCommonConf {
|
||||||
|
return ClientCommonConf{
|
||||||
|
ClientConfig: auth.GetDefaultClientConf(),
|
||||||
|
ServerAddr: "0.0.0.0",
|
||||||
|
ServerPort: 7000,
|
||||||
|
DialServerTimeout: 10,
|
||||||
|
DialServerKeepAlive: 7200,
|
||||||
|
HTTPProxy: os.Getenv("http_proxy"),
|
||||||
|
LogFile: "console",
|
||||||
|
LogWay: "console",
|
||||||
|
LogLevel: "info",
|
||||||
|
LogMaxDays: 3,
|
||||||
|
AdminAddr: "127.0.0.1",
|
||||||
|
PoolCount: 1,
|
||||||
|
TCPMux: true,
|
||||||
|
TCPMuxKeepaliveInterval: 60,
|
||||||
|
LoginFailExit: true,
|
||||||
|
Start: make([]string, 0),
|
||||||
|
Protocol: "tcp",
|
||||||
|
QUICKeepalivePeriod: 10,
|
||||||
|
QUICMaxIdleTimeout: 30,
|
||||||
|
QUICMaxIncomingStreams: 100000,
|
||||||
|
HeartbeatInterval: 30,
|
||||||
|
HeartbeatTimeout: 90,
|
||||||
|
Metas: make(map[string]string),
|
||||||
|
UDPPacketSize: 1500,
|
||||||
|
IncludeConfigFiles: make([]string, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *ClientCommonConf) Complete() {
|
||||||
|
if cfg.LogFile == "console" {
|
||||||
|
cfg.LogWay = "console"
|
||||||
|
} else {
|
||||||
|
cfg.LogWay = "file"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *ClientCommonConf) Validate() error {
|
||||||
|
if cfg.HeartbeatTimeout > 0 && cfg.HeartbeatInterval > 0 {
|
||||||
|
if cfg.HeartbeatTimeout < cfg.HeartbeatInterval {
|
||||||
|
return fmt.Errorf("invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cfg.TLSEnable {
|
||||||
|
if cfg.TLSCertFile != "" {
|
||||||
|
fmt.Println("WARNING! tls_cert_file is invalid when tls_enable is false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.TLSKeyFile != "" {
|
||||||
|
fmt.Println("WARNING! tls_key_file is invalid when tls_enable is false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.TLSTrustedCaFile != "" {
|
||||||
|
fmt.Println("WARNING! tls_trusted_ca_file is invalid when tls_enable is false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Protocol != "tcp" && cfg.Protocol != "kcp" && cfg.Protocol != "websocket" && cfg.Protocol != "quic" {
|
||||||
|
return fmt.Errorf("invalid protocol")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range cfg.IncludeConfigFiles {
|
||||||
|
absDir, err := filepath.Abs(filepath.Dir(f))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("include: parse directory of %s failed: %v", f, absDir)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(absDir); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("include: directory of %s not exist", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supported sources including: string(file path), []byte, Reader interface.
|
||||||
|
func UnmarshalClientConfFromIni(source interface{}) (ClientCommonConf, error) {
|
||||||
|
f, err := ini.LoadSources(ini.LoadOptions{
|
||||||
|
Insensitive: false,
|
||||||
|
InsensitiveSections: false,
|
||||||
|
InsensitiveKeys: false,
|
||||||
|
IgnoreInlineComment: true,
|
||||||
|
AllowBooleanKeys: true,
|
||||||
|
}, source)
|
||||||
|
if err != nil {
|
||||||
|
return ClientCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := f.GetSection("common")
|
||||||
|
if err != nil {
|
||||||
|
return ClientCommonConf{}, fmt.Errorf("invalid configuration file, not found [common] section")
|
||||||
|
}
|
||||||
|
|
||||||
|
common := GetDefaultClientConf()
|
||||||
|
err = s.MapTo(&common)
|
||||||
|
if err != nil {
|
||||||
|
return ClientCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
common.Metas = GetMapWithoutPrefix(s.KeysHash(), "meta_")
|
||||||
|
common.ClientConfig.OidcAdditionalEndpointParams = GetMapWithoutPrefix(s.KeysHash(), "oidc_additional_")
|
||||||
|
|
||||||
|
return common, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// if len(startProxy) is 0, start all
|
||||||
|
// otherwise just start proxies in startProxy map
|
||||||
|
func LoadAllProxyConfsFromIni(
|
||||||
|
prefix string,
|
||||||
|
source interface{},
|
||||||
|
start []string,
|
||||||
|
) (map[string]ProxyConf, map[string]VisitorConf, error) {
|
||||||
|
f, err := ini.LoadSources(ini.LoadOptions{
|
||||||
|
Insensitive: false,
|
||||||
|
InsensitiveSections: false,
|
||||||
|
InsensitiveKeys: false,
|
||||||
|
IgnoreInlineComment: true,
|
||||||
|
AllowBooleanKeys: true,
|
||||||
|
}, source)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyConfs := make(map[string]ProxyConf)
|
||||||
|
visitorConfs := make(map[string]VisitorConf)
|
||||||
|
|
||||||
|
if prefix != "" {
|
||||||
|
prefix += "."
|
||||||
|
}
|
||||||
|
|
||||||
|
startProxy := make(map[string]struct{})
|
||||||
|
for _, s := range start {
|
||||||
|
startProxy[s] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
startAll := true
|
||||||
|
if len(startProxy) > 0 {
|
||||||
|
startAll = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build template sections from range section And append to ini.File.
|
||||||
|
rangeSections := make([]*ini.Section, 0)
|
||||||
|
for _, section := range f.Sections() {
|
||||||
|
|
||||||
|
if !strings.HasPrefix(section.Name(), "range:") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rangeSections = append(rangeSections, section)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, section := range rangeSections {
|
||||||
|
err = renderRangeProxyTemplates(f, section)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to render template for proxy %s: %v", section.Name(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, section := range f.Sections() {
|
||||||
|
name := section.Name()
|
||||||
|
|
||||||
|
if name == ini.DefaultSection || name == "common" || strings.HasPrefix(name, "range:") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, shouldStart := startProxy[name]
|
||||||
|
if !startAll && !shouldStart {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
roleType := section.Key("role").String()
|
||||||
|
if roleType == "" {
|
||||||
|
roleType = "server"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch roleType {
|
||||||
|
case "server":
|
||||||
|
newConf, newErr := NewProxyConfFromIni(prefix, name, section)
|
||||||
|
if newErr != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to parse proxy %s, err: %v", name, newErr)
|
||||||
|
}
|
||||||
|
proxyConfs[prefix+name] = newConf
|
||||||
|
case "visitor":
|
||||||
|
newConf, newErr := NewVisitorConfFromIni(prefix, name, section)
|
||||||
|
if newErr != nil {
|
||||||
|
return nil, nil, newErr
|
||||||
|
}
|
||||||
|
visitorConfs[prefix+name] = newConf
|
||||||
|
default:
|
||||||
|
return nil, nil, fmt.Errorf("proxy %s role should be 'server' or 'visitor'", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return proxyConfs, visitorConfs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderRangeProxyTemplates(f *ini.File, section *ini.Section) error {
|
||||||
|
// Validation
|
||||||
|
localPortStr := section.Key("local_port").String()
|
||||||
|
remotePortStr := section.Key("remote_port").String()
|
||||||
|
if localPortStr == "" || remotePortStr == "" {
|
||||||
|
return fmt.Errorf("local_port or remote_port is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
localPorts, err := util.ParseRangeNumbers(localPortStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
remotePorts, err := util.ParseRangeNumbers(remotePortStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(localPorts) != len(remotePorts) {
|
||||||
|
return fmt.Errorf("local ports number should be same with remote ports number")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(localPorts) == 0 {
|
||||||
|
return fmt.Errorf("local_port and remote_port is necessary")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Templates
|
||||||
|
prefix := strings.TrimSpace(strings.TrimPrefix(section.Name(), "range:"))
|
||||||
|
|
||||||
|
for i := range localPorts {
|
||||||
|
tmpname := fmt.Sprintf("%s_%d", prefix, i)
|
||||||
|
|
||||||
|
tmpsection, err := f.NewSection(tmpname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
copySection(section, tmpsection)
|
||||||
|
if _, err := tmpsection.NewKey("local_port", fmt.Sprintf("%d", localPorts[i])); err != nil {
|
||||||
|
return fmt.Errorf("local_port new key in section error: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := tmpsection.NewKey("remote_port", fmt.Sprintf("%d", remotePorts[i])); err != nil {
|
||||||
|
return fmt.Errorf("remote_port new key in section error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copySection(source, target *ini.Section) {
|
||||||
|
for key, value := range source.KeysHash() {
|
||||||
|
_, _ = target.NewKey(key, value)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,365 +0,0 @@
|
|||||||
// Copyright 2016 fatedier, fatedier@gmail.com
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
|
||||||
|
|
||||||
ini "github.com/vaughan0/go-ini"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ClientCommonConf contains information for a client service. It is
|
|
||||||
// recommended to use GetDefaultClientConf instead of creating this object
|
|
||||||
// directly, so that all unspecified fields have reasonable default values.
|
|
||||||
type ClientCommonConf struct {
|
|
||||||
auth.ClientConfig
|
|
||||||
// ServerAddr specifies the address of the server to connect to. By
|
|
||||||
// default, this value is "0.0.0.0".
|
|
||||||
ServerAddr string `json:"server_addr"`
|
|
||||||
// ServerPort specifies the port to connect to the server on. By default,
|
|
||||||
// this value is 7000.
|
|
||||||
ServerPort int `json:"server_port"`
|
|
||||||
// HTTPProxy specifies a proxy address to connect to the server through. If
|
|
||||||
// this value is "", the server will be connected to directly. By default,
|
|
||||||
// this value is read from the "http_proxy" environment variable.
|
|
||||||
HTTPProxy string `json:"http_proxy"`
|
|
||||||
// LogFile specifies a file where logs will be written to. This value will
|
|
||||||
// only be used if LogWay is set appropriately. By default, this value is
|
|
||||||
// "console".
|
|
||||||
LogFile string `json:"log_file"`
|
|
||||||
// LogWay specifies the way logging is managed. Valid values are "console"
|
|
||||||
// or "file". If "console" is used, logs will be printed to stdout. If
|
|
||||||
// "file" is used, logs will be printed to LogFile. By default, this value
|
|
||||||
// is "console".
|
|
||||||
LogWay string `json:"log_way"`
|
|
||||||
// LogLevel specifies the minimum log level. Valid values are "trace",
|
|
||||||
// "debug", "info", "warn", and "error". By default, this value is "info".
|
|
||||||
LogLevel string `json:"log_level"`
|
|
||||||
// LogMaxDays specifies the maximum number of days to store log information
|
|
||||||
// before deletion. This is only used if LogWay == "file". By default, this
|
|
||||||
// value is 0.
|
|
||||||
LogMaxDays int64 `json:"log_max_days"`
|
|
||||||
// DisableLogColor disables log colors when LogWay == "console" when set to
|
|
||||||
// true. By default, this value is false.
|
|
||||||
DisableLogColor bool `json:"disable_log_color"`
|
|
||||||
// AdminAddr specifies the address that the admin server binds to. By
|
|
||||||
// default, this value is "127.0.0.1".
|
|
||||||
AdminAddr string `json:"admin_addr"`
|
|
||||||
// AdminPort specifies the port for the admin server to listen on. If this
|
|
||||||
// value is 0, the admin server will not be started. By default, this value
|
|
||||||
// is 0.
|
|
||||||
AdminPort int `json:"admin_port"`
|
|
||||||
// AdminUser specifies the username that the admin server will use for
|
|
||||||
// login. By default, this value is "admin".
|
|
||||||
AdminUser string `json:"admin_user"`
|
|
||||||
// AdminPwd specifies the password that the admin server will use for
|
|
||||||
// login. By default, this value is "admin".
|
|
||||||
AdminPwd string `json:"admin_pwd"`
|
|
||||||
// AssetsDir specifies the local directory that the admin server will load
|
|
||||||
// resources from. If this value is "", assets will be loaded from the
|
|
||||||
// bundled executable using statik. By default, this value is "".
|
|
||||||
AssetsDir string `json:"assets_dir"`
|
|
||||||
// PoolCount specifies the number of connections the client will make to
|
|
||||||
// the server in advance. By default, this value is 0.
|
|
||||||
PoolCount int `json:"pool_count"`
|
|
||||||
// TCPMux toggles TCP stream multiplexing. This allows multiple requests
|
|
||||||
// from a client to share a single TCP connection. If this value is true,
|
|
||||||
// the server must have TCP multiplexing enabled as well. By default, this
|
|
||||||
// value is true.
|
|
||||||
TCPMux bool `json:"tcp_mux"`
|
|
||||||
// User specifies a prefix for proxy names to distinguish them from other
|
|
||||||
// clients. If this value is not "", proxy names will automatically be
|
|
||||||
// changed to "{user}.{proxy_name}". By default, this value is "".
|
|
||||||
User string `json:"user"`
|
|
||||||
// DNSServer specifies a DNS server address for FRPC to use. If this value
|
|
||||||
// is "", the default DNS will be used. By default, this value is "".
|
|
||||||
DNSServer string `json:"dns_server"`
|
|
||||||
// LoginFailExit controls whether or not the client should exit after a
|
|
||||||
// failed login attempt. If false, the client will retry until a login
|
|
||||||
// attempt succeeds. By default, this value is true.
|
|
||||||
LoginFailExit bool `json:"login_fail_exit"`
|
|
||||||
// Start specifies a set of enabled proxies by name. If this set is empty,
|
|
||||||
// all supplied proxies are enabled. By default, this value is an empty
|
|
||||||
// set.
|
|
||||||
Start map[string]struct{} `json:"start"`
|
|
||||||
// Protocol specifies the protocol to use when interacting with the server.
|
|
||||||
// Valid values are "tcp", "kcp" and "websocket". By default, this value
|
|
||||||
// is "tcp".
|
|
||||||
Protocol string `json:"protocol"`
|
|
||||||
// TLSEnable specifies whether or not TLS should be used when communicating
|
|
||||||
// with the server. If "tls_cert_file" and "tls_key_file" are valid,
|
|
||||||
// client will load the supplied tls configuration.
|
|
||||||
TLSEnable bool `json:"tls_enable"`
|
|
||||||
// ClientTLSCertPath specifies the path of the cert file that client will
|
|
||||||
// load. It only works when "tls_enable" is true and "tls_key_file" is valid.
|
|
||||||
TLSCertFile string `json:"tls_cert_file"`
|
|
||||||
// ClientTLSKeyPath specifies the path of the secret key file that client
|
|
||||||
// will load. It only works when "tls_enable" is true and "tls_cert_file"
|
|
||||||
// are valid.
|
|
||||||
TLSKeyFile string `json:"tls_key_file"`
|
|
||||||
// TrustedCaFile specifies the path of the trusted ca file that will load.
|
|
||||||
// It only works when "tls_enable" is valid and tls configuration of server
|
|
||||||
// has been specified.
|
|
||||||
TLSTrustedCaFile string `json:"tls_trusted_ca_file"`
|
|
||||||
// HeartBeatInterval specifies at what interval heartbeats are sent to the
|
|
||||||
// server, in seconds. It is not recommended to change this value. By
|
|
||||||
// default, this value is 30.
|
|
||||||
HeartBeatInterval int64 `json:"heartbeat_interval"`
|
|
||||||
// HeartBeatTimeout specifies the maximum allowed heartbeat response delay
|
|
||||||
// before the connection is terminated, in seconds. It is not recommended
|
|
||||||
// to change this value. By default, this value is 90.
|
|
||||||
HeartBeatTimeout int64 `json:"heartbeat_timeout"`
|
|
||||||
// Client meta info
|
|
||||||
Metas map[string]string `json:"metas"`
|
|
||||||
// UDPPacketSize specifies the udp packet size
|
|
||||||
// By default, this value is 1500
|
|
||||||
UDPPacketSize int64 `json:"udp_packet_size"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDefaultClientConf returns a client configuration with default values.
|
|
||||||
func GetDefaultClientConf() ClientCommonConf {
|
|
||||||
return ClientCommonConf{
|
|
||||||
ServerAddr: "0.0.0.0",
|
|
||||||
ServerPort: 7000,
|
|
||||||
HTTPProxy: os.Getenv("http_proxy"),
|
|
||||||
LogFile: "console",
|
|
||||||
LogWay: "console",
|
|
||||||
LogLevel: "info",
|
|
||||||
LogMaxDays: 3,
|
|
||||||
DisableLogColor: false,
|
|
||||||
AdminAddr: "127.0.0.1",
|
|
||||||
AdminPort: 0,
|
|
||||||
AdminUser: "",
|
|
||||||
AdminPwd: "",
|
|
||||||
AssetsDir: "",
|
|
||||||
PoolCount: 1,
|
|
||||||
TCPMux: true,
|
|
||||||
User: "",
|
|
||||||
DNSServer: "",
|
|
||||||
LoginFailExit: true,
|
|
||||||
Start: make(map[string]struct{}),
|
|
||||||
Protocol: "tcp",
|
|
||||||
TLSEnable: false,
|
|
||||||
TLSCertFile: "",
|
|
||||||
TLSKeyFile: "",
|
|
||||||
TLSTrustedCaFile: "",
|
|
||||||
HeartBeatInterval: 30,
|
|
||||||
HeartBeatTimeout: 90,
|
|
||||||
Metas: make(map[string]string),
|
|
||||||
UDPPacketSize: 1500,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmarshalClientConfFromIni(content string) (cfg ClientCommonConf, err error) {
|
|
||||||
cfg = GetDefaultClientConf()
|
|
||||||
|
|
||||||
conf, err := ini.Load(strings.NewReader(content))
|
|
||||||
if err != nil {
|
|
||||||
return ClientCommonConf{}, fmt.Errorf("parse ini conf file error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.ClientConfig = auth.UnmarshalClientConfFromIni(conf)
|
|
||||||
|
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
v int64
|
|
||||||
)
|
|
||||||
if tmpStr, ok = conf.Get("common", "server_addr"); ok {
|
|
||||||
cfg.ServerAddr = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "server_port"); ok {
|
|
||||||
v, err = strconv.ParseInt(tmpStr, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid server_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.ServerPort = int(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "disable_log_color"); ok && tmpStr == "true" {
|
|
||||||
cfg.DisableLogColor = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "http_proxy"); ok {
|
|
||||||
cfg.HTTPProxy = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_file"); ok {
|
|
||||||
cfg.LogFile = tmpStr
|
|
||||||
if cfg.LogFile == "console" {
|
|
||||||
cfg.LogWay = "console"
|
|
||||||
} else {
|
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_level"); ok {
|
|
||||||
cfg.LogLevel = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_max_days"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err == nil {
|
|
||||||
cfg.LogMaxDays = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "admin_addr"); ok {
|
|
||||||
cfg.AdminAddr = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "admin_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err == nil {
|
|
||||||
cfg.AdminPort = int(v)
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid admin_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "admin_user"); ok {
|
|
||||||
cfg.AdminUser = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "admin_pwd"); ok {
|
|
||||||
cfg.AdminPwd = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "assets_dir"); ok {
|
|
||||||
cfg.AssetsDir = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "pool_count"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err == nil {
|
|
||||||
cfg.PoolCount = int(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tcp_mux"); ok && tmpStr == "false" {
|
|
||||||
cfg.TCPMux = false
|
|
||||||
} else {
|
|
||||||
cfg.TCPMux = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "user"); ok {
|
|
||||||
cfg.User = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dns_server"); ok {
|
|
||||||
cfg.DNSServer = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "start"); ok {
|
|
||||||
proxyNames := strings.Split(tmpStr, ",")
|
|
||||||
for _, name := range proxyNames {
|
|
||||||
cfg.Start[strings.TrimSpace(name)] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "login_fail_exit"); ok && tmpStr == "false" {
|
|
||||||
cfg.LoginFailExit = false
|
|
||||||
} else {
|
|
||||||
cfg.LoginFailExit = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "protocol"); ok {
|
|
||||||
// Now it only support tcp and kcp and websocket.
|
|
||||||
if tmpStr != "tcp" && tmpStr != "kcp" && tmpStr != "websocket" {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid protocol")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.Protocol = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tls_enable"); ok && tmpStr == "true" {
|
|
||||||
cfg.TLSEnable = true
|
|
||||||
} else {
|
|
||||||
cfg.TLSEnable = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tls_cert_file"); ok {
|
|
||||||
cfg.TLSCertFile = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok := conf.Get("common", "tls_key_file"); ok {
|
|
||||||
cfg.TLSKeyFile = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok := conf.Get("common", "tls_trusted_ca_file"); ok {
|
|
||||||
cfg.TLSTrustedCaFile = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "heartbeat_timeout"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid heartbeat_timeout")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.HeartBeatTimeout = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "heartbeat_interval"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid heartbeat_interval")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.HeartBeatInterval = v
|
|
||||||
}
|
|
||||||
for k, v := range conf.Section("common") {
|
|
||||||
if strings.HasPrefix(k, "meta_") {
|
|
||||||
cfg.Metas[strings.TrimPrefix(k, "meta_")] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tmpStr, ok = conf.Get("common", "udp_packet_size"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid udp_packet_size")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.UDPPacketSize = v
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *ClientCommonConf) Check() (err error) {
|
|
||||||
if cfg.HeartBeatInterval <= 0 {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid heartbeat_interval")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.HeartBeatTimeout < cfg.HeartBeatInterval {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.TLSEnable == false {
|
|
||||||
if cfg.TLSCertFile != "" {
|
|
||||||
fmt.Println("WARNING! tls_cert_file is invalid when tls_enable is false")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.TLSKeyFile != "" {
|
|
||||||
fmt.Println("WARNING! tls_key_file is invalid when tls_enable is false")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.TLSTrustedCaFile != "" {
|
|
||||||
fmt.Println("WARNING! tls_trusted_ca_file is invalid when tls_enable is false")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
649
pkg/config/client_test.go
Normal file
649
pkg/config/client_test.go
Normal file
@@ -0,0 +1,649 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
testUser = "test"
|
||||||
|
)
|
||||||
|
|
||||||
|
var testClientBytesWithFull = []byte(`
|
||||||
|
# [common] is integral section
|
||||||
|
[common]
|
||||||
|
server_addr = 0.0.0.9
|
||||||
|
server_port = 7009
|
||||||
|
http_proxy = http://user:passwd@192.168.1.128:8080
|
||||||
|
log_file = ./frpc.log9
|
||||||
|
log_way = file
|
||||||
|
log_level = info9
|
||||||
|
log_max_days = 39
|
||||||
|
disable_log_color = false
|
||||||
|
authenticate_heartbeats = false
|
||||||
|
authenticate_new_work_conns = false
|
||||||
|
token = 12345678
|
||||||
|
oidc_client_id = client-id
|
||||||
|
oidc_client_secret = client-secret
|
||||||
|
oidc_audience = audience
|
||||||
|
oidc_token_endpoint_url = endpoint_url
|
||||||
|
admin_addr = 127.0.0.9
|
||||||
|
admin_port = 7409
|
||||||
|
admin_user = admin9
|
||||||
|
admin_pwd = admin9
|
||||||
|
assets_dir = ./static9
|
||||||
|
pool_count = 59
|
||||||
|
tcp_mux
|
||||||
|
user = your_name
|
||||||
|
login_fail_exit
|
||||||
|
protocol = tcp
|
||||||
|
tls_enable = true
|
||||||
|
tls_cert_file = client.crt
|
||||||
|
tls_key_file = client.key
|
||||||
|
tls_trusted_ca_file = ca.crt
|
||||||
|
tls_server_name = example.com
|
||||||
|
dns_server = 8.8.8.9
|
||||||
|
start = ssh,dns
|
||||||
|
heartbeat_interval = 39
|
||||||
|
heartbeat_timeout = 99
|
||||||
|
meta_var1 = 123
|
||||||
|
meta_var2 = 234
|
||||||
|
udp_packet_size = 1509
|
||||||
|
|
||||||
|
# all proxy
|
||||||
|
[ssh]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 29
|
||||||
|
bandwidth_limit = 19MB
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
remote_port = 6009
|
||||||
|
group = test_group
|
||||||
|
group_key = 123456
|
||||||
|
health_check_type = tcp
|
||||||
|
health_check_timeout_s = 3
|
||||||
|
health_check_max_failed = 3
|
||||||
|
health_check_interval_s = 19
|
||||||
|
meta_var1 = 123
|
||||||
|
meta_var2 = 234
|
||||||
|
|
||||||
|
[ssh_random]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 29
|
||||||
|
remote_port = 9
|
||||||
|
|
||||||
|
[range:tcp_port]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 6010-6011,6019
|
||||||
|
remote_port = 6010-6011,6019
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
|
||||||
|
[dns]
|
||||||
|
type = udp
|
||||||
|
local_ip = 114.114.114.114
|
||||||
|
local_port = 59
|
||||||
|
remote_port = 6009
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
|
||||||
|
[range:udp_port]
|
||||||
|
type = udp
|
||||||
|
local_ip = 114.114.114.114
|
||||||
|
local_port = 6000,6010-6011
|
||||||
|
remote_port = 6000,6010-6011
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
|
||||||
|
[web01]
|
||||||
|
type = http
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 89
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
http_user = admin
|
||||||
|
http_pwd = admin
|
||||||
|
subdomain = web01
|
||||||
|
custom_domains = web02.yourdomain.com
|
||||||
|
locations = /,/pic
|
||||||
|
host_header_rewrite = example.com
|
||||||
|
header_X-From-Where = frp
|
||||||
|
health_check_type = http
|
||||||
|
health_check_url = /status
|
||||||
|
health_check_interval_s = 19
|
||||||
|
health_check_max_failed = 3
|
||||||
|
health_check_timeout_s = 3
|
||||||
|
|
||||||
|
[web02]
|
||||||
|
type = https
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 8009
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
subdomain = web01
|
||||||
|
custom_domains = web02.yourdomain.com
|
||||||
|
proxy_protocol_version = v2
|
||||||
|
|
||||||
|
[secret_tcp]
|
||||||
|
type = stcp
|
||||||
|
sk = abcdefg
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 22
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
|
||||||
|
[p2p_tcp]
|
||||||
|
type = xtcp
|
||||||
|
sk = abcdefg
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 22
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
|
||||||
|
[tcpmuxhttpconnect]
|
||||||
|
type = tcpmux
|
||||||
|
multiplexer = httpconnect
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 10701
|
||||||
|
custom_domains = tunnel1
|
||||||
|
|
||||||
|
[plugin_unix_domain_socket]
|
||||||
|
type = tcp
|
||||||
|
remote_port = 6003
|
||||||
|
plugin = unix_domain_socket
|
||||||
|
plugin_unix_path = /var/run/docker.sock
|
||||||
|
|
||||||
|
[plugin_http_proxy]
|
||||||
|
type = tcp
|
||||||
|
remote_port = 6004
|
||||||
|
plugin = http_proxy
|
||||||
|
plugin_http_user = abc
|
||||||
|
plugin_http_passwd = abc
|
||||||
|
|
||||||
|
[plugin_socks5]
|
||||||
|
type = tcp
|
||||||
|
remote_port = 6005
|
||||||
|
plugin = socks5
|
||||||
|
plugin_user = abc
|
||||||
|
plugin_passwd = abc
|
||||||
|
|
||||||
|
[plugin_static_file]
|
||||||
|
type = tcp
|
||||||
|
remote_port = 6006
|
||||||
|
plugin = static_file
|
||||||
|
plugin_local_path = /var/www/blog
|
||||||
|
plugin_strip_prefix = static
|
||||||
|
plugin_http_user = abc
|
||||||
|
plugin_http_passwd = abc
|
||||||
|
|
||||||
|
[plugin_https2http]
|
||||||
|
type = https
|
||||||
|
custom_domains = test.yourdomain.com
|
||||||
|
plugin = https2http
|
||||||
|
plugin_local_addr = 127.0.0.1:80
|
||||||
|
plugin_crt_path = ./server.crt
|
||||||
|
plugin_key_path = ./server.key
|
||||||
|
plugin_host_header_rewrite = 127.0.0.1
|
||||||
|
plugin_header_X-From-Where = frp
|
||||||
|
|
||||||
|
[plugin_http2https]
|
||||||
|
type = http
|
||||||
|
custom_domains = test.yourdomain.com
|
||||||
|
plugin = http2https
|
||||||
|
plugin_local_addr = 127.0.0.1:443
|
||||||
|
plugin_host_header_rewrite = 127.0.0.1
|
||||||
|
plugin_header_X-From-Where = frp
|
||||||
|
|
||||||
|
# visitor
|
||||||
|
[secret_tcp_visitor]
|
||||||
|
role = visitor
|
||||||
|
type = stcp
|
||||||
|
server_name = secret_tcp
|
||||||
|
sk = abcdefg
|
||||||
|
bind_addr = 127.0.0.1
|
||||||
|
bind_port = 9000
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
|
||||||
|
[p2p_tcp_visitor]
|
||||||
|
role = visitor
|
||||||
|
type = xtcp
|
||||||
|
server_name = p2p_tcp
|
||||||
|
sk = abcdefg
|
||||||
|
bind_addr = 127.0.0.1
|
||||||
|
bind_port = 9001
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`)
|
||||||
|
|
||||||
|
func Test_LoadClientCommonConf(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
expected := ClientCommonConf{
|
||||||
|
ClientConfig: auth.ClientConfig{
|
||||||
|
BaseConfig: auth.BaseConfig{
|
||||||
|
AuthenticationMethod: "token",
|
||||||
|
AuthenticateHeartBeats: false,
|
||||||
|
AuthenticateNewWorkConns: false,
|
||||||
|
},
|
||||||
|
TokenConfig: auth.TokenConfig{
|
||||||
|
Token: "12345678",
|
||||||
|
},
|
||||||
|
OidcClientConfig: auth.OidcClientConfig{
|
||||||
|
OidcClientID: "client-id",
|
||||||
|
OidcClientSecret: "client-secret",
|
||||||
|
OidcAudience: "audience",
|
||||||
|
OidcTokenEndpointURL: "endpoint_url",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ServerAddr: "0.0.0.9",
|
||||||
|
ServerPort: 7009,
|
||||||
|
DialServerTimeout: 10,
|
||||||
|
DialServerKeepAlive: 7200,
|
||||||
|
HTTPProxy: "http://user:passwd@192.168.1.128:8080",
|
||||||
|
LogFile: "./frpc.log9",
|
||||||
|
LogWay: "file",
|
||||||
|
LogLevel: "info9",
|
||||||
|
LogMaxDays: 39,
|
||||||
|
DisableLogColor: false,
|
||||||
|
AdminAddr: "127.0.0.9",
|
||||||
|
AdminPort: 7409,
|
||||||
|
AdminUser: "admin9",
|
||||||
|
AdminPwd: "admin9",
|
||||||
|
AssetsDir: "./static9",
|
||||||
|
PoolCount: 59,
|
||||||
|
TCPMux: true,
|
||||||
|
TCPMuxKeepaliveInterval: 60,
|
||||||
|
User: "your_name",
|
||||||
|
LoginFailExit: true,
|
||||||
|
Protocol: "tcp",
|
||||||
|
QUICKeepalivePeriod: 10,
|
||||||
|
QUICMaxIdleTimeout: 30,
|
||||||
|
QUICMaxIncomingStreams: 100000,
|
||||||
|
TLSEnable: true,
|
||||||
|
TLSCertFile: "client.crt",
|
||||||
|
TLSKeyFile: "client.key",
|
||||||
|
TLSTrustedCaFile: "ca.crt",
|
||||||
|
TLSServerName: "example.com",
|
||||||
|
DNSServer: "8.8.8.9",
|
||||||
|
Start: []string{"ssh", "dns"},
|
||||||
|
HeartbeatInterval: 39,
|
||||||
|
HeartbeatTimeout: 99,
|
||||||
|
Metas: map[string]string{
|
||||||
|
"var1": "123",
|
||||||
|
"var2": "234",
|
||||||
|
},
|
||||||
|
UDPPacketSize: 1509,
|
||||||
|
IncludeConfigFiles: []string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
common, err := UnmarshalClientConfFromIni(testClientBytesWithFull)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.EqualValues(expected, common)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_LoadClientBasicConf(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
proxyExpected := map[string]ProxyConf{
|
||||||
|
testUser + ".ssh": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".ssh",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
Group: "test_group",
|
||||||
|
GroupKey: "123456",
|
||||||
|
BandwidthLimit: MustBandwidthQuantity("19MB"),
|
||||||
|
Metas: map[string]string{
|
||||||
|
"var1": "123",
|
||||||
|
"var2": "234",
|
||||||
|
},
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 29,
|
||||||
|
},
|
||||||
|
HealthCheckConf: HealthCheckConf{
|
||||||
|
HealthCheckType: consts.TCPProxy,
|
||||||
|
HealthCheckTimeoutS: 3,
|
||||||
|
HealthCheckMaxFailed: 3,
|
||||||
|
HealthCheckIntervalS: 19,
|
||||||
|
HealthCheckAddr: "127.0.0.9:29",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6009,
|
||||||
|
},
|
||||||
|
testUser + ".ssh_random": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".ssh_random",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 29,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 9,
|
||||||
|
},
|
||||||
|
testUser + ".tcp_port_0": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".tcp_port_0",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6010,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6010,
|
||||||
|
},
|
||||||
|
testUser + ".tcp_port_1": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".tcp_port_1",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6011,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6011,
|
||||||
|
},
|
||||||
|
testUser + ".tcp_port_2": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".tcp_port_2",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6019,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6019,
|
||||||
|
},
|
||||||
|
testUser + ".dns": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".dns",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 59,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6009,
|
||||||
|
},
|
||||||
|
testUser + ".udp_port_0": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".udp_port_0",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6000,
|
||||||
|
},
|
||||||
|
testUser + ".udp_port_1": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".udp_port_1",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6010,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6010,
|
||||||
|
},
|
||||||
|
testUser + ".udp_port_2": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".udp_port_2",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6011,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6011,
|
||||||
|
},
|
||||||
|
testUser + ".web01": &HTTPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".web01",
|
||||||
|
ProxyType: consts.HTTPProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 89,
|
||||||
|
},
|
||||||
|
HealthCheckConf: HealthCheckConf{
|
||||||
|
HealthCheckType: consts.HTTPProxy,
|
||||||
|
HealthCheckTimeoutS: 3,
|
||||||
|
HealthCheckMaxFailed: 3,
|
||||||
|
HealthCheckIntervalS: 19,
|
||||||
|
HealthCheckURL: "http://127.0.0.9:89/status",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"web02.yourdomain.com"},
|
||||||
|
SubDomain: "web01",
|
||||||
|
},
|
||||||
|
Locations: []string{"/", "/pic"},
|
||||||
|
HTTPUser: "admin",
|
||||||
|
HTTPPwd: "admin",
|
||||||
|
HostHeaderRewrite: "example.com",
|
||||||
|
Headers: map[string]string{
|
||||||
|
"X-From-Where": "frp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
testUser + ".web02": &HTTPSProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".web02",
|
||||||
|
ProxyType: consts.HTTPSProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 8009,
|
||||||
|
},
|
||||||
|
ProxyProtocolVersion: "v2",
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"web02.yourdomain.com"},
|
||||||
|
SubDomain: "web01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
testUser + ".secret_tcp": &STCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".secret_tcp",
|
||||||
|
ProxyType: consts.STCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Role: "server",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
},
|
||||||
|
testUser + ".p2p_tcp": &XTCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".p2p_tcp",
|
||||||
|
ProxyType: consts.XTCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Role: "server",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
},
|
||||||
|
testUser + ".tcpmuxhttpconnect": &TCPMuxProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".tcpmuxhttpconnect",
|
||||||
|
ProxyType: consts.TCPMuxProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 10701,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"tunnel1"},
|
||||||
|
SubDomain: "",
|
||||||
|
},
|
||||||
|
Multiplexer: "httpconnect",
|
||||||
|
},
|
||||||
|
testUser + ".plugin_unix_domain_socket": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_unix_domain_socket",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "unix_domain_socket",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_unix_path": "/var/run/docker.sock",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6003,
|
||||||
|
},
|
||||||
|
testUser + ".plugin_http_proxy": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_http_proxy",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "http_proxy",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_http_user": "abc",
|
||||||
|
"plugin_http_passwd": "abc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6004,
|
||||||
|
},
|
||||||
|
testUser + ".plugin_socks5": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_socks5",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "socks5",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_user": "abc",
|
||||||
|
"plugin_passwd": "abc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6005,
|
||||||
|
},
|
||||||
|
testUser + ".plugin_static_file": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_static_file",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "static_file",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_local_path": "/var/www/blog",
|
||||||
|
"plugin_strip_prefix": "static",
|
||||||
|
"plugin_http_user": "abc",
|
||||||
|
"plugin_http_passwd": "abc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6006,
|
||||||
|
},
|
||||||
|
testUser + ".plugin_https2http": &HTTPSProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_https2http",
|
||||||
|
ProxyType: consts.HTTPSProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "https2http",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_local_addr": "127.0.0.1:80",
|
||||||
|
"plugin_crt_path": "./server.crt",
|
||||||
|
"plugin_key_path": "./server.key",
|
||||||
|
"plugin_host_header_rewrite": "127.0.0.1",
|
||||||
|
"plugin_header_X-From-Where": "frp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"test.yourdomain.com"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
testUser + ".plugin_http2https": &HTTPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testUser + ".plugin_http2https",
|
||||||
|
ProxyType: consts.HTTPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
Plugin: "http2https",
|
||||||
|
PluginParams: map[string]string{
|
||||||
|
"plugin_local_addr": "127.0.0.1:443",
|
||||||
|
"plugin_host_header_rewrite": "127.0.0.1",
|
||||||
|
"plugin_header_X-From-Where": "frp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"test.yourdomain.com"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
visitorExpected := map[string]VisitorConf{
|
||||||
|
testUser + ".secret_tcp_visitor": &STCPVisitorConf{
|
||||||
|
BaseVisitorConf: BaseVisitorConf{
|
||||||
|
ProxyName: testUser + ".secret_tcp_visitor",
|
||||||
|
ProxyType: consts.STCPProxy,
|
||||||
|
Role: "visitor",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
ServerName: testVisitorPrefix + "secret_tcp",
|
||||||
|
BindAddr: "127.0.0.1",
|
||||||
|
BindPort: 9000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
testUser + ".p2p_tcp_visitor": &XTCPVisitorConf{
|
||||||
|
BaseVisitorConf: BaseVisitorConf{
|
||||||
|
ProxyName: testUser + ".p2p_tcp_visitor",
|
||||||
|
ProxyType: consts.XTCPProxy,
|
||||||
|
Role: "visitor",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
ServerName: testProxyPrefix + "p2p_tcp",
|
||||||
|
BindAddr: "127.0.0.1",
|
||||||
|
BindPort: 9001,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyActual, visitorActual, err := LoadAllProxyConfsFromIni(testUser, testClientBytesWithFull, nil)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(proxyExpected, proxyActual)
|
||||||
|
assert.Equal(visitorExpected, visitorActual)
|
||||||
|
}
|
99
pkg/config/parse.go
Normal file
99
pkg/config/parse.go
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
// Copyright 2021 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ParseClientConfig(filePath string) (
|
||||||
|
cfg ClientCommonConf,
|
||||||
|
pxyCfgs map[string]ProxyConf,
|
||||||
|
visitorCfgs map[string]VisitorConf,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
var content []byte
|
||||||
|
content, err = GetRenderedConfFromFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
configBuffer := bytes.NewBuffer(nil)
|
||||||
|
configBuffer.Write(content)
|
||||||
|
|
||||||
|
// Parse common section.
|
||||||
|
cfg, err = UnmarshalClientConfFromIni(content)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfg.Complete()
|
||||||
|
if err = cfg.Validate(); err != nil {
|
||||||
|
err = fmt.Errorf("parse config error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate proxy configs from include files.
|
||||||
|
var buf []byte
|
||||||
|
buf, err = getIncludeContents(cfg.IncludeConfigFiles)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("getIncludeContents error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
configBuffer.WriteString("\n")
|
||||||
|
configBuffer.Write(buf)
|
||||||
|
|
||||||
|
// Parse all proxy and visitor configs.
|
||||||
|
pxyCfgs, visitorCfgs, err = LoadAllProxyConfsFromIni(cfg.User, configBuffer.Bytes(), cfg.Start)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// getIncludeContents renders all configs from paths.
|
||||||
|
// files format can be a single file path or directory or regex path.
|
||||||
|
func getIncludeContents(paths []string) ([]byte, error) {
|
||||||
|
out := bytes.NewBuffer(nil)
|
||||||
|
for _, path := range paths {
|
||||||
|
absDir, err := filepath.Abs(filepath.Dir(path))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(absDir); os.IsNotExist(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
files, err := os.ReadDir(absDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, fi := range files {
|
||||||
|
if fi.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
absFile := filepath.Join(absDir, fi.Name())
|
||||||
|
if matched, _ := filepath.Match(filepath.Join(absDir, filepath.Base(path)), absFile); matched {
|
||||||
|
tmpContent, err := GetRenderedConfFromFile(absFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("render extra config %s error: %v", absFile, err)
|
||||||
|
}
|
||||||
|
out.Write(tmpContent)
|
||||||
|
out.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.Bytes(), nil
|
||||||
|
}
|
1281
pkg/config/proxy.go
1281
pkg/config/proxy.go
File diff suppressed because it is too large
Load Diff
459
pkg/config/proxy_test.go
Normal file
459
pkg/config/proxy_test.go
Normal file
@@ -0,0 +1,459 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
testLoadOptions = ini.LoadOptions{
|
||||||
|
Insensitive: false,
|
||||||
|
InsensitiveSections: false,
|
||||||
|
InsensitiveKeys: false,
|
||||||
|
IgnoreInlineComment: true,
|
||||||
|
AllowBooleanKeys: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
testProxyPrefix = "test."
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Proxy_Interface(t *testing.T) {
|
||||||
|
for name := range proxyConfTypeMap {
|
||||||
|
NewConfByType(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Proxy_UnmarshalFromIni(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testcases := []struct {
|
||||||
|
sname string
|
||||||
|
source []byte
|
||||||
|
expected ProxyConf
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
sname: "ssh",
|
||||||
|
source: []byte(`
|
||||||
|
[ssh]
|
||||||
|
# tcp | udp | http | https | stcp | xtcp, default is tcp
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 29
|
||||||
|
bandwidth_limit = 19MB
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
remote_port = 6009
|
||||||
|
group = test_group
|
||||||
|
group_key = 123456
|
||||||
|
health_check_type = tcp
|
||||||
|
health_check_timeout_s = 3
|
||||||
|
health_check_max_failed = 3
|
||||||
|
health_check_interval_s = 19
|
||||||
|
meta_var1 = 123
|
||||||
|
meta_var2 = 234`),
|
||||||
|
expected: &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "ssh",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
Group: "test_group",
|
||||||
|
GroupKey: "123456",
|
||||||
|
BandwidthLimit: MustBandwidthQuantity("19MB"),
|
||||||
|
Metas: map[string]string{
|
||||||
|
"var1": "123",
|
||||||
|
"var2": "234",
|
||||||
|
},
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 29,
|
||||||
|
},
|
||||||
|
HealthCheckConf: HealthCheckConf{
|
||||||
|
HealthCheckType: consts.TCPProxy,
|
||||||
|
HealthCheckTimeoutS: 3,
|
||||||
|
HealthCheckMaxFailed: 3,
|
||||||
|
HealthCheckIntervalS: 19,
|
||||||
|
HealthCheckAddr: "127.0.0.9:29",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6009,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "ssh_random",
|
||||||
|
source: []byte(`
|
||||||
|
[ssh_random]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 29
|
||||||
|
remote_port = 9
|
||||||
|
`),
|
||||||
|
expected: &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "ssh_random",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 29,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 9,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "dns",
|
||||||
|
source: []byte(`
|
||||||
|
[dns]
|
||||||
|
type = udp
|
||||||
|
local_ip = 114.114.114.114
|
||||||
|
local_port = 59
|
||||||
|
remote_port = 6009
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
`),
|
||||||
|
expected: &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "dns",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 59,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6009,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "web01",
|
||||||
|
source: []byte(`
|
||||||
|
[web01]
|
||||||
|
type = http
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 89
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
http_user = admin
|
||||||
|
http_pwd = admin
|
||||||
|
subdomain = web01
|
||||||
|
custom_domains = web02.yourdomain.com
|
||||||
|
locations = /,/pic
|
||||||
|
host_header_rewrite = example.com
|
||||||
|
header_X-From-Where = frp
|
||||||
|
health_check_type = http
|
||||||
|
health_check_url = /status
|
||||||
|
health_check_interval_s = 19
|
||||||
|
health_check_max_failed = 3
|
||||||
|
health_check_timeout_s = 3
|
||||||
|
`),
|
||||||
|
expected: &HTTPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "web01",
|
||||||
|
ProxyType: consts.HTTPProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 89,
|
||||||
|
},
|
||||||
|
HealthCheckConf: HealthCheckConf{
|
||||||
|
HealthCheckType: consts.HTTPProxy,
|
||||||
|
HealthCheckTimeoutS: 3,
|
||||||
|
HealthCheckMaxFailed: 3,
|
||||||
|
HealthCheckIntervalS: 19,
|
||||||
|
HealthCheckURL: "http://127.0.0.9:89/status",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"web02.yourdomain.com"},
|
||||||
|
SubDomain: "web01",
|
||||||
|
},
|
||||||
|
Locations: []string{"/", "/pic"},
|
||||||
|
HTTPUser: "admin",
|
||||||
|
HTTPPwd: "admin",
|
||||||
|
HostHeaderRewrite: "example.com",
|
||||||
|
Headers: map[string]string{
|
||||||
|
"X-From-Where": "frp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "web02",
|
||||||
|
source: []byte(`
|
||||||
|
[web02]
|
||||||
|
type = https
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 8009
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
subdomain = web01
|
||||||
|
custom_domains = web02.yourdomain.com
|
||||||
|
proxy_protocol_version = v2
|
||||||
|
`),
|
||||||
|
expected: &HTTPSProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "web02",
|
||||||
|
ProxyType: consts.HTTPSProxy,
|
||||||
|
UseCompression: true,
|
||||||
|
UseEncryption: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 8009,
|
||||||
|
},
|
||||||
|
ProxyProtocolVersion: "v2",
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"web02.yourdomain.com"},
|
||||||
|
SubDomain: "web01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "secret_tcp",
|
||||||
|
source: []byte(`
|
||||||
|
[secret_tcp]
|
||||||
|
type = stcp
|
||||||
|
sk = abcdefg
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 22
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`),
|
||||||
|
expected: &STCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "secret_tcp",
|
||||||
|
ProxyType: consts.STCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Role: "server",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "p2p_tcp",
|
||||||
|
source: []byte(`
|
||||||
|
[p2p_tcp]
|
||||||
|
type = xtcp
|
||||||
|
sk = abcdefg
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 22
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`),
|
||||||
|
expected: &XTCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "p2p_tcp",
|
||||||
|
ProxyType: consts.XTCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Role: "server",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "tcpmuxhttpconnect",
|
||||||
|
source: []byte(`
|
||||||
|
[tcpmuxhttpconnect]
|
||||||
|
type = tcpmux
|
||||||
|
multiplexer = httpconnect
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 10701
|
||||||
|
custom_domains = tunnel1
|
||||||
|
`),
|
||||||
|
expected: &TCPMuxProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "tcpmuxhttpconnect",
|
||||||
|
ProxyType: consts.TCPMuxProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.1",
|
||||||
|
LocalPort: 10701,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DomainConf: DomainConf{
|
||||||
|
CustomDomains: []string{"tunnel1"},
|
||||||
|
SubDomain: "",
|
||||||
|
},
|
||||||
|
Multiplexer: "httpconnect",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testcases {
|
||||||
|
f, err := ini.LoadSources(testLoadOptions, c.source)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
proxyType := f.Section(c.sname).Key("type").String()
|
||||||
|
assert.NotEmpty(proxyType)
|
||||||
|
|
||||||
|
actual := DefaultProxyConf(proxyType)
|
||||||
|
assert.NotNil(actual)
|
||||||
|
|
||||||
|
err = actual.UnmarshalFromIni(testProxyPrefix, c.sname, f.Section(c.sname))
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(c.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_RangeProxy_UnmarshalFromIni(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testcases := []struct {
|
||||||
|
sname string
|
||||||
|
source []byte
|
||||||
|
expected map[string]ProxyConf
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
sname: "range:tcp_port",
|
||||||
|
source: []byte(`
|
||||||
|
[range:tcp_port]
|
||||||
|
type = tcp
|
||||||
|
local_ip = 127.0.0.9
|
||||||
|
local_port = 6010-6011,6019
|
||||||
|
remote_port = 6010-6011,6019
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`),
|
||||||
|
expected: map[string]ProxyConf{
|
||||||
|
"tcp_port_0": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "tcp_port_0",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6010,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6010,
|
||||||
|
},
|
||||||
|
"tcp_port_1": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "tcp_port_1",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6011,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6011,
|
||||||
|
},
|
||||||
|
"tcp_port_2": &TCPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "tcp_port_2",
|
||||||
|
ProxyType: consts.TCPProxy,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "127.0.0.9",
|
||||||
|
LocalPort: 6019,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6019,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "range:udp_port",
|
||||||
|
source: []byte(`
|
||||||
|
[range:udp_port]
|
||||||
|
type = udp
|
||||||
|
local_ip = 114.114.114.114
|
||||||
|
local_port = 6000,6010-6011
|
||||||
|
remote_port = 6000,6010-6011
|
||||||
|
use_encryption
|
||||||
|
use_compression
|
||||||
|
`),
|
||||||
|
expected: map[string]ProxyConf{
|
||||||
|
"udp_port_0": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "udp_port_0",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6000,
|
||||||
|
},
|
||||||
|
"udp_port_1": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "udp_port_1",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6010,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6010,
|
||||||
|
},
|
||||||
|
"udp_port_2": &UDPProxyConf{
|
||||||
|
BaseProxyConf: BaseProxyConf{
|
||||||
|
ProxyName: testProxyPrefix + "udp_port_2",
|
||||||
|
ProxyType: consts.UDPProxy,
|
||||||
|
UseEncryption: true,
|
||||||
|
UseCompression: true,
|
||||||
|
LocalSvrConf: LocalSvrConf{
|
||||||
|
LocalIP: "114.114.114.114",
|
||||||
|
LocalPort: 6011,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RemotePort: 6011,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testcases {
|
||||||
|
|
||||||
|
f, err := ini.LoadSources(testLoadOptions, c.source)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
actual := make(map[string]ProxyConf)
|
||||||
|
s := f.Section(c.sname)
|
||||||
|
|
||||||
|
err = renderRangeProxyTemplates(f, s)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
f.DeleteSection(ini.DefaultSection)
|
||||||
|
f.DeleteSection(c.sname)
|
||||||
|
|
||||||
|
for _, section := range f.Sections() {
|
||||||
|
proxyType := section.Key("type").String()
|
||||||
|
newsname := section.Name()
|
||||||
|
|
||||||
|
tmp := DefaultProxyConf(proxyType)
|
||||||
|
err = tmp.UnmarshalFromIni(testProxyPrefix, newsname, section)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
actual[newsname] = tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(c.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
333
pkg/config/server.go
Normal file
333
pkg/config/server.go
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
|
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||||
|
"github.com/fatedier/frp/pkg/util/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ServerCommonConf contains information for a server service. It is
|
||||||
|
// recommended to use GetDefaultServerConf instead of creating this object
|
||||||
|
// directly, so that all unspecified fields have reasonable default values.
|
||||||
|
type ServerCommonConf struct {
|
||||||
|
auth.ServerConfig `ini:",extends"`
|
||||||
|
|
||||||
|
// BindAddr specifies the address that the server binds to. By default,
|
||||||
|
// this value is "0.0.0.0".
|
||||||
|
BindAddr string `ini:"bind_addr" json:"bind_addr"`
|
||||||
|
// BindPort specifies the port that the server listens on. By default, this
|
||||||
|
// value is 7000.
|
||||||
|
BindPort int `ini:"bind_port" json:"bind_port" validate:"gte=0,lte=65535"`
|
||||||
|
// BindUDPPort specifies the UDP port that the server listens on. If this
|
||||||
|
// value is 0, the server will not listen for UDP connections. By default,
|
||||||
|
// this value is 0
|
||||||
|
BindUDPPort int `ini:"bind_udp_port" json:"bind_udp_port" validate:"gte=0,lte=65535"`
|
||||||
|
// KCPBindPort specifies the KCP port that the server listens on. If this
|
||||||
|
// value is 0, the server will not listen for KCP connections. By default,
|
||||||
|
// this value is 0.
|
||||||
|
KCPBindPort int `ini:"kcp_bind_port" json:"kcp_bind_port" validate:"gte=0,lte=65535"`
|
||||||
|
// QUICBindPort specifies the QUIC port that the server listens on.
|
||||||
|
// Set this value to 0 will disable this feature.
|
||||||
|
// By default, the value is 0.
|
||||||
|
QUICBindPort int `ini:"quic_bind_port" json:"quic_bind_port" validate:"gte=0,lte=65535"`
|
||||||
|
// QUIC protocol options
|
||||||
|
QUICKeepalivePeriod int `ini:"quic_keepalive_period" json:"quic_keepalive_period" validate:"gte=0"`
|
||||||
|
QUICMaxIdleTimeout int `ini:"quic_max_idle_timeout" json:"quic_max_idle_timeout" validate:"gte=0"`
|
||||||
|
QUICMaxIncomingStreams int `ini:"quic_max_incoming_streams" json:"quic_max_incoming_streams" validate:"gte=0"`
|
||||||
|
// ProxyBindAddr specifies the address that the proxy binds to. This value
|
||||||
|
// may be the same as BindAddr.
|
||||||
|
ProxyBindAddr string `ini:"proxy_bind_addr" json:"proxy_bind_addr"`
|
||||||
|
// VhostHTTPPort specifies the port that the server listens for HTTP Vhost
|
||||||
|
// requests. If this value is 0, the server will not listen for HTTP
|
||||||
|
// requests. By default, this value is 0.
|
||||||
|
VhostHTTPPort int `ini:"vhost_http_port" json:"vhost_http_port" validate:"gte=0,lte=65535"`
|
||||||
|
// VhostHTTPSPort specifies the port that the server listens for HTTPS
|
||||||
|
// Vhost requests. If this value is 0, the server will not listen for HTTPS
|
||||||
|
// requests. By default, this value is 0.
|
||||||
|
VhostHTTPSPort int `ini:"vhost_https_port" json:"vhost_https_port" validate:"gte=0,lte=65535"`
|
||||||
|
// TCPMuxHTTPConnectPort specifies the port that the server listens for TCP
|
||||||
|
// HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
|
||||||
|
// requests on one single port. If it's not - it will listen on this value for
|
||||||
|
// HTTP CONNECT requests. By default, this value is 0.
|
||||||
|
TCPMuxHTTPConnectPort int `ini:"tcpmux_httpconnect_port" json:"tcpmux_httpconnect_port" validate:"gte=0,lte=65535"`
|
||||||
|
// If TCPMuxPassthrough is true, frps won't do any update on traffic.
|
||||||
|
TCPMuxPassthrough bool `ini:"tcpmux_passthrough" json:"tcpmux_passthrough"`
|
||||||
|
// VhostHTTPTimeout specifies the response header timeout for the Vhost
|
||||||
|
// HTTP server, in seconds. By default, this value is 60.
|
||||||
|
VhostHTTPTimeout int64 `ini:"vhost_http_timeout" json:"vhost_http_timeout"`
|
||||||
|
// DashboardAddr specifies the address that the dashboard binds to. By
|
||||||
|
// default, this value is "0.0.0.0".
|
||||||
|
DashboardAddr string `ini:"dashboard_addr" json:"dashboard_addr"`
|
||||||
|
// DashboardPort specifies the port that the dashboard listens on. If this
|
||||||
|
// value is 0, the dashboard will not be started. By default, this value is
|
||||||
|
// 0.
|
||||||
|
DashboardPort int `ini:"dashboard_port" json:"dashboard_port" validate:"gte=0,lte=65535"`
|
||||||
|
// DashboardTLSCertFile specifies the path of the cert file that the server will
|
||||||
|
// load. If "dashboard_tls_cert_file", "dashboard_tls_key_file" are valid, the server will use this
|
||||||
|
// supplied tls configuration.
|
||||||
|
DashboardTLSCertFile string `ini:"dashboard_tls_cert_file" json:"dashboard_tls_cert_file"`
|
||||||
|
// DashboardTLSKeyFile specifies the path of the secret key that the server will
|
||||||
|
// load. If "dashboard_tls_cert_file", "dashboard_tls_key_file" are valid, the server will use this
|
||||||
|
// supplied tls configuration.
|
||||||
|
DashboardTLSKeyFile string `ini:"dashboard_tls_key_file" json:"dashboard_tls_key_file"`
|
||||||
|
// DashboardTLSMode specifies the mode of the dashboard between HTTP or HTTPS modes. By
|
||||||
|
// default, this value is false, which is HTTP mode.
|
||||||
|
DashboardTLSMode bool `ini:"dashboard_tls_mode" json:"dashboard_tls_mode"`
|
||||||
|
// DashboardUser specifies the username that the dashboard will use for
|
||||||
|
// login.
|
||||||
|
DashboardUser string `ini:"dashboard_user" json:"dashboard_user"`
|
||||||
|
// DashboardPwd specifies the password that the dashboard will use for
|
||||||
|
// login.
|
||||||
|
DashboardPwd string `ini:"dashboard_pwd" json:"dashboard_pwd"`
|
||||||
|
// EnablePrometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port}
|
||||||
|
// in /metrics api.
|
||||||
|
EnablePrometheus bool `ini:"enable_prometheus" json:"enable_prometheus"`
|
||||||
|
// AssetsDir specifies the local directory that the dashboard will load
|
||||||
|
// resources from. If this value is "", assets will be loaded from the
|
||||||
|
// bundled executable using statik. By default, this value is "".
|
||||||
|
AssetsDir string `ini:"assets_dir" json:"assets_dir"`
|
||||||
|
// LogFile specifies a file where logs will be written to. This value will
|
||||||
|
// only be used if LogWay is set appropriately. By default, this value is
|
||||||
|
// "console".
|
||||||
|
LogFile string `ini:"log_file" json:"log_file"`
|
||||||
|
// LogWay specifies the way logging is managed. Valid values are "console"
|
||||||
|
// or "file". If "console" is used, logs will be printed to stdout. If
|
||||||
|
// "file" is used, logs will be printed to LogFile. By default, this value
|
||||||
|
// is "console".
|
||||||
|
LogWay string `ini:"log_way" json:"log_way"`
|
||||||
|
// LogLevel specifies the minimum log level. Valid values are "trace",
|
||||||
|
// "debug", "info", "warn", and "error". By default, this value is "info".
|
||||||
|
LogLevel string `ini:"log_level" json:"log_level"`
|
||||||
|
// LogMaxDays specifies the maximum number of days to store log information
|
||||||
|
// before deletion. This is only used if LogWay == "file". By default, this
|
||||||
|
// value is 0.
|
||||||
|
LogMaxDays int64 `ini:"log_max_days" json:"log_max_days"`
|
||||||
|
// DisableLogColor disables log colors when LogWay == "console" when set to
|
||||||
|
// true. By default, this value is false.
|
||||||
|
DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"`
|
||||||
|
// DetailedErrorsToClient defines whether to send the specific error (with
|
||||||
|
// debug info) to frpc. By default, this value is true.
|
||||||
|
DetailedErrorsToClient bool `ini:"detailed_errors_to_client" json:"detailed_errors_to_client"`
|
||||||
|
|
||||||
|
// SubDomainHost specifies the domain that will be attached to sub-domains
|
||||||
|
// requested by the client when using Vhost proxying. For example, if this
|
||||||
|
// value is set to "frps.com" and the client requested the subdomain
|
||||||
|
// "test", the resulting URL would be "test.frps.com". By default, this
|
||||||
|
// value is "".
|
||||||
|
SubDomainHost string `ini:"subdomain_host" json:"subdomain_host"`
|
||||||
|
// TCPMux toggles TCP stream multiplexing. This allows multiple requests
|
||||||
|
// from a client to share a single TCP connection. By default, this value
|
||||||
|
// is true.
|
||||||
|
TCPMux bool `ini:"tcp_mux" json:"tcp_mux"`
|
||||||
|
// TCPMuxKeepaliveInterval specifies the keep alive interval for TCP stream multipler.
|
||||||
|
// If TCPMux is true, heartbeat of application layer is unnecessary because it can only rely on heartbeat in TCPMux.
|
||||||
|
TCPMuxKeepaliveInterval int64 `ini:"tcp_mux_keepalive_interval" json:"tcp_mux_keepalive_interval"`
|
||||||
|
// TCPKeepAlive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
|
||||||
|
// If negative, keep-alive probes are disabled.
|
||||||
|
TCPKeepAlive int64 `ini:"tcp_keepalive" json:"tcp_keepalive"`
|
||||||
|
// Custom404Page specifies a path to a custom 404 page to display. If this
|
||||||
|
// value is "", a default page will be displayed. By default, this value is
|
||||||
|
// "".
|
||||||
|
Custom404Page string `ini:"custom_404_page" json:"custom_404_page"`
|
||||||
|
|
||||||
|
// AllowPorts specifies a set of ports that clients are able to proxy to.
|
||||||
|
// If the length of this value is 0, all ports are allowed. By default,
|
||||||
|
// this value is an empty set.
|
||||||
|
AllowPorts map[int]struct{} `ini:"-" json:"-"`
|
||||||
|
// MaxPoolCount specifies the maximum pool size for each proxy. By default,
|
||||||
|
// this value is 5.
|
||||||
|
MaxPoolCount int64 `ini:"max_pool_count" json:"max_pool_count"`
|
||||||
|
// MaxPortsPerClient specifies the maximum number of ports a single client
|
||||||
|
// may proxy to. If this value is 0, no limit will be applied. By default,
|
||||||
|
// this value is 0.
|
||||||
|
MaxPortsPerClient int64 `ini:"max_ports_per_client" json:"max_ports_per_client"`
|
||||||
|
// TLSOnly specifies whether to only accept TLS-encrypted connections.
|
||||||
|
// By default, the value is false.
|
||||||
|
TLSOnly bool `ini:"tls_only" json:"tls_only"`
|
||||||
|
// TLSCertFile specifies the path of the cert file that the server will
|
||||||
|
// load. If "tls_cert_file", "tls_key_file" are valid, the server will use this
|
||||||
|
// supplied tls configuration. Otherwise, the server will use the tls
|
||||||
|
// configuration generated by itself.
|
||||||
|
TLSCertFile string `ini:"tls_cert_file" json:"tls_cert_file"`
|
||||||
|
// TLSKeyFile specifies the path of the secret key that the server will
|
||||||
|
// load. If "tls_cert_file", "tls_key_file" are valid, the server will use this
|
||||||
|
// supplied tls configuration. Otherwise, the server will use the tls
|
||||||
|
// configuration generated by itself.
|
||||||
|
TLSKeyFile string `ini:"tls_key_file" json:"tls_key_file"`
|
||||||
|
// TLSTrustedCaFile specifies the paths of the client cert files that the
|
||||||
|
// server will load. It only works when "tls_only" is true. If
|
||||||
|
// "tls_trusted_ca_file" is valid, the server will verify each client's
|
||||||
|
// certificate.
|
||||||
|
TLSTrustedCaFile string `ini:"tls_trusted_ca_file" json:"tls_trusted_ca_file"`
|
||||||
|
// HeartBeatTimeout specifies the maximum time to wait for a heartbeat
|
||||||
|
// before terminating the connection. It is not recommended to change this
|
||||||
|
// value. By default, this value is 90. Set negative value to disable it.
|
||||||
|
HeartbeatTimeout int64 `ini:"heartbeat_timeout" json:"heartbeat_timeout"`
|
||||||
|
// UserConnTimeout specifies the maximum time to wait for a work
|
||||||
|
// connection. By default, this value is 10.
|
||||||
|
UserConnTimeout int64 `ini:"user_conn_timeout" json:"user_conn_timeout"`
|
||||||
|
// HTTPPlugins specify the server plugins support HTTP protocol.
|
||||||
|
HTTPPlugins map[string]plugin.HTTPPluginOptions `ini:"-" json:"http_plugins"`
|
||||||
|
// UDPPacketSize specifies the UDP packet size
|
||||||
|
// By default, this value is 1500
|
||||||
|
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
|
||||||
|
// Enable golang pprof handlers in dashboard listener.
|
||||||
|
// Dashboard port must be set first.
|
||||||
|
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultServerConf returns a server configuration with reasonable
|
||||||
|
// defaults.
|
||||||
|
func GetDefaultServerConf() ServerCommonConf {
|
||||||
|
return ServerCommonConf{
|
||||||
|
ServerConfig: auth.GetDefaultServerConf(),
|
||||||
|
BindAddr: "0.0.0.0",
|
||||||
|
BindPort: 7000,
|
||||||
|
QUICKeepalivePeriod: 10,
|
||||||
|
QUICMaxIdleTimeout: 30,
|
||||||
|
QUICMaxIncomingStreams: 100000,
|
||||||
|
VhostHTTPTimeout: 60,
|
||||||
|
DashboardAddr: "0.0.0.0",
|
||||||
|
LogFile: "console",
|
||||||
|
LogWay: "console",
|
||||||
|
LogLevel: "info",
|
||||||
|
LogMaxDays: 3,
|
||||||
|
DetailedErrorsToClient: true,
|
||||||
|
TCPMux: true,
|
||||||
|
TCPMuxKeepaliveInterval: 60,
|
||||||
|
TCPKeepAlive: 7200,
|
||||||
|
AllowPorts: make(map[int]struct{}),
|
||||||
|
MaxPoolCount: 5,
|
||||||
|
MaxPortsPerClient: 0,
|
||||||
|
HeartbeatTimeout: 90,
|
||||||
|
UserConnTimeout: 10,
|
||||||
|
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
|
||||||
|
UDPPacketSize: 1500,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
||||||
|
f, err := ini.LoadSources(ini.LoadOptions{
|
||||||
|
Insensitive: false,
|
||||||
|
InsensitiveSections: false,
|
||||||
|
InsensitiveKeys: false,
|
||||||
|
IgnoreInlineComment: true,
|
||||||
|
AllowBooleanKeys: true,
|
||||||
|
}, source)
|
||||||
|
if err != nil {
|
||||||
|
return ServerCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := f.GetSection("common")
|
||||||
|
if err != nil {
|
||||||
|
return ServerCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
common := GetDefaultServerConf()
|
||||||
|
err = s.MapTo(&common)
|
||||||
|
if err != nil {
|
||||||
|
return ServerCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow_ports
|
||||||
|
allowPortStr := s.Key("allow_ports").String()
|
||||||
|
if allowPortStr != "" {
|
||||||
|
allowPorts, err := util.ParseRangeNumbers(allowPortStr)
|
||||||
|
if err != nil {
|
||||||
|
return ServerCommonConf{}, fmt.Errorf("invalid allow_ports: %v", err)
|
||||||
|
}
|
||||||
|
for _, port := range allowPorts {
|
||||||
|
common.AllowPorts[int(port)] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// plugin.xxx
|
||||||
|
pluginOpts := make(map[string]plugin.HTTPPluginOptions)
|
||||||
|
for _, section := range f.Sections() {
|
||||||
|
name := section.Name()
|
||||||
|
if !strings.HasPrefix(name, "plugin.") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
opt, err := loadHTTPPluginOpt(section)
|
||||||
|
if err != nil {
|
||||||
|
return ServerCommonConf{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginOpts[opt.Name] = *opt
|
||||||
|
}
|
||||||
|
common.HTTPPlugins = pluginOpts
|
||||||
|
|
||||||
|
return common, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *ServerCommonConf) Complete() {
|
||||||
|
if cfg.LogFile == "console" {
|
||||||
|
cfg.LogWay = "console"
|
||||||
|
} else {
|
||||||
|
cfg.LogWay = "file"
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.ProxyBindAddr == "" {
|
||||||
|
cfg.ProxyBindAddr = cfg.BindAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.TLSTrustedCaFile != "" {
|
||||||
|
cfg.TLSOnly = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *ServerCommonConf) Validate() error {
|
||||||
|
if !cfg.DashboardTLSMode {
|
||||||
|
if cfg.DashboardTLSCertFile != "" {
|
||||||
|
fmt.Println("WARNING! dashboard_tls_cert_file is invalid when dashboard_tls_mode is false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.DashboardTLSKeyFile != "" {
|
||||||
|
fmt.Println("WARNING! dashboard_tls_key_file is invalid when dashboard_tls_mode is false")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if cfg.DashboardTLSCertFile == "" {
|
||||||
|
return fmt.Errorf("ERROR! dashboard_tls_cert_file must be specified when dashboard_tls_mode is true")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.DashboardTLSKeyFile == "" {
|
||||||
|
return fmt.Errorf("ERROR! dashboard_tls_cert_file must be specified when dashboard_tls_mode is true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validator.New().Struct(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadHTTPPluginOpt(section *ini.Section) (*plugin.HTTPPluginOptions, error) {
|
||||||
|
name := strings.TrimSpace(strings.TrimPrefix(section.Name(), "plugin."))
|
||||||
|
|
||||||
|
opt := new(plugin.HTTPPluginOptions)
|
||||||
|
err := section.MapTo(opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.Name = name
|
||||||
|
|
||||||
|
return opt, nil
|
||||||
|
}
|
@@ -1,477 +0,0 @@
|
|||||||
// Copyright 2016 fatedier, fatedier@gmail.com
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
|
||||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
|
||||||
"github.com/fatedier/frp/pkg/util/util"
|
|
||||||
|
|
||||||
ini "github.com/vaughan0/go-ini"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ServerCommonConf contains information for a server service. It is
|
|
||||||
// recommended to use GetDefaultServerConf instead of creating this object
|
|
||||||
// directly, so that all unspecified fields have reasonable default values.
|
|
||||||
type ServerCommonConf struct {
|
|
||||||
auth.ServerConfig
|
|
||||||
// BindAddr specifies the address that the server binds to. By default,
|
|
||||||
// this value is "0.0.0.0".
|
|
||||||
BindAddr string `json:"bind_addr"`
|
|
||||||
// BindPort specifies the port that the server listens on. By default, this
|
|
||||||
// value is 7000.
|
|
||||||
BindPort int `json:"bind_port"`
|
|
||||||
// BindUDPPort specifies the UDP port that the server listens on. If this
|
|
||||||
// value is 0, the server will not listen for UDP connections. By default,
|
|
||||||
// this value is 0
|
|
||||||
BindUDPPort int `json:"bind_udp_port"`
|
|
||||||
// KCPBindPort specifies the KCP port that the server listens on. If this
|
|
||||||
// value is 0, the server will not listen for KCP connections. By default,
|
|
||||||
// this value is 0.
|
|
||||||
KCPBindPort int `json:"kcp_bind_port"`
|
|
||||||
// ProxyBindAddr specifies the address that the proxy binds to. This value
|
|
||||||
// may be the same as BindAddr. By default, this value is "0.0.0.0".
|
|
||||||
ProxyBindAddr string `json:"proxy_bind_addr"`
|
|
||||||
// VhostHTTPPort specifies the port that the server listens for HTTP Vhost
|
|
||||||
// requests. If this value is 0, the server will not listen for HTTP
|
|
||||||
// requests. By default, this value is 0.
|
|
||||||
VhostHTTPPort int `json:"vhost_http_port"`
|
|
||||||
// VhostHTTPSPort specifies the port that the server listens for HTTPS
|
|
||||||
// Vhost requests. If this value is 0, the server will not listen for HTTPS
|
|
||||||
// requests. By default, this value is 0.
|
|
||||||
VhostHTTPSPort int `json:"vhost_https_port"`
|
|
||||||
// TCPMuxHTTPConnectPort specifies the port that the server listens for TCP
|
|
||||||
// HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
|
|
||||||
// requests on one single port. If it's not - it will listen on this value for
|
|
||||||
// HTTP CONNECT requests. By default, this value is 0.
|
|
||||||
TCPMuxHTTPConnectPort int `json:"tcpmux_httpconnect_port"`
|
|
||||||
// VhostHTTPTimeout specifies the response header timeout for the Vhost
|
|
||||||
// HTTP server, in seconds. By default, this value is 60.
|
|
||||||
VhostHTTPTimeout int64 `json:"vhost_http_timeout"`
|
|
||||||
// DashboardAddr specifies the address that the dashboard binds to. By
|
|
||||||
// default, this value is "0.0.0.0".
|
|
||||||
DashboardAddr string `json:"dashboard_addr"`
|
|
||||||
// DashboardPort specifies the port that the dashboard listens on. If this
|
|
||||||
// value is 0, the dashboard will not be started. By default, this value is
|
|
||||||
// 0.
|
|
||||||
DashboardPort int `json:"dashboard_port"`
|
|
||||||
// DashboardUser specifies the username that the dashboard will use for
|
|
||||||
// login. By default, this value is "admin".
|
|
||||||
DashboardUser string `json:"dashboard_user"`
|
|
||||||
// DashboardUser specifies the password that the dashboard will use for
|
|
||||||
// login. By default, this value is "admin".
|
|
||||||
DashboardPwd string `json:"dashboard_pwd"`
|
|
||||||
// EnablePrometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port}
|
|
||||||
// in /metrics api.
|
|
||||||
EnablePrometheus bool `json:"enable_prometheus"`
|
|
||||||
// AssetsDir specifies the local directory that the dashboard will load
|
|
||||||
// resources from. If this value is "", assets will be loaded from the
|
|
||||||
// bundled executable using statik. By default, this value is "".
|
|
||||||
AssetsDir string `json:"asserts_dir"`
|
|
||||||
// LogFile specifies a file where logs will be written to. This value will
|
|
||||||
// only be used if LogWay is set appropriately. By default, this value is
|
|
||||||
// "console".
|
|
||||||
LogFile string `json:"log_file"`
|
|
||||||
// LogWay specifies the way logging is managed. Valid values are "console"
|
|
||||||
// or "file". If "console" is used, logs will be printed to stdout. If
|
|
||||||
// "file" is used, logs will be printed to LogFile. By default, this value
|
|
||||||
// is "console".
|
|
||||||
LogWay string `json:"log_way"`
|
|
||||||
// LogLevel specifies the minimum log level. Valid values are "trace",
|
|
||||||
// "debug", "info", "warn", and "error". By default, this value is "info".
|
|
||||||
LogLevel string `json:"log_level"`
|
|
||||||
// LogMaxDays specifies the maximum number of days to store log information
|
|
||||||
// before deletion. This is only used if LogWay == "file". By default, this
|
|
||||||
// value is 0.
|
|
||||||
LogMaxDays int64 `json:"log_max_days"`
|
|
||||||
// DisableLogColor disables log colors when LogWay == "console" when set to
|
|
||||||
// true. By default, this value is false.
|
|
||||||
DisableLogColor bool `json:"disable_log_color"`
|
|
||||||
// DetailedErrorsToClient defines whether to send the specific error (with
|
|
||||||
// debug info) to frpc. By default, this value is true.
|
|
||||||
DetailedErrorsToClient bool `json:"detailed_errors_to_client"`
|
|
||||||
|
|
||||||
// SubDomainHost specifies the domain that will be attached to sub-domains
|
|
||||||
// requested by the client when using Vhost proxying. For example, if this
|
|
||||||
// value is set to "frps.com" and the client requested the subdomain
|
|
||||||
// "test", the resulting URL would be "test.frps.com". By default, this
|
|
||||||
// value is "".
|
|
||||||
SubDomainHost string `json:"subdomain_host"`
|
|
||||||
// TCPMux toggles TCP stream multiplexing. This allows multiple requests
|
|
||||||
// from a client to share a single TCP connection. By default, this value
|
|
||||||
// is true.
|
|
||||||
TCPMux bool `json:"tcp_mux"`
|
|
||||||
// Custom404Page specifies a path to a custom 404 page to display. If this
|
|
||||||
// value is "", a default page will be displayed. By default, this value is
|
|
||||||
// "".
|
|
||||||
Custom404Page string `json:"custom_404_page"`
|
|
||||||
|
|
||||||
// AllowPorts specifies a set of ports that clients are able to proxy to.
|
|
||||||
// If the length of this value is 0, all ports are allowed. By default,
|
|
||||||
// this value is an empty set.
|
|
||||||
AllowPorts map[int]struct{}
|
|
||||||
// MaxPoolCount specifies the maximum pool size for each proxy. By default,
|
|
||||||
// this value is 5.
|
|
||||||
MaxPoolCount int64 `json:"max_pool_count"`
|
|
||||||
// MaxPortsPerClient specifies the maximum number of ports a single client
|
|
||||||
// may proxy to. If this value is 0, no limit will be applied. By default,
|
|
||||||
// this value is 0.
|
|
||||||
MaxPortsPerClient int64 `json:"max_ports_per_client"`
|
|
||||||
// TLSOnly specifies whether to only accept TLS-encrypted connections.
|
|
||||||
// By default, the value is false.
|
|
||||||
TLSOnly bool `json:"tls_only"`
|
|
||||||
// TLSCertFile specifies the path of the cert file that the server will
|
|
||||||
// load. If "tls_cert_file", "tls_key_file" are valid, the server will use this
|
|
||||||
// supplied tls configuration. Otherwise, the server will use the tls
|
|
||||||
// configuration generated by itself.
|
|
||||||
TLSCertFile string `json:"tls_cert_file"`
|
|
||||||
// TLSKeyFile specifies the path of the secret key that the server will
|
|
||||||
// load. If "tls_cert_file", "tls_key_file" are valid, the server will use this
|
|
||||||
// supplied tls configuration. Otherwise, the server will use the tls
|
|
||||||
// configuration generated by itself.
|
|
||||||
TLSKeyFile string `json:"tls_key_file"`
|
|
||||||
// TLSTrustedCaFile specifies the paths of the client cert files that the
|
|
||||||
// server will load. It only works when "tls_only" is true. If
|
|
||||||
// "tls_trusted_ca_file" is valid, the server will verify each client's
|
|
||||||
// certificate.
|
|
||||||
TLSTrustedCaFile string `json:"tls_trusted_ca_file"`
|
|
||||||
// HeartBeatTimeout specifies the maximum time to wait for a heartbeat
|
|
||||||
// before terminating the connection. It is not recommended to change this
|
|
||||||
// value. By default, this value is 90.
|
|
||||||
HeartBeatTimeout int64 `json:"heart_beat_timeout"`
|
|
||||||
// UserConnTimeout specifies the maximum time to wait for a work
|
|
||||||
// connection. By default, this value is 10.
|
|
||||||
UserConnTimeout int64 `json:"user_conn_timeout"`
|
|
||||||
// HTTPPlugins specify the server plugins support HTTP protocol.
|
|
||||||
HTTPPlugins map[string]plugin.HTTPPluginOptions `json:"http_plugins"`
|
|
||||||
// UDPPacketSize specifies the UDP packet size
|
|
||||||
// By default, this value is 1500
|
|
||||||
UDPPacketSize int64 `json:"udp_packet_size"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDefaultServerConf returns a server configuration with reasonable
|
|
||||||
// defaults.
|
|
||||||
func GetDefaultServerConf() ServerCommonConf {
|
|
||||||
return ServerCommonConf{
|
|
||||||
BindAddr: "0.0.0.0",
|
|
||||||
BindPort: 7000,
|
|
||||||
BindUDPPort: 0,
|
|
||||||
KCPBindPort: 0,
|
|
||||||
ProxyBindAddr: "0.0.0.0",
|
|
||||||
VhostHTTPPort: 0,
|
|
||||||
VhostHTTPSPort: 0,
|
|
||||||
TCPMuxHTTPConnectPort: 0,
|
|
||||||
VhostHTTPTimeout: 60,
|
|
||||||
DashboardAddr: "0.0.0.0",
|
|
||||||
DashboardPort: 0,
|
|
||||||
DashboardUser: "admin",
|
|
||||||
DashboardPwd: "admin",
|
|
||||||
EnablePrometheus: false,
|
|
||||||
AssetsDir: "",
|
|
||||||
LogFile: "console",
|
|
||||||
LogWay: "console",
|
|
||||||
LogLevel: "info",
|
|
||||||
LogMaxDays: 3,
|
|
||||||
DisableLogColor: false,
|
|
||||||
DetailedErrorsToClient: true,
|
|
||||||
SubDomainHost: "",
|
|
||||||
TCPMux: true,
|
|
||||||
AllowPorts: make(map[int]struct{}),
|
|
||||||
MaxPoolCount: 5,
|
|
||||||
MaxPortsPerClient: 0,
|
|
||||||
TLSOnly: false,
|
|
||||||
TLSCertFile: "",
|
|
||||||
TLSKeyFile: "",
|
|
||||||
TLSTrustedCaFile: "",
|
|
||||||
HeartBeatTimeout: 90,
|
|
||||||
UserConnTimeout: 10,
|
|
||||||
Custom404Page: "",
|
|
||||||
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
|
|
||||||
UDPPacketSize: 1500,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalServerConfFromIni parses the contents of a server configuration ini
|
|
||||||
// file and returns the resulting server configuration.
|
|
||||||
func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error) {
|
|
||||||
cfg = GetDefaultServerConf()
|
|
||||||
|
|
||||||
conf, err := ini.Load(strings.NewReader(content))
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("parse ini conf file error: %v", err)
|
|
||||||
return ServerCommonConf{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
UnmarshalPluginsFromIni(conf, &cfg)
|
|
||||||
|
|
||||||
cfg.ServerConfig = auth.UnmarshalServerConfFromIni(conf)
|
|
||||||
|
|
||||||
var (
|
|
||||||
tmpStr string
|
|
||||||
ok bool
|
|
||||||
v int64
|
|
||||||
)
|
|
||||||
if tmpStr, ok = conf.Get("common", "bind_addr"); ok {
|
|
||||||
cfg.BindAddr = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "bind_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid bind_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.BindPort = int(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "bind_udp_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid bind_udp_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.BindUDPPort = int(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "kcp_bind_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid kcp_bind_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.KCPBindPort = int(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "proxy_bind_addr"); ok {
|
|
||||||
cfg.ProxyBindAddr = tmpStr
|
|
||||||
} else {
|
|
||||||
cfg.ProxyBindAddr = cfg.BindAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "vhost_http_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid vhost_http_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.VhostHTTPPort = int(v)
|
|
||||||
} else {
|
|
||||||
cfg.VhostHTTPPort = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "vhost_https_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid vhost_https_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.VhostHTTPSPort = int(v)
|
|
||||||
} else {
|
|
||||||
cfg.VhostHTTPSPort = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tcpmux_httpconnect_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid tcpmux_httpconnect_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.TCPMuxHTTPConnectPort = int(v)
|
|
||||||
} else {
|
|
||||||
cfg.TCPMuxHTTPConnectPort = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "vhost_http_timeout"); ok {
|
|
||||||
v, errRet := strconv.ParseInt(tmpStr, 10, 64)
|
|
||||||
if errRet != nil || v < 0 {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid vhost_http_timeout")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.VhostHTTPTimeout = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dashboard_addr"); ok {
|
|
||||||
cfg.DashboardAddr = tmpStr
|
|
||||||
} else {
|
|
||||||
cfg.DashboardAddr = cfg.BindAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dashboard_port"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid dashboard_port")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.DashboardPort = int(v)
|
|
||||||
} else {
|
|
||||||
cfg.DashboardPort = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dashboard_user"); ok {
|
|
||||||
cfg.DashboardUser = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "dashboard_pwd"); ok {
|
|
||||||
cfg.DashboardPwd = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "enable_prometheus"); ok && tmpStr == "true" {
|
|
||||||
cfg.EnablePrometheus = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "assets_dir"); ok {
|
|
||||||
cfg.AssetsDir = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_file"); ok {
|
|
||||||
cfg.LogFile = tmpStr
|
|
||||||
if cfg.LogFile == "console" {
|
|
||||||
cfg.LogWay = "console"
|
|
||||||
} else {
|
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_level"); ok {
|
|
||||||
cfg.LogLevel = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "log_max_days"); ok {
|
|
||||||
v, err = strconv.ParseInt(tmpStr, 10, 64)
|
|
||||||
if err == nil {
|
|
||||||
cfg.LogMaxDays = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "disable_log_color"); ok && tmpStr == "true" {
|
|
||||||
cfg.DisableLogColor = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "detailed_errors_to_client"); ok && tmpStr == "false" {
|
|
||||||
cfg.DetailedErrorsToClient = false
|
|
||||||
} else {
|
|
||||||
cfg.DetailedErrorsToClient = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok {
|
|
||||||
// e.g. 1000-2000,2001,2002,3000-4000
|
|
||||||
ports, errRet := util.ParseRangeNumbers(allowPortsStr)
|
|
||||||
if errRet != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: allow_ports: %v", errRet)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, port := range ports {
|
|
||||||
cfg.AllowPorts[int(port)] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "max_pool_count"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid max_pool_count")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if v < 0 {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid max_pool_count")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.MaxPoolCount = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "max_ports_per_client"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid max_ports_per_client")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if v < 0 {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid max_ports_per_client")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.MaxPortsPerClient = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "subdomain_host"); ok {
|
|
||||||
cfg.SubDomainHost = strings.ToLower(strings.TrimSpace(tmpStr))
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tcp_mux"); ok && tmpStr == "false" {
|
|
||||||
cfg.TCPMux = false
|
|
||||||
} else {
|
|
||||||
cfg.TCPMux = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "custom_404_page"); ok {
|
|
||||||
cfg.Custom404Page = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "heartbeat_timeout"); ok {
|
|
||||||
v, errRet := strconv.ParseInt(tmpStr, 10, 64)
|
|
||||||
if errRet != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: heartbeat_timeout is incorrect")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.HeartBeatTimeout = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "tls_only"); ok && tmpStr == "true" {
|
|
||||||
cfg.TLSOnly = true
|
|
||||||
} else {
|
|
||||||
cfg.TLSOnly = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "udp_packet_size"); ok {
|
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: invalid udp_packet_size")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cfg.UDPPacketSize = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok := conf.Get("common", "tls_cert_file"); ok {
|
|
||||||
cfg.TLSCertFile = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok := conf.Get("common", "tls_key_file"); ok {
|
|
||||||
cfg.TLSKeyFile = tmpStr
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok := conf.Get("common", "tls_trusted_ca_file"); ok {
|
|
||||||
cfg.TLSTrustedCaFile = tmpStr
|
|
||||||
cfg.TLSOnly = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmarshalPluginsFromIni(sections ini.File, cfg *ServerCommonConf) {
|
|
||||||
for name, section := range sections {
|
|
||||||
if strings.HasPrefix(name, "plugin.") {
|
|
||||||
name = strings.TrimSpace(strings.TrimPrefix(name, "plugin."))
|
|
||||||
options := plugin.HTTPPluginOptions{
|
|
||||||
Name: name,
|
|
||||||
Addr: section["addr"],
|
|
||||||
Path: section["path"],
|
|
||||||
Ops: strings.Split(section["ops"], ","),
|
|
||||||
}
|
|
||||||
for i := range options.Ops {
|
|
||||||
options.Ops[i] = strings.TrimSpace(options.Ops[i])
|
|
||||||
}
|
|
||||||
cfg.HTTPPlugins[name] = options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *ServerCommonConf) Check() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
218
pkg/config/server_test.go
Normal file
218
pkg/config/server_test.go
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
|
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_LoadServerCommonConf(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testcases := []struct {
|
||||||
|
source []byte
|
||||||
|
expected ServerCommonConf
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
source: []byte(`
|
||||||
|
# [common] is integral section
|
||||||
|
[common]
|
||||||
|
bind_addr = 0.0.0.9
|
||||||
|
bind_port = 7009
|
||||||
|
bind_udp_port = 7008
|
||||||
|
kcp_bind_port = 7007
|
||||||
|
proxy_bind_addr = 127.0.0.9
|
||||||
|
vhost_http_port = 89
|
||||||
|
vhost_https_port = 449
|
||||||
|
vhost_http_timeout = 69
|
||||||
|
tcpmux_httpconnect_port = 1339
|
||||||
|
dashboard_addr = 0.0.0.9
|
||||||
|
dashboard_port = 7509
|
||||||
|
dashboard_user = admin9
|
||||||
|
dashboard_pwd = admin9
|
||||||
|
enable_prometheus
|
||||||
|
assets_dir = ./static9
|
||||||
|
log_file = ./frps.log9
|
||||||
|
log_way = file
|
||||||
|
log_level = info9
|
||||||
|
log_max_days = 39
|
||||||
|
disable_log_color = false
|
||||||
|
detailed_errors_to_client
|
||||||
|
authentication_method = token
|
||||||
|
authenticate_heartbeats = false
|
||||||
|
authenticate_new_work_conns = false
|
||||||
|
token = 123456789
|
||||||
|
oidc_issuer = test9
|
||||||
|
oidc_audience = test9
|
||||||
|
oidc_skip_expiry_check
|
||||||
|
oidc_skip_issuer_check
|
||||||
|
heartbeat_timeout = 99
|
||||||
|
user_conn_timeout = 9
|
||||||
|
allow_ports = 10-12,99
|
||||||
|
max_pool_count = 59
|
||||||
|
max_ports_per_client = 9
|
||||||
|
tls_only = false
|
||||||
|
tls_cert_file = server.crt
|
||||||
|
tls_key_file = server.key
|
||||||
|
tls_trusted_ca_file = ca.crt
|
||||||
|
subdomain_host = frps.com
|
||||||
|
tcp_mux
|
||||||
|
udp_packet_size = 1509
|
||||||
|
[plugin.user-manager]
|
||||||
|
addr = 127.0.0.1:9009
|
||||||
|
path = /handler
|
||||||
|
ops = Login
|
||||||
|
[plugin.port-manager]
|
||||||
|
addr = 127.0.0.1:9009
|
||||||
|
path = /handler
|
||||||
|
ops = NewProxy
|
||||||
|
tls_verify
|
||||||
|
`),
|
||||||
|
expected: ServerCommonConf{
|
||||||
|
ServerConfig: auth.ServerConfig{
|
||||||
|
BaseConfig: auth.BaseConfig{
|
||||||
|
AuthenticationMethod: "token",
|
||||||
|
AuthenticateHeartBeats: false,
|
||||||
|
AuthenticateNewWorkConns: false,
|
||||||
|
},
|
||||||
|
TokenConfig: auth.TokenConfig{
|
||||||
|
Token: "123456789",
|
||||||
|
},
|
||||||
|
OidcServerConfig: auth.OidcServerConfig{
|
||||||
|
OidcIssuer: "test9",
|
||||||
|
OidcAudience: "test9",
|
||||||
|
OidcSkipExpiryCheck: true,
|
||||||
|
OidcSkipIssuerCheck: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BindAddr: "0.0.0.9",
|
||||||
|
BindPort: 7009,
|
||||||
|
BindUDPPort: 7008,
|
||||||
|
KCPBindPort: 7007,
|
||||||
|
QUICKeepalivePeriod: 10,
|
||||||
|
QUICMaxIdleTimeout: 30,
|
||||||
|
QUICMaxIncomingStreams: 100000,
|
||||||
|
ProxyBindAddr: "127.0.0.9",
|
||||||
|
VhostHTTPPort: 89,
|
||||||
|
VhostHTTPSPort: 449,
|
||||||
|
VhostHTTPTimeout: 69,
|
||||||
|
TCPMuxHTTPConnectPort: 1339,
|
||||||
|
DashboardAddr: "0.0.0.9",
|
||||||
|
DashboardPort: 7509,
|
||||||
|
DashboardUser: "admin9",
|
||||||
|
DashboardPwd: "admin9",
|
||||||
|
EnablePrometheus: true,
|
||||||
|
AssetsDir: "./static9",
|
||||||
|
LogFile: "./frps.log9",
|
||||||
|
LogWay: "file",
|
||||||
|
LogLevel: "info9",
|
||||||
|
LogMaxDays: 39,
|
||||||
|
DisableLogColor: false,
|
||||||
|
DetailedErrorsToClient: true,
|
||||||
|
HeartbeatTimeout: 99,
|
||||||
|
UserConnTimeout: 9,
|
||||||
|
AllowPorts: map[int]struct{}{
|
||||||
|
10: {},
|
||||||
|
11: {},
|
||||||
|
12: {},
|
||||||
|
99: {},
|
||||||
|
},
|
||||||
|
MaxPoolCount: 59,
|
||||||
|
MaxPortsPerClient: 9,
|
||||||
|
TLSOnly: true,
|
||||||
|
TLSCertFile: "server.crt",
|
||||||
|
TLSKeyFile: "server.key",
|
||||||
|
TLSTrustedCaFile: "ca.crt",
|
||||||
|
SubDomainHost: "frps.com",
|
||||||
|
TCPMux: true,
|
||||||
|
TCPMuxKeepaliveInterval: 60,
|
||||||
|
TCPKeepAlive: 7200,
|
||||||
|
UDPPacketSize: 1509,
|
||||||
|
|
||||||
|
HTTPPlugins: map[string]plugin.HTTPPluginOptions{
|
||||||
|
"user-manager": {
|
||||||
|
Name: "user-manager",
|
||||||
|
Addr: "127.0.0.1:9009",
|
||||||
|
Path: "/handler",
|
||||||
|
Ops: []string{"Login"},
|
||||||
|
},
|
||||||
|
"port-manager": {
|
||||||
|
Name: "port-manager",
|
||||||
|
Addr: "127.0.0.1:9009",
|
||||||
|
Path: "/handler",
|
||||||
|
Ops: []string{"NewProxy"},
|
||||||
|
TLSVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: []byte(`
|
||||||
|
# [common] is integral section
|
||||||
|
[common]
|
||||||
|
bind_addr = 0.0.0.9
|
||||||
|
bind_port = 7009
|
||||||
|
bind_udp_port = 7008
|
||||||
|
`),
|
||||||
|
expected: ServerCommonConf{
|
||||||
|
ServerConfig: auth.ServerConfig{
|
||||||
|
BaseConfig: auth.BaseConfig{
|
||||||
|
AuthenticationMethod: "token",
|
||||||
|
AuthenticateHeartBeats: false,
|
||||||
|
AuthenticateNewWorkConns: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BindAddr: "0.0.0.9",
|
||||||
|
BindPort: 7009,
|
||||||
|
BindUDPPort: 7008,
|
||||||
|
QUICKeepalivePeriod: 10,
|
||||||
|
QUICMaxIdleTimeout: 30,
|
||||||
|
QUICMaxIncomingStreams: 100000,
|
||||||
|
ProxyBindAddr: "0.0.0.9",
|
||||||
|
VhostHTTPTimeout: 60,
|
||||||
|
DashboardAddr: "0.0.0.0",
|
||||||
|
DashboardUser: "",
|
||||||
|
DashboardPwd: "",
|
||||||
|
EnablePrometheus: false,
|
||||||
|
LogFile: "console",
|
||||||
|
LogWay: "console",
|
||||||
|
LogLevel: "info",
|
||||||
|
LogMaxDays: 3,
|
||||||
|
DetailedErrorsToClient: true,
|
||||||
|
TCPMux: true,
|
||||||
|
TCPMuxKeepaliveInterval: 60,
|
||||||
|
TCPKeepAlive: 7200,
|
||||||
|
AllowPorts: make(map[int]struct{}),
|
||||||
|
MaxPoolCount: 5,
|
||||||
|
HeartbeatTimeout: 90,
|
||||||
|
UserConnTimeout: 10,
|
||||||
|
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
|
||||||
|
UDPPacketSize: 1500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testcases {
|
||||||
|
actual, err := UnmarshalServerConfFromIni(c.source)
|
||||||
|
assert.NoError(err)
|
||||||
|
actual.Complete()
|
||||||
|
assert.Equal(c.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
@@ -41,6 +41,15 @@ func NewBandwidthQuantity(s string) (BandwidthQuantity, error) {
|
|||||||
return q, nil
|
return q, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MustBandwidthQuantity(s string) BandwidthQuantity {
|
||||||
|
q := BandwidthQuantity{}
|
||||||
|
err := q.UnmarshalString(s)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
func (q *BandwidthQuantity) Equal(u *BandwidthQuantity) bool {
|
func (q *BandwidthQuantity) Equal(u *BandwidthQuantity) bool {
|
||||||
if q == nil && u == nil {
|
if q == nil && u == nil {
|
||||||
return true
|
return true
|
||||||
@@ -66,21 +75,22 @@ func (q *BandwidthQuantity) UnmarshalString(s string) error {
|
|||||||
f float64
|
f float64
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if strings.HasSuffix(s, "MB") {
|
switch {
|
||||||
|
case strings.HasSuffix(s, "MB"):
|
||||||
base = MB
|
base = MB
|
||||||
fstr := strings.TrimSuffix(s, "MB")
|
fstr := strings.TrimSuffix(s, "MB")
|
||||||
f, err = strconv.ParseFloat(fstr, 64)
|
f, err = strconv.ParseFloat(fstr, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if strings.HasSuffix(s, "KB") {
|
case strings.HasSuffix(s, "KB"):
|
||||||
base = KB
|
base = KB
|
||||||
fstr := strings.TrimSuffix(s, "KB")
|
fstr := strings.TrimSuffix(s, "KB")
|
||||||
f, err = strconv.ParseFloat(fstr, 64)
|
f, err = strconv.ParseFloat(fstr, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
return errors.New("unit not support")
|
return errors.New("unit not support")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
51
pkg/config/utils.go
Normal file
51
pkg/config/utils.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMapWithoutPrefix(set map[string]string, prefix string) map[string]string {
|
||||||
|
m := make(map[string]string)
|
||||||
|
|
||||||
|
for key, value := range set {
|
||||||
|
if strings.HasPrefix(key, prefix) {
|
||||||
|
m[strings.TrimPrefix(key, prefix)] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(m) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMapByPrefix(set map[string]string, prefix string) map[string]string {
|
||||||
|
m := make(map[string]string)
|
||||||
|
|
||||||
|
for key, value := range set {
|
||||||
|
if strings.HasPrefix(key, prefix) {
|
||||||
|
m[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(m) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
@@ -1,26 +1,37 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var glbEnvs map[string]string
|
||||||
glbEnvs map[string]string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glbEnvs = make(map[string]string)
|
glbEnvs = make(map[string]string)
|
||||||
envs := os.Environ()
|
envs := os.Environ()
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
kv := strings.Split(env, "=")
|
pair := strings.SplitN(env, "=", 2)
|
||||||
if len(kv) != 2 {
|
if len(pair) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glbEnvs[kv[0]] = kv[1]
|
glbEnvs[pair[0]] = pair[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,8 +45,8 @@ func GetValues() *Values {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderContent(in string) (out string, err error) {
|
func RenderContent(in []byte) (out []byte, err error) {
|
||||||
tmpl, errRet := template.New("frp").Parse(in)
|
tmpl, errRet := template.New("frp").Parse(string(in))
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
err = errRet
|
err = errRet
|
||||||
return
|
return
|
||||||
@@ -47,18 +58,17 @@ func RenderContent(in string) (out string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
out = buffer.String()
|
out = buffer.Bytes()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRenderedConfFromFile(path string) (out string, err error) {
|
func GetRenderedConfFromFile(path string) (out []byte, err error) {
|
||||||
var b []byte
|
var b []byte
|
||||||
b, err = ioutil.ReadFile(path)
|
b, err = os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content := string(b)
|
|
||||||
|
|
||||||
out, err = RenderContent(content)
|
out, err = RenderContent(b)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -17,72 +17,89 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
ini "github.com/vaughan0/go-ini"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Visitor
|
||||||
var (
|
var (
|
||||||
visitorConfTypeMap map[string]reflect.Type
|
visitorConfTypeMap = map[string]reflect.Type{
|
||||||
|
consts.STCPProxy: reflect.TypeOf(STCPVisitorConf{}),
|
||||||
|
consts.XTCPProxy: reflect.TypeOf(XTCPVisitorConf{}),
|
||||||
|
consts.SUDPProxy: reflect.TypeOf(SUDPVisitorConf{}),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
visitorConfTypeMap = make(map[string]reflect.Type)
|
|
||||||
visitorConfTypeMap[consts.STCPProxy] = reflect.TypeOf(STCPVisitorConf{})
|
|
||||||
visitorConfTypeMap[consts.XTCPProxy] = reflect.TypeOf(XTCPVisitorConf{})
|
|
||||||
visitorConfTypeMap[consts.SUDPProxy] = reflect.TypeOf(SUDPVisitorConf{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type VisitorConf interface {
|
type VisitorConf interface {
|
||||||
GetBaseInfo() *BaseVisitorConf
|
GetBaseInfo() *BaseVisitorConf
|
||||||
Compare(cmp VisitorConf) bool
|
Compare(cmp VisitorConf) bool
|
||||||
UnmarshalFromIni(prefix string, name string, section ini.Section) error
|
UnmarshalFromIni(prefix string, name string, section *ini.Section) error
|
||||||
Check() error
|
Check() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVisitorConfByType(cfgType string) VisitorConf {
|
type BaseVisitorConf struct {
|
||||||
v, ok := visitorConfTypeMap[cfgType]
|
ProxyName string `ini:"name" json:"name"`
|
||||||
|
ProxyType string `ini:"type" json:"type"`
|
||||||
|
UseEncryption bool `ini:"use_encryption" json:"use_encryption"`
|
||||||
|
UseCompression bool `ini:"use_compression" json:"use_compression"`
|
||||||
|
Role string `ini:"role" json:"role"`
|
||||||
|
Sk string `ini:"sk" json:"sk"`
|
||||||
|
ServerName string `ini:"server_name" json:"server_name"`
|
||||||
|
BindAddr string `ini:"bind_addr" json:"bind_addr"`
|
||||||
|
BindPort int `ini:"bind_port" json:"bind_port"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SUDPVisitorConf struct {
|
||||||
|
BaseVisitorConf `ini:",extends"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type STCPVisitorConf struct {
|
||||||
|
BaseVisitorConf `ini:",extends"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XTCPVisitorConf struct {
|
||||||
|
BaseVisitorConf `ini:",extends"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultVisitorConf creates a empty VisitorConf object by visitorType.
|
||||||
|
// If visitorType doesn't exist, return nil.
|
||||||
|
func DefaultVisitorConf(visitorType string) VisitorConf {
|
||||||
|
v, ok := visitorConfTypeMap[visitorType]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cfg := reflect.New(v).Interface().(VisitorConf)
|
|
||||||
return cfg
|
return reflect.New(v).Interface().(VisitorConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVisitorConfFromIni(prefix string, name string, section ini.Section) (cfg VisitorConf, err error) {
|
// Visitor loaded from ini
|
||||||
cfgType := section["type"]
|
func NewVisitorConfFromIni(prefix string, name string, section *ini.Section) (VisitorConf, error) {
|
||||||
if cfgType == "" {
|
// section.Key: if key not exists, section will set it with default value.
|
||||||
err = fmt.Errorf("visitor [%s] type shouldn't be empty", name)
|
visitorType := section.Key("type").String()
|
||||||
return
|
|
||||||
|
if visitorType == "" {
|
||||||
|
return nil, fmt.Errorf("visitor [%s] type shouldn't be empty", name)
|
||||||
}
|
}
|
||||||
cfg = NewVisitorConfByType(cfgType)
|
|
||||||
if cfg == nil {
|
conf := DefaultVisitorConf(visitorType)
|
||||||
err = fmt.Errorf("visitor [%s] type [%s] error", name, cfgType)
|
if conf == nil {
|
||||||
return
|
return nil, fmt.Errorf("visitor [%s] type [%s] error", name, visitorType)
|
||||||
}
|
}
|
||||||
if err = cfg.UnmarshalFromIni(prefix, name, section); err != nil {
|
|
||||||
return
|
if err := conf.UnmarshalFromIni(prefix, name, section); err != nil {
|
||||||
|
return nil, fmt.Errorf("visitor [%s] type [%s] error", name, visitorType)
|
||||||
}
|
}
|
||||||
if err = cfg.Check(); err != nil {
|
|
||||||
return
|
if err := conf.Check(); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
return conf, nil
|
||||||
|
|
||||||
type BaseVisitorConf struct {
|
|
||||||
ProxyName string `json:"proxy_name"`
|
|
||||||
ProxyType string `json:"proxy_type"`
|
|
||||||
UseEncryption bool `json:"use_encryption"`
|
|
||||||
UseCompression bool `json:"use_compression"`
|
|
||||||
Role string `json:"role"`
|
|
||||||
Sk string `json:"sk"`
|
|
||||||
ServerName string `json:"server_name"`
|
|
||||||
BindAddr string `json:"bind_addr"`
|
|
||||||
BindPort int `json:"bind_port"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base
|
||||||
func (cfg *BaseVisitorConf) GetBaseInfo() *BaseVisitorConf {
|
func (cfg *BaseVisitorConf) GetBaseInfo() *BaseVisitorConf {
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
@@ -118,45 +135,41 @@ func (cfg *BaseVisitorConf) check() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BaseVisitorConf) UnmarshalFromIni(prefix string, name string, section ini.Section) (err error) {
|
func (cfg *BaseVisitorConf) unmarshalFromIni(prefix string, name string, section *ini.Section) error {
|
||||||
var (
|
_ = section
|
||||||
tmpStr string
|
|
||||||
ok bool
|
// Custom decoration after basic unmarshal:
|
||||||
)
|
// proxy name
|
||||||
cfg.ProxyName = prefix + name
|
cfg.ProxyName = prefix + name
|
||||||
cfg.ProxyType = section["type"]
|
|
||||||
|
|
||||||
if tmpStr, ok = section["use_encryption"]; ok && tmpStr == "true" {
|
// server_name
|
||||||
cfg.UseEncryption = true
|
cfg.ServerName = prefix + cfg.ServerName
|
||||||
}
|
|
||||||
if tmpStr, ok = section["use_compression"]; ok && tmpStr == "true" {
|
|
||||||
cfg.UseCompression = true
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.Role = section["role"]
|
// bind_addr
|
||||||
if cfg.Role != "visitor" {
|
if cfg.BindAddr == "" {
|
||||||
return fmt.Errorf("Parse conf error: proxy [%s] incorrect role [%s]", name, cfg.Role)
|
|
||||||
}
|
|
||||||
cfg.Sk = section["sk"]
|
|
||||||
cfg.ServerName = prefix + section["server_name"]
|
|
||||||
if cfg.BindAddr = section["bind_addr"]; cfg.BindAddr == "" {
|
|
||||||
cfg.BindAddr = "127.0.0.1"
|
cfg.BindAddr = "127.0.0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
if tmpStr, ok = section["bind_port"]; ok {
|
|
||||||
if cfg.BindPort, err = strconv.Atoi(tmpStr); err != nil {
|
|
||||||
return fmt.Errorf("Parse conf error: proxy [%s] bind_port incorrect", name)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("Parse conf error: proxy [%s] bind_port not found", name)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SUDPVisitorConf struct {
|
func preVisitorUnmarshalFromIni(cfg VisitorConf, prefix string, name string, section *ini.Section) error {
|
||||||
BaseVisitorConf
|
err := section.MapTo(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cfg.GetBaseInfo().unmarshalFromIni(prefix, name, section)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SUDP
|
||||||
|
var _ VisitorConf = &SUDPVisitorConf{}
|
||||||
|
|
||||||
func (cfg *SUDPVisitorConf) Compare(cmp VisitorConf) bool {
|
func (cfg *SUDPVisitorConf) Compare(cmp VisitorConf) bool {
|
||||||
cmpConf, ok := cmp.(*SUDPVisitorConf)
|
cmpConf, ok := cmp.(*SUDPVisitorConf)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -166,13 +179,20 @@ func (cfg *SUDPVisitorConf) Compare(cmp VisitorConf) bool {
|
|||||||
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom login equal, if exists
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *SUDPVisitorConf) UnmarshalFromIni(prefix string, name string, section ini.Section) (err error) {
|
func (cfg *SUDPVisitorConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) (err error) {
|
||||||
if err = cfg.BaseVisitorConf.UnmarshalFromIni(prefix, name, section); err != nil {
|
err = preVisitorUnmarshalFromIni(cfg, prefix, name, section)
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic unmarshal, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,12 +200,14 @@ func (cfg *SUDPVisitorConf) Check() (err error) {
|
|||||||
if err = cfg.BaseVisitorConf.check(); err != nil {
|
if err = cfg.BaseVisitorConf.check(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic validate, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type STCPVisitorConf struct {
|
// STCP
|
||||||
BaseVisitorConf
|
var _ VisitorConf = &STCPVisitorConf{}
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *STCPVisitorConf) Compare(cmp VisitorConf) bool {
|
func (cfg *STCPVisitorConf) Compare(cmp VisitorConf) bool {
|
||||||
cmpConf, ok := cmp.(*STCPVisitorConf)
|
cmpConf, ok := cmp.(*STCPVisitorConf)
|
||||||
@@ -196,13 +218,20 @@ func (cfg *STCPVisitorConf) Compare(cmp VisitorConf) bool {
|
|||||||
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom login equal, if exists
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *STCPVisitorConf) UnmarshalFromIni(prefix string, name string, section ini.Section) (err error) {
|
func (cfg *STCPVisitorConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) (err error) {
|
||||||
if err = cfg.BaseVisitorConf.UnmarshalFromIni(prefix, name, section); err != nil {
|
err = preVisitorUnmarshalFromIni(cfg, prefix, name, section)
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic unmarshal, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +239,14 @@ func (cfg *STCPVisitorConf) Check() (err error) {
|
|||||||
if err = cfg.BaseVisitorConf.check(); err != nil {
|
if err = cfg.BaseVisitorConf.check(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic validate, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type XTCPVisitorConf struct {
|
// XTCP
|
||||||
BaseVisitorConf
|
var _ VisitorConf = &XTCPVisitorConf{}
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *XTCPVisitorConf) Compare(cmp VisitorConf) bool {
|
func (cfg *XTCPVisitorConf) Compare(cmp VisitorConf) bool {
|
||||||
cmpConf, ok := cmp.(*XTCPVisitorConf)
|
cmpConf, ok := cmp.(*XTCPVisitorConf)
|
||||||
@@ -226,13 +257,20 @@ func (cfg *XTCPVisitorConf) Compare(cmp VisitorConf) bool {
|
|||||||
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
if !cfg.BaseVisitorConf.compare(&cmpConf.BaseVisitorConf) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom login equal, if exists
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *XTCPVisitorConf) UnmarshalFromIni(prefix string, name string, section ini.Section) (err error) {
|
func (cfg *XTCPVisitorConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) (err error) {
|
||||||
if err = cfg.BaseVisitorConf.UnmarshalFromIni(prefix, name, section); err != nil {
|
err = preVisitorUnmarshalFromIni(cfg, prefix, name, section)
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic unmarshal, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,5 +278,8 @@ func (cfg *XTCPVisitorConf) Check() (err error) {
|
|||||||
if err = cfg.BaseVisitorConf.check(); err != nil {
|
if err = cfg.BaseVisitorConf.check(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add custom logic validate, if exists
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
108
pkg/config/visitor_test.go
Normal file
108
pkg/config/visitor_test.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
// Copyright 2020 The frp Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testVisitorPrefix = "test."
|
||||||
|
|
||||||
|
func Test_Visitor_Interface(t *testing.T) {
|
||||||
|
for name := range visitorConfTypeMap {
|
||||||
|
DefaultVisitorConf(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Visitor_UnmarshalFromIni(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testcases := []struct {
|
||||||
|
sname string
|
||||||
|
source []byte
|
||||||
|
expected VisitorConf
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
sname: "secret_tcp_visitor",
|
||||||
|
source: []byte(`
|
||||||
|
[secret_tcp_visitor]
|
||||||
|
role = visitor
|
||||||
|
type = stcp
|
||||||
|
server_name = secret_tcp
|
||||||
|
sk = abcdefg
|
||||||
|
bind_addr = 127.0.0.1
|
||||||
|
bind_port = 9000
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`),
|
||||||
|
expected: &STCPVisitorConf{
|
||||||
|
BaseVisitorConf: BaseVisitorConf{
|
||||||
|
ProxyName: testVisitorPrefix + "secret_tcp_visitor",
|
||||||
|
ProxyType: consts.STCPProxy,
|
||||||
|
Role: "visitor",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
ServerName: testVisitorPrefix + "secret_tcp",
|
||||||
|
BindAddr: "127.0.0.1",
|
||||||
|
BindPort: 9000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sname: "p2p_tcp_visitor",
|
||||||
|
source: []byte(`
|
||||||
|
[p2p_tcp_visitor]
|
||||||
|
role = visitor
|
||||||
|
type = xtcp
|
||||||
|
server_name = p2p_tcp
|
||||||
|
sk = abcdefg
|
||||||
|
bind_addr = 127.0.0.1
|
||||||
|
bind_port = 9001
|
||||||
|
use_encryption = false
|
||||||
|
use_compression = false
|
||||||
|
`),
|
||||||
|
expected: &XTCPVisitorConf{
|
||||||
|
BaseVisitorConf: BaseVisitorConf{
|
||||||
|
ProxyName: testVisitorPrefix + "p2p_tcp_visitor",
|
||||||
|
ProxyType: consts.XTCPProxy,
|
||||||
|
Role: "visitor",
|
||||||
|
Sk: "abcdefg",
|
||||||
|
ServerName: testProxyPrefix + "p2p_tcp",
|
||||||
|
BindAddr: "127.0.0.1",
|
||||||
|
BindPort: 9001,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testcases {
|
||||||
|
f, err := ini.LoadSources(testLoadOptions, c.source)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
visitorType := f.Section(c.sname).Key("type").String()
|
||||||
|
assert.NotEmpty(visitorType)
|
||||||
|
|
||||||
|
actual := DefaultVisitorConf(visitorType)
|
||||||
|
assert.NotNil(actual)
|
||||||
|
|
||||||
|
err = actual.UnmarshalFromIni(testVisitorPrefix, c.sname, f.Section(c.sname))
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(c.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
@@ -16,26 +16,26 @@ package consts
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// proxy status
|
// proxy status
|
||||||
Idle string = "idle"
|
Idle = "idle"
|
||||||
Working string = "working"
|
Working = "working"
|
||||||
Closed string = "closed"
|
Closed = "closed"
|
||||||
Online string = "online"
|
Online = "online"
|
||||||
Offline string = "offline"
|
Offline = "offline"
|
||||||
|
|
||||||
// proxy type
|
// proxy type
|
||||||
TCPProxy string = "tcp"
|
TCPProxy = "tcp"
|
||||||
UDPProxy string = "udp"
|
UDPProxy = "udp"
|
||||||
TCPMuxProxy string = "tcpmux"
|
TCPMuxProxy = "tcpmux"
|
||||||
HTTPProxy string = "http"
|
HTTPProxy = "http"
|
||||||
HTTPSProxy string = "https"
|
HTTPSProxy = "https"
|
||||||
STCPProxy string = "stcp"
|
STCPProxy = "stcp"
|
||||||
XTCPProxy string = "xtcp"
|
XTCPProxy = "xtcp"
|
||||||
SUDPProxy string = "sudp"
|
SUDPProxy = "sudp"
|
||||||
|
|
||||||
// authentication method
|
// authentication method
|
||||||
TokenAuthMethod string = "token"
|
TokenAuthMethod = "token"
|
||||||
OidcAuthMethod string = "oidc"
|
OidcAuthMethod = "oidc"
|
||||||
|
|
||||||
// TCP multiplexer
|
// TCP multiplexer
|
||||||
HTTPConnectTCPMultiplexer string = "httpconnect"
|
HTTPConnectTCPMultiplexer = "httpconnect"
|
||||||
)
|
)
|
||||||
|
@@ -30,7 +30,7 @@ func EnablePrometheus() {
|
|||||||
sm.Add(prometheus.ServerMetrics)
|
sm.Add(prometheus.ServerMetrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
var sm *serverMetrics = &serverMetrics{}
|
var sm = &serverMetrics{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
metrics.Register(sm)
|
metrics.Register(sm)
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user