Esempio n. 1
0
    def delete_txt_record(self, domain_name, record_name, record_value):
        """
        : delete TXT domain record for authentication;
        """
        from aliyunsdkalidns.request.v20150109 \
        import DescribeDomainRecordsRequest, DeleteDomainRecordRequest

        # describe request for dns record id
        record_id = None
        des_request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest(
        )
        des_request.set_accept_format("json")
        des_request.set_PageNumber(1)
        des_request.set_PageSize(PAGE_SIZE)

        # delete request for delete corresponsing dns record
        del_request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
        del_request.set_accept_format("json")

        record_name = record_name.replace(("." + domain_name), "")
        des_request.set_DomainName(domain_name)
        record_first_page_result = json.loads(
            self._client.do_action_with_exception(des_request))
        #
        total_record_count = record_first_page_result["TotalCount"]
        if total_record_count < PAGE_SIZE:
            result = record_first_page_result["DomainRecords"]["Record"]
            for record in result:
                if record["Type"] == "TXT" and \
                   record["RR"] == record_name and \
                   record["Value"] == record_value and \
                   record["DomainName"] == domain_name:
                    record_id = record["RecordId"]
                    LOGGER.info("Delete record %s %s-%s, record Id: %s.",\
                        record_name, domain_name, record["Value"], record_id)
        else:
            page_num = (total_record_count / PAGE_SIZE) if total_record_count % PAGE_SIZE == 0 \
                       else (int(total_record_count/PAGE_SIZE) + 1)
            for page in range(2, page_num + 1):
                des_request.set_PageNumber(page)
                result = json.loads(
                    self._client.do_action_with_exception(des_request))
                for record in result:
                    if record["Type"] == "TXT" and \
                       record["RR"] == record_name and \
                       record["DomainName"] == domain_name:
                        record_id = record["RecordId"]
                        LOGGER.info("Delete record %s %s-%s, record Id: %s.",\
                            record_name, domain_name, record["Value"], record_id)
                        break
        LOGGER.info("record id: {}.".format(record_id))
        # no record Id no delete operation.
        if record_id:
            del_request.set_RecordId(record_id)
            del_result = json.loads(
                self._client.do_action_with_exception(del_request))
            LOGGER.info("delete result: %s.", del_result)
        else:
            raise Exception("{} {}-{} record cannot be found.".format(
                record_name, domain_name, record["Value"]))
Esempio n. 2
0
 def _aliyun_remove_record(recordId):
     with open(aliyun_access_key, 'r') as f:
         accessKeyId, accessKeySecret = f.read().split()
     client = AcsClient(accessKeyId, accessKeySecret, "cn-hangzhou")
     request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
     request.set_RecordId(recordId)
     client.do_action_with_exception(request)
Esempio n. 3
0
    def delete_dns_record(self, domain_name, domain_dns_value):
        """
        delete a txt record we created just now.
        :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. we do not use this.
        :return _ResponseForAliyun:
        :return:
        """
        self.logger.info("delete_dns_record start: %s",
                         (domain_name, domain_dns_value))

        root, _, acme_txt = self.extract_zone(domain_name)

        record_id = self.query_recored_id(root, acme_txt)
        if not record_id:
            msg = "failed to find record_id of domain: %s, value: %s", domain_name, domain_dns_value
            self.logger.warning(msg)
            return

        self.logger.info("start to delete model record, id: %s", record_id)

        request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
        request.set_RecordId(record_id)
        resp = self._send_reqeust(request)

        self.logger.info("delete_dns_record end: %s",
                         (domain_name, domain_dns_value, resp.json()))
        return resp
Esempio n. 4
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
Esempio n. 5
0
 def del_record(self, domain):
     dels = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
     dels.set_accept_format('json')
     dels.add_query_param('RecordId',
                          self._check_domain(domain, types="deles"))
     rst_dels = self.clt.do_action_with_exception(dels)
     return rst_dels
Esempio n. 6
0
def DeleteDomainRecord(sldomain):
    clt = client.AcsClient(accesskey['accesskeyid'],
                           accesskey['accesskeysecret'], 'cn-hangzhou')
    delRequest = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
    delRequest.set_RecordId(sldomain)
    delResult = clt.do_action_with_exception(delRequest)
    return delResult
Esempio n. 7
0
 def del_record(self, domain, record):
     clt = client.AcsClient(self.access_key_id, self.access_key_secret, 'cn-hangzhou')
     request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
     request.set_RecordId(record)
     request.set_accept_format(rc_format)
     result = clt.do_action(request).decode('utf-8')
     result = json.JSONDecoder().decode(result)
     return result
Esempio n. 8
0
def del_domain_record(RRKeyWord):
    try:
        record_id = get_record_id(RRKeyWord)
        # print(RecordId)
        if record_id != 0:
            request = DeleteDomainRecordRequest()
            request.set_RecordId(record_id)
            # 输出格式为byte,需要转成str输出为宜
            response = client.do_action_with_exception(request)
            print('域名' + RRKeyWord + '.' + DomainName + ',\nRcordID为:' +
                  str(response, encoding="utf-8").split(':')[1].split(
                      ',')[0].split('"')[1] + '\nA记录已被删除。')
        else:
            print('域名' + RRKeyWord + '.' + DomainName + '找不到Rcord信息,删除失败。')

    except Exception as e:
        print(e)
def cleanup():
    client = AcsClient(os.environ['ALI_DNS_ACCESS_KEY_ID'],
                       os.environ['ALI_DNS_ACCESS_KEY_SECRET'], 'cn-beijing')

    request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
    request.set_RecordId(
        open('/tmp/ali-dns-record-id-%s' % os.environ['CERTBOT_DOMAIN'],
             'r').read().rstrip())

    client.do_action_with_exception(request)
    print('successfully delete domain record used for challenge validation...')
Esempio n. 10
0
def delete_dns_records(RecordId):
    request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
    # 发起 API和参数 请求
    request.set_accept_format('json')
    request.set_RecordId(RecordId)
    # 并打印返回
    response = client.do_action_with_exception(request)
    f = open('./record.txt', 'a+')
    f.write("%s\n" % response)
    f.close()
    print response
Esempio n. 11
0
def delete_dns_record(DomainName, hostname):
    DomainRecords = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
    DomainRecords.set_accept_format('json')
    DomainRecords.set_DomainName(DomainName)
    DomainRecordsJson = json.loads(client.do_action_with_exception(DomainRecords))
    for x in DomainRecordsJson['DomainRecords']['Record']:
        if hostname == x['RR']:
            RecordId = x['RecordId']
            DeleteDomainRecord = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
            DeleteDomainRecord.set_RecordId(RecordId)
            DeleteDomainRecordJson = json.loads(client.do_action_with_exception(DeleteDomainRecord))
            print DeleteDomainRecordJson
Esempio n. 12
0
    def delete_txt_record(self, record_id):

        req = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
        req.set_RecordId(record_id)

        try:
            resp_str = self.acs_client.do_action_with_exception(req)
            logger.debug("delete_txt_record:" + resp_str)
        except ServerException as e:
            logger.warning(
                "delete_txt_record: could not delete DNS TXT record " + str(e))
            pass
Esempio n. 13
0
    def delete_dns_record(self, domain_name, domain_dns_value):
        """
        delete a txt record we created just now.
        :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. we do not use this.
        :return _ResponseForAliyun:
        :return:
        """
        root, _, acme_txt = self.extract_zone(domain_name)

        record_id = self.query_recored_id(root, acme_txt)
        if not record_id:
            return

        request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
        request.set_RecordId(record_id)
        resp = self._send_reqeust(request)

        try:
            record_id = self.query_recored_id(root, '@', 'CAA')
            if record_id:
                request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
                request.set_RecordId(record_id)
                self._send_reqeust(request)
        except:
            pass

        try:
            tmp = acme_txt.split('.')
            if len(tmp) > 1:
                record_id = self.query_recored_id(root, tmp[-1], 'CAA')
                if record_id:
                    request = DeleteDomainRecordRequest.DeleteDomainRecordRequest(
                    )
                    request.set_RecordId(record_id)
                    self._send_reqeust(request)
        except:
            pass

        return resp
Esempio n. 14
0
 def del_record(self, domain, record):
     clt = client.AcsClient(self.SECRETID, self.SECRETKEY, 'cn-hangzhou')
     request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
     request.set_RecordId(record)
     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
Esempio n. 15
0
def delDomainRecord(client,subdomain):
    info = getDomainInfo(subdomain)
    if info['TotalCount'] == 0:
        logger.debug('没有相关的记录信息,删除失败!')
    elif info["TotalCount"] == 1:
        logger.debug('准备删除记录')
        request = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
        request.set_accept_format('json')

        record_id = info["DomainRecords"]["Record"][0]["RecordId"]
        request.set_RecordId(record_id) # 删除记录需要指定 record_id ,该字段为记录的唯一标识,可以在获取方法的返回信息中得到该字段的值
        result = client.do_action_with_exception(request)
        logger.debug('删除成功,返回信息:{}'.format(result))
    else:
        # 正常不应该有多条相同的记录,如果存在这种情况,应该手动去网站检查核实是否有操作失误
        logger.debug("存在多个相同子域名解析记录值,请核查后再操作!")
Esempio n. 16
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')

delRequest = DeleteDomainRecordRequest.DeleteDomainRecordRequest()
delRequest.set_RecordId(sys.argv[1])
delResult = clt.do_action(delRequest)
#delResult2 = json.loads(delResult)
print delResult