Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.