This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathfrp_utils.py
55 lines (45 loc) · 2.31 KB
/
frp_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
from .db_utils import DBUtils
from .models import DynamicDockerChallenge
class FrpUtils:
@staticmethod
def update_frp_redirect():
configs = DBUtils.get_all_configs()
domain = configs.get('frp_http_domain_suffix', "")
containers = DBUtils.get_all_alive_container()
output = configs.get("frp_config_template")
http_template = "\n\n[http_%s]\n" + \
"type = http\n" + \
"local_ip = %s\n" + \
"local_port = %s\n" + \
"custom_domains = %s\n" + \
"use_compression = true"
direct_template = "\n\n[direct_%s]\n" + \
"type = tcp\n" + \
"local_ip = %s\n" + \
"local_port = %s\n" + \
"remote_port = %s\n" + \
"use_compression = true" + \
"\n\n[direct_%s_udp]\n" + \
"type = udp\n" + \
"local_ip = %s\n" + \
"local_port = %s\n" + \
"remote_port = %s\n" + \
"use_compression = true"
for c in containers:
dynamic_docker_challenge = DynamicDockerChallenge.query \
.filter(DynamicDockerChallenge.id == c.challenge_id) \
.first_or_404()
if dynamic_docker_challenge.redirect_type == 'http':
output += http_template % (
str(c.user_id) + '-' + c.uuid, str(c.user_id) + '-' + c.uuid,
dynamic_docker_challenge.redirect_port, c.uuid + domain)
else:
output += direct_template % (
str(c.user_id) + '-' + c.uuid, str(c.user_id) + '-' + c.uuid,
dynamic_docker_challenge.redirect_port, c.port,
str(c.user_id) + '-' + c.uuid, str(c.user_id) + '-' + c.uuid,
dynamic_docker_challenge.redirect_port, c.port)
requests.put("http://" + configs.get("frp_api_ip") + ":" + configs.get("frp_api_port") + "/api/config", output,
timeout=5)
requests.get("http://" + configs.get("frp_api_ip") + ":" + configs.get("frp_api_port") + "/api/reload", timeout=5)