def addtxt(self):
     try:
           alld=self.init_data_Text.get(1.0, END).strip()
           par=self.jiexizhi.get(1.0,END).strip()
           htxt=par.split()
           dnsauth=htxt[0]
           par=htxt[1]
     except Exception as err:
         self.name_data_Text.insert(END, f'按照 主机记录 空格 记录值填写 \n', "tag1")
         return 0
     for domain in alld.split():
               domain=domain.strip()
               try:
                 request = AddDomainRecordRequest()
                 request.set_accept_format('json')
                 request.set_Value(par)
                 request.set_Type('TXT')
                 request.set_RR(dnsauth)
                 request.set_DomainName(domain)
                 self.client.do_action_with_exception(request)
                 self.name_data_Text.insert(END, domain+"  添加TXT  "+par+'    已添加完成\n', "tag2")
               except  Exception as err:
                  if "The specified domain name does not exist" in str(err):
                      self.name_data_Text.insert(END, f'{domain} 此账户没有这条域名\n', "tag1")
                  elif "DomainRecordDuplicate The DNS record already exists" in str(err):
                      self.name_data_Text.insert(END, f'  TXT  {par}  解析值已存在\n', "tag1")
                  else:
                      self.name_data_Text.insert(END, "========================================\n", "tag1")
                      self.name_data_Text.insert(END, f"{domain}    {err}\n", "tag1")
                      self.name_data_Text.insert(END, "========================================\n", "tag1")
Esempio n. 2
0
def aliyun_add_subdomain(client, subdomain, ipaddress, addtype):
    request = None
    response = None
    request = AddDomainRecordRequest()
    request.set_accept_format('json')

    tmp = subdomain.partition('.')
    request.set_DomainName(tmp[-1])
    request.set_RR(tmp[0])
    if addtype == 'ipv4':
        request.set_Type('A')
    else:
        request.set_Type('AAAA')
    request.set_Value(ipaddress)

    try:
        response = client.do_action_with_exception(request)
    except ServerException as e:
        print('Server Error! Domain: {}, Code: {}.'.format(
            subdomain, e.get_error_code()))
        print(e.get_error_msg())
        return None
    except ClientException as e:
        print('Client Error! Domain: {}, Code: {}.'.format(
            subdomain, e.get_error_code()))
        print(e.get_error_msg())
        return None
    return json.loads(str(response, encoding='utf-8'))
    def add_txt_record(self, domain, record_name, record_content, record_ttl):
        """
        Add a TXT record using the supplied information.

        :param str domain: The domain to use to look up the Alidns zone.
        :param str record_name: The record name (typically beginning with '_acme-challenge.').
        :param str record_content: The record content (typically the challenge validation).
        :param int record_ttl: The record TTL (number of seconds that the record may be cached).
        :raises certbot.errors.PluginError: if an error occurs communicating with the Aliyun API
        """

        if self._find_txt_record_id(domain, record_name, record_content):
            logger.debug('TXT record exited; no add needed.')
            return

        request = AddDomainRecordRequest()

        domain_root = '.'.join(domain.split('.')[-2:])
        doamin_rr = record_name[:record_name.find(domain_root) - 1]
        request.set_accept_format('json')
        request.set_DomainName(domain_root)
        request.set_Type("TXT")
        request.set_RR(doamin_rr)
        request.set_Value(record_content)
        request.set_TTL(record_ttl)

        try:
            self.ac.do_action_with_exception(request)
        except ClientException as e:
            logger.error(
                'Encountered ClientException adding TXT record: %d %s', e, e)
            raise errors.PluginError(
                'Error communicating with the aliyun API: {0}'.format(e))
 def addmobile(self):
     alld = self.init_data_Text.get(1.0, END).strip()
     par = self.jiexizhi.get(1.0, END).strip()
     for domain in alld.split():
           domain = domain.strip()
           try:
             request = AddDomainRecordRequest()
             request.set_accept_format('json')
             request.set_Value(par)
             request.set_Line('mobile')
             request.set_Type('CNAME')
             request.set_RR("www")
             request.set_DomainName(domain)
             self.client.do_action_with_exception(request)
             self.name_data_Text.insert(END, domain+"  www  "+par+'    移动线路添加完成\n', "tag2")
             request.set_RR("@")
             self.client.do_action_with_exception(request)
             self.name_data_Text.insert(END, domain+"  @    "+par+'    移动线路添加完成\n', "tag2")
           except  Exception as err:
              if "The specified domain name does not exist" in str(err):
                  self.name_data_Text.insert(END, f'{domain}  此账户没有这条域名\n', "tag1")
              elif "DNS record is invalid or in the wrong format" in str(err):
                  self.name_data_Text.insert(END, f'{domain}  格式错误\n', "tag1")
              elif "DomainRecordDuplicate The DNS record already exists" in str(err):
                  self.name_data_Text.insert(END, f'{domain}  mobile  {par}  解析值已存在\n', "tag1")
              else:
                  self.name_data_Text.insert(END, "========================================\n", "tag1")
                  self.name_data_Text.insert(END, f"{domain}    {err}\n", "tag1")
                  self.name_data_Text.insert(END, "========================================\n", "tag1")
 def addc(self):
   alld=self.init_data_Text.get(1.0, END).strip()
   dtype="CNAME"
   par=self.jiexizhi.get(1.0,END).strip()
   for domain in alld.split():
       domain=domain.strip()
       try:
         request = AddDomainRecordRequest()
         request.set_accept_format('json')
         request.set_Value(par)
         request.set_Type(dtype)
         request.set_RR("www")
         request.set_DomainName(domain)
         self.client.do_action_with_exception(request)
         self.name_data_Text.insert(END, domain+"  www  "+par+'    已添加完成\n', "tag2")
         request.set_RR("@")
         self.client.do_action_with_exception(request)
         self.name_data_Text.insert(END, domain+"    @  "+par+'    已添加完成\n', "tag2")
       except  Exception as err:
          if "The domain name belongs to other users" in str(err):
              self.name_data_Text.insert(END, f'{domain}  域名已被其他账户添加\n', "tag1")
          elif "DNS record is invalid or in the wrong format" in str(err):
              self.name_data_Text.insert(END, f'{domain}  格式错误\n', "tag1")
          elif "The specified domain name does not exist" in str(err):
              self.name_data_Text.insert(END, f'{domain}  此账户没有这条域名\n', "tag1")
          elif "The parameter value Value is invalid" in str(err):
              self.name_data_Text.insert(END, f'{domain}  参数键值无效\n', "tag1")
          elif "DomainRecordDuplicate The DNS record already exists" in str(err):
              self.name_data_Text.insert(END, f'{domain}  解析值已存在\n', "tag1")
          elif "type record is in conflict the" in str(err):
              self.name_data_Text.insert(END, f'{domain}  记录类型冲突\n', "tag1")
          else:
              self.name_data_Text.insert(END, "========================================\n", "tag1")
              self.name_data_Text.insert(END, f"{domain}    {err}\n", "tag1")
              self.name_data_Text.insert(END, "========================================\n", "tag1")
Esempio n. 6
0
 def add(self, domain_type, rr, domain_name, value):
     """
     :param domain_type: A
     :param rr: hk
     :param domain_name: ***************
     :param value: ***************
     :return:
     """
     request = AddDomainRecordRequest()
     request.set_accept_format('json')
     request.set_Value(value)
     request.set_Type(domain_type)
     request.set_RR(rr)
     request.set_DomainName(domain_name)
     try:
         response = self.client.do_action_with_exception(request)
         if ResponseUtil.success(response):
             record_id = response_record_id(response)
             if record_id:
                 logging.info(
                     "Successfully add domain information for : %s.%s to %s"
                     % (rr, domain, value))
                 return True, None
         else:
             return False, str(response, encoding='utf-8')
     except Exception as e:
         logging.error(
             "Failed to add sub domain parse information for %s.%s to %s" %
             (rr, domain, value), e)
         return False, e
Esempio n. 7
0
def add_domain_record(domain, value, rr, type='A'):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(domain)
    request.set_Type(type)
    request.set_RR(rr)
    request.set_Value(value)
    response = client.do_action_with_exception(request)
    return response
Esempio n. 8
0
 def add(DomainName, RR, Type, Value):
     from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
     request = AddDomainRecordRequest()
     request.set_accept_format("json")
     request.set_DomainName(DomainName)
     request.set_RR(RR)
     request.set_Type(Type)
     request.set_Value(Value)
     DDNSUnit.response(request)
def add(DomainName, RR, Type, Value):  # 添加新的域名解析记录
    from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(DomainName)
    request.set_RR(RR)  # https://blog.zeruns.tech
    request.set_Type(Type)
    request.set_Value(Value)
    response = client.do_action_with_exception(request)
Esempio n. 10
0
def add_record(x):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(DomainName)
    request.set_RR(RR)
    request.set_Type(Type)
    request.set_Value(x)
    response = client.do_action_with_exception(request)
    return str(response, encoding='utf-8')
Esempio n. 11
0
 def create_domain_record(self, domain, rr, record_type, value, ttl):
     request = AddDomainRecordRequest()
     if ttl is not None:
         request.set_TTL(ttl)
     request.set_Type(record_type)
     request.set_RR(rr)
     request.set_Value(value)
     request.set_DomainName(domain)
     request.set_accept_format("JSON")
     return json.loads(self.clt.do_action_with_exception(request))
Esempio n. 12
0
def AddRecords(DomainName, ResolutionRecord, RecordType, RecordValue):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(DomainName)
    request.set_RR(ResolutionRecord)
    request.set_Type(RecordType)
    request.set_Value(RecordValue)
    response = client.do_action_with_exception(request)
    records = json.loads(response)
    print(records)
Esempio n. 13
0
def add_record(client, domain_name, host, ip):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(domain_name)
    request.set_RR(host)
    request.set_Type("A")
    request.set_Value(ip)
    response = client.do_action_with_exception(request)
    r = response is not None and 'RequestId' in to_dict(response)
    print('     - [{}] {}'.format(r, host))
def add_domain_record(domain_name, rr, record_type, value, line=Line.default):
    client = create_client()
    request = AddDomainRecordRequest()
    request.set_accept_format('json')
    request.set_DomainName(domain_name)
    request.set_RR(rr)
    request.set_Type(record_type)
    request.set_Value(value)
    request.set_Line(line)
    response = client.do_action_with_exception(request)
    return response
    def add_record(accessKeyId, accessSecret, DomainName, RR, Type, target):
        client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou')

        request = AddDomainRecordRequest()
        request.set_accept_format('json')

        request.set_DomainName(DomainName)
        request.set_RR(RR)
        request.set_Type(Type)
        request.set_Value(target)

        response = client.do_action_with_exception(request)
Esempio n. 16
0
    def add_record(self, *args, **kwargs):
        request = AddDomainRecordRequest()
        request.set_accept_format('json')

        request.set_DomainName(kwargs.get('domain_name'))
        request.set_RR(kwargs.get('domain_rr'))
        request.set_Type(kwargs.get('domain_type'))
        request.set_Value(kwargs.get('domain_value'))
        request.set_TTL(kwargs.get('domain_ttl'))
        request.set_Line(kwargs.get('line'))
        response = self.__client.do_action_with_exception(request)
        return json.loads(str(response, encoding="utf8")).get('RecordId')
Esempio n. 17
0
 def __add_record(self, record, value, record_type, ttl):
     '''Add record.'''
     req = AddDomainRecordRequest()
     req.set_DomainName(self.__domain)
     req.set_accept_format('json')
     req.set_RR(record)
     req.set_Type(record_type)
     req.set_TTL(ttl)
     req.set_Value(value)
     js = json.loads(self.__bs.do_action_with_exception(req).decode())
     print('[+]%8s.%s -> %-16s;  %-8s;%s' %
           (record, self.__domain, value, record_type, ttl))
Esempio n. 18
0
def add_record(value):
    try:
        logging.info('AddDomainRecordRequest %s %s' % (SUBDOMAIN, value))
        request = AddDomainRecordRequest()
        request.set_DomainName(DOMAIN)
        request.set_RR(RECORD)
        request.set_Type('AAAA')
        request.set_Value(value)
        request.set_accept_format('json')
        response = acsClient.do_action_with_exception(request)
        return json.loads(response)['RecordId']
    except Exception as e:
        logging.error(e)
Esempio n. 19
0
    def add_txt_record(self, domain, record_name, record_value, ttl):
        rr = record_name[:record_name.rindex('.' + domain)]

        request = AddDomainRecordRequest()
        request.set_accept_format("json")

        request.set_DomainName(domain)
        request.set_Type("TXT")
        request.set_RR(rr)
        request.set_Value(record_value)
        request.set_TTL(ttl)

        self._client.do_action_with_exception(request)
    def _add_domain_record(self, domain_name: str, host_record: str,
                           record_type: str, value: str):
        request = AddDomainRecordRequest()
        request.set_accept_format('json')

        request.set_DomainName(domain_name)
        request.set_RR(host_record)
        request.set_Type(record_type)
        request.set_Value(value)

        response = self.client.do_action_with_exception(request)
        response = response.decode('utf-8')
        return json.loads(response)
Esempio n. 21
0
def add_record(ip_addr):
    add_record_id = None
    try:
        request = AddDomainRecordRequest()
        request.set_DomainName(DOMAIN)
        request.set_RR(SUBDOMAIN)
        request.set_Type('AAAA')
        request.set_Value(ip_addr)
        request.set_accept_format('json')
        response = acsClient.do_action_with_exception(request)
        add_record_id = json.loads(response)['RecordId']
    except Exception as e:
        print('add_record : %s' % e)
    return add_record_id
Esempio n. 22
0
def AddDomainRecordHelper(Client, DomainName, RR, Type, Value, Line):
    Request = AddDomainRecordRequest()
    Request.set_accept_format('json')

    #设置增加记录的信息
    Request.set_DomainName(DomainName)
    Request.set_RR(RR)
    Request.set_Type(Type)
    Request.set_Value(Value)
    Request.set_Line(Line)

    result = ExecuteGetResults(Client,Request)
    #print(result)
    return result
Esempio n. 23
0
def add_domain_record(client, domain_name, sub_name, dtype, value):
    request = AddDomainRecordRequest()
    request.set_accept_format('json')

    request.set_DomainName(domain_name)
    request.set_RR(sub_name)
    request.set_Type(dtype)
    request.set_Value(value)

    response = client.do_action_with_exception(request)
    response = response.decode()
    response = json.loads(response)
    if "RecordId" in response:
        return response['RecordId']
    return None
Esempio n. 24
0
    def add_record(self,
                   rr=None,
                   type=None,
                   line=None,
                   value=None,
                   ttl=600,
                   mx=None):
        """
        添加记录
        :return: True|False
        """
        try:
            if type == "显示URL":
                type = "REDIRECT_URL"

            if type == "隐性URL":
                type = "FORWARD_URL"

            client = AcsClient(self.key, self.secret, 'cn-hangzhou')
            request = AddDomainRecordRequest()
            request.set_accept_format('json')
            request.set_Line(self.record_line(value=line))
            request.set_TTL(600 if int(ttl) < 600 else int(ttl))
            request.set_Value(value)
            request.set_Type(type)
            # request.set_RR(RR + ("." + self.prefix_domain if self.prefix_domain else ""))
            if self.prefix_domain:
                rr = ''.join([rr, ".", self.prefix_domain])
            request.set_RR(rr)
            request.set_DomainName(self.second_level_domain)

            if type == "MX":
                request.set_Priority(mx)

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

            if "Code" in response.keys():
                print(F"add record failed: {response}")
                return False

            print(F"add record success: {rr}")
            return True

        except Exception:
            print("add record unknown exception")
            print(traceback.format_exc())
            return False
Esempio n. 25
0
    def add(self, rr, value):
        """
        Add a new domain record, failed if rr existed.

        :param rr: subdomain
        :param value: ip address
        """
        request = AddDomainRecordRequest()
        request.set_accept_format('json')
        request.set_DomainName(f'{self.domain}')
        request.set_RR(f'{rr}')
        request.set_Type(f'A')
        request.set_Value(f'{value}')
        response = str(self.client.do_action_with_exception(request),
                       encoding='utf-8')
        logging.debug(json.loads(response))
Esempio n. 26
0
def add_domain_record(client, domain, rr, value):
    """
    新增解析记录
    :param client
    :param domain:
    :param rr:
    :param value:
    :return:
    """
    request = AddDomainRecordRequest()
    request.set_DomainName(domain)
    request.set_RR(rr)
    request.set_Type('A')
    request.set_Value(value)

    response = client.do_action_with_exception(request)
    return response
Esempio n. 27
0
    def add_record(self, priority, ttl, record_type, value, rr, domain_name):
        logging.info("添加域名解析记录")
        from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest
        request = AddDomainRecordRequest()

        request.set_accept_format('json')
        request.set_Priority(priority)
        request.set_TTL(ttl)
        request.set_Value(value)
        request.set_Type(record_type)
        request.set_RR(rr)
        request.set_DomainName(domain_name)

        response = self.client.do_action_with_exception(request)
        response = str(response, encoding='utf-8')
        result = json.loads(response)
        logging.debug(result)
        return result
Esempio n. 28
0
    def add_record(self, obj):
        self.client = AcsClient(obj.domain_name.account.access_id,
                                obj.domain_name.account.access_key,
                                'cn-hangzhou')
        request = AddDomainRecordRequest()
        request.set_accept_format('json')

        request.set_TTL(obj.ttl)
        request.set_Line(obj.line)
        request.set_Value(obj.value)
        request.set_Type(obj.type)
        request.set_RR(obj.rr)
        request.set_DomainName(obj.domain_name.domain_name)
        if obj.priority:
            request.set_Priority(obj.priority)

        try:
            response = self.client.do_action_with_exception(request)
            ret = json.loads(str(response, encoding='utf-8'))
            return {'code': 1, 'message': ret}
        except Exception as e:
            return {'code': 0, 'message': e}
Esempio n. 29
0
#!/usr/bin/env python3
#coding=utf-8

import os
import sys
import idna
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest

domain = idna.decode(os.getenv("DOMAIN"))
accessKeyID = os.getenv("ACCESSKEYID")
accessSecret = os.getenv("ACCESSSECRET")
apinode = "cn-shanghai"

client = AcsClient(accessKeyID, accessSecret, apinode)

for r in sys.argv[1:]:
    request = AddDomainRecordRequest()
    request.set_accept_format('json')

    request.set_DomainName(domain)
    request.set_RR("_acme-challenge")
    request.set_Type("TXT")
    request.set_Value(str(r))

    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))
Esempio n. 30
0
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkalidns.request.v20150109.UpdateDomainRecordRequest import UpdateDomainRecordRequest
from aliyunsdkalidns.request.v20150109.AddDomainRecordRequest import AddDomainRecordRequest

import sys
sys.path.append("..")
from content import accessKeyId, accessSecret

from getip import get_ip

client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou')

ip = get_ip()
print(type(ip))
request = AddDomainRecordRequest()
request.set_accept_format('json')
request.set_Value(ip)
request.set_Type("A")
request.set_RR("blog")
request.set_DomainName("henqy.club")
response = client.do_action_with_exception(request)
# python2:  print(response)
print(str(response, encoding='utf-8'))