-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx_proxy_api.py
61 lines (48 loc) · 1.37 KB
/
nginx_proxy_api.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
56
57
58
59
60
61
# Tea Inside internal nginx_prox API.
import requests
from requests.auth import AuthBase
class TokenAuth(AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
r.headers['Authorization'] = f'{self.token}'
return r
class SimpleTeaProxDomainResolver:
def __init__(self, token, domain):
self.token = token
self.domain = domain
# Build Tea Inside ipton data
@staticmethod
def tea_ipton_resolve(a, b, c, d):
return hex(d | (c << 8) | (b << 16) | (a << 24))
# Set domain IP.
def set_ip(self, target_ip):
target_ip = target_ip.split(".")
return requests.post(
'https://api.teainside.org/internal.php',
auth=TokenAuth(token),
params={
'action': 'nginx_prox',
'domain': self.domain,
'sb_act': 'set',
'set_target': self.tea_ipton_resolve(int(target_ip[0]), int(target_ip[1]), int(target_ip[2]), int(target_ip[3]))
}
)
# Get current domain IP.
def get_ip(self):
return requests.get(
'https://api.teainside.org/internal.php',
auth=TokenAuth(token),
params={
'action': 'nginx_prox',
'domain': self.domain,
'sb_act': 'get'
}
)
token = "... your token here ..."
domain = "... your domain here ..."
st = SimpleTeaProxDomainResolver(token, domain)
# Set domain IP to 123.123.123.123
print(st.set_ip("123.123.123.123").text)
# # Get current domain IP
# print(st.get_ip().text)