mirror of
https://github.com/NewFuture/DDNS.git
synced 2022-04-19 20:24:44 +00:00
Merge pull request #89 from NewFuture/refact-config-log
refactor(log): dns log api endopoint
This commit is contained in:
+11
-8
@@ -29,8 +29,12 @@ __author__ = 'New Future'
|
||||
ID = "id"
|
||||
TOKEN = "TOKEN"
|
||||
PROXY = None # 代理设置
|
||||
API_SITE = "alidns.aliyuncs.com"
|
||||
API_METHOD = "POST"
|
||||
|
||||
|
||||
class API:
|
||||
# API 配置
|
||||
SITE = "alidns.aliyuncs.com" # API endpoint
|
||||
METHOD = "POST" # 请求方法
|
||||
|
||||
|
||||
def signature(params):
|
||||
@@ -48,7 +52,7 @@ def signature(params):
|
||||
})
|
||||
query = urlencode(sorted(params.items()))
|
||||
debug(query)
|
||||
sign = API_METHOD + "&" + quote_plus("/") + "&" + quote(query, safe='')
|
||||
sign = API.METHOD + "&" + quote_plus("/") + "&" + quote(query, safe='')
|
||||
debug("signString: %s", sign)
|
||||
|
||||
sign = hmac((TOKEN + "&").encode('utf-8'),
|
||||
@@ -65,15 +69,14 @@ def request(param=None, **params):
|
||||
if param:
|
||||
params.update(param)
|
||||
params = signature(params)
|
||||
debug("params:%s", params)
|
||||
info("%s: %s", API.SITE, params)
|
||||
|
||||
if PROXY:
|
||||
conn = HTTPSConnection(PROXY)
|
||||
conn.set_tunnel(API_SITE, 443)
|
||||
conn.set_tunnel(API.SITE, 443)
|
||||
else:
|
||||
conn = HTTPSConnection(API_SITE)
|
||||
|
||||
conn.request(API_METHOD, '/', urlencode(params),
|
||||
conn = HTTPSConnection(API.SITE)
|
||||
conn.request(API.METHOD, '/', urlencode(params),
|
||||
{"Content-type": "application/x-www-form-urlencoded"})
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
|
||||
+8
-4
@@ -23,7 +23,11 @@ __author__ = 'TongYifan'
|
||||
ID = "AUTH EMAIL" # CloudFlare 验证的是用户Email,等同于其他平台的userID
|
||||
TOKEN = "API KEY"
|
||||
PROXY = None # 代理设置
|
||||
API_SITE = "api.cloudflare.com"
|
||||
|
||||
|
||||
class API:
|
||||
# API 配置
|
||||
SITE = "api.cloudflare.com" # API endpoint
|
||||
|
||||
|
||||
def request(method, action, param=None, **params):
|
||||
@@ -33,12 +37,12 @@ def request(method, action, param=None, **params):
|
||||
if param:
|
||||
params.update(param)
|
||||
|
||||
info("$s %s : params:%s", action, params)
|
||||
info("%s/%s : %s", API.SITE, action, params)
|
||||
if PROXY:
|
||||
conn = HTTPSConnection(PROXY)
|
||||
conn.set_tunnel(API_SITE, 443)
|
||||
conn.set_tunnel(API.SITE, 443)
|
||||
else:
|
||||
conn = HTTPSConnection(API_SITE)
|
||||
conn = HTTPSConnection(API.SITE)
|
||||
|
||||
if method in ['PUT', 'POST', 'PATCH']:
|
||||
# 从public_v(4,6)获取的IP是bytes类型,在json.dumps时会报TypeError
|
||||
|
||||
+10
-7
@@ -23,15 +23,18 @@ except ImportError:
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
|
||||
__author__ = 'Bigjin'
|
||||
# __all__ = ["request", "ID", "TOKEN", "PROXY"]
|
||||
|
||||
ID = "id"
|
||||
TOKEN = "TOKEN"
|
||||
PROXY = None # 代理设置
|
||||
API_SITE = "www.dns.com"
|
||||
API_METHOD = "POST"
|
||||
|
||||
|
||||
class API:
|
||||
# API 配置
|
||||
SITE = "www.dns.com" # API endpoint
|
||||
METHOD = "POST" # 请求方法
|
||||
|
||||
|
||||
def signature(params):
|
||||
@@ -60,15 +63,15 @@ def request(action, param=None, **params):
|
||||
if param:
|
||||
params.update(param)
|
||||
params = signature(params)
|
||||
info("%s : params:%s", action, params)
|
||||
info("%s/api/%s/ : params:%s", API.SITE, action, params)
|
||||
|
||||
if PROXY:
|
||||
conn = HTTPSConnection(PROXY)
|
||||
conn.set_tunnel(API_SITE, 443)
|
||||
conn.set_tunnel(API.SITE, 443)
|
||||
else:
|
||||
conn = HTTPSConnection(API_SITE)
|
||||
conn = HTTPSConnection(API.SITE)
|
||||
|
||||
conn.request(API_METHOD, '/api/' + action + '/', urlencode(params),
|
||||
conn.request(API.METHOD, '/api/' + action + '/', urlencode(params),
|
||||
{"Content-type": "application/x-www-form-urlencoded"})
|
||||
response = conn.getresponse()
|
||||
result = response.read()
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ def request(action, param=None, **params):
|
||||
params.update(param)
|
||||
|
||||
params.update({API.TOKEN_PARAM: '***', 'format': 'json'})
|
||||
info("%s : params:%s", action, params)
|
||||
info("%s/%s : %s", API.SITE, action, params)
|
||||
params[API.TOKEN_PARAM] = "%s,%s" % (ID, TOKEN)
|
||||
|
||||
if PROXY:
|
||||
|
||||
Reference in New Issue
Block a user