Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit a711e00

Browse files
committed
add host_key_regen
1 parent 9a2b244 commit a711e00

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

cloudflare-partner-cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'add_subdomain':("zone_name", "subdomains", "resolve_to"),
2727
'delete_subdomain': ("zone_name", "subdomains"),
2828
'ssl_verfication': ("zone",),
29+
'host_key_regen': (),
2930
}
3031
CFHOST_FILE = ".cfhost"
3132

@@ -78,6 +79,7 @@
7879
"run this \"ssl_verfication\" after record become effective":
7980
"如果需要启用SSL, 请将%s的CNAME记录设置为%s, 然后在解析生效后运行一次\"开通SSL\"",
8081
"Zone %s not exists or is not under user %s": "域名%s不存在,或者不属于用户%s",
82+
"Host key has been changed to %s": "Hostkey已更新为 %s",
8183
}
8284

8385
def i18n(s):
@@ -106,7 +108,6 @@ def __init__(self):
106108
self.user_email = None
107109
self.user_key = None
108110
self.user_api_key = None
109-
self.host_key = HOSTKEY
110111
if os.path.exists(CFHOST_FILE):
111112
r = open(CFHOST_FILE).read()
112113
_ = r.split(",")
@@ -126,7 +127,7 @@ def _hostapi(self, act, extra={}):
126127
return
127128
payload = {
128129
"act": act,
129-
"host_key": self.host_key,
130+
"host_key": HOSTKEY,
130131
}
131132
if act not in ("user_auth", "host_key_regen"):
132133
payload.update({"user_key": self.user_key})
@@ -301,16 +302,19 @@ def _zone_lookup(self, j):
301302

302303
@catch_err
303304
def _host_key_regen(self, j):
304-
pass
305+
global HOSTKEY
306+
HOSTKEY = j['request']['host_key']['__host_key'].encode('utf-8')
307+
check_hostkey(force = True)
308+
log("Host key has been changed to %s", HOSTKEY)
305309

306310
def __getattr__(self, act, handle=True):
307311
if act not in CFARG:
308312
raise AttributeError("'CF' object has no attribute '%s'" % act)
309313
return lambda k={}:getattr(self, "_%s" % act)(self._hostapi(act, k))
310314

311-
def check_hostkey():
315+
def check_hostkey(force = False):
312316
global HOSTKEY
313-
if HOSTKEY and len(HOSTKEY) == 32:
317+
if HOSTKEY and len(HOSTKEY) == 32 and not force:
314318
return
315319
while not HOSTKEY or len(HOSTKEY) != 32:
316320
HOSTKEY = raw_input(i18n("Please enter your Cloudflare partner hostkey (https://partners.cloudflare.com/api-management)> ")).strip()

0 commit comments

Comments
 (0)