Created
May 26, 2020 22:39
-
-
Save Hiroki-Kawakami/301ddcec49dff9423753fdbe00120c54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib.parse | |
import urllib.request | |
import base64 | |
import sys | |
import os | |
def mydns_register_validation(master_id, password, domain, validation, cmd = "REGIST"): | |
url = "https://www.mydns.jp/directedit.html" | |
authorization = master_id + ":" + password | |
headers = { | |
"Content-Type": "application/x-www-form-urlencoded", | |
"Authorization": "Basic " + base64.b64encode(authorization.encode()).decode("utf-8") | |
} | |
data = { | |
"EDIT_CMD": cmd, | |
"CERTBOT_DOMAIN": domain, | |
"CERTBOT_VALIDATION": validation | |
} | |
request = urllib.request.Request(url, headers=headers, data=urllib.parse.urlencode(data).encode(), method="POST") | |
try: urllib.request.urlopen(request) | |
except urllib.error.HTTPError as e: | |
print(e.code) | |
print(e.read()) | |
cmd = "REGIST" | |
if len(sys.argv) > 1: | |
cmd = sys.argv[1] | |
domain = os.environ.get('CERTBOT_DOMAIN') | |
validation = os.environ.get('CERTBOT_VALIDATION') | |
print("Domain: " + domain) | |
print("Validation: " + validation) | |
# ドメインが1つの場合 | |
mydns_register_validation("mydns999999", "MyDNS(mydns999999)のパスワード", domain, validation, cmd) | |
# ドメイン・MyDNSアカウントが複数ある場合 | |
# if domain == "example.net": | |
# mydns_register_validation("mydns888888", "MyDNS(mydns888888)のパスワード", domain, validation, cmd) | |
# if domain == "example.com": | |
# mydns_register_validation("mydns999999", "MyDNS(mydns999999)のパスワード", domain, validation, cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment