Ejemplo n.º 1
0
 def create_record(self, domain, sub_domain, value, record_type, line):
     clt = client.AcsClient(self.SECRETID, self.SECRETKEY, 'cn-hangzhou')
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_DomainName(domain)
     request.set_RR(sub_domain)
     # 阿里云线路名映射:https://help.aliyun.com/document_detail/29807.html
     if line == "电信":
         line = "telecom"
     elif line == "联通":
         line = "unicom"
     elif line == "移动":
         line = "mobile"
     request.set_Line(line)
     request.set_Type(record_type)
     request.set_Value(value)
     request.set_accept_format(rc_format)
     result = clt.do_action(request).decode('utf-8')
     result = json.loads(result)
     #替换为标准格式
     # {
     #   "result":True,
     #   "message":{...}
     # }
     data = {}
     data["result"] = 'RecordId' in ret
     data["message"] = result
     return data
Ejemplo n.º 2
0
    def _aliyun_set_txtrecord(domain, txtrecord):
        with open(aliyun_access_key, 'r') as f:
            accessKeyId, accessKeySecret = f.read().split()
        client = AcsClient(accessKeyId, accessKeySecret, "cn-hangzhou")

        request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
        request.set_DomainName(domain)
        request.set_PageNumber(1)
        request.set_PageSize(500)
        request.set_RRKeyWord("_acme-challenge")
        request.set_TypeKeyWord("TXT")

        response = json.loads(
            client.do_action_with_exception(request).decode())

        for record in response['DomainRecords']['Record']:
            request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
            request.set_RecordId(record['RecordId'])
            client.do_action_with_exception(request)

        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_DomainName(domain)
        request.set_RR('_acme-challenge')
        request.set_Type('TXT')
        request.set_Value(txtrecord)
        recordId = json.loads(
            client.do_action_with_exception(request).decode())['RecordId']
        return recordId
Ejemplo n.º 3
0
def add_dns(dns_rr, dns_domain, dns_type, dns_value, dns_ttl):
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_RR(dns_rr)  # 设置子域名信息
    request.set_DomainName(dns_domain)  # 设置请求域名
    request.set_Type(dns_type)  # 设置 DNS 类型
    request.set_Value(dns_value)  # 设置解析 IP
    request.set_TTL(dns_ttl)  # 设置 TTL 时间
    request.set_accept_format(rc_format)  # 设置返回格式
    return clt.do_action_with_exception(request)  # 发送请求内容
Ejemplo n.º 4
0
def add_dns_record(DomainName, hostname, Types, IP):
    AddDomainRecord = AddDomainRecordRequest.AddDomainRecordRequest()
    AddDomainRecord.set_DomainName(DomainName)
    AddDomainRecord.set_RR(hostname)
    AddDomainRecord.set_Type(Types)
    AddDomainRecord.set_TTL('600')
    AddDomainRecord.set_Value(IP)
    AddDomainRecordJson = json.loads(client.do_action_with_exception(AddDomainRecord))
    print AddDomainRecordJson
Ejemplo n.º 5
0
def addDomainRecord(ip):
    cl = client.AcsClient(AccessKeyId, AccessKeySecret, region_id)
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_DomainName(domain)
    request.set_Type('A')
    request.set_Value(ip)
    request.set_RR('www')
    response = cl.do_action_with_exception(request)
    print response
Ejemplo n.º 6
0
def add_domain_record():
    req = AddDomainRecordRequest.AddDomainRecordRequest()
    req.set_DomainName(domain)
    req.set_RR(subDomain)
    req.set_Type('A')
    req.set_Value(publicIp)
    print(json.dumps(req.get_query_params()))
    res = client.do_action_with_exception(req)
    print(res.decode())
Ejemplo n.º 7
0
 def add_dns_record(self, host, domain, record_ip):
     '''as name'''
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_DomainName(domain)
     request.set_RR(host)
     request.set_Type('A')  # can add A record only
     request.set_Value(record_ip)
     response = self._client.do_action_with_exception(request)
     logger.log(response)
     return json.loads(response)['RecordId']
Ejemplo n.º 8
0
def add_record(acs_client, rr, domain_name, current_ip, ttl):
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_RR(rr)
    request.set_Type('A')
    request.set_DomainName(domain_name)
    request.set_Value(current_ip)
    request.set_TTL(ttl)
    request.set_accept_format('json')
    result = acs_client.do_action_with_exception(request)
    return result
Ejemplo n.º 9
0
    def create_dns_record(self, domain_name, domain_dns_value):
        """
        create a dns record
        :param str domain_name: the value sewer client passed in, like *.menduo.example.com
        :param str domain_dns_value: the value sewer client passed in.
        :return _ResponseForAliyun:
        """
        root, _, acme_txt = self.extract_zone(domain_name)

        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_DomainName(root)
        request.set_TTL(600)
        request.set_RR(acme_txt)
        request.set_Type("TXT")
        request.set_Value(domain_dns_value)
        resp = self._send_reqeust(request)

        try:
            request = AddDomainRecordRequest.AddDomainRecordRequest()
            request.set_DomainName(root)
            request.set_TTL(600)
            request.set_RR('@')
            request.set_Type("CAA")
            request.set_Value('1 issue letsencrypt.org')
            resp = self._send_reqeust(request)
        except:
            pass

        try:
            tmp = acme_txt.split('.')
            if len(tmp) > 1:
                request = AddDomainRecordRequest.AddDomainRecordRequest()
                request.set_DomainName(root)
                request.set_TTL(600)
                request.set_RR(tmp[-1])
                request.set_Type("CAA")
                request.set_Value('1 issue letsencrypt.org')
                resp = self._send_reqeust(request)
        except:
            pass

        return resp
Ejemplo n.º 10
0
def AddDomainRecord(HostName, DomainName, Types, IP):
    AddDomainRecord = AddDomainRecordRequest.AddDomainRecordRequest()
    AddDomainRecord.set_accept_format('json')
    AddDomainRecord.set_DomainName(DomainName)
    AddDomainRecord.set_RR(HostName)
    AddDomainRecord.set_Type(Types)
    AddDomainRecord.set_TTL('600')
    AddDomainRecord.set_Value(IP)
    AddDomainRecordJson = json.loads(
        clt.do_action_with_exception(AddDomainRecord))
    print AddDomainRecordJson
Ejemplo n.º 11
0
def add(RR, text):
    print_("add RR '%s' value is %s " % (RR, text))
    id_r = AddDomainRecordRequest.AddDomainRecordRequest()

    id_r.set_DomainName(domain)
    id_r.set_RR(RR)
    id_r.set_Type('TXT')
    id_r.set_Value(text)

    id_re = c.do_action(id_r)
    print_(id_re)
Ejemplo n.º 12
0
 def add_dns(self, dns_rr, dns_value, dns_type, dns_ttl, dns_domain):
     print('add_dns')
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_DomainName(dns_domain)
     request.set_RR(dns_rr)
     request.set_Type(dns_type)
     request.set_Value(dns_value)
     request.set_TTL(dns_ttl)
     result = self.do_action(request)
     self.records_cache_time = None
     print('{}.{} -> {}'.format(dns_rr, dns_domain, dns_value))
     return result
Ejemplo n.º 13
0
 def add_record(self, domain, types, ip):
     if not self._check_domain(domain=domain):
         add = AddDomainRecordRequest.AddDomainRecordRequest()
         add.set_accept_format('json')
         add.add_query_param('DomainName',
                             self._domain_prefix(domain)['main'])
         add.add_query_param('RR', self._domain_prefix(domain)['sub'])
         add.add_query_param('Type', types)
         add.add_query_param('Value', ip)
         rst_add = self.clt.do_action_with_exception(add)
         return rst_add
     print(self._check_domain(domain=domain, types="add"))
     return "domain record [{}] isexist".format(
         self._domain_prefix(domain)['sub'])
Ejemplo n.º 14
0
 def add_domain_record(self,
                       domain_name,
                       value,
                       record_type='A',
                       rr='frp',
                       priority=1):
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_DomainName(domain_name)
     request.set_RR(rr)
     request.set_Type(record_type)
     request.set_Value(value)
     request.set_Priority(priority)
     response = self.client.do_action_with_exception(request)
     return json.loads(response.decode('utf-8'))['RecordId']
Ejemplo n.º 15
0
def add_dns(ali_ctl, dns_value, domain, sub_domain, ttl, ip_ver):
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_DomainName(domain)
    request.set_RR(sub_domain)
    request.set_Value(dns_value)
    request.set_TTL(ttl)

    if ip_ver == 4:
        request.set_Type('A')
    else:
        request.set_Type('AAAA')

    result = ali_ctl.do_action_with_exception(request)
    return result
Ejemplo n.º 16
0
    def addDomainRecord(self):
        add = AddDomainRecordRequest.AddDomainRecordRequest()
        add.set_RR(self.rrKeyWord)
        add.set_Type('A')
        add.set_Value(self.newIp)
        add.set_Line("default")
        add.set_DomainName(self.domainName)
        addResult = self.clt.do_action(add)

        xml = fromstring(addResult.decode())
        if xml.find('Error') != None:
            message = xml.find('Error/Message').text
        else:
            message = 'The DNS record add success.'
        self.writeLog(message)
Ejemplo n.º 17
0
 def add(self, rr, value):
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_action_name("AddDomainRecord")
     request.set_Type('A')
     request.set_RR(rr)
     request.set_Value(value)
     request.set_DomainName(self.domain['DomainName'])
     r = json.loads(self.client.do_action_with_exception(request))
     try:
         if 'Code' in r.keys():
             raise Error(r['Code'], r['Message'])
     except Error(r['Code'], r['Message']):
         return ''
     else:
         return r['RecordId']
Ejemplo n.º 18
0
def add_record(website, value, type='A', line='default', ttl=600):

    rr_domainname = domainname_split(website)
    if rr_domainname:
        rr = rr_domainname[0]
        domainname = rr_domainname[1]
        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_RR(rr)
        request.set_DomainName(domainname)
        request.set_Type(type)
        request.set_Value(value)
        request.set_Line(line)
        request.set_TTL(ttl)
        result = send_request(request)
        return result
    return False
Ejemplo n.º 19
0
    def add_txt_record(self, domain_name, record_name, record_value):
        from aliyunsdkalidns.request.v20150109 import AddDomainRecordRequest

        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_accept_format("json")
        #
        request.set_DomainName(domain_name)
        request.set_Type("TXT")
        record_name = record_name.replace(("." + domain_name), "")
        request.set_RR(record_name)
        request.set_Value(record_value)
        request.set_TTL(TTL)
        LOGGER.info("domain_name: %s, record_name: %s, record_value: %s.",\
                domain_name, record_name, record_value)
        result = json.loads(self._client.do_action_with_exception(request))
        LOGGER.info("add result: %s.", result)
Ejemplo n.º 20
0
def addDomainRecord(client, ip, subDomain, mainDomain):
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_accept_format('json')

    # request.set_Priority('1')  # MX 记录时的必选参数
    request.set_TTL('600')  # 可选值的范围取决于你的阿里云账户等级,免费版为 600 - 86400 单位为秒
    request.set_Value(ip)  # 新增的 ip 地址
    request.set_Type('A')  # 记录类型
    request.set_RR(subDomain)  # 子域名名称
    request.set_DomainName(mainDomain)  # 主域名

    # 获取记录信息,返回信息中包含 TotalCount 字段,表示获取到的记录条数 0 表示没有记录, 其他数字为多少表示有多少条相同记录,正常有记录的值应该为1,如果值大于1则应该检查是不是重复添加了相同的记录
    response = client.do_action_with_exception(request)
    response = str(response, encoding='utf-8')
    relsult = json.loads(response)
    return relsult
Ejemplo n.º 21
0
def create_dns(rc_domain, dns_rr, dns_type, dns_value, dns_record_id, dns_ttl,
               dns_format):
    clt = client.AcsClient(access_key_id, access_Key_secret, 'cn-hangzhou')
    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_DomainName(rc_domain)
    request.set_RR(dns_rr)
    request.set_Type(dns_type)
    request.set_Value(dns_value)
    #request.set_RecordId(dns_record_id)
    #request.set_TTL(dns_ttl)
    #request.set_accept_format(dns_format)
    print request
    result = clt.do_action(request)
    print result
    result = json.JSONDecoder().decode(result)
    print result
    print result['RequestId'], result['RecordId']
    return result
Ejemplo n.º 22
0
 def create_record(self, domain, sub_domain, value, record_type, line):
     clt = client.AcsClient(self.access_key_id, self.access_key_secret, 'cn-hangzhou')
     request = AddDomainRecordRequest.AddDomainRecordRequest()
     request.set_DomainName(domain)
     request.set_RR(sub_domain)
     if line == "电信":
         line = "telecom"
     elif line == "联通":
         line = "unicom"
     elif line == "移动":
         line = "mobile"
     request.set_Line(line)
     request.set_Type(record_type)
     request.set_Value(value)
     request.set_accept_format(rc_format)
     result = clt.do_action(request).decode('utf-8')
     result = json.JSONDecoder().decode(result)
     return result
Ejemplo n.º 23
0
    def add_txt_record(self, domain, rr, value):

        req = AddDomainRecordRequest.AddDomainRecordRequest()
        req.set_DomainName(domain)
        req.set_Type("TXT")
        req.set_RR(rr)
        req.set_Value(value)

        resp_str = self.acs_client.do_action_with_exception(req)
        resp_dict = json.loads(resp_str)
        record_id = resp_dict.get('RecordId')

        logger.debug("add_txt_record:" + resp_str)

        if record_id and type(record_id) == str:
            return record_id
        else:
            return None
Ejemplo n.º 24
0
    def create_dns_record(self, domain_name, domain_dns_value):
        """
        create a model record
        :param str domain_name: the value sewer client passed in, like *.menduo.example.com
        :param str domain_dns_value: the value sewer client passed in.
        :return _ResponseForAliyun:
        """
        self.logger.info("create_dns_record start: %s",
                         (domain_name, domain_dns_value))
        root, _, acme_txt = self.extract_zone(domain_name)

        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_DomainName(root)
        request.set_TTL(600)
        request.set_RR(acme_txt)
        request.set_Type("TXT")
        request.set_Value(domain_dns_value)
        resp = self._send_reqeust(request)

        self.logger.info("create_dns_record end: %s",
                         (domain_name, domain_dns_value, resp.json()))

        return resp
Ejemplo n.º 25
0
    def setDomainRRAsValue(self, domain, RR, value):
        print('Set RR {} as value {} for domain {}.'.format(RR, value, domain))
        request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
        request.set_DomainName(self.getBaseDomain(domain))
        response = json.loads(
            self.client.do_action_with_exception(request).decode())

        for record in response['DomainRecords']['Record']:
            if record['Type'] == 'TXT' and record['RR'] == RR and record[
                    'Value'] == value:
                print('value already exists.')
                return

        print('Create a new record.')
        request = AddDomainRecordRequest.AddDomainRecordRequest()
        request.set_DomainName(self.getBaseDomain(domain))

        request.set_Type('TXT')
        request.set_RR(RR)
        request.set_Value(value)
        response = json.loads(
            self.client.do_action_with_exception(request).decode())
        print(response)
Ejemplo n.º 26
0
def auth():
    client = AcsClient(
        os.environ['ALI_DNS_ACCESS_KEY_ID'],
        os.environ['ALI_DNS_ACCESS_KEY_SECRET'],
        'cn-beijing'
    )

    certbot_domain = os.environ['CERTBOT_DOMAIN']
    domain = tld.get_tld(certbot_domain, as_object=True, fix_protocol=True)
    top_domain = domain.fld
    rr = '.'.join(['_acme-challenge'] + ([] if len(domain.subdomain) == 0 else [domain.subdomain]))

    request = AddDomainRecordRequest.AddDomainRecordRequest()
    request.set_DomainName(top_domain)
    request.set_Type('TXT')
    request.set_RR(rr)
    request.set_Value(os.environ['CERTBOT_VALIDATION'])

    response = client.do_action_with_exception(request)
    print('successfully added txt record for challenge validation...')
    print(response)

    with open('/tmp/ali-dns-record-id-%s' % certbot_domain, 'w') as f:
        f.write(json.loads(response)['RecordId'])
Ejemplo n.º 27
0
def add_domain_record(RRKeyWord, Value):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_Value(Value)
    request.set_Type("A")
    request.set_RR(RRKeyWord)
    request.set_DomainName(DomainName)
    # 输出格式为byte,需要转成str输出为宜
    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))
Ejemplo n.º 28
0
#!/usr/bin/python

from aliyunsdkcore import client
from aliyunsdkalidns.request.v20150109 import DescribeDomainRecordsRequest
from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest
from aliyunsdkalidns.request.v20150109 import AddDomainRecordRequest
from aliyunsdkalidns.request.v20150109 import DeleteDomainRecordRequest

AccessKeyID = "xxx"
AccessKeySecret = "xxx"

import json
import sys
clt = client.AcsClient(AccessKeyID, AccessKeySecret, 'cn-hangzhou')

#addRequest = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
addRequest = AddDomainRecordRequest.AddDomainRecordRequest()
addRequest.set_DomainName('t5b.net')
addRequest.set_accept_format('json')
addRequest.set_RR(sys.argv[1])
addRequest.set_Type('A')
addRequest.set_Value(sys.argv[2])
addResult = clt.do_action(addRequest)
addResult2 = json.loads(addResult)
print addResult2